From 1a2e97bb5e10b8534718908e38edff3f59d7feca Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 9 Jun 2012 10:00:08 -0300 Subject: [PATCH] show private message on screen * disable GL blending in some situations to speedup on older hardware * fix wrap size in CachedText --- modules/client_options/general.otui | 4 ++ modules/client_options/options.lua | 3 +- modules/game/gameinterface.lua | 2 +- modules/game_console/console.lua | 15 +++++--- modules/game_textmessage/textmessage.lua | 47 ++++++++++------------- modules/game_textmessage/textmessage.otui | 23 +++++++---- src/framework/graphics/cachedtext.cpp | 4 +- src/framework/graphics/framebuffer.cpp | 6 +-- src/framework/graphics/graphics.cpp | 7 ---- src/framework/graphics/painter.cpp | 3 +- src/otclient/core/mapview.cpp | 5 +-- src/otclient/ui/uimap.cpp | 5 +-- 12 files changed, 63 insertions(+), 61 deletions(-) diff --git a/modules/client_options/general.otui b/modules/client_options/general.otui index c0b0c32b..910c4b1d 100644 --- a/modules/client_options/general.otui +++ b/modules/client_options/general.otui @@ -26,3 +26,7 @@ Panel OptionCheckBox id: showPrivateMessagesInConsole !text: tr('Show private messages in console') + + OptionCheckBox + id: showPrivateMessagesOnScreen + !text: tr('Show private messages on screen') diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 6984e3f3..de95e779 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -12,7 +12,8 @@ local options = { vsync = false, showInfoMessagesInConsole = true, showTimestampsInConsole = true, showLevelsInConsole = true, - showPrivateMessagesInConsole = false } + showPrivateMessagesInConsole = false, + showPrivateMessagesOnScreen = true } local generalPanel local graphicsPanel diff --git a/modules/game/gameinterface.lua b/modules/game/gameinterface.lua index 663ba597..f6fcab2b 100644 --- a/modules/game/gameinterface.lua +++ b/modules/game/gameinterface.lua @@ -272,7 +272,7 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu menu:addSeparator() menu:addOption(tr('Rule Violation'), function() RuleViolation.show(creatureThing:getName()) end) end - + menu:addSeparator() menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end) diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 479fb928..95c1d5ff 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -87,10 +87,13 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat speaktype = SpeakTypes[speaktype] if speaktype.hideInConsole then return end - message = applyMessagePrefixies(name, level, message) + local composedMessage = applyMessagePrefixies(name, level, message) if speaktype.private then - Console.addPrivateText(message, speaktype, name, false, name) + Console.addPrivateText(composedMessage, speaktype, name, false, name) + if Options.getOption('showPrivateMessagesOnScreen') then + TextMessage.displayPrivate(name .. ':\n' .. message) + end else local channel = tr('Default') if not defaultMessage then @@ -98,7 +101,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat end if channel then - Console.addText(message, speaktype, channel, name) + Console.addText(composedMessage, speaktype, channel, name) elseif channelId ~= 0 then -- server sent a message on a channel that is not open warning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel') @@ -350,7 +353,7 @@ function Console.addPrivateText(text, speaktype, name, isPrivateCommand, creatur local privateTab = Console.getTab(name) if privateTab == nil then - if Options['showPrivateMessagesInConsole'] or (isPrivateCommand and not privateTab) then + if (Options.getOption('showPrivateMessagesInConsole') and not focus) or (isPrivateCommand and not privateTab) then privateTab = Console.getTab(tr('Default')) else privateTab = Console.addTab(name, focus) @@ -383,7 +386,7 @@ function Console.addTabText(text, speaktype, tab, creatureName) consoleTabBar:blinkTab(tab) label.onMouseRelease = function (self, mousePos, mouseButton) Console.popupMenu(mousePos, mouseButton, creatureName, text) end - + if consoleBuffer:getChildCount() > MAX_LINES then consoleBuffer:getFirstChild():destroy() end @@ -469,7 +472,7 @@ function Console.sendCurrentMessage() tab = Console.getTab(tr('Default')) name = tr('Default') end - + local speaktypedesc if (tab.channelId or name == tr('Default')) and not chatCommandPrivateReady then if name == tr('Default') then diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index f9ca13c9..e6504047 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -8,16 +8,18 @@ local MessageTypes = { consoleRed = { color = '#F55E5E', consoleTab = tr('Default') }, consoleOrange = { color = '#FE6500', consoleTab = tr('Default') }, consoleBlue = { color = '#9F9DFD', consoleTab = tr('Default') }, - warning = { color = '#F55E5E', consoleTab = tr('Server Log'), labelId = 'centerWarning', wrap = true }, - infoDescription = { color = '#00EB00', consoleTab = tr('Server Log'), labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole', wrap = true }, - eventAdvance = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole', wrap = true }, + warning = { color = '#F55E5E', consoleTab = tr('Server Log'), labelId = 'centerWarning' }, + infoDescription = { color = '#00EB00', consoleTab = tr('Server Log'), labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole' }, + eventAdvance = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole' }, eventDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showEventMessagesInConsole' }, statusDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showStatusMessagesInConsole' }, statusSmall = { color = '#FFFFFF', labelId = 'bottomStatus' }, + private = { color = '#5FF7F7', labelId = 'centerPrivate' } } local centerTextMessagePanel local bottomStatusLabel +local privateLabel -- private functions local function displayMessage(msgtype, msg, time) @@ -35,13 +37,6 @@ local function displayMessage(msgtype, msg, time) label:setText(msg) label:setColor(msgtype.color) - if msgtype.wrap then - label:setWidth(label:getParent():getWidth()) - label:setHeight(label:getTextSize().height) - else - label:resizeToText() - end - if not time then time = math.max(#msg * 100, 4000) else @@ -53,15 +48,10 @@ local function displayMessage(msgtype, msg, time) end end -local function createTextMessageLabel(id, parent) - local label = createWidget('UILabel', parent) +local function createTextMessageLabel(id, parent, class) + local label = createWidget(class, parent) label:setFont('verdana-11px-rounded') - label:setTextAlign(AlignCenter) label:setId(id) - label:setMarginBottom(2) - label:setTextWrap(true) - label:setTextAutoResize(true) - label:setVisible(false) return label end @@ -80,15 +70,12 @@ function TextMessage.init() centerTextMessagePanel:setWidth(360) centerTextMessagePanel:centerIn('parent') - createTextMessageLabel('centerWarning', centerTextMessagePanel) - createTextMessageLabel('centerAdvance', centerTextMessagePanel) - createTextMessageLabel('centerInfo', centerTextMessagePanel) + createTextMessageLabel('centerWarning', centerTextMessagePanel, 'CenterLabel') + createTextMessageLabel('centerAdvance', centerTextMessagePanel, 'CenterLabel') + createTextMessageLabel('centerInfo', centerTextMessagePanel, 'CenterLabel') - bottomStatusLabel = createTextMessageLabel('bottomStatus', GameInterface.getMapPanel()) - bottomStatusLabel:setHeight(16) - bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom) - bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft) - bottomStatusLabel:addAnchor(AnchorRight, 'parent', AnchorRight) + privateLabel = createTextMessageLabel('centerPrivate', GameInterface.getMapPanel(), 'TopCenterLabel') + bottomStatusLabel = createTextMessageLabel('bottomStatus', GameInterface.getMapPanel(), 'BottomLabel') end function TextMessage.terminate() @@ -98,11 +85,14 @@ function TextMessage.terminate() removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerWarning').hideEvent) removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerAdvance').hideEvent) removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerInfo').hideEvent) + removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerPrivate').hideEvent) removeEvent(GameInterface.getMapPanel():recursiveGetChildById('bottomStatus').hideEvent) centerTextMessagePanel:destroy() - centerTextMessagePanel = nil bottomStatusLabel:destroy() + privateLabel:destroy() + centerTextMessagePanel = nil bottomStatusLabel = nil + privateLabel = nil TextMessage = nil end @@ -110,6 +100,7 @@ function TextMessage.clearMessages() GameInterface.getMapPanel():recursiveGetChildById('centerWarning'):hide() GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide() GameInterface.getMapPanel():recursiveGetChildById('centerInfo'):hide() + GameInterface.getMapPanel():recursiveGetChildById('centerPrivate'):hide() GameInterface.getMapPanel():recursiveGetChildById('bottomStatus'):hide() end @@ -121,6 +112,10 @@ function TextMessage.displayEventAdvance(msg, time) displayMessage(MessageTypes.eventAdvance, msg, time) end +function TextMessage.displayPrivate(msg, time) + displayMessage(MessageTypes.private, msg, time) +end + function TextMessage.display(msgtypedesc, msg) local msgtype = MessageTypes[msgtypedesc] if msgtype then diff --git a/modules/game_textmessage/textmessage.otui b/modules/game_textmessage/textmessage.otui index 78015ae4..9eca1262 100644 --- a/modules/game_textmessage/textmessage.otui +++ b/modules/game_textmessage/textmessage.otui @@ -1,15 +1,22 @@ -CenterLabel < GameLabel +CenterLabel < UILabel font: verdana-11px-rounded - height: 64 text-align: center text-wrap: true - anchors.centerIn: parent - size: 360 264 + text-auto-resize: true + margin-bottom: 2 + visible: false -BottomLabel < GameLabel +TopCenterLabel < UILabel font: verdana-11px-rounded - height: 16 text-align: center - margin-bottom: 2 - anchors.bottom: parent.bottom + text-wrap: true + visible: false + anchors.top: parent.top + anchors.bottom: centerTextMessagePanel.top anchors.horizontalCenter: parent.horizontalCenter + width: 360 + +BottomLabel < CenterLabel + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right diff --git a/src/framework/graphics/cachedtext.cpp b/src/framework/graphics/cachedtext.cpp index 0d69534c..8c4a30d8 100644 --- a/src/framework/graphics/cachedtext.cpp +++ b/src/framework/graphics/cachedtext.cpp @@ -55,6 +55,8 @@ void CachedText::update() void CachedText::wrapText(int maxWidth) { - if(m_font) + if(m_font) { m_text = m_font->wrapText(m_text, maxWidth); + update(); + } } diff --git a/src/framework/graphics/framebuffer.cpp b/src/framework/graphics/framebuffer.cpp index 15d10a1c..6efd0dea 100644 --- a/src/framework/graphics/framebuffer.cpp +++ b/src/framework/graphics/framebuffer.cpp @@ -148,10 +148,10 @@ void FrameBuffer::internalRelease() // restore screen original content if(m_backuping) { - Painter::CompositionMode oldComposition = g_painter->getCompositionMode(); - g_painter->setCompositionMode(Painter::CompositionMode_Replace); + glDisable(GL_BLEND); + g_painter->setColor(Color::white); g_painter->drawTexturedRect(screenRect, m_screenBackup, screenRect); - g_painter->setCompositionMode(oldComposition); + glEnable(GL_BLEND); } } } diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index d476d5a9..47b70448 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -79,13 +79,6 @@ void Graphics::init() // blending is always enabled glEnable(GL_BLEND); - // face culling may improve performance - /* - glCullFace(GL_BACK); - glFrontFace(GL_CW); - glEnable(GL_CULL_FACE); - */ - // determine max texture size GLint maxTextureSize = 0; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); diff --git a/src/framework/graphics/painter.cpp b/src/framework/graphics/painter.cpp index 64371a34..2c3ddda9 100644 --- a/src/framework/graphics/painter.cpp +++ b/src/framework/graphics/painter.cpp @@ -162,9 +162,8 @@ void Painter::updateGlCompositionMode() case CompositionMode_Normal: if(g_graphics.canUseBlendFuncSeparate()) glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - else { + else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } break; case CompositionMode_Multiply: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index 93f56171..a87a8f65 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -125,9 +125,8 @@ void MapView::draw(const Rect& rect) drawOffset.y += (srcVisible.height() - srcSize.height()) / 2; Rect srcRect = Rect(drawOffset, srcSize); - g_painter->saveState(); g_painter->setColor(Color::white); - g_painter->setCompositionMode(Painter::CompositionMode_Replace); + glDisable(GL_BLEND); #if 0 // debug source area g_painter->saveAndResetState(); @@ -140,7 +139,7 @@ void MapView::draw(const Rect& rect) #else m_framebuffer->draw(rect, srcRect); #endif - g_painter->restoreSavedState(); + glEnable(GL_BLEND); //g_painter->resetShaderProgram(); diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 2be6f2e2..a7445ae0 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -55,11 +55,10 @@ void UIMap::drawSelf(Fw::DrawPane drawPane) g_painter->drawBoundingRect(m_mapRect.expanded(1)); if(drawPane != Fw::BothPanes) { - g_painter->saveState(); - g_painter->setCompositionMode(Painter::CompositionMode_Replace); + glDisable(GL_BLEND); g_painter->setColor(Color::alpha); g_painter->drawFilledRect(m_mapRect); - g_painter->restoreSavedState(); + glEnable(GL_BLEND); } }