Browse Source

fix dragqueen and containers

Henrique Santiago 9 years ago
parent
commit
bd63bde722

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

@@ -1,10 +1,10 @@
1 1
 function UIMap:onDragEnter(mousePos)
2
-  local tile = self:getTile(mousePosition)
2
+  local tile = self:getTile(mousePos)
3 3
   if not tile then return false end
4 4
   
5 5
   local thing = tile:getTopMoveThing()
6 6
   if not thing then return false end
7
-  
7
+
8 8
   self.currentDragThing = thing
9 9
   setTargetCursor()
10 10
   return true

+ 71
- 15
modules/game_containers/containers.lua View File

@@ -18,7 +18,7 @@ function Containers.getFreeContainerId()
18 18
 end
19 19
 
20 20
 -- hooked events
21
-function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent)
21
+function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent, items)
22 22
   local container = m_containers[containerId]
23 23
   if container then
24 24
     Game.gameRightPanel:removeChild(container)
@@ -35,22 +35,26 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
35 35
     -- parent button
36 36
   end
37 37
 
38
-  container.itemCount = 0
38
+  container.itemCount = #items
39 39
   container.capacity = capacity
40 40
 
41 41
   for i=1,capacity do
42
-    local item = UIItem.create()
43
-    item:setStyle('Item')
44
-    container:addChild(item)
45
-    item.position = {x=65535, y=containerId+64, z=i-1}
42
+    local itemWidget = UIItem.create()
43
+    itemWidget:setStyle('Item')
44
+    container:addChild(itemWidget)
45
+    itemWidget.position = {x=65535, y=containerId+64, z=i-1}
46
+    
47
+    if i <= #items then
48
+      local item = items[i]
49
+      item:setPos(itemWidget.position)
50
+      itemWidget:setItem(item)
51
+    end
46 52
   end
47 53
 
48 54
   m_containers[containerId] = container
49
-  print("opencid ".. containerId)
50 55
 end
51 56
 
52 57
 function Containers.onContainerClose(containerId)
53
-  print("closecid ".. containerId)
54 58
   local container = m_containers[containerId]
55 59
   if container then
56 60
     Game.gameRightPanel:removeChild(container)
@@ -59,23 +63,75 @@ function Containers.onContainerClose(containerId)
59 63
 end
60 64
 
61 65
 function Containers.onContainerAddItem(containerId, item)
62
-  print("addcid ".. containerId)
63 66
   local container = m_containers[containerId]
64 67
   if not container or not item or container.itemCount >= container.capacity then return end
65 68
 
66
-  -- maybe this has to be moved to client internal's files
67
-  local pos = item:getPos()
68
-  pos.z = container.itemCount
69
-  item:setPos(pos)
69
+  local i = container.itemCount
70
+  while i >= 1 do
71
+    local itemWidget = container:getChildByIndex(i)
72
+    if not itemWidget then return end
73
+    
74
+    local nextItemWidget = container:getChildByIndex(i+1)
75
+    if not nextItemWidget then return end
76
+
77
+    local swapItem = itemWidget:getItem()
78
+    if swapItem then
79
+      swapItem:setPos(nextItemWidget.position)
80
+      nextItemWidget:setItem(swapItem)
81
+    end
82
+    
83
+    i = i - 1
84
+  end
70 85
 
71
-  local itemWidget = container:getChildByIndex(container.itemCount + 1)
86
+  local itemWidget = container:getChildByIndex(1)
87
+  if not itemWidget then return end
88
+  item:setPos(itemWidget.position)
72 89
   itemWidget:setItem(item)
90
+
73 91
   container.itemCount = container.itemCount + 1
92
+end
74 93
 
94
+function Containers.onContainerUpdateItem(containerId, slot, item)
95
+  local container = m_containers[containerId]
96
+  if not container then return end
97
+  
98
+  local itemWidget = container:getChildByIndex(slot + 1)
99
+  if not itemWidget then return end
100
+  itemWidget:setItem(item)
101
+end
102
+
103
+function Containers.onContainerRemoveItem(containerId, slot)
104
+  local container = m_containers[containerId]
105
+  if not container then return end
106
+  
107
+  local itemWidget = container:getChildByIndex(slot+1)
108
+  if not itemWidget then return end
109
+  itemWidget:setItem(nil)
110
+  
111
+  for i=slot,container.itemCount-2 do
112
+    local itemWidget = container:getChildByIndex(i+1)
113
+    if not itemWidget then return end
114
+    
115
+    local nextItemWidget = container:getChildByIndex(i+2)
116
+    if not nextItemWidget then return end
117
+    
118
+    local item = nextItemWidget:getItem()
119
+    local pos = item:getPos()
120
+    pos.z = pos.z - 1
121
+    item:setPos(pos)
122
+    
123
+    itemWidget:setItem(item)
124
+    nextItemWidget:setItem(nil)
125
+  end
126
+  
127
+  container.itemCount = container.itemCount - 1
75 128
 end
76 129
 
77 130
 connect(Game, { onLogin = Containers.clean,
78 131
                 onLogout = Containers.clean,
79 132
                 onContainerOpen = Containers.onContainerOpen,
80 133
                 onContainerClose = Containers.onContainerClose,
81
-                onContainerAddItem = Containers.onContainerAddItem })
134
+                onContainerAddItem = Containers.onContainerAddItem,
135
+                onContainerUpdateItem = Containers.onContainerUpdateItem,
136
+                onContainerRemoveItem = Containers.onContainerRemoveItem })
137
+                

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

@@ -77,6 +77,7 @@ UIWindow
77 77
     anchors.top: prev.bottom
78 78
     anchors.horizontalCenter: prev.horizontalCenter
79 79
     margin-top: 5
80
+    &position: {x=65535, y=5, z=0}
80 81
 
81 82
   Item
82 83
     // ammo

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

@@ -198,6 +198,7 @@ void OTClient::registerLuaFunctions()
198 198
     g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));
199 199
     g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
200 200
     g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
201
+    g_lua.bindClassStaticFunction<Game>("move", std::bind(&Game::move, &g_game, _1, _2, _3));
201 202
     g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1, _2));
202 203
     g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
203 204
     g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));

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

@@ -435,12 +435,14 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
435 435
     bool hasParent = (msg.getU8() != 0);
436 436
     int itemCount = msg.getU8();
437 437
 
438
-    g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent);
439
-
438
+    std::vector<ItemPtr> items;
439
+    items.reserve(itemCount);
440 440
     for(int i = 0; i < itemCount; i++) {
441 441
         ItemPtr item = internalGetItem(msg);
442
-        g_game.processContainerAddItem(containerId, item);
442
+        items.push_back(item);
443 443
     }
444
+
445
+    g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items);
444 446
 }
445 447
 
446 448
 void ProtocolGame::parseCloseContainer(InputMessage& msg)

+ 5
- 0
src/otclient/ui/uimap.cpp View File

@@ -27,6 +27,11 @@
27 27
 #include <framework/graphics/graphics.h>
28 28
 #include <otclient/core/localplayer.h>
29 29
 
30
+UIMap::UIMap()
31
+{
32
+    m_dragable = true;
33
+}
34
+
30 35
 void UIMap::draw()
31 36
 {
32 37
     drawSelf();

+ 1
- 0
src/otclient/ui/uimap.h View File

@@ -30,6 +30,7 @@
30 30
 class UIMap : public UIWidget
31 31
 {
32 32
 public:
33
+    UIMap();
33 34
     void draw();
34 35
 
35 36
     Position getPosition(const Point& mousePos);

Loading…
Cancel
Save