mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
save window position and size
This commit is contained in:
14
modules/addon_mapeffects/mapeffects.lua
Normal file
14
modules/addon_mapeffects/mapeffects.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
MapEffects = {}
|
||||
|
||||
function MapEffects.init()
|
||||
local box = createWidget('ComboBox')
|
||||
box:moveTo({x=100, y=8})
|
||||
box:addOption('Normal')
|
||||
box:addOption('Bloom')
|
||||
box:addOption('TV')
|
||||
--displayUI(box)
|
||||
end
|
||||
|
||||
function MapEffects.terminate()
|
||||
|
||||
end
|
16
modules/addon_mapeffects/mapeffects.otmod
Normal file
16
modules/addon_mapeffects/mapeffects.otmod
Normal file
@@ -0,0 +1,16 @@
|
||||
Module
|
||||
name: mapeffects
|
||||
description: Contains experimental shader effects for map
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
// console can be loaded after core
|
||||
autoLoad: true
|
||||
autoLoadPriority: 1000
|
||||
|
||||
onLoad: |
|
||||
require 'mapeffects'
|
||||
MapEffects.init()
|
||||
|
||||
onUnload: |
|
||||
MapEffects.terminate()
|
@@ -2,6 +2,7 @@ Client = {}
|
||||
|
||||
-- TODO: load and save configurations
|
||||
function Client.init()
|
||||
-- set default settings
|
||||
g_window.show()
|
||||
g_window.setMinimumSize({ width = 550, height = 450 })
|
||||
|
||||
@@ -9,14 +10,21 @@ function Client.init()
|
||||
if g_window.getPlatformType() == "X11-EGL" then
|
||||
g_window.setFullscreen(true)
|
||||
else
|
||||
local size = { width = 1024,
|
||||
height = 768 }
|
||||
-- window size
|
||||
local size = { width = 800, height = 600 }
|
||||
size = Settings.getSize('window-size', size)
|
||||
g_window.resize(size)
|
||||
|
||||
-- window position, default is the screen center
|
||||
local displaySize = g_window.getDisplaySize()
|
||||
local pos = { x = (displaySize.width - size.width)/2,
|
||||
y = (displaySize.height - size.height)/2 }
|
||||
pos = Settings.getPoint('window-pos', size)
|
||||
g_window.move(pos)
|
||||
|
||||
-- window maximized?
|
||||
local maximized = Settings.getBoolean('window-maximized', false)
|
||||
if maximized then g_window.maximize() end
|
||||
end
|
||||
|
||||
g_window.setTitle('OTClient')
|
||||
@@ -28,4 +36,7 @@ function Client.init()
|
||||
end
|
||||
|
||||
function Client.terminate()
|
||||
Settings.set('window-size', g_window.getUnmaximizedSize())
|
||||
Settings.set('window-pos', g_window.getUnmaximizedPos())
|
||||
Settings.set('window-maximized', g_window.isMaximized())
|
||||
end
|
||||
|
@@ -78,10 +78,7 @@ MainWindow
|
||||
margin-top: 10
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
@onCheckChange: |
|
||||
function(self, checked)
|
||||
self:getParent():getChildById('autoLoginBox'):setEnabled(checked)
|
||||
end
|
||||
@onCheckChange: self:getParent():getChildById('autoLoginBox'):setEnabled(self:isChecked())
|
||||
|
||||
CheckBox
|
||||
id: autoLoginBox
|
||||
|
@@ -1,72 +1,34 @@
|
||||
Options = {}
|
||||
|
||||
-- private variables
|
||||
local options
|
||||
local fpsEnabled = false
|
||||
local vsyncEnabled = false
|
||||
|
||||
function getConfig(name, default)
|
||||
if g_configs.exists(name) then
|
||||
local val = g_configs.get(name):trim()
|
||||
if val == 'true' or val == 'false' then
|
||||
return toboolean(val)
|
||||
else
|
||||
return val
|
||||
end
|
||||
else
|
||||
if default ~= nil then
|
||||
g_configs.set(name, default)
|
||||
return default
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setConfig(name, value)
|
||||
g_configs.set(name, tostring(value))
|
||||
end
|
||||
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
vsyncEnabled = on
|
||||
g_window.setVerticalSync(on)
|
||||
setConfig('vsync', on)
|
||||
end
|
||||
|
||||
function Options.enableFps(on)
|
||||
fpsEnabled = on
|
||||
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
|
||||
frameCounter:setVisible(on)
|
||||
setConfig('showfps', on)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Options.create()
|
||||
options = displayUI('options.otui', { locked = true })
|
||||
|
||||
local fpsBox = options:getChildById('fpsCheckBox')
|
||||
local vsyncBox = options:getChildById('vsyncCheckBox')
|
||||
|
||||
fpsBox:setChecked(fpsEnabled)
|
||||
vsyncBox:setChecked(vsyncEnabled)
|
||||
|
||||
fpsBox.onCheckChange = function(self, checked) Options.enableFps(checked) end
|
||||
vsyncBox.onCheckChange = function(self, checked) Options.enableVsync(checked) end
|
||||
end
|
||||
|
||||
function Options.load()
|
||||
Options.enableVsync(getConfig('vsync', true))
|
||||
Options.enableFps(getConfig('showfps', true))
|
||||
-- set default settings
|
||||
Settings.setDefault('vsync', true)
|
||||
Settings.setDefault('showfps', true)
|
||||
|
||||
-- load the options
|
||||
Options.enableVsync(Settings.getBoolean('vsync'))
|
||||
Options.enableFps(Settings.getBoolean('showfps'))
|
||||
end
|
||||
|
||||
function Options.destroy()
|
||||
options:destroy()
|
||||
options = nil
|
||||
function Options.show()
|
||||
displayUI('options.otui', { locked = true })
|
||||
end
|
||||
|
||||
function Options.openWebpage()
|
||||
displayErrorBox("Error", "Not implemented yet")
|
||||
end
|
||||
|
||||
addEvent(Options.load)
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
g_window.setVerticalSync(on)
|
||||
Settings.set('vsync', on)
|
||||
Options.vsync = on
|
||||
end
|
||||
|
||||
function Options.enableFps(on)
|
||||
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
|
||||
frameCounter:setVisible(on)
|
||||
Settings.set('showfps', on)
|
||||
Options.fps = on
|
||||
end
|
||||
|
@@ -6,3 +6,5 @@ Module
|
||||
|
||||
onLoad: |
|
||||
require 'options'
|
||||
Options.load()
|
||||
|
||||
|
@@ -13,6 +13,8 @@ MainWindow
|
||||
margin-top: 28
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
@onCheckChange: Options.enableVsync(self:isChecked())
|
||||
@onSetup: self:setChecked(Options.vsync)
|
||||
|
||||
CheckBox
|
||||
id: fpsCheckBox
|
||||
@@ -23,6 +25,8 @@ MainWindow
|
||||
margin-top: 10
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
@onCheckChange: Options.enableFps(self:isChecked())
|
||||
@onSetup: self:setChecked(Options.fps)
|
||||
|
||||
Button
|
||||
text: Ok
|
||||
@@ -31,4 +35,4 @@ MainWindow
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 10
|
||||
margin-bottom: 10
|
||||
@onClick: Options.destroy()
|
||||
@onClick: self:getParent():destroy()
|
@@ -13,7 +13,7 @@ TopPanel
|
||||
margin-left: 6
|
||||
tooltip: Options
|
||||
icon: /core_styles/icons/settings.png
|
||||
@onClick: Options.create()
|
||||
@onClick: Options.show()
|
||||
|
||||
|
||||
TopButton
|
||||
|
@@ -15,6 +15,5 @@ Module
|
||||
require 'util'
|
||||
require 'globals'
|
||||
require 'dispatcher'
|
||||
require 'widget'
|
||||
require 'effects'
|
||||
require 'settings'
|
||||
|
@@ -2,6 +2,7 @@ local eventId = 0
|
||||
local eventList = {}
|
||||
|
||||
function scheduleEvent(func, delay)
|
||||
if not func then return end
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
|
79
modules/core_lib/settings.lua
Normal file
79
modules/core_lib/settings.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
Settings = {}
|
||||
|
||||
local function convertSettingValue(value)
|
||||
if type(value) == 'table' then
|
||||
if value.x and value.width then
|
||||
return recttostring(value)
|
||||
elseif value.x then
|
||||
return pointtostring(value)
|
||||
elseif value.width then
|
||||
return sizetostring(value)
|
||||
elseif value.r then
|
||||
return colortostring(value)
|
||||
end
|
||||
else
|
||||
return tostring(value)
|
||||
end
|
||||
end
|
||||
|
||||
function Settings.exists(key)
|
||||
return g_configs.exists(key)
|
||||
end
|
||||
|
||||
function Settings.remove(key)
|
||||
g_configs.remove(key)
|
||||
end
|
||||
|
||||
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)
|
||||
return true
|
||||
end
|
||||
|
||||
function Settings.get(key, default)
|
||||
if Settings.exists(key) then
|
||||
elseif default ~= nil then
|
||||
Settings.set(key, default)
|
||||
end
|
||||
return g_configs.get(key)
|
||||
end
|
||||
|
||||
function Settings.getString(key, default)
|
||||
return Settings.get(key, default)
|
||||
end
|
||||
|
||||
function Settings.getInteger(key, default)
|
||||
return tonumber(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getNumber(key, default)
|
||||
return tonumber(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getBoolean(key, default)
|
||||
return toboolean(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getPoint(key, default)
|
||||
return topoint(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getRect(key, default)
|
||||
return torect(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getSize(key, default)
|
||||
return tosize(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getColor(key, default)
|
||||
return tocolor(Settings.get(key, default))
|
||||
end
|
||||
|
||||
function Settings.getColor(key, default)
|
||||
return tocolor(Settings.get(key, default))
|
||||
end
|
@@ -7,6 +7,7 @@ Module
|
||||
onLoad: |
|
||||
require 'tooltip/tooltip'
|
||||
require 'messagebox/messagebox'
|
||||
require 'uiwidget'
|
||||
require 'uibutton'
|
||||
require 'uilabel'
|
||||
require 'uicombobox'
|
||||
|
@@ -45,7 +45,7 @@ function UIPopupMenu:onDestroy()
|
||||
end
|
||||
|
||||
function UIPopupMenu:onMousePress(mousePos, mouseButton)
|
||||
-- clicks outside self area destroys the self
|
||||
-- clicks outside menu area destroys the menu
|
||||
if not self:containsPoint(mousePos) then
|
||||
self:destroy()
|
||||
return true
|
||||
@@ -61,11 +61,10 @@ function UIPopupMenu:onKeyPress(keyCode, keyText, keyboardModifiers)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onRootGeometryUpdate()
|
||||
-- close all menus when the window is resized
|
||||
local function onRootGeometryUpdate()
|
||||
for i,menu in ipairs(displayedMenuList) do
|
||||
menu:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
connect(rootWidget, { onGeometryChange = onRootGeometryUpdate} )
|
||||
|
@@ -19,7 +19,7 @@ end
|
||||
|
||||
local function setSkillValue(id, value)
|
||||
local skill = skillWindow:recursiveGetChildById(id)
|
||||
|
||||
|
||||
if skill then
|
||||
local widget = skill:getChildById('value')
|
||||
widget:setText(value)
|
||||
@@ -28,11 +28,11 @@ end
|
||||
|
||||
local function setSkillPercent(id, percent, tooltip)
|
||||
local skill = skillWindow:recursiveGetChildById(id)
|
||||
|
||||
|
||||
if skill then
|
||||
local widget = skill:getChildById('percent')
|
||||
widget:setPercent(percent)
|
||||
|
||||
|
||||
if tooltip then
|
||||
widget:setTooltip(tooltip)
|
||||
end
|
||||
@@ -49,6 +49,19 @@ function Skills.destroy()
|
||||
skillWindow = nil
|
||||
end
|
||||
|
||||
function Skills.onSkillButtonClick(button)
|
||||
local percentBar = button:getChildById('percent')
|
||||
if percentBar then
|
||||
percentBar:setVisible(not percentBar:isVisible())
|
||||
if percentBar:isVisible() then
|
||||
button:setHeight(21)
|
||||
else
|
||||
button:setHeight(21 - 6)
|
||||
end
|
||||
button:updateParentLayout()
|
||||
end
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Skills.onExperienceChange(value)
|
||||
setSkillValue('experience', getNumberString(value))
|
||||
@@ -82,7 +95,7 @@ function Skills.onStaminaChange(stamina)
|
||||
minutes = '0' .. minutes
|
||||
end
|
||||
local percent = 100 * stamina / (42 * 60) -- max is 42 hours
|
||||
|
||||
|
||||
setSkillValue('stamina', hours .. ":" .. minutes)
|
||||
setSkillPercent('stamina', percent, 'You have ' .. percent .. ' percent')
|
||||
end
|
||||
|
@@ -5,20 +5,7 @@ SkillButton < UIButton
|
||||
margin-top: 3
|
||||
margin-left: 10
|
||||
margin-right: 10
|
||||
|
||||
@onClick: |
|
||||
function(self)
|
||||
local percentBar = self:getChildById('percent')
|
||||
if percentBar then
|
||||
percentBar:setVisible(not percentBar:isVisible())
|
||||
if percentBar:isVisible() then
|
||||
self:setHeight(21)
|
||||
else
|
||||
self:setHeight(21 - 6)
|
||||
end
|
||||
self:updateParentLayout()
|
||||
end
|
||||
end
|
||||
&onClick: Skills.onSkillButtonClick
|
||||
|
||||
SkillNameLabel < GameLabel
|
||||
font: verdana-11px-monochrome
|
||||
|
Reference in New Issue
Block a user