textmessage
This commit is contained in:
parent
bdbfa5b6ac
commit
b69dc5487f
|
@ -20,6 +20,7 @@ local function createMainInterface()
|
||||||
Game.gameMapUi = Game.gameUi:getChildById('gameMap')
|
Game.gameMapUi = Game.gameUi:getChildById('gameMap')
|
||||||
Game.gameUi.onKeyPress = onGameKeyPress
|
Game.gameUi.onKeyPress = onGameKeyPress
|
||||||
|
|
||||||
|
createTextInterface()
|
||||||
createVipWindow()
|
createVipWindow()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,56 @@
|
||||||
local textMessageWidget
|
importStyles('/game/ui/textmessage.otui')
|
||||||
|
|
||||||
function Game.onTextMessage(message)
|
local bottomLabelWidget, centerLabelWidget
|
||||||
if textMessageWidget then
|
|
||||||
textMessageWidget:destroy()
|
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
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
font: tibia-12px-rounded
|
||||||
color: white
|
|
||||||
height: 16
|
height: 16
|
||||||
align: center
|
align: center
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
|
@ -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)
|
void Game::walk(Otc::Direction direction)
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
void processLogin(const LocalPlayerPtr& localPlayer);
|
void processLogin(const LocalPlayerPtr& localPlayer);
|
||||||
void processLogout();
|
void processLogout();
|
||||||
|
|
||||||
void processTextMessage(const std::string& message);
|
void processTextMessage(int type, const std::string& message);
|
||||||
|
|
||||||
void walk(Otc::Direction direction);
|
void walk(Otc::Direction direction);
|
||||||
void turn(Otc::Direction direction);
|
void turn(Otc::Direction direction);
|
||||||
|
|
|
@ -734,11 +734,11 @@ void ProtocolGame::parseClosePrivateChannel(InputMessage& msg)
|
||||||
|
|
||||||
void ProtocolGame::parseTextMessage(InputMessage& msg)
|
void ProtocolGame::parseTextMessage(InputMessage& msg)
|
||||||
{
|
{
|
||||||
msg.getU8(); // messageType
|
uint8 type = msg.getU8();
|
||||||
std::string message = msg.getString();
|
std::string message = msg.getString();
|
||||||
|
|
||||||
// must be scheduled because the map may not exist yet
|
// 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)
|
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
||||||
|
|
Loading…
Reference in New Issue