-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.lua
261 lines (246 loc) · 8.06 KB
/
settings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
dofile("data/scripts/lib/mod_settings.lua")
function mod_setting_bool_custom( mod_id, gui, in_main_menu, im_id, setting )
local value = ModSettingGetNextValue( mod_setting_get_id(mod_id,setting) )
local text = setting.ui_name .. " - " .. GameTextGet( value and "$option_on" or "$option_off" )
if GuiButton( gui, im_id, mod_setting_group_x_offset, 0, text ) then
ModSettingSetNextValue( mod_setting_get_id(mod_id,setting), not value, false )
end
mod_setting_tooltip( mod_id, gui, in_main_menu, setting )
end
function mod_setting_change_callback(mod_id, gui, in_main_menu, setting, old_value, new_value)
print(tostring(new_value))
end
local csv = dofile_once("mods/wand_editor/files/libs/csv.lua")
local currentLang = csv(ModTextFileGetContent("mods/wand_editor/files/lang/lang.csv"))
local gameLang = csv(ModTextFileGetContent("data/translations/common.csv"))
local CurrentMap = {}
for v,_ in pairs(gameLang.rowHeads) do--构建一个关联表用来查询键值
if v ~= "" then
local tempKey = gameLang.get("current_language",v)
CurrentMap[tempKey] = v
end
end
local function GetText(key) --获取文本
if key == "" then
return key
end
local GameKey
local GameTextLangGet = GameTextGet("$current_language")
GameKey = CurrentMap[GameTextLangGet]
if GameKey == nil then
GameKey = "en"
end
local result = currentLang.get(key, GameKey) or ""
result = string.gsub(result, [[\n]], "\n")
if result == nil or result == "" then
result = currentLang.get(key, "en")
end
return result
end
---监听访问
---@param t table
---@param callback function
local function TableListener(t, callback)
local function NewListener()
local __data = {}
local deleteList = {}
for k, v in pairs(t) do
__data[k] = v
deleteList[#deleteList + 1] = k
end
for _, v in pairs(deleteList) do
t[v] = nil
end
local result = {
__newindex = function(table, key, value)
local temp = callback(key, value)
value = temp or value
rawset(__data, key, value)
rawset(table, key, nil)
end,
__index = function(table, key)
local temp = callback(key, rawget(__data, key))
if temp == nil then
return rawget(__data, key)
else
return temp
end
end,
__call = function()
return __data
end
}
return result
end
setmetatable(t, NewListener())
end
local function Setting(t)
TableListener(t, function(key, value)
if key == "ui_name" or key == "ui_description" then
local result = GetText(value)
return result
end
end)
return t
end
local function GetTextOrKey(key)
local result = GetText(key)
return result or key
end
local function ValueListInit(t)
TableListener(t, function(key, value)
return GetTextOrKey(value)
end)
return t
end
local function ValueList(t)
for k,v in pairs(t)do
t[k] = ValueListInit(v)
end
return t
end
local IKnowWhatImDoing_wand_editor_reset_btn_pos = false
local mod_id = "wand_editor"
local ModID = mod_id
mod_settings_version = 1
mod_settings =
{
Setting({
id = "auto_update",
ui_name = "wand_editor_auto_update",
ui_description = "wand_editor_auto_update_tips",
value_default = false,
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "spell_mod_id_or_name",
ui_name = "wand_editor_spell_mod_id_or_name",
value_default = "name",
values = ValueList({
{ "name", "wand_editor_spell_mod_id_or_name_only_name" },
{ "id", "wand_editor_spell_mod_id_or_name_only_id" },
{ "all", "wand_editor_spell_mod_id_or_name_all" },
}),
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "cache_spell_data",
ui_name = "wand_editor_no_spell_cache",
ui_description = "wand_editor_no_spell_cache_tip",
value_default = true,
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "locked_target_pos",
ui_name = "wand_editor_locked_target_pos",
ui_description = "wand_editor_locked_target_pos_tip",
value_default = true,
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "split_search_text",
ui_name = "wand_editor_split_search_text",
ui_description = "wand_editor_split_search_text_tip",
value_default = false,
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "real_unlimited_spells",
ui_name = "wand_editor_real_unlimited_spells",
ui_description = "wand_editor_real_unlimited_spells_tips",
value_default = false,
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART,
}),
Setting({
id = "remove_fog_of_war",
ui_name = "wand_editor_remove_fog_of_war",
ui_description = "wand_editor_remove_fog_of_war_tip",
value_default = false,
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART,
}),
Setting({
id = "reset_all_btn_in_setting",
ui_name = "",
ui_description = "",
ui_fn = function(mod_id, gui, in_main_menu, im_id, setting)
GuiIdPushString(gui,"wand_editor")
local click = GuiButton(gui, 1, 0, 0, GetTextOrKey("wand_editor_reset_btn_pos"))
local _, _, hover = GuiGetPreviousWidgetInfo(gui)
if not hover and IKnowWhatImDoing_wand_editor_reset_btn_pos then
IKnowWhatImDoing_wand_editor_reset_btn_pos = false
end
if click and not ModSettingGet("wand_editor.reset_all_btn") and not IKnowWhatImDoing_wand_editor_reset_btn_pos then
IKnowWhatImDoing_wand_editor_reset_btn_pos = true
elseif click and IKnowWhatImDoing_wand_editor_reset_btn_pos then
ModSettingSet("wand_editor.reset_all_btn", true)
IKnowWhatImDoing_wand_editor_reset_btn_pos = false
end
if IKnowWhatImDoing_wand_editor_reset_btn_pos then
GuiTooltip(gui,GetTextOrKey("wand_editor_reset_btn_pos_IKnowWhatImDoing"),"")
else
GuiTooltip(gui,GetTextOrKey("wand_editor_reset_btn_pos_tip"),"")
end
GuiIdPop(gui)
end
}),
Setting({
category_id = "load_other_wand_box_btns",
ui_name = "wand_editor_load_other_wand_box",
ui_description = "",
foldable = true,
settings = {
Setting({
id = "load_spell_lab",
ui_name = "",
ui_description = "",
ui_fn = function(mod_id, gui, in_main_menu, im_id, setting)
GuiIdPushString(gui,"wand_editor")
local click = GuiButton(gui, 2, 0, 0, GetTextOrKey("wand_editor_load_spell_lab_wand_box"))
GuiTooltip(gui,GetTextOrKey("wand_editor_load_spell_lab_wand_box_tip"),"")
if click then
ModSettingSet(ModID.."LoadSpellLab", true)
end
GuiIdPop(gui)
end,
}),
Setting({
id = "load_wands_conn",
ui_name = "",
ui_description = "",
ui_fn = function(mod_id, gui, in_main_menu, im_id, setting)
GuiIdPushString(gui, "wand_editor")
local click = GuiButton(gui, 3, 0, 0, GetTextOrKey("wand_editor_load_wands_conn_wand_box"))
GuiTooltip(gui, GetTextOrKey("wand_editor_load_wands_conn_wand_box_tip"), "")
if click then
ModSettingSet(ModID.."LoadECSSpellLab", true)
end
GuiIdPop(gui)
end,
}),
Setting({
id = "load_spell_lab_shug",
ui_name = "",
ui_description = "",
ui_fn = function(mod_id, gui, in_main_menu, im_id, setting)
GuiIdPushString(gui,"wand_editor")
local click = GuiButton(gui, 4, 0, 0, GetTextOrKey("wand_editor_load_spell_lab_shug_wand_box"))
GuiTooltip(gui, GetTextOrKey("wand_editor_load_spell_lab_shug_wand_box_tip"), "")
if click then
ModSettingSet(ModID.."LoadSpellLabShug", true)
end
GuiIdPop(gui)
end,
})
}
}),
}
function ModSettingsUpdate( init_scope )
local old_version = mod_settings_get_version( mod_id )
mod_settings_update( mod_id, mod_settings, init_scope )
end
function ModSettingsGuiCount()
return mod_settings_gui_count( mod_id, mod_settings )
end
function ModSettingsGui( gui, in_main_menu )
mod_settings_gui( mod_id, mod_settings, gui, in_main_menu )
end