add onGameStart/onGameEnd/onLogin/onLogout events

This commit is contained in:
Eduardo Bart 2012-02-07 21:54:33 -02:00
parent ee1357a848
commit 09b3aa82df
16 changed files with 59 additions and 46 deletions

View File

@ -25,8 +25,8 @@ function TopMenu.init()
TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout) TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
Keyboard.bindKeyDown('Ctrl+Q', onLogout) Keyboard.bindKeyDown('Ctrl+Q', onLogout)
connect(Game, { onLogin = TopMenu.showGameButtons, connect(Game, { onGameStart = TopMenu.showGameButtons,
onLogout = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
end end
function TopMenu.terminate() function TopMenu.terminate()
@ -37,8 +37,8 @@ function TopMenu.terminate()
topMenu:destroy() topMenu:destroy()
topMenu = nil topMenu = nil
disconnect(Game, { onLogin = TopMenu.showGameButtons, disconnect(Game, { onGameStart = TopMenu.showGameButtons,
onLogout = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
TopMenu = nil TopMenu = nil
end end

View File

@ -108,5 +108,5 @@ local function onApplicationClose()
end end
setonclose(onApplicationClose) setonclose(onApplicationClose)
connect(Game, { onLogin = Game.createInterface }, true) connect(Game, { onGameStart = Game.createInterface }, true)
connect(Game, { onLogout = Game.destroyInterface }) connect(Game, { onGameEnd = Game.destroyInterface })

View File

@ -66,8 +66,8 @@ function CombatControls.init()
connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange }) connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
connect(chaseModeButton, { onCheckChange = onChaseModeChange }) connect(chaseModeButton, { onCheckChange = onChaseModeChange })
connect(safeFightButton, { onCheckChange = onSafeFightChange }) connect(safeFightButton, { onCheckChange = onSafeFightChange })
connect(Game, { onLogin = CombatControls.online }) connect(Game, { onGameStart = CombatControls.online })
connect(Game, { onLogout = CombatControls.offline }) connect(Game, { onGameEnd = CombatControls.offline })
if Game.isOnline() then if Game.isOnline() then
CombatControls.online() CombatControls.online()
@ -94,8 +94,8 @@ function CombatControls.terminate()
combatControlsWindow:destroy() combatControlsWindow:destroy()
combatControlsWindow = nil combatControlsWindow = nil
disconnect(Game, { onLogin = CombatControls.online }) disconnect(Game, { onGameStart = CombatControls.online })
disconnect(Game, { onLogout = CombatControls.offline }) disconnect(Game, { onGameEnd = CombatControls.offline })
CombatControls = nil CombatControls = nil
end end

View File

@ -365,8 +365,8 @@ local function onChannelList(channelList)
end end
end end
connect(Game, { onLogin = Console.create, connect(Game, { onGameStart = Console.create,
onLogout = Console.destroy, onGameEnd = Console.destroy,
onCreatureSpeak = onCreatureSpeak, onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList, onChannelList = onChannelList,
onOpenChannel = onOpenChannel, onOpenChannel = onOpenChannel,

View File

@ -128,8 +128,8 @@ function Containers.onContainerRemoveItem(containerId, slot)
container.itemCount = container.itemCount - 1 container.itemCount = container.itemCount - 1
end end
connect(Game, { onLogin = Containers.clean, connect(Game, { onGameStart = Containers.clean,
onLogout = Containers.clean, onGameEnd = Containers.clean,
onContainerOpen = Containers.onContainerOpen, onContainerOpen = Containers.onContainerOpen,
onContainerClose = Containers.onContainerClose, onContainerClose = Containers.onContainerClose,
onContainerAddItem = Containers.onContainerAddItem, onContainerAddItem = Containers.onContainerAddItem,

View File

@ -53,7 +53,7 @@ function HealthBar.onManaChange(mana, maxMana)
manaBar:setPercent(percent) manaBar:setPercent(percent)
end end
connect(Game, { onLogin = HealthBar.create, connect(Game, { onGameStart = HealthBar.create,
onLogout = HealthBar.destroy, onGameEnd = HealthBar.destroy,
onHealthChange = HealthBar.onHealthChange, onHealthChange = HealthBar.onHealthChange,
onManaChange = HealthBar.onManaChange }) onManaChange = HealthBar.onManaChange })

View File

@ -42,8 +42,8 @@ function Inventory.onSoulChange(soul)
widget:setText("Soul:\n" .. soul) widget:setText("Soul:\n" .. soul)
end end
connect(Game, { onLogin = Inventory.create, connect(Game, { onGameStart = Inventory.create,
onLogout = Inventory.destroy, onGameEnd = Inventory.destroy,
onInventoryChange = Inventory.onInventoryChange, onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange, onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange }) onSoulChange = Inventory.onSoulChange })

View File

@ -199,4 +199,4 @@ end
-- hooked events -- hooked events
connect(Game, { onOpenOutfitWindow = Outfit.create, connect(Game, { onOpenOutfitWindow = Outfit.create,
onLogout = Outfit.destroy }) onGameEnd = Outfit.destroy })

View File

@ -122,8 +122,8 @@ function Skills.onSkillChange(id, level, percent)
setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
connect(Game, { onLogin = Skills.create, connect(Game, { onGameStart = Skills.create,
onLogout = Skills.destroy, onGameEnd = Skills.destroy,
onExperienceChange = Skills.onExperienceChange, onExperienceChange = Skills.onExperienceChange,
onLevelChange = Skills.onLevelChange, onLevelChange = Skills.onLevelChange,
onHealthChange = Skills.onHealthChange, onHealthChange = Skills.onHealthChange,

View File

@ -111,7 +111,7 @@ local function onGameTextMessage(msgtypedesc, msg)
TextMessage.display(msgtypedesc, msg) TextMessage.display(msgtypedesc, msg)
end end
connect(Game, { onLogin = TextMessage.create, connect(Game, { onGameStart = TextMessage.create,
onLogout = TextMessage.destroy, onGameEnd = TextMessage.destroy,
onDeath = onGameDeath, onDeath = onGameDeath,
onTextMessage = onGameTextMessage }) onTextMessage = onGameTextMessage })

View File

@ -123,7 +123,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
end end
connect(Game, { onLogin = VipList.create, connect(Game, { onGameStart = VipList.create,
onLogout = VipList.destroy, onGameEnd = VipList.destroy,
onAddVip = VipList.onAddVip, onAddVip = VipList.onAddVip,
onVipStateChange = VipList.onVipStateChange }) onVipStateChange = VipList.onVipStateChange })

View File

@ -72,7 +72,7 @@ void Game::processConnectionError(const boost::system::error_code& error)
} }
} }
void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat) void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
{ {
m_localPlayer = localPlayer; m_localPlayer = localPlayer;
m_serverBeat = serverBeat; m_serverBeat = serverBeat;
@ -83,8 +83,16 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
m_safeFight = true; m_safeFight = true;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight); m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
// NOTE: the entire map description is not known yet // NOTE: the entire map description and local player informations is not known yet
g_lua.callGlobalField("Game", "onLogin", localPlayer); g_lua.callGlobalField("Game", "onGameStart");
}
void Game::processLogin()
{
if(!isOnline())
return;
g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
} }
void Game::processLogout() void Game::processLogout()
@ -93,6 +101,8 @@ void Game::processLogout()
g_lua.callGlobalField("Game", "onLogout", m_localPlayer); g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
m_localPlayer = nullptr; m_localPlayer = nullptr;
g_lua.callGlobalField("Game", "onGameEnd");
} }
if(m_protocolGame) { if(m_protocolGame) {

View File

@ -42,7 +42,8 @@ public:
void cleanLogout() { logout(false); } void cleanLogout() { logout(false); }
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, int serverBeat); void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
void processLogin();
void processLogout(); void processLogout();
void processDeath(); void processDeath();
void processPlayerStats(double health, double maxHealth, void processPlayerStats(double health, double maxHealth,

View File

@ -38,11 +38,11 @@ Tile::Tile(const Position& position)
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
{ {
m_drawElevation = 0;
bool animate = drawFlags & Otc::DrawAnimations; bool animate = drawFlags & Otc::DrawAnimations;
// first bottom items // first bottom items
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) { if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
m_drawElevation = 0;
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom()) if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
break; break;

View File

@ -106,7 +106,7 @@ private:
// Parse Messages // Parse Messages
void parseMessage(InputMessage& msg); void parseMessage(InputMessage& msg);
void parsePlayerLogin(InputMessage& msg); void parseInitGame(InputMessage& msg);
void parseGMActions(InputMessage& msg); void parseGMActions(InputMessage& msg);
void parseLoginError(InputMessage& msg); void parseLoginError(InputMessage& msg);
void parseFYIMessage(InputMessage& msg); void parseFYIMessage(InputMessage& msg);

View File

@ -41,7 +41,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
switch(opt) { switch(opt) {
case Proto::GameServerInitGame: case Proto::GameServerInitGame:
parsePlayerLogin(msg); parseInitGame(msg);
break; break;
case Proto::GameServerGMActions: case Proto::GameServerGMActions:
parseGMActions(msg); parseGMActions(msg);
@ -265,7 +265,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
} }
} }
void ProtocolGame::parsePlayerLogin(InputMessage& msg) void ProtocolGame::parseInitGame(InputMessage& msg)
{ {
uint playerId = msg.getU32(); uint playerId = msg.getU32();
int serverBeat = msg.getU16(); int serverBeat = msg.getU16();
@ -274,7 +274,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg)
m_localPlayer = LocalPlayerPtr(new LocalPlayer); m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setId(playerId); m_localPlayer->setId(playerId);
m_localPlayer->setCanReportBugs(playerCanReportBugs); m_localPlayer->setCanReportBugs(playerCanReportBugs);
g_game.processLogin(m_localPlayer, serverBeat); g_game.processGameStart(m_localPlayer, serverBeat);
} }
void ProtocolGame::parseGMActions(InputMessage& msg) void ProtocolGame::parseGMActions(InputMessage& msg)
@ -1110,8 +1110,10 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
creature->setPassable(passable); creature->setPassable(passable);
creature->setDirection(direction); creature->setDirection(direction);
// now that the local player is known, we can schedule login event
if(creature == m_localPlayer) { if(creature == m_localPlayer) {
m_localPlayer->setKnown(true); m_localPlayer->setKnown(true);
g_dispatcher.addEvent([] { g_game.processLogin(); });
} }
} }