fix warnings and some reloading issues

This commit is contained in:
Eduardo Bart 2012-04-27 01:54:14 -03:00
parent da1baf9673
commit d0b839a4eb
28 changed files with 106 additions and 62 deletions

View File

@ -8,8 +8,8 @@ Module
reloadable: false reloadable: false
load-later: load-later:
- client_topmenu
- client_locales - client_locales
- client_topmenu
- client_background - client_background
//- client_about //- client_about
- client_options - client_options

View File

@ -28,7 +28,7 @@ function Locales.init()
Locales.setLocale(defaultLocaleName) Locales.setLocale(defaultLocaleName)
Settings.set('locale', defaultLocaleName) Settings.set('locale', defaultLocaleName)
end end
--[[
addEvent( function() addEvent( function()
localeComboBox = createWidget('ComboBox', rootWidget:recursiveGetChildById('rightButtonsPanel')) localeComboBox = createWidget('ComboBox', rootWidget:recursiveGetChildById('rightButtonsPanel'))
for key,value in pairs(installedLocales) do for key,value in pairs(installedLocales) do
@ -37,6 +37,7 @@ function Locales.init()
localeComboBox:setCurrentOption(currentLocale.languageName) localeComboBox:setCurrentOption(currentLocale.languageName)
localeComboBox.onOptionChange = onLocaleComboBoxOptionChange localeComboBox.onOptionChange = onLocaleComboBoxOptionChange
end, false) end, false)
]]--
end end
function Locales.terminate() function Locales.terminate()

View File

@ -182,6 +182,7 @@ locale = {
["You are burning"] = "Você está queimando", ["You are burning"] = "Você está queimando",
["You are cursed"] = "Você está amaldiçoado", ["You are cursed"] = "Você está amaldiçoado",
["You are dazzled"] = "Você está deslumbrado", ["You are dazzled"] = "Você está deslumbrado",
["You are dead."] = "Você está morto.",
["You are drowing"] = "Você está se afogando", ["You are drowing"] = "Você está se afogando",
["You are electrified"] = "Você está eletrificado", ["You are electrified"] = "Você está eletrificado",
["You are freezing"] = "Você está congelando", ["You are freezing"] = "Você está congelando",

View File

@ -177,19 +177,19 @@ function Terminal.hide()
end end
function Terminal.addLine(text, color) function Terminal.addLine(text, color)
-- create new line label
local numLines = terminalBuffer:getChildCount() + 1
local label = createWidget('TerminalLabel', terminalBuffer)
label:setId('terminalLabel' .. numLines)
label:setText(text)
label:setColor(color)
-- delete old lines if needed -- delete old lines if needed
local numLines = terminalBuffer:getChildCount() + 1
if numLines > MaxLogLines then if numLines > MaxLogLines then
terminalBuffer:getChildByIndex(1):destroy() terminalBuffer:getChildByIndex(1):destroy()
else else
terminalBuffer:setHeight(terminalBuffer:getHeight() + LabelHeight) terminalBuffer:setHeight(terminalBuffer:getHeight() + LabelHeight)
end end
-- create new line label
local label = createWidget('TerminalLabel', terminalBuffer)
label:setId('terminalLabel' .. numLines)
label:setText(text)
label:setColor(color)
end end
function Terminal.executeCommand(command) function Terminal.executeCommand(command)

View File

@ -8,7 +8,7 @@ end
local function tabBlink(tab) local function tabBlink(tab)
if not tab.blinking then return end if not tab.blinking then return end
tab:setOn(not tab:isOn()) tab:setOn(not tab:isOn())
scheduleEvent(function() tabBlink(tab) end, 500) tab.blinkEvent = scheduleEvent(function() tabBlink(tab) end, 500)
end end
-- public functions -- public functions
@ -29,12 +29,14 @@ end
function UITabBar:addTab(text, panel) function UITabBar:addTab(text, panel)
if panel == nil then if panel == nil then
panel = createWidget(self:getStyleName() .. 'Panel') panel = createWidget(self:getStyleName() .. 'Panel')
panel:setId('tabPanel')
end end
local tab = createWidget(self:getStyleName() .. 'Button', self) local tab = createWidget(self:getStyleName() .. 'Button', self)
panel.isTab = true panel.isTab = true
tab.tabPanel = panel tab.tabPanel = panel
tab.tabBar = self tab.tabBar = self
tab:setId('tab')
tab:setText(text) tab:setText(text)
tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight()) tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
tab.onClick = onTabClick tab.onClick = onTabClick
@ -55,6 +57,9 @@ function UITabBar:removeTab(tab)
self:selectPrevTab() self:selectPrevTab()
end end
table.remove(self.tabs, index) table.remove(self.tabs, index)
if tab.blinkEvent then
removeEvent(tab.blinkEvent)
end
tab:destroy() tab:destroy()
end end

View File

@ -81,11 +81,15 @@ function Battle.terminate()
battleButton = nil battleButton = nil
battleWindow:destroy() battleWindow:destroy()
battleWindow = nil battleWindow = nil
mouseWidget:destroy()
mouseWidget = nil
disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull, disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull,
onEmblemChange = Battle.checkCreatureEmblem } ) onEmblemChange = Battle.checkCreatureEmblem } )
disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } ) disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } )
Battle = nil
end end
function Battle.toggle() function Battle.toggle()

View File

@ -5,10 +5,13 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
icon: battle.png icon: battle.png
dependencies:
- game
@onLoad: | @onLoad: |
dofile 'battle' dofile 'battle'
Battle.init() Battle.init()
@onUnload: @onUnload: |
Battle.terminate() Battle.terminate()

View File

@ -4,6 +4,9 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependencies:
- game
@onLoad: | @onLoad: |
dofile 'combatcontrols' dofile 'combatcontrols'
CombatControls.init() CombatControls.init()

View File

@ -42,17 +42,18 @@ local SayModes = {
[3] = { speakTypeDesc = 'yell', icon = '/core_styles/icons/yell.png' } [3] = { speakTypeDesc = 'yell', icon = '/core_styles/icons/yell.png' }
} }
local MAX_HISTORY = 1000
local MAX_LINES = 100
local consolePanel local consolePanel
local consoleContentPanel local consoleContentPanel
local consoleTabBar local consoleTabBar
local consoleTextEdit local consoleTextEdit
local channels local channels
local messageHistory = { }
local currentMessageIndex = 0
local MaxHistory = 1000
local channelsWindow local channelsWindow
local MAX_LINES = 100
local ownPrivateName local ownPrivateName
local messageHistory = {}
local currentMessageIndex = 0
-- private functions -- private functions
local function navigateMessageHistory(step) local function navigateMessageHistory(step)
@ -252,9 +253,9 @@ function Console.terminate()
consoleContentPanel = nil consoleContentPanel = nil
consoleTabBar = nil consoleTabBar = nil
Console = nil
ownPrivateName = nil ownPrivateName = nil
Console = nil
end end
function Console.clear() function Console.clear()
@ -418,7 +419,7 @@ function Console.sendCurrentMessage()
-- add new command to history -- add new command to history
currentMessageIndex = 0 currentMessageIndex = 0
table.insert(messageHistory, originalMessage) table.insert(messageHistory, originalMessage)
if #messageHistory > MaxHistory then if #messageHistory > MAX_HISTORY then
table.remove(messageHistory, 1) table.remove(messageHistory, 1)
end end

View File

@ -4,7 +4,7 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |

View File

@ -4,7 +4,7 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |

View File

@ -63,6 +63,8 @@ function HealthBar.terminate()
manaBar = nil manaBar = nil
healthLabel = nil healthLabel = nil
manaLabel = nil manaLabel = nil
HealthBar = nil
end end
function HealthBar.toggle() function HealthBar.toggle()

View File

@ -4,7 +4,7 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |

View File

@ -116,6 +116,8 @@ function HotkeysManager.terminate()
hotkeysWindow = nil hotkeysWindow = nil
hotkeysButton:destroy() hotkeysButton:destroy()
hotkeysButton = nil hotkeysButton = nil
HotkeysManager = nil
end end
function HotkeysManager.toggle() function HotkeysManager.toggle()

View File

@ -38,6 +38,8 @@ function Inventory.terminate()
inventoryWindow = nil inventoryWindow = nil
inventoryButton = nil inventoryButton = nil
inventoryPanel = nil inventoryPanel = nil
Inventory = nil
end end
function Inventory.toggle() function Inventory.toggle()

View File

@ -4,7 +4,7 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |

View File

@ -43,13 +43,15 @@ function Minimap.init()
end end
function Minimap.terminate() function Minimap.terminate()
Keyboard.unbindKeyDown('Ctrl+M')
disconnect(g_game, { onLogin = Minimap.reset }) disconnect(g_game, { onLogin = Minimap.reset })
Keyboard.unbindKeyDown('Ctrl+M')
minimapWidget:destroy() minimapWidget:destroy()
minimapWidget = nil minimapWidget = nil
minimapButton:destroy() minimapButton:destroy()
minimapButton = nil minimapButton = nil
Minimap = nil
end end
function Minimap.toggle() function Minimap.toggle()

View File

@ -4,12 +4,12 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |
dofile 'minimap' dofile 'minimap'
Minimap.init() Minimap.init()
@onUnload: @onUnload: |
Minimap.terminate() Minimap.terminate()

View File

@ -87,11 +87,15 @@ function NPCTrade.terminate()
cacheItems = nil cacheItems = nil
cacheGoods = nil cacheGoods = nil
buyTab = nil
sellTab = nil
disconnect(g_game, { onGameEnd = NPCTrade.hide, disconnect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade, onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods, onPlayerGoods = NPCTrade.onPlayerGoods,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } ) onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
NPCTrade = nil
end end
-- private functions -- private functions

View File

@ -126,6 +126,8 @@ function Outfit.terminate()
disconnect(g_game, { onOpenOutfitWindow = Outfit.create, disconnect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy }) onGameEnd = Outfit.destroy })
Outfit.destroy() Outfit.destroy()
Outfit = nil
end end
function Outfit.create(creature, outfitList) function Outfit.create(creature, outfitList)

View File

@ -4,6 +4,9 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependencies:
- game
@onLoad: | @onLoad: |
dofile 'outfit' dofile 'outfit'
Outfit.init() Outfit.init()

View File

@ -59,6 +59,8 @@ function Skills.terminate()
skillsButton = nil skillsButton = nil
skillsWindow:destroy() skillsWindow:destroy()
skillsWindow = nil skillsWindow = nil
Skills = nil
end end
function Skills.toggle() function Skills.toggle()

View File

@ -4,6 +4,9 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependencies:
- game
@onLoad: | @onLoad: |
dofile 'skills' dofile 'skills'
Skills.init() Skills.init()

View File

@ -131,5 +131,5 @@ end
function TextMessage.displayDeadMessage() function TextMessage.displayDeadMessage()
local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance') local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then return end if advanceLabel:isVisible() then return end
TextMessage.displayEventAdvance('You are dead.') TextMessage.displayEventAdvance(tr('You are dead.'))
end end

View File

@ -4,7 +4,7 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
dependecies: dependencies:
- game - game
@onLoad: | @onLoad: |

View File

@ -26,6 +26,8 @@ function VipList.terminate()
vipWindow = nil vipWindow = nil
vipButton:destroy() vipButton:destroy()
vipButton = nil vipButton = nil
VipList = nil
end end
function VipList.clear() function VipList.clear()

View File

@ -8,5 +8,5 @@ Module
dofile 'viplist' dofile 'viplist'
VipList.init() VipList.init()
@onUnload: @onUnload: |
VipList.terminate() VipList.terminate()

View File

@ -281,13 +281,15 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
checkEvent = g_eventDispatcher.scheduleEvent([] { checkEvent = g_eventDispatcher.scheduleEvent([] {
g_lua.collectGarbage(); g_lua.collectGarbage();
g_eventDispatcher.addEvent([] { UIWidgetList backupList = destroyedWidgets;
destroyedWidgets.clear();
g_eventDispatcher.scheduleEvent([backupList] {
g_lua.collectGarbage(); g_lua.collectGarbage();
for(const UIWidgetPtr& widget : destroyedWidgets) { for(const UIWidgetPtr& widget : backupList) {
if(widget->getUseCount() != 1) if(widget->getUseCount() != 1)
logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left"); logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left");
} }
}); }, 1);
}, 1000); }, 1000);
#endif #endif
} }