implement status messages
This commit is contained in:
parent
4d90b674ac
commit
27ccb472d2
|
@ -1,3 +1,5 @@
|
|||
require 'textmessage'
|
||||
|
||||
-- private functions
|
||||
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardCtrlModifier then
|
||||
|
@ -13,15 +15,16 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
|||
end
|
||||
|
||||
local function createMainInterface()
|
||||
gameUi = loadUI('/game/ui/gameinterface.otui', UI.root)
|
||||
gameUi.onKeyPress = onGameKeyPress
|
||||
Game.gameUi = loadUI('/game/ui/gameinterface.otui', UI.root)
|
||||
Game.gameMapUi = Game.gameUi:getChildById('gameMap')
|
||||
Game.gameUi.onKeyPress = onGameKeyPress
|
||||
end
|
||||
|
||||
|
||||
local function destroyMainInterface()
|
||||
if gameUi then
|
||||
gameUi:destroy()
|
||||
gameUi = nil
|
||||
Game.gameUi:destroy()
|
||||
Game.gameUi = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
local textMessageWidget
|
||||
|
||||
function Game.onTextMessage(message)
|
||||
if textMessageWidget then
|
||||
textMessageWidget:destroy()
|
||||
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
|
|
@ -0,0 +1,8 @@
|
|||
Label
|
||||
font: tibia-12px-rounded
|
||||
color: white
|
||||
height: 16
|
||||
align: center
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
|
@ -76,6 +76,8 @@ void UIWidget::destroy()
|
|||
// remove itself from parent
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->removeChild(asUIWidget());
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void UIWidget::render()
|
||||
|
|
|
@ -97,6 +97,11 @@ void Game::processLogout()
|
|||
}
|
||||
}
|
||||
|
||||
void Game::processTextMessage(const std::string& message)
|
||||
{
|
||||
g_lua.callGlobalField("Game","onTextMessage", message);
|
||||
}
|
||||
|
||||
void Game::walk(Otc::Direction direction)
|
||||
{
|
||||
|
||||
|
|
|
@ -32,18 +32,20 @@ public:
|
|||
void init();
|
||||
void terminate();
|
||||
|
||||
// login/logout related
|
||||
void loginWorld(const std::string& account,
|
||||
const std::string& password,
|
||||
const std::string& worldHost, int worldPort,
|
||||
const std::string& characterName);
|
||||
void cancelLogin();
|
||||
void logout(bool force);
|
||||
|
||||
void processLoginError(const std::string& error);
|
||||
void processConnectionError(const boost::system::error_code& error);
|
||||
void processLogin(const LocalPlayerPtr& localPlayer);
|
||||
void processLogout();
|
||||
|
||||
void processTextMessage(const std::string& message);
|
||||
|
||||
void walk(Otc::Direction direction);
|
||||
void turn(Otc::Direction direction);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
|||
{
|
||||
while(!msg.eof()) {
|
||||
uint8 opt = msg.getU8();
|
||||
dump << "protocol id:" << std::hex << (int)opt;
|
||||
//dump << "protocol id:" << std::hex << (int)opt;
|
||||
|
||||
switch(opt) {
|
||||
case 0x0A:
|
||||
|
@ -757,7 +757,9 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
|
|||
{
|
||||
msg.getU8(); // messageType
|
||||
std::string message = msg.getString();
|
||||
//logDebug(message);
|
||||
|
||||
// must be scheduled because the map may not exist yet
|
||||
g_dispatcher.addEvent(std::bind(&Game::processTextMessage, &g_game, message));
|
||||
}
|
||||
|
||||
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
||||
|
|
|
@ -31,13 +31,8 @@ void UIMap::setup()
|
|||
|
||||
void UIMap::render()
|
||||
{
|
||||
if(g_game.isOnline()) {
|
||||
Rect mapRect = m_rect;
|
||||
Size mapSize(15*32, 11*32);
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
mapRect.setSize(mapSize);
|
||||
g_map.draw(mapRect);
|
||||
}
|
||||
if(g_game.isOnline())
|
||||
g_map.draw(m_rect);
|
||||
|
||||
UIWidget::render();
|
||||
}
|
||||
|
@ -92,3 +87,13 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
|||
{
|
||||
return UIWidget::onMousePress(mousePos, button);
|
||||
}
|
||||
|
||||
void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
|
||||
{
|
||||
Rect mapRect = newRect;
|
||||
Size mapSize(15*32, 11*32);
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
mapRect.setSize(mapSize);
|
||||
if(mapRect != newRect)
|
||||
setRect(mapRect);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
protected:
|
||||
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
|
||||
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue