Browse Source

finally reloadable vip, skills, inventory, chat and minimap

Eduardo Bart 8 years ago
parent
commit
ceb051cb75

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

@@ -113,7 +113,7 @@ end
113 113
 local function onOpenPrivateChannel(receiver)
114 114
   local privateTab = Console.getTab(receiver)
115 115
   if privateTab == nil then
116
-    Console.addTab(receiver)
116
+    Console.addTab(receiver, true)
117 117
   end
118 118
 end
119 119
 

+ 18
- 23
modules/game_inventory/inventory.lua View File

@@ -7,10 +7,9 @@ local inventoryButton
7 7
 
8 8
 -- public functions
9 9
 function Inventory.init()
10
-  connect(g_game, { onGameEnd = Inventory.clear,
11
-                    onInventoryChange = Inventory.onInventoryChange,
12
-                    onFreeCapacityChange = Inventory.onFreeCapacityChange,
13
-                    onSoulChange = Inventory.onSoulChange })
10
+  connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
11
+                         onFreeCapacityChange = Inventory.onFreeCapacityChange })
12
+  connect(g_game, { onGameEnd = Inventory.clear })
14 13
 
15 14
   Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
16 15
 
@@ -20,16 +19,13 @@ function Inventory.init()
20 19
   inventoryButton = TopMenu.addGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', Inventory.toggle)
21 20
   inventoryButton:setOn(true)
22 21
 
23
-  if g_game.isOnline() then
24
-    Inventory.reload()
25
-  end
22
+  Inventory.refresh()
26 23
 end
27 24
 
28 25
 function Inventory.terminate()
29
-  connect(g_game, { onGameEnd = Inventory.clear,
30
-                    onInventoryChange = Inventory.onInventoryChange,
31
-                    onFreeCapacityChange = Inventory.onFreeCapacityChange,
32
-                    onSoulChange = Inventory.onSoulChange })
26
+  disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
27
+                         onFreeCapacityChange = Inventory.onFreeCapacityChange })
28
+  disconnect(g_game, { onGameEnd = Inventory.clear })
33 29
 
34 30
   Keyboard.unbindKeyDown('Ctrl+I')
35 31
 
@@ -42,30 +38,29 @@ function Inventory.terminate()
42 38
   Inventory = nil
43 39
 end
44 40
 
41
+function Inventory.refresh()
42
+  local player = g_game.getLocalPlayer()
43
+  if not player then return end
44
+
45
+  for i=1,10 do
46
+    Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
47
+  end
48
+end
49
+
45 50
 function Inventory.toggle()
46 51
   local visible = not inventoryWindow:isExplicitlyVisible()
47 52
   inventoryWindow:setVisible(visible)
48 53
   inventoryButton:setOn(visible)
49 54
 end
50 55
 
51
-function Inventory.clear()
52
-end
53
-
54
-function Inventory.reload()
55
-end
56
-
57 56
 -- hooked events
58
-function Inventory.onInventoryChange(slot, item)
57
+function Inventory.onInventoryChange(player, slot, item)
59 58
   local itemWidget = inventoryPanel:getChildById('slot' .. slot)
60 59
   itemWidget:setItem(item)
61 60
 end
62 61
 
63
-function Inventory.onFreeCapacityChange(freeCapacity)
62
+function Inventory.onFreeCapacityChange(player, freeCapacity)
64 63
   local widget = inventoryPanel:getChildById('capacity')
65 64
   widget:setText("Cap:\n" .. freeCapacity)
66 65
 end
67 66
 
68
-function Inventory.onSoulChange(soul)
69
-  local widget = inventoryPanel:getChildById('soul')
70
-  widget:setText("Soul:\n" .. soul)
71
-end

+ 7
- 2
modules/game_minimap/minimap.lua View File

@@ -3,6 +3,7 @@ Minimap = {}
3 3
 -- private variables
4 4
 local minimapWidget
5 5
 local minimapButton
6
+local DEFAULT_ZOOM = 45
6 7
 
7 8
 -- private functions
8 9
 function onMinimapMouseRelease(self, mousePosition, mouseButton)
@@ -40,6 +41,8 @@ function Minimap.init()
40 41
   minimapWidget.onMouseRelease = onMinimapMouseRelease
41 42
   minimapWidget.onMouseWheel = onMinimapMouseWheel
42 43
   minimapWidget:hide()
44
+
45
+  Minimap.reset()
43 46
 end
44 47
 
45 48
 function Minimap.terminate()
@@ -61,7 +64,9 @@ function Minimap.toggle()
61 64
 end
62 65
 
63 66
 function Minimap.reset()
64
-  minimapWidget:followCreature(g_game.getLocalPlayer())
65
-  for i=1,10 do minimapWidget:zoomOut() end
67
+  local player = g_game.getLocalPlayer()
68
+  if not player then return end
69
+  minimapWidget:followCreature(player)
70
+  minimapWidget:setZoom(DEFAULT_ZOOM)
66 71
 end
67 72
 

+ 20
- 0
modules/game_skills/skills.lua View File

@@ -39,6 +39,8 @@ function Skills.init()
39 39
   skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle)
40 40
   skillsButton:setOn(true)
41 41
   Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
42
+
43
+  Skills.refresh()
42 44
 end
43 45
 
44 46
 function Skills.terminate()
@@ -63,6 +65,24 @@ function Skills.terminate()
63 65
   Skills = nil
64 66
 end
65 67
 
68
+function Skills.refresh()
69
+  local player = g_game.getLocalPlayer()
70
+  if not player then return end
71
+
72
+  Skills.onExperienceChange(player, player:getExperience())
73
+  Skills.onLevelChange(player, player:getLevel(), player:getLevelPercent())
74
+  Skills.onHealthChange(player, player:getHealth(), player:getMaxHealth())
75
+  Skills.onManaChange(player, player:getMana(), player:getMaxMana())
76
+  Skills.onSoulChange(player, player:getSoul())
77
+  Skills.onFreeCapacityChange(player, player:getFreeCapacity())
78
+  Skills.onStaminaChange(player, player:getStamina())
79
+  Skills.onMagicLevelChange(player, player:getMagicLevel(), player:getMagicLevelPercent())
80
+
81
+  for i=0,6 do
82
+    Skills.onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i))
83
+  end
84
+end
85
+
66 86
 function Skills.toggle()
67 87
   local visible = not skillsWindow:isExplicitlyVisible()
68 88
   skillsWindow:setVisible(visible)

+ 9
- 0
modules/game_viplist/viplist.lua View File

@@ -15,6 +15,8 @@ function VipList.init()
15 15
   vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
16 16
   vipButton = TopMenu.addGameToggleButton('vipListButton', tr('VIP list'), 'viplist.png', VipList.toggle)
17 17
   vipButton:setOn(true)
18
+
19
+  VipList.refresh()
18 20
 end
19 21
 
20 22
 function VipList.terminate()
@@ -30,6 +32,13 @@ function VipList.terminate()
30 32
   VipList = nil
31 33
 end
32 34
 
35
+function VipList.refresh()
36
+  VipList.clear()
37
+  for id,vip in pairs(g_game.getVips()) do
38
+    VipList.onAddVip(id, unpack(vip))
39
+  end
40
+end
41
+
33 42
 function VipList.clear()
34 43
   local vipList = vipWindow:getChildById('contentsPanel')
35 44
   vipList:destroyChildren()

+ 15
- 0
src/otclient/const.h View File

@@ -154,6 +154,21 @@ namespace Otc
154 154
         LastSkill
155 155
     };
156 156
 
157
+    enum Inventory {
158
+        NoInventory = 0,
159
+        Head,
160
+        Neck,
161
+        Bag,
162
+        Armor,
163
+        RightHand,
164
+        LeftHand,
165
+        Legs,
166
+        Feet,
167
+        Ring,
168
+        Ammo,
169
+        LastInventory
170
+    };
171
+
157 172
     enum Direction {
158 173
         North = 0,
159 174
         East,

+ 4
- 1
src/otclient/core/game.cpp View File

@@ -55,6 +55,7 @@ void Game::resetGameStates()
55 55
             container->close();
56 56
     }
57 57
     m_containers.clear();
58
+    m_vips.clear();
58 59
 
59 60
     m_worldName = "";
60 61
 }
@@ -241,7 +242,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
241 242
     if(item)
242 243
         item->setPosition(Position(65535, slot, 0));
243 244
 
244
-    g_lua.callGlobalField("g_game","onInventoryChange", slot, item);
245
+    m_localPlayer->setInventoryItem((Otc::Inventory)slot, item);
245 246
 }
246 247
 
247 248
 void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
@@ -288,11 +289,13 @@ void Game::processCloseChannel(int channelId)
288 289
 
289 290
 void Game::processVipAdd(uint id, const std::string& name, bool online)
290 291
 {
292
+    m_vips[id] = Vip(name, online);
291 293
     g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
292 294
 }
293 295
 
294 296
 void Game::processVipStateChange(uint id, bool online)
295 297
 {
298
+    std::get<1>(m_vips[id]) = online;
296 299
     g_lua.callGlobalField("g_game", "onVipStateChange", id, online);
297 300
 }
298 301
 

+ 5
- 0
src/otclient/core/game.h View File

@@ -29,6 +29,8 @@
29 29
 #include <otclient/core/outfit.h>
30 30
 #include <framework/core/timer.h>
31 31
 
32
+typedef std::tuple<std::string, bool> Vip;
33
+
32 34
 class Game
33 35
 {
34 36
 public:
@@ -221,6 +223,7 @@ public:
221 223
 
222 224
     ContainerPtr getContainer(int index) { return m_containers[index]; }
223 225
     std::map<int, ContainerPtr> getContainers() { return m_containers; }
226
+    std::map<int, Vip> getVips() { return m_vips; }
224 227
     CreaturePtr getAttackingCreature() { return m_attackingCreature; }
225 228
     CreaturePtr getFollowingCreature() { return m_followingCreature; }
226 229
     int getServerBeat() { return m_serverBeat; }
@@ -238,6 +241,8 @@ private:
238 241
     CreaturePtr m_followingCreature;
239 242
     ProtocolGamePtr m_protocolGame;
240 243
     std::map<int, ContainerPtr> m_containers;
244
+    std::map<int, Vip> m_vips;
245
+
241 246
     bool m_dead;
242 247
     int m_serverBeat;
243 248
     Otc::FightModes m_fightMode;

+ 10
- 0
src/otclient/core/localplayer.cpp View File

@@ -284,3 +284,13 @@ void LocalPlayer::setStamina(double stamina)
284 284
         callLuaField("onStaminaChange", stamina, oldStamina);
285 285
     }
286 286
 }
287
+
288
+void LocalPlayer::setInventoryItem(Otc::Inventory inventory, const ItemPtr& item)
289
+{
290
+    if(m_inventoryItems[inventory] != item) {
291
+        ItemPtr oldItem = m_inventoryItems[inventory];
292
+        m_inventoryItems[inventory] = item;
293
+
294
+        callLuaField("onInventoryChange", inventory, item, oldItem);
295
+    }
296
+}

+ 3
- 0
src/otclient/core/localplayer.h View File

@@ -50,6 +50,7 @@ public:
50 50
     void setSoul(double soul);
51 51
     void setStamina(double stamina);
52 52
     void setKnown(bool known) { m_known = known; }
53
+    void setInventoryItem(Otc::Inventory inventory, const ItemPtr& item);
53 54
 
54 55
     int getStates() { return m_states; }
55 56
     int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
@@ -66,6 +67,7 @@ public:
66 67
     double getMagicLevelPercent() { return m_magicLevelPercent; }
67 68
     double getSoul() { return m_soul; }
68 69
     double getStamina() { return m_stamina; }
70
+    ItemPtr getInventoryItem(Otc::Inventory inventory) { return m_inventoryItems[inventory]; }
69 71
 
70 72
     bool isKnown() { return m_known; }
71 73
     bool isPreWalking() { return m_preWalking; }
@@ -92,6 +94,7 @@ private:
92 94
     bool m_walkLocked;
93 95
     Position m_lastPrewalkDestionation;
94 96
     Timer m_walkLockTimer;
97
+    ItemPtr m_inventoryItems[Otc::LastInventory];
95 98
 
96 99
     std::array<int, Otc::LastSkill> m_skillsLevel;
97 100
     std::array<int, Otc::LastSkill> m_skillsLevelPercent;

+ 3
- 0
src/otclient/luafunctions.cpp View File

@@ -151,6 +151,7 @@ void OTClient::registerLuaFunctions()
151 151
     g_lua.bindClassStaticFunction("g_game", "isFollowing", std::bind(&Game::isFollowing, &g_game));
152 152
     g_lua.bindClassStaticFunction("g_game", "getContainer", std::bind(&Game::getContainer, &g_game, std::placeholders::_1));
153 153
     g_lua.bindClassStaticFunction("g_game", "getContainers", std::bind(&Game::getContainers, &g_game));
154
+    g_lua.bindClassStaticFunction("g_game", "getVips", std::bind(&Game::getVips, &g_game));
154 155
     g_lua.bindClassStaticFunction("g_game", "getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
155 156
     g_lua.bindClassStaticFunction("g_game", "getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
156 157
     g_lua.bindClassStaticFunction("g_game", "getServerBeat", std::bind(&Game::getServerBeat, &g_game));
@@ -272,6 +273,7 @@ void OTClient::registerLuaFunctions()
272 273
     g_lua.bindClassMemberFunction<LocalPlayer>("setSoul", &LocalPlayer::setSoul);
273 274
     g_lua.bindClassMemberFunction<LocalPlayer>("setStamina", &LocalPlayer::setStamina);
274 275
     g_lua.bindClassMemberFunction<LocalPlayer>("setKnown", &LocalPlayer::setKnown);
276
+    g_lua.bindClassMemberFunction<LocalPlayer>("setInventoryItem", &LocalPlayer::setInventoryItem);
275 277
     g_lua.bindClassMemberFunction<LocalPlayer>("getStates", &LocalPlayer::getStates);
276 278
     g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevel", &LocalPlayer::getSkillLevel);
277 279
     g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevelPercent", &LocalPlayer::getSkillLevelPercent);
@@ -287,6 +289,7 @@ void OTClient::registerLuaFunctions()
287 289
     g_lua.bindClassMemberFunction<LocalPlayer>("getMagicLevelPercent", &LocalPlayer::getMagicLevelPercent);
288 290
     g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul);
289 291
     g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina);
292
+    g_lua.bindClassMemberFunction<LocalPlayer>("getInventoryItem", &LocalPlayer::getInventoryItem);
290 293
     g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
291 294
     g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
292 295
     g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer);

+ 3
- 1
src/otclient/ui/uimap.cpp View File

@@ -36,6 +36,7 @@ UIMap::UIMap()
36 36
     m_aspectRatio = 0.0f;
37 37
     m_maxZoomIn = 3;
38 38
     m_maxZoomOut = 512;
39
+    m_mapRect.resize(1,1);
39 40
     g_map.addMapView(m_mapView);
40 41
 }
41 42
 
@@ -58,7 +59,8 @@ void UIMap::drawSelf()
58 59
 
59 60
 bool UIMap::setZoom(int zoom)
60 61
 {
61
-    //TODO
62
+    m_zoom = std::min(std::max(zoom, m_maxZoomIn), m_maxZoomOut);
63
+    updateVisibleDimension();
62 64
     return false;
63 65
 }
64 66
 

Loading…
Cancel
Save