Browse Source

Implement purse slot (closes #208), add version 10.37 (could not find protocol changes)

Sam 7 years ago
parent
commit
a58a3e90c8

BIN
data/images/game/slots/purse.png View File


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

@@ -14,6 +14,7 @@ InventorySlotStyles = {
14 14
 inventoryWindow = nil
15 15
 inventoryPanel = nil
16 16
 inventoryButton = nil
17
+purseButton = nil
17 18
 
18 19
 function init()
19 20
   connect(LocalPlayer, { onInventoryChange = onInventoryChange })
@@ -28,6 +29,16 @@ function init()
28 29
   inventoryWindow:disableResize()
29 30
   inventoryPanel = inventoryWindow:getChildById('contentsPanel')
30 31
 
32
+  purseButton = inventoryPanel:getChildById('purseButton')
33
+  local function purseFunction()
34
+    local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
35
+    if purse then
36
+      print(purse:getId())
37
+      g_game.use(purse)
38
+    end
39
+  end
40
+  purseButton.onClick = purseFunction
41
+
31 42
   refresh()
32 43
   inventoryWindow:setup()
33 44
 end
@@ -44,13 +55,15 @@ end
44 55
 
45 56
 function refresh()
46 57
   local player = g_game.getLocalPlayer()
47
-  for i=InventorySlotFirst,InventorySlotLast do
58
+  for i = InventorySlotFirst, InventorySlotPurse do
48 59
     if g_game.isOnline() then
49 60
       onInventoryChange(player, i, player:getInventoryItem(i))
50 61
     else
51 62
       onInventoryChange(player, i, nil)
52 63
     end
53 64
   end
65
+
66
+  purseButton:setVisible(g_game.getFeature(GamePurseSlot))
54 67
 end
55 68
 
56 69
 function toggle()
@@ -69,7 +82,15 @@ end
69 82
 
70 83
 -- hooked events
71 84
 function onInventoryChange(player, slot, item, oldItem)
72
-  if slot >= InventorySlotPurse then return end
85
+  if slot > InventorySlotPurse then return end
86
+
87
+  if slot == InventorySlotPurse then
88
+    if g_game.getFeature(GamePurseSlot) then
89
+      purseButton:setEnabled(item and true or false)
90
+    end
91
+    return
92
+  end
93
+
73 94
   local itemWidget = inventoryPanel:getChildById('slot' .. slot)
74 95
   if item then
75 96
     itemWidget:setStyle('Item')

+ 14
- 1
modules/game_inventory/inventory.otui View File

@@ -50,6 +50,14 @@ AmmoSlot < InventoryItem
50 50
   image-source: /images/game/slots/ammo
51 51
   &position: {x=65535, y=10, z=0}
52 52
 
53
+PurseButton < Button
54
+  id: purseButton
55
+  size: 26 26
56
+  !tooltip: tr('Open purse')
57
+  icon-source: /images/game/slots/purse
58
+  icon-size: 24 24
59
+  icon-offset: 1 1
60
+
53 61
 MiniWindow
54 62
   id: inventoryWindow
55 63
   !text: tr('Inventory')
@@ -109,4 +117,9 @@ MiniWindow
109 117
     AmmoSlot
110 118
       anchors.top: prev.bottom
111 119
       anchors.horizontalCenter: prev.horizontalCenter
112
-      margin-top: 3
120
+      margin-top: 3
121
+
122
+    PurseButton
123
+      margin-top: 3
124
+      anchors.top: prev.bottom
125
+      anchors.horizontalCenter: prev.horizontalCenter

+ 1
- 1
modules/gamelib/game.lua View File

@@ -54,7 +54,7 @@ function g_game.getSupportedClients()
54 54
     940, 944, 953, 954, 960, 961, 963,
55 55
     970, 980, 981, 982, 983, 984, 985,
56 56
     986, 1001, 1002, 1010, 1020, 1021,
57
-    1022, 1031, 1034, 1035, 1036
57
+    1022, 1031, 1034, 1035, 1036, 1037
58 58
   }
59 59
 end
60 60
 

+ 2
- 2
src/client/game.cpp View File

@@ -1459,7 +1459,7 @@ void Game::setProtocolVersion(int version)
1459 1459
     if(isOnline())
1460 1460
         stdext::throw_exception("Unable to change protocol version while online");
1461 1461
 
1462
-    if(version != 0 && (version < 760 || version > 1036))
1462
+    if(version != 0 && (version < 760 || version > 1037))
1463 1463
         stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
1464 1464
 
1465 1465
     m_features.reset();
@@ -1587,7 +1587,7 @@ void Game::setClientVersion(int version)
1587 1587
     if(isOnline())
1588 1588
         stdext::throw_exception("Unable to change client version while online");
1589 1589
 
1590
-    if(version != 0 && (version < 760 || version > 1036))
1590
+    if(version != 0 && (version < 760 || version > 1037))
1591 1591
         stdext::throw_exception(stdext::format("Client version %d not supported", version));
1592 1592
 
1593 1593
     m_clientVersion = version;

Loading…
Cancel
Save