fix warnings and some reloading issues

master
Eduardo Bart 12 years ago
parent da1baf9673
commit d0b839a4eb

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -33,15 +33,15 @@ local WEIGHT_UNIT = 'oz'
function NPCTrade.init()
cacheItems = {}
cacheGoods = {}
npcWindow = displayUI('npctrade.otui')
npcWindow:setVisible(false)
itemsPanel = npcWindow:recursiveGetChildById('itemsPanel')
buyTab = npcWindow:getChildById('buyTab')
sellTab = npcWindow:getChildById('sellTab')
searchText = npcWindow:getChildById('searchText')
setupPanel = npcWindow:recursiveGetChildById('setupPanel')
quantityLabel = setupPanel:getChildById('quantity')
quantityScroll = setupPanel:getChildById('quantityScroll')
@ -51,13 +51,13 @@ function NPCTrade.init()
weightLabel = setupPanel:getChildById('weight')
capacityLabel = setupPanel:getChildById('capacity')
setupButton = setupPanel:getChildById('setupButton')
radioTabs = RadioGroup.create()
radioTabs:addWidget(buyTab)
radioTabs:addWidget(sellTab)
radioTabs:selectWidget(buyTab)
radioTabs.onSelectionChange = NPCTrade.setList
connect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods,
@ -73,7 +73,7 @@ function NPCTrade.terminate()
buyButton = nil
sellButton = nil
searchText = nil
setupPanel = nil
quantityLabel = nil
quantityScroll = nil
@ -84,14 +84,18 @@ function NPCTrade.terminate()
capacityLabel = nil
offerSelected = nil
setupButton = nil
cacheItems = nil
cacheGoods = nil
buyTab = nil
sellTab = nil
disconnect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
NPCTrade = nil
end
-- private functions
@ -106,12 +110,12 @@ function NPCTrade.hide()
npcWindow:hide()
end
function NPCTrade.setList(radioTabs, selected, deselected)
function NPCTrade.setList(radioTabs, selected, deselected)
setupButton:setText(selected:getText())
selected:setOn(true)
deselected:setOn(false)
NPCTrade.createItemsOnPanel()
NPCTrade.resetSetup()
NPCTrade.refreshItemsPanel()
NPCTrade.refreshFilters()
@ -140,7 +144,7 @@ function NPCTrade.updateSetup()
if cacheGoods[offerSelected[1]:getId()] then -- list might be empty.
quantityScroll:setMaximum(math.max(0, math.min(100, cacheGoods[offerSelected[1]:getId()])))
end
end
end
else
NPCTrade.resetSetup()
end
@ -174,11 +178,11 @@ function NPCTrade.setItem(widget)
weightLabel:setText(string.format('%.2f', offer[3]/100) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(price .. ' ' .. CURRENCY)
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
quantityLabel:setText(1)
quantityScroll:setValue(1)
NPCTrade.updateSetup()
NPCTrade.updateSetup()
setupPanel:enable()
end
@ -186,7 +190,7 @@ function NPCTrade.setQuantity(quantity)
if quantityLabel and offerSelected then
local price = NPCTrade.getOfferPrice(offerSelected)
quantityLabel:setText(quantity)
weightLabel:setText(string.format('%.2f', offerSelected[3]*quantity/100) .. ' ' .. WEIGHT_UNIT)
weightLabel:setText(string.format('%.2f', offerSelected[3]*quantity/100) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(price .. ' ' .. CURRENCY)
end
end
@ -208,14 +212,14 @@ function NPCTrade.onOpenNpcTrade(items)
-- item[5] = sellPrice
cacheItems = items
NPCTrade.createItemsOnPanel()
NPCTrade.show()
end
function NPCTrade.switchBuyWithBackpack()
buyWithBackpack = not buyWithBackpack
buyWithBackpack = not buyWithBackpack
if offerSelected then
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. ' ' .. CURRENCY)
end
@ -238,12 +242,12 @@ function NPCTrade.itemPopup(self, mousePosition, mouseButton)
end
end
function NPCTrade.createItemsOnPanel()
function NPCTrade.createItemsOnPanel()
local layout = itemsPanel:getLayout()
layout:disableUpdates()
NPCTrade.resetSetup()
offerSelected = nil
itemsPanel:destroyChildren()
@ -251,7 +255,7 @@ function NPCTrade.createItemsOnPanel()
radioItems:destroy()
end
radioItems = RadioGroup.create()
for i, v in pairs(cacheItems) do
local price = NPCTrade.getOfferPrice(v)
if price > 0 then
@ -260,28 +264,28 @@ function NPCTrade.createItemsOnPanel()
itemBox:getChildById('item'):setItem(v[1])
itemBox:getChildById('nameLabel'):setText(v[2])
itemBox:getChildById('weightLabel'):setText(string.format('%.2f', v[3]/100) .. ' ' .. WEIGHT_UNIT)
itemBox:getChildById('priceLabel'):setText(price .. ' ' .. CURRENCY)
itemBox:getChildById('priceLabel'):setText(price .. ' ' .. CURRENCY)
itemBox.onMouseRelease = NPCTrade.itemPopup
itemBox:getChildById('item').onMouseRelease = function (self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end
radioItems:addWidget(itemBox)
end
end
layout:enableUpdates()
layout:update()
end
function NPCTrade.extraFilters(widget, showOnlyHolding)
if setupButton:getText() == tr('Sell') then
if setupButton:getText() == tr('Sell') then
if not showOnlyHolding or cacheGoods[widget.offer[1]:getId()] then
return true
else
return false
end
end
return true
end
@ -332,16 +336,16 @@ end
function NPCTrade.onPlayerGoods(money, goods)
moneyGoods = money
moneyLabel:setText(money .. ' ' .. CURRENCY)
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
cacheGoods = {}
for i,v in pairs(goods) do
cacheGoods[v[1]:getId()] = v[2]
end
NPCTrade.refreshItemsPanel()
NPCTrade.updateSetup()
end

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save