diff --git a/modules/core_styles/styles/progressbars.otui b/modules/core_styles/styles/progressbars.otui index e5f41c9a..889b3591 100644 --- a/modules/core_styles/styles/progressbars.otui +++ b/modules/core_styles/styles/progressbars.otui @@ -2,5 +2,5 @@ ProgressBar < UIProgressBar height: 16 background-color: red border: 1 black - image: /core_styles/styles/images/progressbar.png + image-source: /core_styles/styles/images/progressbar.png image-border: 1 diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 017b88b2..49b7344d 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -14,10 +14,11 @@ Module - game_console - game_outfit - game_healthbar + - game_skills - game_inventory - //- game_combatcontrols - //- game_skills - //- game_viplist + - game_combatcontrols + - game_battle + - game_viplist //- game_hotkeys @onLoad: | diff --git a/modules/game/gameinterface.otui b/modules/game/gameinterface.otui index 8e003060..2c9c80ab 100644 --- a/modules/game/gameinterface.otui +++ b/modules/game/gameinterface.otui @@ -1,6 +1,7 @@ GameSidePanel < UIMiniWindowContainer image-source: images/sidepanel.png image-border: 4 + padding: 4 GameBottomPanel < Panel image-source: images/bottompanel.png @@ -33,7 +34,7 @@ UIWidget GameSidePanel id: gameLeftPanel - width: 0 + width: 190 layout: verticalBox anchors.left: parent.left anchors.top: parent.top @@ -66,6 +67,7 @@ UIWidget anchors.bottom: parent.bottom relative-margin: right margin-right: 190 + enabled: false @canUpdateMargin: function(self, newMargin) return math.max(math.min(newMargin, self:getParent():getWidth() - 300), 150) end @onGeometryChange: function(self) self:setMarginRight(math.min(math.max(self:getParent():getWidth() - 300, 150), self:getMarginRight())) end diff --git a/modules/game/images/miniwindowbuttons.png b/modules/game/images/miniwindowbuttons.png index 890d194c..bc065015 100644 Binary files a/modules/game/images/miniwindowbuttons.png and b/modules/game/images/miniwindowbuttons.png differ diff --git a/modules/game/styles/miniwindow.otui b/modules/game/styles/miniwindow.otui index cde84ea2..4a44541d 100644 --- a/modules/game/styles/miniwindow.otui +++ b/modules/game/styles/miniwindow.otui @@ -1,23 +1,22 @@ MiniWindow < UIMiniWindow font: verdana-11px-antialised - //icon: /core_styles/icons/login.png icon-rect: 4 4 16 16 width: 192 height: 200 text-offset: 26 5 text-align: topLeft - margin-top: 2 - margin-left: 6 - margin-right: 6 + margin-bottom: 2 move-policy: free updated image-source: /game/images/miniwindow.png image-border: 4 image-border-top: 23 image-border-left: 23 + image-border-bottom: 4 + focusable: false + &minimizedHeight: 24 $on: - height: 24 - image-border-bottom: 1 + image-border-bottom: 2 UIButton id: closeButton @@ -27,13 +26,13 @@ MiniWindow < UIMiniWindow margin-right: 5 size: 14 14 image-source: /game/images/miniwindowbuttons.png - image-clip: 14 0 14 14 + image-clip: 28 0 14 14 $hover: - image-clip: 14 14 14 14 + image-clip: 28 14 14 14 $pressed: - image-clip: 14 28 14 14 + image-clip: 28 28 14 14 UIButton id: minimizeButton @@ -50,6 +49,15 @@ MiniWindow < UIMiniWindow $pressed: image-clip: 0 28 14 14 + $on: + image-clip: 14 0 14 14 + + $on hover: + image-clip: 14 14 14 14 + + $on pressed: + image-clip: 14 28 14 14 + VerticalScrollBar id: miniwindowScrollBar anchors.top: parent.top @@ -67,14 +75,16 @@ MiniWindow < UIMiniWindow anchors.left: parent.left anchors.right: parent.right height: 3 - minimum: 70 + minimum: 64 background: #ffffff88 MiniWindowContents < ScrollablePanel + id: contentsPanel anchors.fill: parent margin-right: 14 - padding: 25 8 3 8 + padding: 25 6 6 6 vertical-scrollbar: miniwindowScrollBar BorderlessGameWindow < UIWindow focusable: false + margin: 2 diff --git a/modules/game/widgets/uiitem.lua b/modules/game/widgets/uiitem.lua index 4f2b1249..b99c5c34 100644 --- a/modules/game/widgets/uiitem.lua +++ b/modules/game/widgets/uiitem.lua @@ -27,7 +27,7 @@ end function UIItem:onDrop(widget, mousePos) if self:isVirtual() then return false end - if not widget or not widget.currentDragThing then return true end + if not widget or not widget.currentDragThing then return false end local pos = self.position local count = widget.currentDragThing:getCount() diff --git a/modules/game/widgets/uiminiwindow.lua b/modules/game/widgets/uiminiwindow.lua index 10af00e7..aa04b7e3 100644 --- a/modules/game/widgets/uiminiwindow.lua +++ b/modules/game/widgets/uiminiwindow.lua @@ -2,10 +2,16 @@ UIMiniWindow = extends(UIWindow) function UIMiniWindow.create() local miniwindow = UIMiniWindow.internalCreate() - miniwindow:setFocusable(false) return miniwindow end +function UIMiniWindow:onSetup() + addEvent(function() + self:getChildById('closeButton').onClick = function() signalcall(self.onClose, self) end + self:getChildById('minimizeButton').onClick = function() signalcall(self.onMinimize, self) end + end) +end + function UIMiniWindow:onDragEnter(mousePos) local parent = self:getParent() if not parent then return false end @@ -19,9 +25,19 @@ function UIMiniWindow:onDragEnter(mousePos) local oldPos = self:getPosition() self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y } self:setPosition(oldPos) + self.free = true return true end +function UIMiniWindow:onMousePress() + local parent = self:getParent() + if not parent then return false end + if parent:getClassName() ~= 'UIMiniWindowContainer' then + self:raise() + return true + end +end + function UIMiniWindow:onDragLeave(droppedWidget, mousePos) -- TODO: drop on other interfaces end @@ -35,3 +51,25 @@ function UIMiniWindow:onFocusChange(focused) end end +function UIMiniWindow:onClose() +end + +function UIMiniWindow:onMinimize() + if self:isOn() then + self:setOn(false) + self:getChildById('contentsPanel'):show() + self:getChildById('miniwindowScrollBar'):show() + self:getChildById('bottomResizeBorder'):show() + self:getChildById('minimizeButton'):setOn(false) + self:setHeight(self.savedHeight) + else + self.savedHeight = self:getHeight() + self:setHeight(self.minimizedHeight) + self:setOn(true) + self:getChildById('contentsPanel'):hide() + self:getChildById('miniwindowScrollBar'):hide() + self:getChildById('bottomResizeBorder'):hide() + self:getChildById('minimizeButton'):setOn(true) + end +end + diff --git a/modules/game/widgets/uiminiwindowcontainer.lua b/modules/game/widgets/uiminiwindowcontainer.lua index 944bfd8c..a463c5d1 100644 --- a/modules/game/widgets/uiminiwindowcontainer.lua +++ b/modules/game/widgets/uiminiwindowcontainer.lua @@ -8,7 +8,8 @@ function UIMiniWindowContainer.create() end function UIMiniWindowContainer:onDrop(widget, mousePos) - print 'drop' + widget:setParent(self) + return true end function UIMiniWindowContainer:getClassName() diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index 67514e42..ca38a98a 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -35,19 +35,19 @@ table.insert(lifeBarColors, {percentAbove = 3, color = '#3C0000' } ) table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } ) -- public functions -function Battle.create() +function Battle.init() battleWindow = displayUI('battle.otui', GameInterface.getRightPanel()) - battleWindow:hide() - battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle) + battleButton = TopMenu.addGameToggleButton('battleButton', 'Battle (Ctrl+B)', 'battle.png', Battle.toggle) + battleButton:setOn(true) Keyboard.bindKeyDown('Ctrl+B', Battle.toggle) - battlePannel = battleWindow:getChildById('battlePanel') + battlePanel = battleWindow:recursiveGetChildById('battlePanel') - hidePlayersButton = battleWindow:getChildById('hidePlayers') - hideNPCsButton = battleWindow:getChildById('hideNPCs') - hideMonstersButton = battleWindow:getChildById('hideMonsters') - hideSkullsButton = battleWindow:getChildById('hideSkulls') - hidePartyButton = battleWindow:getChildById('hideParty') + hidePlayersButton = battleWindow:recursiveGetChildById('hidePlayers') + hideNPCsButton = battleWindow:recursiveGetChildById('hideNPCs') + hideMonstersButton = battleWindow:recursiveGetChildById('hideMonsters') + hideSkullsButton = battleWindow:recursiveGetChildById('hideSkulls') + hidePartyButton = battleWindow:recursiveGetChildById('hideParty') mouseWidget = createWidget('UIButton') mouseWidget:setVisible(false) @@ -63,9 +63,9 @@ function Battle.create() checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200) end -function Battle.destroy() +function Battle.terminate() Keyboard.unbindKeyDown('Ctrl+B') - battlePannel = nil + battlePanel = nil lastBattleButtonTargeted = nil lastBattleButtonFollowed = nil battleButtonsByCreaturesList = {} @@ -95,15 +95,15 @@ end function Battle.addAllCreatures() local spectators = {} - local player = g_game.getLocalPlayer() - if player then - creatures = g_map.getSpectators(player:getPosition(), false) - for i, creature in ipairs(creatures) do - if creature ~= player and Battle.doCreatureFitFilters(creature) then - table.insert(spectators, creature) - end - end - end + local player = g_game.getLocalPlayer() + if player then + creatures = g_map.getSpectators(player:getPosition(), false) + for i, creature in ipairs(creatures) do + if creature ~= player and Battle.doCreatureFitFilters(creature) then + table.insert(spectators, creature) + end + end + end for i, v in pairs(spectators) do Battle.addCreature(v) @@ -176,7 +176,7 @@ function Battle.addCreature(creature) local creatureId = creature:getId() if battleButtonsByCreaturesList[creatureId] == nil then - local battleButton = displayUI('battleButton.otui', battlePanne) + local battleButton = displayUI('battleButton.otui', battlePanel) local creatureWidget = battleButton:getChildById('creature') local labelWidget = battleButton:getChildById('label') local lifeBarWidget = battleButton:getChildById('lifeBar') @@ -292,7 +292,7 @@ function Battle.setLifeBarPercent(battleButton, percent) lifeBarWidget:setBackgroundColor(color) end -function Battle.onbattlePannelHoverChange(widget, hovered) +function Battle.onbattleButtonHoverChange(widget, hovered) if widget.isBattleButton then widget.isHovered = hovered Battle.checkBattleButton(widget) @@ -345,6 +345,3 @@ function Battle.checkBattleButton(battleButton) lastBattleButtonSwitched = battleButton end end - -connect(g_game, { onGameStart = Battle.create, - onGameEnd = Battle.destroy } ) \ No newline at end of file diff --git a/modules/game_battle/battle.otmod b/modules/game_battle/battle.otmod index a1341672..f602bdcc 100644 --- a/modules/game_battle/battle.otmod +++ b/modules/game_battle/battle.otmod @@ -3,6 +3,12 @@ Module description: Manage battle window author: OTClient team website: https://github.com/edubart/otclient + icon: battle.png @onLoad: | dofile 'battle' + Battle.init() + + @onUnload: + Battle.terminate() + diff --git a/modules/game_battle/battle.otui b/modules/game_battle/battle.otui index f235c4ca..f8258d97 100644 --- a/modules/game_battle/battle.otui +++ b/modules/game_battle/battle.otui @@ -26,66 +26,72 @@ BattlePlayers < BattleIcon BattleNPCs < BattleIcon image-source: /game_battle/battle_npcs.png - + BattleMonsters < BattleIcon image-source: /game_battle/battle_monsters.png BattleSkulls < BattleIcon image-source: /game_battle/battle_skulls.png - + BattleParty < BattleIcon - image-source: /game_battle/battle_party.png - + image-source: /game_battle/battle_party.png + MiniWindow id: battleWindow text: Battle - height: 250 - - BattlePlayers - id: hidePlayers - tooltip: Hide players - anchors.top: parent.top - anchors.right: next.left - margin-right: 5 - - BattleNPCs - id: hideNPCs - tooltip: Hide Npc's - anchors.top: parent.top - anchors.right: next.left - margin-right: 5 - - BattleMonsters - id: hideMonsters - tooltip: Hide monsters - anchors.top: parent.top - anchors.horizontalCenter: parent.horizontalCenter - - BattleSkulls - id: hideSkulls - tooltip: Hide non-skull players - anchors.top: prev.top - anchors.left: prev.right - margin-left: 5 - - BattleParty - id: hideParty - tooltip: Hide party members - anchors.top: prev.top - anchors.left: prev.right - margin-left: 5 - - HorizontalSeparator - anchors.top: prev.bottom - anchors.left: parent.left - anchors.right: parent.right - margin-top: 5 - - Panel - id: battlePanel - anchors.fill: parent - anchors.top: prev.bottom - margin-top: 5 - layout: verticalBox - - + height: 100 + icon: battle.png + @onClose: Battle.toggle() + + MiniWindowContents + BattlePlayers + id: hidePlayers + tooltip: Hide players + anchors.top: parent.top + anchors.right: next.left + margin-right: 5 + + BattleNPCs + id: hideNPCs + tooltip: Hide Npc's + anchors.top: parent.top + anchors.right: next.left + margin-right: 5 + + BattleMonsters + id: hideMonsters + tooltip: Hide monsters + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + + BattleSkulls + id: hideSkulls + tooltip: Hide non-skull players + anchors.top: prev.top + anchors.left: prev.right + margin-left: 5 + + BattleParty + id: hideParty + tooltip: Hide party members + anchors.top: prev.top + anchors.left: prev.right + margin-left: 5 + + HorizontalSeparator + anchors.top: prev.bottom + anchors.left: parent.left + anchors.right: parent.right + margin-top: 5 + + Panel + id: battlePanel + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 5 + layout: + type: verticalBox + fit-children: true + + diff --git a/modules/game_battle/battle.png b/modules/game_battle/battle.png index 247c6ec6..ed67347b 100644 Binary files a/modules/game_battle/battle.png and b/modules/game_battle/battle.png differ diff --git a/modules/game_battle/battleButton.otui b/modules/game_battle/battleButton.otui index bfee2035..b75254dc 100644 --- a/modules/game_battle/battleButton.otui +++ b/modules/game_battle/battleButton.otui @@ -4,7 +4,7 @@ BattleButton height: 20 margin-top: 5 fixed-size: true - &onHoverChange: Battle.onbattlePannelHoverChange + &onHoverChange: Battle.onbattleButtonHoverChange &onMouseRelease: Battle.onMouseRelease &isBattleButton: true @@ -51,4 +51,4 @@ BattleButton anchors.right: parent.right anchors.top: label.bottom margin-top: 2 - phantom: true \ No newline at end of file + phantom: true diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/game_combatcontrols/combatcontrols.lua index 3e64d33b..9048f75e 100644 --- a/modules/game_combatcontrols/combatcontrols.lua +++ b/modules/game_combatcontrols/combatcontrols.lua @@ -48,15 +48,15 @@ end -- public functions function CombatControls.init() - combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle) + combatControlsButton = TopMenu.addGameToggleButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle) combatControlsButton:setOn(true) combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel()) - fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox') - fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox') - fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox') - chaseModeButton = combatControlsWindow:getChildById('chaseModeBox') - safeFightButton = combatControlsWindow:getChildById('safeFightBox') + fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox') + fightBalancedBox = combatControlsWindow:recursiveGetChildById('fightBalancedBox') + fightDefensiveBox = combatControlsWindow:recursiveGetChildById('fightDefensiveBox') + chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox') + safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox') fightModeRadioGroup = RadioGroup.create() fightModeRadioGroup:addWidget(fightOffensiveBox) diff --git a/modules/game_combatcontrols/combatcontrols.otui b/modules/game_combatcontrols/combatcontrols.otui index e9a3af05..366ad8db 100644 --- a/modules/game_combatcontrols/combatcontrols.otui +++ b/modules/game_combatcontrols/combatcontrols.otui @@ -19,25 +19,29 @@ ChaseModeBox < CombatBox SafeFightBox < CombatBox image-source: /game_combatcontrols/icons/safefight.png -UIWindow - width: 130 - height: 30 - margin-top: 10 - margin-left: 6 - margin-right: 6 +MiniWindow + text: Combat Controls + icon: combatcontrols.png + height: 64 + @onClose: CombatControls.toggle() - FightOffensiveBox - id: fightOffensiveBox - anchors.right: next.left - FightBalancedBox - id: fightBalancedBox - anchors.right: next.left - FightDefensiveBox - id: fightDefensiveBox - anchors.horizontalCenter: parent.horizontalCenter - ChaseModeBox - id: chaseModeBox - anchors.left: prev.right - SafeFightBox - id: safeFightBox - anchors.left: prev.right + MiniWindowContents + FightOffensiveBox + id: fightOffensiveBox + anchors.right: next.left + anchors.top: next.top + FightBalancedBox + id: fightBalancedBox + anchors.right: next.left + anchors.top: next.top + FightDefensiveBox + id: fightDefensiveBox + anchors.centerIn: parent + ChaseModeBox + id: chaseModeBox + anchors.left: prev.right + anchors.top: prev.top + SafeFightBox + id: safeFightBox + anchors.left: prev.right + anchors.top: prev.top diff --git a/modules/game_healthbar/healthbar.lua b/modules/game_healthbar/healthbar.lua index 99b8cefc..bc861cb8 100644 --- a/modules/game_healthbar/healthbar.lua +++ b/modules/game_healthbar/healthbar.lua @@ -12,13 +12,13 @@ function HealthBar.init() connect(LocalPlayer, { onHealthChange = HealthBar.onHealthChange, onManaChange = HealthBar.onManaChange }) - healthBarWindow = displayUI('healthbar.otui', GameInterface.getRightPanel()) + healthBarWindow = displayUI('healthbar.otui', GameInterface.getLeftPanel()) healthBarButton = TopMenu.addGameToggleButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle) healthBarButton:setOn(true) - healthBar = healthBarWindow:getChildById('healthBar') - manaBar = healthBarWindow:getChildById('manaBar') - healthLabel = healthBarWindow:getChildById('healthLabel') - manaLabel = healthBarWindow:getChildById('manaLabel') + healthBar = healthBarWindow:recursiveGetChildById('healthBar') + manaBar = healthBarWindow:recursiveGetChildById('manaBar') + healthLabel = healthBarWindow:recursiveGetChildById('healthLabel') + manaLabel = healthBarWindow:recursiveGetChildById('manaLabel') if g_game.isOnline() then local localPlayer = g_game.getLocalPlayer() @@ -32,8 +32,8 @@ function HealthBar.terminate() onManaChange = HealthBar.onManaChange }) healthBarWindow:destroy() - healthBarWindow = nil healthBarButton:destroy() + healthBarWindow = nil healthBarButton = nil healthBar = nil manaBar = nil diff --git a/modules/game_healthbar/healthbar.otui b/modules/game_healthbar/healthbar.otui index dda120fe..d687bb4d 100644 --- a/modules/game_healthbar/healthbar.otui +++ b/modules/game_healthbar/healthbar.otui @@ -10,9 +10,10 @@ ManaBar < ProgressBar id: manaBar height: 15 background-color: #4444ff - anchors.bottom: parent.bottom + anchors.top: prev.bottom anchors.left: parent.left anchors.right: parent.right + margin-top: 4 HealthLabel < GameLabel id: healthLabel @@ -32,16 +33,15 @@ ManaLabel < GameLabel margin-top: 2 text: 0 / 0 -BorderlessGameWindow - id: healthManaPanel - width: 192 - height: 34 - margin-top: 10 - margin-left: 6 - margin-right: 6 - move-policy: free updated +MiniWindow + icon: healthbar.png + id: healthBarWindow + text: Health Bar + height: 64 + @onClose: HealthBar.toggle() - HealthBar - HealthLabel - ManaBar - ManaLabel + MiniWindowContents + HealthBar + HealthLabel + ManaBar + ManaLabel diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index c1b81100..133c229a 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -145,7 +145,7 @@ end function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton) local item = nil if mouseButton == MouseLeftButton then - local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) + local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition, false) if clickedWidget then if clickedWidget:getClassName() == 'UIMap' then local tile = clickedWidget:getTile(mousePosition) diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index 96bd2021..c14d8e8a 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -1,6 +1,7 @@ Inventory = {} -- private variables +local inventoryWindow local inventoryPanel local inventoryButton @@ -13,7 +14,9 @@ function Inventory.init() Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) - inventoryPanel = displayUI('inventory.otui', GameInterface.getRightPanel()):getChildById('inventoryPanel') + inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel()) + inventoryWindow.onClose = Inventory.toggle + inventoryPanel = inventoryWindow:getChildById('contentsPanel') inventoryButton = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle) inventoryButton:setOn(true) @@ -30,15 +33,16 @@ function Inventory.terminate() Keyboard.unbindKeyDown('Ctrl+I') - inventoryPanel:destroy() - inventoryPanel = nil + inventoryWindow:destroy() inventoryButton:destroy() + inventoryWindow = nil inventoryButton = nil + inventoryPanel = nil end function Inventory.toggle() - local visible = not inventoryPanel:isExplicitlyVisible() - inventoryPanel:setVisible(visible) + local visible = not inventoryWindow:isExplicitlyVisible() + inventoryWindow:setVisible(visible) inventoryButton:setOn(visible) end diff --git a/modules/game_inventory/inventory.otui b/modules/game_inventory/inventory.otui index 03cbd647..f787ed48 100644 --- a/modules/game_inventory/inventory.otui +++ b/modules/game_inventory/inventory.otui @@ -2,12 +2,10 @@ MiniWindow id: inventoryMiniWindow text: Inventory icon: inventory.png - width: 192 - height: 154 + height: 180 + @onClose: Inventory.toggle() MiniWindowContents - id: inventoryPanel - Item // head id: slot1 @@ -37,7 +35,6 @@ MiniWindow anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 - margin-bottom: 10 &position: {x=65535, y=8, z=0} Item diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index a125f486..bb44bd3e 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -42,13 +42,37 @@ end -- public functions function Skills.init() - skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel()) - skillsWindow:hide() - skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle) + connect(LocalPlayer, { + onExperienceChange = Skills.onExperienceChange, + onLevelChange = Skills.onLevelChange, + onHealthChange = Skills.onHealthChange, + onManaChange = Skills.onManaChange, + onSoulChange = Skills.onSoulChange, + onFreeCapacityChange = Skills.onFreeCapacityChange, + onStaminaChange = Skills.onStaminaChange, + onMagicLevelChange = Skills.onMagicLevelChange, + onSkillChange = Skills.onSkillChange + }) + + skillsWindow = displayUI('skills.otui', GameInterface.getLeftPanel()) + skillsButton = TopMenu.addGameToggleButton('skillsButton', 'Skills (Ctrl+S)', 'skills.png', Skills.toggle) + skillsButton:setOn(true) Keyboard.bindKeyDown('Ctrl+S', Skills.toggle) end function Skills.terminate() + disconnect(LocalPlayer, { + onExperienceChange = Skills.onExperienceChange, + onLevelChange = Skills.onLevelChange, + onHealthChange = Skills.onHealthChange, + onManaChange = Skills.onManaChange, + onSoulChange = Skills.onSoulChange, + onFreeCapacityChange = Skills.onFreeCapacityChange, + onStaminaChange = Skills.onStaminaChange, + onMagicLevelChange = Skills.onMagicLevelChange, + onSkillChange = Skills.onSkillChange + }) + Keyboard.unbindKeyDown('Ctrl+S') skillsButton:destroy() skillsButton = nil @@ -122,16 +146,3 @@ function Skills.onSkillChange(localPlayer, id, level, percent) setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go') end -connect(g_game, { onGameStart = Skills.create, - onGameEnd = Skills.destroy }) - -connect(LocalPlayer, { - onExperienceChange = Skills.onExperienceChange, - onLevelChange = Skills.onLevelChange, - onHealthChange = Skills.onHealthChange, - onManaChange = Skills.onManaChange, - onSoulChange = Skills.onSoulChange, - onFreeCapacityChange = Skills.onFreeCapacityChange, - onStaminaChange = Skills.onStaminaChange, - onMagicLevelChange = Skills.onMagicLevelChange, - onSkillChange = Skills.onSkillChange }) diff --git a/modules/game_skills/skills.otui b/modules/game_skills/skills.otui index a9909c56..a716d440 100644 --- a/modules/game_skills/skills.otui +++ b/modules/game_skills/skills.otui @@ -28,15 +28,16 @@ SkillPercentPanel < ProgressBar anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top - tooltip: 0 + phantom: false MiniWindow id: skillWindow text: Skills height: 350 + icon: skills.png + @onClose: Skills.toggle() - Panel - id: skillPanel + MiniWindowContents anchors.fill: parent layout: verticalBox diff --git a/modules/game_skills/skills.png b/modules/game_skills/skills.png new file mode 100644 index 00000000..52deb107 Binary files /dev/null and b/modules/game_skills/skills.png differ diff --git a/modules/game_viplist/viplist.lua b/modules/game_viplist/viplist.lua index 853c5220..7feca5f4 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/game_viplist/viplist.lua @@ -6,13 +6,13 @@ local vipButton local addVipWindow -- public functions -function VipList.create() - vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel()) - vipWindow:hide() - vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) +function VipList.init() + vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel()) + vipButton = TopMenu.addGameToggleButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) + vipButton:setOn(true) end -function VipList.destroy() +function VipList.terminate() vipWindow:destroy() vipWindow = nil vipButton:destroy() @@ -41,7 +41,7 @@ end -- hooked events function VipList.onAddVip(id, name, online) - local vipList = vipWindow:getChildById('vipList') + local vipList = vipWindow:getChildById('contentsPanel') local label = createWidget('VipListLabel', nil) label:setId('vip' .. id) diff --git a/modules/game_viplist/viplist.otmod b/modules/game_viplist/viplist.otmod index a91b426d..64ee77fa 100644 --- a/modules/game_viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -6,3 +6,7 @@ Module @onLoad: | dofile 'viplist' + VipList.init() + + @onUnload: + VipList.terminate() diff --git a/modules/game_viplist/viplist.otui b/modules/game_viplist/viplist.otui index c5422e37..b675a93c 100644 --- a/modules/game_viplist/viplist.otui +++ b/modules/game_viplist/viplist.otui @@ -7,9 +7,10 @@ MiniWindow id: vipWindow text: VIP List height: 100 + icon: viplist.png + @onClose: VipList.toggle() - UIWidget - id: vipList + MiniWindowContents layout: verticalBox anchors.fill: parent &onMousePress: VipList.onVipListMousePress diff --git a/modules/old/game/game.lua b/modules/old/game/game.lua index cede73ee..364023ca 100644 --- a/modules/old/game/game.lua +++ b/modules/old/game/game.lua @@ -18,7 +18,7 @@ end local function onUseWithMouseRelease(self, mousePosition, mouseButton) if g_game.selectedThing == nil then return false end if mouseButton == MouseLeftButton then - local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) + local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition, false) if clickedWidget then if clickedWidget:getClassName() == 'UIMap' then local tile = clickedWidget:getTile(mousePosition) diff --git a/src/framework/graphics/texturemanager.cpp b/src/framework/graphics/texturemanager.cpp index 1e2193fe..a2b1c18c 100644 --- a/src/framework/graphics/texturemanager.cpp +++ b/src/framework/graphics/texturemanager.cpp @@ -53,7 +53,7 @@ TexturePtr TextureManager::getTexture(const std::string& textureFile) g_resources.loadFile(textureFile, fin); texture = loadPNG(fin); } catch(Exception& e) { - Fw::throwException("unable to load texture '", textureFile, "': ", e.what()); + logError("unable to load texture '", textureFile, "': ", e.what()); } } diff --git a/src/framework/ui/uianchorlayout.cpp b/src/framework/ui/uianchorlayout.cpp index bad1adcd..d514aadf 100644 --- a/src/framework/ui/uianchorlayout.cpp +++ b/src/framework/ui/uianchorlayout.cpp @@ -57,6 +57,11 @@ void UIAnchorLayout::removeAnchors(const UIWidgetPtr& anchoredWidget) update(); } +bool UIAnchorLayout::hasAnchors(const UIWidgetPtr& anchoredWidget) +{ + return m_anchorsGroups.find(anchoredWidget) != m_anchorsGroups.end(); +} + void UIAnchorLayout::centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId) { addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter); diff --git a/src/framework/ui/uianchorlayout.h b/src/framework/ui/uianchorlayout.h index 1e644686..09c8c6fa 100644 --- a/src/framework/ui/uianchorlayout.h +++ b/src/framework/ui/uianchorlayout.h @@ -66,6 +66,7 @@ public: void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge); void removeAnchors(const UIWidgetPtr& anchoredWidget); + bool hasAnchors(const UIWidgetPtr& anchoredWidget); void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId); void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId); diff --git a/src/framework/ui/uilayout.cpp b/src/framework/ui/uilayout.cpp index cc42b4ac..2ce98683 100644 --- a/src/framework/ui/uilayout.cpp +++ b/src/framework/ui/uilayout.cpp @@ -37,8 +37,10 @@ void UILayout::update() m_updating = true; internalUpdate(); - if(UIWidgetPtr parentWidget = getParentWidget()) + if(UIWidgetPtr parentWidget = getParentWidget()) { + if(!parentWidget->isDestroyed()) parentWidget->onLayoutUpdate(); + } m_updating = false; } diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 7a806411..412825af 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -80,7 +80,7 @@ void UIManager::inputEvent(const InputEvent& event) break; case Fw::MousePressInputEvent: if(event.mouseButton == Fw::MouseLeftButton && m_mouseReceiver->isVisible()) { - UIWidgetPtr pressedWidget = m_mouseReceiver->recursiveGetChildByPos(event.mousePos); + UIWidgetPtr pressedWidget = m_mouseReceiver->recursiveGetChildByPos(event.mousePos, false); if(pressedWidget && !pressedWidget->isEnabled()) pressedWidget = nullptr; updatePressedWidget(pressedWidget, event.mousePos); @@ -219,7 +219,7 @@ void UIManager::updateHoveredWidget() return; m_hoverUpdateScheduled = false; - UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition()); + UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition(), false); if(hoveredWidget && !hoveredWidget->isEnabled()) hoveredWidget = nullptr; diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index d95f935c..a516ee90 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -635,7 +635,7 @@ void UIWidget::bindRectToParent() Rect boundRect = m_rect; UIWidgetPtr parent = getParent(); if(parent) { - Rect parentRect = parent->getRect(); + Rect parentRect = parent->getClippingRect(); boundRect.bind(parentRect); } @@ -872,6 +872,14 @@ bool UIWidget::isVisible() return asUIWidget() == g_ui.getRootWidget(); } +bool UIWidget::isAnchored() +{ + if(UIWidgetPtr parent = getParent()) + if(UIAnchorLayoutPtr anchorLayout = parent->getAnchoredLayout()) + return anchorLayout->hasAnchors(asUIWidget()); + return false; +} + bool UIWidget::isChildLocked(const UIWidgetPtr& child) { auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child); @@ -1013,7 +1021,7 @@ UIWidgetPtr UIWidget::recursiveGetChildById(const std::string& id) return widget; } -UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos) +UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom) { if(!containsChildPoint(childPos)) return nullptr; @@ -1021,10 +1029,10 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos) for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { const UIWidgetPtr& child = (*it); if(child->isExplicitlyVisible() && child->containsPoint(childPos)) { - UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos); + UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos, wantsPhantom); if(subChild) return subChild; - else if(!child->isPhantom()) + else if(wantsPhantom || !child->isPhantom()) return child; } } @@ -1043,8 +1051,7 @@ UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos) UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos); if(!subChildren.empty()) children.insert(children.end(), subChildren.begin(), subChildren.end()); - else if(!child->isPhantom()) - children.push_back(child); + children.push_back(child); } } return children; @@ -1279,6 +1286,12 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect) if(m_textWrap && oldRect.size() != newRect.size()) updateText(); + + // move children that is outside the parent rect to inside again + for(const UIWidgetPtr& child : m_children) { + if(!child->isAnchored()) + child->bindRectToParent(); + } } void UIWidget::onLayoutUpdate() diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index c297cb41..d678c998 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -130,6 +130,7 @@ public: void setVirtualOffset(const Point& offset); bool isVisible(); + bool isAnchored(); bool isChildLocked(const UIWidgetPtr& child); bool hasChild(const UIWidgetPtr& child); int getChildIndex(const UIWidgetPtr& child); @@ -144,7 +145,7 @@ public: UIWidgetPtr getChildByPos(const Point& childPos); UIWidgetPtr getChildByIndex(int index); UIWidgetPtr recursiveGetChildById(const std::string& id); - UIWidgetPtr recursiveGetChildByPos(const Point& childPos); + UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom); UIWidgetList recursiveGetChildrenByPos(const Point& childPos); UIWidgetPtr backwardsGetWidgetById(const std::string& id);