diff --git a/modules/corelib/ui/uiminiwindow.lua b/modules/corelib/ui/uiminiwindow.lua index f7a8601c..98e4d3fa 100644 --- a/modules/corelib/ui/uiminiwindow.lua +++ b/modules/corelib/ui/uiminiwindow.lua @@ -138,6 +138,24 @@ function UIMiniWindow:onDragEnter(mousePos) return true end +function UIMiniWindow:onDragLeave(droppedWidget, mousePos) + if self.movedWidget then + self.setMovedChildMargin(0) + self.movedWidget = nil + self.setMovedChildMargin = nil + self.movedIndex = nil + end + + local parent = self:getParent() + if parent then + if parent:getClassName() == 'UIMiniWindowContainer' then + parent:saveChildren() + else + self:saveParentPosition(parent:getId(), self:getPosition()) + end + end +end + function UIMiniWindow:onDragMove(mousePos, mouseMoved) local oldMousePosY = mousePos.y - mouseMoved.y local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos) @@ -188,24 +206,6 @@ function UIMiniWindow:onMousePress() end end -function UIMiniWindow:onDragLeave(droppedWidget, mousePos) - if self.movedWidget then - self.setMovedChildMargin(0) - self.movedWidget = nil - self.setMovedChildMargin = nil - self.movedIndex = nil - end - - local parent = self:getParent() - if parent then - if parent:getClassName() == 'UIMiniWindowContainer' then - parent:saveChildren() - else - self:saveParentPosition(parent:getId(), self:getPosition()) - end - end -end - function UIMiniWindow:onFocusChange(focused) -- miniwindows only raises when its outside MiniWindowContainers if not focused then return end @@ -253,3 +253,13 @@ end function UIMiniWindow:disableResize() self:getChildById('bottomResizeBorder'):disable() end + +function UIMiniWindow:setMinimumHeight(height) + local resizeBorder = self:getChildById('bottomResizeBorder') + resizeBorder:setMinimum(height) +end + +function UIMiniWindow:setMaximumHeight(height) + local resizeBorder = self:getChildById('bottomResizeBorder') + resizeBorder:setMaximum(height) +end diff --git a/modules/corelib/ui/uiwindow.lua b/modules/corelib/ui/uiwindow.lua index 671c1241..4ced7f2e 100644 --- a/modules/corelib/ui/uiwindow.lua +++ b/modules/corelib/ui/uiwindow.lua @@ -8,6 +8,10 @@ function UIWindow.create() return window end +function UIWindow:getClassName() + return 'UIWindow' +end + function UIWindow:onKeyDown(keyCode, keyboardModifiers) if keyboardModifiers == KeyboardNoModifier then if keyCode == KeyEnter then diff --git a/modules/game_battle/battle.otui b/modules/game_battle/battle.otui index f1a521bc..b131d34e 100644 --- a/modules/game_battle/battle.otui +++ b/modules/game_battle/battle.otui @@ -41,7 +41,7 @@ MiniWindow !text: tr('Battle') height: 166 icon: battle.png - @onClose: onMiniWindowClose() + @onClose: modules.game_battle.onMiniWindowClose() &save: true MiniWindowContents diff --git a/modules/game_combatcontrols/combatcontrols.otui b/modules/game_combatcontrols/combatcontrols.otui index a47033c7..8a8ba333 100644 --- a/modules/game_combatcontrols/combatcontrols.otui +++ b/modules/game_combatcontrols/combatcontrols.otui @@ -28,7 +28,7 @@ MiniWindow icon: combatcontrols.png height: 48 &save: true - @onClose: onMiniWindowClose() + @onClose: modules.game_combatcontrols.onMiniWindowClose() MiniWindowContents FightOffensiveBox diff --git a/modules/game_healthinfo/healthinfo.otui b/modules/game_healthinfo/healthinfo.otui index ab968d32..fb056691 100644 --- a/modules/game_healthinfo/healthinfo.otui +++ b/modules/game_healthinfo/healthinfo.otui @@ -65,7 +65,7 @@ MiniWindow id: healthInfoWindow !text: tr('Health Info') height: 102 - @onClose: onMiniWindowClose() + @onClose: modules.game_healthinfo.onMiniWindowClose() &save: true MiniWindowContents diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 9c9c32a4..3bf23390 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -179,9 +179,9 @@ function onUseWith(clickedWidget, mousePosition) local tile = clickedWidget:getTile(mousePosition) if tile then g_game.useWith(selectedThing, tile:getTopMultiUseThing()) - elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then - g_game.useWith(selectedThing, clickedWidget:getItem()) end + elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then + g_game.useWith(selectedThing, clickedWidget:getItem()) end end diff --git a/modules/game_interface/widgets/uigamemap.lua b/modules/game_interface/widgets/uigamemap.lua index 607c0963..0d341144 100644 --- a/modules/game_interface/widgets/uigamemap.lua +++ b/modules/game_interface/widgets/uigamemap.lua @@ -7,7 +7,6 @@ function UIGameMap.create() return gameMap end - function UIGameMap:onDragEnter(mousePos) local tile = self:getTile(mousePos) if not tile then return false end @@ -28,7 +27,7 @@ function UIGameMap:onDragLeave(droppedWidget, mousePos) end function UIGameMap:onDrop(widget, mousePos) - if not widget or not widget.currentDragThing then return false end + if not self:canAcceptDrop(widget, mousePos) then return false end local tile = self:getTile(mousePos) if not tile then return false end @@ -82,3 +81,20 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton) return ret end + +function UIGameMap:canAcceptDrop(widget, mousePos) + if not widget or not widget.currentDragThing then return false end + + local children = rootWidget:recursiveGetChildrenByPos(mousePos) + for i=1,#children do + local child = children[i] + if child == self then + return true + elseif not child:isPhantom() then + return false + end + end + + error('Widget ' .. self:getId() .. ' not in drop list.') + return false +end diff --git a/modules/game_interface/widgets/uiitem.lua b/modules/game_interface/widgets/uiitem.lua index d5e84faf..af067ed6 100644 --- a/modules/game_interface/widgets/uiitem.lua +++ b/modules/game_interface/widgets/uiitem.lua @@ -20,9 +20,7 @@ function UIItem:onDragLeave(droppedWidget, mousePos) end function UIItem:onDrop(widget, mousePos) - if self:isVirtual() then return false end - - if not widget or not widget.currentDragThing then return false end + if not self:canAcceptDrop(widget, mousePos) then return false end local item = widget.currentDragThing if not item:isItem() then return false end @@ -94,3 +92,20 @@ function UIItem:onMouseRelease(mousePosition, mouseButton) return false end +function UIItem:canAcceptDrop(widget, mousePos) + if self:isVirtual() then return false end + if not widget or not widget.currentDragThing then return false end + + local children = rootWidget:recursiveGetChildrenByPos(mousePos) + for i=1,#children do + local child = children[i] + if child == self then + return true + elseif not child:isPhantom() then + return false + end + end + + error('Widget ' .. self:getId() .. ' not in drop list.') + return false +end diff --git a/modules/game_inventory/inventory.otui b/modules/game_inventory/inventory.otui index 417fa5b8..1da9c381 100644 --- a/modules/game_inventory/inventory.otui +++ b/modules/game_inventory/inventory.otui @@ -56,7 +56,7 @@ MiniWindow !text: tr('Inventory') icon: inventory.png height: 95 - @onClose: onMiniWindowClose() + @onClose: modules.game_inventory.onMiniWindowClose() &save: true MiniWindowContents diff --git a/modules/game_minimap/minimap.otui b/modules/game_minimap/minimap.otui index ebbadd61..4774a9b2 100644 --- a/modules/game_minimap/minimap.otui +++ b/modules/game_minimap/minimap.otui @@ -25,7 +25,7 @@ MiniWindow !text: tr('Minimap') height: 150 icon: minimap.png - @onClose: onMiniWindowClose() + @onClose: modules.game_minimap.onMiniWindowClose() &save: true Label diff --git a/modules/game_skills/skills.otui b/modules/game_skills/skills.otui index a3792382..2c33b5f9 100644 --- a/modules/game_skills/skills.otui +++ b/modules/game_skills/skills.otui @@ -35,7 +35,7 @@ MiniWindow !text: tr('Skills') height: 150 icon: skills.png - @onClose: onMiniWindowClose() + @onClose: modules.game_skills.onMiniWindowClose() &save: true MiniWindowContents @@ -149,4 +149,3 @@ MiniWindow !text: tr('Fishing') SkillValueLabel SkillPercentPanel - diff --git a/modules/game_viplist/viplist.lua b/modules/game_viplist/viplist.lua index 42e9fbc8..3de10d0e 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/game_viplist/viplist.lua @@ -11,7 +11,6 @@ function init() g_keyboard.bindKeyDown('Ctrl+P', toggle) vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel()) - vipWindow.onClose = onMiniWindowClose vipButton = TopMenu.addRightGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', toggle) vipButton:setOn(true) diff --git a/modules/game_viplist/viplist.otui b/modules/game_viplist/viplist.otui index 69443470..fc015ed8 100644 --- a/modules/game_viplist/viplist.otui +++ b/modules/game_viplist/viplist.otui @@ -7,6 +7,7 @@ MiniWindow !text: tr('VIP List') height: 100 icon: viplist.png + @onClose: modules.game_viplist.onMiniWindowClose() &save: true MiniWindowContents diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 224fba73..2517ddae 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -1198,7 +1198,6 @@ UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id) return widget; } - bool UIWidget::setState(Fw::WidgetState state, bool on) { if(state == Fw::InvalidState) diff --git a/src/otclient/creature.cpp b/src/otclient/creature.cpp index ba4ee942..8a23f547 100644 --- a/src/otclient/creature.cpp +++ b/src/otclient/creature.cpp @@ -156,7 +156,7 @@ void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWal if(m_outfit.getCategory() == ThingCategoryEffect) animationPhase = std::min(animationPhase+1, getAnimationPhases()); - rawGetThingType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase); + rawGetThingType()->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase); } } @@ -632,6 +632,30 @@ int Creature::getStepDuration() return interval; } +Point Creature::getDisplacement() +{ + Point displacement = Thing::getDisplacement(); + if(m_outfit.getCategory() == ThingCategoryEffect) + displacement = Point(8, 8); + return displacement; +} + +int Creature::getDisplacementX() +{ + int displacementX = Thing::getDisplacementX(); + if(m_outfit.getCategory() == ThingCategoryEffect) + displacementX = 8; + return displacementX; +} + +int Creature::getDisplacementY() +{ + int displacementY = Thing::getDisplacementY(); + if(m_outfit.getCategory() == ThingCategoryEffect) + displacementY = 8; + return displacementY; +} + const ThingTypePtr& Creature::getThingType() { return g_things.getThingType(m_outfit.getId(), m_outfit.getCategory()); diff --git a/src/otclient/creature.h b/src/otclient/creature.h index ad2f8917..573c02f3 100644 --- a/src/otclient/creature.h +++ b/src/otclient/creature.h @@ -84,6 +84,9 @@ public: Point getDrawOffset(); int getStepDuration(); Point getWalkOffset() { return m_walkOffset; } + virtual Point getDisplacement(); + virtual int getDisplacementX(); + virtual int getDisplacementY(); void updateShield(); diff --git a/src/otclient/thing.h b/src/otclient/thing.h index ac4f8c93..fbbd56d6 100644 --- a/src/otclient/thing.h +++ b/src/otclient/thing.h @@ -65,9 +65,9 @@ public: Size getSize() { return rawGetThingType()->getSize(); } int getWidth() { return rawGetThingType()->getWidth(); } int getHeight() { return rawGetThingType()->getHeight(); } - Point getDisplacement() { return rawGetThingType()->getDisplacement(); } - int getDisplacementX() { return rawGetThingType()->getDisplacementX(); } - int getDisplacementY() { return rawGetThingType()->getDisplacementY(); } + virtual Point getDisplacement() { return rawGetThingType()->getDisplacement(); } + virtual int getDisplacementX() { return rawGetThingType()->getDisplacementX(); } + virtual int getDisplacementY() { return rawGetThingType()->getDisplacementY(); } int getExactSize() { return rawGetThingType()->getExactSize(); } int getLayers() { return rawGetThingType()->getLayers(); } int getNumPatternX() { return rawGetThingType()->getNumPatternX(); }