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:
parent
1281b04a6a
commit
59b6abfa09
|
@ -1,4 +1,5 @@
|
|||
SpeakTypesSettings = {
|
||||
none = {},
|
||||
say = { speakType = MessageModes.Say, color = '#FFFF00' },
|
||||
whisper = { speakType = MessageModes.Whisper, color = '#FFFF00' },
|
||||
yell = { speakType = MessageModes.Yell, color = '#FFFF00' },
|
||||
|
@ -31,6 +32,11 @@ SpeakTypes = {
|
|||
[MessageModes.ChannelHighlight] = SpeakTypesSettings.channelOrange,
|
||||
[MessageModes.MonsterSay] = SpeakTypesSettings.monsterSay,
|
||||
[MessageModes.MonsterYell] = SpeakTypesSettings.monsterYell,
|
||||
|
||||
-- ignored types
|
||||
[MessageModes.Spell] = SpeakTypesSettings.none,
|
||||
[MessageModes.BarkLow] = SpeakTypesSettings.none,
|
||||
[MessageModes.BarkLoud] = SpeakTypesSettings.none,
|
||||
}
|
||||
|
||||
SayModes = {
|
||||
|
@ -454,16 +460,21 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
|
|||
speaktype = SpeakTypes[mode]
|
||||
|
||||
if not speaktype then
|
||||
perror('unhandled onTalk message mode ' .. mode)
|
||||
perror('unhandled onTalk message mode ' .. mode .. ': ' .. message)
|
||||
return
|
||||
end
|
||||
|
||||
if speaktype == SpeakTypesSettings.none then return end
|
||||
|
||||
if speaktype.hideInConsole then return end
|
||||
|
||||
local composedMessage = applyMessagePrefixies(name, level, message)
|
||||
|
||||
if speaktype.private then
|
||||
addPrivateText(composedMessage, speaktype, name, false, name)
|
||||
if Options.getOption('showPrivateMessagesOnScreen') and speaktype.speakType ~= SpeakPrivateNpcToPlayer then
|
||||
modules.game_textmessage.displayPrivateMessage(name .. ':\n' .. message)
|
||||
end
|
||||
else
|
||||
local channel = tr('Default')
|
||||
if not defaultMessage then
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
MessageSettings = {
|
||||
none = {},
|
||||
consoleRed = { color = TextColors.red, consoleTab='Default' },
|
||||
consoleOrange = { color = TextColors.orange, consoleTab='Default' },
|
||||
consoleBlue = { color = TextColors.blue, consoleTab='Default' },
|
||||
|
@ -24,6 +25,25 @@ MessageTypes = {
|
|||
[MessageModes.Red] = MessageSettings.consoleRed,
|
||||
[MessageModes.Blue] = 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
|
||||
}
|
||||
|
||||
|
@ -37,7 +57,6 @@ end
|
|||
|
||||
function terminate()
|
||||
disconnect(g_game, 'onTextMessage', displayMessage)
|
||||
disconnect(g_game, 'onPrivateTalk', onPrivateTalk)
|
||||
disconnect(g_game, 'onGameEnd',clearMessages)
|
||||
clearMessages()
|
||||
messagesPanel:destroy()
|
||||
|
@ -53,10 +72,12 @@ function displayMessage(mode, text)
|
|||
local msgtype = MessageTypes[mode]
|
||||
|
||||
if not msgtype then
|
||||
perror('unhandled onTextMessage message mode ' .. mode)
|
||||
perror('unhandled onTextMessage message mode ' .. mode .. ': ' .. text)
|
||||
return
|
||||
end
|
||||
|
||||
if msgtype == MessageSettings.none then return end
|
||||
|
||||
if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption)) then
|
||||
modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab))
|
||||
--TODO move to game_console
|
||||
|
@ -72,6 +93,10 @@ function displayMessage(mode, text)
|
|||
end
|
||||
end
|
||||
|
||||
function displayPrivateMessage(text)
|
||||
displayMessage(254, text)
|
||||
end
|
||||
|
||||
function displayStatusMessage(text)
|
||||
displayMessage(MessageModes.Status, text)
|
||||
end
|
||||
|
@ -88,9 +113,3 @@ function clearMessages()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
function onPrivateTalk(code, text, speaker, speakerlevel, statmentid)
|
||||
if Options.getOption('showPrivateMessagesOnScreen') then
|
||||
displayMessage(254, speaker .. ':\n' .. text)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,9 @@ void Application::deinit()
|
|||
|
||||
// poll remaining events
|
||||
poll();
|
||||
|
||||
// disable dispatcher events
|
||||
g_dispatcher.shutdown();
|
||||
}
|
||||
|
||||
void Application::terminate()
|
||||
|
@ -115,9 +118,6 @@ void Application::terminate()
|
|||
// terminate script environment
|
||||
g_lua.terminate();
|
||||
|
||||
// flush remaining dispatcher events
|
||||
g_dispatcher.flush();
|
||||
|
||||
m_terminated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
EventDispatcher g_dispatcher;
|
||||
|
||||
void EventDispatcher::flush()
|
||||
void EventDispatcher::shutdown()
|
||||
{
|
||||
while(!m_eventList.empty())
|
||||
poll();
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
void flush();
|
||||
void shutdown();
|
||||
void poll();
|
||||
|
||||
EventPtr addEvent(const std::function<void()>& callback, bool pushFront = false);
|
||||
|
|
|
@ -37,7 +37,11 @@ FileStream::FileStream(const std::string& name, PHYSFS_File *fileHandle, bool wr
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -63,7 +67,7 @@ void FileStream::cache()
|
|||
|
||||
void FileStream::close()
|
||||
{
|
||||
if(m_fileHandle) {
|
||||
if(m_fileHandle && PHYSFS_isInit()) {
|
||||
if(!PHYSFS_close(m_fileHandle))
|
||||
throwError("close failed", true);
|
||||
m_fileHandle = nullptr;
|
||||
|
|
|
@ -47,7 +47,10 @@ void FrameBuffer::internalCreate()
|
|||
|
||||
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)
|
||||
glDeleteFramebuffers(1, &m_fbo);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,10 @@ HardwareBuffer::HardwareBuffer(Type type)
|
|||
|
||||
HardwareBuffer::~HardwareBuffer()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("HardwareBuffer reference not released");
|
||||
#endif
|
||||
if(g_graphics.ok())
|
||||
glDeleteBuffers(1, &m_id);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,10 @@ Shader::Shader(Shader::ShaderType shaderType)
|
|||
|
||||
Shader::~Shader()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("Shader reference not released");
|
||||
#endif
|
||||
if(g_graphics.ok())
|
||||
glDeleteShader(m_shaderId);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,10 @@ 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())
|
||||
glDeleteProgram(m_programId);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,10 @@ Texture::Texture(const ImagePtr& image, bool buildMipmaps)
|
|||
|
||||
Texture::~Texture()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("a texture reference was not released");
|
||||
#endif
|
||||
// free texture from gl memory
|
||||
if(g_graphics.ok() && m_id != 0)
|
||||
glDeleteTextures(1, &m_id);
|
||||
|
|
|
@ -37,18 +37,6 @@ void TextureManager::init()
|
|||
|
||||
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_emptyTexture = nullptr;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,10 @@ LuaObject::LuaObject() :
|
|||
|
||||
LuaObject::~LuaObject()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("LuaObject reference not released");
|
||||
#endif
|
||||
releaseLuaFieldsTable();
|
||||
|
||||
if(m_metatableRef != -1) {
|
||||
|
|
|
@ -41,7 +41,10 @@ Connection::Connection() :
|
|||
|
||||
Connection::~Connection()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("Connection reference not released");
|
||||
#endif
|
||||
close();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,10 @@ Protocol::Protocol()
|
|||
|
||||
Protocol::~Protocol()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning("Protocol reference not released");
|
||||
#endif
|
||||
disconnect();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
std::unordered_map<std::string, OTMLNodePtr> m_styles;
|
||||
UIWidgetList m_destroyedWidgets;
|
||||
ScheduledEventPtr m_checkEvent;
|
||||
|
||||
};
|
||||
|
||||
extern UIManager g_ui;
|
||||
|
|
|
@ -46,8 +46,9 @@ UIWidget::UIWidget()
|
|||
|
||||
UIWidget::~UIWidget()
|
||||
{
|
||||
assert(!g_app.isTerminated());
|
||||
#ifndef NDEBUG
|
||||
if(g_app.isTerminated())
|
||||
g_logger.warning(stdext::format("UIWidget '%s' reference not released", m_id));
|
||||
if(!m_destroyed)
|
||||
g_logger.warning(stdext::format("widget '%s' was not explicitly destroyed", m_id));
|
||||
#endif
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
if(pos.isValid() && (mode == Otc::MessageSay || mode == Otc::MessageWhisper || mode == Otc::MessageYell ||
|
||||
mode == Otc::MessageMonsterSay || mode == Otc::MessageMonsterYell || mode == Otc::MessageNpcFrom))
|
||||
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::MessageBarkLow || mode == Otc::MessageBarkLoud))
|
||||
{
|
||||
StaticTextPtr staticText = StaticTextPtr(new StaticText);
|
||||
staticText->addMessage(name, mode, text);
|
||||
|
|
|
@ -302,7 +302,7 @@ int Item::getSubType()
|
|||
{
|
||||
if(isSplash() || isFluidContainer())
|
||||
return m_countOrSubType;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Item::getCount()
|
||||
|
|
|
@ -64,7 +64,10 @@ 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)
|
||||
|
|
|
@ -120,7 +120,7 @@ void StaticText::compose()
|
|||
text += m_name;
|
||||
text += " yells:\n";
|
||||
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);
|
||||
} else if(m_mode == Otc::MessageNpcFrom) {
|
||||
text += m_name;
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
Otc::MessageMode getMessageMode() { return m_mode; }
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue