-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodmain.lua
More file actions
377 lines (351 loc) · 14.4 KB
/
modmain.lua
File metadata and controls
377 lines (351 loc) · 14.4 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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
_G = GLOBAL
rawget = _G.rawget
tonumber = _G.tonumber
tostring = _G.tostring
TheSim = _G.TheSim
require = _G.require
STRINGS = _G.STRINGS
IsDST = _G.MOD_API_VERSION == 10
Thai = {
SelectedLanguage = "th",
StringUITable = {},
}
modimport("scripts/utility.lua")
if GetModConfigData("DISABLE_MOD_WARNING") then
_G.DISABLE_MOD_WARNING = true
end
Config = {
UI = GetModConfigData("CFG_UI"),
CON = GetModConfigData("CFG_CON"),
ITEM = GetModConfigData("CFG_ITEM"),
ITEM_TWO = GetModConfigData("CFG_ITEM_TWO"),
CON_ITEM = GetModConfigData("CFG_CON_ITEM"),
OTHER_MOD = GetModConfigData("CFG_OTHER_MOD"),
}
--โหลดฟอนต์
local function applyLocalizedFonts()
-- List of font assets file
local fontAssetsList = {
["kodchasan50"] = true,
["kodchasan100"] = true,
["leelawadeeui50"] = true,
["leelawadeeui_small"] = true,
["leelawadeeui50_outline"] = true,
["leelawadeeui_outline_small"] = true,
["dilleniaupc50"] = true,
["dilleniaupc50_outline"] = true,
}
-- Index of game original font to thai custom font
local fontIndex = {
["belisaplumilla100"] = "kodchasan50",
["belisaplumilla50"] = "kodchasan50",
["bellefair50"] = "leelawadeeui50",
["bellefair50_outline"] = "leelawadeeui50_outline",
["buttonfont"] = "kodchasan100",
["hammerhead50"] = "leelawadeeui50",
["opensans50"] = "leelawadeeui50_outline",
["spirequal"] = "leelawadeeui50",
["spirequal_outline"] = "leelawadeeui50_outline",
["spirequal_outline_small"] = "leelawadeeui_outline_small",
["spirequal_small"] = "leelawadeeui_small",
["stint-ucr20"] = "dilleniaupc50_outline",
["stint-ucr50"] = "dilleniaupc50",
["talkingfont"] = "leelawadeeui50_outline",
["talkingfont_hermit"] = "leelawadeeui50_outline",
["talkingfont_tradein"] = "leelawadeeui50_outline",
["talkingfont_wathgrithr"] = "leelawadeeui50_outline",
["talkingfont_wormwood"] = "leelawadeeui50_outline",
}
local fontPrefab = Thai.SelectedLanguage.."_fonts_"..modname
-- Unload thai font and prefab on reloading mod
for fontName, fontUseName in pairs(fontIndex) do
local fontID = Thai.SelectedLanguage.."_"..fontName
TheSim:UnloadFont(fontID)
end
TheSim:UnloadPrefabs({fontPrefab})
-- Loading font file assets
local localFontAssets = {}
for fontName in pairs(fontAssetsList) do
local fontPath = MODROOT.."fonts/"..fontName.."__"..Thai.SelectedLanguage..".zip"
table.insert(localFontAssets, _G.Asset("FONT", fontPath))
end
-- Load thai fonts to engine
local localizedFontsPrefab = _G.Prefab("common/"..fontPrefab, nil, localFontAssets)
_G.RegisterPrefabs(localizedFontsPrefab)
TheSim:LoadPrefabs({fontPrefab})
for fontName, fontUseName in pairs(fontIndex) do
local fontID = Thai.SelectedLanguage.."_"..fontName
local fontPath = MODROOT.."fonts/"..fontUseName.."__"..Thai.SelectedLanguage..".zip"
TheSim:LoadFont(fontPath, fontID)
end
-- Set fallback font for misssing charactor to game original
for _, v in pairs(_G.FONTS) do
local fontName = v.filename:sub(7, -5)
if fontIndex[fontName] then
local fontID = Thai.SelectedLanguage.."_"..fontName
TheSim:SetupFontFallbacks(fontID, {v.alias, _G.unpack(type(v.fallback) == "table" and v.fallback or {})})
end
end
-- Apple font to the engine
if IsTranslateEnabled() then
if rawget(_G, "DEFAULTFONT") then
_G.DEFAULTFONT = Thai.SelectedLanguage.."_".."opensans50"
end
if rawget(_G, "DIALOGFONT") then
_G.DIALOGFONT = Thai.SelectedLanguage.."_".."opensans50"
end
if rawget(_G, "TITLEFONT") then
_G.TITLEFONT = Thai.SelectedLanguage.."_".."belisaplumilla100"
end
if rawget(_G, "UIFONT") then
_G.UIFONT = Thai.SelectedLanguage.."_".."belisaplumilla50"
end
if rawget(_G, "BUTTONFONT") then
_G.BUTTONFONT = Thai.SelectedLanguage.."_".."buttonfont"
end
if rawget(_G, "HEADERFONT") then
_G.HEADERFONT = Thai.SelectedLanguage.."_".."hammerhead50"
end
if rawget(_G, "NUMBERFONT") then
_G.NUMBERFONT = Thai.SelectedLanguage.."_".."stint-ucr50"
end
if rawget(_G, "SMALLNUMBERFONT") then
_G.SMALLNUMBERFONT = Thai.SelectedLanguage.."_".."stint-ucr20"
end
if rawget(_G, "BODYTEXTFONT") then
_G.BODYTEXTFONT = Thai.SelectedLanguage.."_".."stint-ucr50"
end
if rawget(_G, "CHATFONT_OUTLINE") then
_G.CHATFONT_OUTLINE = Thai.SelectedLanguage.."_".."bellefair50_outline"
end
if rawget(_G, "NEWFONT") then
_G.NEWFONT = Thai.SelectedLanguage.."_".."spirequal"
end
if rawget(_G, "NEWFONT_SMALL") then
_G.NEWFONT_SMALL = Thai.SelectedLanguage.."_".."spirequal_small"
end
if rawget(_G, "NEWFONT_OUTLINE") then
_G.NEWFONT_OUTLINE = Thai.SelectedLanguage.."_".."spirequal_outline"
end
if rawget(_G, "NEWFONT_OUTLINE_SMALL") then
_G.NEWFONT_OUTLINE_SMALL = Thai.SelectedLanguage.."_".."spirequal_outline_small"
end
end
if rawget(_G, "CHATFONT") then
_G.CHATFONT = Thai.SelectedLanguage.."_".."bellefair50"
end
if rawget(_G, "TALKINGFONT") then
_G.TALKINGFONT = Thai.SelectedLanguage.."_".."talkingfont"
end
if rawget(_G, "TALKINGFONT_HERMIT") then
_G.TALKINGFONT_HERMIT = Thai.SelectedLanguage.."_".."talkingfont_hermit"
end
if rawget(_G, "TALKINGFONT_TRADEIN") then
_G.TALKINGFONT_TRADEIN = Thai.SelectedLanguage.."_".."talkingfont_tradein"
end
if rawget(_G, "TALKINGFONT_WORMWOOD") then
_G.TALKINGFONT_WORMWOOD = Thai.SelectedLanguage.."_".."talkingfont_wormwood"
end
if rawget(_G, "TALKINGFONT_WATHGRITHR") then
_G.TALKINGFONT_WATHGRITHR = Thai.SelectedLanguage.."_".."talkingfont_wathgrithr"
end
end
-- โหลดฟอนต์ไทย
local OldStart = _G.Start
function _G.Start()
applyLocalizedFonts()
OldStart()
end
_G.getmetatable(TheSim).__index.UnregisterAllPrefabs = (function()
local oldUnregisterAllPrefabs = _G.getmetatable(TheSim).__index.UnregisterAllPrefabs
return function(self, ...)
oldUnregisterAllPrefabs(self, ...)
applyLocalizedFonts()
end
end)()
-- โหลดฟอนต์ในหน้าที่เกมไม่โหลดให้
local oldSetFont = _G.TextWidget.SetFont
_G.TextWidget.SetFont = function(guid, font)
if font == "opensans" then
oldSetFont(guid, _G.DEFAULTFONT)
elseif font == "opensans" then
oldSetFont(guid, _G.DIALOGFONT)
elseif font == "bp100" then
oldSetFont(guid, _G.TITLEFONT)
elseif font == "bp50" then
oldSetFont(guid, _G.UIFONT)
elseif font == "buttonfont" then
oldSetFont(guid, _G.BUTTONFONT)
elseif font == "hammerhead" then
oldSetFont(guid, _G.HEADERFONT)
elseif font == "stint-ucr" then
oldSetFont(guid, _G.NUMBERFONT)
elseif font == "stint-small" then
oldSetFont(guid, _G.SMALLNUMBERFONT)
elseif font == "stint-ucr" then
oldSetFont(guid, _G.BODYTEXTFONT)
elseif font == "bellefair_outline" then
oldSetFont(guid, _G.CHATFONT_OUTLINE)
elseif font == "spirequal" then
oldSetFont(guid, _G.NEWFONT)
elseif font == "spirequal_small" then
oldSetFont(guid, _G.NEWFONT_SMALL)
elseif font == "spirequal_outline" then
oldSetFont(guid, _G.NEWFONT_OUTLINE)
elseif font == "spirequal_outline_small" then
oldSetFont(guid, _G.NEWFONT_OUTLINE_SMALL)
elseif font == "bellefair" then
oldSetFont(guid, _G.CHATFONT)
elseif font == "talkingfont" then
oldSetFont(guid, _G.TALKINGFONT)
elseif font == "talkingfont_hermit" then
oldSetFont(guid, _G.TALKINGFONT_HERMIT)
elseif font == "talkingfont_tradein" then
oldSetFont(guid, _G.TALKINGFONT_TRADEIN)
elseif font == "talkingfont_wormwood" then
oldSetFont(guid, _G.TALKINGFONT_WORMWOOD)
else
oldSetFont(guid, font)
end
end
--------------------------
--โหลดรูปภาพที่แปลภาษาแล้ว
Assets = {
Asset("IMAGE", MODROOT.."images/customisation.tex"),
Asset("ATLAS", MODROOT.."images/customisation.xml"),
Asset("IMAGE", MODROOT.."images/customization_porkland.tex"),
Asset("ATLAS", MODROOT.."images/customization_porkland.xml"),
Asset("IMAGE", MODROOT.."images/customization_shipwrecked.tex"),
Asset("ATLAS", MODROOT.."images/customization_shipwrecked.xml"),
Asset("IMAGE", MODROOT.."images/eyebutton.tex"),
Asset("ATLAS", MODROOT.."images/eyebutton.xml"),
Asset("IMAGE", MODROOT.."images/gradient.tex"),
Asset("ATLAS", MODROOT.."images/gradient.xml"),
Asset("IMAGE", MODROOT.."images/upgradepanels.tex"),
Asset("ATLAS", MODROOT.."images/upgradepanels.xml")
}
--โหลดไฟล์ภาษา
if IsTranslateEnabled() then
LoadPOFile("scripts/languages/thai.po", Thai.SelectedLanguage)
Thai.PO = _G.LanguageTranslator.languages[Thai.SelectedLanguage]
modimport("scripts/conItem/conItem.lua")
local uiStrings = {
"STRINGS.UI",
"STRINGS.ACTIONS",
"STRINGS.RECIPE_DESC",
"STRINGS.ANTIADDICTION",
"STRINGS.CHARACTER_",
"STRINGS.SKILLTREE",
"STRINGS.SKIN_DESCRIPTIONS",
}
local conStrings = {
"STRINGS.CHARACTERS",
"STRINGS.BOARLORD_",
"STRINGS.CARNIVAL_",
"STRINGS.GOATMUM_",
"STRINGS.HERMITCRAB_",
"STRINGS.VOIDCLOTH_",
"STRINGS.YOTB_",
"STRINGS.LUCY",
"STRINGS.MERM_KING_TALK_",
"STRINGS.MERM_TALK",
}
local itemStrings = {
"STRINGS.NAMES",
"STRINGS.BUNNYMANNAMES",
"STRINGS.CHARACTER_NAMES",
"STRINGS.MERMNAMES",
"STRINGS.PIGNAMES",
}
if IsDST then
table.insert(itemStrings, "STRINGS.BEEFALONAMING")
table.insert(itemStrings, "STRINGS.CROWNAMES")
table.insert(itemStrings, "STRINGS.KITCOON_NAMING")
table.insert(itemStrings, "STRINGS.SWAMPIGNAMES")
else
table.insert(itemStrings, "STRINGS.CITYPIGNAMES")
table.insert(itemStrings, "STRINGS.ANTNAMES")
table.insert(itemStrings, "STRINGS.ANTWARRIORNAMES")
table.insert(itemStrings, "STRINGS.BALLPHINNAMES")
table.insert(itemStrings, "STRINGS.MANDRAKEMANNAMES")
table.insert(itemStrings, "STRINGS.PARROTNAMES")
table.insert(itemStrings, "STRINGS.SHIPNAMES")
end
-- ไอเทมสองภาษาในชื่อไอเทมเลย
if Config.ITEM and Config.ITEM_TWO then
for _, text in ipairs(itemStrings) do
for itemIndex, itemEN in pairs(GetOriginalStringsFromIndex(text)) do
local itemTH = Thai.PO[itemIndex]
if itemTH then
if not itemTH:find("%s") then
Thai.PO[itemIndex] = itemTH..(itemEN and "\n("..itemEN..")" or "")
end
end
end
end
end
if not Config.UI or not Config.CON or not Config.ITEM then
for stringIndex in pairs(Thai.PO) do
-- ปิดการแปล UI
if not Config.UI then
for _, v in ipairs(uiStrings) do
if stringIndex:find(v) then
Thai.PO[stringIndex] = nil
end
end
end
-- ปิดการแปลบทพูด
if not Config.CON then
for _, v in ipairs(conStrings) do
if stringIndex:find(v) then
Thai.PO[stringIndex] = nil
end
end
end
-- ปิดการแปลชื่อไอเทม
if not Config.ITEM then
for _, v in ipairs(itemStrings) do
if stringIndex:find(v) then
Thai.PO[stringIndex] = nil
end
end
end
end
end
end
modimport("scripts/fix_ui.lua")
modimport("scripts/mods/main.lua")
modimport("scripts/string.lua")
---------------------------
-- Version Check
-- ^^ SimLuaProxy::QueryServer() tried to access a URL not permitted by the game.
--[[ AddClassPostConstruct("screens/redux/multiplayermainscreen", function(self, prev_screen, profile, offline, session_data)
TheSim:QueryServer("https://raw.githubusercontent.com/chaixshot/DST-Thai/main/version.txt", function(result, isSuccessful, resultCode)
if resultCode == 200 and isSuccessful then
local json = require("json")
local data = json.decode(result)
if modinfo.version ~= data.version then
local PopupDialogScreen = require("screens/redux/popupdialog")
local ModsScreen = require("screens/redux/modsscreen")
_G.TheFrontEnd:PushScreen(PopupDialogScreen("อัพเดท", "ส่วนเสริม \"ภาษาไทย\" มีอัพเดทใหม่\nกรุณาไปที่เมนู \"ส่วนเสริม\" เพื่ออัพเดท",
{
{
text = "อัพเดทเลย!",
cb = function()
_G.TheFrontEnd:PopScreen()
self:OnModsButton()
end
},
{
text = "ปิด",
cb = function()
_G.TheFrontEnd:PopScreen()
end
}
}))
end
end
end, "GET")
end) ]]
-- แก้ข้อความบังคับอัตโนมัติ เช่น "Moon Shard"
_G.setfenv(1, _G)