diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 903f38fd..a0aba95d 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -8,8 +8,8 @@ Module reloadable: false load-later: - - client_topmenu - client_locales + - client_topmenu - client_background //- client_about - client_options diff --git a/modules/client_locales/locales.lua b/modules/client_locales/locales.lua index b2a02d61..f9afaf7a 100644 --- a/modules/client_locales/locales.lua +++ b/modules/client_locales/locales.lua @@ -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() diff --git a/modules/client_locales/locales/pt-br.lua b/modules/client_locales/locales/pt-br.lua index ae78f531..c7555de1 100644 --- a/modules/client_locales/locales/pt-br.lua +++ b/modules/client_locales/locales/pt-br.lua @@ -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", diff --git a/modules/client_terminal/terminal.lua b/modules/client_terminal/terminal.lua index 60339a4c..c503613c 100644 --- a/modules/client_terminal/terminal.lua +++ b/modules/client_terminal/terminal.lua @@ -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) diff --git a/modules/core_lib/widgets/uitabbar.lua b/modules/core_lib/widgets/uitabbar.lua index 40909f76..24c0e219 100644 --- a/modules/core_lib/widgets/uitabbar.lua +++ b/modules/core_lib/widgets/uitabbar.lua @@ -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 diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index 2301e369..8013b622 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -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() diff --git a/modules/game_battle/battle.otmod b/modules/game_battle/battle.otmod index f602bdcc..3823d403 100644 --- a/modules/game_battle/battle.otmod +++ b/modules/game_battle/battle.otmod @@ -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() diff --git a/modules/game_combatcontrols/combatcontrols.otmod b/modules/game_combatcontrols/combatcontrols.otmod index b7932c4f..d81ba973 100644 --- a/modules/game_combatcontrols/combatcontrols.otmod +++ b/modules/game_combatcontrols/combatcontrols.otmod @@ -4,6 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient + dependencies: + - game + @onLoad: | dofile 'combatcontrols' CombatControls.init() diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 183849c6..01106acc 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -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 diff --git a/modules/game_console/console.otmod b/modules/game_console/console.otmod index 3d9a1b71..308ba597 100644 --- a/modules/game_console/console.otmod +++ b/modules/game_console/console.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - dependecies: + dependencies: - game @onLoad: | diff --git a/modules/game_containers/containers.otmod b/modules/game_containers/containers.otmod index 5654e135..a389f8a7 100644 --- a/modules/game_containers/containers.otmod +++ b/modules/game_containers/containers.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - dependecies: + dependencies: - game @onLoad: | diff --git a/modules/game_healthbar/healthbar.lua b/modules/game_healthbar/healthbar.lua index 08ff8ff4..1eea9dc6 100644 --- a/modules/game_healthbar/healthbar.lua +++ b/modules/game_healthbar/healthbar.lua @@ -63,6 +63,8 @@ function HealthBar.terminate() manaBar = nil healthLabel = nil manaLabel = nil + + HealthBar = nil end function HealthBar.toggle() diff --git a/modules/game_healthbar/healthbar.otmod b/modules/game_healthbar/healthbar.otmod index a358f276..5f8769de 100644 --- a/modules/game_healthbar/healthbar.otmod +++ b/modules/game_healthbar/healthbar.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - dependecies: + dependencies: - game @onLoad: | diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index d2423b5f..4b5a7f8f 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -116,6 +116,8 @@ function HotkeysManager.terminate() hotkeysWindow = nil hotkeysButton:destroy() hotkeysButton = nil + + HotkeysManager = nil end function HotkeysManager.toggle() diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index 91d444b1..8070e0ca 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -38,6 +38,8 @@ function Inventory.terminate() inventoryWindow = nil inventoryButton = nil inventoryPanel = nil + + Inventory = nil end function Inventory.toggle() diff --git a/modules/game_inventory/inventory.otmod b/modules/game_inventory/inventory.otmod index 5256bb38..202f6df7 100644 --- a/modules/game_inventory/inventory.otmod +++ b/modules/game_inventory/inventory.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - dependecies: + dependencies: - game @onLoad: | diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index fa7c4bdc..bd23773a 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -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() diff --git a/modules/game_minimap/minimap.otmod b/modules/game_minimap/minimap.otmod index 82301708..f3513607 100644 --- a/modules/game_minimap/minimap.otmod +++ b/modules/game_minimap/minimap.otmod @@ -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() diff --git a/modules/game_npctrade/npctrade.lua b/modules/game_npctrade/npctrade.lua index fc3da376..b9d0e1da 100644 --- a/modules/game_npctrade/npctrade.lua +++ b/modules/game_npctrade/npctrade.lua @@ -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 diff --git a/modules/game_outfit/outfit.lua b/modules/game_outfit/outfit.lua index a7d631a4..99c678ba 100644 --- a/modules/game_outfit/outfit.lua +++ b/modules/game_outfit/outfit.lua @@ -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) diff --git a/modules/game_outfit/outfit.otmod b/modules/game_outfit/outfit.otmod index 5119ad92..148ac912 100644 --- a/modules/game_outfit/outfit.otmod +++ b/modules/game_outfit/outfit.otmod @@ -4,6 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient + dependencies: + - game + @onLoad: | dofile 'outfit' Outfit.init() diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index 75e32aa2..c9914d3f 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -59,6 +59,8 @@ function Skills.terminate() skillsButton = nil skillsWindow:destroy() skillsWindow = nil + + Skills = nil end function Skills.toggle() diff --git a/modules/game_skills/skills.otmod b/modules/game_skills/skills.otmod index fc567318..caf4cbe6 100644 --- a/modules/game_skills/skills.otmod +++ b/modules/game_skills/skills.otmod @@ -4,6 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient + dependencies: + - game + @onLoad: | dofile 'skills' Skills.init() diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 6b7e41f5..9d4a7168 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -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 diff --git a/modules/game_textmessage/textmessage.otmod b/modules/game_textmessage/textmessage.otmod index a52bb11f..bc138c5d 100644 --- a/modules/game_textmessage/textmessage.otmod +++ b/modules/game_textmessage/textmessage.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - dependecies: + dependencies: - game @onLoad: | diff --git a/modules/game_viplist/viplist.lua b/modules/game_viplist/viplist.lua index 378c22ce..ce978215 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/game_viplist/viplist.lua @@ -26,6 +26,8 @@ function VipList.terminate() vipWindow = nil vipButton:destroy() vipButton = nil + + VipList = nil end function VipList.clear() diff --git a/modules/game_viplist/viplist.otmod b/modules/game_viplist/viplist.otmod index 64ee77fa..fa7d8b4e 100644 --- a/modules/game_viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -8,5 +8,5 @@ Module dofile 'viplist' VipList.init() - @onUnload: + @onUnload: | VipList.terminate() diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index e2c04328..f0286166 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -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 }