Browse Source

add onGameStart/onGameEnd/onLogin/onLogout events

Eduardo Bart 9 years ago
parent
commit
09b3aa82df

+ 4
- 4
modules/client_topmenu/topmenu.lua View File

@@ -25,8 +25,8 @@ function TopMenu.init()
25 25
   TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
26 26
   Keyboard.bindKeyDown('Ctrl+Q', onLogout)
27 27
 
28
-  connect(Game, { onLogin = TopMenu.showGameButtons,
29
-                  onLogout = TopMenu.hideGameButtons })
28
+  connect(Game, { onGameStart = TopMenu.showGameButtons,
29
+                  onGameEnd = TopMenu.hideGameButtons })
30 30
 end
31 31
 
32 32
 function TopMenu.terminate()
@@ -37,8 +37,8 @@ function TopMenu.terminate()
37 37
   topMenu:destroy()
38 38
   topMenu = nil
39 39
 
40
-  disconnect(Game, { onLogin = TopMenu.showGameButtons,
41
-                     onLogout = TopMenu.hideGameButtons })
40
+  disconnect(Game, { onGameStart = TopMenu.showGameButtons,
41
+                     onGameEnd = TopMenu.hideGameButtons })
42 42
 
43 43
   TopMenu = nil
44 44
 end

+ 2
- 2
modules/game/game.lua View File

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

+ 4
- 4
modules/game_combatcontrols/combatcontrols.lua View File

@@ -66,8 +66,8 @@ function CombatControls.init()
66 66
   connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
67 67
   connect(chaseModeButton, { onCheckChange = onChaseModeChange })
68 68
   connect(safeFightButton, { onCheckChange = onSafeFightChange })
69
-  connect(Game, { onLogin = CombatControls.online })
70
-  connect(Game, { onLogout = CombatControls.offline })
69
+  connect(Game, { onGameStart = CombatControls.online })
70
+  connect(Game, { onGameEnd = CombatControls.offline })
71 71
 
72 72
   if Game.isOnline() then
73 73
     CombatControls.online()
@@ -94,8 +94,8 @@ function CombatControls.terminate()
94 94
   combatControlsWindow:destroy()
95 95
   combatControlsWindow = nil
96 96
 
97
-  disconnect(Game, { onLogin = CombatControls.online })
98
-  disconnect(Game, { onLogout = CombatControls.offline })
97
+  disconnect(Game, { onGameStart = CombatControls.online })
98
+  disconnect(Game, { onGameEnd = CombatControls.offline })
99 99
 
100 100
   CombatControls = nil
101 101
 end

+ 2
- 2
modules/game_console/console.lua View File

@@ -365,8 +365,8 @@ local function onChannelList(channelList)
365 365
   end
366 366
 end
367 367
 
368
-connect(Game, { onLogin = Console.create,
369
-                onLogout = Console.destroy,
368
+connect(Game, { onGameStart = Console.create,
369
+                onGameEnd = Console.destroy,
370 370
                 onCreatureSpeak = onCreatureSpeak,
371 371
                 onChannelList = onChannelList,
372 372
                 onOpenChannel = onOpenChannel,

+ 13
- 13
modules/game_containers/containers.lua View File

@@ -43,7 +43,7 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
43 43
     itemWidget:setStyle('Item')
44 44
     container:addChild(itemWidget)
45 45
     itemWidget.position = {x=65535, y=containerId+64, z=i-1}
46
-    
46
+
47 47
     if i <= #items then
48 48
       local item = items[i]
49 49
       item:setPosition(itemWidget.position)
@@ -70,7 +70,7 @@ function Containers.onContainerAddItem(containerId, item)
70 70
   while i >= 1 do
71 71
     local itemWidget = container:getChildByIndex(i)
72 72
     if not itemWidget then return end
73
-    
73
+
74 74
     local nextItemWidget = container:getChildByIndex(i+1)
75 75
     if not nextItemWidget then return end
76 76
 
@@ -79,7 +79,7 @@ function Containers.onContainerAddItem(containerId, item)
79 79
       swapItem:setPosition(nextItemWidget.position)
80 80
       nextItemWidget:setItem(swapItem)
81 81
     end
82
-    
82
+
83 83
     i = i - 1
84 84
   end
85 85
 
@@ -94,7 +94,7 @@ end
94 94
 function Containers.onContainerUpdateItem(containerId, slot, item)
95 95
   local container = m_containers[containerId]
96 96
   if not container then return end
97
-  
97
+
98 98
   local itemWidget = container:getChildByIndex(slot + 1)
99 99
   if not itemWidget then return end
100 100
   itemWidget:setItem(item)
@@ -104,35 +104,35 @@ end
104 104
 function Containers.onContainerRemoveItem(containerId, slot)
105 105
   local container = m_containers[containerId]
106 106
   if not container then return end
107
-  
107
+
108 108
   local itemWidget = container:getChildByIndex(slot+1)
109 109
   if not itemWidget then return end
110 110
   itemWidget:setItem(nil)
111
-  
111
+
112 112
   for i=slot,container.itemCount-2 do
113 113
     local itemWidget = container:getChildByIndex(i+1)
114 114
     if not itemWidget then return end
115
-    
115
+
116 116
     local nextItemWidget = container:getChildByIndex(i+2)
117 117
     if not nextItemWidget then return end
118
-    
118
+
119 119
     local item = nextItemWidget:getItem()
120 120
     local pos = item:getPosition()
121 121
     pos.z = pos.z - 1
122 122
     item:setPosition(pos)
123
-    
123
+
124 124
     itemWidget:setItem(item)
125 125
     nextItemWidget:setItem(nil)
126 126
   end
127
-  
127
+
128 128
   container.itemCount = container.itemCount - 1
129 129
 end
130 130
 
131
-connect(Game, { onLogin = Containers.clean,
132
-                onLogout = Containers.clean,
131
+connect(Game, { onGameStart = Containers.clean,
132
+                onGameEnd = Containers.clean,
133 133
                 onContainerOpen = Containers.onContainerOpen,
134 134
                 onContainerClose = Containers.onContainerClose,
135 135
                 onContainerAddItem = Containers.onContainerAddItem,
136 136
                 onContainerUpdateItem = Containers.onContainerUpdateItem,
137 137
                 onContainerRemoveItem = Containers.onContainerRemoveItem })
138
-                
138
+

+ 2
- 2
modules/game_healthbar/healthbar.lua View File

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

+ 2
- 2
modules/game_inventory/inventory.lua View File

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

+ 1
- 1
modules/game_outfit/outfit.lua View File

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

+ 2
- 2
modules/game_skills/skills.lua View File

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

+ 2
- 2
modules/game_textmessage/textmessage.lua View File

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

+ 3
- 3
modules/game_viplist/viplist.lua View File

@@ -57,7 +57,7 @@ function VipList.onAddVip(id, name, online)
57 57
 
58 58
   label:setPhantom(false)
59 59
   connect(label, { onDoubleClick = function () Game.openPrivateChannel(label:getText()) return true end } )
60
-  
60
+
61 61
   local nameLower = name:lower()
62 62
   local childrenCount = vipList:getChildCount()
63 63
 
@@ -123,7 +123,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
123 123
 end
124 124
 
125 125
 
126
-connect(Game, { onLogin = VipList.create,
127
-                onLogout = VipList.destroy,
126
+connect(Game, { onGameStart = VipList.create,
127
+                onGameEnd = VipList.destroy,
128 128
                 onAddVip = VipList.onAddVip,
129 129
                 onVipStateChange = VipList.onVipStateChange })

+ 13
- 3
src/otclient/core/game.cpp View File

@@ -72,7 +72,7 @@ void Game::processConnectionError(const boost::system::error_code& error)
72 72
     }
73 73
 }
74 74
 
75
-void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
75
+void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
76 76
 {
77 77
     m_localPlayer = localPlayer;
78 78
     m_serverBeat = serverBeat;
@@ -83,8 +83,16 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
83 83
     m_safeFight = true;
84 84
     m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
85 85
 
86
-    // NOTE: the entire map description is not known yet
87
-    g_lua.callGlobalField("Game", "onLogin", localPlayer);
86
+    // NOTE: the entire map description and local player informations is not known yet
87
+    g_lua.callGlobalField("Game", "onGameStart");
88
+}
89
+
90
+void Game::processLogin()
91
+{
92
+    if(!isOnline())
93
+        return;
94
+
95
+    g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
88 96
 }
89 97
 
90 98
 void Game::processLogout()
@@ -93,6 +101,8 @@ void Game::processLogout()
93 101
         g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
94 102
 
95 103
         m_localPlayer = nullptr;
104
+
105
+        g_lua.callGlobalField("Game", "onGameEnd");
96 106
     }
97 107
 
98 108
     if(m_protocolGame) {

+ 2
- 1
src/otclient/core/game.h View File

@@ -42,7 +42,8 @@ public:
42 42
     void cleanLogout() { logout(false); }
43 43
     void processLoginError(const std::string& error);
44 44
     void processConnectionError(const boost::system::error_code& error);
45
-    void processLogin(const LocalPlayerPtr& localPlayer, int serverBeat);
45
+    void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
46
+    void processLogin();
46 47
     void processLogout();
47 48
     void processDeath();
48 49
     void processPlayerStats(double health, double maxHealth,

+ 1
- 1
src/otclient/core/tile.cpp View File

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

+ 1
- 1
src/otclient/net/protocolgame.h View File

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

+ 5
- 3
src/otclient/net/protocolgameparse.cpp View File

@@ -41,7 +41,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
41 41
 
42 42
             switch(opt) {
43 43
             case Proto::GameServerInitGame:
44
-                parsePlayerLogin(msg);
44
+                parseInitGame(msg);
45 45
                 break;
46 46
             case Proto::GameServerGMActions:
47 47
                 parseGMActions(msg);
@@ -265,7 +265,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
265 265
     }
266 266
 }
267 267
 
268
-void ProtocolGame::parsePlayerLogin(InputMessage& msg)
268
+void ProtocolGame::parseInitGame(InputMessage& msg)
269 269
 {
270 270
     uint playerId = msg.getU32();
271 271
     int serverBeat = msg.getU16();
@@ -274,7 +274,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg)
274 274
     m_localPlayer = LocalPlayerPtr(new LocalPlayer);
275 275
     m_localPlayer->setId(playerId);
276 276
     m_localPlayer->setCanReportBugs(playerCanReportBugs);
277
-    g_game.processLogin(m_localPlayer, serverBeat);
277
+    g_game.processGameStart(m_localPlayer, serverBeat);
278 278
 }
279 279
 
280 280
 void ProtocolGame::parseGMActions(InputMessage& msg)
@@ -1110,8 +1110,10 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
1110 1110
             creature->setPassable(passable);
1111 1111
             creature->setDirection(direction);
1112 1112
 
1113
+            // now that the local player is known, we can schedule login event
1113 1114
             if(creature == m_localPlayer) {
1114 1115
                 m_localPlayer->setKnown(true);
1116
+                g_dispatcher.addEvent([] { g_game.processLogin(); });
1115 1117
             }
1116 1118
         }
1117 1119
 

Loading…
Cancel
Save