Browse Source

new lua function for creating widgets: createWidget

Eduardo Bart 9 years ago
parent
commit
05230f44e4

+ 2
- 2
modules/addon_console/commands.lua View File

@@ -1,5 +1,5 @@
1 1
 function dumpWidgets()
2
-  for i=1,UI.root:getChildCount() do
3
-    print(UI.root:getChildByIndex(i):getId())
2
+  for i=1,rootWidget:getChildCount() do
3
+    print(rootWidget:getChildByIndex(i):getId())
4 4
   end
5 5
 end

+ 2
- 4
modules/addon_console/console.lua View File

@@ -120,7 +120,7 @@ end
120 120
 
121 121
 -- public functions
122 122
 function Console.init()
123
-  consoleWidget = UI.display('console.otui', { visible = false })
123
+  consoleWidget = displayUI('console.otui', { visible = false })
124 124
   connect(consoleWidget, { onKeyPress = onKeyPress })
125 125
 
126 126
   commandLineEdit = consoleWidget:getChildById('commandLineEdit')
@@ -139,10 +139,8 @@ end
139 139
 function Console.addLine(text, color)
140 140
   -- create new line label
141 141
   local numLines = consoleBuffer:getChildCount() + 1
142
-  local label = UILabel.create()
143
-  consoleBuffer:addChild(label)
142
+  local label = createWidget('ConsoleLabel', consoleBuffer)
144 143
   label:setId('consoleLabel' .. numLines)
145
-  label:setStyle('ConsoleLabel')
146 144
   label:setText(text)
147 145
   label:setForegroundColor(color)
148 146
 

+ 2
- 3
modules/addon_playground/playground.lua View File

@@ -1,10 +1,9 @@
1 1
 -- place any code for testing purposes here
2 2
 
3 3
 function init()
4
-  local box = UIComboBox.create()
5
-  box:setStyle('ComboBox')
4
+  local box = createWidget('ComboBox')
6 5
   box:moveTo({x=100, y=8})
7
-  UI.display(box)
6
+  displayUI(box)
8 7
 end
9 8
 
10 9
 addEvent(init)

+ 1
- 1
modules/client_about/about.lua View File

@@ -5,7 +5,7 @@ local aboutWindow
5 5
 
6 6
 -- public functions
7 7
 function About.create()
8
-  aboutWindow = UI.display('about.otui', { locked = true })
8
+  aboutWindow = displayUI('about.otui', { locked = true })
9 9
 end
10 10
 
11 11
 function About.destroy()

+ 1
- 1
modules/client_background/background.lua View File

@@ -5,7 +5,7 @@ local background
5 5
 
6 6
 -- public functions
7 7
 function Background.create()
8
-  background = UI.display('background.otui')
8
+  background = displayUI('background.otui')
9 9
 end
10 10
 
11 11
 function Background.destroy()

+ 2
- 4
modules/client_entergame/characterlist.lua View File

@@ -56,7 +56,7 @@ function CharacterList.create(characters, premDays)
56 56
     charactersWindow:destroy()
57 57
   end
58 58
 
59
-  charactersWindow = UI.display('characterlist.otui')
59
+  charactersWindow = displayUI('characterlist.otui')
60 60
   characterList = charactersWindow:getChildById('characterList')
61 61
   local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
62 62
   charactersWindow.onKeyPress = onCharactersWindowKeyPress
@@ -68,10 +68,8 @@ function CharacterList.create(characters, premDays)
68 68
     local worldHost = characterInfo[3]
69 69
     local worldIp = characterInfo[4]
70 70
 
71
-    local label = UILabel.create()
72
-    characterList:addChild(label)
71
+    local label = createWidget('CharacterListLabel', characterList)
73 72
     label:setText(characterName .. '  (' .. worldName .. ')')
74
-    label:setStyle('CharacterListLabel')
75 73
     label.characterName = characterName
76 74
     label.worldHost = worldHost
77 75
     label.worldPort = worldIp

+ 1
- 1
modules/client_entergame/entergame.lua View File

@@ -51,7 +51,7 @@ end
51 51
 
52 52
 -- public functions
53 53
 function EnterGame.create()
54
-  enterGame = UI.display('entergame.otui')
54
+  enterGame = displayUI('entergame.otui')
55 55
 
56 56
   local account = g_configs.get('account')
57 57
   local password = g_configs.get('password')

+ 2
- 2
modules/client_options/options.lua View File

@@ -36,14 +36,14 @@ end
36 36
 
37 37
 function Options.enableFps(on)
38 38
   fpsEnabled = on
39
-  local frameCounter = UI.root:recursiveGetChildById('frameCounter')
39
+  local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
40 40
   frameCounter:setVisible(on)
41 41
   setConfig('showfps', on)
42 42
 end
43 43
 
44 44
 -- public functions
45 45
 function Options.create()
46
-  options = UI.display('options.otui', { locked = true })
46
+  options = displayUI('options.otui', { locked = true })
47 47
 
48 48
   local fpsBox = options:getChildById('fpsCheckBox')
49 49
   local vsyncBox = options:getChildById('vsyncCheckBox')

+ 1
- 1
modules/client_topmenu/topmenu.lua View File

@@ -5,7 +5,7 @@ local topMenu
5 5
 
6 6
 -- public functions
7 7
 function TopMenu.create()
8
-  topMenu = UI.display('topmenu.otui')
8
+  topMenu = displayUI('topmenu.otui')
9 9
 end
10 10
 
11 11
 function TopMenu.destroy()

+ 1
- 1
modules/core/core.otmod View File

@@ -10,8 +10,8 @@ Module
10 10
 
11 11
   // NOTE: order does matter
12 12
   dependencies:
13
+    - core_scripts
13 14
     - core_fonts
14 15
     - core_styles
15
-    - core_scripts
16 16
     - core_widgets
17 17
 

+ 20
- 5
modules/core_scripts/ui.lua View File

@@ -1,17 +1,21 @@
1
-UI = { }
2
-UI.root = getRootWidget()
1
+-- globals
2
+rootWidget = g_ui.getRootWidget()
3 3
 
4 4
 -- public functions
5
-function UI.display(arg1, options)
5
+function importStyle(otui)
6
+  g_ui.importStyle(resolveFileFullPath(otui, 2))
7
+end
8
+
9
+function displayUI(arg1, options)
6 10
   local widget
7 11
   local parent
8 12
   if options then parent = options.parent end
9
-  parent = parent or UI.root
13
+  parent = parent or rootWidget
10 14
 
11 15
   -- display otui files
12 16
   if type(arg1) == 'string' then
13 17
     local otuiFilePath = resolveFileFullPath(arg1, 2)
14
-    widget = loadUI(otuiFilePath, parent)
18
+    widget = g_ui.loadUI(otuiFilePath, parent)
15 19
   -- display already loaded widgets
16 20
   else
17 21
     widget = arg1
@@ -40,3 +44,14 @@ function UI.display(arg1, options)
40 44
   end
41 45
   return widget
42 46
 end
47
+
48
+function createWidget(style, parent)
49
+  local className = g_ui.getStyleClass(style)
50
+  local class = _G[className]
51
+  local widget = class.create()
52
+  if parent then
53
+    parent:addChild(widget)
54
+  end
55
+  widget:setStyle(style)
56
+  return widget
57
+end

+ 12
- 12
modules/core_styles/core_styles.otmod View File

@@ -5,16 +5,16 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    importStyles 'styles/buttons.otui'
9
-    importStyles 'styles/labels.otui'
10
-    importStyles 'styles/panels.otui'
11
-    importStyles 'styles/separators.otui'
12
-    importStyles 'styles/lineedits.otui'
13
-    importStyles 'styles/checkboxes.otui'
14
-    importStyles 'styles/windows.otui'
15
-    importStyles 'styles/listboxes.otui'
16
-    importStyles 'styles/items.otui'
17
-    importStyles 'styles/creatures.otui'
18
-    importStyles 'styles/comboboxes.otui'
19
-    importStyles 'styles/popupmenus.otui'
8
+    importStyle 'styles/buttons.otui'
9
+    importStyle 'styles/labels.otui'
10
+    importStyle 'styles/panels.otui'
11
+    importStyle 'styles/separators.otui'
12
+    importStyle 'styles/lineedits.otui'
13
+    importStyle 'styles/checkboxes.otui'
14
+    importStyle 'styles/windows.otui'
15
+    importStyle 'styles/listboxes.otui'
16
+    importStyle 'styles/items.otui'
17
+    importStyle 'styles/creatures.otui'
18
+    importStyle 'styles/comboboxes.otui'
19
+    importStyle 'styles/popupmenus.otui'
20 20
     return true

+ 2
- 0
modules/core_styles/styles/popupmenus.otui View File

@@ -35,6 +35,8 @@ PopupMenuSeparator < UIWidget
35 35
 
36 36
 PopupMenu < UIPopupMenu
37 37
   width: 100
38
+  button-style: PopupMenuButton
39
+  separator-style: PopupMenuSeparator
38 40
   border-image:
39 41
     source: /core_styles/images/menubox.png
40 42
     border: 3

+ 1
- 1
modules/core_widgets/messagebox/messagebox.lua View File

@@ -10,7 +10,7 @@ function MessageBox.create(title, text, flags)
10 10
   setmetatable(box, MessageBox)
11 11
 
12 12
   -- create messagebox window
13
-  local window = UI.display('messagebox.otui', { locked = true })
13
+  local window = displayUI('messagebox.otui', { locked = true })
14 14
   window:setTitle(title)
15 15
 
16 16
   local label = window:getChildById('messageBoxLabel')

+ 1
- 1
modules/core_widgets/tooltip/tooltip.lua View File

@@ -20,7 +20,7 @@ end
20 20
 function ToolTip.display(text)
21 21
   if text then
22 22
     ToolTip.hide()
23
-    currentToolTip = UI.display('tooltip.otui')
23
+    currentToolTip = displayUI('tooltip.otui')
24 24
     currentToolTip.onMouseMove = moveToolTip
25 25
     local label = currentToolTip:getChildById('toolTipText')
26 26
     label:setText(text)

+ 12
- 8
modules/core_widgets/uipopupmenu.lua View File

@@ -7,12 +7,11 @@ function UIPopupMenu.create()
7 7
   local layout = UIVerticalLayout.create(menu)
8 8
   layout:setFitParent(true)
9 9
   menu:setLayout(layout)
10
-  menu:setStyle('PopupMenu')
11 10
   return menu
12 11
 end
13 12
 
14 13
 function UIPopupMenu.display(menu, pos)
15
-  UI.display(menu, {x = pos.x, y = pos.y})
14
+  displayUI(menu, {x = pos.x, y = pos.y})
16 15
   menu:bindRectToParent()
17 16
   menu:grabMouse()
18 17
   menu:grabKeyboard()
@@ -20,21 +19,17 @@ function UIPopupMenu.display(menu, pos)
20 19
 end
21 20
 
22 21
 function UIPopupMenu.addOption(menu, optionName, optionCallback)
23
-  local optionWidget = UIButton.create()
22
+  local optionWidget = createWidget(menu.buttonStyle, menu)
24 23
   local lastOptionWidget = menu:getLastChild()
25 24
   optionWidget.onClick = function()
26 25
     optionCallback()
27 26
     menu:destroy()
28 27
   end
29 28
   optionWidget:setText(optionName)
30
-  optionWidget:setStyle('PopupMenuButton')
31
-  menu:addChild(optionWidget)
32 29
 end
33 30
 
34 31
 function UIPopupMenu.addSeparator(menu)
35
-  local separatorWidget = UIWidget.create()
36
-  separatorWidget:setStyle('PopupMenuSeparator')
37
-  menu:addChild(separator)
32
+  local separatorWidget = createWidget(menu.separatorStyle, separator)
38 33
 end
39 34
 
40 35
 -- hooked events
@@ -54,3 +49,12 @@ function UIPopupMenu.onKeyPress(menu, keyCode, keyText, keyboardModifiers)
54 49
   end
55 50
   return false
56 51
 end
52
+
53
+function UIPopupMenu.onStyleApply(menu, style)
54
+  if style['button-style'] then
55
+    menu.buttonStyle = style['button-style']
56
+  end
57
+  if style['separator-style'] then
58
+    menu.separatorStyle = style['separator-style']
59
+  end
60
+end

+ 2
- 2
modules/game/game.lua View File

@@ -16,8 +16,8 @@ end
16 16
 function Game.createInterface()
17 17
   Background.hide()
18 18
   CharacterList.destroyLoadBox()
19
-  Game.gameUi = UI.display('game.otui')
20
-  UI.root:moveChildToIndex(Game.gameUi, 1)
19
+  Game.gameUi = displayUI('game.otui')
20
+  rootWidget:moveChildToIndex(Game.gameUi, 1)
21 21
   Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
22 22
   Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
23 23
   Game.gameBottomPanel = Game.gameUi:getChildById('bottomPanel')

+ 2
- 3
modules/game_chat/chat.lua View File

@@ -12,15 +12,14 @@ local function onCreatureSpeak(name, level, msgtype, message)
12 12
       style = 'YellowChatLabel'
13 13
   end
14 14
 
15
-  local label = UILabel.create()
16
-  label:setStyle(style)
15
+  local label = createWidget(style)
17 16
   label:setText(message)
18 17
   chatBuffer:addChild(label)
19 18
 end
20 19
 
21 20
 -- public functions
22 21
 function Chat.create()
23
-  chatPanel = UI.display('chat.otui', { parent = Game.gameBottomPanel } )
22
+  chatPanel = displayUI('chat.otui', { parent = Game.gameBottomPanel } )
24 23
   chatBuffer = chatPanel:getChildById('chatBuffer')
25 24
 end
26 25
 

+ 5
- 13
modules/game_healthbar/healthbar.lua View File

@@ -5,28 +5,20 @@ local healthManaPanel = nil
5 5
 
6 6
 -- public functions
7 7
 function HealthBar.create()
8
-  healthManaPanel = UI.display('healthbar.otui', { parent = Game.gameRightPanel })
8
+  healthManaPanel = displayUI('healthbar.otui', { parent = Game.gameRightPanel })
9 9
 
10
-  local healthBar = UIProgressBar.create()
11
-  healthManaPanel:addChild(healthBar)
10
+  local healthBar = createWidget('HealthBar', healthManaPanel)
12 11
   healthBar:setId('healthBar')
13
-  healthBar:setStyle('HealthBar')
14 12
 
15
-  local healthLabel = UILabel.create()
16
-  healthManaPanel:addChild(healthLabel)
13
+  local healthLabel = createWidget('HealthLabel', healthManaPanel)
17 14
   healthLabel:setId('healthLabel')
18
-  healthLabel:setStyle('HealthLabel')
19 15
   healthLabel:setText('0 / 0')
20 16
 
21
-  local manaBar = UIProgressBar.create()
22
-  healthManaPanel:addChild(manaBar)
17
+  local manaBar = createWidget('ManaBar', healthManaPanel)
23 18
   manaBar:setId('manaBar')
24
-  manaBar:setStyle('ManaBar')
25 19
 
26
-  local manaLabel = UILabel.create()
27
-  healthManaPanel:addChild(manaLabel)
20
+  local manaLabel = createWidget('ManaLabel', healthManaPanel)
28 21
   manaLabel:setId('manaLabel')
29
-  manaLabel:setStyle('ManaLabel')
30 22
   manaLabel:setText('0 / 0')
31 23
 
32 24
   healthManaPanel:setHeight(healthBar:getHeight() + manaBar:getHeight() + 4)

+ 6
- 7
modules/game_inventory/inventory.lua View File

@@ -5,7 +5,7 @@ local window = nil
5 5
 
6 6
 -- public functions
7 7
 function Inventory.create()
8
-  window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
8
+  window = displayUI('inventory.otui', { parent = Game.gameRightPanel })
9 9
 end
10 10
 
11 11
 function Inventory.destroy()
@@ -31,24 +31,23 @@ end
31 31
 
32 32
 function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
33 33
   if mouseButton ~= MouseRightButton then return end
34
-  
34
+
35 35
   local item = itemWidget:getItem()
36 36
   if not item then return end
37
-  
38
-  local menu = UIPopupMenu.create()
39
-  
37
+
38
+  local menu = createWidget('PopupMenu')
39
+
40 40
   -- Look
41 41
   local itemId = item:getId()
42 42
   local slotId = tonumber(itemWidget:getId():sub(5))
43 43
   menu:addOption('Look', function() Game.lookAtInventory(itemId, slotId) end)
44
-  
44
+
45 45
   -- Open or Use, depending if thing is a container
46 46
   if item:isContainer() then
47 47
     menu:addOption('Open', function() print('open') end)
48 48
   else
49 49
     menu:addOption('Use', function() print('use') end)
50 50
   end
51
-  
52 51
   menu:display(mousePos)
53 52
 end
54 53
 

+ 0
- 5
modules/game_inventory/itempopupmenu.otui View File

@@ -1,5 +0,0 @@
1
-PopupMenu
2
-  PopupMenuFirstButton
3
-    text: Look
4
-  PopupMenuLastButton
5
-    text: Use

+ 6
- 11
modules/game_outfit/outfit.lua View File

@@ -40,7 +40,7 @@ local function onColorCheckChange(color)
40 40
     elseif m_currentClothe:getId() == 'detail' then
41 41
       m_outfit.feet = m_currentColor.colorId
42 42
     end
43
-      
43
+
44 44
     m_creature:setOutfit(m_outfit)
45 45
   end
46 46
 end
@@ -56,7 +56,7 @@ local function onClotheCheckChange(clothe)
56 56
     m_currentClothe.onCheckChange = onClotheCheckChange
57 57
 
58 58
     m_currentClothe = clothe
59
-    
59
+
60 60
     local color = 0
61 61
     if m_currentClothe:getId() == 'head' then
62 62
       color = m_outfit.head
@@ -119,10 +119,8 @@ end
119 119
 
120 120
 -- public functions
121 121
 function Outfit.test()
122
-  local button = UIButton.create()
123
-  UI.root:addChild(button)
122
+  local button = createWidget('Button', rootWidget)
124 123
   button:setText('Set Outfit')
125
-  button:setStyle('Button')
126 124
   button:moveTo({x = 0, y = 100})
127 125
   button:setWidth('100')
128 126
   button:setHeight('30')
@@ -131,11 +129,11 @@ end
131 129
 
132 130
 function Outfit.create(creature, outfitList)
133 131
   Outfit.destroy()
134
-  window = UI.display('outfit.otui', { parent = UI.root })
132
+  window = displayUI('outfit.otui', { parent = rootWidget })
135 133
   window:lock()
136 134
 
137 135
   m_outfit = creature:getOutfit()
138
-  
136
+
139 137
   m_currentClothe = window:getChildById('head')
140 138
   window:getChildById('head').onCheckChange = onClotheCheckChange
141 139
   window:getChildById('primary').onCheckChange = onClotheCheckChange
@@ -147,13 +145,10 @@ function Outfit.create(creature, outfitList)
147 145
 
148 146
   for i=0,18 do
149 147
     for j=0,6 do
150
-      local color = UICheckBox.create()
151
-      window:addChild(color)
152
-
148
+      local color = createWidget('Color', window)
153 149
       local outfitColor = getOufitColor(j*19 + i)
154 150
       color:setId('color' .. j*19+i)
155 151
       color.colorId = j*19 + i
156
-      color:setStyle('Color')
157 152
       color:setBackgroundColor(outfitColor)
158 153
       color:setMarginTop(j * 3 + j * 14)
159 154
       color:setMarginLeft(10 + i * 3 + i * 14)

+ 1
- 1
modules/game_skills/skills.lua View File

@@ -41,7 +41,7 @@ end
41 41
 
42 42
 -- public functions
43 43
 function Skills.create()
44
-  skillWindow = UI.display('skills.otui', { parent = Game.gameRightPanel })
44
+  skillWindow = displayUI('skills.otui', { parent = Game.gameRightPanel })
45 45
 end
46 46
 
47 47
 function Skills.destroy()

+ 15
- 18
modules/game_textmessage/textmessage.lua View File

@@ -1,37 +1,34 @@
1 1
 TextMessage = {}
2 2
 
3 3
 -- require styles
4
-importStyles 'textmessage.otui'
4
+importStyle 'textmessage.otui'
5 5
 
6 6
 -- private variables
7 7
 local bottomLabelWidget, centerLabelWidget
8 8
 local messageTypes = {
9 9
   first = 12,
10
-  { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
11
-  { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
12
-  { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
13
-  { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
14
-  { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
15
-  { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
16
-  { type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
17
-  { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
18
-  { type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
19
-  { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
10
+  { msgtype = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
11
+  { msgtype = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
12
+  { msgtype = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
13
+  { msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
14
+  { msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
15
+  { msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
16
+  { msgtype = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
17
+  { msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
18
+  { msgtype = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
19
+  { msgtype = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
20 20
 }
21 21
 local hideEvent
22 22
 
23 23
 -- public functions
24 24
 function TextMessage.create()
25
-  bottomLabelWidget = UILabel.create()
26
-  Game.gameMapPanel:addChild(bottomLabelWidget)
27
-
28
-  centerLabelWidget = UILabel.create()
29
-  Game.gameMapPanel:addChild(centerLabelWidget)
25
+  bottomLabelWidget = createWidget('UILabel', Game.gameMapPanel)
26
+  centerLabelWidget = createWidget('UILabel', Game.gameMapPanel)
30 27
 end
31 28
 
32 29
 -- hooked events
33
-function TextMessage.onTextMessage(type, message)
34
-  local messageType = messageTypes[type - messageTypes.first]
30
+function TextMessage.onTextMessage(msgtype, message)
31
+  local messageType = messageTypes[msgtype - messageTypes.first]
35 32
 
36 33
   if messageType.showOnConsole then
37 34
     -- TODO

+ 2
- 4
modules/game_viplist/viplist.lua View File

@@ -5,7 +5,7 @@ local vipWindow = nil
5 5
 
6 6
 -- public functions
7 7
 function VipList.create()
8
-  vipWindow = UI.display('viplist.otui', { parent = Game.gameRightPanel })
8
+  vipWindow = displayUI('viplist.otui', { parent = Game.gameRightPanel })
9 9
 end
10 10
 
11 11
 function VipList.destroy()
@@ -17,11 +17,9 @@ end
17 17
 function Game.onAddVip(id, name, online)
18 18
   local vipList = vipWindow:getChildById('vipList')
19 19
 
20
-  local label = UILabel.create()
21
-  vipList:addChild(label)
20
+  local label = createWidget('VipListLabel', vipList)
22 21
   label:setId('vip' .. id)
23 22
   label:setText(name)
24
-  label:setStyle('VipListLabel')
25 23
 
26 24
   if online then
27 25
     label:setForegroundColor('#00ff00')

+ 7
- 4
src/framework/luafunctions.cpp View File

@@ -241,7 +241,13 @@ void Application::registerLuaFunctions()
241 241
     g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
242 242
     g_lua.bindClassStaticFunction<Logger>("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
243 243
 
244
-    // Font
244
+    // UI
245
+    g_lua.registerStaticClass("g_ui");
246
+    g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1));
247
+    g_lua.bindClassStaticFunction("g_ui", "getStyle", std::bind(&UIManager::getStyle, &g_ui, _1));
248
+    g_lua.bindClassStaticFunction("g_ui", "getStyleClass", std::bind(&UIManager::getStyleClass, &g_ui, _1));
249
+    g_lua.bindClassStaticFunction("g_ui", "loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2));
250
+    g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
245 251
 
246 252
     /*
247 253
     // FontManager
@@ -260,8 +266,5 @@ void Application::registerLuaFunctions()
260 266
 
261 267
     // global functions
262 268
     g_lua.bindGlobalFunction("importFont", std::bind(&FontManager::importFont, &g_fonts, _1));
263
-    g_lua.bindGlobalFunction("importStyles", std::bind(&UIManager::importStyles, &g_ui, _1));
264 269
     g_lua.bindGlobalFunction("setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
265
-    g_lua.bindGlobalFunction("loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2));
266
-    g_lua.bindGlobalFunction("getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
267 270
 }

+ 15
- 1
src/framework/luascript/luavaluecasts.cpp View File

@@ -226,7 +226,7 @@ bool luavalue_cast(int index, Size& size)
226 226
 }
227 227
 
228 228
 // otml nodes
229
-void push_luavalue(const OTMLNodePtr& node)
229
+void push_otml_subnode_luavalue(const OTMLNodePtr& node)
230 230
 {
231 231
     if(node->hasValue()) {
232 232
         g_lua.pushString(node->value());
@@ -251,6 +251,20 @@ void push_luavalue(const OTMLNodePtr& node)
251 251
         g_lua.pushNil();
252 252
 }
253 253
 
254
+void push_luavalue(const OTMLNodePtr& node)
255
+{
256
+    g_lua.newTable();
257
+    for(const OTMLNodePtr& cnode : node->children()) {
258
+        if(cnode->isUnique()) {
259
+            push_otml_subnode_luavalue(cnode);
260
+            if(!g_lua.isNil()) {
261
+                g_lua.setField(cnode->tag());
262
+            } else
263
+                g_lua.pop();
264
+        }
265
+    }
266
+}
267
+
254 268
 bool luavalue_cast(int index, OTMLNodePtr& node)
255 269
 {
256 270
     node = OTMLNode::create();

+ 11
- 3
src/framework/ui/uimanager.cpp View File

@@ -81,7 +81,7 @@ void UIManager::inputEvent(const InputEvent& event)
81 81
     };
82 82
 }
83 83
 
84
-bool UIManager::importStyles(const std::string& file)
84
+bool UIManager::importStyle(const std::string& file)
85 85
 {
86 86
     try {
87 87
         OTMLDocumentPtr doc = OTMLDocument::parse(file);
@@ -135,13 +135,21 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
135 135
     // styles starting with UI are automatically defined
136 136
     if(boost::starts_with(styleName, "UI")) {
137 137
         OTMLNodePtr node = OTMLNode::create();
138
-        node->writeAt("__widgetType", styleName);
138
+        node->writeAt("__class", styleName);
139 139
         return node;
140 140
     }
141 141
 
142 142
     return nullptr;
143 143
 }
144 144
 
145
+std::string UIManager::getStyleClass(const std::string& styleName)
146
+{
147
+    OTMLNodePtr style = getStyle(styleName);
148
+    if(style && style->get("__class"))
149
+        return style->valueAt("__class");
150
+    return "";
151
+}
152
+
145 153
 UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent)
146 154
 {
147 155
     try {
@@ -176,7 +184,7 @@ UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const U
176 184
     OTMLNodePtr styleNode = originalStyleNode->clone();
177 185
     styleNode->merge(widgetNode);
178 186
 
179
-    std::string widgetType = styleNode->valueAt("__widgetType");
187
+    std::string widgetType = styleNode->valueAt("__class");
180 188
 
181 189
     // call widget creation from lua
182 190
     UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create");

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

@@ -37,9 +37,10 @@ public:
37 37
     void resize(const Size& size);
38 38
     void inputEvent(const InputEvent& event);
39 39
 
40
-    bool importStyles(const std::string& file);
40
+    bool importStyle(const std::string& file);
41 41
     void importStyleFromOTML(const OTMLNodePtr& styleNode);
42 42
     OTMLNodePtr getStyle(const std::string& styleName);
43
+    std::string getStyleClass(const std::string& styleName);
43 44
 
44 45
     UIWidgetPtr loadUI(const std::string& file, const UIWidgetPtr& parent = nullptr);
45 46
     UIWidgetPtr loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);

Loading…
Cancel
Save