Browse Source

init move items

Henrique Santiago 9 years ago
parent
commit
733039e50e

+ 26
- 0
modules/core_widgets/uiitem.lua View File

@@ -1,3 +1,29 @@
1
+function UIItem:onDragEnter(mousePos)
2
+  local item = self:getItem()
3
+  if not item then return false end
4
+  
5
+  self.currentDragThing = item
6
+  setTargetCursor()
7
+  return true
8
+end
9
+
10
+function UIItem:onDragLeave(widget, mousePos)
11
+  self.currentDragThing = nil
12
+  restoreCursor()
13
+  return true
14
+end
15
+
16
+function UIItem:onDrop(widget, mousePos)
17
+  if not widget or not widget.currentDragThing then return false end
18
+  
19
+  local pos = self.position
20
+  local count = 1 -- todo make a window for it
21
+  
22
+  Game.move(widget.currentDragThing, pos, count)
23
+  return true
24
+end
25
+
26
+
1 27
 function UIItem:onMouseRelease(mousePosition, mouseButton)
2 28
   local item = self:getItem()
3 29
   if not item or not self:containsPoint(mousePosition) then return false end

+ 29
- 0
modules/game/map.lua View File

@@ -1,5 +1,34 @@
1
+function UIMap:onDragEnter(mousePos)
2
+  local tile = self:getTile(mousePosition)
3
+  if not tile then return false end
4
+  
5
+  local thing = tile:getTopMoveThing()
6
+  if not thing then return false end
7
+  
8
+  self.currentDragThing = thing
9
+  setTargetCursor()
10
+  return true
11
+end
12
+
13
+function UIMap:onDragLeave(widget, mousePos)
14
+  self.currentDragThing = nil
15
+  restoreCursor()
16
+  return true
17
+end
18
+
19
+function UIMap:onDrop(widget, mousePos)
20
+  if not widget or not widget.currentDragThing then return false end
21
+  
22
+  local pos = self:getPosition(mousePos)
23
+  local count = 1 -- todo make a window for it
24
+  
25
+  Game.move(widget.currentDragThing, pos, count)
26
+  return true
27
+end
28
+
1 29
 function UIMap:onMouseRelease(mousePosition, mouseButton)
2 30
   local tile = self:getTile(mousePosition)
3 31
   if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
4 32
   return false
5 33
 end
34
+

+ 1
- 0
modules/game_containers/containers.lua View File

@@ -42,6 +42,7 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
42 42
     local item = UIItem.create()
43 43
     item:setStyle('Item')
44 44
     container:addChild(item)
45
+    item.position = {x=65535, y=containerId+64, z=i-1}
45 46
   end
46 47
 
47 48
   m_containers[containerId] = container

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

@@ -11,6 +11,7 @@ UIWindow
11 11
     id: slot1
12 12
     anchors.top: parent.top
13 13
     anchors.horizontalCenter: parent.horizontalCenter
14
+    &position: {x=65535, y=1, z=0}
14 15
 
15 16
   Item
16 17
     // armor
@@ -18,6 +19,7 @@ UIWindow
18 19
     anchors.top: prev.bottom
19 20
     anchors.horizontalCenter: prev.horizontalCenter
20 21
     margin-top: 5
22
+    &position: {x=65535, y=4, z=0}
21 23
 
22 24
   Item
23 25
     // legs
@@ -25,6 +27,7 @@ UIWindow
25 27
     anchors.top: prev.bottom
26 28
     anchors.horizontalCenter: prev.horizontalCenter
27 29
     margin-top: 5
30
+    &position: {x=65535, y=7, z=0}
28 31
 
29 32
   Item
30 33
     // feet
@@ -32,6 +35,7 @@ UIWindow
32 35
     anchors.top: prev.bottom
33 36
     anchors.horizontalCenter: prev.horizontalCenter
34 37
     margin-top: 5
38
+    &position: {x=65535, y=8, z=0}
35 39
 
36 40
   Item
37 41
     // necklace
@@ -40,6 +44,7 @@ UIWindow
40 44
     anchors.right: slot1.left
41 45
     margin-top: 10
42 46
     margin-right: 5
47
+    &position: {x=65535, y=2, z=0}
43 48
 
44 49
   Item
45 50
     // left
@@ -47,6 +52,7 @@ UIWindow
47 52
     anchors.top: prev.bottom
48 53
     anchors.horizontalCenter: prev.horizontalCenter
49 54
     margin-top: 5
55
+    &position: {x=65535, y=6, z=0}
50 56
 
51 57
   Item
52 58
     // ring
@@ -54,6 +60,7 @@ UIWindow
54 60
     anchors.top: prev.bottom
55 61
     anchors.horizontalCenter: prev.horizontalCenter
56 62
     margin-top: 5
63
+    &position: {x=65535, y=9, z=0}
57 64
 
58 65
   Item
59 66
     // backpack
@@ -62,6 +69,7 @@ UIWindow
62 69
     anchors.left: slot1.right
63 70
     margin-top: 10
64 71
     margin-left: 5
72
+    &position: {x=65535, y=3, z=0}
65 73
 
66 74
   Item
67 75
     // right
@@ -76,6 +84,7 @@ UIWindow
76 84
     anchors.top: prev.bottom
77 85
     anchors.horizontalCenter: prev.horizontalCenter
78 86
     margin-top: 5
87
+    &position: {x=65535, y=10, z=0}
79 88
 
80 89
   GameLabel
81 90
     id: soul

+ 14
- 0
src/otclient/core/game.cpp View File

@@ -299,6 +299,20 @@ void Game::useInventoryItem(int itemId, const ThingPtr& toThing)
299 299
     }
300 300
 }
301 301
 
302
+void Game::move(const ThingPtr& thing, const Position& toPos, int count)
303
+{
304
+    if(!isOnline() || !thing || !checkBotProtection() || thing->getPos() == toPos || count <= 0)
305
+        return;
306
+
307
+    m_localPlayer->lockWalk();
308
+
309
+    int stackpos = getThingStackpos(thing);
310
+    if(stackpos == -1)
311
+        return;
312
+
313
+    m_protocolGame->sendThrow(thing->getPos(), thing->getId(), stackpos, toPos, count);
314
+}
315
+
302 316
 void Game::attack(const CreaturePtr& creature)
303 317
 {
304 318
     if(!isOnline() || !creature || !checkBotProtection())

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

@@ -65,6 +65,7 @@ public:
65 65
     void use(const ThingPtr& thing);
66 66
     void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
67 67
     void useInventoryItem(int itemId, const ThingPtr& toThing);
68
+    void move(const ThingPtr &thing, const Position& toPos, int count);
68 69
 
69 70
     // attack/follow related
70 71
     void attack(const CreaturePtr& creature);

+ 17
- 0
src/otclient/core/tile.cpp View File

@@ -247,6 +247,23 @@ CreaturePtr Tile::getTopCreature()
247 247
     return creature;
248 248
 }
249 249
 
250
+ThingPtr Tile::getTopMoveThing()
251
+{
252
+    if(isEmpty())
253
+        return nullptr;
254
+
255
+    for(uint i = 0; i < m_things.size(); ++i) {
256
+        ThingPtr thing = m_things[i];
257
+        if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->asCreature()) {
258
+            if(i > 0 && thing->isNotMoveable())
259
+                return m_things[i-1];
260
+            return thing;
261
+        }
262
+    }
263
+
264
+    return m_things[0];
265
+}
266
+
250 267
 ThingPtr Tile::getTopMultiUseThing()
251 268
 {
252 269
     // this is related to classic controls, getting top item, forceuse or creature

+ 1
- 0
src/otclient/core/tile.h View File

@@ -48,6 +48,7 @@ public:
48 48
     ThingPtr getTopLookThing();
49 49
     ThingPtr getTopUseThing();
50 50
     CreaturePtr getTopCreature();
51
+    ThingPtr getTopMoveThing();
51 52
     ThingPtr getTopMultiUseThing();
52 53
 
53 54
     const Position& getPos() { return m_pos; }

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

@@ -169,6 +169,7 @@ void OTClient::registerLuaFunctions()
169 169
     g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
170 170
     g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
171 171
     g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
172
+    g_lua.bindClassMemberFunction<Tile>("getTopMoveThing", &Tile::getTopMoveThing);
172 173
     g_lua.bindClassMemberFunction<Tile>("getTopMultiUseThing", &Tile::getTopMultiUseThing);
173 174
     g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
174 175
     g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
@@ -237,6 +238,7 @@ void OTClient::registerLuaFunctions()
237 238
     g_lua.registerClass<UIMap, UIWidget>();
238 239
     g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
239 240
     g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
241
+    g_lua.bindClassMemberFunction<UIMap>("getPosition", &UIMap::getPosition);
240 242
 
241 243
     g_lua.registerClass<UIGame, UIWidget>();
242 244
     g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );

+ 11
- 2
src/otclient/ui/uimap.cpp View File

@@ -38,10 +38,10 @@ void UIMap::draw()
38 38
     drawChildren();
39 39
 }
40 40
 
41
-TilePtr UIMap::getTile(const Point& mousePos)
41
+Position UIMap::getPosition(const Point& mousePos)
42 42
 {
43 43
     if(!m_mapRect.contains(mousePos))
44
-        return nullptr;
44
+        return Position();
45 45
 
46 46
     // Get tile position
47 47
     Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
@@ -58,6 +58,15 @@ TilePtr UIMap::getTile(const Point& mousePos)
58 58
     PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS;
59 59
     Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
60 60
 
61
+    return tilePos;
62
+}
63
+
64
+TilePtr UIMap::getTile(const Point& mousePos)
65
+{
66
+    Position tilePos = getPosition(mousePos);
67
+    if(!tilePos.isValid())
68
+        return nullptr;
69
+
61 70
     // Get tile
62 71
     TilePtr tile = nullptr;
63 72
 

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

@@ -32,6 +32,7 @@ class UIMap : public UIWidget
32 32
 public:
33 33
     void draw();
34 34
 
35
+    Position getPosition(const Point& mousePos);
35 36
     TilePtr getTile(const Point& mousePos);
36 37
 
37 38
 protected:

Loading…
Cancel
Save