restore old modules

* partially restore vip, battle, healthbar, skills and inventory modules
* more fixes on UIWidgets
* implement UIMiniWindow close/minimize functionality
* allow drag and drop miniwindows beteween game panels
This commit is contained in:
Eduardo Bart 2012-03-28 11:10:21 -03:00
parent e2ea267703
commit 8d14d9bc99
34 changed files with 301 additions and 196 deletions

View File

@ -2,5 +2,5 @@ ProgressBar < UIProgressBar
height: 16 height: 16
background-color: red background-color: red
border: 1 black border: 1 black
image: /core_styles/styles/images/progressbar.png image-source: /core_styles/styles/images/progressbar.png
image-border: 1 image-border: 1

View File

@ -14,10 +14,11 @@ Module
- game_console - game_console
- game_outfit - game_outfit
- game_healthbar - game_healthbar
- game_skills
- game_inventory - game_inventory
//- game_combatcontrols - game_combatcontrols
//- game_skills - game_battle
//- game_viplist - game_viplist
//- game_hotkeys //- game_hotkeys
@onLoad: | @onLoad: |

View File

@ -1,6 +1,7 @@
GameSidePanel < UIMiniWindowContainer GameSidePanel < UIMiniWindowContainer
image-source: images/sidepanel.png image-source: images/sidepanel.png
image-border: 4 image-border: 4
padding: 4
GameBottomPanel < Panel GameBottomPanel < Panel
image-source: images/bottompanel.png image-source: images/bottompanel.png
@ -33,7 +34,7 @@ UIWidget
GameSidePanel GameSidePanel
id: gameLeftPanel id: gameLeftPanel
width: 0 width: 190
layout: verticalBox layout: verticalBox
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
@ -66,6 +67,7 @@ UIWidget
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
relative-margin: right relative-margin: right
margin-right: 190 margin-right: 190
enabled: false
@canUpdateMargin: function(self, newMargin) return math.max(math.min(newMargin, self:getParent():getWidth() - 300), 150) end @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 @onGeometryChange: function(self) self:setMarginRight(math.min(math.max(self:getParent():getWidth() - 300, 150), self:getMarginRight())) end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 551 B

After

Width:  |  Height:  |  Size: 626 B

View File

@ -1,23 +1,22 @@
MiniWindow < UIMiniWindow MiniWindow < UIMiniWindow
font: verdana-11px-antialised font: verdana-11px-antialised
//icon: /core_styles/icons/login.png
icon-rect: 4 4 16 16 icon-rect: 4 4 16 16
width: 192 width: 192
height: 200 height: 200
text-offset: 26 5 text-offset: 26 5
text-align: topLeft text-align: topLeft
margin-top: 2 margin-bottom: 2
margin-left: 6
margin-right: 6
move-policy: free updated move-policy: free updated
image-source: /game/images/miniwindow.png image-source: /game/images/miniwindow.png
image-border: 4 image-border: 4
image-border-top: 23 image-border-top: 23
image-border-left: 23 image-border-left: 23
image-border-bottom: 4
focusable: false
&minimizedHeight: 24
$on: $on:
height: 24 image-border-bottom: 2
image-border-bottom: 1
UIButton UIButton
id: closeButton id: closeButton
@ -27,13 +26,13 @@ MiniWindow < UIMiniWindow
margin-right: 5 margin-right: 5
size: 14 14 size: 14 14
image-source: /game/images/miniwindowbuttons.png image-source: /game/images/miniwindowbuttons.png
image-clip: 14 0 14 14 image-clip: 28 0 14 14
$hover: $hover:
image-clip: 14 14 14 14 image-clip: 28 14 14 14
$pressed: $pressed:
image-clip: 14 28 14 14 image-clip: 28 28 14 14
UIButton UIButton
id: minimizeButton id: minimizeButton
@ -50,6 +49,15 @@ MiniWindow < UIMiniWindow
$pressed: $pressed:
image-clip: 0 28 14 14 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 VerticalScrollBar
id: miniwindowScrollBar id: miniwindowScrollBar
anchors.top: parent.top anchors.top: parent.top
@ -67,14 +75,16 @@ MiniWindow < UIMiniWindow
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
height: 3 height: 3
minimum: 70 minimum: 64
background: #ffffff88 background: #ffffff88
MiniWindowContents < ScrollablePanel MiniWindowContents < ScrollablePanel
id: contentsPanel
anchors.fill: parent anchors.fill: parent
margin-right: 14 margin-right: 14
padding: 25 8 3 8 padding: 25 6 6 6
vertical-scrollbar: miniwindowScrollBar vertical-scrollbar: miniwindowScrollBar
BorderlessGameWindow < UIWindow BorderlessGameWindow < UIWindow
focusable: false focusable: false
margin: 2

View File

@ -27,7 +27,7 @@ end
function UIItem:onDrop(widget, mousePos) function UIItem:onDrop(widget, mousePos)
if self:isVirtual() then return false end 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 pos = self.position
local count = widget.currentDragThing:getCount() local count = widget.currentDragThing:getCount()

View File

@ -2,10 +2,16 @@ UIMiniWindow = extends(UIWindow)
function UIMiniWindow.create() function UIMiniWindow.create()
local miniwindow = UIMiniWindow.internalCreate() local miniwindow = UIMiniWindow.internalCreate()
miniwindow:setFocusable(false)
return miniwindow return miniwindow
end 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) function UIMiniWindow:onDragEnter(mousePos)
local parent = self:getParent() local parent = self:getParent()
if not parent then return false end if not parent then return false end
@ -19,9 +25,19 @@ function UIMiniWindow:onDragEnter(mousePos)
local oldPos = self:getPosition() local oldPos = self:getPosition()
self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y } self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
self:setPosition(oldPos) self:setPosition(oldPos)
self.free = true
return true return true
end 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) function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
-- TODO: drop on other interfaces -- TODO: drop on other interfaces
end end
@ -35,3 +51,25 @@ function UIMiniWindow:onFocusChange(focused)
end end
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

View File

@ -8,7 +8,8 @@ function UIMiniWindowContainer.create()
end end
function UIMiniWindowContainer:onDrop(widget, mousePos) function UIMiniWindowContainer:onDrop(widget, mousePos)
print 'drop' widget:setParent(self)
return true
end end
function UIMiniWindowContainer:getClassName() function UIMiniWindowContainer:getClassName()

View File

@ -35,19 +35,19 @@ table.insert(lifeBarColors, {percentAbove = 3, color = '#3C0000' } )
table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } ) table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
-- public functions -- public functions
function Battle.create() function Battle.init()
battleWindow = displayUI('battle.otui', GameInterface.getRightPanel()) battleWindow = displayUI('battle.otui', GameInterface.getRightPanel())
battleWindow:hide() battleButton = TopMenu.addGameToggleButton('battleButton', 'Battle (Ctrl+B)', 'battle.png', Battle.toggle)
battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle) battleButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+B', Battle.toggle) Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
battlePannel = battleWindow:getChildById('battlePanel') battlePanel = battleWindow:recursiveGetChildById('battlePanel')
hidePlayersButton = battleWindow:getChildById('hidePlayers') hidePlayersButton = battleWindow:recursiveGetChildById('hidePlayers')
hideNPCsButton = battleWindow:getChildById('hideNPCs') hideNPCsButton = battleWindow:recursiveGetChildById('hideNPCs')
hideMonstersButton = battleWindow:getChildById('hideMonsters') hideMonstersButton = battleWindow:recursiveGetChildById('hideMonsters')
hideSkullsButton = battleWindow:getChildById('hideSkulls') hideSkullsButton = battleWindow:recursiveGetChildById('hideSkulls')
hidePartyButton = battleWindow:getChildById('hideParty') hidePartyButton = battleWindow:recursiveGetChildById('hideParty')
mouseWidget = createWidget('UIButton') mouseWidget = createWidget('UIButton')
mouseWidget:setVisible(false) mouseWidget:setVisible(false)
@ -63,9 +63,9 @@ function Battle.create()
checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200) checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200)
end end
function Battle.destroy() function Battle.terminate()
Keyboard.unbindKeyDown('Ctrl+B') Keyboard.unbindKeyDown('Ctrl+B')
battlePannel = nil battlePanel = nil
lastBattleButtonTargeted = nil lastBattleButtonTargeted = nil
lastBattleButtonFollowed = nil lastBattleButtonFollowed = nil
battleButtonsByCreaturesList = {} battleButtonsByCreaturesList = {}
@ -95,15 +95,15 @@ end
function Battle.addAllCreatures() function Battle.addAllCreatures()
local spectators = {} local spectators = {}
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if player then if player then
creatures = g_map.getSpectators(player:getPosition(), false) creatures = g_map.getSpectators(player:getPosition(), false)
for i, creature in ipairs(creatures) do for i, creature in ipairs(creatures) do
if creature ~= player and Battle.doCreatureFitFilters(creature) then if creature ~= player and Battle.doCreatureFitFilters(creature) then
table.insert(spectators, creature) table.insert(spectators, creature)
end end
end end
end end
for i, v in pairs(spectators) do for i, v in pairs(spectators) do
Battle.addCreature(v) Battle.addCreature(v)
@ -176,7 +176,7 @@ function Battle.addCreature(creature)
local creatureId = creature:getId() local creatureId = creature:getId()
if battleButtonsByCreaturesList[creatureId] == nil then if battleButtonsByCreaturesList[creatureId] == nil then
local battleButton = displayUI('battleButton.otui', battlePanne) local battleButton = displayUI('battleButton.otui', battlePanel)
local creatureWidget = battleButton:getChildById('creature') local creatureWidget = battleButton:getChildById('creature')
local labelWidget = battleButton:getChildById('label') local labelWidget = battleButton:getChildById('label')
local lifeBarWidget = battleButton:getChildById('lifeBar') local lifeBarWidget = battleButton:getChildById('lifeBar')
@ -292,7 +292,7 @@ function Battle.setLifeBarPercent(battleButton, percent)
lifeBarWidget:setBackgroundColor(color) lifeBarWidget:setBackgroundColor(color)
end end
function Battle.onbattlePannelHoverChange(widget, hovered) function Battle.onbattleButtonHoverChange(widget, hovered)
if widget.isBattleButton then if widget.isBattleButton then
widget.isHovered = hovered widget.isHovered = hovered
Battle.checkBattleButton(widget) Battle.checkBattleButton(widget)
@ -345,6 +345,3 @@ function Battle.checkBattleButton(battleButton)
lastBattleButtonSwitched = battleButton lastBattleButtonSwitched = battleButton
end end
end end
connect(g_game, { onGameStart = Battle.create,
onGameEnd = Battle.destroy } )

View File

@ -3,6 +3,12 @@ Module
description: Manage battle window description: Manage battle window
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
icon: battle.png
@onLoad: | @onLoad: |
dofile 'battle' dofile 'battle'
Battle.init()
@onUnload:
Battle.terminate()

View File

@ -39,53 +39,59 @@ BattleParty < BattleIcon
MiniWindow MiniWindow
id: battleWindow id: battleWindow
text: Battle text: Battle
height: 250 height: 100
icon: battle.png
@onClose: Battle.toggle()
BattlePlayers MiniWindowContents
id: hidePlayers BattlePlayers
tooltip: Hide players id: hidePlayers
anchors.top: parent.top tooltip: Hide players
anchors.right: next.left anchors.top: parent.top
margin-right: 5 anchors.right: next.left
margin-right: 5
BattleNPCs BattleNPCs
id: hideNPCs id: hideNPCs
tooltip: Hide Npc's tooltip: Hide Npc's
anchors.top: parent.top anchors.top: parent.top
anchors.right: next.left anchors.right: next.left
margin-right: 5 margin-right: 5
BattleMonsters BattleMonsters
id: hideMonsters id: hideMonsters
tooltip: Hide monsters tooltip: Hide monsters
anchors.top: parent.top anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
BattleSkulls BattleSkulls
id: hideSkulls id: hideSkulls
tooltip: Hide non-skull players tooltip: Hide non-skull players
anchors.top: prev.top anchors.top: prev.top
anchors.left: prev.right anchors.left: prev.right
margin-left: 5 margin-left: 5
BattleParty BattleParty
id: hideParty id: hideParty
tooltip: Hide party members tooltip: Hide party members
anchors.top: prev.top anchors.top: prev.top
anchors.left: prev.right anchors.left: prev.right
margin-left: 5 margin-left: 5
HorizontalSeparator HorizontalSeparator
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
margin-top: 5 margin-top: 5
Panel Panel
id: battlePanel id: battlePanel
anchors.fill: parent anchors.left: parent.left
anchors.top: prev.bottom anchors.right: parent.right
margin-top: 5 anchors.top: prev.bottom
layout: verticalBox margin-top: 5
layout:
type: verticalBox
fit-children: true

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -4,7 +4,7 @@ BattleButton
height: 20 height: 20
margin-top: 5 margin-top: 5
fixed-size: true fixed-size: true
&onHoverChange: Battle.onbattlePannelHoverChange &onHoverChange: Battle.onbattleButtonHoverChange
&onMouseRelease: Battle.onMouseRelease &onMouseRelease: Battle.onMouseRelease
&isBattleButton: true &isBattleButton: true

View File

@ -48,15 +48,15 @@ end
-- public functions -- public functions
function CombatControls.init() 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) combatControlsButton:setOn(true)
combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel()) combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel())
fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox') fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox')
fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox') fightBalancedBox = combatControlsWindow:recursiveGetChildById('fightBalancedBox')
fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox') fightDefensiveBox = combatControlsWindow:recursiveGetChildById('fightDefensiveBox')
chaseModeButton = combatControlsWindow:getChildById('chaseModeBox') chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox')
safeFightButton = combatControlsWindow:getChildById('safeFightBox') safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox')
fightModeRadioGroup = RadioGroup.create() fightModeRadioGroup = RadioGroup.create()
fightModeRadioGroup:addWidget(fightOffensiveBox) fightModeRadioGroup:addWidget(fightOffensiveBox)

View File

@ -19,25 +19,29 @@ ChaseModeBox < CombatBox
SafeFightBox < CombatBox SafeFightBox < CombatBox
image-source: /game_combatcontrols/icons/safefight.png image-source: /game_combatcontrols/icons/safefight.png
UIWindow MiniWindow
width: 130 text: Combat Controls
height: 30 icon: combatcontrols.png
margin-top: 10 height: 64
margin-left: 6 @onClose: CombatControls.toggle()
margin-right: 6
FightOffensiveBox MiniWindowContents
id: fightOffensiveBox FightOffensiveBox
anchors.right: next.left id: fightOffensiveBox
FightBalancedBox anchors.right: next.left
id: fightBalancedBox anchors.top: next.top
anchors.right: next.left FightBalancedBox
FightDefensiveBox id: fightBalancedBox
id: fightDefensiveBox anchors.right: next.left
anchors.horizontalCenter: parent.horizontalCenter anchors.top: next.top
ChaseModeBox FightDefensiveBox
id: chaseModeBox id: fightDefensiveBox
anchors.left: prev.right anchors.centerIn: parent
SafeFightBox ChaseModeBox
id: safeFightBox id: chaseModeBox
anchors.left: prev.right anchors.left: prev.right
anchors.top: prev.top
SafeFightBox
id: safeFightBox
anchors.left: prev.right
anchors.top: prev.top

View File

@ -12,13 +12,13 @@ function HealthBar.init()
connect(LocalPlayer, { onHealthChange = HealthBar.onHealthChange, connect(LocalPlayer, { onHealthChange = HealthBar.onHealthChange,
onManaChange = HealthBar.onManaChange }) 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 = TopMenu.addGameToggleButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle)
healthBarButton:setOn(true) healthBarButton:setOn(true)
healthBar = healthBarWindow:getChildById('healthBar') healthBar = healthBarWindow:recursiveGetChildById('healthBar')
manaBar = healthBarWindow:getChildById('manaBar') manaBar = healthBarWindow:recursiveGetChildById('manaBar')
healthLabel = healthBarWindow:getChildById('healthLabel') healthLabel = healthBarWindow:recursiveGetChildById('healthLabel')
manaLabel = healthBarWindow:getChildById('manaLabel') manaLabel = healthBarWindow:recursiveGetChildById('manaLabel')
if g_game.isOnline() then if g_game.isOnline() then
local localPlayer = g_game.getLocalPlayer() local localPlayer = g_game.getLocalPlayer()
@ -32,8 +32,8 @@ function HealthBar.terminate()
onManaChange = HealthBar.onManaChange }) onManaChange = HealthBar.onManaChange })
healthBarWindow:destroy() healthBarWindow:destroy()
healthBarWindow = nil
healthBarButton:destroy() healthBarButton:destroy()
healthBarWindow = nil
healthBarButton = nil healthBarButton = nil
healthBar = nil healthBar = nil
manaBar = nil manaBar = nil

View File

@ -10,9 +10,10 @@ ManaBar < ProgressBar
id: manaBar id: manaBar
height: 15 height: 15
background-color: #4444ff background-color: #4444ff
anchors.bottom: parent.bottom anchors.top: prev.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
margin-top: 4
HealthLabel < GameLabel HealthLabel < GameLabel
id: healthLabel id: healthLabel
@ -32,16 +33,15 @@ ManaLabel < GameLabel
margin-top: 2 margin-top: 2
text: 0 / 0 text: 0 / 0
BorderlessGameWindow MiniWindow
id: healthManaPanel icon: healthbar.png
width: 192 id: healthBarWindow
height: 34 text: Health Bar
margin-top: 10 height: 64
margin-left: 6 @onClose: HealthBar.toggle()
margin-right: 6
move-policy: free updated
HealthBar MiniWindowContents
HealthLabel HealthBar
ManaBar HealthLabel
ManaLabel ManaBar
ManaLabel

View File

@ -145,7 +145,7 @@ end
function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton) function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil local item = nil
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition) local tile = clickedWidget:getTile(mousePosition)

View File

@ -1,6 +1,7 @@
Inventory = {} Inventory = {}
-- private variables -- private variables
local inventoryWindow
local inventoryPanel local inventoryPanel
local inventoryButton local inventoryButton
@ -13,7 +14,9 @@ function Inventory.init()
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) 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 = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true) inventoryButton:setOn(true)
@ -30,15 +33,16 @@ function Inventory.terminate()
Keyboard.unbindKeyDown('Ctrl+I') Keyboard.unbindKeyDown('Ctrl+I')
inventoryPanel:destroy() inventoryWindow:destroy()
inventoryPanel = nil
inventoryButton:destroy() inventoryButton:destroy()
inventoryWindow = nil
inventoryButton = nil inventoryButton = nil
inventoryPanel = nil
end end
function Inventory.toggle() function Inventory.toggle()
local visible = not inventoryPanel:isExplicitlyVisible() local visible = not inventoryWindow:isExplicitlyVisible()
inventoryPanel:setVisible(visible) inventoryWindow:setVisible(visible)
inventoryButton:setOn(visible) inventoryButton:setOn(visible)
end end

View File

@ -2,12 +2,10 @@ MiniWindow
id: inventoryMiniWindow id: inventoryMiniWindow
text: Inventory text: Inventory
icon: inventory.png icon: inventory.png
width: 192 height: 180
height: 154 @onClose: Inventory.toggle()
MiniWindowContents MiniWindowContents
id: inventoryPanel
Item Item
// head // head
id: slot1 id: slot1
@ -37,7 +35,6 @@ MiniWindow
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5 margin-top: 5
margin-bottom: 10
&position: {x=65535, y=8, z=0} &position: {x=65535, y=8, z=0}
Item Item

View File

@ -42,13 +42,37 @@ end
-- public functions -- public functions
function Skills.init() function Skills.init()
skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel()) connect(LocalPlayer, {
skillsWindow:hide() onExperienceChange = Skills.onExperienceChange,
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle) 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) Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
end end
function Skills.terminate() 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') Keyboard.unbindKeyDown('Ctrl+S')
skillsButton:destroy() skillsButton:destroy()
skillsButton = nil skillsButton = nil
@ -122,16 +146,3 @@ function Skills.onSkillChange(localPlayer, id, level, percent)
setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
end 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 })

View File

@ -28,15 +28,16 @@ SkillPercentPanel < ProgressBar
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.top: parent.top
tooltip: 0 phantom: false
MiniWindow MiniWindow
id: skillWindow id: skillWindow
text: Skills text: Skills
height: 350 height: 350
icon: skills.png
@onClose: Skills.toggle()
Panel MiniWindowContents
id: skillPanel
anchors.fill: parent anchors.fill: parent
layout: verticalBox layout: verticalBox

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

View File

@ -6,13 +6,13 @@ local vipButton
local addVipWindow local addVipWindow
-- public functions -- public functions
function VipList.create() function VipList.init()
vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel()) vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
vipWindow:hide() vipButton = TopMenu.addGameToggleButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) vipButton:setOn(true)
end end
function VipList.destroy() function VipList.terminate()
vipWindow:destroy() vipWindow:destroy()
vipWindow = nil vipWindow = nil
vipButton:destroy() vipButton:destroy()
@ -41,7 +41,7 @@ end
-- hooked events -- hooked events
function VipList.onAddVip(id, name, online) function VipList.onAddVip(id, name, online)
local vipList = vipWindow:getChildById('vipList') local vipList = vipWindow:getChildById('contentsPanel')
local label = createWidget('VipListLabel', nil) local label = createWidget('VipListLabel', nil)
label:setId('vip' .. id) label:setId('vip' .. id)

View File

@ -6,3 +6,7 @@ Module
@onLoad: | @onLoad: |
dofile 'viplist' dofile 'viplist'
VipList.init()
@onUnload:
VipList.terminate()

View File

@ -7,9 +7,10 @@ MiniWindow
id: vipWindow id: vipWindow
text: VIP List text: VIP List
height: 100 height: 100
icon: viplist.png
@onClose: VipList.toggle()
UIWidget MiniWindowContents
id: vipList
layout: verticalBox layout: verticalBox
anchors.fill: parent anchors.fill: parent
&onMousePress: VipList.onVipListMousePress &onMousePress: VipList.onVipListMousePress

View File

@ -18,7 +18,7 @@ end
local function onUseWithMouseRelease(self, mousePosition, mouseButton) local function onUseWithMouseRelease(self, mousePosition, mouseButton)
if g_game.selectedThing == nil then return false end if g_game.selectedThing == nil then return false end
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition) local tile = clickedWidget:getTile(mousePosition)

View File

@ -53,7 +53,7 @@ TexturePtr TextureManager::getTexture(const std::string& textureFile)
g_resources.loadFile(textureFile, fin); g_resources.loadFile(textureFile, fin);
texture = loadPNG(fin); texture = loadPNG(fin);
} catch(Exception& e) { } catch(Exception& e) {
Fw::throwException("unable to load texture '", textureFile, "': ", e.what()); logError("unable to load texture '", textureFile, "': ", e.what());
} }
} }

View File

@ -57,6 +57,11 @@ void UIAnchorLayout::removeAnchors(const UIWidgetPtr& anchoredWidget)
update(); 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) void UIAnchorLayout::centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
{ {
addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter); addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);

View File

@ -66,6 +66,7 @@ public:
void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge); const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
void removeAnchors(const UIWidgetPtr& anchoredWidget); void removeAnchors(const UIWidgetPtr& anchoredWidget);
bool hasAnchors(const UIWidgetPtr& anchoredWidget);
void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId); void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId); void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);

View File

@ -37,8 +37,10 @@ void UILayout::update()
m_updating = true; m_updating = true;
internalUpdate(); internalUpdate();
if(UIWidgetPtr parentWidget = getParentWidget()) if(UIWidgetPtr parentWidget = getParentWidget()) {
if(!parentWidget->isDestroyed())
parentWidget->onLayoutUpdate(); parentWidget->onLayoutUpdate();
}
m_updating = false; m_updating = false;
} }

View File

@ -80,7 +80,7 @@ void UIManager::inputEvent(const InputEvent& event)
break; break;
case Fw::MousePressInputEvent: case Fw::MousePressInputEvent:
if(event.mouseButton == Fw::MouseLeftButton && m_mouseReceiver->isVisible()) { 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()) if(pressedWidget && !pressedWidget->isEnabled())
pressedWidget = nullptr; pressedWidget = nullptr;
updatePressedWidget(pressedWidget, event.mousePos); updatePressedWidget(pressedWidget, event.mousePos);
@ -219,7 +219,7 @@ void UIManager::updateHoveredWidget()
return; return;
m_hoverUpdateScheduled = false; m_hoverUpdateScheduled = false;
UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition()); UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition(), false);
if(hoveredWidget && !hoveredWidget->isEnabled()) if(hoveredWidget && !hoveredWidget->isEnabled())
hoveredWidget = nullptr; hoveredWidget = nullptr;

View File

@ -635,7 +635,7 @@ void UIWidget::bindRectToParent()
Rect boundRect = m_rect; Rect boundRect = m_rect;
UIWidgetPtr parent = getParent(); UIWidgetPtr parent = getParent();
if(parent) { if(parent) {
Rect parentRect = parent->getRect(); Rect parentRect = parent->getClippingRect();
boundRect.bind(parentRect); boundRect.bind(parentRect);
} }
@ -872,6 +872,14 @@ bool UIWidget::isVisible()
return asUIWidget() == g_ui.getRootWidget(); 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) bool UIWidget::isChildLocked(const UIWidgetPtr& child)
{ {
auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), 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; return widget;
} }
UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos) UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom)
{ {
if(!containsChildPoint(childPos)) if(!containsChildPoint(childPos))
return nullptr; return nullptr;
@ -1021,10 +1029,10 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it); const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) { if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos); UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos, wantsPhantom);
if(subChild) if(subChild)
return subChild; return subChild;
else if(!child->isPhantom()) else if(wantsPhantom || !child->isPhantom())
return child; return child;
} }
} }
@ -1043,8 +1051,7 @@ UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos); UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos);
if(!subChildren.empty()) if(!subChildren.empty())
children.insert(children.end(), subChildren.begin(), subChildren.end()); children.insert(children.end(), subChildren.begin(), subChildren.end());
else if(!child->isPhantom()) children.push_back(child);
children.push_back(child);
} }
} }
return children; return children;
@ -1279,6 +1286,12 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
if(m_textWrap && oldRect.size() != newRect.size()) if(m_textWrap && oldRect.size() != newRect.size())
updateText(); 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() void UIWidget::onLayoutUpdate()

View File

@ -130,6 +130,7 @@ public:
void setVirtualOffset(const Point& offset); void setVirtualOffset(const Point& offset);
bool isVisible(); bool isVisible();
bool isAnchored();
bool isChildLocked(const UIWidgetPtr& child); bool isChildLocked(const UIWidgetPtr& child);
bool hasChild(const UIWidgetPtr& child); bool hasChild(const UIWidgetPtr& child);
int getChildIndex(const UIWidgetPtr& child); int getChildIndex(const UIWidgetPtr& child);
@ -144,7 +145,7 @@ public:
UIWidgetPtr getChildByPos(const Point& childPos); UIWidgetPtr getChildByPos(const Point& childPos);
UIWidgetPtr getChildByIndex(int index); UIWidgetPtr getChildByIndex(int index);
UIWidgetPtr recursiveGetChildById(const std::string& id); UIWidgetPtr recursiveGetChildById(const std::string& id);
UIWidgetPtr recursiveGetChildByPos(const Point& childPos); UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom);
UIWidgetList recursiveGetChildrenByPos(const Point& childPos); UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
UIWidgetPtr backwardsGetWidgetById(const std::string& id); UIWidgetPtr backwardsGetWidgetById(const std::string& id);