From b69dc5487f0e1beadfd739eb050a8ad5f0ba8e39 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sun, 4 Sep 2011 14:21:42 -0300 Subject: [PATCH] textmessage --- modules/game/game.lua | 1 + modules/game/textmessage.lua | 63 +++++++++++++++++++++----- modules/game/ui/textmessage.otui | 14 ++++-- src/otclient/core/game.cpp | 4 +- src/otclient/core/game.h | 2 +- src/otclient/net/protocolgameparse.cpp | 4 +- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/modules/game/game.lua b/modules/game/game.lua index bf8fd160..bceb5894 100644 --- a/modules/game/game.lua +++ b/modules/game/game.lua @@ -20,6 +20,7 @@ local function createMainInterface() Game.gameMapUi = Game.gameUi:getChildById('gameMap') Game.gameUi.onKeyPress = onGameKeyPress + createTextInterface() createVipWindow() end diff --git a/modules/game/textmessage.lua b/modules/game/textmessage.lua index aa1c0b09..275203cc 100644 --- a/modules/game/textmessage.lua +++ b/modules/game/textmessage.lua @@ -1,15 +1,56 @@ -local textMessageWidget +importStyles('/game/ui/textmessage.otui') -function Game.onTextMessage(message) - if textMessageWidget then - textMessageWidget:destroy() +local bottomLabelWidget, centerLabelWidget + +local messageTypes = { +first = 12, +{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, +{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, +{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, +{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, +{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, +{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, +{ type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, +{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' }, +{ type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false }, +{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false } +} + +function createTextInterface() + bottomLabelWidget = UILabel.create() + Game.gameMapUi:addChild(bottomLabelWidget) + + centerLabelWidget = UILabel.create() + Game.gameMapUi:addChild(centerLabelWidget) +end + +function Game.onTextMessage(type, message) + + local messageType = messageTypes[type - messageTypes.first] + + if messageType.showOnConsole then + -- TODO + end + + if messageType.showOnWindow then + local label + if messageType.windowLocation == 'BottomLabel' then + label = bottomLabelWidget + elseif messageType.windowLocation == 'CenterLabel' then + label = centerLabelWidget + end + + label:setVisible(true) + label:setForegroundColor(messageType.color) + label:setText(message) + + label:setStyle(messageType.windowLocation) + + time = #message * 75 + scheduleEvent(function() + label:setVisible(false) + end, time) end - local newTextMessageWidget = loadUI('/game/ui/textmessage.otui', Game.gameMapUi) - time = #message * 75 - newTextMessageWidget:setText(message) - scheduleEvent(function() - newTextMessageWidget:destroy() - end, time) - textMessageWidget = newTextMessageWidget end + diff --git a/modules/game/ui/textmessage.otui b/modules/game/ui/textmessage.otui index 2ebb426f..aab2e1e9 100644 --- a/modules/game/ui/textmessage.otui +++ b/modules/game/ui/textmessage.otui @@ -1,8 +1,16 @@ -Label +CenterLabel < Label + font: tibia-12px-rounded + height: 16 + align: center + anchors.top: parent.verticalCenter + anchors.bottom: parent.verticalCenter + anchors.left: parent.left + anchors.right: parent.right + +BottomLabel < Label font: tibia-12px-rounded - color: white height: 16 align: center anchors.bottom: parent.bottom anchors.left: parent.left - anchors.right: parent.right \ No newline at end of file + anchors.right: parent.right diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b4febee8..70ec478a 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -97,9 +97,9 @@ void Game::processLogout() } } -void Game::processTextMessage(const std::string& message) +void Game::processTextMessage(int type, const std::string& message) { - g_lua.callGlobalField("Game","onTextMessage", message); + g_lua.callGlobalField("Game","onTextMessage", type, message); } void Game::walk(Otc::Direction direction) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index b431e40f..5e1f6c95 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -44,7 +44,7 @@ public: void processLogin(const LocalPlayerPtr& localPlayer); void processLogout(); - void processTextMessage(const std::string& message); + void processTextMessage(int type, const std::string& message); void walk(Otc::Direction direction); void turn(Otc::Direction direction); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index c9a4f38e..56f7bd08 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -734,11 +734,11 @@ void ProtocolGame::parseClosePrivateChannel(InputMessage& msg) void ProtocolGame::parseTextMessage(InputMessage& msg) { - msg.getU8(); // messageType + uint8 type = msg.getU8(); std::string message = msg.getString(); // must be scheduled because the map may not exist yet - g_dispatcher.addEvent(std::bind(&Game::processTextMessage, &g_game, message)); + g_dispatcher.addEvent(std::bind(&Game::processTextMessage, &g_game, type, message)); } void ProtocolGame::parseCancelWalk(InputMessage& msg)