diff --git a/modules/core_styles/styles/creatures.otui b/modules/core_styles/styles/creatures.otui index d03a18da..80324482 100644 --- a/modules/core_styles/styles/creatures.otui +++ b/modules/core_styles/styles/creatures.otui @@ -1,6 +1,6 @@ Creature < UICreature size: 66 66 - creature-margin: 1 + padding: 1 border-image: source: /core_styles/images/panel_flat.png border: 1 diff --git a/modules/core_styles/styles/items.otui b/modules/core_styles/styles/items.otui index 0102ac1e..4b41db44 100644 --- a/modules/core_styles/styles/items.otui +++ b/modules/core_styles/styles/items.otui @@ -1,6 +1,6 @@ Item < UIItem size: 34 34 - item margin: 1 + padding: 1 border-image: source: /core_styles/images/panel_flat.png border: 1 diff --git a/modules/core_styles/styles/panels.otui b/modules/core_styles/styles/panels.otui index dadc2d01..4dee070c 100644 --- a/modules/core_styles/styles/panels.otui +++ b/modules/core_styles/styles/panels.otui @@ -28,7 +28,7 @@ InterfacePanel2 < Panel border: 4 Map< UIMap - map margin: 4 + padding: 4 border-image: source: /core_styles/images/map_panel.png - border: 4 \ No newline at end of file + border: 4 diff --git a/modules/game/map.lua b/modules/game/map.lua index a02a15d8..24ba4c08 100644 --- a/modules/game/map.lua +++ b/modules/game/map.lua @@ -1,26 +1,5 @@ -function UIMap:onMouseRelease(mousePos, mouseButton) - local tile = self:getTile(mousePos) - if not tile then return false end - - local keyboardModifiers = g_window.getKeyboardModifiers() - if not Options.classicControl then - if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then - -- auto walk - return true - elseif keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then - Game.createThingMenu(mousePos, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature()) - return true - elseif keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then - Game.look(tile:getTopLookThing()) - return true - elseif keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then - Game.use(tile:getTopUseThing()) - return true - elseif keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then - Game.attack(tile:getTopCreature()) - return true - end - 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 diff --git a/modules/game/thing.lua b/modules/game/thing.lua index 76a1e934..d1c7ad7e 100644 --- a/modules/game/thing.lua +++ b/modules/game/thing.lua @@ -1,5 +1,61 @@ -- public functions +function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing) + local keyboardModifiers = g_window.getKeyboardModifiers() + + if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then + -- todo auto walk + return true + end + + if not Options.classicControl then + if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then + Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) + return true + elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + Game.look(lookThing) + return true + elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + if useThing:isContainer() then + print "open" + elseif useThing:isMultiUse() then + print "use with..." + else + Game.use(useThing) + end + return true + elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + Game.attack(creatureThing) + return true + end + else + if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then + if multiUseThing:asCreature() then + Game.attack(multiUseThing:asCreature()) + elseif multiUseThing:isContainer() then + print "open" + elseif multiUseThing:isMultiUse() then + print "use with..." + else + Game.use(useThing) + end + return true + elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + Game.look(lookThing) + return true + elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) + return true + elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then + Game.attack(creatureThing) + return true + end + end + + return false +end + + function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) local menu = createWidget('PopupMenu') diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index c94d14ad..9e0a106a 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -29,13 +29,10 @@ function Inventory.onSoulChange(soul) widget:setText("Soul:\n" .. soul) end -function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton) - if mouseButton ~= MouseRightButton then return end - +function Inventory.onInventoryItemMousePress(itemWidget, mousePosition, mouseButton) local item = itemWidget:getItem() - if not item then return end - - Game.createThingMenu(mousePos, item, item, nil) + if item and Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then return true end + return false end connect(Game, { onLogin = Inventory.create, @@ -43,3 +40,4 @@ connect(Game, { onLogin = Inventory.create, onInventoryChange = Inventory.onInventoryChange, onFreeCapacityChange = Inventory.onFreeCapacityChange, onSoulChange = Inventory.onSoulChange }) + diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index a5ec02dc..74f6ba81 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -238,6 +238,24 @@ CreaturePtr Tile::getTopCreature() return creature; } +ThingPtr Tile::getTopMultiUseThing() +{ + // this is related to classic controls, getting top item, forceuse or creature + if(isEmpty()) + return nullptr; + + for(uint i = 0; i < m_things.size(); ++i) { + ThingPtr thing = m_things[i]; + if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())) { + if(i > 0 && thing->isFluid()) + return m_things[i-1]; + return thing; + } + } + + return m_things[0]; +} + bool Tile::isWalkable() { if(!getGround()) diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 817907c6..9b8fda95 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -48,6 +48,7 @@ public: ThingPtr getTopLookThing(); ThingPtr getTopUseThing(); CreaturePtr getTopCreature(); + ThingPtr getTopMultiUseThing(); const Position& getPos() { return m_position; } int getDrawElevation() { return m_drawElevation; } diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 65fc1894..46fdc47c 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -152,6 +152,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getTopLookThing", &Tile::getTopLookThing); g_lua.bindClassMemberFunction("getTopUseThing", &Tile::getTopUseThing); g_lua.bindClassMemberFunction("getTopCreature", &Tile::getTopCreature); + g_lua.bindClassMemberFunction("getTopMultiUseThing", &Tile::getTopMultiUseThing); g_lua.bindClassMemberFunction("getPos", &Tile::getPos); g_lua.bindClassMemberFunction("getDrawElevation", &Tile::getDrawElevation); g_lua.bindClassMemberFunction("getCreatures", &Tile::getCreatures); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index e74fb5ed..62581918 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -24,29 +24,14 @@ #include #include -UICreature::UICreature() -{ - m_creatureMargin = 0; -} - void UICreature::render() { renderSelf(); if(m_creature) { g_painter.setColor(Fw::white); - m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin, m_rect); + m_creature->draw(m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop), m_rect); } renderChildren(); } - -void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) -{ - for(OTMLNodePtr node : styleNode->children()) { - if(node->tag() == "creature-margin") - m_creatureMargin = node->value(); - } - - UIWidget::onStyleApply(styleName, styleNode); -} diff --git a/src/otclient/ui/uicreature.h b/src/otclient/ui/uicreature.h index fe73627d..44da3dcf 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -30,19 +30,14 @@ class UICreature : public UIWidget { public: - UICreature(); void render(); void setCreature(const CreaturePtr& creature) { m_creature = creature; } CreaturePtr getCreature() { return m_creature; } -protected: - virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); - private: CreaturePtr m_creature; - int m_creatureMargin; }; #endif diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index 3180c0d6..beb63a56 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -27,7 +27,6 @@ UIItem::UIItem() { - m_itemMargin = 0; m_font = g_fonts.getFont("verdana-11px-rounded"); } @@ -36,7 +35,7 @@ void UIItem::render() renderSelf(); if(m_item) { - Point topLeft = m_rect.bottomRight() - Point(32, 32) + m_itemMargin; + Point topLeft = m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop); g_painter.setColor(Fw::white); m_item->draw(topLeft, m_rect); @@ -49,13 +48,3 @@ void UIItem::render() renderChildren(); } - -void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) -{ - for(OTMLNodePtr node : styleNode->children()) { - if(node->tag() == "item margin") - m_itemMargin = node->value(); - } - - UIWidget::onStyleApply(styleName, styleNode); -} diff --git a/src/otclient/ui/uiitem.h b/src/otclient/ui/uiitem.h index 59e8ab5d..64b08362 100644 --- a/src/otclient/ui/uiitem.h +++ b/src/otclient/ui/uiitem.h @@ -36,12 +36,8 @@ public: void setItem(const ItemPtr& item) { m_item = item; } ItemPtr getItem() { return m_item; } -protected: - virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); - private: ItemPtr m_item; - int m_itemMargin; FontPtr m_font; }; diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 6a15761d..985ba661 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -27,11 +27,6 @@ #include #include -UIMap::UIMap() -{ - m_mapMargin = 0; -} - void UIMap::render() { renderSelf(); @@ -43,16 +38,6 @@ void UIMap::render() renderChildren(); } -void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) -{ - for(OTMLNodePtr node : styleNode->children()) { - if(node->tag() == "map margin") - m_mapMargin = node->value(); - } - - UIWidget::onStyleApply(styleName, styleNode); -} - TilePtr UIMap::getTile(const Point& mousePos) { if(!m_mapRect.contains(mousePos)) @@ -96,7 +81,11 @@ TilePtr UIMap::getTile(const Point& mousePos) void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect) { - Rect mapRect = newRect.expanded(-m_mapMargin-1); + Rect mapRect = newRect.expanded(-1); + mapRect.addTop(m_paddingTop); + mapRect.addLeft(m_paddingLeft); + mapRect.addBottom(-m_paddingBottom); + mapRect.addRight(-m_paddingRight); Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS); mapSize.scale(mapRect.size(), Fw::KeepAspectRatio); diff --git a/src/otclient/ui/uimap.h b/src/otclient/ui/uimap.h index dd5ce11f..6984d1da 100644 --- a/src/otclient/ui/uimap.h +++ b/src/otclient/ui/uimap.h @@ -30,17 +30,14 @@ class UIMap : public UIWidget { public: - UIMap(); void render(); TilePtr getTile(const Point& mousePos); protected: - virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); private: - int m_mapMargin; Rect m_mapRect; };