change loadUI/UI.display lua API
This commit is contained in:
parent
63cbe11f7e
commit
55136fe866
|
@ -5,7 +5,7 @@ local about
|
|||
|
||||
-- public functions
|
||||
function About.create()
|
||||
about = UI.loadAndDisplay("/about/about.otui")
|
||||
about = UI.display('about.otui')
|
||||
UI.root:lockChild(about)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ local background
|
|||
|
||||
-- public functions
|
||||
function Background.create()
|
||||
background = UI.loadAndDisplay('/background/background.otui')
|
||||
background = UI.display('background.otui')
|
||||
end
|
||||
|
||||
function Background.destroy()
|
||||
|
|
|
@ -20,7 +20,7 @@ end
|
|||
|
||||
-- public functions
|
||||
function Chat.create()
|
||||
chatPanel = loadUI("/chat/chat.otui", Game.gameBottomPanel)
|
||||
chatPanel = UI.display('chat.otui', { parent = Game.gameBottomPanel } )
|
||||
chatBuffer = chatPanel:getChildById('chatBuffer')
|
||||
end
|
||||
|
||||
|
|
|
@ -120,8 +120,7 @@ end
|
|||
|
||||
-- public functions
|
||||
function Console.init()
|
||||
consoleWidget = UI.loadAndDisplay("/console/console.otui")
|
||||
consoleWidget:hide()
|
||||
consoleWidget = UI.display('console.otui', { visible = false })
|
||||
connect(consoleWidget, { onKeyPress = onKeyPress })
|
||||
|
||||
commandLineEdit = consoleWidget:getChildById('commandLineEdit')
|
||||
|
|
|
@ -3,7 +3,7 @@ function table.dump(t, depth)
|
|||
for k,v in pairs(t) do
|
||||
str = string.rep(' ', depth * 2) .. k .. ': '
|
||||
if type(v) ~= "table" then
|
||||
print(str .. v)
|
||||
print(str .. tostring(v))
|
||||
else
|
||||
print(str)
|
||||
table.dump(v, depth+1)
|
||||
|
|
|
@ -1,22 +1,38 @@
|
|||
UI = { }
|
||||
UI.root = getRootWidget()
|
||||
|
||||
function UI.loadAndDisplayLocked(otuiFile)
|
||||
local widget = loadUI(otuiFile, UI.root)
|
||||
UI.root:lockChild(widget)
|
||||
-- public functions
|
||||
function UI.display(arg1, options)
|
||||
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
|
||||
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())
|
||||
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()
|
||||
end
|
||||
|
||||
charactersWindow = UI.loadAndDisplay('/entergame/characterlist.otui')
|
||||
charactersWindow = UI.display('characterlist.otui')
|
||||
characterList = charactersWindow:getChildById('characterList')
|
||||
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
||||
charactersWindow.onKeyPress = onCharactersWindowKeyPress
|
||||
|
|
|
@ -51,7 +51,7 @@ end
|
|||
|
||||
-- public functions
|
||||
function EnterGame.create()
|
||||
enterGame = UI.loadAndDisplay('/entergame/entergame.otui')
|
||||
enterGame = UI.display('entergame.otui')
|
||||
|
||||
local account = Configs.get('account')
|
||||
local password = Configs.get('password')
|
||||
|
|
|
@ -16,7 +16,7 @@ end
|
|||
function Game.createInterface()
|
||||
Background.hide()
|
||||
CharacterList.destroyLoadBox()
|
||||
Game.gameUi = UI.loadAndDisplay('/game/game.otui')
|
||||
Game.gameUi = UI.display('/game/game.otui')
|
||||
UI.root:moveChildToIndex(Game.gameUi, 1)
|
||||
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
|
||||
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
|
||||
|
|
|
@ -5,7 +5,7 @@ local healthManaPanel = nil
|
|||
|
||||
-- public functions
|
||||
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()
|
||||
healthManaPanel:addChild(healthBar)
|
||||
|
|
|
@ -16,7 +16,7 @@ local InventorySlotAmmo = 10
|
|||
|
||||
-- public functions
|
||||
function Inventory.create()
|
||||
window = loadUI("/inventory/inventory.otui", Game.gameRightPanel)
|
||||
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
|
||||
|
||||
local itemWidget = window:getChildById('feet')
|
||||
window:setHeight(itemWidget:getPosition().y + itemWidget:getHeight() - window:getPosition().y)
|
||||
|
|
|
@ -10,7 +10,7 @@ function MessageBox.create(title, text, flags)
|
|||
setmetatable(box, MessageBox)
|
||||
|
||||
-- create messagebox window
|
||||
local window = UI.loadAndDisplayLocked('/messagebox/messagebox.otui')
|
||||
local window = UI.display('messagebox.otui', { locked = true })
|
||||
window:setTitle(title)
|
||||
|
||||
local label = window:getChildById('messageBoxLabel')
|
||||
|
|
|
@ -43,7 +43,7 @@ end
|
|||
|
||||
-- public functions
|
||||
function Options.create()
|
||||
options = UI.loadAndDisplayLocked("/options/options.otui")
|
||||
options = UI.display('options.otui', { locked = true })
|
||||
|
||||
local fpsBox = options:getChildById('fpsCheckBox')
|
||||
local vsyncBox = options:getChildById('vsyncCheckBox')
|
||||
|
|
|
@ -96,7 +96,7 @@ end
|
|||
|
||||
function Outfit.create(creature, outfitList)
|
||||
Outfit.destroy()
|
||||
window = loadUI("/outfit/outfit.otui", UI.root)
|
||||
window = UI.display('outfit.otui', { parent = UI.root })
|
||||
window:lock()
|
||||
|
||||
m_outfit = creature:getOutfit()
|
||||
|
|
|
@ -11,7 +11,7 @@ function UIItem.onMouseRelease(self, mousePos, mouseButton)
|
|||
local menuFile = self:getStyle()['popup menu']
|
||||
if not menuFile then return end
|
||||
|
||||
local popupMenu = UI.loadAndDisplay(menuFile)
|
||||
local popupMenu = UI.display(menuFile)
|
||||
if not popupMenu then return end
|
||||
|
||||
popupMenu:moveTo(mousePos)
|
||||
|
|
|
@ -6,7 +6,7 @@ local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fightin
|
|||
|
||||
-- public functions
|
||||
function Skills.create()
|
||||
skillWindow = loadUI("/skills/skills.otui", Game.gameRightPanel)
|
||||
skillWindow = UI.display('skills.otui', { parent = Game.gameRightPanel })
|
||||
|
||||
local skillPanel = skillWindow:getChildById('skillPanel')
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ end
|
|||
function ToolTip.display(text)
|
||||
if text then
|
||||
ToolTip.hide()
|
||||
currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
|
||||
currentToolTip = UI.display('tooltip.otui')
|
||||
currentToolTip.onMouseMove = moveToolTip
|
||||
local label = currentToolTip:getChildById('toolTipText')
|
||||
label:setText(text)
|
||||
|
|
|
@ -5,7 +5,7 @@ local topMenu
|
|||
|
||||
-- public functions
|
||||
function TopMenu.create()
|
||||
topMenu = UI.loadAndDisplay("/topmenu/topmenu.otui")
|
||||
topMenu = UI.display('topmenu.otui')
|
||||
end
|
||||
|
||||
function TopMenu.destroy()
|
||||
|
|
|
@ -5,7 +5,7 @@ local vipWindow = nil
|
|||
|
||||
-- public functions
|
||||
function VipList.create()
|
||||
vipWindow = loadUI("/viplist/viplist.otui", Game.gameRightPanel)
|
||||
vipWindow = UI.display('viplist.otui', { parent = Game.gameRightPanel })
|
||||
end
|
||||
|
||||
function VipList.destroy()
|
||||
|
|
|
@ -156,10 +156,14 @@ void UIWidget::setStyleFromNode(const OTMLNodePtr& styleNode)
|
|||
|
||||
void UIWidget::setParent(const UIWidgetPtr& parent)
|
||||
{
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
|
||||
// remove from old parent
|
||||
UIWidgetPtr oldParent = getParent();
|
||||
|
||||
// the parent is already the same
|
||||
if(oldParent == parent)
|
||||
return;
|
||||
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
if(oldParent && oldParent->hasChild(self))
|
||||
oldParent->removeChild(self);
|
||||
|
||||
|
|
Loading…
Reference in New Issue