change loadUI/UI.display lua API
This commit is contained in:
parent
63cbe11f7e
commit
55136fe866
|
@ -5,7 +5,7 @@ local about
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function About.create()
|
function About.create()
|
||||||
about = UI.loadAndDisplay("/about/about.otui")
|
about = UI.display('about.otui')
|
||||||
UI.root:lockChild(about)
|
UI.root:lockChild(about)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ local background
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Background.create()
|
function Background.create()
|
||||||
background = UI.loadAndDisplay('/background/background.otui')
|
background = UI.display('background.otui')
|
||||||
end
|
end
|
||||||
|
|
||||||
function Background.destroy()
|
function Background.destroy()
|
||||||
|
|
|
@ -20,7 +20,7 @@ end
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Chat.create()
|
function Chat.create()
|
||||||
chatPanel = loadUI("/chat/chat.otui", Game.gameBottomPanel)
|
chatPanel = UI.display('chat.otui', { parent = Game.gameBottomPanel } )
|
||||||
chatBuffer = chatPanel:getChildById('chatBuffer')
|
chatBuffer = chatPanel:getChildById('chatBuffer')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,7 @@ end
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Console.init()
|
function Console.init()
|
||||||
consoleWidget = UI.loadAndDisplay("/console/console.otui")
|
consoleWidget = UI.display('console.otui', { visible = false })
|
||||||
consoleWidget:hide()
|
|
||||||
connect(consoleWidget, { onKeyPress = onKeyPress })
|
connect(consoleWidget, { onKeyPress = onKeyPress })
|
||||||
|
|
||||||
commandLineEdit = consoleWidget:getChildById('commandLineEdit')
|
commandLineEdit = consoleWidget:getChildById('commandLineEdit')
|
||||||
|
|
|
@ -3,7 +3,7 @@ function table.dump(t, depth)
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
str = string.rep(' ', depth * 2) .. k .. ': '
|
str = string.rep(' ', depth * 2) .. k .. ': '
|
||||||
if type(v) ~= "table" then
|
if type(v) ~= "table" then
|
||||||
print(str .. v)
|
print(str .. tostring(v))
|
||||||
else
|
else
|
||||||
print(str)
|
print(str)
|
||||||
table.dump(v, depth+1)
|
table.dump(v, depth+1)
|
||||||
|
|
|
@ -1,22 +1,38 @@
|
||||||
UI = { }
|
UI = { }
|
||||||
UI.root = getRootWidget()
|
UI.root = getRootWidget()
|
||||||
|
|
||||||
function UI.loadAndDisplayLocked(otuiFile)
|
-- public functions
|
||||||
local widget = loadUI(otuiFile, UI.root)
|
function UI.display(arg1, options)
|
||||||
UI.root:lockChild(widget)
|
local widget
|
||||||
|
local parent
|
||||||
|
if options then parent = options.parent end
|
||||||
|
parent = parent or UI.root
|
||||||
|
|
||||||
|
-- display otui files
|
||||||
|
if type(arg1) == 'string' then
|
||||||
|
local otuiFilePath = resolveFileFullPath(arg1, 2)
|
||||||
|
widget = loadUI(otuiFilePath, parent)
|
||||||
|
-- display already loaded widgets
|
||||||
|
else
|
||||||
|
widget = arg1
|
||||||
|
if parent:hasChild(widget) then
|
||||||
|
widget:focus()
|
||||||
|
widget:show()
|
||||||
|
else
|
||||||
|
parent:addChild(widget)
|
||||||
|
widget:show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- apply display options
|
||||||
|
if widget and options then
|
||||||
|
for option,value in pairs(options) do
|
||||||
|
if option == 'locked' and value then
|
||||||
|
widget:lock()
|
||||||
|
elseif option == 'visible' then
|
||||||
|
widget:setVisible(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
return widget
|
return widget
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.loadAndDisplay(otuiFile)
|
|
||||||
local widget = loadUI(otuiFile, UI.root)
|
|
||||||
return widget
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.display(widget)
|
|
||||||
UI.root:addChild(widget)
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.displayLocked(widget)
|
|
||||||
UI.root:addChild(widget)
|
|
||||||
UI.root:lockChild(widget)
|
|
||||||
end
|
|
||||||
|
|
|
@ -29,3 +29,27 @@ function dumpWidgets()
|
||||||
print(UI.root:getChildByIndex(i):getId())
|
print(UI.root:getChildByIndex(i):getId())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function getCallingScriptSourcePath(depth)
|
||||||
|
depth = depth or 2
|
||||||
|
local info = debug.getinfo(1+depth, "Sn")
|
||||||
|
local path
|
||||||
|
if info.short_src then
|
||||||
|
path = info.short_src:match("(.*)/.*")
|
||||||
|
end
|
||||||
|
if not path then
|
||||||
|
path = '/'
|
||||||
|
elseif path:sub(0, 1) ~= '/' then
|
||||||
|
path = '/' .. path
|
||||||
|
end
|
||||||
|
return path
|
||||||
|
end
|
||||||
|
|
||||||
|
function resolveFileFullPath(filePath, depth)
|
||||||
|
depth = depth or 1
|
||||||
|
if filePath:sub(0, 1) ~= '/' then
|
||||||
|
return getCallingScriptSourcePath(depth+1) .. '/' .. filePath
|
||||||
|
else
|
||||||
|
return filePath
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -56,7 +56,7 @@ function CharacterList.create(characters, premDays)
|
||||||
charactersWindow:destroy()
|
charactersWindow:destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
charactersWindow = UI.loadAndDisplay('/entergame/characterlist.otui')
|
charactersWindow = UI.display('characterlist.otui')
|
||||||
characterList = charactersWindow:getChildById('characterList')
|
characterList = charactersWindow:getChildById('characterList')
|
||||||
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
||||||
charactersWindow.onKeyPress = onCharactersWindowKeyPress
|
charactersWindow.onKeyPress = onCharactersWindowKeyPress
|
||||||
|
|
|
@ -51,7 +51,7 @@ end
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function EnterGame.create()
|
function EnterGame.create()
|
||||||
enterGame = UI.loadAndDisplay('/entergame/entergame.otui')
|
enterGame = UI.display('entergame.otui')
|
||||||
|
|
||||||
local account = Configs.get('account')
|
local account = Configs.get('account')
|
||||||
local password = Configs.get('password')
|
local password = Configs.get('password')
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
function Game.createInterface()
|
function Game.createInterface()
|
||||||
Background.hide()
|
Background.hide()
|
||||||
CharacterList.destroyLoadBox()
|
CharacterList.destroyLoadBox()
|
||||||
Game.gameUi = UI.loadAndDisplay('/game/game.otui')
|
Game.gameUi = UI.display('/game/game.otui')
|
||||||
UI.root:moveChildToIndex(Game.gameUi, 1)
|
UI.root:moveChildToIndex(Game.gameUi, 1)
|
||||||
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
|
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
|
||||||
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
|
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
|
||||||
|
|
|
@ -5,7 +5,7 @@ local healthManaPanel = nil
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function HealthMana.create()
|
function HealthMana.create()
|
||||||
healthManaPanel = loadUI("/health_mana/health_mana.otui", Game.gameRightPanel)
|
healthManaPanel = UI.display('health_mana.otui', { parent = Game.gameRightPanel })
|
||||||
|
|
||||||
local healthBar = UIProgressBar.create()
|
local healthBar = UIProgressBar.create()
|
||||||
healthManaPanel:addChild(healthBar)
|
healthManaPanel:addChild(healthBar)
|
||||||
|
|
|
@ -16,7 +16,7 @@ local InventorySlotAmmo = 10
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Inventory.create()
|
function Inventory.create()
|
||||||
window = loadUI("/inventory/inventory.otui", Game.gameRightPanel)
|
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
|
||||||
|
|
||||||
local itemWidget = window:getChildById('feet')
|
local itemWidget = window:getChildById('feet')
|
||||||
window:setHeight(itemWidget:getPosition().y + itemWidget:getHeight() - window:getPosition().y)
|
window:setHeight(itemWidget:getPosition().y + itemWidget:getHeight() - window:getPosition().y)
|
||||||
|
|
|
@ -10,7 +10,7 @@ function MessageBox.create(title, text, flags)
|
||||||
setmetatable(box, MessageBox)
|
setmetatable(box, MessageBox)
|
||||||
|
|
||||||
-- create messagebox window
|
-- create messagebox window
|
||||||
local window = UI.loadAndDisplayLocked('/messagebox/messagebox.otui')
|
local window = UI.display('messagebox.otui', { locked = true })
|
||||||
window:setTitle(title)
|
window:setTitle(title)
|
||||||
|
|
||||||
local label = window:getChildById('messageBoxLabel')
|
local label = window:getChildById('messageBoxLabel')
|
||||||
|
|
|
@ -43,7 +43,7 @@ end
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Options.create()
|
function Options.create()
|
||||||
options = UI.loadAndDisplayLocked("/options/options.otui")
|
options = UI.display('options.otui', { locked = true })
|
||||||
|
|
||||||
local fpsBox = options:getChildById('fpsCheckBox')
|
local fpsBox = options:getChildById('fpsCheckBox')
|
||||||
local vsyncBox = options:getChildById('vsyncCheckBox')
|
local vsyncBox = options:getChildById('vsyncCheckBox')
|
||||||
|
|
|
@ -61,7 +61,7 @@ local function update()
|
||||||
m_outfit.type = m_outfits[currentOutfit][1]
|
m_outfit.type = m_outfits[currentOutfit][1]
|
||||||
m_outfit.addons = 0
|
m_outfit.addons = 0
|
||||||
m_creature:setOutfit(m_outfit)
|
m_creature:setOutfit(m_outfit)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onColorCheckChange(color)
|
local function onColorCheckChange(color)
|
||||||
|
@ -74,9 +74,9 @@ local function onColorCheckChange(color)
|
||||||
m_currentColor:setChecked(false)
|
m_currentColor:setChecked(false)
|
||||||
local color2 = m_currentColor
|
local color2 = m_currentColor
|
||||||
m_currentColor.onCheckChange = function() onColorCheckChange(color2) end
|
m_currentColor.onCheckChange = function() onColorCheckChange(color2) end
|
||||||
|
|
||||||
m_currentColor = color
|
m_currentColor = color
|
||||||
|
|
||||||
m_outfit.head = m_currentColor.colorId
|
m_outfit.head = m_currentColor.colorId
|
||||||
m_creature:setOutfit(m_outfit)
|
m_creature:setOutfit(m_outfit)
|
||||||
end
|
end
|
||||||
|
@ -96,9 +96,9 @@ end
|
||||||
|
|
||||||
function Outfit.create(creature, outfitList)
|
function Outfit.create(creature, outfitList)
|
||||||
Outfit.destroy()
|
Outfit.destroy()
|
||||||
window = loadUI("/outfit/outfit.otui", UI.root)
|
window = UI.display('outfit.otui', { parent = UI.root })
|
||||||
window:lock()
|
window:lock()
|
||||||
|
|
||||||
m_outfit = creature:getOutfit()
|
m_outfit = creature:getOutfit()
|
||||||
|
|
||||||
local creatureWidget = window:getChildById('creature')
|
local creatureWidget = window:getChildById('creature')
|
||||||
|
@ -115,19 +115,19 @@ function Outfit.create(creature, outfitList)
|
||||||
color:setBackgroundColor(outfitColor)
|
color:setBackgroundColor(outfitColor)
|
||||||
color:setMarginTop(j * 3 + j * 14)
|
color:setMarginTop(j * 3 + j * 14)
|
||||||
color:setMarginLeft(10 + i * 3 + i * 14)
|
color:setMarginLeft(10 + i * 3 + i * 14)
|
||||||
|
|
||||||
if j*19 + i == m_outfit.head then
|
if j*19 + i == m_outfit.head then
|
||||||
m_currentColor = color
|
m_currentColor = color
|
||||||
color:setChecked(true)
|
color:setChecked(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
color.onCheckChange = function() onColorCheckChange(color) end
|
color.onCheckChange = function() onColorCheckChange(color) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
m_creature = creature
|
m_creature = creature
|
||||||
m_outfits = outfitList
|
m_outfits = outfitList
|
||||||
|
|
||||||
currentOutfit = 1
|
currentOutfit = 1
|
||||||
for i=1,#outfitList do
|
for i=1,#outfitList do
|
||||||
if outfitList[i][1] == m_outfit.type then
|
if outfitList[i][1] == m_outfit.type then
|
||||||
|
|
|
@ -11,7 +11,7 @@ function UIItem.onMouseRelease(self, mousePos, mouseButton)
|
||||||
local menuFile = self:getStyle()['popup menu']
|
local menuFile = self:getStyle()['popup menu']
|
||||||
if not menuFile then return end
|
if not menuFile then return end
|
||||||
|
|
||||||
local popupMenu = UI.loadAndDisplay(menuFile)
|
local popupMenu = UI.display(menuFile)
|
||||||
if not popupMenu then return end
|
if not popupMenu then return end
|
||||||
|
|
||||||
popupMenu:moveTo(mousePos)
|
popupMenu:moveTo(mousePos)
|
||||||
|
|
|
@ -6,7 +6,7 @@ local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fightin
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function Skills.create()
|
function Skills.create()
|
||||||
skillWindow = loadUI("/skills/skills.otui", Game.gameRightPanel)
|
skillWindow = UI.display('skills.otui', { parent = Game.gameRightPanel })
|
||||||
|
|
||||||
local skillPanel = skillWindow:getChildById('skillPanel')
|
local skillPanel = skillWindow:getChildById('skillPanel')
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ end
|
||||||
function ToolTip.display(text)
|
function ToolTip.display(text)
|
||||||
if text then
|
if text then
|
||||||
ToolTip.hide()
|
ToolTip.hide()
|
||||||
currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
|
currentToolTip = UI.display('tooltip.otui')
|
||||||
currentToolTip.onMouseMove = moveToolTip
|
currentToolTip.onMouseMove = moveToolTip
|
||||||
local label = currentToolTip:getChildById('toolTipText')
|
local label = currentToolTip:getChildById('toolTipText')
|
||||||
label:setText(text)
|
label:setText(text)
|
||||||
|
|
|
@ -5,7 +5,7 @@ local topMenu
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function TopMenu.create()
|
function TopMenu.create()
|
||||||
topMenu = UI.loadAndDisplay("/topmenu/topmenu.otui")
|
topMenu = UI.display('topmenu.otui')
|
||||||
end
|
end
|
||||||
|
|
||||||
function TopMenu.destroy()
|
function TopMenu.destroy()
|
||||||
|
|
|
@ -5,7 +5,7 @@ local vipWindow = nil
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function VipList.create()
|
function VipList.create()
|
||||||
vipWindow = loadUI("/viplist/viplist.otui", Game.gameRightPanel)
|
vipWindow = UI.display('viplist.otui', { parent = Game.gameRightPanel })
|
||||||
end
|
end
|
||||||
|
|
||||||
function VipList.destroy()
|
function VipList.destroy()
|
||||||
|
|
|
@ -156,10 +156,14 @@ void UIWidget::setStyleFromNode(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
void UIWidget::setParent(const UIWidgetPtr& parent)
|
void UIWidget::setParent(const UIWidgetPtr& parent)
|
||||||
{
|
{
|
||||||
UIWidgetPtr self = asUIWidget();
|
|
||||||
|
|
||||||
// remove from old parent
|
// remove from old parent
|
||||||
UIWidgetPtr oldParent = getParent();
|
UIWidgetPtr oldParent = getParent();
|
||||||
|
|
||||||
|
// the parent is already the same
|
||||||
|
if(oldParent == parent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UIWidgetPtr self = asUIWidget();
|
||||||
if(oldParent && oldParent->hasChild(self))
|
if(oldParent && oldParent->hasChild(self))
|
||||||
oldParent->removeChild(self);
|
oldParent->removeChild(self);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue