-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
166 lines (151 loc) · 4.66 KB
/
settings.lua
File metadata and controls
166 lines (151 loc) · 4.66 KB
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
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/CustomFont/files/lib/csv.lua")
local currentLang = csv(ModTextFileGetContent("mods/CustomFont/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 = "CustomFont"
local ModID = mod_id
mod_settings_version = 1
mod_settings =
{
Setting({
id = "font_preview_render",
ui_name = "custom_font_font_preview_render",
value_default = "hover",
values = ValueList({
{ "no", "custom_font_font_no" },
{ "hover", "custom_font_font_hover" },
{ "hover_shift", "custom_font_font_hover_shift" },
}),
scope = MOD_SETTING_SCOPE_RUNTIME,
}),
Setting({
id = "disable_font",
ui_name = "custom_font_disable_font",
ui_description = "custom_font_disable_font_tips",
value_default = false,
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART,
}),
Setting({
id = "disable_font_and_clear",
ui_name = "",
ui_description = "",
value_default = false,
ui_fn = function(mod_id, gui, in_main_menu, im_id, setting)
GuiIdPushString(gui,"CustomFont_disable_font_and_clear")
local click = GuiButton(gui, 1, 0, 0, GetText("custom_font_disable_and_clear_font"))
GuiTooltip(gui,GetText("custom_font_disable_and_clear_font_tips"), "")
if click then
ModSettingSet(ModID .. "DisableFontAndClear", 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