Implement message modes for 9.6

Fix possible crash when closing otclient
Fix private messages
Fix messages in 9.6
This commit is contained in:
Eduardo Bart 2012-07-30 09:29:13 -03:00
parent 1281b04a6a
commit 59b6abfa09
22 changed files with 95 additions and 42 deletions

View File

@ -1,4 +1,5 @@
SpeakTypesSettings = { SpeakTypesSettings = {
none = {},
say = { speakType = MessageModes.Say, color = '#FFFF00' }, say = { speakType = MessageModes.Say, color = '#FFFF00' },
whisper = { speakType = MessageModes.Whisper, color = '#FFFF00' }, whisper = { speakType = MessageModes.Whisper, color = '#FFFF00' },
yell = { speakType = MessageModes.Yell, color = '#FFFF00' }, yell = { speakType = MessageModes.Yell, color = '#FFFF00' },
@ -31,6 +32,11 @@ SpeakTypes = {
[MessageModes.ChannelHighlight] = SpeakTypesSettings.channelOrange, [MessageModes.ChannelHighlight] = SpeakTypesSettings.channelOrange,
[MessageModes.MonsterSay] = SpeakTypesSettings.monsterSay, [MessageModes.MonsterSay] = SpeakTypesSettings.monsterSay,
[MessageModes.MonsterYell] = SpeakTypesSettings.monsterYell, [MessageModes.MonsterYell] = SpeakTypesSettings.monsterYell,
-- ignored types
[MessageModes.Spell] = SpeakTypesSettings.none,
[MessageModes.BarkLow] = SpeakTypesSettings.none,
[MessageModes.BarkLoud] = SpeakTypesSettings.none,
} }
SayModes = { SayModes = {
@ -454,16 +460,21 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
speaktype = SpeakTypes[mode] speaktype = SpeakTypes[mode]
if not speaktype then if not speaktype then
perror('unhandled onTalk message mode ' .. mode) perror('unhandled onTalk message mode ' .. mode .. ': ' .. message)
return return
end end
if speaktype == SpeakTypesSettings.none then return end
if speaktype.hideInConsole then return end if speaktype.hideInConsole then return end
local composedMessage = applyMessagePrefixies(name, level, message) local composedMessage = applyMessagePrefixies(name, level, message)
if speaktype.private then if speaktype.private then
addPrivateText(composedMessage, speaktype, name, false, name) addPrivateText(composedMessage, speaktype, name, false, name)
if Options.getOption('showPrivateMessagesOnScreen') and speaktype.speakType ~= SpeakPrivateNpcToPlayer then
modules.game_textmessage.displayPrivateMessage(name .. ':\n' .. message)
end
else else
local channel = tr('Default') local channel = tr('Default')
if not defaultMessage then if not defaultMessage then

View File

@ -1,4 +1,5 @@
MessageSettings = { MessageSettings = {
none = {},
consoleRed = { color = TextColors.red, consoleTab='Default' }, consoleRed = { color = TextColors.red, consoleTab='Default' },
consoleOrange = { color = TextColors.orange, consoleTab='Default' }, consoleOrange = { color = TextColors.orange, consoleTab='Default' },
consoleBlue = { color = TextColors.blue, consoleTab='Default' }, consoleBlue = { color = TextColors.blue, consoleTab='Default' },
@ -24,6 +25,25 @@ MessageTypes = {
[MessageModes.Red] = MessageSettings.consoleRed, [MessageModes.Red] = MessageSettings.consoleRed,
[MessageModes.Blue] = MessageSettings.consoleBlue, [MessageModes.Blue] = MessageSettings.consoleBlue,
[MessageModes.PrivateFrom] = MessageSettings.consoleBlue, [MessageModes.PrivateFrom] = MessageSettings.consoleBlue,
[MessageModes.DamageDealed] = MessageSettings.status,
[MessageModes.DamageReceived] = MessageSettings.status,
[MessageModes.Heal] = MessageSettings.status,
[MessageModes.Exp] = MessageSettings.status,
[MessageModes.DamageOthers] = MessageSettings.none,
[MessageModes.HealOthers] = MessageSettings.none,
[MessageModes.ExpOthers] = MessageSettings.none,
[MessageModes.TradeNpc] = MessageSettings.centerWhite,
[MessageModes.Guild] = MessageSettings.centerWhite,
[MessageModes.PartyManagement] = MessageSettings.centerWhite,
[MessageModes.TutorialHint] = MessageSettings.centerWhite,
[MessageModes.Market] = MessageSettings.centerWhite,
[MessageModes.BeyondLast] = MessageSettings.centerWhite,
[MessageModes.Report] = MessageSettings.consoleRed,
[MessageModes.HotkeyUse] = MessageSettings.centerGreen,
[254] = MessageSettings.private [254] = MessageSettings.private
} }
@ -37,7 +57,6 @@ end
function terminate() function terminate()
disconnect(g_game, 'onTextMessage', displayMessage) disconnect(g_game, 'onTextMessage', displayMessage)
disconnect(g_game, 'onPrivateTalk', onPrivateTalk)
disconnect(g_game, 'onGameEnd',clearMessages) disconnect(g_game, 'onGameEnd',clearMessages)
clearMessages() clearMessages()
messagesPanel:destroy() messagesPanel:destroy()
@ -53,10 +72,12 @@ function displayMessage(mode, text)
local msgtype = MessageTypes[mode] local msgtype = MessageTypes[mode]
if not msgtype then if not msgtype then
perror('unhandled onTextMessage message mode ' .. mode) perror('unhandled onTextMessage message mode ' .. mode .. ': ' .. text)
return return
end end
if msgtype == MessageSettings.none then return end
if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption)) then if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption)) then
modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab)) modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab))
--TODO move to game_console --TODO move to game_console
@ -72,6 +93,10 @@ function displayMessage(mode, text)
end end
end end
function displayPrivateMessage(text)
displayMessage(254, text)
end
function displayStatusMessage(text) function displayStatusMessage(text)
displayMessage(MessageModes.Status, text) displayMessage(MessageModes.Status, text)
end end
@ -88,9 +113,3 @@ function clearMessages()
end end
end end
end end
function onPrivateTalk(code, text, speaker, speakerlevel, statmentid)
if Options.getOption('showPrivateMessagesOnScreen') then
displayMessage(254, speaker .. ':\n' .. text)
end
end

View File

@ -97,6 +97,9 @@ void Application::deinit()
// poll remaining events // poll remaining events
poll(); poll();
// disable dispatcher events
g_dispatcher.shutdown();
} }
void Application::terminate() void Application::terminate()
@ -115,9 +118,6 @@ void Application::terminate()
// terminate script environment // terminate script environment
g_lua.terminate(); g_lua.terminate();
// flush remaining dispatcher events
g_dispatcher.flush();
m_terminated = true; m_terminated = true;
} }

View File

@ -27,7 +27,7 @@
EventDispatcher g_dispatcher; EventDispatcher g_dispatcher;
void EventDispatcher::flush() void EventDispatcher::shutdown()
{ {
while(!m_eventList.empty()) while(!m_eventList.empty())
poll(); poll();

View File

@ -30,7 +30,7 @@
class EventDispatcher class EventDispatcher
{ {
public: public:
void flush(); void shutdown();
void poll(); void poll();
EventPtr addEvent(const std::function<void()>& callback, bool pushFront = false); EventPtr addEvent(const std::function<void()>& callback, bool pushFront = false);

View File

@ -37,7 +37,11 @@ FileStream::FileStream(const std::string& name, PHYSFS_File *fileHandle, bool wr
FileStream::~FileStream() FileStream::~FileStream()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("FileStream reference not released");
#endif
if(!g_app.isTerminated())
close(); close();
} }
@ -63,7 +67,7 @@ void FileStream::cache()
void FileStream::close() void FileStream::close()
{ {
if(m_fileHandle) { if(m_fileHandle && PHYSFS_isInit()) {
if(!PHYSFS_close(m_fileHandle)) if(!PHYSFS_close(m_fileHandle))
throwError("close failed", true); throwError("close failed", true);
m_fileHandle = nullptr; m_fileHandle = nullptr;

View File

@ -47,7 +47,10 @@ void FrameBuffer::internalCreate()
FrameBuffer::~FrameBuffer() FrameBuffer::~FrameBuffer()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("FrameBuffer reference not released");
#endif
if(g_graphics.ok() && m_fbo != 0) if(g_graphics.ok() && m_fbo != 0)
glDeleteFramebuffers(1, &m_fbo); glDeleteFramebuffers(1, &m_fbo);
} }

View File

@ -37,7 +37,10 @@ HardwareBuffer::HardwareBuffer(Type type)
HardwareBuffer::~HardwareBuffer() HardwareBuffer::~HardwareBuffer()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("HardwareBuffer reference not released");
#endif
if(g_graphics.ok()) if(g_graphics.ok())
glDeleteBuffers(1, &m_id); glDeleteBuffers(1, &m_id);
} }

View File

@ -44,7 +44,10 @@ Shader::Shader(Shader::ShaderType shaderType)
Shader::~Shader() Shader::~Shader()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("Shader reference not released");
#endif
if(g_graphics.ok()) if(g_graphics.ok())
glDeleteShader(m_shaderId); glDeleteShader(m_shaderId);
} }

View File

@ -38,7 +38,10 @@ ShaderProgram::ShaderProgram()
ShaderProgram::~ShaderProgram() ShaderProgram::~ShaderProgram()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("ShaderProgram reference not released");
#endif
if(g_graphics.ok()) if(g_graphics.ok())
glDeleteProgram(m_programId); glDeleteProgram(m_programId);
} }

View File

@ -79,6 +79,10 @@ Texture::Texture(const ImagePtr& image, bool buildMipmaps)
Texture::~Texture() Texture::~Texture()
{ {
#ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("a texture reference was not released");
#endif
// free texture from gl memory // free texture from gl memory
if(g_graphics.ok() && m_id != 0) if(g_graphics.ok() && m_id != 0)
glDeleteTextures(1, &m_id); glDeleteTextures(1, &m_id);

View File

@ -37,18 +37,6 @@ void TextureManager::init()
void TextureManager::terminate() void TextureManager::terminate()
{ {
#ifndef NDEBUG
// check for leaks
int refs = 0;
for(const auto& it : m_textures) {
if(it.second->ref_count() > 1) {
refs++;
g_logger.debug(stdext::format("texture reference released: %s", it.first));
}
}
if(refs > 0)
g_logger.debug(stdext::format("%d textures references left", refs));
#endif
m_textures.clear(); m_textures.clear();
m_emptyTexture = nullptr; m_emptyTexture = nullptr;
} }

View File

@ -33,7 +33,10 @@ LuaObject::LuaObject() :
LuaObject::~LuaObject() LuaObject::~LuaObject()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("LuaObject reference not released");
#endif
releaseLuaFieldsTable(); releaseLuaFieldsTable();
if(m_metatableRef != -1) { if(m_metatableRef != -1) {

View File

@ -41,7 +41,10 @@ Connection::Connection() :
Connection::~Connection() Connection::~Connection()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("Connection reference not released");
#endif
close(); close();
} }

View File

@ -33,7 +33,10 @@ Protocol::Protocol()
Protocol::~Protocol() Protocol::~Protocol()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("Protocol reference not released");
#endif
disconnect(); disconnect();
} }

View File

@ -87,6 +87,7 @@ private:
std::unordered_map<std::string, OTMLNodePtr> m_styles; std::unordered_map<std::string, OTMLNodePtr> m_styles;
UIWidgetList m_destroyedWidgets; UIWidgetList m_destroyedWidgets;
ScheduledEventPtr m_checkEvent; ScheduledEventPtr m_checkEvent;
}; };
extern UIManager g_ui; extern UIManager g_ui;

View File

@ -46,8 +46,9 @@ UIWidget::UIWidget()
UIWidget::~UIWidget() UIWidget::~UIWidget()
{ {
assert(!g_app.isTerminated());
#ifndef NDEBUG #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning(stdext::format("UIWidget '%s' reference not released", m_id));
if(!m_destroyed) if(!m_destroyed)
g_logger.warning(stdext::format("widget '%s' was not explicitly destroyed", m_id)); g_logger.warning(stdext::format("widget '%s' was not explicitly destroyed", m_id));
#endif #endif

View File

@ -170,8 +170,9 @@ void Game::processTextMessage(Otc::MessageMode mode, const std::string& text)
void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos) void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos)
{ {
if(pos.isValid() && (mode == Otc::MessageSay || mode == Otc::MessageWhisper || mode == Otc::MessageYell || if(pos.isValid() && (mode == Otc::MessageSay || mode == Otc::MessageWhisper || mode == Otc::MessageYell || mode == Otc::MessageSpell ||
mode == Otc::MessageMonsterSay || mode == Otc::MessageMonsterYell || mode == Otc::MessageNpcFrom)) mode == Otc::MessageMonsterSay || mode == Otc::MessageMonsterYell || mode == Otc::MessageNpcFrom ||
mode == Otc::MessageBarkLow || mode == Otc::MessageBarkLoud))
{ {
StaticTextPtr staticText = StaticTextPtr(new StaticText); StaticTextPtr staticText = StaticTextPtr(new StaticText);
staticText->addMessage(name, mode, text); staticText->addMessage(name, mode, text);

View File

@ -302,7 +302,7 @@ int Item::getSubType()
{ {
if(isSplash() || isFluidContainer()) if(isSplash() || isFluidContainer())
return m_countOrSubType; return m_countOrSubType;
return 1; return 0;
} }
int Item::getCount() int Item::getCount()

View File

@ -64,7 +64,10 @@ MapView::MapView()
MapView::~MapView() MapView::~MapView()
{ {
assert(!g_app.isTerminated()); #ifndef NDEBUG
if(g_app.isTerminated())
g_logger.warning("MapView reference not released");
#endif
} }
void MapView::draw(const Rect& rect) void MapView::draw(const Rect& rect)

View File

@ -120,7 +120,7 @@ void StaticText::compose()
text += m_name; text += m_name;
text += " yells:\n"; text += " yells:\n";
m_color = Color(239, 239, 0); m_color = Color(239, 239, 0);
} else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageSpell) { } else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageSpell || m_mode == Otc::MessageBarkLow || m_mode == Otc::MessageBarkLoud) {
m_color = Color(254, 101, 0); m_color = Color(254, 101, 0);
} else if(m_mode == Otc::MessageNpcFrom) { } else if(m_mode == Otc::MessageNpcFrom) {
text += m_name; text += m_name;

View File

@ -39,7 +39,7 @@ public:
Otc::MessageMode getMessageMode() { return m_mode; } Otc::MessageMode getMessageMode() { return m_mode; }
std::string getFirstMessage() { return m_messages[0].first; } std::string getFirstMessage() { return m_messages[0].first; }
bool isYell() { return m_mode == Otc::MessageYell || m_mode == Otc::MessageMonsterYell; } bool isYell() { return m_mode == Otc::MessageYell || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageBarkLoud; }
bool addMessage(const std::string& name, Otc::MessageMode mode, const std::string& text); bool addMessage(const std::string& name, Otc::MessageMode mode, const std::string& text);