init move items
This commit is contained in:
parent
168f03125c
commit
733039e50e
|
@ -1,3 +1,29 @@
|
|||
function UIItem:onDragEnter(mousePos)
|
||||
local item = self:getItem()
|
||||
if not item then return false end
|
||||
|
||||
self.currentDragThing = item
|
||||
setTargetCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIItem:onDragLeave(widget, mousePos)
|
||||
self.currentDragThing = nil
|
||||
restoreCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIItem:onDrop(widget, mousePos)
|
||||
if not widget or not widget.currentDragThing then return false end
|
||||
|
||||
local pos = self.position
|
||||
local count = 1 -- todo make a window for it
|
||||
|
||||
Game.move(widget.currentDragThing, pos, count)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
||||
local item = self:getItem()
|
||||
if not item or not self:containsPoint(mousePosition) then return false end
|
||||
|
|
|
@ -1,5 +1,34 @@
|
|||
function UIMap:onDragEnter(mousePos)
|
||||
local tile = self:getTile(mousePosition)
|
||||
if not tile then return false end
|
||||
|
||||
local thing = tile:getTopMoveThing()
|
||||
if not thing then return false end
|
||||
|
||||
self.currentDragThing = thing
|
||||
setTargetCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onDragLeave(widget, mousePos)
|
||||
self.currentDragThing = nil
|
||||
restoreCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onDrop(widget, mousePos)
|
||||
if not widget or not widget.currentDragThing then return false end
|
||||
|
||||
local pos = self:getPosition(mousePos)
|
||||
local count = 1 -- todo make a window for it
|
||||
|
||||
Game.move(widget.currentDragThing, pos, count)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onMouseRelease(mousePosition, mouseButton)
|
||||
local tile = self:getTile(mousePosition)
|
||||
if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
|
|||
local item = UIItem.create()
|
||||
item:setStyle('Item')
|
||||
container:addChild(item)
|
||||
item.position = {x=65535, y=containerId+64, z=i-1}
|
||||
end
|
||||
|
||||
m_containers[containerId] = container
|
||||
|
|
|
@ -11,6 +11,7 @@ UIWindow
|
|||
id: slot1
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
&position: {x=65535, y=1, z=0}
|
||||
|
||||
Item
|
||||
// armor
|
||||
|
@ -18,6 +19,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=4, z=0}
|
||||
|
||||
Item
|
||||
// legs
|
||||
|
@ -25,6 +27,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=7, z=0}
|
||||
|
||||
Item
|
||||
// feet
|
||||
|
@ -32,6 +35,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=8, z=0}
|
||||
|
||||
Item
|
||||
// necklace
|
||||
|
@ -40,6 +44,7 @@ UIWindow
|
|||
anchors.right: slot1.left
|
||||
margin-top: 10
|
||||
margin-right: 5
|
||||
&position: {x=65535, y=2, z=0}
|
||||
|
||||
Item
|
||||
// left
|
||||
|
@ -47,6 +52,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=6, z=0}
|
||||
|
||||
Item
|
||||
// ring
|
||||
|
@ -54,6 +60,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=9, z=0}
|
||||
|
||||
Item
|
||||
// backpack
|
||||
|
@ -62,6 +69,7 @@ UIWindow
|
|||
anchors.left: slot1.right
|
||||
margin-top: 10
|
||||
margin-left: 5
|
||||
&position: {x=65535, y=3, z=0}
|
||||
|
||||
Item
|
||||
// right
|
||||
|
@ -76,6 +84,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=10, z=0}
|
||||
|
||||
GameLabel
|
||||
id: soul
|
||||
|
|
|
@ -299,6 +299,20 @@ void Game::useInventoryItem(int itemId, const ThingPtr& toThing)
|
|||
}
|
||||
}
|
||||
|
||||
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
|
||||
{
|
||||
if(!isOnline() || !thing || !checkBotProtection() || thing->getPos() == toPos || count <= 0)
|
||||
return;
|
||||
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos == -1)
|
||||
return;
|
||||
|
||||
m_protocolGame->sendThrow(thing->getPos(), thing->getId(), stackpos, toPos, count);
|
||||
}
|
||||
|
||||
void Game::attack(const CreaturePtr& creature)
|
||||
{
|
||||
if(!isOnline() || !creature || !checkBotProtection())
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
void use(const ThingPtr& thing);
|
||||
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
|
||||
void useInventoryItem(int itemId, const ThingPtr& toThing);
|
||||
void move(const ThingPtr &thing, const Position& toPos, int count);
|
||||
|
||||
// attack/follow related
|
||||
void attack(const CreaturePtr& creature);
|
||||
|
|
|
@ -247,6 +247,23 @@ CreaturePtr Tile::getTopCreature()
|
|||
return creature;
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMoveThing()
|
||||
{
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->asCreature()) {
|
||||
if(i > 0 && thing->isNotMoveable())
|
||||
return m_things[i-1];
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
|
||||
return m_things[0];
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMultiUseThing()
|
||||
{
|
||||
// this is related to classic controls, getting top item, forceuse or creature
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
ThingPtr getTopLookThing();
|
||||
ThingPtr getTopUseThing();
|
||||
CreaturePtr getTopCreature();
|
||||
ThingPtr getTopMoveThing();
|
||||
ThingPtr getTopMultiUseThing();
|
||||
|
||||
const Position& getPos() { return m_pos; }
|
||||
|
|
|
@ -169,6 +169,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopMoveThing", &Tile::getTopMoveThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopMultiUseThing", &Tile::getTopMultiUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
|
||||
g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
|
||||
|
@ -237,6 +238,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
|
||||
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getPosition", &UIMap::getPosition);
|
||||
|
||||
g_lua.registerClass<UIGame, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
|
||||
|
|
|
@ -38,10 +38,10 @@ void UIMap::draw()
|
|||
drawChildren();
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
Position UIMap::getPosition(const Point& mousePos)
|
||||
{
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
return nullptr;
|
||||
return Position();
|
||||
|
||||
// Get tile position
|
||||
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
|
||||
|
@ -58,6 +58,15 @@ TilePtr UIMap::getTile(const Point& mousePos)
|
|||
PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS;
|
||||
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
|
||||
|
||||
return tilePos;
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
{
|
||||
Position tilePos = getPosition(mousePos);
|
||||
if(!tilePos.isValid())
|
||||
return nullptr;
|
||||
|
||||
// Get tile
|
||||
TilePtr tile = nullptr;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class UIMap : public UIWidget
|
|||
public:
|
||||
void draw();
|
||||
|
||||
Position getPosition(const Point& mousePos);
|
||||
TilePtr getTile(const Point& mousePos);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue