Browse Source

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
Eduardo Bart 9 years ago
parent
commit
8d14d9bc99
34 changed files with 301 additions and 196 deletions
  1. 1
    1
      modules/core_styles/styles/progressbars.otui
  2. 4
    3
      modules/game/game.otmod
  3. 3
    1
      modules/game/gameinterface.otui
  4. BIN
      modules/game/images/miniwindowbuttons.png
  5. 21
    11
      modules/game/styles/miniwindow.otui
  6. 1
    1
      modules/game/widgets/uiitem.lua
  7. 39
    1
      modules/game/widgets/uiminiwindow.lua
  8. 2
    1
      modules/game/widgets/uiminiwindowcontainer.lua
  9. 22
    25
      modules/game_battle/battle.lua
  10. 6
    0
      modules/game_battle/battle.otmod
  11. 60
    54
      modules/game_battle/battle.otui
  12. BIN
      modules/game_battle/battle.png
  13. 2
    2
      modules/game_battle/battleButton.otui
  14. 6
    6
      modules/game_combatcontrols/combatcontrols.lua
  15. 25
    21
      modules/game_combatcontrols/combatcontrols.otui
  16. 6
    6
      modules/game_healthbar/healthbar.lua
  17. 13
    13
      modules/game_healthbar/healthbar.otui
  18. 1
    1
      modules/game_hotkeys/hotkeys_manager.lua
  19. 9
    5
      modules/game_inventory/inventory.lua
  20. 2
    5
      modules/game_inventory/inventory.otui
  21. 27
    16
      modules/game_skills/skills.lua
  22. 4
    3
      modules/game_skills/skills.otui
  23. BIN
      modules/game_skills/skills.png
  24. 6
    6
      modules/game_viplist/viplist.lua
  25. 4
    0
      modules/game_viplist/viplist.otmod
  26. 3
    2
      modules/game_viplist/viplist.otui
  27. 1
    1
      modules/old/game/game.lua
  28. 1
    1
      src/framework/graphics/texturemanager.cpp
  29. 5
    0
      src/framework/ui/uianchorlayout.cpp
  30. 1
    0
      src/framework/ui/uianchorlayout.h
  31. 3
    1
      src/framework/ui/uilayout.cpp
  32. 2
    2
      src/framework/ui/uimanager.cpp
  33. 19
    6
      src/framework/ui/uiwidget.cpp
  34. 2
    1
      src/framework/ui/uiwidget.h

+ 1
- 1
modules/core_styles/styles/progressbars.otui View File

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

+ 4
- 3
modules/game/game.otmod View File

@@ -14,10 +14,11 @@ Module
14 14
     - game_console
15 15
     - game_outfit
16 16
     - game_healthbar
17
+    - game_skills
17 18
     - game_inventory
18
-    //- game_combatcontrols
19
-    //- game_skills
20
-    //- game_viplist
19
+    - game_combatcontrols
20
+    - game_battle
21
+    - game_viplist
21 22
     //- game_hotkeys
22 23
 
23 24
   @onLoad: |

+ 3
- 1
modules/game/gameinterface.otui View File

@@ -1,6 +1,7 @@
1 1
 GameSidePanel < UIMiniWindowContainer
2 2
   image-source: images/sidepanel.png
3 3
   image-border: 4
4
+  padding: 4
4 5
 
5 6
 GameBottomPanel < Panel
6 7
   image-source: images/bottompanel.png
@@ -33,7 +34,7 @@ UIWidget
33 34
 
34 35
   GameSidePanel
35 36
     id: gameLeftPanel
36
-    width: 0
37
+    width: 190
37 38
     layout: verticalBox
38 39
     anchors.left: parent.left
39 40
     anchors.top: parent.top
@@ -66,6 +67,7 @@ UIWidget
66 67
     anchors.bottom: parent.bottom
67 68
     relative-margin: right
68 69
     margin-right: 190
70
+    enabled: false
69 71
     @canUpdateMargin: function(self, newMargin) return math.max(math.min(newMargin, self:getParent():getWidth() - 300), 150) end
70 72
     @onGeometryChange: function(self) self:setMarginRight(math.min(math.max(self:getParent():getWidth() - 300, 150), self:getMarginRight())) end
71 73
 

BIN
modules/game/images/miniwindowbuttons.png View File


+ 21
- 11
modules/game/styles/miniwindow.otui View File

@@ -1,23 +1,22 @@
1 1
 MiniWindow < UIMiniWindow
2 2
   font: verdana-11px-antialised
3
-  //icon: /core_styles/icons/login.png
4 3
   icon-rect: 4 4 16 16
5 4
   width: 192
6 5
   height: 200
7 6
   text-offset: 26 5
8 7
   text-align: topLeft
9
-  margin-top: 2
10
-  margin-left: 6
11
-  margin-right: 6
8
+  margin-bottom: 2
12 9
   move-policy: free updated
13 10
   image-source: /game/images/miniwindow.png
14 11
   image-border: 4
15 12
   image-border-top: 23
16 13
   image-border-left: 23
14
+  image-border-bottom: 4
15
+  focusable: false
16
+  &minimizedHeight: 24
17 17
 
18 18
   $on:
19
-    height: 24
20
-    image-border-bottom: 1
19
+    image-border-bottom: 2
21 20
 
22 21
   UIButton
23 22
     id: closeButton
@@ -27,13 +26,13 @@ MiniWindow < UIMiniWindow
27 26
     margin-right: 5
28 27
     size: 14 14
29 28
     image-source: /game/images/miniwindowbuttons.png
30
-    image-clip: 14 0 14 14
29
+    image-clip: 28 0 14 14
31 30
 
32 31
     $hover:
33
-      image-clip: 14 14 14 14
32
+      image-clip: 28 14 14 14
34 33
 
35 34
     $pressed:
36
-      image-clip: 14 28 14 14
35
+      image-clip: 28 28 14 14
37 36
 
38 37
   UIButton
39 38
     id: minimizeButton
@@ -50,6 +49,15 @@ MiniWindow < UIMiniWindow
50 49
     $pressed:
51 50
       image-clip: 0 28 14 14
52 51
 
52
+    $on:
53
+      image-clip: 14 0 14 14
54
+
55
+    $on hover:
56
+      image-clip: 14 14 14 14
57
+
58
+    $on pressed:
59
+      image-clip: 14 28 14 14
60
+
53 61
   VerticalScrollBar
54 62
     id: miniwindowScrollBar
55 63
     anchors.top: parent.top
@@ -67,14 +75,16 @@ MiniWindow < UIMiniWindow
67 75
     anchors.left: parent.left
68 76
     anchors.right: parent.right
69 77
     height: 3
70
-    minimum: 70
78
+    minimum: 64
71 79
     background: #ffffff88
72 80
 
73 81
 MiniWindowContents < ScrollablePanel
82
+  id: contentsPanel
74 83
   anchors.fill: parent
75 84
   margin-right: 14
76
-  padding: 25 8 3 8
85
+  padding: 25 6 6 6
77 86
   vertical-scrollbar: miniwindowScrollBar
78 87
 
79 88
 BorderlessGameWindow < UIWindow
80 89
   focusable: false
90
+  margin: 2

+ 1
- 1
modules/game/widgets/uiitem.lua View File

@@ -27,7 +27,7 @@ end
27 27
 function UIItem:onDrop(widget, mousePos)
28 28
   if self:isVirtual() then return false end
29 29
 
30
-  if not widget or not widget.currentDragThing then return true end
30
+  if not widget or not widget.currentDragThing then return false end
31 31
 
32 32
   local pos = self.position
33 33
   local count = widget.currentDragThing:getCount()

+ 39
- 1
modules/game/widgets/uiminiwindow.lua View File

@@ -2,10 +2,16 @@ UIMiniWindow = extends(UIWindow)
2 2
 
3 3
 function UIMiniWindow.create()
4 4
   local miniwindow = UIMiniWindow.internalCreate()
5
-  miniwindow:setFocusable(false)
6 5
   return miniwindow
7 6
 end
8 7
 
8
+function UIMiniWindow:onSetup()
9
+  addEvent(function()
10
+    self:getChildById('closeButton').onClick = function() signalcall(self.onClose, self) end
11
+    self:getChildById('minimizeButton').onClick = function() signalcall(self.onMinimize, self) end
12
+  end)
13
+end
14
+
9 15
 function UIMiniWindow:onDragEnter(mousePos)
10 16
   local parent = self:getParent()
11 17
   if not parent then return false end
@@ -19,9 +25,19 @@ function UIMiniWindow:onDragEnter(mousePos)
19 25
   local oldPos = self:getPosition()
20 26
   self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
21 27
   self:setPosition(oldPos)
28
+  self.free = true
22 29
   return true
23 30
 end
24 31
 
32
+function UIMiniWindow:onMousePress()
33
+  local parent = self:getParent()
34
+  if not parent then return false end
35
+  if parent:getClassName() ~= 'UIMiniWindowContainer' then
36
+    self:raise()
37
+    return true
38
+  end
39
+end
40
+
25 41
 function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
26 42
   -- TODO: drop on other interfaces
27 43
 end
@@ -35,3 +51,25 @@ function UIMiniWindow:onFocusChange(focused)
35 51
   end
36 52
 end
37 53
 
54
+function UIMiniWindow:onClose()
55
+end
56
+
57
+function UIMiniWindow:onMinimize()
58
+  if self:isOn() then
59
+    self:setOn(false)
60
+    self:getChildById('contentsPanel'):show()
61
+    self:getChildById('miniwindowScrollBar'):show()
62
+    self:getChildById('bottomResizeBorder'):show()
63
+    self:getChildById('minimizeButton'):setOn(false)
64
+    self:setHeight(self.savedHeight)
65
+  else
66
+    self.savedHeight = self:getHeight()
67
+    self:setHeight(self.minimizedHeight)
68
+    self:setOn(true)
69
+    self:getChildById('contentsPanel'):hide()
70
+    self:getChildById('miniwindowScrollBar'):hide()
71
+    self:getChildById('bottomResizeBorder'):hide()
72
+    self:getChildById('minimizeButton'):setOn(true)
73
+  end
74
+end
75
+

+ 2
- 1
modules/game/widgets/uiminiwindowcontainer.lua View File

@@ -8,7 +8,8 @@ function UIMiniWindowContainer.create()
8 8
 end
9 9
 
10 10
 function UIMiniWindowContainer:onDrop(widget, mousePos)
11
-  print 'drop'
11
+  widget:setParent(self)
12
+  return true
12 13
 end
13 14
 
14 15
 function UIMiniWindowContainer:getClassName()

+ 22
- 25
modules/game_battle/battle.lua View File

@@ -35,19 +35,19 @@ table.insert(lifeBarColors, {percentAbove = 3, color = '#3C0000' } )
35 35
 table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
36 36
 
37 37
 -- public functions
38
-function Battle.create()
38
+function Battle.init()
39 39
   battleWindow = displayUI('battle.otui', GameInterface.getRightPanel())
40
-  battleWindow:hide()
41
-  battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle)
40
+  battleButton = TopMenu.addGameToggleButton('battleButton', 'Battle (Ctrl+B)', 'battle.png', Battle.toggle)
41
+  battleButton:setOn(true)
42 42
   Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
43 43
 
44
-  battlePannel = battleWindow:getChildById('battlePanel')
44
+  battlePanel = battleWindow:recursiveGetChildById('battlePanel')
45 45
 
46
-  hidePlayersButton = battleWindow:getChildById('hidePlayers')
47
-  hideNPCsButton = battleWindow:getChildById('hideNPCs')
48
-  hideMonstersButton = battleWindow:getChildById('hideMonsters')
49
-  hideSkullsButton = battleWindow:getChildById('hideSkulls')
50
-  hidePartyButton = battleWindow:getChildById('hideParty')
46
+  hidePlayersButton = battleWindow:recursiveGetChildById('hidePlayers')
47
+  hideNPCsButton = battleWindow:recursiveGetChildById('hideNPCs')
48
+  hideMonstersButton = battleWindow:recursiveGetChildById('hideMonsters')
49
+  hideSkullsButton = battleWindow:recursiveGetChildById('hideSkulls')
50
+  hidePartyButton = battleWindow:recursiveGetChildById('hideParty')
51 51
 
52 52
   mouseWidget = createWidget('UIButton')
53 53
   mouseWidget:setVisible(false)
@@ -63,9 +63,9 @@ function Battle.create()
63 63
   checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200)
64 64
 end
65 65
 
66
-function Battle.destroy()
66
+function Battle.terminate()
67 67
   Keyboard.unbindKeyDown('Ctrl+B')
68
-  battlePannel = nil
68
+  battlePanel = nil
69 69
   lastBattleButtonTargeted = nil
70 70
   lastBattleButtonFollowed = nil
71 71
   battleButtonsByCreaturesList = {}
@@ -95,15 +95,15 @@ end
95 95
 
96 96
 function Battle.addAllCreatures()
97 97
   local spectators = {}
98
-	local player = g_game.getLocalPlayer()
99
-	if player then
100
-		creatures = g_map.getSpectators(player:getPosition(), false)
101
-		for i, creature in ipairs(creatures) do
102
-			if creature ~= player and Battle.doCreatureFitFilters(creature) then
103
-        table.insert(spectators, creature)
104
-			end
105
-		end
106
-	end
98
+    local player = g_game.getLocalPlayer()
99
+    if player then
100
+        creatures = g_map.getSpectators(player:getPosition(), false)
101
+        for i, creature in ipairs(creatures) do
102
+            if creature ~= player and Battle.doCreatureFitFilters(creature) then
103
+              table.insert(spectators, creature)
104
+            end
105
+        end
106
+    end
107 107
 
108 108
   for i, v in pairs(spectators) do
109 109
     Battle.addCreature(v)
@@ -176,7 +176,7 @@ function Battle.addCreature(creature)
176 176
   local creatureId = creature:getId()
177 177
 
178 178
   if battleButtonsByCreaturesList[creatureId] == nil then
179
-    local battleButton = displayUI('battleButton.otui', battlePanne)
179
+    local battleButton = displayUI('battleButton.otui', battlePanel)
180 180
     local creatureWidget = battleButton:getChildById('creature')
181 181
     local labelWidget = battleButton:getChildById('label')
182 182
     local lifeBarWidget = battleButton:getChildById('lifeBar')
@@ -292,7 +292,7 @@ function Battle.setLifeBarPercent(battleButton, percent)
292 292
   lifeBarWidget:setBackgroundColor(color)
293 293
 end
294 294
 
295
-function Battle.onbattlePannelHoverChange(widget, hovered)
295
+function Battle.onbattleButtonHoverChange(widget, hovered)
296 296
   if widget.isBattleButton then
297 297
     widget.isHovered = hovered
298 298
     Battle.checkBattleButton(widget)
@@ -345,6 +345,3 @@ function Battle.checkBattleButton(battleButton)
345 345
     lastBattleButtonSwitched = battleButton
346 346
   end
347 347
 end
348
-
349
-connect(g_game, { onGameStart = Battle.create,
350
-                  onGameEnd = Battle.destroy } )

+ 6
- 0
modules/game_battle/battle.otmod View File

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

+ 60
- 54
modules/game_battle/battle.otui View File

@@ -26,66 +26,72 @@ BattlePlayers < BattleIcon
26 26
 
27 27
 BattleNPCs < BattleIcon
28 28
   image-source: /game_battle/battle_npcs.png
29
-  
29
+
30 30
 BattleMonsters < BattleIcon
31 31
   image-source: /game_battle/battle_monsters.png
32 32
 
33 33
 BattleSkulls < BattleIcon
34 34
   image-source: /game_battle/battle_skulls.png
35
-  
35
+
36 36
 BattleParty < BattleIcon
37
-  image-source: /game_battle/battle_party.png    
38
-    
37
+  image-source: /game_battle/battle_party.png
38
+
39 39
 MiniWindow
40 40
   id: battleWindow
41 41
   text: Battle
42
-  height: 250
43
-    
44
-  BattlePlayers
45
-    id: hidePlayers
46
-    tooltip: Hide players
47
-    anchors.top: parent.top
48
-    anchors.right: next.left
49
-    margin-right: 5
50
-    
51
-  BattleNPCs
52
-    id: hideNPCs
53
-    tooltip: Hide Npc's
54
-    anchors.top: parent.top
55
-    anchors.right: next.left
56
-    margin-right: 5
57
-  
58
-  BattleMonsters
59
-    id: hideMonsters
60
-    tooltip: Hide monsters
61
-    anchors.top: parent.top
62
-    anchors.horizontalCenter: parent.horizontalCenter
63
-    
64
-  BattleSkulls
65
-    id: hideSkulls
66
-    tooltip: Hide non-skull players
67
-    anchors.top: prev.top
68
-    anchors.left: prev.right
69
-    margin-left: 5
70
-    
71
-  BattleParty
72
-    id: hideParty
73
-    tooltip: Hide party members
74
-    anchors.top: prev.top
75
-    anchors.left: prev.right
76
-    margin-left: 5
77
-    
78
-  HorizontalSeparator
79
-    anchors.top: prev.bottom
80
-    anchors.left: parent.left
81
-    anchors.right: parent.right
82
-    margin-top: 5
83
-    
84
-  Panel
85
-    id: battlePanel
86
-    anchors.fill: parent
87
-    anchors.top: prev.bottom
88
-    margin-top: 5
89
-    layout: verticalBox
90
-    
91
-    
42
+  height: 100
43
+  icon: battle.png
44
+  @onClose: Battle.toggle()
45
+
46
+  MiniWindowContents
47
+    BattlePlayers
48
+      id: hidePlayers
49
+      tooltip: Hide players
50
+      anchors.top: parent.top
51
+      anchors.right: next.left
52
+      margin-right: 5
53
+
54
+    BattleNPCs
55
+      id: hideNPCs
56
+      tooltip: Hide Npc's
57
+      anchors.top: parent.top
58
+      anchors.right: next.left
59
+      margin-right: 5
60
+
61
+    BattleMonsters
62
+      id: hideMonsters
63
+      tooltip: Hide monsters
64
+      anchors.top: parent.top
65
+      anchors.horizontalCenter: parent.horizontalCenter
66
+
67
+    BattleSkulls
68
+      id: hideSkulls
69
+      tooltip: Hide non-skull players
70
+      anchors.top: prev.top
71
+      anchors.left: prev.right
72
+      margin-left: 5
73
+
74
+    BattleParty
75
+      id: hideParty
76
+      tooltip: Hide party members
77
+      anchors.top: prev.top
78
+      anchors.left: prev.right
79
+      margin-left: 5
80
+
81
+    HorizontalSeparator
82
+      anchors.top: prev.bottom
83
+      anchors.left: parent.left
84
+      anchors.right: parent.right
85
+      margin-top: 5
86
+
87
+    Panel
88
+      id: battlePanel
89
+      anchors.left: parent.left
90
+      anchors.right: parent.right
91
+      anchors.top: prev.bottom
92
+      margin-top: 5
93
+      layout:
94
+        type: verticalBox
95
+        fit-children: true
96
+
97
+

BIN
modules/game_battle/battle.png View File


+ 2
- 2
modules/game_battle/battleButton.otui View File

@@ -4,7 +4,7 @@ BattleButton
4 4
   height: 20
5 5
   margin-top: 5
6 6
   fixed-size: true
7
-  &onHoverChange: Battle.onbattlePannelHoverChange
7
+  &onHoverChange: Battle.onbattleButtonHoverChange
8 8
   &onMouseRelease: Battle.onMouseRelease
9 9
   &isBattleButton: true
10 10
 
@@ -51,4 +51,4 @@ BattleButton
51 51
     anchors.right: parent.right
52 52
     anchors.top: label.bottom
53 53
     margin-top: 2
54
-    phantom: true
54
+    phantom: true

+ 6
- 6
modules/game_combatcontrols/combatcontrols.lua View File

@@ -48,15 +48,15 @@ end
48 48
 
49 49
 -- public functions
50 50
 function CombatControls.init()
51
-  combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
51
+  combatControlsButton = TopMenu.addGameToggleButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
52 52
   combatControlsButton:setOn(true)
53 53
   combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel())
54 54
 
55
-  fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox')
56
-  fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox')
57
-  fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox')
58
-  chaseModeButton = combatControlsWindow:getChildById('chaseModeBox')
59
-  safeFightButton = combatControlsWindow:getChildById('safeFightBox')
55
+  fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox')
56
+  fightBalancedBox = combatControlsWindow:recursiveGetChildById('fightBalancedBox')
57
+  fightDefensiveBox = combatControlsWindow:recursiveGetChildById('fightDefensiveBox')
58
+  chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox')
59
+  safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox')
60 60
 
61 61
   fightModeRadioGroup = RadioGroup.create()
62 62
   fightModeRadioGroup:addWidget(fightOffensiveBox)

+ 25
- 21
modules/game_combatcontrols/combatcontrols.otui View File

@@ -19,25 +19,29 @@ ChaseModeBox < CombatBox
19 19
 SafeFightBox < CombatBox
20 20
   image-source: /game_combatcontrols/icons/safefight.png
21 21
 
22
-UIWindow
23
-  width: 130
24
-  height: 30
25
-  margin-top: 10
26
-  margin-left: 6
27
-  margin-right: 6
22
+MiniWindow
23
+  text: Combat Controls
24
+  icon: combatcontrols.png
25
+  height: 64
26
+  @onClose: CombatControls.toggle()
28 27
 
29
-  FightOffensiveBox
30
-    id: fightOffensiveBox
31
-    anchors.right: next.left
32
-  FightBalancedBox
33
-    id: fightBalancedBox
34
-    anchors.right: next.left
35
-  FightDefensiveBox
36
-    id: fightDefensiveBox
37
-    anchors.horizontalCenter: parent.horizontalCenter
38
-  ChaseModeBox
39
-    id: chaseModeBox
40
-    anchors.left: prev.right
41
-  SafeFightBox
42
-    id: safeFightBox
43
-    anchors.left: prev.right
28
+  MiniWindowContents
29
+    FightOffensiveBox
30
+      id: fightOffensiveBox
31
+      anchors.right: next.left
32
+      anchors.top: next.top
33
+    FightBalancedBox
34
+      id: fightBalancedBox
35
+      anchors.right: next.left
36
+      anchors.top: next.top
37
+    FightDefensiveBox
38
+      id: fightDefensiveBox
39
+      anchors.centerIn: parent
40
+    ChaseModeBox
41
+      id: chaseModeBox
42
+      anchors.left: prev.right
43
+      anchors.top: prev.top
44
+    SafeFightBox
45
+      id: safeFightBox
46
+      anchors.left: prev.right
47
+      anchors.top: prev.top

+ 6
- 6
modules/game_healthbar/healthbar.lua View File

@@ -12,13 +12,13 @@ function HealthBar.init()
12 12
   connect(LocalPlayer, { onHealthChange = HealthBar.onHealthChange,
13 13
                          onManaChange = HealthBar.onManaChange })
14 14
 
15
-  healthBarWindow = displayUI('healthbar.otui', GameInterface.getRightPanel())
15
+  healthBarWindow = displayUI('healthbar.otui', GameInterface.getLeftPanel())
16 16
   healthBarButton = TopMenu.addGameToggleButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle)
17 17
   healthBarButton:setOn(true)
18
-  healthBar = healthBarWindow:getChildById('healthBar')
19
-  manaBar = healthBarWindow:getChildById('manaBar')
20
-  healthLabel = healthBarWindow:getChildById('healthLabel')
21
-  manaLabel = healthBarWindow:getChildById('manaLabel')
18
+  healthBar = healthBarWindow:recursiveGetChildById('healthBar')
19
+  manaBar = healthBarWindow:recursiveGetChildById('manaBar')
20
+  healthLabel = healthBarWindow:recursiveGetChildById('healthLabel')
21
+  manaLabel = healthBarWindow:recursiveGetChildById('manaLabel')
22 22
 
23 23
   if g_game.isOnline() then
24 24
     local localPlayer = g_game.getLocalPlayer()
@@ -32,8 +32,8 @@ function HealthBar.terminate()
32 32
                             onManaChange = HealthBar.onManaChange })
33 33
 
34 34
   healthBarWindow:destroy()
35
-  healthBarWindow = nil
36 35
   healthBarButton:destroy()
36
+  healthBarWindow = nil
37 37
   healthBarButton = nil
38 38
   healthBar = nil
39 39
   manaBar = nil

+ 13
- 13
modules/game_healthbar/healthbar.otui View File

@@ -10,9 +10,10 @@ ManaBar < ProgressBar
10 10
   id: manaBar
11 11
   height: 15
12 12
   background-color: #4444ff
13
-  anchors.bottom: parent.bottom
13
+  anchors.top: prev.bottom
14 14
   anchors.left: parent.left
15 15
   anchors.right: parent.right
16
+  margin-top: 4
16 17
 
17 18
 HealthLabel < GameLabel
18 19
   id: healthLabel
@@ -32,16 +33,15 @@ ManaLabel < GameLabel
32 33
   margin-top: 2
33 34
   text: 0 / 0
34 35
 
35
-BorderlessGameWindow
36
-  id: healthManaPanel
37
-  width: 192
38
-  height: 34
39
-  margin-top: 10
40
-  margin-left: 6
41
-  margin-right: 6
42
-  move-policy: free updated
36
+MiniWindow
37
+  icon: healthbar.png
38
+  id: healthBarWindow
39
+  text: Health Bar
40
+  height: 64
41
+  @onClose: HealthBar.toggle()
43 42
 
44
-  HealthBar
45
-  HealthLabel
46
-  ManaBar
47
-  ManaLabel
43
+  MiniWindowContents
44
+    HealthBar
45
+    HealthLabel
46
+    ManaBar
47
+    ManaLabel

+ 1
- 1
modules/game_hotkeys/hotkeys_manager.lua View File

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

+ 9
- 5
modules/game_inventory/inventory.lua View File

@@ -1,6 +1,7 @@
1 1
 Inventory = {}
2 2
 
3 3
 -- private variables
4
+local inventoryWindow
4 5
 local inventoryPanel
5 6
 local inventoryButton
6 7
 
@@ -13,7 +14,9 @@ function Inventory.init()
13 14
 
14 15
   Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
15 16
 
16
-  inventoryPanel = displayUI('inventory.otui', GameInterface.getRightPanel()):getChildById('inventoryPanel')
17
+  inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
18
+  inventoryWindow.onClose = Inventory.toggle
19
+  inventoryPanel = inventoryWindow:getChildById('contentsPanel')
17 20
   inventoryButton = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
18 21
   inventoryButton:setOn(true)
19 22
 
@@ -30,15 +33,16 @@ function Inventory.terminate()
30 33
 
31 34
   Keyboard.unbindKeyDown('Ctrl+I')
32 35
 
33
-  inventoryPanel:destroy()
34
-  inventoryPanel = nil
36
+  inventoryWindow:destroy()
35 37
   inventoryButton:destroy()
38
+  inventoryWindow = nil
36 39
   inventoryButton = nil
40
+  inventoryPanel = nil
37 41
 end
38 42
 
39 43
 function Inventory.toggle()
40
-  local visible = not inventoryPanel:isExplicitlyVisible()
41
-  inventoryPanel:setVisible(visible)
44
+  local visible = not inventoryWindow:isExplicitlyVisible()
45
+  inventoryWindow:setVisible(visible)
42 46
   inventoryButton:setOn(visible)
43 47
 end
44 48
 

+ 2
- 5
modules/game_inventory/inventory.otui View File

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

+ 27
- 16
modules/game_skills/skills.lua View File

@@ -42,13 +42,37 @@ end
42 42
 
43 43
 -- public functions
44 44
 function Skills.init()
45
-  skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel())
46
-  skillsWindow:hide()
47
-  skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
45
+  connect(LocalPlayer, {
46
+    onExperienceChange = Skills.onExperienceChange,
47
+    onLevelChange = Skills.onLevelChange,
48
+    onHealthChange = Skills.onHealthChange,
49
+    onManaChange = Skills.onManaChange,
50
+    onSoulChange = Skills.onSoulChange,
51
+    onFreeCapacityChange = Skills.onFreeCapacityChange,
52
+    onStaminaChange = Skills.onStaminaChange,
53
+    onMagicLevelChange = Skills.onMagicLevelChange,
54
+    onSkillChange = Skills.onSkillChange
55
+  })
56
+
57
+  skillsWindow = displayUI('skills.otui', GameInterface.getLeftPanel())
58
+  skillsButton = TopMenu.addGameToggleButton('skillsButton', 'Skills (Ctrl+S)', 'skills.png', Skills.toggle)
59
+  skillsButton:setOn(true)
48 60
   Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
49 61
 end
50 62
 
51 63
 function Skills.terminate()
64
+  disconnect(LocalPlayer, {
65
+    onExperienceChange = Skills.onExperienceChange,
66
+    onLevelChange = Skills.onLevelChange,
67
+    onHealthChange = Skills.onHealthChange,
68
+    onManaChange = Skills.onManaChange,
69
+    onSoulChange = Skills.onSoulChange,
70
+    onFreeCapacityChange = Skills.onFreeCapacityChange,
71
+    onStaminaChange = Skills.onStaminaChange,
72
+    onMagicLevelChange = Skills.onMagicLevelChange,
73
+    onSkillChange = Skills.onSkillChange
74
+  })
75
+
52 76
   Keyboard.unbindKeyDown('Ctrl+S')
53 77
   skillsButton:destroy()
54 78
   skillsButton = nil
@@ -122,16 +146,3 @@ function Skills.onSkillChange(localPlayer, id, level, percent)
122 146
   setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
123 147
 end
124 148
 
125
-connect(g_game, { onGameStart = Skills.create,
126
-                onGameEnd = Skills.destroy })
127
-
128
-connect(LocalPlayer, {
129
-                onExperienceChange = Skills.onExperienceChange,
130
-                onLevelChange = Skills.onLevelChange,
131
-                onHealthChange = Skills.onHealthChange,
132
-                onManaChange = Skills.onManaChange,
133
-                onSoulChange = Skills.onSoulChange,
134
-                onFreeCapacityChange = Skills.onFreeCapacityChange,
135
-                onStaminaChange = Skills.onStaminaChange,
136
-                onMagicLevelChange = Skills.onMagicLevelChange,
137
-                onSkillChange = Skills.onSkillChange })

+ 4
- 3
modules/game_skills/skills.otui View File

@@ -28,15 +28,16 @@ SkillPercentPanel < ProgressBar
28 28
   anchors.left: parent.left
29 29
   anchors.right: parent.right
30 30
   anchors.top: parent.top
31
-  tooltip: 0
31
+  phantom: false
32 32
 
33 33
 MiniWindow
34 34
   id: skillWindow
35 35
   text: Skills
36 36
   height: 350
37
+  icon: skills.png
38
+  @onClose: Skills.toggle()
37 39
 
38
-  Panel
39
-    id: skillPanel
40
+  MiniWindowContents
40 41
     anchors.fill: parent
41 42
     layout: verticalBox
42 43
 

BIN
modules/game_skills/skills.png View File


+ 6
- 6
modules/game_viplist/viplist.lua View File

@@ -6,13 +6,13 @@ local vipButton
6 6
 local addVipWindow
7 7
 
8 8
 -- public functions
9
-function VipList.create()
10
-  vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel())
11
-  vipWindow:hide()
12
-  vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
9
+function VipList.init()
10
+  vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
11
+  vipButton = TopMenu.addGameToggleButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
12
+  vipButton:setOn(true)
13 13
 end
14 14
 
15
-function VipList.destroy()
15
+function VipList.terminate()
16 16
   vipWindow:destroy()
17 17
   vipWindow = nil
18 18
   vipButton:destroy()
@@ -41,7 +41,7 @@ end
41 41
 
42 42
 -- hooked events
43 43
 function VipList.onAddVip(id, name, online)
44
-  local vipList = vipWindow:getChildById('vipList')
44
+  local vipList = vipWindow:getChildById('contentsPanel')
45 45
 
46 46
   local label = createWidget('VipListLabel', nil)
47 47
   label:setId('vip' .. id)

+ 4
- 0
modules/game_viplist/viplist.otmod View File

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

+ 3
- 2
modules/game_viplist/viplist.otui View File

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

+ 1
- 1
modules/old/game/game.lua View File

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

+ 1
- 1
src/framework/graphics/texturemanager.cpp View File

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

+ 5
- 0
src/framework/ui/uianchorlayout.cpp View File

@@ -57,6 +57,11 @@ void UIAnchorLayout::removeAnchors(const UIWidgetPtr& anchoredWidget)
57 57
     update();
58 58
 }
59 59
 
60
+bool UIAnchorLayout::hasAnchors(const UIWidgetPtr& anchoredWidget)
61
+{
62
+    return m_anchorsGroups.find(anchoredWidget) != m_anchorsGroups.end();
63
+}
64
+
60 65
 void UIAnchorLayout::centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
61 66
 {
62 67
     addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);

+ 1
- 0
src/framework/ui/uianchorlayout.h View File

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

+ 3
- 1
src/framework/ui/uilayout.cpp View File

@@ -37,8 +37,10 @@ void UILayout::update()
37 37
 
38 38
     m_updating = true;
39 39
     internalUpdate();
40
-    if(UIWidgetPtr parentWidget = getParentWidget())
40
+    if(UIWidgetPtr parentWidget = getParentWidget()) {
41
+        if(!parentWidget->isDestroyed())
41 42
             parentWidget->onLayoutUpdate();
43
+    }
42 44
     m_updating = false;
43 45
 }
44 46
 

+ 2
- 2
src/framework/ui/uimanager.cpp View File

@@ -80,7 +80,7 @@ void UIManager::inputEvent(const InputEvent& event)
80 80
             break;
81 81
         case Fw::MousePressInputEvent:
82 82
             if(event.mouseButton == Fw::MouseLeftButton && m_mouseReceiver->isVisible()) {
83
-                UIWidgetPtr pressedWidget = m_mouseReceiver->recursiveGetChildByPos(event.mousePos);
83
+                UIWidgetPtr pressedWidget = m_mouseReceiver->recursiveGetChildByPos(event.mousePos, false);
84 84
                 if(pressedWidget && !pressedWidget->isEnabled())
85 85
                     pressedWidget = nullptr;
86 86
                 updatePressedWidget(pressedWidget, event.mousePos);
@@ -219,7 +219,7 @@ void UIManager::updateHoveredWidget()
219 219
             return;
220 220
 
221 221
         m_hoverUpdateScheduled = false;
222
-        UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition());
222
+        UIWidgetPtr hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition(), false);
223 223
         if(hoveredWidget && !hoveredWidget->isEnabled())
224 224
             hoveredWidget = nullptr;
225 225
 

+ 19
- 6
src/framework/ui/uiwidget.cpp View File

@@ -635,7 +635,7 @@ void UIWidget::bindRectToParent()
635 635
     Rect boundRect = m_rect;
636 636
     UIWidgetPtr parent = getParent();
637 637
     if(parent) {
638
-        Rect parentRect = parent->getRect();
638
+        Rect parentRect = parent->getClippingRect();
639 639
         boundRect.bind(parentRect);
640 640
     }
641 641
 
@@ -872,6 +872,14 @@ bool UIWidget::isVisible()
872 872
         return asUIWidget() == g_ui.getRootWidget();
873 873
 }
874 874
 
875
+bool UIWidget::isAnchored()
876
+{
877
+    if(UIWidgetPtr parent = getParent())
878
+        if(UIAnchorLayoutPtr anchorLayout = parent->getAnchoredLayout())
879
+            return anchorLayout->hasAnchors(asUIWidget());
880
+    return false;
881
+}
882
+
875 883
 bool UIWidget::isChildLocked(const UIWidgetPtr& child)
876 884
 {
877 885
     auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child);
@@ -1013,7 +1021,7 @@ UIWidgetPtr UIWidget::recursiveGetChildById(const std::string& id)
1013 1021
     return widget;
1014 1022
 }
1015 1023
 
1016
-UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
1024
+UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom)
1017 1025
 {
1018 1026
     if(!containsChildPoint(childPos))
1019 1027
         return nullptr;
@@ -1021,10 +1029,10 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
1021 1029
     for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1022 1030
         const UIWidgetPtr& child = (*it);
1023 1031
         if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
1024
-            UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos);
1032
+            UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos, wantsPhantom);
1025 1033
             if(subChild)
1026 1034
                 return subChild;
1027
-            else if(!child->isPhantom())
1035
+            else if(wantsPhantom || !child->isPhantom())
1028 1036
                 return child;
1029 1037
         }
1030 1038
     }
@@ -1043,8 +1051,7 @@ UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
1043 1051
             UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos);
1044 1052
             if(!subChildren.empty())
1045 1053
                 children.insert(children.end(), subChildren.begin(), subChildren.end());
1046
-            else if(!child->isPhantom())
1047
-                children.push_back(child);
1054
+            children.push_back(child);
1048 1055
         }
1049 1056
     }
1050 1057
     return children;
@@ -1279,6 +1286,12 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
1279 1286
 
1280 1287
     if(m_textWrap && oldRect.size() != newRect.size())
1281 1288
         updateText();
1289
+
1290
+    // move children that is outside the parent rect to inside again
1291
+    for(const UIWidgetPtr& child : m_children) {
1292
+        if(!child->isAnchored())
1293
+            child->bindRectToParent();
1294
+    }
1282 1295
 }
1283 1296
 
1284 1297
 void UIWidget::onLayoutUpdate()

+ 2
- 1
src/framework/ui/uiwidget.h View File

@@ -130,6 +130,7 @@ public:
130 130
     void setVirtualOffset(const Point& offset);
131 131
 
132 132
     bool isVisible();
133
+    bool isAnchored();
133 134
     bool isChildLocked(const UIWidgetPtr& child);
134 135
     bool hasChild(const UIWidgetPtr& child);
135 136
     int getChildIndex(const UIWidgetPtr& child);
@@ -144,7 +145,7 @@ public:
144 145
     UIWidgetPtr getChildByPos(const Point& childPos);
145 146
     UIWidgetPtr getChildByIndex(int index);
146 147
     UIWidgetPtr recursiveGetChildById(const std::string& id);
147
-    UIWidgetPtr recursiveGetChildByPos(const Point& childPos);
148
+    UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom);
148 149
     UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
149 150
     UIWidgetPtr backwardsGetWidgetById(const std::string& id);
150 151
 

Loading…
Cancel
Save