Skip to content

Commit 6e2c568

Browse files
fix: opentibiabr#1501 Mouse Control Mode save (opentibiabr#1503)
1 parent 285a906 commit 6e2c568

File tree

2 files changed

+56
-94
lines changed

2 files changed

+56
-94
lines changed

modules/client_options/data_options.lua

Lines changed: 56 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,29 @@ return {
2727
value = g_platform.isMobile() and true or false,
2828
action = function(value, options, controller, panels, extraWidgets)
2929
-- Update the mouseControlMode based on this option
30+
-- 0 = Regular Controls, 1 = Classic Controls, 2 = Left Smart-Click
3031
local mouseControlMode = 0
3132
if value == true then
32-
mouseControlMode = 1
33-
-- Update settings directly to ensure persistence
34-
g_settings.set('mouseControlMode', mouseControlMode)
35-
options.mouseControlMode.value = mouseControlMode
36-
37-
-- Update loot control visibility
38-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
39-
if lootControlModeCombobox then
40-
lootControlModeCombobox:setVisible(true)
41-
end
33+
mouseControlMode = 1 -- Classic Controls
4234
elseif options.smartLeftClick.value == true then
43-
mouseControlMode = 2
44-
-- Update settings directly to ensure persistence
45-
g_settings.set('mouseControlMode', mouseControlMode)
46-
options.mouseControlMode.value = mouseControlMode
47-
48-
-- Update loot control visibility
49-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
50-
if lootControlModeCombobox then
51-
lootControlModeCombobox:setVisible(false)
52-
end
35+
mouseControlMode = 2 -- Left Smart-Click
5336
else
54-
mouseControlMode = 0
55-
-- Update settings directly to ensure persistence
56-
g_settings.set('mouseControlMode', mouseControlMode)
57-
options.mouseControlMode.value = mouseControlMode
58-
59-
-- Update loot control visibility
60-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
61-
if lootControlModeCombobox then
62-
lootControlModeCombobox:setVisible(false)
63-
end
37+
mouseControlMode = 0 -- Regular Controls
38+
end
39+
40+
-- Update the value in options table first
41+
options.mouseControlMode.value = mouseControlMode
42+
43+
-- Then update settings
44+
g_settings.set('mouseControlMode', mouseControlMode)
45+
46+
-- Update loot control visibility (only visible for Classic Controls)
47+
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
48+
if lootControlModeCombobox then
49+
lootControlModeCombobox:setVisible(mouseControlMode == 1)
6450
end
6551

52+
-- Update the combobox UI
6653
local mouseControlModeCombobox = panels.generalPanel:recursiveGetChildById('mouseControlMode')
6754
if mouseControlModeCombobox then
6855
mouseControlModeCombobox:setCurrentOption(mouseControlMode, true)
@@ -73,42 +60,29 @@ return {
7360
value = false,
7461
action = function(value, options, controller, panels, extraWidgets)
7562
-- Update the mouseControlMode based on this option
63+
-- 0 = Regular Controls, 1 = Classic Controls, 2 = Left Smart-Click
7664
local mouseControlMode = 0
7765
if options.classicControl.value == true then
78-
mouseControlMode = 1
79-
-- Update settings directly to ensure persistence
80-
g_settings.set('mouseControlMode', mouseControlMode)
81-
options.mouseControlMode.value = mouseControlMode
82-
83-
-- Update loot control visibility
84-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
85-
if lootControlModeCombobox then
86-
lootControlModeCombobox:setVisible(true)
87-
end
66+
mouseControlMode = 1 -- Classic Controls
8867
elseif value == true then
89-
mouseControlMode = 2
90-
-- Update settings directly to ensure persistence
91-
g_settings.set('mouseControlMode', mouseControlMode)
92-
options.mouseControlMode.value = mouseControlMode
93-
94-
-- Update loot control visibility
95-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
96-
if lootControlModeCombobox then
97-
lootControlModeCombobox:setVisible(false)
98-
end
68+
mouseControlMode = 2 -- Left Smart-Click
9969
else
100-
mouseControlMode = 0
101-
-- Update settings directly to ensure persistence
102-
g_settings.set('mouseControlMode', mouseControlMode)
103-
options.mouseControlMode.value = mouseControlMode
104-
105-
-- Update loot control visibility
106-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
107-
if lootControlModeCombobox then
108-
lootControlModeCombobox:setVisible(false)
109-
end
70+
mouseControlMode = 0 -- Regular Controls
71+
end
72+
73+
-- Update the value in options table first
74+
options.mouseControlMode.value = mouseControlMode
75+
76+
-- Then update settings
77+
g_settings.set('mouseControlMode', mouseControlMode)
78+
79+
-- Update loot control visibility (only visible for Classic Controls)
80+
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
81+
if lootControlModeCombobox then
82+
lootControlModeCombobox:setVisible(mouseControlMode == 1)
11083
end
11184

85+
-- Update the combobox UI
11286
local mouseControlModeCombobox = panels.generalPanel:recursiveGetChildById('mouseControlMode')
11387
if mouseControlModeCombobox then
11488
mouseControlModeCombobox:setCurrentOption(mouseControlMode, true)
@@ -118,32 +92,8 @@ return {
11892
mouseControlMode = {
11993
value = 0, -- Default to "Regular Controls"
12094
action = function(value, options, controller, panels, extraWidgets)
121-
-- We need a small delay to ensure the UI updates correctly
122-
scheduleEvent(function()
123-
-- Update the mouseControlMode combobox - get it fresh each time
124-
local mouseControlModeCombobox = panels.generalPanel:recursiveGetChildById('mouseControlMode')
125-
if mouseControlModeCombobox then
126-
-- Force the combobox to select the right option
127-
for i = 0, 2 do
128-
if i == value then
129-
mouseControlModeCombobox:setCurrentOptionByData(i)
130-
break
131-
end
132-
end
133-
end
134-
135-
-- Update loot control mode visibility based on selection
136-
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
137-
if lootControlModeCombobox then
138-
if value == 1 then
139-
lootControlModeCombobox:setVisible(true)
140-
else
141-
lootControlModeCombobox:setVisible(false)
142-
end
143-
end
144-
end, 50)
145-
146-
-- Also update the underlying options
95+
-- Update the underlying options values first
96+
-- 0 = Regular Controls, 1 = Classic Controls, 2 = Left Smart-Click
14797
if value == 0 then
14898
options.classicControl.value = false
14999
options.smartLeftClick.value = false
@@ -161,8 +111,26 @@ return {
161111
g_settings.set('smartLeftClick', true)
162112
end
163113

164-
-- Force save
165-
g_settings.save()
114+
-- Schedule UI updates to ensure they happen after value updates
115+
scheduleEvent(function()
116+
-- Update the mouseControlMode combobox
117+
local mouseControlModeCombobox = panels.generalPanel:recursiveGetChildById('mouseControlMode')
118+
if mouseControlModeCombobox then
119+
-- Force the combobox to select the right option
120+
for i = 0, 2 do
121+
if i == value then
122+
mouseControlModeCombobox:setCurrentOptionByData(i)
123+
break
124+
end
125+
end
126+
end
127+
128+
-- Update loot control mode visibility (only visible for Classic Controls)
129+
local lootControlModeCombobox = panels.generalPanel:recursiveGetChildById('lootControlMode')
130+
if lootControlModeCombobox then
131+
lootControlModeCombobox:setVisible(value == 1)
132+
end
133+
end, 50)
166134
end
167135
},
168136
lootControlMode = {
@@ -182,9 +150,6 @@ return {
182150
end
183151
end
184152
end, 50)
185-
186-
-- Force save
187-
g_settings.save()
188153
end
189154
},
190155
smartWalk = false,

modules/client_options/options.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ local function setup()
262262
end
263263
end
264264
end, 100)
265-
266-
-- Ensure settings are saved
267-
g_settings.save()
268265
end
269266

270267

0 commit comments

Comments
 (0)