diff --git a/modules/client_background/background.lua b/modules/client_background/background.lua index 1c41201b..5161fddb 100644 --- a/modules/client_background/background.lua +++ b/modules/client_background/background.lua @@ -10,6 +10,7 @@ function Background.init() local clientVersionLabel = background:getChildById('clientVersionLabel') clientVersionLabel:setText('OTClient ' .. g_app.getVersion() .. '\n' .. + 'Rev ' .. g_app.getBuildRevision() .. '\n' .. 'Built on ' .. g_app.getBuildDate()) if not g_game.isOnline() then diff --git a/modules/client_background/background.otui b/modules/client_background/background.otui index 210d788e..5cc69d85 100644 --- a/modules/client_background/background.otui +++ b/modules/client_background/background.otui @@ -15,8 +15,8 @@ Panel background-color: #00000099 anchors.right: parent.right anchors.bottom: parent.bottom - text-offset: 4 2 - height: 32 + text-align: center + height: 48 width: 120 color: #ffffff font: verdana-11px-monochrome diff --git a/modules/client_terminal/terminal.otui b/modules/client_terminal/terminal.otui index 4437a644..42fd41fe 100644 --- a/modules/client_terminal/terminal.otui +++ b/modules/client_terminal/terminal.otui @@ -2,12 +2,11 @@ TerminalLabel < UILabel font: terminus-14px-bold height: 16 -Panel - id: terminalPanel +UIWidget + id: terminalWidget background-color: #000000 opacity: 0.85 anchors.fill: parent - @onEscape: Terminal.hide() Panel id: terminalBuffer diff --git a/modules/core_lib/widgets/uicombobox.lua b/modules/core_lib/widgets/uicombobox.lua index 676bdf1d..ef6b9aed 100644 --- a/modules/core_lib/widgets/uicombobox.lua +++ b/modules/core_lib/widgets/uicombobox.lua @@ -2,16 +2,16 @@ UIComboBox = extends(UIWidget) function UIComboBox.create() local combobox = UIComboBox.internalCreate() - combobox.m_options = {} - combobox.m_currentIndex = -1 + combobox.options = {} + combobox.currentIndex = -1 return combobox end function UIComboBox:setCurrentOption(text) - if not self.m_options then return end - for i,v in ipairs(self.m_options) do - if v.text == text and self.m_currentIndex ~= i then - self.m_currentIndex = i + if not self.options then return end + for i,v in ipairs(self.options) do + if v.text == text and self.currentIndex ~= i then + self.currentIndex = i self:setText(text) self:onOptionChange(text, v.data) return @@ -20,24 +20,24 @@ function UIComboBox:setCurrentOption(text) end function UIComboBox:setCurrentIndex(index) - if index >= 1 and index <= #self.m_options then - local v = self.m_options[index] - self.m_currentIndex = index + if index >= 1 and index <= #self.options then + local v = self.options[index] + self.currentIndex = index self:setText(v.text) self:onOptionChange(v.text, v.data) end end function UIComboBox:addOption(text, data) - table.insert(self.m_options, { text = text, data = data }) - local index = #self.m_options + table.insert(self.options, { text = text, data = data }) + local index = #self.options if index == 1 then self:setCurrentOption(text) end return index end function UIComboBox:onMousePress(mousePos, mouseButton) local menu = createWidget(self:getStyleName() .. 'PopupMenu', self) - for i,v in ipairs(self.m_options) do + for i,v in ipairs(self.options) do menu:addOption(v.text, function() self:setCurrentOption(v.text) end) end menu:setWidth(self:getWidth()) @@ -48,10 +48,10 @@ function UIComboBox:onMousePress(mousePos, mouseButton) end function UIComboBox:onMouseWheel(mousePos, direction) - if direction == MouseWheelUp and self.m_currentIndex > 1 then - self:setCurrentIndex(self.m_currentIndex - 1) - elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then - self:setCurrentIndex(self.m_currentIndex + 1) + if direction == MouseWheelUp and self.currentIndex > 1 then + self:setCurrentIndex(self.currentIndex - 1) + elseif direction == MouseWheelDown and self.currentIndex < #self.options then + self:setCurrentIndex(self.currentIndex + 1) end return true end diff --git a/modules/core_lib/widgets/uiprogressbar.lua b/modules/core_lib/widgets/uiprogressbar.lua index a9f0c34e..dceb0beb 100644 --- a/modules/core_lib/widgets/uiprogressbar.lua +++ b/modules/core_lib/widgets/uiprogressbar.lua @@ -4,23 +4,23 @@ function UIProgressBar.create() local progressbar = UIProgressBar.internalCreate() progressbar:setFocusable(false) progressbar:setPhantom(true) - progressbar.m_percent = 0 + progressbar.percent = 0 progressbar:updateBackground() return progressbar end function UIProgressBar:setPercent(percent) - self.m_percent = math.max(math.min(percent, 100), 0) + self.percent = math.max(math.min(percent, 100), 0) self:updateBackground() end function UIProgressBar:getPercent() - return self.m_percent + return self.percent end function UIProgressBar:updateBackground() - local width = math.max((self.m_percent * self:getWidth())/100, 1) + local width = math.max((self.percent * self:getWidth())/100, 1) local height = self:getHeight() self:setBackgroundSize({width=width, height=height}) end diff --git a/modules/core_lib/widgets/uispinbox.lua b/modules/core_lib/widgets/uispinbox.lua index a6521d96..8593f503 100644 --- a/modules/core_lib/widgets/uispinbox.lua +++ b/modules/core_lib/widgets/uispinbox.lua @@ -3,54 +3,54 @@ UISpinBox = extends(UILineEdit) function UISpinBox.create() local spinbox = UISpinBox.internalCreate() spinbox:setValidCharacters('0123456789') - spinbox.m_minimum = 0 - spinbox.m_maximum = 0 + spinbox.minimum = 0 + spinbox.maximum = 0 spinbox:setCurrentIndex(0) spinbox:setText("0") return spinbox end function UISpinBox:setCurrentIndex(index) - if index >= self.m_minimum and index <= self.m_maximum then + if index >= self.minimum and index <= self.maximum then if self:getText():len() > 0 then self:setText(index) end - self.m_currentIndex = index + self.currentIndex = index self:onIndexChange(index) end end function UISpinBox:setMinimum(minimum) - if minimum > self.m_maximum then + if minimum > self.maximum then print("[UISpinBox:setMinimum]: minimum value cant be greater than maximum") return false end - if self.m_currentIndex < minimum then + if self.currentIndex < minimum then self:setCurrentIndex(minimum) end - self.m_minimum = minimum + self.minimum = minimum end function UISpinBox:setMaximum(maximum) - if maximum < self.m_minimum then + if maximum < self.minimum then print("[UISpinBox:setMaximum]: maximum value cant be lower than minimum") return false end - if self.m_currentIndex > maximum then + if self.currentIndex > maximum then self:setCurrentIndex(maximum) end - self.m_maximum = maximum + self.maximum = maximum end function UISpinBox:getCurrentIndex() - return self.m_currentIndex + return self.currentIndex end function UISpinBox:onMouseWheel(mousePos, direction) if direction == MouseWheelUp then - self:setCurrentIndex(self.m_currentIndex + 1) + self:setCurrentIndex(self.currentIndex + 1) elseif direction == MouseWheelDown then - self:setCurrentIndex(self.m_currentIndex - 1) + self:setCurrentIndex(self.currentIndex - 1) end return true end @@ -58,12 +58,12 @@ end function UISpinBox:onTextChange(text, oldText) if text:len() == 0 then - self:setCurrentIndex(self.m_minimum) + self:setCurrentIndex(self.minimum) return end local number = tonumber(text) - if not number or number > self.m_maximum or number < self.m_minimum then + if not number or number > self.maximum or number < self.minimum then self:setText(oldText) return end diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 4cbe2a59..79c3d20a 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -13,6 +13,13 @@ Module load-later: - game_textmessage - game_console + - game_outfit + //- game_healthbar + //- game_inventory + //- game_combatcontrols + //- game_skills + //- game_viplist + //- game_hotkeys @onLoad: | importStyle 'styles/items.otui' diff --git a/modules/game/gameinterface.lua b/modules/game/gameinterface.lua index dcb5cbf8..59e45eeb 100644 --- a/modules/game/gameinterface.lua +++ b/modules/game/gameinterface.lua @@ -211,7 +211,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l return true end - if not Options.classicControl then + if not Options['classicControl'] then if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing) return true diff --git a/modules/game/gameinterface.otui b/modules/game/gameinterface.otui index fe41b0b0..bb989925 100644 --- a/modules/game/gameinterface.otui +++ b/modules/game/gameinterface.otui @@ -26,7 +26,7 @@ UIWidget GameSidePanel id: gameLeftPanel - width: 190 + width: 0 layout: verticalBox anchors.left: parent.left anchors.top: parent.top diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index b5576132..67514e42 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -36,7 +36,7 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } ) -- public functions function Battle.create() - battleWindow = displayUI('battle.otui', g_game.gameRightPanel) + battleWindow = displayUI('battle.otui', GameInterface.getRightPanel()) battleWindow:hide() battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle) Keyboard.bindKeyDown('Ctrl+B', Battle.toggle) diff --git a/modules/game_battle/battle.otmod b/modules/game_battle/battle.otmod index 885e430b..a1341672 100644 --- a/modules/game_battle/battle.otmod +++ b/modules/game_battle/battle.otmod @@ -3,5 +3,6 @@ Module description: Manage battle window author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'battle' diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/game_combatcontrols/combatcontrols.lua index f8debe1e..3e64d33b 100644 --- a/modules/game_combatcontrols/combatcontrols.lua +++ b/modules/game_combatcontrols/combatcontrols.lua @@ -50,7 +50,7 @@ end function CombatControls.init() combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle) combatControlsButton:setOn(true) - combatControlsWindow = loadUI('combatcontrols.otui') + combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel()) fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox') fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox') @@ -101,7 +101,6 @@ function CombatControls.terminate() end function CombatControls.online() - g_game.gameRightPanel:addChild(combatControlsWindow) combatControlsWindow:setVisible(combatControlsButton:isOn()) local fightMode = g_game.getFightMode() @@ -121,7 +120,6 @@ function CombatControls.online() end function CombatControls.offline() - g_game.gameRightPanel:removeChild(combatControlsWindow) end function CombatControls.toggle() diff --git a/modules/game_combatcontrols/combatcontrols.otmod b/modules/game_combatcontrols/combatcontrols.otmod index 19a54913..b7932c4f 100644 --- a/modules/game_combatcontrols/combatcontrols.otmod +++ b/modules/game_combatcontrols/combatcontrols.otmod @@ -4,9 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + @onLoad: | dofile 'combatcontrols' CombatControls.init() - onUnload: | + @onUnload: | CombatControls.terminate() diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index eeaadd25..ff2acdf1 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -50,6 +50,7 @@ local channels local messageHistory = { } local currentMessageIndex = 0 local MaxHistory = 1000 +local channelsWindow -- private functions local function navigateMessageHistory(step) @@ -67,7 +68,7 @@ end function applyMessagePrefixies(name, level, message) if name then - if Options.showLevelsInConsole and level > 0 then + if Options.getOption('showLevelsInConsole') and level > 0 then message = name .. ' [' .. level .. ']: ' .. message else message = name .. ': ' .. message @@ -109,7 +110,7 @@ local function onOpenPrivateChannel(receiver) end end -local function doChannelListSubmit(channelsWindow) +local function doChannelListSubmit() local channelListPanel = channelsWindow:getChildById('channelList') local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() if openPrivateChannelWith ~= '' then @@ -119,13 +120,16 @@ local function doChannelListSubmit(channelsWindow) if not selectedChannelLabel then return end g_game.joinChannel(selectedChannelLabel.channelId) end + channelsWindow:destroy() end local function onChannelList(channelList) - local channelsWindow = displayUI('channelswindow.otui') + if channelsWindow then channelsWindow:destroy() end + channelsWindow = displayUI('channelswindow.otui') local channelListPanel = channelsWindow:getChildById('channelList') - channelsWindow.onEnter = function() doChannelListSubmit(channelsWindow) end + channelsWindow.onEnter = doChannelListSubmit + channelsWindow.onDestroy = function() channelsWindow = nil end Keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow) Keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow) @@ -139,7 +143,7 @@ local function onChannelList(channelList) label:setText(channelName) label:setPhantom(false) - label.onDoubleClick = function() doChannelListSubmit(channelsWindow) end + label.onDoubleClick = doChannelListSubmit end end end @@ -150,7 +154,8 @@ function Console.init() connect(g_game, { onCreatureSpeak = onCreatureSpeak, onChannelList = onChannelList, onOpenChannel = onOpenChannel, - onOpenPrivateChannel = onOpenPrivateChannel}) + onOpenPrivateChannel = onOpenPrivateChannel, + onGameEnd = Console.clean }) consolePanel = displayUI('console.otui', GameInterface.getBottomPanel()) consoleLineEdit = consolePanel:getChildById('consoleLineEdit') @@ -182,15 +187,24 @@ function Console.terminate() disconnect(g_game, { onCreatureSpeak = onCreatureSpeak, onChannelList = onChannelList, onOpenChannel = onOpenChannel, - onOpenPrivateChannel = onOpenPrivateChannel }) + onOpenPrivateChannel = onOpenPrivateChannel, + onGameEnd = Console.clean }) - for channelid, channelname in ipairs(channels) do - g_game.leaveChannel(channelid) + for channelid, channelname in pairs(channels) do + if channelid ~= 0 then + g_game.leaveChannel(channelid) + end end + channels = {} Keyboard.unbindKeyDown('Ctrl+O') Keyboard.unbindKeyDown('Ctrl+E') + if channelsWindow then + channelsWindow:destroy() + channelsWindow = nil + end + consolePanel:destroy() consolePanel = nil consoleLineEdit = nil @@ -200,6 +214,28 @@ function Console.terminate() Console = nil end +function Console.debug() + print(#channels) +end + +function Console.clean() + for channelid, channelname in pairs(channels) do + if channelid ~= 0 then + local tab = consoleTabBar:getTab(channelname) + consoleTabBar:removeTab(tab) + end + end + channels = {} + + consoleTabBar:getTab('Default').tabPanel:destroyChildren() + consoleTabBar:getTab('Server Log').tabPanel:destroyChildren() + + if channelsWindow then + channelsWindow:destroy() + channelsWindow = nil + end +end + function Console.setLineEditText(text) consoleLineEdit:setText(text) end @@ -260,7 +296,7 @@ function Console.addPrivateText(text, speaktype, name, isPrivateCommand) local privateTab = Console.getTab(name) if privateTab == nil then - if Options.showPrivateMessagesInConsole or (isPrivateCommand and not privateTab) then + if Options['showPrivateMessagesInConsole'] or (isPrivateCommand and not privateTab) then privateTab = Console.getTab('Default') else privateTab = Console.addTab(name, focus) @@ -280,7 +316,7 @@ function Console.addText(text, speaktype, tabName) end function Console.addTabText(text, speaktype, tab) - if Options.showTimestampsInConsole then + if Options['showTimestampsInConsole'] then text = os.date('%H:%M') .. ' ' .. text end diff --git a/modules/game_containers/containers.lua b/modules/game_containers/containers.lua index 34dd4145..13b7ca5c 100644 --- a/modules/game_containers/containers.lua +++ b/modules/game_containers/containers.lua @@ -1,16 +1,16 @@ Containers = {} -- private variables -local m_containers = {} +local containers = {} -- public functions function Containers.clean() - m_containers = {} + containers = {} end function Containers.getFreeContainerId() for i=0,15 do - if not m_containers[i] then + if not containers[i] then return i end end @@ -19,12 +19,12 @@ end -- hooked events function Containers.onOpenContainer(containerId, itemId, name, capacity, hasParent, items) - local container = m_containers[containerId] + local container = containers[containerId] if container then - g_game.gameRightPanel:removeChild(container) + GameInterface.getRightPanel():removeChild(container) end - container = displayUI('container.otui', g_game.gameRightPanel) + container = displayUI('container.otui', GameInterface.getRightPanel()) name = name:sub(1,1):upper() .. name:sub(2) container:setText(name) @@ -51,19 +51,19 @@ function Containers.onOpenContainer(containerId, itemId, name, capacity, hasPare end end - m_containers[containerId] = container + containers[containerId] = container end function Containers.onCloseContainer(containerId) - local container = m_containers[containerId] + local container = containers[containerId] if container then - g_game.gameRightPanel:removeChild(container) + GameInterface.getRightPanel():removeChild(container) end - m_containers[containerId] = nil + containers[containerId] = nil end function Containers.onContainerAddItem(containerId, item) - local container = m_containers[containerId] + local container = containers[containerId] if not container or not item or container.itemCount >= container.capacity then return end local i = container.itemCount @@ -92,7 +92,7 @@ function Containers.onContainerAddItem(containerId, item) end function Containers.onContainerUpdateItem(containerId, slot, item) - local container = m_containers[containerId] + local container = containers[containerId] if not container then return end local itemWidget = container:getChildByIndex(slot + 1) @@ -102,7 +102,7 @@ function Containers.onContainerUpdateItem(containerId, slot, item) end function Containers.onContainerRemoveItem(containerId, slot) - local container = m_containers[containerId] + local container = containers[containerId] if not container then return end local itemWidget = container:getChildByIndex(slot+1) diff --git a/modules/game_containers/containers.otmod b/modules/game_containers/containers.otmod index 670c35d3..bd4fa8d4 100644 --- a/modules/game_containers/containers.otmod +++ b/modules/game_containers/containers.otmod @@ -3,5 +3,6 @@ Module description: Manage containers author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'containers' diff --git a/modules/game_healthbar/healthbar.lua b/modules/game_healthbar/healthbar.lua index 89fd7753..a4678bcb 100644 --- a/modules/game_healthbar/healthbar.lua +++ b/modules/game_healthbar/healthbar.lua @@ -9,7 +9,7 @@ local manaLabel -- public functions function HealthBar.create() - healthBarWindow = displayUI('healthbar.otui', g_game.gameRightPanel) + healthBarWindow = displayUI('healthbar.otui', GameInterface.getRightPanel()) healthBarButton = TopMenu.addGameButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle) healthBarButton:setOn(true) healthBar = healthBarWindow:getChildById('healthBar') diff --git a/modules/game_healthbar/healthbar.otmod b/modules/game_healthbar/healthbar.otmod index 0c411cb2..9df387c0 100644 --- a/modules/game_healthbar/healthbar.otmod +++ b/modules/game_healthbar/healthbar.otmod @@ -3,5 +3,6 @@ Module description: Displays health and mana points author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'healthbar' diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index 6a1b0e67..c1b81100 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -37,7 +37,7 @@ function HotkeysManager.init() hotkeysWindow = displayUI('hotkeys_manager.otui') hotkeysWindow:setVisible(false) - hotkeysButton = TopMenu.addButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle) + hotkeysButton = TopMenu.addLeftButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle) Keyboard.bindKeyDown('Ctrl+K', HotkeysManager.toggle) currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys') diff --git a/modules/game_hotkeys/hotkeys_manager.otmod b/modules/game_hotkeys/hotkeys_manager.otmod index 50e6fa6a..af9ff48b 100644 --- a/modules/game_hotkeys/hotkeys_manager.otmod +++ b/modules/game_hotkeys/hotkeys_manager.otmod @@ -3,13 +3,13 @@ Module description: Manage client hotkeys author: OTClient team website: https://github.com/edubart/otclient - + dependencies: - - client_tibiafiles - - onLoad: | + - game + + @onLoad: | dofile 'hotkeys_manager' HotkeysManager.init() - onUnload: | + @onUnload: | HotkeysManager.terminate() \ No newline at end of file diff --git a/modules/game_interface/gameinterface.otmod b/modules/game_interface/gameinterface.otmod index 3c395a06..854b126f 100644 --- a/modules/game_interface/gameinterface.otmod +++ b/modules/game_interface/gameinterface.otmod @@ -7,7 +7,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + @onLoad: | dofile 'uiminiwindow' dofile 'uiminiwindowcontainer' dofile 'uiitem' @@ -16,5 +16,5 @@ Module GameInterface.init() - onUnload: | + @onUnload: | GameInterface.terminate() diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index 60c9472e..4631d346 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -6,7 +6,7 @@ local inventoryButton -- public functions function Inventory.create() - inventoryWindow = displayUI('inventory.otui', g_game.gameRightPanel) + inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel()) inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle) inventoryButton:setOn(true) Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) diff --git a/modules/game_inventory/inventory.otmod b/modules/game_inventory/inventory.otmod index e84eb31c..6e1aa54d 100644 --- a/modules/game_inventory/inventory.otmod +++ b/modules/game_inventory/inventory.otmod @@ -3,5 +3,6 @@ Module description: View local player equipments window author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'inventory' diff --git a/modules/game_outfit/outfit.lua b/modules/game_outfit/outfit.lua index 9fa17430..a7d631a4 100644 --- a/modules/game_outfit/outfit.lua +++ b/modules/game_outfit/outfit.lua @@ -1,84 +1,84 @@ Outfit = {} -- private variables -local window = nil -local m_creature = nil -local m_outfit = nil -local m_outfits = nil -local m_currentOutfit = 1 -local m_currentColor = nil -local m_currentClothe = nil +local outfitWindow +local outfitCreature +local outfit +local outfits +local currentOutfit = 1 +local currentColorBox +local currentClotheButtonBox -- private functions local function onAddonCheckChange(addon, value) if addon:isChecked() then - m_outfit.addons = m_outfit.addons + value + outfit.addons = outfit.addons + value else - m_outfit.addons = m_outfit.addons - value + outfit.addons = outfit.addons - value end - m_creature:setOutfit(m_outfit) + outfitCreature:setOutfit(outfit) end -local function onColorCheckChange(color) - if color == m_currentColor then - color.onCheckChange = nil - color:setChecked(true) - color.onCheckChange = onColorCheckChange +local function onColorCheckChange(colorBox) + if colorBox == currentColorBox then + colorBox.onCheckChange = nil + colorBox:setChecked(true) + colorBox.onCheckChange = onColorCheckChange else - m_currentColor.onCheckChange = nil - m_currentColor:setChecked(false) - m_currentColor.onCheckChange = onColorCheckChange - - m_currentColor = color - - if m_currentClothe:getId() == 'head' then - m_outfit.head = m_currentColor.colorId - elseif m_currentClothe:getId() == 'primary' then - m_outfit.body = m_currentColor.colorId - elseif m_currentClothe:getId() == 'secondary' then - m_outfit.legs = m_currentColor.colorId - elseif m_currentClothe:getId() == 'detail' then - m_outfit.feet = m_currentColor.colorId + currentColorBox.onCheckChange = nil + currentColorBox:setChecked(false) + currentColorBox.onCheckChange = onColorCheckChange + + currentColorBox = colorBox + + if currentClotheButtonBox:getId() == 'head' then + outfit.head = currentColorBox.colorId + elseif currentClotheButtonBox:getId() == 'primary' then + outfit.body = currentColorBox.colorId + elseif currentClotheButtonBox:getId() == 'secondary' then + outfit.legs = currentColorBox.colorId + elseif currentClotheButtonBox:getId() == 'detail' then + outfit.feet = currentColorBox.colorId end - m_creature:setOutfit(m_outfit) + outfitCreature:setOutfit(outfit) end end -local function onClotheCheckChange(clothe) - if clothe == m_currentClothe then - clothe.onCheckChange = nil - clothe:setChecked(true) - clothe.onCheckChange = onClotheCheckChange +local function onClotheCheckChange(clotheButtonBox) + if clotheButtonBox == currentClotheButtonBox then + clotheButtonBox.onCheckChange = nil + clotheButtonBox:setChecked(true) + clotheButtonBox.onCheckChange = onClotheCheckChange else - m_currentClothe.onCheckChange = nil - m_currentClothe:setChecked(false) - m_currentClothe.onCheckChange = onClotheCheckChange - - m_currentClothe = clothe - - local color = 0 - if m_currentClothe:getId() == 'head' then - color = m_outfit.head - elseif m_currentClothe:getId() == 'primary' then - color = m_outfit.body - elseif m_currentClothe:getId() == 'secondary' then - color = m_outfit.legs - elseif m_currentClothe:getId() == 'detail' then - color = m_outfit.feet + currentClotheButtonBox.onCheckChange = nil + currentClotheButtonBox:setChecked(false) + currentClotheButtonBox.onCheckChange = onClotheCheckChange + + currentClotheButtonBox = clotheButtonBox + + local colorId = 0 + if currentClotheButtonBox:getId() == 'head' then + colorId = outfit.head + elseif currentClotheButtonBox:getId() == 'primary' then + colorId = outfit.body + elseif currentClotheButtonBox:getId() == 'secondary' then + colorId = outfit.legs + elseif currentClotheButtonBox:getId() == 'detail' then + colorId = outfit.feet end - window:getChildById('color' .. color):setChecked(true) + outfitWindow:recursiveGetChildById('colorBox' .. colorId):setChecked(true) end end local function update() - local nameWidget = window:getChildById('name') - nameWidget:setText(m_outfits[m_currentOutfit][2]) + local nameWidget = outfitWindow:getChildById('outfitName') + nameWidget:setText(outfits[currentOutfit][2]) - local availableAddons = m_outfits[m_currentOutfit][3] - local addon1 = window:getChildById('addon1') - local addon2 = window:getChildById('addon2') - local addon3 = window:getChildById('addon3') + local availableAddons = outfits[currentOutfit][3] + local addon1 = outfitWindow:getChildById('addon1') + local addon2 = outfitWindow:getChildById('addon2') + local addon3 = outfitWindow:getChildById('addon3') addon1:setChecked(false) addon2:setChecked(false) addon3:setChecked(false) @@ -111,55 +111,63 @@ local function update() addon3:setEnabled(true) end - m_outfit.type = m_outfits[m_currentOutfit][1] - m_outfit.addons = 0 - m_creature:setOutfit(m_outfit) - + outfit.type = outfits[currentOutfit][1] + outfit.addons = 0 + outfitCreature:setOutfit(outfit) end -- public functions +function Outfit.init() + connect(g_game, { onOpenOutfitWindow = Outfit.create, + onGameEnd = Outfit.destroy }) +end + +function Outfit.terminate() + disconnect(g_game, { onOpenOutfitWindow = Outfit.create, + onGameEnd = Outfit.destroy }) + Outfit.destroy() +end + function Outfit.create(creature, outfitList) + outfitCreature = creature + outfits = outfitList Outfit.destroy() - window = displayUI('outfit.otui') - window:lock() - m_outfit = creature:getOutfit() + outfitWindow = displayUI('outfit.otui') + --outfitWindow:lock() - m_currentClothe = window:getChildById('head') - window:getChildById('head').onCheckChange = onClotheCheckChange - window:getChildById('primary').onCheckChange = onClotheCheckChange - window:getChildById('secondary').onCheckChange = onClotheCheckChange - window:getChildById('detail').onCheckChange = onClotheCheckChange + outfit = outfitCreature:getOutfit() - local creatureWidget = window:getChildById('creature') - creatureWidget:setCreature(creature) + currentClotheButtonBox = outfitWindow:getChildById('head') + outfitWindow:getChildById('head').onCheckChange = onClotheCheckChange + outfitWindow:getChildById('primary').onCheckChange = onClotheCheckChange + outfitWindow:getChildById('secondary').onCheckChange = onClotheCheckChange + outfitWindow:getChildById('detail').onCheckChange = onClotheCheckChange - for i=0,18 do - for j=0,6 do - local color = createWidget('Color', window) + local outfitCreatureBox = outfitWindow:getChildById('outfitCreatureBox') + local colorBoxPanel = outfitWindow:getChildById('colorBoxPanel') + outfitCreatureBox:setCreature(outfitCreature) + + for j=0,6 do + for i=0,18 do + local colorBox = createWidget('ColorBox', colorBoxPanel) local outfitColor = getOufitColor(j*19 + i) - color:setId('color' .. j*19+i) - color.colorId = j*19 + i - color:setImageColor(outfitColor) - color:setMarginTop(j * 3 + j * 14) - color:setMarginLeft(10 + i * 3 + i * 14) - - if j*19 + i == m_outfit.head then - m_currentColor = color - color:setChecked(true) - end + colorBox:setImageColor(outfitColor) + colorBox:setId('colorBox' .. j*19+i) + colorBox.colorId = j*19 + i - color.onCheckChange = onColorCheckChange + if j*19 + i == outfit.head then + currentColorBox = colorBox + colorBox:setChecked(true) + end + colorBox.onCheckChange = onColorCheckChange end end - m_creature = creature - m_outfits = outfitList - - m_currentOutfit = 1 + currentOutfit = 1 for i=1,#outfitList do - if outfitList[i][1] == m_outfit.type then - m_currentOutfit = i + if outfitList[i][1] == outfit.type then + currentOutfit = i break end end @@ -168,35 +176,33 @@ function Outfit.create(creature, outfitList) end function Outfit.destroy() - if window ~= nil then - window:destroy() - window = nil + if outfitWindow then + outfitWindow:destroy() + outfitWindow = nil + outfitCreature = nil + currentColorBox = nil + currentClotheButtonBox = nil end end function Outfit.accept() - g_game.changeOutfit(m_outfit) + g_game.changeOutfit(outfit) Outfit.destroy() end function Outfit.nextType() - m_currentOutfit = m_currentOutfit + 1 - if m_currentOutfit > #m_outfits then - m_currentOutfit = 1 + currentOutfit = currentOutfit + 1 + if currentOutfit > #outfits then + currentOutfit = 1 end - update() end function Outfit.previousType() - m_currentOutfit = m_currentOutfit - 1 - if m_currentOutfit <= 0 then - m_currentOutfit = #m_outfits + currentOutfit = currentOutfit - 1 + if currentOutfit <= 0 then + currentOutfit = #outfits end - update() end --- hooked events -connect(g_game, { onOpenOutfitWindow = Outfit.create, - onGameEnd = Outfit.destroy }) diff --git a/modules/game_outfit/outfit.otmod b/modules/game_outfit/outfit.otmod index 6aa64a13..2d1bf655 100644 --- a/modules/game_outfit/outfit.otmod +++ b/modules/game_outfit/outfit.otmod @@ -3,5 +3,11 @@ Module description: Change local player outfit author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + reloadable: true + + @onLoad: | dofile 'outfit' + Outfit.init() + + @onUnload: | + Outfit.terminate() diff --git a/modules/game_outfit/outfit.otui b/modules/game_outfit/outfit.otui index f34ba0b6..3982eb73 100644 --- a/modules/game_outfit/outfit.otui +++ b/modules/game_outfit/outfit.otui @@ -1,7 +1,3 @@ -Color < ColorBox - anchors.top: head.top - anchors.left: head.right - Window text: Select Outfit size: 550 280 @@ -14,7 +10,7 @@ Window @onEscape: Outfit.destroy() Label - id: name + id: outfitName text: Outfit Name width: 100 anchors.top: parent.top @@ -23,60 +19,81 @@ Window margin-left: 20 Creature - id: creature - anchors.top: name.bottom - anchors.left: name.left + id: outfitCreatureBox + anchors.top: outfitName.bottom + anchors.left: outfitName.left margin-top: 5 padding: 16 4 4 16 fixed-creature-size: true + Panel + id: colorBoxPanel + anchors.top: parent.top + anchors.right: parent.right + margin-top: 54 + margin-right: 20 + width: 323 + height: 119 + layout: + type: grid + cell-size: 16 16 + cell-spacing: 2 + num-columns: 19 + num-lines: 7 + ButtonBox id: head text: Head - anchors.top: creature.top - anchors.left: creature.right + anchors.top: outfitCreatureBox.top + anchors.left: outfitCreatureBox.right margin-left: 10 checked: true + width: 90 ButtonBox id: primary text: Primary anchors.top: prev.bottom anchors.left: prev.left + width: 90 ButtonBox id: secondary text: Secondary anchors.top: prev.bottom anchors.left: prev.left + width: 90 ButtonBox id: detail text: Detail anchors.top: prev.bottom anchors.left: prev.left + width: 90 Button + id: outfitNextButton @onClick: Outfit.nextType() text: >> width: 32 margin-top: 4 - anchors.top: creature.bottom - anchors.right: creature.right + anchors.top: outfitCreatureBox.bottom + anchors.right: outfitCreatureBox.right Button + id: outfitPreviousButton @onClick: Outfit.previousType() text: << width: 32 margin-top: 4 - anchors.top: creature.bottom - anchors.left: creature.left + anchors.top: outfitCreatureBox.bottom + anchors.left: outfitCreatureBox.left CheckBox id: addon1 text: Addon 1 enabled: false - margin-top: 10 + margin-top: 6 width: 100 anchors.top: prev.bottom anchors.left: prev.left @@ -85,7 +102,7 @@ Window id: addon2 text: Addon 2 enabled: false - margin-top: 10 + margin-top: 2 width: 100 anchors.top: prev.bottom anchors.left: prev.left @@ -94,7 +111,7 @@ Window id: addon3 text: Addon 3 enabled: false - margin-top: 10 + margin-top: 2 width: 100 anchors.top: prev.bottom anchors.left: prev.left @@ -108,7 +125,7 @@ Window margin-bottom: 10 Button - id: buttonOk + id: outfitOkButton text: Ok width: 64 anchors.right: next.left @@ -118,7 +135,7 @@ Window @onClick: Outfit.accept() Button - id: buttonCancel + id: outfitCancelButton text: Cancel width: 64 anchors.right: parent.right diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index b866ab47..6df65ebb 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -42,7 +42,7 @@ end -- public functions function Skills.create() - skillsWindow = displayUI('skills.otui', g_game.gameRightPanel) + skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel()) skillsWindow:hide() skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle) Keyboard.bindKeyDown('Ctrl+S', Skills.toggle) diff --git a/modules/game_skills/skills.otmod b/modules/game_skills/skills.otmod index c9cfdd7b..991f6fc6 100644 --- a/modules/game_skills/skills.otmod +++ b/modules/game_skills/skills.otmod @@ -3,5 +3,6 @@ Module description: Manage skills window author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'skills' diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 4fc39084..7070d4a4 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -24,7 +24,7 @@ local function displayMessage(msgtype, msg, time) if not g_game.isOnline() then return end if msgtype.consoleTab ~= nil then - if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then + if msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption) then Console.addText(msg, msgtype, msgtype.consoleTab) end end @@ -93,7 +93,7 @@ end function TextMessage.terminate() disconnect(g_game, { onDeath = TextMessage.displayDeadMessage, onTextMessage = TextMessage.display, - onGameStart = TextMessage.clearMessages }) + onGameEnd = TextMessage.clearMessages }) centerTextMessagePanel:destroy() centerTextMessagePanel = nil bottomStatusLabel:destroy() diff --git a/modules/game_tibiafiles/.gitignore b/modules/game_tibiafiles/.gitignore new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/modules/game_tibiafiles/.gitignore @@ -0,0 +1 @@ + diff --git a/modules/game_viplist/viplist.lua b/modules/game_viplist/viplist.lua index 5a5838ea..853c5220 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/game_viplist/viplist.lua @@ -7,7 +7,7 @@ local addVipWindow -- public functions function VipList.create() - vipWindow = displayUI('viplist.otui', g_game.gameRightPanel) + vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel()) vipWindow:hide() vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) end diff --git a/modules/game_viplist/viplist.otmod b/modules/game_viplist/viplist.otmod index 95d02acb..a91b426d 100644 --- a/modules/game_viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -3,5 +3,6 @@ Module description: Manage vip list window author: OTClient team website: https://github.com/edubart/otclient - onLoad: | + + @onLoad: | dofile 'viplist' diff --git a/modules/old/game/game.lua b/modules/old/game/game.lua index 0cd3266a..cede73ee 100644 --- a/modules/old/game/game.lua +++ b/modules/old/game/game.lua @@ -1,5 +1,5 @@ -- private variables -local m_mouseGrabberWidget +local mouseGrabberWidget -- private functions local function onGameKeyPress(self, keyCode, keyboardModifiers) @@ -41,7 +41,7 @@ end -- public functions function g_game.startUseWith(thing) g_game.selectedThing = thing - m_mouseGrabberWidget:grabMouse() + mouseGrabberWidget:grabMouse() Mouse.setTargetCursor() end @@ -49,11 +49,11 @@ function g_game.createInterface() rootWidget:moveChildToIndex(g_game.gameUi, 1) g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel') - g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel') + GameInterface.getRightPanel() = g_game.gameUi:getChildById('gameRightPanel') g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel') - m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber') + mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber') connect(g_game.gameUi, { onKeyPress = onGameKeyPress }) - connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease }) + connect(mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease }) end function g_game.destroyInterface() diff --git a/modules/old/game/thing.lua b/modules/old/game/thing.lua index 61db9c92..fe920a83 100644 --- a/modules/old/game/thing.lua +++ b/modules/old/game/thing.lua @@ -19,7 +19,7 @@ function g_game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThin return true end - if not Options.classicControl then + if not Options.getOption('classicControl') then if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) return true diff --git a/src/framework/core/logger.cpp b/src/framework/core/logger.cpp index b1b119ad..1802901c 100644 --- a/src/framework/core/logger.cpp +++ b/src/framework/core/logger.cpp @@ -44,6 +44,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message) std::size_t now = std::time(NULL); m_logMessages.push_back(LogMessage(level, outmsg, now)); + if(m_logMessages.size() > MAX_LOG_HISTORY) + m_logMessages.pop_front(); if(m_onLog) m_onLog(level, outmsg, now); diff --git a/src/framework/core/logger.h b/src/framework/core/logger.h index 47420f53..d06cad7d 100644 --- a/src/framework/core/logger.h +++ b/src/framework/core/logger.h @@ -34,6 +34,10 @@ struct LogMessage { class Logger { + enum { + MAX_LOG_HISTORY = 1000 + }; + typedef std::function OnLogCallback; public: diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index a4ba3648..36b981fe 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -171,7 +171,6 @@ void Texture::generateSoftwareMipmaps(std::vector inPixels) Size outSize = inSize / 2; std::vector outPixels(outSize.area()*4); - dump << "yeah"; int mipmap = 1; while(true) { // this is a simple bilinear filtering algorithm, it combines every 4 pixels in one pixel diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 70215d7b..e88e86d4 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -225,6 +225,31 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget) updateDraggingWidget(nullptr); } +void UIManager::addDestroyedWidget(const UIWidgetPtr& widget) +{ + static UIWidgetList destroyedWidgets; + static ScheduledEventPtr checkEvent; + + if(widget == m_rootWidget) + return; + + destroyedWidgets.push_back(widget); + + if(checkEvent && !checkEvent->isExecuted()) + return; + + checkEvent = g_eventDispatcher.scheduleEvent([] { + g_lua.collectGarbage(); + g_eventDispatcher.addEvent([] { + g_lua.collectGarbage(); + for(const UIWidgetPtr& widget : destroyedWidgets) { + if(widget->getUseCount() != 1) + logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left"); + } + }); + }, 1000); +} + bool UIManager::importStyle(const std::string& file) { try { diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 09d90789..622ceffe 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -68,6 +68,7 @@ protected: void onWidgetAppear(const UIWidgetPtr& widget); void onWidgetDisappear(const UIWidgetPtr& widget); void onWidgetDestroy(const UIWidgetPtr& widget); + void addDestroyedWidget(const UIWidgetPtr& widget); friend class UIWidget; diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 95edde98..8aff05bb 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -636,10 +636,8 @@ void UIWidget::destroy() g_ui.onWidgetDestroy(asUIWidget()); // remove itself from parent - if(UIWidgetPtr parent = getParent()) { - assert(parent->hasChild(asUIWidget())); + if(UIWidgetPtr parent = getParent()) parent->removeChild(asUIWidget()); - } destroyChildren(); m_focusedChild = nullptr; @@ -649,15 +647,7 @@ void UIWidget::destroy() releaseLuaFieldsTable(); #ifdef DEBUG - auto self = asUIWidget(); - g_lua.collectGarbage(); - if(self != g_ui.getRootWidget()) { - g_eventDispatcher.scheduleEvent([self] { - g_lua.collectGarbage(); - if(self->getUseCount() != 1) - logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left"); - }, 500); - } + g_ui.addDestroyedWidget(asUIWidget()); #endif } diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 1d27729c..db80ce73 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -207,6 +207,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("setEmblemTexture", &Creature::setEmblemTexture); g_lua.bindClassMemberFunction("showStaticSquare", &Creature::showStaticSquare); g_lua.bindClassMemberFunction("hideStaticSquare", &Creature::hideStaticSquare); + g_lua.bindClassMemberFunction("isWalking", &Creature::isWalking); g_lua.bindClassMemberFunction("asMonster", &Creature::asMonster); g_lua.bindClassMemberFunction("asNpc", &Creature::asNpc); @@ -220,7 +221,9 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.registerClass(); - g_lua.bindClassMemberFunction("isWalking", &Creature::isWalking); + g_lua.bindClassMemberFunction("isPartyMember", &LocalPlayer::isPartyMember); + g_lua.bindClassMemberFunction("isPartyLeader", &LocalPlayer::isPartyLeader); + g_lua.bindClassMemberFunction("isPartySharedExperienceActive", &LocalPlayer::isPartySharedExperienceActive); g_lua.registerClass(); g_lua.registerClass();