diff --git a/modules/client_main/client.lua b/modules/client/client.lua similarity index 88% rename from modules/client_main/client.lua rename to modules/client/client.lua index 5fcc36e5..36288807 100644 --- a/modules/client_main/client.lua +++ b/modules/client/client.lua @@ -1,7 +1,6 @@ Client = {} function Client.init() - g_window.show() g_window.setMinimumSize({ width = 600, height = 480 }) -- initialize in fullscreen mode on mobile devices @@ -27,6 +26,13 @@ function Client.init() g_window.setTitle('OTClient') g_window.setIcon(resolvepath('clienticon.png')) + + -- show the only window after the first frame is rendered + addEvent(function() + addEvent(function() + g_window.show() + end) + end) end function Client.terminate() diff --git a/modules/client/client.otmod b/modules/client/client.otmod new file mode 100644 index 00000000..7d68479a --- /dev/null +++ b/modules/client/client.otmod @@ -0,0 +1,23 @@ +Module + name: client + description: Initialize the client and setups its main window + author: OTClient team + website: https://github.com/edubart/otclient + autoload: true + autoload-priority: 100 + + load-later: + - client_topmenu + - client_background + - client_about + - client_options + - client_terminal + - client_modulemanager + - client_entergame + + @onLoad: | + dofile 'client' + Client.init() + + @onUnload: | + Client.terminate() diff --git a/modules/client_main/clienticon.png b/modules/client/clienticon.png similarity index 100% rename from modules/client_main/clienticon.png rename to modules/client/clienticon.png diff --git a/modules/client_about/about.lua b/modules/client_about/about.lua index f53cc384..795da653 100644 --- a/modules/client_about/about.lua +++ b/modules/client_about/about.lua @@ -2,22 +2,33 @@ About = {} -- private variables local aboutButton +local aboutWindow -- public functions function About.init() - aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.display) -end - -function About.display() - displayUI('about.otui', { locked = true }) + aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.show) + aboutWindow = displayUI('about.otui') + aboutWindow:hide() end function About.terminate() aboutButton:destroy() aboutButton = nil + aboutWindow:destroy() + aboutWindow = nil About = nil end +function About.show() + aboutWindow:show() + aboutWindow:raise() + aboutWindow:focus() +end + +function About.hide() + aboutWindow:hide() +end + function About.openWebpage() displayErrorBox("Error", "Not implemented yet") end diff --git a/modules/client_about/about.otmod b/modules/client_about/about.otmod index f461baa4..0e98b90f 100644 --- a/modules/client_about/about.otmod +++ b/modules/client_about/about.otmod @@ -3,16 +3,14 @@ Module description: Create the about window author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 160 - unloadable: true + reloadable: true dependencies: - client_topmenu - onLoad: | + @onLoad: | dofile 'about' About.init() - onUnload: | + @onUnload: | About.terminate() diff --git a/modules/client_about/about.otui b/modules/client_about/about.otui index 37fcb63b..2dc9f88f 100644 --- a/modules/client_about/about.otui +++ b/modules/client_about/about.otui @@ -3,6 +3,9 @@ MainWindow text: Info size: 244 221 + @onEnter: About.hide() + @onEscape: About.hide() + FlatPanel size: 208 129 anchors.left: parent.left @@ -52,4 +55,4 @@ MainWindow size: 46 24 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: self:getParent():destroy() + @onClick: About.hide() diff --git a/modules/client_background/background.lua b/modules/client_background/background.lua index 3b237b84..2cd62aec 100644 --- a/modules/client_background/background.lua +++ b/modules/client_background/background.lua @@ -7,11 +7,18 @@ local background function Background.init() background = displayUI('background.otui') background:lower() + + connect(g_game, { onGameStart = Background.hide }) + connect(g_game, { onGameEnd = Background.show }) end function Background.terminate() + disconnect(g_game, { onGameStart = Background.hide }) + disconnect(g_game, { onGameEnd = Background.show }) + background:destroy() background = nil + Background = nil end diff --git a/modules/client_background/background.otmod b/modules/client_background/background.otmod index 0a8ecfd9..312fca2b 100644 --- a/modules/client_background/background.otmod +++ b/modules/client_background/background.otmod @@ -3,12 +3,14 @@ Module description: Handles the background of the login screen author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 110 + reloadable: true - onLoad: | + dependencies: + - client_topmenu + + @onLoad: | dofile 'background' Background.init() - onUnload: | + @onUnload: | Background.terminate() diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index 20709d14..33412f64 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -52,7 +52,27 @@ local function tryLogin(charInfo, tries) Settings.set('lastUsedCharacter', charInfo.characterName) end + +function onGameLoginError(message) + CharacterList.destroyLoadBox() + local errorBox = displayErrorBox("Login Error", "Login error: " .. message) + errorBox.onOk = CharacterList.show +end + +function onGameConnectionError(message) + CharacterList.destroyLoadBox() + local errorBox = displayErrorBox("Login Error", "Connection error: " .. message) + errorBox.onOk = CharacterList.show +end + -- public functions +function CharacterList.init() + connect(g_game, { onLoginError = onGameLoginError }) + connect(g_game, { onConnectionError = onGameConnectionError }) + connect(g_game, { onGameStart = CharacterList.destroyLoadBox }) + connect(g_game, { onGameEnd = CharacterList.show }) +end + function CharacterList.terminate() characterList = nil if charactersWindow then @@ -60,6 +80,7 @@ function CharacterList.terminate() charactersWindow = nil end if loadBox then + g_game.cancelLogin() loadBox:destroy() loadBox = nil end @@ -118,6 +139,7 @@ end function CharacterList.show() if not loadBox then charactersWindow:show() + charactersWindow:raise() charactersWindow:focus() end end diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index 00cbb8e0..caba4504 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -59,11 +59,11 @@ end -- public functions function EnterGame.init() - enterGameButton = TopMenu.addButton('enterGameButton', 'Login (Ctrl + G)', '/core_styles/icons/login.png', EnterGame.openWindow) - Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow) - motdButton = TopMenu.addButton('motdButton', 'Message of the day', '/core_styles/icons/motd.png', EnterGame.displayMotd) - motdButton:hide() enterGame = displayUI('entergame.otui') + enterGameButton = TopMenu.addLeftButton('enterGameButton', 'Login (Ctrl + G)', 'login.png', EnterGame.openWindow) + motdButton = TopMenu.addLeftButton('motdButton', 'Message of the day', 'motd.png', EnterGame.displayMotd) + motdButton:hide() + Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow) local account = Settings.get('account') local password = Settings.get('password') @@ -102,6 +102,7 @@ end function EnterGame.show() enterGame:show() + enterGame:raise() enterGame:focus() end diff --git a/modules/client_entergame/entergame.otmod b/modules/client_entergame/entergame.otmod index 85a2e8d4..fc259753 100644 --- a/modules/client_entergame/entergame.otmod +++ b/modules/client_entergame/entergame.otmod @@ -3,14 +3,17 @@ Module description: Manages enter game and character list windows author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 150 + reloadable: true - onLoad: | + dependencies: + - client_topmenu + + @onLoad: | dofile 'entergame' dofile 'characterlist' EnterGame.init() + CharacterList.init() - onUnload: | + @onUnload: | EnterGame.terminate() CharacterList.terminate() diff --git a/modules/client_entergame/entergame.otui b/modules/client_entergame/entergame.otui index 0da010c7..7a9d2d71 100644 --- a/modules/client_entergame/entergame.otui +++ b/modules/client_entergame/entergame.otui @@ -5,7 +5,7 @@ MainWindow @onEnter: EnterGame.doLogin() @onEscape: EnterGame.hide() - LargerLabel + Label text: Account name anchors.left: parent.left anchors.top: parent.top @@ -17,7 +17,7 @@ MainWindow anchors.top: prev.bottom margin-top: 2 - LargerLabel + Label text: Password anchors.left: prev.left anchors.top: prev.bottom @@ -30,7 +30,7 @@ MainWindow anchors.top: prev.bottom margin-top: 2 - LargerLabel + Label id: serverLabel width: 140 text: Server @@ -46,7 +46,7 @@ MainWindow anchors.top: serverLabel.bottom margin-top: 2 - LargerLabel + Label id: portLabel text: Port width: 50 diff --git a/modules/core_styles/icons/login.png b/modules/client_entergame/login.png similarity index 100% rename from modules/core_styles/icons/login.png rename to modules/client_entergame/login.png diff --git a/modules/core_styles/icons/motd.png b/modules/client_entergame/motd.png similarity index 100% rename from modules/core_styles/icons/motd.png rename to modules/client_entergame/motd.png diff --git a/modules/client_main/client.otmod b/modules/client_main/client.otmod deleted file mode 100644 index f968137b..00000000 --- a/modules/client_main/client.otmod +++ /dev/null @@ -1,14 +0,0 @@ -Module - name: client_main - description: Initialize the client and setups its main window - author: OTClient team - website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 100 - - onLoad: | - dofile 'client' - Client.init() - - onUnload: | - Client.terminate() diff --git a/modules/client_modulemanager/modulemanager.lua b/modules/client_modulemanager/modulemanager.lua index 0abe9544..4d6f8b6e 100644 --- a/modules/client_modulemanager/modulemanager.lua +++ b/modules/client_modulemanager/modulemanager.lua @@ -16,8 +16,9 @@ function ModuleManager.init() Keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow) Keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow) - moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle) + moduleManagerButton = TopMenu.addLeftButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle) + -- refresh modules only after all modules are loaded addEvent(ModuleManager.listModules) end @@ -36,8 +37,8 @@ end function ModuleManager.show() moduleManagerWindow:show() - moduleManagerWindow:focus() moduleManagerWindow:raise() + moduleManagerWindow:focus() end function ModuleManager.toggle() @@ -98,8 +99,8 @@ function ModuleManager.updateModuleInfo(moduleName) website = module:getWebsite() version = module:getVersion() loaded = module:isLoaded() + canReload = module:canReload() canUnload = module:canUnload() - canReload = not loaded or canUnload end moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name) @@ -111,12 +112,10 @@ function ModuleManager.updateModuleInfo(moduleName) local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton') reloadButton:setEnabled(canReload) - reloadButton:setVisible(true) if loaded then reloadButton:setText('Reload') else reloadButton:setText('Load') end local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton') - unloadButton:setVisible(true) unloadButton:setEnabled(canUnload) end @@ -126,6 +125,7 @@ function ModuleManager.reloadCurrentModule() local module = g_modules.getModule(focusedChild:getText()) if module then module:reload() + if ModuleManager == nil then return end ModuleManager.updateModuleInfo(module:getName()) ModuleManager.refreshLoadedModules() ModuleManager.show() @@ -139,6 +139,7 @@ function ModuleManager.unloadCurrentModule() local module = g_modules.getModule(focusedChild:getText()) if module then module:unload() + if ModuleManager == nil then return end ModuleManager.updateModuleInfo(module:getName()) ModuleManager.refreshLoadedModules() end diff --git a/modules/client_modulemanager/modulemanager.otmod b/modules/client_modulemanager/modulemanager.otmod index c66210b0..a3b5fd87 100644 --- a/modules/client_modulemanager/modulemanager.otmod +++ b/modules/client_modulemanager/modulemanager.otmod @@ -3,15 +3,16 @@ Module description: Manage other modules author: OTClient team website: https://github.com/edubart/otclient + reloadable: true autoload: true - autoload-antecedence: 140 + autoload-priority: 140 dependencies: - client_topmenu - onLoad: | + @onLoad: | dofile 'modulemanager' ModuleManager.init() - onUnload: | + @onUnload: | ModuleManager.terminate() diff --git a/modules/client_modulemanager/modulemanager.otui b/modules/client_modulemanager/modulemanager.otui index 69bb012b..2d58499e 100644 --- a/modules/client_modulemanager/modulemanager.otui +++ b/modules/client_modulemanager/modulemanager.otui @@ -27,7 +27,7 @@ ModuleValueLabel < UILabel font: verdana-11px-antialised color: #aaaaaa text-offset: 3 0 - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 height: 16 @@ -92,9 +92,9 @@ MainWindow // id: moduleAutoload //ModuleInfoLabel - // text: Autoload antecedence + // text: Autoload priority //ModuleValueLabel - // id: moduleLoadAntecedence + // id: moduleLoadPriority // text: 1000 ModuleInfoLabel @@ -118,7 +118,7 @@ MainWindow anchors.left: moduleInfo.left margin-top: 8 text: Load - visible: false + enabled: false @onClick: ModuleManager.reloadCurrentModule() Button @@ -128,6 +128,14 @@ MainWindow margin-left: 10 margin-top: 8 text: Unload - visible: false + enabled: false @onClick: ModuleManager.unloadCurrentModule() + Button + id: closeButton + anchors.bottom: parent.bottom + anchors.right: parent.right + text: Close + width: 60 + @onClick: ModuleManager.hide() + diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index e2225613..b7d5957e 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -2,29 +2,29 @@ Options = {} local optionsWindow local optionsButton +local options = { vsync = true, + showfps = true, + fullscreen = false, + classicControl = false, + showStatusMessagesInConsole = true, + showEventMessagesInConsole = true, + showInfoMessagesInConsole = true, + showTimestampsInConsole = true, + showLevelsInConsole = true, + showPrivateMessagesInConsole = true } function Options.init() - -- load settings - local booleanOptions = { vsync = true, - showfps = true, - fullscreen = false, - classicControl = false, - showStatusMessagesInConsole = true, - showEventMessagesInConsole = true, - showInfoMessagesInConsole = true, - showTimestampsInConsole = true, - showLevelsInConsole = true, - showPrivateMessagesInConsole = true, - } - - for k,v in pairs(booleanOptions) do - Settings.setDefault(k, v) - Options.changeOption(k, Settings.getBoolean(k)) + -- load options + for k,v in pairs(options) do + if type(v) == 'boolean' then + Settings.setDefault(k, v) + Options.setOption(k, Settings.getBoolean(k)) + end end optionsWindow = displayUI('options.otui') - optionsWindow:setVisible(false) - optionsButton = TopMenu.addButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle) + optionsWindow:hide() + optionsButton = TopMenu.addLeftButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle) Keyboard.bindKeyDown('Ctrl+O', Options.toggle) end @@ -47,11 +47,11 @@ end function Options.show() optionsWindow:show() - optionsWindow:lock() + optionsWindow:raise() + optionsWindow:focus() end function Options.hide() - optionsWindow:unlock() optionsWindow:hide() end @@ -59,20 +59,24 @@ function Options.openWebpage() displayErrorBox("Error", "Not implemented yet") end --- private functions -function Options.changeOption(key, status) +function Options.setOption(key, value) if key == 'vsync' then - g_window.setVerticalSync(status) + g_window.setVerticalSync(value) elseif key == 'showfps' then addEvent(function() local frameCounter = rootWidget:recursiveGetChildById('frameCounter') - if frameCounter then frameCounter:setVisible(status) end + if frameCounter then frameCounter:setVisible(value) end end) elseif key == 'fullscreen' then addEvent(function() - g_window.setFullscreen(status) + g_window.setFullscreen(value) end) end - Settings.set(key, status) - Options[key] = status + Settings.set(key, value) + options[key] = value end + +function Options.getOption(key) + return options[key] +end + diff --git a/modules/client_options/options.otmod b/modules/client_options/options.otmod index 1ceda63e..bc9c118f 100644 --- a/modules/client_options/options.otmod +++ b/modules/client_options/options.otmod @@ -3,15 +3,14 @@ Module description: Create the options window author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 130 + reloadable: true dependencies: - client_topmenu - onLoad: | + @onLoad: | dofile 'options' Options.init() - onUnload: | + @onUnload: | Options.terminate() \ No newline at end of file diff --git a/modules/client_options/options.otui b/modules/client_options/options.otui index feaf0285..7353b113 100644 --- a/modules/client_options/options.otui +++ b/modules/client_options/options.otui @@ -1,6 +1,6 @@ OptionCheckBox < CheckBox - @onCheckChange: Options.changeOption(self:getId(), self:isChecked()) - @onSetup: self:setChecked(Options[self:getId()]) + @onCheckChange: Options.setOption(self:getId(), self:isChecked()) + @onSetup: self:setChecked(Options.getOption(self:getId())) $first: anchors.left: parent.left @@ -67,4 +67,4 @@ MainWindow width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: Options.hide() \ No newline at end of file + @onClick: Options.hide() diff --git a/modules/client_terminal/commands.lua b/modules/client_terminal/commands.lua index 45403a51..b4cba943 100644 --- a/modules/client_terminal/commands.lua +++ b/modules/client_terminal/commands.lua @@ -41,10 +41,6 @@ function debugContainersItems() end end -function quit() - exit() -end - function autoReloadModule(name) local function reloadEvent() reloadModule(name) diff --git a/modules/client_terminal/terminal.lua b/modules/client_terminal/terminal.lua index 5118748d..9dccd91e 100644 --- a/modules/client_terminal/terminal.lua +++ b/modules/client_terminal/terminal.lua @@ -110,26 +110,27 @@ function Terminal.init() terminalWidget = displayUI('terminal.otui') terminalWidget:setVisible(false) - terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle) + terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle) Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle) commandHistory = Settings.getList('terminal-history') commandLineEdit = terminalWidget:getChildById('commandLineEdit') - Keyboard.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit) - Keyboard.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit) + Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit) + Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit) Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit) Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit) + Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWidget) terminalBuffer = terminalWidget:getChildById('terminalBuffer') - Logger.setOnLog(onLog) - Logger.fireOldMessages() + g_logger.setOnLog(onLog) + g_logger.fireOldMessages() end function Terminal.terminate() Settings.setList('terminal-history', commandHistory) Keyboard.unbindKeyDown('Ctrl+T') - Logger.setOnLog(nil) + g_logger.setOnLog(nil) terminalButton:destroy() terminalButton = nil commandLineEdit = nil @@ -150,11 +151,11 @@ end function Terminal.show() terminalWidget:show() - terminalWidget:lock() + terminalWidget:raise() + terminalWidget:focus() end function Terminal.hide() - terminalWidget:unlock() terminalWidget:hide() end @@ -178,7 +179,7 @@ function Terminal.executeCommand(command) if command == nil or #command == 0 then return end logLocked = true - Logger.log(LogInfo, '>> ' .. command) + g_logger.log(LogInfo, '>> ' .. command) logLocked = false -- detect and convert commands with simple syntax @@ -210,7 +211,7 @@ function Terminal.executeCommand(command) -- check for syntax errors if not func then - Logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5)) + g_logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5)) return end @@ -223,6 +224,6 @@ function Terminal.executeCommand(command) -- if the command returned a value, print it if ret then print(ret) end else - Logger.log(LogError, 'command failed: ' .. ret) + g_logger.log(LogError, 'command failed: ' .. ret) end end diff --git a/modules/client_terminal/terminal.otmod b/modules/client_terminal/terminal.otmod index 7cc5618f..e354205c 100644 --- a/modules/client_terminal/terminal.otmod +++ b/modules/client_terminal/terminal.otmod @@ -3,13 +3,12 @@ Module description: Terminal for executing lua functions author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 160 + reloadable: true - onLoad: | + @onLoad: | dofile 'terminal' dofile 'commands' Terminal.init() - onUnload: | + @onUnload: | Terminal.terminate() diff --git a/modules/client_tibiafiles/tibiafiles.otmod b/modules/client_tibiafiles/tibiafiles.otmod deleted file mode 100644 index c487f543..00000000 --- a/modules/client_tibiafiles/tibiafiles.otmod +++ /dev/null @@ -1,14 +0,0 @@ -Module - name: client_tibiafiles - description: Contains tibia spr and dat - unloadable: false - autoload: true - autoload-antecedence: 170 - - onLoad: | - if not g_thingsType.load('/client_tibiafiles/Tibia.dat') then - fatal("Unable to load dat file, please place a valid Tibia dat in modules/client_tibiafiles/Tibia.dat") - end - if not g_sprites.load('/client_tibiafiles/Tibia.spr') then - fatal("Unable to load spr file, please place a valid Tibia spr in modules/client_tibiafiles/Tibia.spr") - end diff --git a/modules/core_styles/images/top_button.png b/modules/client_topmenu/images/top_button.png similarity index 100% rename from modules/core_styles/images/top_button.png rename to modules/client_topmenu/images/top_button.png diff --git a/modules/core_styles/images/top_button2.png b/modules/client_topmenu/images/top_game_button.png similarity index 100% rename from modules/core_styles/images/top_button2.png rename to modules/client_topmenu/images/top_game_button.png diff --git a/modules/core_styles/images/top_panel.png b/modules/client_topmenu/images/top_panel.png similarity index 100% rename from modules/core_styles/images/top_panel.png rename to modules/client_topmenu/images/top_panel.png diff --git a/modules/client_topmenu/topmenu.lua b/modules/client_topmenu/topmenu.lua index c476c60e..3ae4502f 100644 --- a/modules/client_topmenu/topmenu.lua +++ b/modules/client_topmenu/topmenu.lua @@ -7,12 +7,25 @@ local rightButtonsPanel local gameButtonsPanel -- private functions -local function onLogout() - if g_game.isOnline() then - g_game.safeLogout() +local function addButton(id, description, icon, callback, panel, toggle) + local class + if toggle then + class = 'TopToggleButton' + else + class = 'TopButton' + end + + local button = createWidget(class, panel) + button:setId(id) + button:setTooltip(description) + button:setIcon(resolvepath(icon, 3)) + + if toggle then + button.onCheckChange = callback else - exit() + button.onClick = callback end + return button end -- public functions @@ -22,15 +35,11 @@ function TopMenu.init() rightButtonsPanel = topMenu:getChildById('rightButtonsPanel') gameButtonsPanel = topMenu:getChildById('gameButtonsPanel') - TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout) - Keyboard.bindKeyDown('Ctrl+Q', onLogout) - connect(g_game, { onGameStart = TopMenu.showGameButtons, - onGameEnd = TopMenu.hideGameButtons }) + onGameEnd = TopMenu.hideGameButtons }) end function TopMenu.terminate() - Keyboard.unbindKeyDown('Ctrl+Q') leftButtonsPanel = nil rightButtonsPanel = nil gameButtonsPanel = nil @@ -38,45 +47,33 @@ function TopMenu.terminate() topMenu = nil disconnect(g_game, { onGameStart = TopMenu.showGameButtons, - onGameEnd = TopMenu.hideGameButtons }) + onGameEnd = TopMenu.hideGameButtons }) TopMenu = nil end -function TopMenu.addButton(id, description, icon, callback, right) - local panel - local class - if right then - panel = rightButtonsPanel - class = 'TopRightButton' - else - panel = leftButtonsPanel - class = 'TopLeftButton' - end +function TopMenu.addLeftButton(id, description, icon, callback) + return addButton(id, description, icon, callback, leftButtonsPanel, false) +end - local button = createWidget(class, panel) - button:setId(id) - button:setTooltip(description) - button:setIcon(resolvepath(icon, 2)) - button.onClick = callback - return button +function TopMenu.addLeftToggleButton(id, description, icon, callback, right) + return addButton(id, description, icon, callback, leftButtonsPanel, true) end -function TopMenu.addGameButton(id, description, icon, callback) - local button = createWidget('GameTopButton', gameButtonsPanel) - button:setId(id) - button:setTooltip(description) - button:setIcon(resolvepath(icon, 2)) - button.onClick = callback - return button +function TopMenu.addRightButton(id, description, icon, callback) + return addButton(id, description, icon, callback, rightButtonsPanel, false) end -function TopMenu.addLeftButton(id, description, icon, callback) - return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, false) +function TopMenu.addRightToggleButton(id, description, icon, callback, right) + return addButton(id, description, icon, callback, rightButtonsPanel, true) end -function TopMenu.addRightButton(id, description, icon, callback) - return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true) +function TopMenu.addGameButton(id, description, icon, callback) + return addButton(id, description, icon, callback, gameButtonsPanel, false) +end + +function TopMenu.addGameToggleButton(id, description, icon, callback, right) + return addButton(id, description, icon, callback, gameButtonsPanel, true) end function TopMenu.hideGameButtons() @@ -90,3 +87,5 @@ end function TopMenu.getButton(id) return topMenu:recursiveGetChildById(id) end + + diff --git a/modules/client_topmenu/topmenu.otmod b/modules/client_topmenu/topmenu.otmod index a2ff5ef7..82e357b4 100644 --- a/modules/client_topmenu/topmenu.otmod +++ b/modules/client_topmenu/topmenu.otmod @@ -3,12 +3,11 @@ Module description: Create the top menu author: OTClient team website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 120 + reloadable: true - onLoad: | + @onLoad: | dofile 'topmenu' TopMenu.init() - onUnload: | + @onUnload: | TopMenu.terminate() diff --git a/modules/client_topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui index 288704b2..fe791a4d 100644 --- a/modules/client_topmenu/topmenu.otui +++ b/modules/client_topmenu/topmenu.otui @@ -1,6 +1,6 @@ TopButton < UIButton size: 26 26 - image-source: /core_styles/images/top_button.png + image-source: images/top_button.png image-clip: 0 0 26 26 image-border: 3 image-color: #ffffffff @@ -17,66 +17,61 @@ TopButton < UIButton image-color: #ffffff44 icon-color: #ffffff44 -GameTopButton < UIButton +TopToggleButton < UICheckBox size: 26 26 - image-source: /core_styles/images/top_button2.png + image-source: images/top_game_button.png image-clip: 26 0 26 26 image-color: #ffffff22 - icon-color: #ffffffff image-border: 3 + icon-color: #ffffffff - $on: + $checked: image-clip: 0 0 26 26 image-color: #ffffffff icon-color: #ffffffff -TopLeftButton < TopButton -TopRightButton < TopButton +TopMenuButtonsPanel < Panel + layout: + type: horizontalBox + spacing: 4 + fit-children: true + padding: 6 4 + +TopPanel < Panel + height: 36 + image-source: images/top_panel.png + image-repeated: true + focusable: false + TopPanel id: topMenu anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right - focusable: false - Panel + TopMenuButtonsPanel id: leftButtonsPanel anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: parent.left - layout: - type: horizontalBox - spacing: 4 - fit-children: true - padding: 6 4 - Panel + TopMenuButtonsPanel id: gameButtonsPanel anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: prev.right anchors.right: next.left - layout: - type: horizontalBox - spacing: 4 - padding: 6 4 - visible: false - Panel + TopMenuButtonsPanel id: rightButtonsPanel anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right - layout: - type: horizontalBox - spacing: 4 - fit-children: true - padding: 6 4 FrameCounter id: frameCounter anchors.top: parent.top anchors.right: prev.left margin-top: 8 - margin-right: 5 \ No newline at end of file + margin-right: 5 diff --git a/modules/core_fonts/core_fonts.otmod b/modules/core_fonts/core_fonts.otmod deleted file mode 100644 index 1dcc0c5c..00000000 --- a/modules/core_fonts/core_fonts.otmod +++ /dev/null @@ -1,15 +0,0 @@ -Module - name: core_fonts - description: Contains fonts used by core - author: OTClient team - website: https://github.com/edubart/otclient - autoload: true - autoload-antecedence: 30 - - onLoad: | - importFont 'verdana-11px-antialised' - importFont 'verdana-11px-monochrome' - importFont 'verdana-11px-rounded' - importFont 'terminus-14px-bold' - setDefaultFont 'verdana-11px-antialised' - diff --git a/modules/core_lib/core_lib.otmod b/modules/core_lib/core_lib.otmod index 1039eba8..9992a42a 100644 --- a/modules/core_lib/core_lib.otmod +++ b/modules/core_lib/core_lib.otmod @@ -4,9 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient autoload: true - autoload-antecedence: 10 + autoload-priority: 10 - onLoad: | + @onLoad: | dofile 'ext/table' dofile 'ext/string' dofile 'ext/os' @@ -17,9 +17,26 @@ Module dofile 'const' dofile 'util' dofile 'globals' - dofile 'dispatcher' - dofile 'effects' dofile 'settings' dofile 'keyboard' dofile 'mouse' + dofile 'ui/effects' + dofile 'ui/radiogroup' + dofile 'ui/tooltip' + + dofile 'widgets/uiwidget' + dofile 'widgets/uibutton' + dofile 'widgets/uilabel' + dofile 'widgets/uicheckbox' + dofile 'widgets/uicombobox' + dofile 'widgets/uispinbox' + dofile 'widgets/uiprogressbar' + dofile 'widgets/uitabbar' + dofile 'widgets/uipopupmenu' + dofile 'widgets/uiwindow' + --dofile 'widgets/uiminiwindow' + --dofile 'widgets/uiminiwindowcontainer' + dofile 'widgets/uimessagebox' + + diff --git a/modules/core_lib/dispatcher.lua b/modules/core_lib/dispatcher.lua deleted file mode 100644 index e1997a63..00000000 --- a/modules/core_lib/dispatcher.lua +++ /dev/null @@ -1,20 +0,0 @@ -function scheduleEvent(callback, delay) - local event = g_dispatcher.scheduleEvent(callback, delay) - - -- must hold a reference to the callback, otherwise it would be collected - event._callback = callback - return event -end - -function addEvent(callback, front) - local event = g_dispatcher.addEvent(callback, front) - -- must hold a reference to the callback, otherwise it would be collected - event._callback = callback - return event -end - -function removeEvent(event) - if event then - event:cancel() - end -end diff --git a/modules/core_lib/globals.lua b/modules/core_lib/globals.lua index 5ef31a99..43da9fc6 100644 --- a/modules/core_lib/globals.lua +++ b/modules/core_lib/globals.lua @@ -1,57 +1,13 @@ rootWidget = g_ui.getRootWidget() -function importStyle(otui) - g_ui.importStyle(resolvepath(otui, 2)) -end - -function importFont(otfont) - g_fonts.importFont(resolvepath(otfont, 2)) -end +importStyle = g_ui.importStyle +importFont = g_fonts.importFont +setDefaultFont = g_fonts.setDefaultFont -function setDefaultFont(font) - g_fonts.setDefaultFont(font) -end +loadUI = g_ui.loadUI -function displayUI(arg1, options) - local widget - local parent - if options then parent = options.parent end +function displayUI(otui, parent) parent = parent or rootWidget - - -- display otui files - if type(arg1) == 'string' then - local otuiFilePath = resolvepath(arg1, 2) - widget = g_ui.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) - elseif option == 'x' then - widget:setX(value) - elseif option == 'y' then - widget:setY(value) - end - end - end - return widget -end - -function loadUI(otui, parent) local otuiFilePath = resolvepath(otui, 2) return g_ui.loadUI(otuiFilePath, parent) end @@ -65,7 +21,7 @@ function createWidget(style, parent) local class = _G[className] if not class then - error('could not find widget class ' .. class) + error('could not find widget class ' .. className) return end @@ -80,6 +36,28 @@ function createWidget(style, parent) return widget end +function scheduleEvent(callback, delay) + local event = g_dispatcher.scheduleEvent(callback, delay) + + -- must hold a reference to the callback, otherwise it would be collected + event._callback = callback + return event +end + +function addEvent(callback, front) + local event = g_dispatcher.addEvent(callback, front) + -- must hold a reference to the callback, otherwise it would be collected + event._callback = callback + return event +end + +function removeEvent(event) + if event then + event:cancel() + event._callback = nil + end +end + function reloadModule(name) local module = g_modules.getModule(name) if module then diff --git a/modules/core_lib/mouse.lua b/modules/core_lib/mouse.lua index 952ec6de..57a3123d 100644 --- a/modules/core_lib/mouse.lua +++ b/modules/core_lib/mouse.lua @@ -7,3 +7,4 @@ end function Mouse.restoreCursor() g_window.restoreMouseCursor() end + diff --git a/modules/core_lib/settings.lua b/modules/core_lib/settings.lua index 60e76c82..b7a92aee 100644 --- a/modules/core_lib/settings.lua +++ b/modules/core_lib/settings.lua @@ -32,7 +32,6 @@ function Settings.set(key, value) g_configs.set(key, convertSettingValue(value)) end - function Settings.setDefault(key, value) if Settings.exists(key) then return false end Settings.set(key, value) diff --git a/modules/core_lib/effects.lua b/modules/core_lib/ui/effects.lua similarity index 100% rename from modules/core_lib/effects.lua rename to modules/core_lib/ui/effects.lua diff --git a/modules/core_widgets/radiogroup.lua b/modules/core_lib/ui/radiogroup.lua similarity index 100% rename from modules/core_widgets/radiogroup.lua rename to modules/core_lib/ui/radiogroup.lua diff --git a/modules/core_widgets/tooltip.lua b/modules/core_lib/ui/tooltip.lua similarity index 85% rename from modules/core_widgets/tooltip.lua rename to modules/core_lib/ui/tooltip.lua index dec3a1e2..525d41fc 100644 --- a/modules/core_widgets/tooltip.lua +++ b/modules/core_lib/ui/tooltip.lua @@ -41,13 +41,15 @@ end -- public functions function ToolTip.init() - toolTipLabel = createWidget('Label', rootWidget) - toolTipLabel:setId('toolTip') - toolTipLabel:setBackgroundColor('#111111bb') - toolTipLabel.onMouseMove = moveToolTip - connect(UIWidget, { onStyleApply = onWidgetStyleApply, onHoverChange = onWidgetHoverChange}) + + addEvent(function() + toolTipLabel = createWidget('Label', rootWidget) + toolTipLabel:setId('toolTip') + toolTipLabel:setBackgroundColor('#111111bb') + toolTipLabel.onMouseMove = moveToolTip + end) end function ToolTip.terminate() @@ -63,6 +65,8 @@ end function ToolTip.display(text) if text == nil then return end + if not toolTipLabel then return end + toolTipLabel:setText(text) toolTipLabel:resizeToText() toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4) @@ -73,6 +77,7 @@ function ToolTip.display(text) end function ToolTip.hide() + toolTipLabel:hide() end @@ -85,3 +90,5 @@ function UIWidget:getTooltip() return self.tooltip end +ToolTip.init() +connect(g_app, { onTerminate = ToolTip.terminate }) diff --git a/modules/core_lib/util.lua b/modules/core_lib/util.lua index 4d3fef0c..386f6b6c 100644 --- a/modules/core_lib/util.lua +++ b/modules/core_lib/util.lua @@ -3,20 +3,15 @@ function print(...) for i,v in ipairs(arg) do msg = msg .. tostring(v) .. "\t" end - Logger.log(LogInfo, msg) + g_logger.log(LogInfo, msg) end function fatal(msg) - Logger.log(LogFatal, msg) + g_logger.log(LogFatal, msg) end -function setonclose(func) - g_app.onClose = func -end - -function exit() - g_app.exit() -end +exit = g_app.exit +quit = g_app.exit function connect(object, signalsAndSlots, pushFront) for signal,slot in pairs(signalsAndSlots) do diff --git a/modules/core_widgets/uibutton.lua b/modules/core_lib/widgets/uibutton.lua similarity index 100% rename from modules/core_widgets/uibutton.lua rename to modules/core_lib/widgets/uibutton.lua diff --git a/modules/core_widgets/uicheckbox.lua b/modules/core_lib/widgets/uicheckbox.lua similarity index 100% rename from modules/core_widgets/uicheckbox.lua rename to modules/core_lib/widgets/uicheckbox.lua diff --git a/modules/core_widgets/uicombobox.lua b/modules/core_lib/widgets/uicombobox.lua similarity index 100% rename from modules/core_widgets/uicombobox.lua rename to modules/core_lib/widgets/uicombobox.lua diff --git a/modules/core_widgets/uilabel.lua b/modules/core_lib/widgets/uilabel.lua similarity index 100% rename from modules/core_widgets/uilabel.lua rename to modules/core_lib/widgets/uilabel.lua diff --git a/modules/core_widgets/uimessagebox.lua b/modules/core_lib/widgets/uimessagebox.lua similarity index 100% rename from modules/core_widgets/uimessagebox.lua rename to modules/core_lib/widgets/uimessagebox.lua diff --git a/modules/core_widgets/uipopupmenu.lua b/modules/core_lib/widgets/uipopupmenu.lua similarity index 97% rename from modules/core_widgets/uipopupmenu.lua rename to modules/core_lib/widgets/uipopupmenu.lua index e149eb70..ab899cad 100644 --- a/modules/core_widgets/uipopupmenu.lua +++ b/modules/core_lib/widgets/uipopupmenu.lua @@ -21,7 +21,8 @@ function UIPopupMenu:display(pos) currentMenu:destroy() end - displayUI(self, {x = pos.x, y = pos.y}) + rootWidget:addChild(self) + self:setPosition(pos) self:grabMouse() self:grabKeyboard() currentMenu = self diff --git a/modules/core_widgets/uiprogressbar.lua b/modules/core_lib/widgets/uiprogressbar.lua similarity index 100% rename from modules/core_widgets/uiprogressbar.lua rename to modules/core_lib/widgets/uiprogressbar.lua diff --git a/modules/core_widgets/uispinbox.lua b/modules/core_lib/widgets/uispinbox.lua similarity index 100% rename from modules/core_widgets/uispinbox.lua rename to modules/core_lib/widgets/uispinbox.lua diff --git a/modules/core_widgets/uitabbar.lua b/modules/core_lib/widgets/uitabbar.lua similarity index 100% rename from modules/core_widgets/uitabbar.lua rename to modules/core_lib/widgets/uitabbar.lua diff --git a/modules/core_widgets/uiwidget.lua b/modules/core_lib/widgets/uiwidget.lua similarity index 100% rename from modules/core_widgets/uiwidget.lua rename to modules/core_lib/widgets/uiwidget.lua diff --git a/modules/core_widgets/uiwindow.lua b/modules/core_lib/widgets/uiwindow.lua similarity index 86% rename from modules/core_widgets/uiwindow.lua rename to modules/core_lib/widgets/uiwindow.lua index 69c8ffe5..d7b768d6 100644 --- a/modules/core_widgets/uiwindow.lua +++ b/modules/core_lib/widgets/uiwindow.lua @@ -7,7 +7,7 @@ function UIWindow.create() return window end -function UIWindow:onKeyPress(keyCode, keyboardModifiers) +function UIWindow:onKeyDown(keyCode, keyboardModifiers) if keyboardModifiers == KeyboardNoModifier then if keyCode == KeyEnter then signalcall(self.onEnter, self) @@ -17,9 +17,8 @@ function UIWindow:onKeyPress(keyCode, keyboardModifiers) end end -function UIWindow:onMousePress(mousePos, mouseButton) - self:raise() - return true +function UIWindow:onFocusChange(focused) + if focused then self:raise() end end function UIWindow:onDragEnter(mousePos) diff --git a/modules/core_styles/core_styles.otmod b/modules/core_styles/core_styles.otmod index dad82a32..63c16445 100644 --- a/modules/core_styles/core_styles.otmod +++ b/modules/core_styles/core_styles.otmod @@ -3,11 +3,16 @@ Module description: Contains ui styles used by other modules author: OTClient team website: https://github.com/edubart/otclient - reloadable: true autoload: true - autoload-antecedence: 20 + autoload-priority: 20 + + @onLoad: | + importFont 'fonts/verdana-11px-antialised' + importFont 'fonts/verdana-11px-monochrome' + importFont 'fonts/verdana-11px-rounded' + importFont 'fonts/terminus-14px-bold' + setDefaultFont 'verdana-11px-antialised' - onLoad: | importStyle 'styles/buttons.otui' importStyle 'styles/labels.otui' importStyle 'styles/panels.otui' diff --git a/modules/core_styles/icons/targetcursor.png b/modules/core_styles/cursors/targetcursor.png similarity index 100% rename from modules/core_styles/icons/targetcursor.png rename to modules/core_styles/cursors/targetcursor.png diff --git a/modules/core_fonts/terminus-14px-bold.otfont b/modules/core_styles/fonts/terminus-14px-bold.otfont similarity index 100% rename from modules/core_fonts/terminus-14px-bold.otfont rename to modules/core_styles/fonts/terminus-14px-bold.otfont diff --git a/modules/core_fonts/terminus-14px-bold.png b/modules/core_styles/fonts/terminus-14px-bold.png similarity index 100% rename from modules/core_fonts/terminus-14px-bold.png rename to modules/core_styles/fonts/terminus-14px-bold.png diff --git a/modules/core_fonts/verdana-11px-antialised.otfont b/modules/core_styles/fonts/verdana-11px-antialised.otfont similarity index 100% rename from modules/core_fonts/verdana-11px-antialised.otfont rename to modules/core_styles/fonts/verdana-11px-antialised.otfont diff --git a/modules/core_fonts/verdana-11px-antialised.png b/modules/core_styles/fonts/verdana-11px-antialised.png similarity index 100% rename from modules/core_fonts/verdana-11px-antialised.png rename to modules/core_styles/fonts/verdana-11px-antialised.png diff --git a/modules/core_fonts/verdana-11px-monochrome.otfont b/modules/core_styles/fonts/verdana-11px-monochrome.otfont similarity index 100% rename from modules/core_fonts/verdana-11px-monochrome.otfont rename to modules/core_styles/fonts/verdana-11px-monochrome.otfont diff --git a/modules/core_fonts/verdana-11px-monochrome.png b/modules/core_styles/fonts/verdana-11px-monochrome.png similarity index 100% rename from modules/core_fonts/verdana-11px-monochrome.png rename to modules/core_styles/fonts/verdana-11px-monochrome.png diff --git a/modules/core_fonts/verdana-11px-rounded.otfont b/modules/core_styles/fonts/verdana-11px-rounded.otfont similarity index 100% rename from modules/core_fonts/verdana-11px-rounded.otfont rename to modules/core_styles/fonts/verdana-11px-rounded.otfont diff --git a/modules/core_fonts/verdana-11px-rounded.png b/modules/core_styles/fonts/verdana-11px-rounded.png similarity index 100% rename from modules/core_fonts/verdana-11px-rounded.png rename to modules/core_styles/fonts/verdana-11px-rounded.png diff --git a/modules/core_styles/styles/buttons.otui b/modules/core_styles/styles/buttons.otui index c8ba47b6..55a0e8e6 100644 --- a/modules/core_styles/styles/buttons.otui +++ b/modules/core_styles/styles/buttons.otui @@ -4,15 +4,15 @@ Button < UIButton size: 106 24 text-offset: 0 0 image-color: white - image-source: /core_styles/images/button.png + image-source: /core_styles/styles/images/button.png image-border: 5 $hover !disabled: - image-source: /core_styles/images/button_hover.png + image-source: /core_styles/styles/images/button_hover.png $pressed: text-offset: 1 1 - image-source: /core_styles/images/button_down.png + image-source: /core_styles/styles/images/button_down.png $disabled: color: #f0ad4d88 @@ -20,7 +20,7 @@ Button < UIButton ConsoleButton < UIButton size: 20 20 - image-source: /core_styles/images/tabbutton.png + image-source: /core_styles/styles/images/tabbutton.png image-color: white image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/core_styles/styles/checkboxes.otui b/modules/core_styles/styles/checkboxes.otui index 0a13b06e..14896c18 100644 --- a/modules/core_styles/styles/checkboxes.otui +++ b/modules/core_styles/styles/checkboxes.otui @@ -6,7 +6,7 @@ CheckBox < UICheckBox image-color: #ffffffff image-rect: 0 0 12 12 image-offset: 0 2 - image-source: /core_styles/images/checkbox.png + image-source: /core_styles/styles/images/checkbox.png $hover !disabled: color: #cccccc @@ -30,7 +30,7 @@ CheckBox < UICheckBox ColorBox < UICheckBox size: 16 16 image-color: #ffffffff - image-source: /core_styles/images/colorbox.png + image-source: /core_styles/styles/images/colorbox.png $checked: image-clip: 16 0 16 16 @@ -44,16 +44,16 @@ ButtonBox < UICheckBox size: 106 24 text-offset: 0 0 text-align: center - image-source: /core_styles/images/button.png + image-source: /core_styles/styles/images/button.png image-color: white image-border: 5 $hover !disabled: - image-source: /core_styles/images/button_hover.png + image-source: /core_styles/styles/images/button_hover.png $checked: text-offset: 1 1 - image-source: /core_styles/images/button_down.png + image-source: /core_styles/styles/images/button_down.png $disabled: color: #f0ad4d88 diff --git a/modules/core_styles/styles/comboboxes.otui b/modules/core_styles/styles/comboboxes.otui index 57ffc3de..245ff3e1 100644 --- a/modules/core_styles/styles/comboboxes.otui +++ b/modules/core_styles/styles/comboboxes.otui @@ -14,14 +14,14 @@ ComboBoxPopupMenuButton < UIButton color: #555555 ComboBoxPopupMenuSeparator < UIWidget - image-source: /core_styles/images/combobox.png + image-source: /core_styles/styles/images/combobox.png image-repeated: true image-clip: 1 59 89 1 height: 1 phantom: true ComboBoxPopupMenu < UIPopupMenu - image-source: /core_styles/images/combobox.png + image-source: /core_styles/styles/images/combobox.png image-clip: 0 60 89 20 image-border: 1 image-border-top: 0 @@ -33,7 +33,7 @@ ComboBox < UIComboBox size: 86 20 text-offset: 3 0 text-align: left - image-source: /core_styles/images/combobox.png + image-source: /core_styles/styles/images/combobox.png image-border: 1 image-border-right: 17 image-clip: 0 0 89 20 diff --git a/modules/core_styles/styles/creatures.otui b/modules/core_styles/styles/creatures.otui index 62170298..73ca8cd3 100644 --- a/modules/core_styles/styles/creatures.otui +++ b/modules/core_styles/styles/creatures.otui @@ -1,8 +1,5 @@ Creature < UICreature size: 80 80 padding: 1 - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 - - UIWidget - id: lala diff --git a/modules/core_styles/images/button.png b/modules/core_styles/styles/images/button.png similarity index 100% rename from modules/core_styles/images/button.png rename to modules/core_styles/styles/images/button.png diff --git a/modules/core_styles/images/button_down.png b/modules/core_styles/styles/images/button_down.png similarity index 100% rename from modules/core_styles/images/button_down.png rename to modules/core_styles/styles/images/button_down.png diff --git a/modules/core_styles/images/button_hover.png b/modules/core_styles/styles/images/button_hover.png similarity index 100% rename from modules/core_styles/images/button_hover.png rename to modules/core_styles/styles/images/button_hover.png diff --git a/modules/core_styles/images/checkbox.png b/modules/core_styles/styles/images/checkbox.png similarity index 100% rename from modules/core_styles/images/checkbox.png rename to modules/core_styles/styles/images/checkbox.png diff --git a/modules/core_styles/images/colorbox.png b/modules/core_styles/styles/images/colorbox.png similarity index 100% rename from modules/core_styles/images/colorbox.png rename to modules/core_styles/styles/images/colorbox.png diff --git a/modules/core_styles/images/combobox.png b/modules/core_styles/styles/images/combobox.png similarity index 100% rename from modules/core_styles/images/combobox.png rename to modules/core_styles/styles/images/combobox.png diff --git a/modules/core_styles/images/container_bg.png b/modules/core_styles/styles/images/container_bg.png similarity index 100% rename from modules/core_styles/images/container_bg.png rename to modules/core_styles/styles/images/container_bg.png diff --git a/modules/core_styles/images/horizontal_separator.png b/modules/core_styles/styles/images/horizontal_separator.png similarity index 100% rename from modules/core_styles/images/horizontal_separator.png rename to modules/core_styles/styles/images/horizontal_separator.png diff --git a/modules/core_styles/images/horizotal_separator.png b/modules/core_styles/styles/images/horizotal_separator.png similarity index 100% rename from modules/core_styles/images/horizotal_separator.png rename to modules/core_styles/styles/images/horizotal_separator.png diff --git a/modules/core_styles/images/item.png b/modules/core_styles/styles/images/item.png similarity index 100% rename from modules/core_styles/images/item.png rename to modules/core_styles/styles/images/item.png diff --git a/modules/core_styles/images/menu.png b/modules/core_styles/styles/images/menu.png similarity index 100% rename from modules/core_styles/images/menu.png rename to modules/core_styles/styles/images/menu.png diff --git a/modules/core_styles/images/menubox.png b/modules/core_styles/styles/images/menubox.png similarity index 100% rename from modules/core_styles/images/menubox.png rename to modules/core_styles/styles/images/menubox.png diff --git a/modules/core_styles/images/panel_flat.png b/modules/core_styles/styles/images/panel_flat.png similarity index 100% rename from modules/core_styles/images/panel_flat.png rename to modules/core_styles/styles/images/panel_flat.png diff --git a/modules/core_styles/images/progressbar.png b/modules/core_styles/styles/images/progressbar.png similarity index 100% rename from modules/core_styles/images/progressbar.png rename to modules/core_styles/styles/images/progressbar.png diff --git a/modules/core_styles/images/tabbutton.png b/modules/core_styles/styles/images/tabbutton.png similarity index 100% rename from modules/core_styles/images/tabbutton.png rename to modules/core_styles/styles/images/tabbutton.png diff --git a/modules/core_styles/images/window.png b/modules/core_styles/styles/images/window.png similarity index 100% rename from modules/core_styles/images/window.png rename to modules/core_styles/styles/images/window.png diff --git a/modules/core_styles/styles/items.otui b/modules/core_styles/styles/items.otui index 1422a9d3..9cd088bc 100644 --- a/modules/core_styles/styles/items.otui +++ b/modules/core_styles/styles/items.otui @@ -1,5 +1,5 @@ Item < UIItem size: 34 34 - image-source: /core_styles/images/item.png + image-source: /core_styles/styles/images/item.png font: verdana-11px-rounded border-color: white diff --git a/modules/core_styles/styles/labels.otui b/modules/core_styles/styles/labels.otui index decc03b1..7046c6b5 100644 --- a/modules/core_styles/styles/labels.otui +++ b/modules/core_styles/styles/labels.otui @@ -5,8 +5,6 @@ Label < UILabel $disabled: color: #aaaaaa88 -LargerLabel < Label - GameLabel < UILabel font: verdana-11px-antialised color: #aaaaaa diff --git a/modules/core_styles/styles/lineedits.otui b/modules/core_styles/styles/lineedits.otui index 18b25b72..aae4257b 100644 --- a/modules/core_styles/styles/lineedits.otui +++ b/modules/core_styles/styles/lineedits.otui @@ -3,7 +3,7 @@ LineEdit < UILineEdit color: #aaaaaa size: 86 20 text-margin: 3 - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 $disabled: diff --git a/modules/core_styles/styles/listboxes.otui b/modules/core_styles/styles/listboxes.otui index 92e2dc9f..5038d3cd 100644 --- a/modules/core_styles/styles/listboxes.otui +++ b/modules/core_styles/styles/listboxes.otui @@ -2,4 +2,4 @@ TextList < UIWidget layout: verticalBox border-width: 1 border-color: #1d222b - background-color: #222833 \ No newline at end of file + background-color: #222833 diff --git a/modules/core_styles/styles/panels.otui b/modules/core_styles/styles/panels.otui index dad6e0ec..883cea27 100644 --- a/modules/core_styles/styles/panels.otui +++ b/modules/core_styles/styles/panels.otui @@ -2,23 +2,5 @@ Panel < UIWidget phantom: true FlatPanel < Panel - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 - -TopPanel < Panel - height: 36 - image-source: /core_styles/images/top_panel.png - image-repeated: true - -InterfacePanel < UIMiniWindowContainer - image-source: /core_styles/images/interface_panel.png - image-border: 4 - -InterfacePanel2 < Panel - image-source: /core_styles/images/interface_panel2.png - image-border: 4 - -Map < UIMap - padding: 4 - image-source: /core_styles/images/map_panel.png - image-border: 4 diff --git a/modules/core_styles/styles/popupmenus.otui b/modules/core_styles/styles/popupmenus.otui index d0199a8e..cacf56c3 100644 --- a/modules/core_styles/styles/popupmenus.otui +++ b/modules/core_styles/styles/popupmenus.otui @@ -17,7 +17,7 @@ PopupMenuButton < UIButton PopupMenuSeparator < UIWidget margin-left: 2 margin-right: 2 - image-source: /core_styles/images/menubox.png + image-source: /core_styles/styles/images/menubox.png image-border-left: 1 image-border-right: 1 image-clip: 0 0 32 2 @@ -26,7 +26,7 @@ PopupMenuSeparator < UIWidget PopupMenu < UIPopupMenu width: 50 - image-source: /core_styles/images/menubox.png + image-source: /core_styles/styles/images/menubox.png image-border: 3 padding-top: 3 padding-bottom: 3 diff --git a/modules/core_styles/styles/progressbars.otui b/modules/core_styles/styles/progressbars.otui index b0e1b38d..57ce896d 100644 --- a/modules/core_styles/styles/progressbars.otui +++ b/modules/core_styles/styles/progressbars.otui @@ -2,6 +2,6 @@ ProgressBar < UIProgressBar height: 16 background-color: red border: 1 black - image: /core_styles/images/progressbar.png + image: /core_styles/styles/images/progressbar.png image-border: 1 diff --git a/modules/core_styles/styles/separators.otui b/modules/core_styles/styles/separators.otui index 9c26b8d6..59d23a4a 100644 --- a/modules/core_styles/styles/separators.otui +++ b/modules/core_styles/styles/separators.otui @@ -1,5 +1,5 @@ HorizontalSeparator < UIWidget - image-source: /core_styles/images/horizontal_separator.png + image-source: /core_styles/styles/images/horizontal_separator.png image-border-top: 2 height: 2 phantom: true diff --git a/modules/core_styles/styles/spinboxes.otui b/modules/core_styles/styles/spinboxes.otui index f9cd80ca..1bcc18a4 100644 --- a/modules/core_styles/styles/spinboxes.otui +++ b/modules/core_styles/styles/spinboxes.otui @@ -3,7 +3,7 @@ SpinBox < UISpinBox color: #aaaaaa size: 86 20 text-margin: 3 - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 $disabled: diff --git a/modules/core_styles/styles/tabbars.otui b/modules/core_styles/styles/tabbars.otui index 3876dd16..4d5b6b31 100644 --- a/modules/core_styles/styles/tabbars.otui +++ b/modules/core_styles/styles/tabbars.otui @@ -2,7 +2,7 @@ TabBar < UITabBar TabBarPanel < Panel TabBarButton < UIButton size: 20 20 - image-source: /core_styles/images/tabbutton.png + image-source: /core_styles/styles/images/tabbutton.png image-color: white image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/core_styles/styles/windows.otui b/modules/core_styles/styles/windows.otui index dc05d0ac..14d10555 100644 --- a/modules/core_styles/styles/windows.otui +++ b/modules/core_styles/styles/windows.otui @@ -5,7 +5,7 @@ Window < UIWindow color: white text-offset: 0 2 text-align: top - image-source: /core_styles/images/window.png + image-source: /core_styles/styles/images/window.png image-border: 4 image-border-top: 20 opacity: 1 @@ -35,7 +35,7 @@ MiniWindow < UIMiniWindow margin-left: 6 margin-right: 6 move-policy: free updated - image-source: /core_styles/images/mini_window.png + image-source: /core_styles/styles/images/mini_window.png image-border: 4 image-border-top: 23 padding: 25 8 2 8 diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod deleted file mode 100644 index 0145bb15..00000000 --- a/modules/core_widgets/core_widgets.otmod +++ /dev/null @@ -1,33 +0,0 @@ -Module - name: core_widgets - description: Contains widgets used by other modules - author: OTClient team - website: https://github.com/edubart/otclient - reloadable: true - unloadble: false - autoload: true - autoload-antecedence: 40 - - onLoad: | - dofile 'uiwidget' - dofile 'uibutton' - dofile 'uilabel' - dofile 'uicheckbox' - dofile 'uicombobox' - dofile 'uispinbox' - dofile 'uiprogressbar' - dofile 'uitabbar' - dofile 'uipopupmenu' - dofile 'uiwindow' - dofile 'uiminiwindow' - dofile 'uiminiwindowcontainer' - dofile 'uiitem' - dofile 'uimessagebox' - - dofile 'tooltip' - dofile 'radiogroup' - - ToolTip.init() - - onUnload: | - ToolTip.terminate() diff --git a/modules/game/game.lua b/modules/game/game.lua index df89e434..0cd3266a 100644 --- a/modules/game/game.lua +++ b/modules/game/game.lua @@ -46,19 +46,6 @@ function g_game.startUseWith(thing) end function g_game.createInterface() - Background.hide() - CharacterList.destroyLoadBox() - g_game.gameUi = displayUI('game.otui') - - --Keyboard.bindKeyPress('Up', function() g_game.walk(North) end) - --Keyboard.bindKeyPress('Down', function() g_game.walk(South) end) - --Keyboard.bindKeyPress('Left', function() g_game.walk(West) end) - --Keyboard.bindKeyPress('Right', function() g_game.walk(East) end) - - Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end) - Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end) - Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end) - Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end) rootWidget:moveChildToIndex(g_game.gameUi, 1) g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel') @@ -89,17 +76,6 @@ function g_game.hide() end -- hooked events -function g_game.onLoginError(message) - CharacterList.destroyLoadBox() - local errorBox = displayErrorBox("Login Error", "Login error: " .. message) - connect(errorBox, { onOk = CharacterList.show }) -end - -function g_game.onConnectionError(message) - CharacterList.destroyLoadBox() - local errorBox = displayErrorBox("Login Error", "Connection error: " .. message) - connect(errorBox, { onOk = CharacterList.show }) -end local function onApplicationClose() if g_game.isOnline() then diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 54d25fa0..5dcf5858 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -3,19 +3,11 @@ Module description: Create the game interface, where the ingame stuff starts author: OTClient team website: https://github.com/edubart/otclient + reloadable: true dependencies: - - game_healthbar - - game_inventory - - game_skills - - game_textmessage - - game_viplist - - game_console - - game_outfit - - game_containers - - game_combatcontrols - - game_hotkeys - - game_battle + - game_tibiafiles + //- game_shaders onLoad: | dofile 'game' diff --git a/modules/game_tibiafiles/tibiafiles.otmod b/modules/game_tibiafiles/tibiafiles.otmod new file mode 100644 index 00000000..1af149ad --- /dev/null +++ b/modules/game_tibiafiles/tibiafiles.otmod @@ -0,0 +1,11 @@ +Module + name: game_tibiafiles + description: Contains tibia spr and dat + + @onLoad: | + if not g_thingsType.load('/game_tibiafiles/Tibia.dat') then + fatal("Unable to load dat file, please place a valid Tibia dat in modules/game_tibiafiles/Tibia.dat") + end + if not g_sprites.load('/game_tibiafiles/Tibia.spr') then + fatal("Unable to load spr file, please place a valid Tibia spr in modules/game_tibiafiles/Tibia.spr") + end diff --git a/modules/game_battle/battle.lua b/modules/old/game_battle/battle.lua similarity index 91% rename from modules/game_battle/battle.lua rename to modules/old/game_battle/battle.lua index eaeebacb..b5576132 100644 --- a/modules/game_battle/battle.lua +++ b/modules/old/game_battle/battle.lua @@ -36,29 +36,29 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } ) -- public functions function Battle.create() - battleWindow = displayUI('battle.otui', { parent = g_game.gameRightPanel }) + battleWindow = displayUI('battle.otui', g_game.gameRightPanel) battleWindow:hide() battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle) Keyboard.bindKeyDown('Ctrl+B', Battle.toggle) - + battlePannel = battleWindow:getChildById('battlePanel') - + hidePlayersButton = battleWindow:getChildById('hidePlayers') hideNPCsButton = battleWindow:getChildById('hideNPCs') hideMonstersButton = battleWindow:getChildById('hideMonsters') hideSkullsButton = battleWindow:getChildById('hideSkulls') hidePartyButton = battleWindow:getChildById('hideParty') - + mouseWidget = createWidget('UIButton') mouseWidget:setVisible(false) - mouseWidget:setFocusable(false) - + mouseWidget:setFocusable(false) + connect(Creature, { onSkullChange = Battle.checkCreatureSkull, - onEmblemChange = Battle.checkCreatureEmblem } ) - + onEmblemChange = Battle.checkCreatureEmblem } ) + connect(g_game, { onAttackingCreatureChange = Battle.onAttack, onFollowingCreatureChange = Battle.onFollow } ) - + addEvent(Battle.addAllCreatures) checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200) end @@ -80,10 +80,10 @@ function Battle.destroy() battleButton = nil battleWindow:destroy() battleWindow = nil - + disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull, - onEmblemChange = Battle.checkCreatureEmblem } ) - + onEmblemChange = Battle.checkCreatureEmblem } ) + disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } ) end @@ -94,7 +94,7 @@ function Battle.toggle() end function Battle.addAllCreatures() - local spectators = {} + local spectators = {} local player = g_game.getLocalPlayer() if player then creatures = g_map.getSpectators(player:getPosition(), false) @@ -104,7 +104,7 @@ function Battle.addAllCreatures() end end end - + for i, v in pairs(spectators) do Battle.addCreature(v) end @@ -116,7 +116,7 @@ function Battle.doCreatureFitFilters(creature) local hideMonsters = hideMonstersButton:isChecked() local hideSkulls = hideSkullsButton:isChecked() local hideParty = hidePartyButton:isChecked() - + if hidePlayers and not creature:asMonster() and not creature:asNpc() then return false elseif hideNPCs and creature:asNpc() then @@ -128,35 +128,35 @@ function Battle.doCreatureFitFilters(creature) elseif hideParty and creature:getShield() > ShieldWhiteBlue then return false end - + return true end function Battle.checkCreatures() local player = g_game.getLocalPlayer() - if player then + if player then local spectators = {} -- reloading list of spectators - local creaturesAppeared = {} + local creaturesAppeared = {} creatures = g_map.getSpectators(player:getPosition(), false) for i, creature in ipairs(creatures) do if creature ~= player and Battle.doCreatureFitFilters(creature) then -- searching for creatures that appeared on battle list local battleButton = battleButtonsByCreaturesList[creature:getId()] if battleButton == nil then - table.insert(creaturesAppeared, creature) + table.insert(creaturesAppeared, creature) else Battle.setLifeBarPercent(battleButton, creature:getHealthPercent()) end spectators[creature:getId()] = creature end end - + for i, v in pairs(creaturesAppeared) do Battle.addCreature(v) end - + -- searching for creatures that disappeared from battle list local creaturesDisappeared = {} for i, creature in pairs(battleButtonsByCreaturesList) do @@ -164,7 +164,7 @@ function Battle.checkCreatures() table.insert(creaturesDisappeared, creature.creature) end end - + for i, v in pairs(creaturesDisappeared) do Battle.removeCreature(v) end @@ -174,28 +174,28 @@ end function Battle.addCreature(creature) local creatureId = creature:getId() - + if battleButtonsByCreaturesList[creatureId] == nil then - local battleButton = displayUI('battleButton.otui', { parent = battlePannel }) + local battleButton = displayUI('battleButton.otui', battlePanne) local creatureWidget = battleButton:getChildById('creature') local labelWidget = battleButton:getChildById('label') local lifeBarWidget = battleButton:getChildById('lifeBar') - + battleButton:setId('BattleButton_' .. creature:getName():gsub('%s','_')) battleButton.creatureId = creatureId battleButton.creature = creature battleButton.isHovered = false battleButton.isTarget = false battleButton.isFollowed = false - + labelWidget:setText(creature:getName()) - creatureWidget:setCreature(creature) + creatureWidget:setCreature(creature) Battle.setLifeBarPercent(battleButton, creature:getHealthPercent()) battleButtonsByCreaturesList[creatureId] = battleButton - + Battle.checkCreatureSkull(battleButton.creature) - Battle.checkCreatureEmblem(battleButton.creature) + Battle.checkCreatureEmblem(battleButton.creature) end end @@ -205,7 +205,7 @@ function Battle.checkCreatureSkull(creature, skullId) local skullWidget = battleButton:getChildById('skull') local labelWidget = battleButton:getChildById('label') local creature = battleButton.creature - + if creature:getSkull() ~= SkullNone then skullWidget:setWidth(skullWidget:getHeight()) local imagePath = getSkullImagePath(creature:getSkull()) @@ -265,12 +265,12 @@ end function Battle.removeCreature(creature) local creatureId = creature:getId() - + if battleButtonsByCreaturesList[creatureId] ~= nil then if lastBattleButtonSwitched == battleButtonsByCreaturesList[creatureId] then lastBattleButtonSwitched = nil end - + battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare() battleButtonsByCreaturesList[creatureId]:destroy() battleButtonsByCreaturesList[creatureId] = nil @@ -280,7 +280,7 @@ end function Battle.setLifeBarPercent(battleButton, percent) local lifeBarWidget = battleButton:getChildById('lifeBar') lifeBarWidget:setPercent(percent) - + local color for i, v in pairs(lifeBarColors) do if percent > v.percentAbove then @@ -288,31 +288,31 @@ function Battle.setLifeBarPercent(battleButton, percent) break end end - + lifeBarWidget:setBackgroundColor(color) end function Battle.onbattlePannelHoverChange(widget, hovered) - if widget.isBattleButton then + if widget.isBattleButton then widget.isHovered = hovered Battle.checkBattleButton(widget) end end -function Battle.onAttack(creature) - local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched +function Battle.onAttack(creature) + local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched if battleButton then battleButton.isTarget = creature and true or false Battle.checkBattleButton(battleButton) end end -function Battle.onFollow(creature) - local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched +function Battle.onFollow(creature) + local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched if battleButton then battleButton.isFollowed = creature and true or false Battle.checkBattleButton(battleButton) - end + end end function Battle.checkBattleButton(battleButton) @@ -322,20 +322,20 @@ function Battle.checkBattleButton(battleButton) elseif battleButton.isFollowed then color = battleButtonColors.onFollowed end - + color = battleButton.isHovered and color.hovered or color.notHovered - + if battleButton.isHovered or battleButton.isTarget or battleButton.isFollowed then battleButton.creature:showStaticSquare(color) battleButton:getChildById('creature'):setBorderWidth(1) battleButton:getChildById('creature'):setBorderColor(color) - battleButton:getChildById('label'):setColor(color) - else + battleButton:getChildById('label'):setColor(color) + else battleButton.creature:hideStaticSquare() battleButton:getChildById('creature'):setBorderWidth(0) - battleButton:getChildById('label'):setColor(color) + battleButton:getChildById('label'):setColor(color) end - + if battleButton.isTarget or battleButton.isFollowed then if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then lastBattleButtonSwitched.isTarget = false diff --git a/modules/game_battle/battle.otmod b/modules/old/game_battle/battle.otmod similarity index 100% rename from modules/game_battle/battle.otmod rename to modules/old/game_battle/battle.otmod diff --git a/modules/game_battle/battle.otui b/modules/old/game_battle/battle.otui similarity index 100% rename from modules/game_battle/battle.otui rename to modules/old/game_battle/battle.otui diff --git a/modules/game_battle/battle.png b/modules/old/game_battle/battle.png similarity index 100% rename from modules/game_battle/battle.png rename to modules/old/game_battle/battle.png diff --git a/modules/game_battle/battleButton.otui b/modules/old/game_battle/battleButton.otui similarity index 91% rename from modules/game_battle/battleButton.otui rename to modules/old/game_battle/battleButton.otui index 5e55f7bb..bfee2035 100644 --- a/modules/game_battle/battleButton.otui +++ b/modules/old/game_battle/battleButton.otui @@ -1,5 +1,5 @@ -BattleButton < UIButton - +BattleButton < UIButton + BattleButton height: 20 margin-top: 5 @@ -7,43 +7,43 @@ BattleButton &onHoverChange: Battle.onbattlePannelHoverChange &onMouseRelease: Battle.onMouseRelease &isBattleButton: true - + UICreature id: creature size: 20 20 anchors.left: parent.left anchors.top: parent.top phantom: true - + UIWidget id: spacer width: 5 anchors.left: creature.right anchors.top: creature.top phantom: true - + UIWidget id: skull height: 11 anchors.left: spacer.right anchors.top: spacer.top phantom: true - + UIWidget id: emblem height: 11 anchors.left: skull.right anchors.top: creature.top phantom: true - - LargerLabel + + Label id: label anchors.left: emblem.right anchors.top: creature.top color: #888888 margin-left: 2 phantom: true - + ProgressBar id: lifeBar height: 5 diff --git a/modules/game_battle/battle_monsters.png b/modules/old/game_battle/battle_monsters.png similarity index 100% rename from modules/game_battle/battle_monsters.png rename to modules/old/game_battle/battle_monsters.png diff --git a/modules/game_battle/battle_npcs.png b/modules/old/game_battle/battle_npcs.png similarity index 100% rename from modules/game_battle/battle_npcs.png rename to modules/old/game_battle/battle_npcs.png diff --git a/modules/game_battle/battle_party.png b/modules/old/game_battle/battle_party.png similarity index 100% rename from modules/game_battle/battle_party.png rename to modules/old/game_battle/battle_party.png diff --git a/modules/game_battle/battle_players.png b/modules/old/game_battle/battle_players.png similarity index 100% rename from modules/game_battle/battle_players.png rename to modules/old/game_battle/battle_players.png diff --git a/modules/game_battle/battle_skulls.png b/modules/old/game_battle/battle_skulls.png similarity index 100% rename from modules/game_battle/battle_skulls.png rename to modules/old/game_battle/battle_skulls.png diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/old/game_combatcontrols/combatcontrols.lua similarity index 100% rename from modules/game_combatcontrols/combatcontrols.lua rename to modules/old/game_combatcontrols/combatcontrols.lua diff --git a/modules/game_combatcontrols/combatcontrols.otmod b/modules/old/game_combatcontrols/combatcontrols.otmod similarity index 100% rename from modules/game_combatcontrols/combatcontrols.otmod rename to modules/old/game_combatcontrols/combatcontrols.otmod diff --git a/modules/game_combatcontrols/combatcontrols.otui b/modules/old/game_combatcontrols/combatcontrols.otui similarity index 100% rename from modules/game_combatcontrols/combatcontrols.otui rename to modules/old/game_combatcontrols/combatcontrols.otui diff --git a/modules/game_combatcontrols/combatcontrols.png b/modules/old/game_combatcontrols/combatcontrols.png similarity index 100% rename from modules/game_combatcontrols/combatcontrols.png rename to modules/old/game_combatcontrols/combatcontrols.png diff --git a/modules/game_combatcontrols/icons/chasemode.png b/modules/old/game_combatcontrols/icons/chasemode.png similarity index 100% rename from modules/game_combatcontrols/icons/chasemode.png rename to modules/old/game_combatcontrols/icons/chasemode.png diff --git a/modules/game_combatcontrols/icons/fightbalanced.png b/modules/old/game_combatcontrols/icons/fightbalanced.png similarity index 100% rename from modules/game_combatcontrols/icons/fightbalanced.png rename to modules/old/game_combatcontrols/icons/fightbalanced.png diff --git a/modules/game_combatcontrols/icons/fightdefensive.png b/modules/old/game_combatcontrols/icons/fightdefensive.png similarity index 100% rename from modules/game_combatcontrols/icons/fightdefensive.png rename to modules/old/game_combatcontrols/icons/fightdefensive.png diff --git a/modules/game_combatcontrols/icons/fightoffensive.png b/modules/old/game_combatcontrols/icons/fightoffensive.png similarity index 100% rename from modules/game_combatcontrols/icons/fightoffensive.png rename to modules/old/game_combatcontrols/icons/fightoffensive.png diff --git a/modules/game_combatcontrols/icons/safefight.png b/modules/old/game_combatcontrols/icons/safefight.png similarity index 100% rename from modules/game_combatcontrols/icons/safefight.png rename to modules/old/game_combatcontrols/icons/safefight.png diff --git a/modules/game_console/channelswindow.otui b/modules/old/game_console/channelswindow.otui similarity index 95% rename from modules/game_console/channelswindow.otui rename to modules/old/game_console/channelswindow.otui index f0c5bac8..daeebade 100644 --- a/modules/game_console/channelswindow.otui +++ b/modules/old/game_console/channelswindow.otui @@ -22,7 +22,7 @@ MainWindow padding: 1 focusable: false - LargerLabel + Label id: openPrivateChannelWithLabel text: Open a private message channel: anchors.left: parent.left diff --git a/modules/game_console/console.lua b/modules/old/game_console/console.lua similarity index 98% rename from modules/game_console/console.lua rename to modules/old/game_console/console.lua index 30e32da6..9a04eb19 100644 --- a/modules/game_console/console.lua +++ b/modules/old/game_console/console.lua @@ -78,7 +78,7 @@ end -- public functions function Console.create() - consolePanel = displayUI('console.otui', { parent = g_game.gameBottomPanel } ) + consolePanel = displayUI('console.otui', g_game.gameBottomPanel) consoleLineEdit = consolePanel:getChildById('consoleLineEdit') consoleBuffer = consolePanel:getChildById('consoleBuffer') consoleTabBar = consolePanel:getChildById('consoleTabBar') diff --git a/modules/game_console/console.otmod b/modules/old/game_console/console.otmod similarity index 100% rename from modules/game_console/console.otmod rename to modules/old/game_console/console.otmod diff --git a/modules/game_console/console.otui b/modules/old/game_console/console.otui similarity index 100% rename from modules/game_console/console.otui rename to modules/old/game_console/console.otui diff --git a/modules/game_containers/container.otui b/modules/old/game_containers/container.otui similarity index 100% rename from modules/game_containers/container.otui rename to modules/old/game_containers/container.otui diff --git a/modules/game_containers/containers.lua b/modules/old/game_containers/containers.lua similarity index 97% rename from modules/game_containers/containers.lua rename to modules/old/game_containers/containers.lua index e046b7e0..34dd4145 100644 --- a/modules/game_containers/containers.lua +++ b/modules/old/game_containers/containers.lua @@ -24,7 +24,7 @@ function Containers.onOpenContainer(containerId, itemId, name, capacity, hasPare g_game.gameRightPanel:removeChild(container) end - container = displayUI('container.otui', { parent = g_game.gameRightPanel }) + container = displayUI('container.otui', g_game.gameRightPanel) name = name:sub(1,1):upper() .. name:sub(2) container:setText(name) diff --git a/modules/game_containers/containers.otmod b/modules/old/game_containers/containers.otmod similarity index 100% rename from modules/game_containers/containers.otmod rename to modules/old/game_containers/containers.otmod diff --git a/modules/game_healthbar/healthbar.lua b/modules/old/game_healthbar/healthbar.lua similarity index 94% rename from modules/game_healthbar/healthbar.lua rename to modules/old/game_healthbar/healthbar.lua index 6af731e7..89fd7753 100644 --- a/modules/game_healthbar/healthbar.lua +++ b/modules/old/game_healthbar/healthbar.lua @@ -9,7 +9,7 @@ local manaLabel -- public functions function HealthBar.create() - healthBarWindow = displayUI('healthbar.otui', { parent = g_game.gameRightPanel }) + healthBarWindow = displayUI('healthbar.otui', g_game.gameRightPanel) 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/old/game_healthbar/healthbar.otmod similarity index 100% rename from modules/game_healthbar/healthbar.otmod rename to modules/old/game_healthbar/healthbar.otmod diff --git a/modules/game_healthbar/healthbar.otui b/modules/old/game_healthbar/healthbar.otui similarity index 100% rename from modules/game_healthbar/healthbar.otui rename to modules/old/game_healthbar/healthbar.otui diff --git a/modules/game_healthbar/healthbar.png b/modules/old/game_healthbar/healthbar.png similarity index 100% rename from modules/game_healthbar/healthbar.png rename to modules/old/game_healthbar/healthbar.png diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/old/game_hotkeys/hotkeys_manager.lua similarity index 99% rename from modules/game_hotkeys/hotkeys_manager.lua rename to modules/old/game_hotkeys/hotkeys_manager.lua index 906f26fb..2371096f 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/old/game_hotkeys/hotkeys_manager.lua @@ -131,6 +131,7 @@ function HotkeysManager.show() hotkeysWindow:grabKeyboard() hotkeysWindow:show() hotkeysWindow:lock() + hotkeysWindow:raise() end end diff --git a/modules/game_hotkeys/hotkeys_manager.otmod b/modules/old/game_hotkeys/hotkeys_manager.otmod similarity index 100% rename from modules/game_hotkeys/hotkeys_manager.otmod rename to modules/old/game_hotkeys/hotkeys_manager.otmod diff --git a/modules/game_hotkeys/hotkeys_manager.otui b/modules/old/game_hotkeys/hotkeys_manager.otui similarity index 95% rename from modules/game_hotkeys/hotkeys_manager.otui rename to modules/old/game_hotkeys/hotkeys_manager.otui index d2da58b0..7b3b6369 100644 --- a/modules/game_hotkeys/hotkeys_manager.otui +++ b/modules/old/game_hotkeys/hotkeys_manager.otui @@ -4,7 +4,7 @@ HotkeyListLabel < UILabel text-offset: 2 0 focusable: true phantom: false - + $focus: background-color: #ffffff22 @@ -16,13 +16,13 @@ MainWindow @onEnter: HotkeysManager.hide() @onEscape: HotkeysManager.hide() - LargerLabel + Label id: currentHotkeysLabel text: Current hotkeys: anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top - + TextList id: currentHotkeys anchors.left: parent.left @@ -32,14 +32,14 @@ MainWindow margin-top: 2 padding: 1 focusable: false - - LargerLabel + + Label text: Manage hotkeys: anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom - margin-top: 10 - + margin-top: 10 + Button id: addHotkey text: Add @@ -48,7 +48,7 @@ MainWindow anchors.top: prev.bottom margin-top: 2 @onClick: HotkeysManager.addHotkey() - + Button id: removeHotkey text: Remove @@ -58,16 +58,16 @@ MainWindow anchors.top: prev.top margin-left: 10 @onClick: HotkeysManager.removeHotkey() - - LargerLabel + + Label id: hotKeyTextLabel text: Edit hotkey text: enable: false anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom - margin-top: 20 - + margin-top: 20 + LineEdit id: hotkeyText enabled: false @@ -76,7 +76,7 @@ MainWindow anchors.top: prev.bottom margin-bottom: 2 @onTextChange: HotkeysManager.onHotkeyTextChange(self:getId(), self:getText()) - + CheckBox id: sendAutomatically text: Send automatically @@ -86,14 +86,14 @@ MainWindow enabled:false margin-top: 10 @onCheckChange: HotkeysManager.sendAutomatically(self:isChecked()) - + Item id: itemPreview anchors.left: parent.left anchors.top: prev.bottom margin-top: 10 virtual: true - + Button id: selectObjectButton text: Select object @@ -103,7 +103,7 @@ MainWindow anchors.top: prev.top margin-left: 10 @onClick: HotkeysManager.startChooseItem() - + Button id: clearObjectButton text: Clear object @@ -114,7 +114,7 @@ MainWindow anchors.top: prev.bottom margin-top: 2 @onClick: HotkeysManager.clearObject() - + ButtonBox id: useOnSelf text: Use on yourself @@ -126,7 +126,7 @@ MainWindow checked: false margin-left: 10 @onCheckChange: HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONSELF, self:isChecked()) - + ButtonBox id: useOnTarget text: Use on target @@ -138,7 +138,7 @@ MainWindow checked: false margin-top: 2 @onCheckChange: HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONTARGET, self:isChecked()) - + ButtonBox id: useWith text: With crosshair @@ -150,7 +150,7 @@ MainWindow checked: false margin-top: 2 @onCheckChange: HotkeysManager.changeUseType(HOTKEY_MANAGER_USEWITH, self:isChecked()) - + Button text: Close width: 64 diff --git a/modules/game_hotkeys/icon.png b/modules/old/game_hotkeys/icon.png similarity index 100% rename from modules/game_hotkeys/icon.png rename to modules/old/game_hotkeys/icon.png diff --git a/modules/old/game_interface/gameinterface.lua b/modules/old/game_interface/gameinterface.lua new file mode 100644 index 00000000..a7a38a50 --- /dev/null +++ b/modules/old/game_interface/gameinterface.lua @@ -0,0 +1,199 @@ +GameInterface = {} + +-- private variables +local WALK_AUTO_REPEAT_DELAY = 90 +local gameRootPanel +local gameMapPanel +local gameRightPanel +local gameLeftPanel +local gameBottomPanel + +-- private functions +function onGameStart() + -- hook window close event + setonclose(GameInterface.tryLogout) + GameInterface.show() +end + +function onGameEnd() + setonclose(exit) + GameInterface.hide() +end + +-- public functions +function GameInterface.init() + gameRootPanel = displayUI('gameinterface.otui') + gameRootPanel:lower() + connect(g_game, { onGameStart = onGameStart }, true) + connect(g_game, { onGameEnd = onGameEnd }) + + Keyboard.bindKeyPress('Up', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Right', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Down', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Left', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad8', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad9', function() g_game.walk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad6', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad3', function() g_game.walk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad2', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad1', function() g_game.walk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad4', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Numpad7', function() g_game.walk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) + Keyboard.bindKeyPress('Esc', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) +end + +function GameInterface.terminate() + disconnect(g_game, { onGameStart = onGameStart }, true) + disconnect(g_game, { onGameEnd = onGameEnd }) +end + +function GameInterface.show() + gameRootPanel:show() +end + +function GameInterface.hide() + gameRootPanel:hide() +end + +function GameInterface.tryLogout() + if g_game.isOnline() then + g_game.forceLogout() + else + exit() + end +end + +function GameInterface.getRootPanel() + return gameRootPanel +end + +function GameInterface.getMapPanel() + return gameMapPanel +end + +function GameInterface.getRightPanel() + return gameRightPanel +end + +function GameInterface.getLeftPanel() + return gameLeftPanel +end + +function GameInterface.getBottomPanel() + return gameBottomPanel +end + +function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing) + local menu = createWidget('PopupMenu') + + if lookThing then + menu:addOption('Look', function() g_game.look(lookThing) end) + end + + if useThing then + if useThing:isContainer() then + if useThing:isInsideContainer() then + menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end) + menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end) + else + menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end) + end + else + if useThing:isMultiUse() then + menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end) + else + menu:addOption('Use', function() g_game.use(useThing) end) + end + end + + if useThing:isRotateable() then + menu:addOption('Rotate', function() g_game.rotate(useThing) end) + end + + end + + if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then + menu:addSeparator() + menu:addOption('Trade with ...', function() print('trade with') end) + end + + -- check for move up + + if creatureThing then + menu:addSeparator() + + if creatureThing:asLocalPlayer() then + menu:addOption('Set Outfit', function() g_game.requestOutfit() end) + + if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then + if creatureThing:asPlayer():isPartyLeader() then + if creatureThing:asPlayer():isPartySharedExperienceActive() then + menu:addOption('Disable Shared Experience', function() g_game.partyShareExperience(false) end) + else + menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end) + end + end + menu:addOption('Leave Party', function() g_game.partyLeave() end) + end + + else + local localPlayer = g_game.getLocalPlayer() + if localPlayer then + if g_game.getAttackingCreature() ~= creatureThing then + menu:addOption('Attack', function() g_game.attack(creatureThing) end) + else + menu:addOption('Stop Attack', function() g_game.cancelAttack() end) + end + + if g_game.getFollowingCreature() ~= creatureThing then + menu:addOption('Follow', function() g_game.follow(creatureThing) end) + else + menu:addOption('Stop Follow', function() g_game.cancelFollow() end) + end + + if creatureThing:asPlayer() then + menu:addSeparator() + menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end) + menu:addOption('Add to VIP list', function() g_game.addVip(creatureThing:getName()) end) + + local localPlayerShield = localPlayer:asCreature():getShield() + local creatureShield = creatureThing:getShield() + + if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then + if creatureShield == ShieldWhiteYellow then + menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end) + else + menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end) + end + elseif localPlayerShield == ShieldWhiteYellow then + if creatureShield == ShieldWhiteBlue then + menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end) + end + elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then + if creatureShield == ShieldWhiteBlue then + menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end) + elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then + menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() g_game.partyPassLeadership(creatureThing:getId()) end) + else + menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end) + end + end + end + end + end + + menu:addSeparator() + menu:addOption('Copy Name', function() g_window.setClipboardText(creatureThing:getName()) end) + + end + + menu:display(menuPosition) +end diff --git a/modules/old/game_interface/gameinterface.otmod b/modules/old/game_interface/gameinterface.otmod new file mode 100644 index 00000000..3c395a06 --- /dev/null +++ b/modules/old/game_interface/gameinterface.otmod @@ -0,0 +1,20 @@ +Module + name: game_interface + description: | + Create the game main interface (map and bottom/left/right panels), + any game module must use it to add ingame interfaces + + author: OTClient team + website: https://github.com/edubart/otclient + + onLoad: | + dofile 'uiminiwindow' + dofile 'uiminiwindowcontainer' + dofile 'uiitem' + dofile 'uimap' + dofile 'gameinterface' + + GameInterface.init() + + onUnload: | + GameInterface.terminate() diff --git a/modules/old/game_interface/gameinterface.otui b/modules/old/game_interface/gameinterface.otui new file mode 100644 index 00000000..1bfb7f9e --- /dev/null +++ b/modules/old/game_interface/gameinterface.otui @@ -0,0 +1,46 @@ +GameSidePanel < UIMiniWindowContainer + image-source: /core_styles/styles/images/sidepanel.png + image-border: 4 + +GameBottomPanel < Panel + image-source: /core_styles/styles/images/bottompanel.png + image-border: 4 + +GameMapPanel < UIMap + padding: 4 + image-source: /core_styles/styles/images/mappanel.png + image-border: 4 + +UIGame + id: gameRootPanel + anchors.fill: parent + anchors.top: topMenu.bottom + + InterfacePanel + id: gameRightPanel + width: 190 + layout: verticalBox + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + + GameBottomPanel + id: gameBottomPanel + height: 170 + anchors.left: parent.left + anchors.right: gameRightPanel.left + anchors.bottom: parent.bottom + + GameMapPanel + id: gameMapPanel + anchors.left: parent.left + anchors.right: gameRightPanel.left + anchors.top: parent.top + anchors.bottom: gameBottomPanel.top + focusable: false + + UIWidget + id: mouseGrabber + focusable: false + visible: false + diff --git a/modules/core_styles/images/interface_panel2.png b/modules/old/game_interface/images/bottompanel.png similarity index 100% rename from modules/core_styles/images/interface_panel2.png rename to modules/old/game_interface/images/bottompanel.png diff --git a/modules/core_styles/images/map_panel.png b/modules/old/game_interface/images/mappanel.png similarity index 100% rename from modules/core_styles/images/map_panel.png rename to modules/old/game_interface/images/mappanel.png diff --git a/modules/core_styles/images/mini_window.png b/modules/old/game_interface/images/miniwindow.png similarity index 100% rename from modules/core_styles/images/mini_window.png rename to modules/old/game_interface/images/miniwindow.png diff --git a/modules/core_styles/images/interface_panel.png b/modules/old/game_interface/images/sidepanel.png similarity index 100% rename from modules/core_styles/images/interface_panel.png rename to modules/old/game_interface/images/sidepanel.png diff --git a/modules/core_widgets/uiitem.lua b/modules/old/game_interface/uiitem.lua similarity index 100% rename from modules/core_widgets/uiitem.lua rename to modules/old/game_interface/uiitem.lua diff --git a/modules/old/game_interface/uimap.lua b/modules/old/game_interface/uimap.lua new file mode 100644 index 00000000..bfc68e80 --- /dev/null +++ b/modules/old/game_interface/uimap.lua @@ -0,0 +1,56 @@ +function UIMap:onDragEnter(mousePos) + local tile = self:getTile(mousePos) + if not tile then return false end + + local thing = tile:getTopMoveThing() + if not thing then return false end + + self.parsed = false + self.currentDragThing = thing + Mouse.setTargetCursor() + return true +end + +function UIMap:onDragLeave(droppedWidget, mousePos) + if not self.parsed then + self.currentDragThing = nil + end + + Mouse.restoreCursor() + return true +end + +function UIMap:onDrop(widget, mousePos) + if not widget or not widget.currentDragThing then return false end + + local tile = self:getTile(mousePos) + if not tile then return false end + + local count = widget.currentDragThing:getCount() + if widget.currentDragThing:isStackable() and count > 1 then + widget.parsed = true + local moveWindow = displayUI('/game/movewindow.otui') + local spinbox = moveWindow:getChildById('spinbox') + spinbox:setMaximum(count) + spinbox:setMinimum(1) + spinbox:setCurrentIndex(count) + + local okButton = moveWindow:getChildById('buttonOk') + okButton.onClick = function() + g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) + okButton:getParent():destroy() + widget.currentDragThing = nil + end + moveWindow.onEnter = okButton.onClick + else + g_game.move(widget.currentDragThing, tile:getPosition(), 1) + end + + return true +end + +function UIMap:onMouseRelease(mousePosition, mouseButton) + local tile = self:getTile(mousePosition) + if tile and g_game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end + return false +end diff --git a/modules/core_widgets/uiminiwindow.lua b/modules/old/game_interface/uiminiwindow.lua similarity index 73% rename from modules/core_widgets/uiminiwindow.lua rename to modules/old/game_interface/uiminiwindow.lua index d71496d2..1293a0d2 100644 --- a/modules/core_widgets/uiminiwindow.lua +++ b/modules/old/game_interface/uiminiwindow.lua @@ -5,16 +5,10 @@ function UIMiniWindow.create() return miniwindow end -function UIMiniWindow:onMousePress(mousePos, mouseButton) - local parent = self:getParent() - if parent:getClassName() ~= 'UIMiniWindowContainer' then - self:raise() - end - return true -end - function UIMiniWindow:onDragEnter(mousePos) local parent = self:getParent() + if not parent then return false end + if parent:getClassName() == 'UIMiniWindowContainer' then local containerParent = parent:getParent() parent:removeChild(self) @@ -30,3 +24,13 @@ end function UIMiniWindow:onDragLeave(droppedWidget, mousePos) -- TODO: drop on other interfaces end + +function UIMiniWindow:onFocusChange(focused) + -- miniwindows only raises when its outside MiniWindowContainers + if not focused then return end + local parent = self:getParent() + if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then + self:raise() + end +end + diff --git a/modules/core_widgets/uiminiwindowcontainer.lua b/modules/old/game_interface/uiminiwindowcontainer.lua similarity index 100% rename from modules/core_widgets/uiminiwindowcontainer.lua rename to modules/old/game_interface/uiminiwindowcontainer.lua diff --git a/modules/game_inventory/inventory.lua b/modules/old/game_inventory/inventory.lua similarity index 94% rename from modules/game_inventory/inventory.lua rename to modules/old/game_inventory/inventory.lua index 758c5619..60c9472e 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/old/game_inventory/inventory.lua @@ -6,7 +6,7 @@ local inventoryButton -- public functions function Inventory.create() - inventoryWindow = displayUI('inventory.otui', { parent = g_game.gameRightPanel }) + inventoryWindow = displayUI('inventory.otui', g_game.gameRightPanel) 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/old/game_inventory/inventory.otmod similarity index 100% rename from modules/game_inventory/inventory.otmod rename to modules/old/game_inventory/inventory.otmod diff --git a/modules/game_inventory/inventory.otui b/modules/old/game_inventory/inventory.otui similarity index 94% rename from modules/game_inventory/inventory.otui rename to modules/old/game_inventory/inventory.otui index 4e1d4a72..5b0884a1 100644 --- a/modules/game_inventory/inventory.otui +++ b/modules/old/game_inventory/inventory.otui @@ -96,7 +96,7 @@ UIWindow text-align: center - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 GameLabel @@ -109,6 +109,6 @@ UIWindow text-align: center - image-source: /core_styles/images/panel_flat.png + image-source: /core_styles/styles/images/panel_flat.png image-border: 1 diff --git a/modules/game_inventory/inventory.png b/modules/old/game_inventory/inventory.png similarity index 100% rename from modules/game_inventory/inventory.png rename to modules/old/game_inventory/inventory.png diff --git a/modules/game_outfit/outfit.lua b/modules/old/game_outfit/outfit.lua similarity index 98% rename from modules/game_outfit/outfit.lua rename to modules/old/game_outfit/outfit.lua index b305539f..9fa17430 100644 --- a/modules/game_outfit/outfit.lua +++ b/modules/old/game_outfit/outfit.lua @@ -120,7 +120,7 @@ end -- public functions function Outfit.create(creature, outfitList) Outfit.destroy() - window = displayUI('outfit.otui', { parent = rootWidget }) + window = displayUI('outfit.otui') window:lock() m_outfit = creature:getOutfit() diff --git a/modules/game_outfit/outfit.otmod b/modules/old/game_outfit/outfit.otmod similarity index 100% rename from modules/game_outfit/outfit.otmod rename to modules/old/game_outfit/outfit.otmod diff --git a/modules/game_outfit/outfit.otui b/modules/old/game_outfit/outfit.otui similarity index 100% rename from modules/game_outfit/outfit.otui rename to modules/old/game_outfit/outfit.otui diff --git a/modules/game_skills/skills.lua b/modules/old/game_skills/skills.lua similarity index 98% rename from modules/game_skills/skills.lua rename to modules/old/game_skills/skills.lua index 8cdcac7f..b866ab47 100644 --- a/modules/game_skills/skills.lua +++ b/modules/old/game_skills/skills.lua @@ -42,7 +42,7 @@ end -- public functions function Skills.create() - skillsWindow = displayUI('skills.otui', { parent = g_game.gameRightPanel }) + skillsWindow = displayUI('skills.otui', g_game.gameRightPanel) 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/old/game_skills/skills.otmod similarity index 100% rename from modules/game_skills/skills.otmod rename to modules/old/game_skills/skills.otmod diff --git a/modules/game_skills/skills.otui b/modules/old/game_skills/skills.otui similarity index 100% rename from modules/game_skills/skills.otui rename to modules/old/game_skills/skills.otui diff --git a/modules/game_textmessage/textmessage.lua b/modules/old/game_textmessage/textmessage.lua similarity index 100% rename from modules/game_textmessage/textmessage.lua rename to modules/old/game_textmessage/textmessage.lua diff --git a/modules/game_textmessage/textmessage.otmod b/modules/old/game_textmessage/textmessage.otmod similarity index 100% rename from modules/game_textmessage/textmessage.otmod rename to modules/old/game_textmessage/textmessage.otmod diff --git a/modules/game_textmessage/textmessage.otui b/modules/old/game_textmessage/textmessage.otui similarity index 100% rename from modules/game_textmessage/textmessage.otui rename to modules/old/game_textmessage/textmessage.otui diff --git a/modules/game_viplist/addvip.otui b/modules/old/game_viplist/addvip.otui similarity index 100% rename from modules/game_viplist/addvip.otui rename to modules/old/game_viplist/addvip.otui diff --git a/modules/game_viplist/viplist.lua b/modules/old/game_viplist/viplist.lua similarity index 97% rename from modules/game_viplist/viplist.lua rename to modules/old/game_viplist/viplist.lua index 44d4e42b..5a5838ea 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/old/game_viplist/viplist.lua @@ -7,7 +7,7 @@ local addVipWindow -- public functions function VipList.create() - vipWindow = displayUI('viplist.otui', { parent = g_game.gameRightPanel }) + vipWindow = displayUI('viplist.otui', g_game.gameRightPanel) vipWindow:hide() vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) end diff --git a/modules/game_viplist/viplist.otmod b/modules/old/game_viplist/viplist.otmod similarity index 100% rename from modules/game_viplist/viplist.otmod rename to modules/old/game_viplist/viplist.otmod diff --git a/modules/game_viplist/viplist.otui b/modules/old/game_viplist/viplist.otui similarity index 100% rename from modules/game_viplist/viplist.otui rename to modules/old/game_viplist/viplist.otui diff --git a/modules/game_viplist/viplist.png b/modules/old/game_viplist/viplist.png similarity index 100% rename from modules/game_viplist/viplist.png rename to modules/old/game_viplist/viplist.png diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 3f69765d..204c7bec 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -13,7 +13,7 @@ OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF) # set debug as default build type IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE Debug) + SET(CMAKE_BUILD_TYPE RelWithDebInfo) ENDIF(NOT CMAKE_BUILD_TYPE) # find needed libraries @@ -36,18 +36,27 @@ FIND_PACKAGE(ZLIB REQUIRED) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch -Wno-missing-field-initializers") - SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}") - SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline") - SET(CMAKE_CXX_FLAGS_RELEASE "-O2") - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb -fno-inline") - SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed") + SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable") + SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}") + SET(CMAKE_C_FLAGS "-pipe ${CXX_WARNS}") + SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb") + SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") + SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") + SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + SET(CMAKE_C_FLAGS_RELEASE "-O2") + SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed") ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_DEFINITIONS(-DDEBUG) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") +IF(CMAKE_BUILD_TYPE STREQUAL "Release") + # NDEBUG disable asserts + ADD_DEFINITIONS(-DNDEBUG) +ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release") + MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) IF(USE_OPENGL_ES2) MESSAGE(STATUS "Renderer: OpenGL ES 2.0") @@ -194,4 +203,5 @@ SET(framework_SOURCES ${framework_SOURCES} # framework third party ${CMAKE_CURRENT_LIST_DIR}/thirdparty/apngloader.cpp + ${CMAKE_CURRENT_LIST_DIR}/thirdparty/lbitlib-5.2.0-backport4.c ) diff --git a/src/framework/application.cpp b/src/framework/application.cpp index f6a5b7b2..4a6a5a26 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -99,6 +99,7 @@ void Application::init(const std::vector& args, int appFlags) g_ui.init(); g_window.init(); + g_window.hide(); g_window.setOnResize(std::bind(&Application::resize, this, _1)); g_window.setOnInputEvent(std::bind(&Application::inputEvent, this, _1)); g_window.setOnClose(std::bind(&Application::close, this)); @@ -110,7 +111,7 @@ void Application::init(const std::vector& args, int appFlags) resize(g_window.getSize()); // display window when the application starts running - g_dispatcher.addEvent([]{ g_window.show(); }); + //g_dispatcher.addEvent([]{ g_window.show(); }); } if(m_appFlags & Fw::AppEnableModules) @@ -169,6 +170,8 @@ void Application::run() // run the first poll poll(); + g_lua.callGlobalField("g_app", "onRun"); + while(!m_stopping) { g_clock.updateTicks(); diff --git a/src/framework/const.h b/src/framework/const.h index 7c76ece3..9ba5e3cf 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -30,7 +30,7 @@ namespace Fw { - static const double pi = 3.14159265; + constexpr double pi = 3.14159265; // NOTE: AABBGGRR order enum GlobalColor : uint32 { diff --git a/src/framework/core/module.cpp b/src/framework/core/module.cpp index f5017d44..8eb2fb34 100644 --- a/src/framework/core/module.cpp +++ b/src/framework/core/module.cpp @@ -56,6 +56,14 @@ bool Module::load() logInfo("Loaded module '", m_name, "'"); g_modules.updateModuleLoadOrder(asModule()); + for(const std::string& modName : m_loadLaterModules) { + ModulePtr dep = g_modules.getModule(modName); + if(!dep) + logError("Unable to find module '", modName, "' required by '", m_name, "'"); + else if(!dep->isLoaded()) + dep->load(); + } + return true; } @@ -100,8 +108,8 @@ void Module::discover(const OTMLNodePtr& moduleNode) m_website = moduleNode->valueAt("website", none); m_version = moduleNode->valueAt("version", none); m_autoLoad = moduleNode->valueAt("autoload", false); - m_unloadable = moduleNode->valueAt("unloadable", true); - m_autoLoadAntecedence = moduleNode->valueAt("autoload-antecedence", 9999); + m_reloadable = moduleNode->valueAt("reloadable", false); + m_autoLoadPriority = moduleNode->valueAt("autoload-priority", 9999); if(OTMLNodePtr node = moduleNode->get("dependencies")) { for(const OTMLNodePtr& tmp : node->children()) @@ -109,16 +117,21 @@ void Module::discover(const OTMLNodePtr& moduleNode) } // set onLoad callback - if(OTMLNodePtr node = moduleNode->get("onLoad")) { + if(OTMLNodePtr node = moduleNode->get("@onLoad")) { g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); g_lua.useValue(); m_loadCallback = g_lua.polymorphicPop(); } // set onUnload callback - if(OTMLNodePtr node = moduleNode->get("onUnload")) { + if(OTMLNodePtr node = moduleNode->get("@onUnload")) { g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); g_lua.useValue(); m_unloadCallback = g_lua.polymorphicPop(); } + + if(OTMLNodePtr node = moduleNode->get("load-later")) { + for(const OTMLNodePtr& tmp : node->children()) + m_loadLaterModules.push_back(tmp->value()); + } } diff --git a/src/framework/core/module.h b/src/framework/core/module.h index 781aaa11..04372492 100644 --- a/src/framework/core/module.h +++ b/src/framework/core/module.h @@ -37,8 +37,10 @@ public: void unload(); bool reload(); - bool canUnload() { return m_loaded && m_unloadable && !isDependent(); } + bool canUnload() { return m_loaded && m_reloadable && !isDependent(); } + bool canReload() { return m_reloadable && !isDependent(); } bool isLoaded() { return m_loaded; } + bool isReloadable() { return m_reloadable; } bool isDependent(); bool hasDependency(const std::string& name); @@ -48,7 +50,7 @@ public: std::string getWebsite() { return m_website; } std::string getVersion() { return m_version; } bool isAutoLoad() { return m_autoLoad; } - int getAutoLoadAntecedence() { return m_autoLoadAntecedence; } + int getAutoLoadPriority() { return m_autoLoadPriority; } ModulePtr asModule() { return std::static_pointer_cast(shared_from_this()); } @@ -59,8 +61,8 @@ protected: private: Boolean m_loaded; Boolean m_autoLoad; - Boolean m_unloadable; - int m_autoLoadAntecedence; + Boolean m_reloadable; + int m_autoLoadPriority; std::string m_name; std::string m_description; std::string m_author; @@ -69,6 +71,7 @@ private: SimpleCallback m_loadCallback; SimpleCallback m_unloadCallback; std::list m_dependencies; + std::list m_loadLaterModules; }; #endif diff --git a/src/framework/core/modulemanager.cpp b/src/framework/core/modulemanager.cpp index ae0b6471..05901fae 100644 --- a/src/framework/core/modulemanager.cpp +++ b/src/framework/core/modulemanager.cpp @@ -40,17 +40,17 @@ void ModuleManager::discoverModules() if(boost::ends_with(moduleFile, ".otmod")) { ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile); if(module && module->isAutoLoad()) - m_autoLoadModules.insert(make_pair(module->getAutoLoadAntecedence(), module)); + m_autoLoadModules.insert(make_pair(module->getAutoLoadPriority(), module)); } } } } -void ModuleManager::autoLoadModules(int maxAntecedence) +void ModuleManager::autoLoadModules(int maxPriority) { for(auto& pair : m_autoLoadModules) { int priority = pair.first; - if(priority > maxAntecedence) + if(priority > maxPriority) break; ModulePtr module = pair.second; if(!module->isLoaded() && !module->load()) diff --git a/src/framework/core/modulemanager.h b/src/framework/core/modulemanager.h index 957d8f57..bada770a 100644 --- a/src/framework/core/modulemanager.h +++ b/src/framework/core/modulemanager.h @@ -30,7 +30,7 @@ class ModuleManager public: void discoverModulesPath(); void discoverModules(); - void autoLoadModules(int maxAntecedence); + void autoLoadModules(int maxPriority); ModulePtr discoverModule(const std::string& moduleFile); void ensureModuleLoaded(const std::string& moduleName); void unloadModules(); diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 8e7db4e9..245965dc 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -160,7 +160,6 @@ std::list ResourceManager::listDirectoryFiles(const std::string& di std::string ResourceManager::checkPath(const std::string& path) { - /* std::string fullPath; if(boost::starts_with(path, "/")) fullPath = path; @@ -170,10 +169,9 @@ std::string ResourceManager::checkPath(const std::string& path) fullPath += scriptPath + "/"; fullPath += path; } - */ - if(!(boost::starts_with(path, "/"))) + if(!(boost::starts_with(fullPath, "/"))) logTraceWarning("the following file path is not fully resolved: ", path); - return path; + return fullPath; } std::string ResourceManager::getBaseDir() diff --git a/src/framework/global.h b/src/framework/global.h index 0ae020e8..f30f6e49 100644 --- a/src/framework/global.h +++ b/src/framework/global.h @@ -23,6 +23,14 @@ #ifndef FRAMEWORK_GLOBAL_H #define FRAMEWORK_GLOBAL_H +#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#error "sorry, you need gcc 4.6 or greater to compile" +#endif + +#if !defined(__GXX_EXPERIMENTAL_CXX0X__) +#error "sorry, you must enable C++0x to compile" +#endif + // common C/C++ headers #include "pch.h" diff --git a/src/framework/graphics/graphics.h b/src/framework/graphics/graphics.h index b811bb7e..122588df 100644 --- a/src/framework/graphics/graphics.h +++ b/src/framework/graphics/graphics.h @@ -42,7 +42,7 @@ public: int getMaxTextureSize(); const Size& getViewportSize() { return m_viewportSize; } - TexturePtr getEmptyTexture() { return m_emptyTexture; } + TexturePtr& getEmptyTexture() { return m_emptyTexture; } private: Size m_viewportSize; diff --git a/src/framework/graphics/painter.cpp b/src/framework/graphics/painter.cpp index 12638d55..c6aac106 100644 --- a/src/framework/graphics/painter.cpp +++ b/src/framework/graphics/painter.cpp @@ -39,12 +39,12 @@ void Painter::init() m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram); m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); m_drawTexturedProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader); - assert(m_drawTexturedProgram->link()); + m_drawTexturedProgram->link(); m_drawSolidColorProgram = PainterShaderProgramPtr(new PainterShaderProgram); m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader); m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader); - assert(m_drawSolidColorProgram->link()); + m_drawSolidColorProgram->link(); } void Painter::terminate() diff --git a/src/framework/graphics/paintershaderprogram.cpp b/src/framework/graphics/paintershaderprogram.cpp index 9cf48bbb..c5a9a72c 100644 --- a/src/framework/graphics/paintershaderprogram.cpp +++ b/src/framework/graphics/paintershaderprogram.cpp @@ -92,7 +92,7 @@ void PainterShaderProgram::setTexture(const TexturePtr& texture) void PainterShaderProgram::draw(const CoordsBuffer& coordsBuffer, DrawMode drawMode) { - assert(bind()); + bind(); setUniformValue(TIME_UNIFORM, (float)m_startTimer.timeElapsed()); diff --git a/src/framework/graphics/paintershadersources.h b/src/framework/graphics/paintershadersources.h index a7013285..cbc74415 100644 --- a/src/framework/graphics/paintershadersources.h +++ b/src/framework/graphics/paintershadersources.h @@ -20,14 +20,14 @@ * THE SOFTWARE. */ -static int VERTEX_COORDS_ATTR = 0; -static int TEXTURE_COORDS_ATTR = 1; +const static int VERTEX_COORDS_ATTR = 0; +const static int TEXTURE_COORDS_ATTR = 1; -static int PROJECTION_MATRIX_UNIFORM = 0; -static int TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1; -static int COLOR_UNIFORM = 2; -static int OPACITY_UNIFORM = 3; -static int TEXTURE_UNIFORM = 4; +const static int PROJECTION_MATRIX_UNIFORM = 0; +const static int TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1; +const static int COLOR_UNIFORM = 2; +const static int OPACITY_UNIFORM = 3; +const static int TEXTURE_UNIFORM = 4; static const std::string glslMainVertexShader = "\n\ highp vec4 calculatePosition();\n\ diff --git a/src/framework/graphics/particle.cpp b/src/framework/graphics/particle.cpp index 91f8700a..d91397ac 100644 --- a/src/framework/graphics/particle.cpp +++ b/src/framework/graphics/particle.cpp @@ -73,8 +73,6 @@ void Particle::update(double elapsedTime) void Particle::updatePosition(double elapsedTime) { - bool mustRedraw = false; - if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) { // update position PointF delta = m_velocity * elapsedTime; @@ -83,7 +81,6 @@ void Particle::updatePosition(double elapsedTime) PointF position = m_position + delta; if(m_position != position) { - mustRedraw = true; m_position += delta; } @@ -96,11 +93,8 @@ void Particle::updatePosition(double elapsedTime) void Particle::updateSize() { - bool mustRedraw = false; - Size size = m_startSize + (m_finalSize - m_startSize) / m_duration * m_elapsedTime; if(m_size != size) { - mustRedraw = true; m_size = size; } @@ -109,15 +103,12 @@ void Particle::updateSize() void Particle::updateColor() { - bool mustRedraw = false; - if(m_elapsedTime < m_colorsStops[1]) { Color color = Color(m_colors[0].r() + (m_colors[1].r() - m_colors[0].r()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]), m_colors[0].g() + (m_colors[1].g() - m_colors[0].g()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]), m_colors[0].b() + (m_colors[1].b() - m_colors[0].b()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]), m_colors[0].a() + (m_colors[1].a() - m_colors[0].a()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0])); if(m_color != color) { - mustRedraw = true; m_color = color; } } @@ -128,7 +119,6 @@ void Particle::updateColor() } else { if(m_color != m_colors[0]) { - mustRedraw = true; m_color = m_colors[0]; } } diff --git a/src/framework/graphics/particlemanager.cpp b/src/framework/graphics/particlemanager.cpp index dea180d7..25872921 100644 --- a/src/framework/graphics/particlemanager.cpp +++ b/src/framework/graphics/particlemanager.cpp @@ -30,7 +30,6 @@ bool ParticleManager::load(const std::string& filename) { try { OTMLDocumentPtr doc = OTMLDocument::parse(filename); - const OTMLNodePtr& node = doc->at("ParticleSystem"); for(const OTMLNodePtr& node : doc->children()) { if(node->tag() == "ParticleSystem") { ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem); diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index e993be7d..f9dcf793 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -386,15 +386,17 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("load", &Module::load); g_lua.bindClassMemberFunction("unload", &Module::unload); g_lua.bindClassMemberFunction("reload", &Module::reload); + g_lua.bindClassMemberFunction("canReload", &Module::canReload); g_lua.bindClassMemberFunction("canUnload", &Module::canUnload); g_lua.bindClassMemberFunction("isLoaded", &Module::isLoaded); + g_lua.bindClassMemberFunction("isReloadble", &Module::isReloadable); g_lua.bindClassMemberFunction("getDescription", &Module::getDescription); g_lua.bindClassMemberFunction("getName", &Module::getName); g_lua.bindClassMemberFunction("getAuthor", &Module::getAuthor); g_lua.bindClassMemberFunction("getWebsite", &Module::getWebsite); g_lua.bindClassMemberFunction("getVersion", &Module::getVersion); g_lua.bindClassMemberFunction("isAutoLoad", &Module::isAutoLoad); - g_lua.bindClassMemberFunction("getAutoLoadAntecedence", &Module::getAutoLoadAntecedence); + g_lua.bindClassMemberFunction("getAutoLoadPriority", &Module::getAutoLoadPriority); // network manipulation via lua is disabled for a while /* @@ -468,14 +470,10 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("g_window", "hasFocus", std::bind(&PlatformWindow::hasFocus, &g_window)); // Logger - g_lua.registerClass(); - g_lua.bindClassStaticFunction("log", std::bind(&Logger::log, &g_logger, _1, _2)); - g_lua.bindClassStaticFunction("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger)); - g_lua.bindClassStaticFunction("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1)); - - // Lua - g_lua.registerStaticClass("g_lua"); - g_lua.bindClassStaticFunction("g_lua", "runScript", std::bind(&LuaInterface::runScript, &g_lua, _1)); + g_lua.registerStaticClass("g_logger"); + g_lua.bindClassStaticFunction("g_logger", "log", std::bind(&Logger::log, &g_logger, _1, _2)); + g_lua.bindClassStaticFunction("g_logger", "fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger)); + g_lua.bindClassStaticFunction("g_logger", "setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1)); // UI g_lua.registerStaticClass("g_ui"); diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index e6b32668..384132c3 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -26,6 +26,8 @@ #include #include +#include + LuaInterface g_lua; LuaInterface::LuaInterface() @@ -590,6 +592,9 @@ void LuaInterface::createLuaState() // load lua standard libraries luaL_openlibs(L); + + // load bit32 lib for bitwise operations + luaopen_bit32(L); // creates weak table newTable(); @@ -812,7 +817,9 @@ void LuaInterface::getEnv(int index) void LuaInterface::setEnv(int index) { assert(hasIndex(index)); - assert(lua_setfenv(L, index) == 1); + int ret; + ret = lua_setfenv(L, index); + assert(ret == 1); } void LuaInterface::getTable(int index) diff --git a/src/framework/luascript/luavaluecasts.h b/src/framework/luascript/luavaluecasts.h index 5b4f5b94..976f15c0 100644 --- a/src/framework/luascript/luavaluecasts.h +++ b/src/framework/luascript/luavaluecasts.h @@ -191,7 +191,8 @@ bool luavalue_cast(int index, std::function& func) { try { if(g_lua.isFunction()) { g_lua.polymorphicPush(args...); - assert(g_lua.safeCall(sizeof...(Args)) == 0); + int rets = g_lua.safeCall(sizeof...(Args)); + g_lua.pop(rets); } else { throw LuaException("attempt to call an expired lua function from C++," "did you forget to hold a reference for that function?", 0); diff --git a/src/framework/platform/platformwindow.h b/src/framework/platform/platformwindow.h index ba421d56..34005944 100644 --- a/src/framework/platform/platformwindow.h +++ b/src/framework/platform/platformwindow.h @@ -80,8 +80,8 @@ public: bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; } bool isVisible() { return m_visible; } + bool isMaximized() { return m_maximized; } bool isFullscreen() { return m_fullscreen; } - virtual bool isMaximized() = 0; bool hasFocus() { return m_focused; } void setOnClose(const SimpleCallback& onClose) { m_onClose = onClose; } @@ -112,6 +112,7 @@ protected: Boolean m_visible; Boolean m_focused; Boolean m_fullscreen; + Boolean m_maximized; SimpleCallback m_onClose; OnResizeCallback m_onResize; diff --git a/src/framework/platform/unixcrashhandler.cpp b/src/framework/platform/unixcrashhandler.cpp index 8bb5bc8a..d86013ca 100644 --- a/src/framework/platform/unixcrashhandler.cpp +++ b/src/framework/platform/unixcrashhandler.cpp @@ -20,14 +20,22 @@ * THE SOFTWARE. */ +#define __USE_GNU + #include "crashhandler.h" #include -#include #include +#include +#include + #define MAX_BACKTRACE_DEPTH 128 #define DEMANGLE_BACKTRACE_SYMBOLS +#ifndef REG_RIP +#error fuck +#endif + void crashHandler(int signum, siginfo_t* info, void* secret) { logError("Application crashed"); @@ -41,20 +49,8 @@ void crashHandler(int signum, siginfo_t* info, void* secret) std::stringstream ss; ss.flags(std::ios::hex | std::ios::showbase); -#ifdef REG_EIP - ss << - ss << " at eip = " << context.uc_mcontext.gregs[REG_EIP] << std::endl; - ss << " eax = " << context.uc_mcontext.gregs[REG_EAX] << std::endl; - ss << " ebx = " << context.uc_mcontext.gregs[REG_EBX] << std::endl; - ss << " ecx = " << context.uc_mcontext.gregs[REG_ECX] << std::endl; - ss << " edx = " << context.uc_mcontext.gregs[REG_EDX] << std::endl; - ss << " esi = " << context.uc_mcontext.gregs[REG_ESI] << std::endl; - ss << " edi = " << context.uc_mcontext.gregs[REG_EDI] << std::endl; - ss << " ebp = " << context.uc_mcontext.gregs[REG_EBP] << std::endl; - ss << " esp = " << context.uc_mcontext.gregs[REG_ESP] << std::endl; - ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl; - ss << std::endl; -#elifdef REG_RIP + +#if __WORDSIZE == 64 ss << " at rip = " << context.uc_mcontext.gregs[REG_RIP] << std::endl; ss << " rax = " << context.uc_mcontext.gregs[REG_RAX] << std::endl; ss << " rbx = " << context.uc_mcontext.gregs[REG_RBX] << std::endl; @@ -66,7 +62,20 @@ void crashHandler(int signum, siginfo_t* info, void* secret) ss << " rsp = " << context.uc_mcontext.gregs[REG_RSP] << std::endl; ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl; ss << std::endl; +#else + ss << " at eip = " << context.uc_mcontext.gregs[REG_EIP] << std::endl; + ss << " eax = " << context.uc_mcontext.gregs[REG_EAX] << std::endl; + ss << " ebx = " << context.uc_mcontext.gregs[REG_EBX] << std::endl; + ss << " ecx = " << context.uc_mcontext.gregs[REG_ECX] << std::endl; + ss << " edx = " << context.uc_mcontext.gregs[REG_EDX] << std::endl; + ss << " esi = " << context.uc_mcontext.gregs[REG_ESI] << std::endl; + ss << " edi = " << context.uc_mcontext.gregs[REG_EDI] << std::endl; + ss << " ebp = " << context.uc_mcontext.gregs[REG_EBP] << std::endl; + ss << " esp = " << context.uc_mcontext.gregs[REG_ESP] << std::endl; + ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl; + ss << std::endl; #endif + ss.flags(std::ios::dec); ss << " backtrace:" << std::endl; diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index fc05039f..681d46fa 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -36,7 +36,6 @@ WIN32Window::WIN32Window() m_deviceContext = 0; m_glContext = 0; m_cursor = 0; - m_maximized = false; m_minimumSize = Size(600,480); m_keyMap[VK_ESCAPE] = Fw::KeyEscape; @@ -675,7 +674,9 @@ void WIN32Window::setFullscreen(bool fullscreen) return; DWORD dwStyle = GetWindowLong(m_window, GWL_STYLE); - static WINDOWPLACEMENT wpPrev = { sizeof(wpPrev) }; + static WINDOWPLACEMENT wpPrev; + wpPrev.length = sizeof(wpPrev); + if(fullscreen) { GetWindowPlacement(m_window, &wpPrev); SetWindowLong(m_window, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW); diff --git a/src/framework/platform/win32window.h b/src/framework/platform/win32window.h index 89bec67c..e4a55846 100644 --- a/src/framework/platform/win32window.h +++ b/src/framework/platform/win32window.h @@ -75,8 +75,6 @@ public: std::string getClipboardText(); std::string getPlatformType(); - bool isMaximized() { return m_maximized; } - private: HWND m_window; HINSTANCE m_instance; @@ -84,7 +82,6 @@ private: HGLRC m_glContext; HCURSOR m_cursor; HCURSOR m_defaultCursor; - bool m_maximized; Size m_minimumSize; }; diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 68e95c80..996ec07b 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -261,7 +261,8 @@ void X11Window::internalCreateWindow() Visual *vis; int depth; unsigned int attrsMask = CWEventMask; - XSetWindowAttributes attrs = {0}; + XSetWindowAttributes attrs; + memset(&attrs, 0, sizeof(attrs)); attrs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | @@ -290,6 +291,8 @@ void X11Window::internalCreateWindow() InputOutput, vis, attrsMask, &attrs); + m_visible = true; + if(!m_window) logFatal("Unable to create X11 window!"); @@ -474,12 +477,9 @@ bool X11Window::isExtensionSupported(const char *ext) void X11Window::move(const Point& pos) { - bool wasVisible = isVisible(); - if(!wasVisible) - show(); - XMoveWindow(m_display, m_window, pos.x, pos.y); - if(!wasVisible) - hide(); + m_position = pos; + if(m_visible) + XMoveWindow(m_display, m_window, m_position.x, m_position.y); } void X11Window::resize(const Size& size) @@ -489,33 +489,45 @@ void X11Window::resize(const Size& size) void X11Window::show() { + m_visible = true; XMapWindow(m_display, m_window); + XMoveWindow(m_display, m_window, m_position.x, m_position.y); + XFlush(m_display); + if(m_maximized) + maximize(); + if(m_fullscreen) + setFullscreen(true); } void X11Window::hide() { + m_visible = false; XUnmapWindow(m_display, m_window); + XFlush(m_display); } void X11Window::maximize() { - Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False); - Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); - Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); - - XEvent e = {0}; - e.xany.type = ClientMessage; - e.xclient.send_event = True; - e.xclient.message_type = wmState; - e.xclient.format = 32; - e.xclient.window = m_window; - e.xclient.data.l[0] = 1; - e.xclient.data.l[1] = wmStateMaximizedVert; - e.xclient.data.l[2] = wmStateMaximizedHorz; - e.xclient.data.l[3] = 0; - - XSendEvent(m_display, m_rootWindow, 0, SubstructureNotifyMask | SubstructureRedirectMask, &e); - XFlush(m_display); + if(m_visible) { + Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False); + Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + + XEvent e = {0}; + e.xany.type = ClientMessage; + e.xclient.send_event = True; + e.xclient.message_type = wmState; + e.xclient.format = 32; + e.xclient.window = m_window; + e.xclient.data.l[0] = 1; + e.xclient.data.l[1] = wmStateMaximizedVert; + e.xclient.data.l[2] = wmStateMaximizedHorz; + e.xclient.data.l[3] = 0; + + XSendEvent(m_display, m_rootWindow, 0, SubstructureNotifyMask | SubstructureRedirectMask, &e); + XFlush(m_display); + } + m_maximized = true; } void X11Window::poll() @@ -543,7 +555,7 @@ void X11Window::poll() // lookup keysym and translate it KeySym keysym; char buf[32]; - int len = XLookupString(&xkey, buf, sizeof(buf), &keysym, 0); + XLookupString(&xkey, buf, sizeof(buf), &keysym, 0); Fw::Key keyCode = Fw::KeyUnknown; if(m_keyMap.find(keysym) != m_keyMap.end()) @@ -580,8 +592,41 @@ void X11Window::poll() needsResizeUpdate = true; } + // checks if the window is maximized + if(m_visible) { + m_maximized = false; + Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False); + Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + Atom actualType; + ulong i, numItems, bytesAfter; + uchar *propertyValue = NULL; + int actualFormat; + + if(XGetWindowProperty(m_display, m_window, wmState, + 0, 1024, False, XA_ATOM, &actualType, + &actualFormat, &numItems, &bytesAfter, + &propertyValue) == Success) { + Atom *atoms = (Atom*)propertyValue; + int maximizedMask = 0; + + for(i=0; i +#include + +/* ----- adapted from lua-5.2.0 luaconf.h: ----- */ + +/* +@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned. +** It must have at least 32 bits. +*/ +#define LUA_UNSIGNED unsigned LUAI_INT32 + +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */ + +/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes + with a DirectX idiosyncrasy */ +#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */ + +#define MS_ASMTRICK + +#else /* }{ */ +/* the next definition uses a trick that should work on any machine + using IEEE754 with a 32-bit integer type */ + +#define LUA_IEEE754TRICK + +/* +@@ LUA_IEEEENDIAN is the endianness of doubles in your machine +** (0 for little endian, 1 for big endian); if not defined, Lua will +** check it dynamically. +*/ +/* check for known architectures */ +#if defined(__i386__) || defined(__i386) || defined(__X86__) || \ + defined (__x86_64) +#define LUA_IEEEENDIAN 0 +#elif defined(__POWERPC__) || defined(__ppc__) +#define LUA_IEEEENDIAN 1 +#endif + +#endif /* } */ + +#endif /* } */ + +/* ----- from lua-5.2.0 lua.h: ----- */ + +/* unsigned integer type */ +typedef LUA_UNSIGNED lua_Unsigned; + +/* ----- adapted from lua-5.2.0 llimits.h: ----- */ + +/* lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned. +** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number. +*/ + +#if defined(MS_ASMTRICK) /* { */ +/* trick with Microsoft assembler for X86 */ + +#define lua_number2unsigned(i,n) \ + {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} + +#elif defined(LUA_IEEE754TRICK) /* }{ */ +/* the next trick should work on any machine using IEEE754 with + a 32-bit integer type */ + +union luai_Cast2 { double l_d; LUAI_INT32 l_p[2]; }; + +#if !defined(LUA_IEEEENDIAN) /* { */ +#define LUAI_EXTRAIEEE \ + static const union luai_Cast2 ieeeendian = {-(33.0 + 6755399441055744.0)}; +#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33) +#else +#define LUAI_EXTRAIEEE /* empty */ +#endif /* } */ + +#define lua_number2int32(i,n,t) \ + { LUAI_EXTRAIEEE \ + volatile union luai_Cast2 u; u.l_d = (n) + 6755399441055744.0; \ + (i) = (t)u.l_p[LUA_IEEEENDIAN]; } + +#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) + +#endif /* } */ + +#if !defined(lua_number2unsigned) /* { */ +/* the following definition assures proper modulo behavior */ +#if defined(LUA_NUMBER_DOUBLE) +#include +#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1) +#define lua_number2unsigned(i,n) \ + ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED)) +#else +#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) +#endif +#endif /* } */ + +/* on several machines, coercion from unsigned to double is slow, + so it may be worth to avoid */ +#define lua_unsigned2number(u) \ + (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) + +/* ----- adapted from lua-5.2.0 lapi.c: ----- */ + +static void lua_pushunsigned (lua_State *L, lua_Unsigned u) { + lua_Number n; + n = lua_unsigned2number(u); + lua_pushnumber(L, n); +} + +/* ----- adapted from lua-5.2.0-work3 lbitlib.c getuintarg(): ----- */ + +static lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) { + lua_Unsigned r; + lua_Number x = lua_tonumber(L, arg); + if (x == 0) luaL_checktype(L, arg, LUA_TNUMBER); + lua_number2unsigned(r, x); + return r; +} + +/* ----- Lua 5.2 luaL_newlib() compatibility: ----- */ + +#define LUAMOD_API LUALIB_API +#define LUA_BITLIBNAME "bit32" +#define luaL_newlib(x, y) luaL_register(x, LUA_BITLIBNAME, y) + +/* ----- avoid a 'symbol redefined' warning below ----- */ + +#undef LUA_LIB + +/* ----- here follows the unmodified lbitlib.c from Lua 5.2.0 ----- */ + +/* +** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $ +** Standard library for bitwise operations +** See Copyright Notice in lua.h +*/ + +#define lbitlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* number of bits to consider in a number */ +#if !defined(LUA_NBITS) +#define LUA_NBITS 32 +#endif + + +#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) + +/* macro to trim extra bits */ +#define trim(x) ((x) & ALLONES) + + +/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ +#define mask(n) (~((ALLONES << 1) << ((n) - 1))) + + +typedef lua_Unsigned b_uint; + + + +static b_uint andaux (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = ~(b_uint)0; + for (i = 1; i <= n; i++) + r &= luaL_checkunsigned(L, i); + return trim(r); +} + + +static int b_and (lua_State *L) { + b_uint r = andaux(L); + lua_pushunsigned(L, r); + return 1; +} + + +static int b_test (lua_State *L) { + b_uint r = andaux(L); + lua_pushboolean(L, r != 0); + return 1; +} + + +static int b_or (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = 0; + for (i = 1; i <= n; i++) + r |= luaL_checkunsigned(L, i); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_xor (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = 0; + for (i = 1; i <= n; i++) + r ^= luaL_checkunsigned(L, i); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_not (lua_State *L) { + b_uint r = ~luaL_checkunsigned(L, 1); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_shift (lua_State *L, b_uint r, int i) { + if (i < 0) { /* shift right? */ + i = -i; + r = trim(r); + if (i >= LUA_NBITS) r = 0; + else r >>= i; + } + else { /* shift left */ + if (i >= LUA_NBITS) r = 0; + else r <<= i; + r = trim(r); + } + lua_pushunsigned(L, r); + return 1; +} + + +static int b_lshift (lua_State *L) { + return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2)); +} + + +static int b_rshift (lua_State *L) { + return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2)); +} + + +static int b_arshift (lua_State *L) { + b_uint r = luaL_checkunsigned(L, 1); + int i = luaL_checkint(L, 2); + if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1)))) + return b_shift(L, r, -i); + else { /* arithmetic shift for 'negative' number */ + if (i >= LUA_NBITS) r = ALLONES; + else + r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */ + lua_pushunsigned(L, r); + return 1; + } +} + + +static int b_rot (lua_State *L, int i) { + b_uint r = luaL_checkunsigned(L, 1); + i &= (LUA_NBITS - 1); /* i = i % NBITS */ + r = trim(r); + r = (r << i) | (r >> (LUA_NBITS - i)); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_lrot (lua_State *L) { + return b_rot(L, luaL_checkint(L, 2)); +} + + +static int b_rrot (lua_State *L) { + return b_rot(L, -luaL_checkint(L, 2)); +} + + +/* +** get field and width arguments for field-manipulation functions, +** checking whether they are valid +*/ +static int fieldargs (lua_State *L, int farg, int *width) { + int f = luaL_checkint(L, farg); + int w = luaL_optint(L, farg + 1, 1); + luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); + luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); + if (f + w > LUA_NBITS) + luaL_error(L, "trying to access non-existent bits"); + *width = w; + return f; +} + + +static int b_extract (lua_State *L) { + int w; + b_uint r = luaL_checkunsigned(L, 1); + int f = fieldargs(L, 2, &w); + r = (r >> f) & mask(w); + lua_pushunsigned(L, r); + return 1; +} + + +static int b_replace (lua_State *L) { + int w; + b_uint r = luaL_checkunsigned(L, 1); + b_uint v = luaL_checkunsigned(L, 2); + int f = fieldargs(L, 3, &w); + int m = mask(w); + v &= m; /* erase bits outside given width */ + r = (r & ~(m << f)) | (v << f); + lua_pushunsigned(L, r); + return 1; +} + + +static const luaL_Reg bitlib[] = { + {"arshift", b_arshift}, + {"band", b_and}, + {"bnot", b_not}, + {"bor", b_or}, + {"bxor", b_xor}, + {"btest", b_test}, + {"extract", b_extract}, + {"lrotate", b_lrot}, + {"lshift", b_lshift}, + {"replace", b_replace}, + {"rrotate", b_rrot}, + {"rshift", b_rshift}, + {NULL, NULL} +}; + + + +int luaopen_bit32 (lua_State *L) { + luaL_newlib(L, bitlib); + return 1; +} + diff --git a/src/framework/thirdparty/lbitlib-5.2.0-backport4.h b/src/framework/thirdparty/lbitlib-5.2.0-backport4.h new file mode 100644 index 00000000..078124bd --- /dev/null +++ b/src/framework/thirdparty/lbitlib-5.2.0-backport4.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef LBITLIB_520_BACKPORT4_H +#define LBITLIB_520_BACKPORT4_H + +struct lua_State; + +extern "C" { +int luaopen_bit32 (lua_State *L); +}; + +#endif diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 168c561c..3eb029e4 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -113,6 +113,8 @@ void UIManager::inputEvent(const InputEvent& event) case Fw::MouseWheelInputEvent: m_mouseReceiver->propagateOnMouseWheel(event.mousePos, event.wheelDirection); break; + default: + break; }; m_isOnInputEvent = false; } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 76489b9e..c5ffb320 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -109,6 +109,11 @@ void UIWidget::addChild(const UIWidgetPtr& child) return; } + if(child->isDestroyed()) { + logWarning("attemp to add a destroyed child into a UIWidget"); + return; + } + if(hasChild(child)) { logWarning("attempt to add a child again into a UIWidget"); return; @@ -145,7 +150,10 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child) index = index <= 0 ? (m_children.size() + index) : index-1; - assert(index >= 0 && (uint)index <= m_children.size()); + if(!(index >= 0 && (uint)index <= m_children.size())) { + logTraceError("attemp to insert a child in an invalid index"); + return; + } // retrieve child by index auto it = m_children.begin() + index; @@ -300,7 +308,11 @@ void UIWidget::lowerChild(UIWidgetPtr child) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); - assert(it != m_children.end()); + if(it == m_children.end()) { + logTraceError("cannot find child"); + return; + } + m_children.erase(it); m_children.push_front(child); updateChildrenIndexStates(); @@ -316,7 +328,10 @@ void UIWidget::raiseChild(UIWidgetPtr child) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); - assert(it != m_children.end()); + if(it == m_children.end()) { + logTraceError("cannot find child"); + return; + } m_children.erase(it); m_children.push_back(child); updateChildrenIndexStates(); @@ -332,7 +347,10 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); - assert(it != m_children.end()); + if(it == m_children.end()) { + logTraceError("cannot find child"); + return; + } m_children.erase(it); m_children.insert(m_children.begin() + index - 1, child); updateChildrenIndexStates(); @@ -346,7 +364,10 @@ void UIWidget::lockChild(const UIWidgetPtr& child) if(!child) return; - assert(hasChild(child)); + if(!hasChild(child)) { + logTraceError("cannot find child"); + return; + } // prevent double locks if(isChildLocked(child)) @@ -365,8 +386,6 @@ void UIWidget::lockChild(const UIWidgetPtr& child) // lock child focus if(child->isFocusable()) focusChild(child, Fw::ActiveFocusReason); - - raiseChild(child); } void UIWidget::unlockChild(const UIWidgetPtr& child) @@ -377,7 +396,10 @@ void UIWidget::unlockChild(const UIWidgetPtr& child) if(!child) return; - assert(hasChild(child)); + if(!hasChild(child)) { + logTraceError("cannot find child"); + return; + } auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child); if(it == m_lockedChildren.end()) @@ -408,8 +430,6 @@ void UIWidget::unlockChild(const UIWidgetPtr& child) if(lockedChild) { if(lockedChild->isFocusable()) focusChild(lockedChild, Fw::ActiveFocusReason); - - raiseChild(lockedChild); } } diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index fc1af13e..5f2b0981 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -28,10 +28,8 @@ void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode) { for(const OTMLNodePtr& node : styleNode->children()) { - if(node->tag() == "image") - setImageSource(node->value()); - else if(node->tag() == "image-source") - setImageSource(node->value()); + if(node->tag() == "image-source") + setImageSource(Fw::resolvePath(node->value(), styleNode->source())); else if(node->tag() == "image-offset-x") setImageOffsetX(node->value()); else if(node->tag() == "image-offset-y") diff --git a/src/otclient/CMakeLists.txt b/src/otclient/CMakeLists.txt index 946ef205..d6148735 100644 --- a/src/otclient/CMakeLists.txt +++ b/src/otclient/CMakeLists.txt @@ -45,7 +45,6 @@ SET(otclient_SOURCES ${otclient_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/ui/uiitem.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uicreature.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uimap.cpp - ${CMAKE_CURRENT_LIST_DIR}/ui/uigame.cpp # otclient net ${CMAKE_CURRENT_LIST_DIR}/net/protocollogin.cpp diff --git a/src/otclient/const.h b/src/otclient/const.h index bd0e69f2..f38d115d 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -27,9 +27,9 @@ namespace Otc { - static const char* AppName = "OTClient"; - static const char* AppCompactName = "otclient"; - static const char* AppVersion = "0.4.0"; + constexpr const char* AppName = "OTClient"; + constexpr const char* AppCompactName = "otclient"; + constexpr const char* AppVersion = "0.4.0"; enum { TILE_PIXELS = 32, diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 9c2d5454..f3f7f05b 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -90,7 +90,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani outfitProgram = PainterShaderProgramPtr(new PainterShaderProgram); outfitProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); outfitProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/outfit.frag"); - assert(outfitProgram->link()); + outfitProgram->link(); outfitProgram->bindUniformLocation(HEAD_COLOR_UNIFORM, "headColor"); outfitProgram->bindUniformLocation(BODY_COLOR_UNIFORM, "bodyColor"); outfitProgram->bindUniformLocation(LEGS_COLOR_UNIFORM, "legsColor"); diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 5d78be27..7b1c15cd 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -407,6 +407,8 @@ void Game::forceWalk(Otc::Direction direction) case Otc::NorthWest: m_protocolGame->sendWalkNorthWest(); break; + default: + break; } } @@ -428,6 +430,8 @@ void Game::turn(Otc::Direction direction) case Otc::West: m_protocolGame->sendTurnWest(); break; + default: + break; } } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 46cf0b90..93f4d5ff 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -166,7 +166,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) itemProgram = PainterShaderProgramPtr(new PainterShaderProgram); itemProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); itemProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/item.frag"); - assert(itemProgram->link()); + itemProgram->link(); //itemProgram->bindUniformLocation(ITEM_ID_UNIFORM, "itemId"); } g_painter.setCustomProgram(itemProgram); diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index 0658f686..30745ac8 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -84,8 +84,6 @@ bool LocalPlayer::canWalk(Otc::Direction direction) void LocalPlayer::walk(const Position& oldPos, const Position& newPos) { - Otc::Direction direction = oldPos.getDirectionFromPosition(newPos); - // a prewalk was going on if(m_preWalking) { // switch to normal walking diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index fb19b669..c9ec08b2 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -47,7 +47,7 @@ MapView::MapView() m_shaderProgram = PainterShaderProgramPtr(new PainterShaderProgram); m_shaderProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); m_shaderProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/map.frag"); - assert(m_shaderProgram->link()); + m_shaderProgram->link(); } void MapView::draw(const Rect& rect) @@ -117,7 +117,7 @@ void MapView::draw(const Rect& rect) float horizontalStretchFactor = rect.width() / (float)(m_visibleDimension.width() * m_tileSize); float verticalStretchFactor = rect.height() / (float)(m_visibleDimension.height() * m_tileSize); - Size tileStretchedSize = Size(m_tileSize * horizontalStretchFactor, m_tileSize * verticalStretchFactor); + //Size tileStretchedSize = Size(m_tileSize * horizontalStretchFactor, m_tileSize * verticalStretchFactor); // avoid drawing texts on map in far zoom outs if(m_viewRange == NEAR_VIEW) { diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 5716375f..48b6f8b7 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -57,7 +57,7 @@ void SpriteManager::unload() void SpriteManager::preloadSprites() { - // preload every 100 sprites, periodically + // preload every 50 sprites, periodically const int burst = 50; const int interval = 10; auto preload = [this](int start) { @@ -138,7 +138,7 @@ TexturePtr SpriteManager::loadSpriteTexture(int id) return spriteTex; } -TexturePtr SpriteManager::getSpriteTexture(int id) +TexturePtr& SpriteManager::getSpriteTexture(int id) { if(id == 0) return g_graphics.getEmptyTexture(); diff --git a/src/otclient/core/spritemanager.h b/src/otclient/core/spritemanager.h index 63aca0a6..da0b1d40 100644 --- a/src/otclient/core/spritemanager.h +++ b/src/otclient/core/spritemanager.h @@ -38,7 +38,7 @@ public: uint32 getSignature() { return m_signature; } int getSpritesCount() { return m_spritesCount; } - TexturePtr getSpriteTexture(int id); + TexturePtr& getSpriteTexture(int id); bool isLoaded() { return m_loaded; } private: diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index ef493d1e..7b487d02 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include @@ -309,8 +308,4 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getTile", &UIMap::getTile); g_lua.bindClassMemberFunction("zoomIn", &UIMap::zoomIn); g_lua.bindClassMemberFunction("zoomOut", &UIMap::zoomOut); - - g_lua.registerClass(); - g_lua.bindClassStaticFunction("create", []{ return UIGamePtr(new UIGame); } ); - } diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index 5cc0947d..9120481d 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -31,26 +31,26 @@ namespace Proto { #ifdef CIPSOFT_RSA - static const char* RSA = "1321277432058722840622950990822933849527763264961655079678763618" - "4334395343554449668205332383339435179772895415509701210392836078" - "6959821132214473291575712138800495033169914814069637740318278150" - "2907336840325241747827401343576296990629870233111328210165697754" - "88792221429527047321331896351555606801473202394175817"; + constexpr const char* RSA = "1321277432058722840622950990822933849527763264961655079678763618" + "4334395343554449668205332383339435179772895415509701210392836078" + "6959821132214473291575712138800495033169914814069637740318278150" + "2907336840325241747827401343576296990629870233111328210165697754" + "88792221429527047321331896351555606801473202394175817"; #else - static const char* RSA = "1091201329673994292788609605089955415282375029027981291234687579" - "3726629149257644633073969600111060390723088861007265581882535850" - "3429057592827629436413108566029093628212635953836686562675849720" - "6207862794310902180176810615217550567108238764764442605581471797" - "07119674283982419152118103759076030616683978566631413"; + constexpr const char* RSA = "1091201329673994292788609605089955415282375029027981291234687579" + "3726629149257644633073969600111060390723088861007265581882535850" + "3429057592827629436413108566029093628212635953836686562675849720" + "6207862794310902180176810615217550567108238764764442605581471797" + "07119674283982419152118103759076030616683978566631413"; #endif - static const int ClientVersion = PROTOCOL; - static const int PicSignature = 0x4E119CBF; + constexpr int ClientVersion = PROTOCOL; + constexpr int PicSignature = 0x4E119CBF; #if PROTOCOL==860 - const int NumViolationReasons = 20; + constexpr int NumViolationReasons = 20; #elif PROTOCOL==861 || PROTOCOL==862 - const int NumViolationReasons = 19; + constexpr int NumViolationReasons = 19; #endif enum OsTypes { diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index a6ff82dd..2e5b1da0 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -43,8 +43,7 @@ void OTClient::init(const std::vector& args) g_modules.ensureModuleLoaded("core_lib"); // client modules 100-499 g_modules.autoLoadModules(499); - g_modules.ensureModuleLoaded("client_main"); - g_modules.ensureModuleLoaded("client_tibiafiles"); + g_modules.ensureModuleLoaded("client"); // game modules 500-999 g_modules.autoLoadModules(999); g_modules.ensureModuleLoaded("game"); diff --git a/src/otclient/util/position.h b/src/otclient/util/position.h index 67bf8178..30335dd2 100644 --- a/src/otclient/util/position.h +++ b/src/otclient/util/position.h @@ -64,6 +64,8 @@ public: pos.x--; pos.y--; break; + default: + break; } return pos; } @@ -99,6 +101,8 @@ public: pos.x++; pos.y++; break; + default: + break; } return pos; }