implement status messages

This commit is contained in:
Eduardo Bart 2011-08-30 12:12:57 -03:00
parent 4d90b674ac
commit 27ccb472d2
9 changed files with 57 additions and 14 deletions

View File

@ -1,3 +1,5 @@
require 'textmessage'
-- private functions -- private functions
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers) local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
if keyboardModifiers == KeyboardCtrlModifier then if keyboardModifiers == KeyboardCtrlModifier then
@ -13,15 +15,16 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
end end
local function createMainInterface() local function createMainInterface()
gameUi = loadUI('/game/ui/gameinterface.otui', UI.root) Game.gameUi = loadUI('/game/ui/gameinterface.otui', UI.root)
gameUi.onKeyPress = onGameKeyPress Game.gameMapUi = Game.gameUi:getChildById('gameMap')
Game.gameUi.onKeyPress = onGameKeyPress
end end
local function destroyMainInterface() local function destroyMainInterface()
if gameUi then if gameUi then
gameUi:destroy() Game.gameUi:destroy()
gameUi = nil Game.gameUi = nil
end end
end end

View File

@ -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

View File

@ -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

View File

@ -76,6 +76,8 @@ void UIWidget::destroy()
// remove itself from parent // remove itself from parent
if(UIWidgetPtr parent = getParent()) if(UIWidgetPtr parent = getParent())
parent->removeChild(asUIWidget()); parent->removeChild(asUIWidget());
setVisible(false);
setEnabled(false);
} }
void UIWidget::render() void UIWidget::render()

View File

@ -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) void Game::walk(Otc::Direction direction)
{ {

View File

@ -32,18 +32,20 @@ public:
void init(); void init();
void terminate(); void terminate();
// login/logout related
void loginWorld(const std::string& account, void loginWorld(const std::string& account,
const std::string& password, const std::string& password,
const std::string& worldHost, int worldPort, const std::string& worldHost, int worldPort,
const std::string& characterName); const std::string& characterName);
void cancelLogin(); void cancelLogin();
void logout(bool force); void logout(bool force);
void processLoginError(const std::string& error); void processLoginError(const std::string& error);
void processConnectionError(const boost::system::error_code& error); void processConnectionError(const boost::system::error_code& error);
void processLogin(const LocalPlayerPtr& localPlayer); void processLogin(const LocalPlayerPtr& localPlayer);
void processLogout(); void processLogout();
void processTextMessage(const std::string& message);
void walk(Otc::Direction direction); void walk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);

View File

@ -34,7 +34,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
{ {
while(!msg.eof()) { while(!msg.eof()) {
uint8 opt = msg.getU8(); uint8 opt = msg.getU8();
dump << "protocol id:" << std::hex << (int)opt; //dump << "protocol id:" << std::hex << (int)opt;
switch(opt) { switch(opt) {
case 0x0A: case 0x0A:
@ -757,7 +757,9 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
{ {
msg.getU8(); // messageType msg.getU8(); // messageType
std::string message = msg.getString(); 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) void ProtocolGame::parseCancelWalk(InputMessage& msg)

View File

@ -31,13 +31,8 @@ void UIMap::setup()
void UIMap::render() void UIMap::render()
{ {
if(g_game.isOnline()) { if(g_game.isOnline())
Rect mapRect = m_rect; g_map.draw(m_rect);
Size mapSize(15*32, 11*32);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
mapRect.setSize(mapSize);
g_map.draw(mapRect);
}
UIWidget::render(); UIWidget::render();
} }
@ -92,3 +87,13 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
{ {
return UIWidget::onMousePress(mousePos, 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);
}

View File

@ -35,6 +35,7 @@ public:
protected: protected:
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers); virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
private: private:
}; };