-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprojz_i18n_inject_4oldversion.rpy
420 lines (365 loc) · 18.4 KB
/
projz_i18n_inject_4oldversion.rpy
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# coding=utf8
# projz_renpy_translation, a translator for RenPy games
# Copyright (C) 2023 github.com/abse4411
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###########################################################
# ________ ________ ________ ___ ________ #
# |\ __ \|\ __ \|\ __ \ |\ \|\_____ \ #
# \ \ \|\ \ \ \|\ \ \ \|\ \ \ \ \\|___/ /| #
# \ \ ____\ \ _ _\ \ \\\ \ __ \ \ \ / / / #
# \ \ \___|\ \ \\ \\ \ \\\ \|\ \\_\ \ / /_/__ #
# \ \__\ \ \__\\ _\\ \_______\ \________\\________\ #
# \|__| \|__|\|__|\|_______|\|________|\|_______| #
# #
# This rpy file is generated by the project: #
# https://github.com/abse4411/projz_renpy_translation) #
###########################################################
# Note: Run after define statements of font in gui.rpy
init offset = 999
# # Enable developer console
# init python:
# if {projz_enable_console_content}:
# renpy.config.developer = True
# location of fotns
define projz_font_dir = "{projz_fonts_dir}"
# Names of gui font var for saving default font
define projz_gui_vars = ["projz_gui_text_font","projz_gui_name_text_font","projz_gui_interface_text_font","projz_gui_button_text_font","projz_gui_choice_button_text_font","projz_gui_system_font","projz_gui_main_font"]
# Names of gui font var for saving selected font
define projz_sgui_vars = ["projz_sgui_text_font","projz_sgui_name_text_font","projz_sgui_interface_text_font","projz_sgui_button_text_font","projz_sgui_choice_button_text_font","projz_sgui_system_font","projz_sgui_main_font"]
define projz_gui_names = ["Text Font","Name Text Font","Interface Text Font","Button Text Font","Choice Button Text Font","System Font","Main Font"]
define projz_global_font = 'projz_global_font'
# Names for saving current selected font by our setting
# define projz_gui_selected_font = "projz_gui_selected_font"
init python:
from store import persistent
def projz_dget(name, dvalue=None):
if hasattr(persistent, name) and getattr(persistent, name) is not None:
return getattr(persistent, name)
sname = name.replace('projz_s', 'projz_')
if hasattr(persistent, sname) and getattr(persistent, sname) is not None:
return getattr(persistent, sname)
return dvalue
def projz_get(name, dvalue=None):
if hasattr(persistent, name) and getattr(persistent, name) is not None:
return getattr(persistent, name)
return dvalue
def projz_set(name, value):
setattr(persistent, name, value)
return value
def projz_dset(name, dobj, dname, dvalue=None):
if hasattr(persistent, name) and getattr(persistent, name) is not None:
return getattr(persistent, name)
if hasattr(dobj, dname):
return projz_set(name, getattr(dobj, dname))
return projz_set(name, dvalue)
def projz_config_get(name, dvalue=None):
return projz_get("projz_config_"+name, dvalue)
def projz_config_set(name, value):
projz_set("projz_config_"+name, value)
setattr(renpy.config, name, value)
if projz_config_get("developer") is not None:
renpy.config.developer = projz_config_get("developer")
else:
projz_config_set("developer", {projz_enable_developer_content})
if projz_config_get("console", None) is not None:
renpy.config.console = projz_config_get("console")
else:
projz_config_set("console", {projz_enable_console_content})
if projz_get(projz_global_font) is None:
projz_set(projz_global_font, None)
# save default fonts
projz_dset(projz_gui_vars[0], gui, 'text_font')
projz_dset(projz_gui_vars[1], gui, 'name_text_font')
projz_dset(projz_gui_vars[2], gui, 'interface_text_font')
projz_dset(projz_gui_vars[3], gui, 'button_text_font')
projz_dset(projz_gui_vars[4], gui, 'choice_button_text_font')
projz_dset(projz_gui_vars[5], gui, 'system_font')
projz_dset(projz_gui_vars[6], gui, 'main_font')
################### Make font vars dynamic since Ren’Py 6.99.14 ###################
# define gui.text_font = gui.preference(projz_gui_vars[0], gui.text_font)
# define gui.name_text_font = gui.preference(projz_gui_vars[1], gui.name_text_font)
# define gui.interface_text_font = gui.preference(projz_gui_vars[2], gui.interface_text_font)
# define gui.button_text_font = gui.preference(projz_gui_vars[3], gui.button_text_font)
# define gui.choice_button_text_font = gui.preference(projz_gui_vars[4], gui.choice_button_text_font)
###################################################################################
################### Make font vars dynamic by our implementation ###################
define gui.text_font = projz_dget(projz_sgui_vars[0])
define gui.name_text_font = projz_dget(projz_sgui_vars[1])
define gui.interface_text_font = projz_dget(projz_sgui_vars[2])
define gui.button_text_font = projz_dget(projz_sgui_vars[3])
define gui.choice_button_text_font = projz_dget(projz_sgui_vars[4])
define gui.system_font = projz_dget(projz_sgui_vars[5])
define gui.main_font = projz_dget(projz_sgui_vars[6])
####################################################################################
# define projz_languages = {"korean": ("한국어", "SourceHanSansLite.ttf"), "japanese": ("日本語","SourceHanSansLite.ttf"), "french":("Русский","DejaVuSans.ttf"), "chinese": ("简体中文","SourceHanSansLite.ttf")}
define projz_languages = {{projz_lang_content}}
# define projz_simple_languages = ["cn", "en"]
define projz_simple_languages = [{projz_slang_content}]
#define projz_fonts = ["DejaVuSans.ttf", "KMKDSP.ttf", "SourceHanSansLite.ttf"]
define projz_fonts = [{projz_font_content}]
# Note that: fonts should be placed in "game/projz_fonts"
init python:
old_set_text = None
_old_prefix_suffix = None
_old_do_display = None
_DialogueTextTags_ref = None
def global_set_text(self, text, scope=None, substitute=False, update=True):
res = old_set_text(self, text, scope, substitute, update)
if not (substitute is True or substitute is None):
return res
if len(text) != 1 or (not isinstance(text[0], basestring)) or isinstance(text[0], bytes):
return res
old_text = self.text[0]
current_font = projz_get(projz_global_font)
if current_font is not None and old_text is not None and old_text.strip()!='':
new_text = u'{font='+str(current_font) + u'}' + old_text + u'{font}'
self.text = [new_text]
return res
def global_prefix_suffix(self, thing, prefix, body, suffix):
current_font = projz_get(projz_global_font)
if current_font is not None:
if (thing == 'what' or thing == 'who') and body is not None and body.strip()!='':
body = u'{font='+str(current_font) + u'}' + body + u'{font}'
return _old_prefix_suffix(self, thing, prefix, body, suffix)
def global_do_display(self, who, what, **display_args):
current_font = projz_get(projz_global_font)
if current_font is None:
return _old_do_display(self, who, what, **display_args)
if what is not None and what.strip() != '':
what = u'{font='+str(current_font) + u'}' + what + u'{font}'
if who is not None and who.strip() != '':
who = u'{font='+str(current_font) + u'}' + who + u'{font}'
old_dtt = display_args.get('dtt', None)
new_dtt = None
if _DialogueTextTags_ref and isinstance(old_dtt, _DialogueTextTags_ref):
new_dtt = _DialogueTextTags_ref(what)
display_args['dtt'] = new_dtt
_old_do_display(self, who, what, **display_args)
if old_dtt is not None:
for k, v in vars(new_dtt).items():
setattr(old_dtt, k, v)
try:
_DialogueTextTags_ref = renpy.character.DialogueTextTags
except Exception as projz_ex:
print(projz_ex)
try:
old_set_text = renpy.text.text.Text.set_text
renpy.text.text.Text.set_text = global_set_text
except Exception as projz_ex:
print(projz_ex)
try:
_old_prefix_suffix = renpy.character.ADVCharacter.prefix_suffix
renpy.character.ADVCharacter.prefix_suffix = global_prefix_suffix
except Exception as projz_ex:
print(projz_ex)
try:
_old_do_display = renpy.character.ADVCharacter.do_display
renpy.character.ADVCharacter.do_display = global_do_display
except Exception as projz_ex:
print(projz_ex)
from store import persistent, Action, DictEquality
class ProjzFontAction(Action, DictEquality):
def __init__(self, name, value, rebuild=True):
self.name = name
self.value = value
self.rebuild = rebuild
def __call__(self):
projz_set(self.name, self.value)
if self.rebuild:
gui.rebuild()
def get_selected(self):
return projz_get(self.name, None) == self.value
class ProjzDefaultFontAction(Action, DictEquality):
def __init__(self, name, rebuild=True):
self.name = name
self.rebuild = rebuild
def __call__(self):
projz_set(self.name, None)
if self.rebuild:
gui.rebuild()
def get_selected(self):
return projz_get(self.name, None) is None
class ProjzAllFontAction(Action, DictEquality):
def __init__(self, value, rebuild=True):
self.value = value
self.rebuild = rebuild
def __call__(self):
for name in projz_sgui_vars:
projz_set(name, self.value)
if self.rebuild:
gui.rebuild()
def get_selected(self):
for i in range(len(projz_sgui_vars)):
sfont = projz_get(projz_sgui_vars[i], None)
if sfont is None or sfont != self.value:
return False
return True
class ProjzDefaultAllFontAction(Action, DictEquality):
def __init__(self, rebuild=True):
self.rebuild = rebuild
def __call__(self):
for name in projz_sgui_vars:
projz_set(name, None)
if self.rebuild:
gui.rebuild()
def get_selected(self):
for name in projz_sgui_vars:
if projz_get(name, None) is not None:
return False
return True
class ProjzConfigAction(Action, DictEquality):
def __init__(self, name, value, rebuild=True):
self.name = name
self.value = value
self.rebuild = rebuild
def __call__(self):
projz_config_set(self.name, self.value)
if self.rebuild:
gui.rebuild()
def get_selected(self):
if hasattr(renpy.config, self.name) and getattr(renpy.config, self.name) == self.value:
return True
return False
class ProjzValueAction(Action, DictEquality):
def __init__(self, name, value, rebuild=True):
self.name = name
self.value = value
self.rebuild = rebuild
def __call__(self):
projz_set(self.name, self.value)
if self.rebuild:
gui.rebuild()
def get_selected(self):
return projz_get(self.name) == self.value
def projz_set_font(font):
for name in projz_sgui_vars:
projz_set(name, font)
gui.rebuild()
def projz_show_i18n_settings():
renpy.show_screen('projz_i18n_settings')
def projz_reload_game():
if old_set_text is not None:
renpy.text.text.Text.set_text = old_set_text
if _old_prefix_suffix is not None:
renpy.character.ADVCharacter.prefix_suffix = _old_prefix_suffix
if _old_do_display is not None:
renpy.character.ADVCharacter.do_display = _old_do_display
renpy.reload_script()
config.underlay[0].keymap['projz_show_i18n_settings'] = projz_show_i18n_settings
config.keymap['projz_show_i18n_settings'] = ['{projz_shortcut_key}']
screen projz_i18n_settings():
modal True
default show_more = False
side "c b r":
viewport id "vp":
mousewheel True
draggable True
vbox:
textbutton _("Hide") action Hide("projz_i18n_settings")
hbox:
box_wrap True
vbox:
style_prefix "radio"
label _("Language")
textbutton _("Default") action [Function(projz_set_font, None), Language(None)]
for k,v in projz_languages.items():
textbutton v[0] text_font projz_font_dir+v[1] action [Function(projz_set_font, projz_font_dir+v[1]), Language(k)]
for k in projz_simple_languages:
textbutton k action Language(k)
################### Make font vars dynamic by our implementation ###################
vbox:
style_prefix "radio"
label _("Global Font")
textbutton _("Default") action ProjzValueAction(projz_global_font, None)
for f in projz_fonts:
textbutton f:
text_font projz_font_dir+f
action ProjzValueAction(projz_global_font, projz_font_dir+f)
vbox:
style_prefix "radio"
label _("Font")
textbutton _("Default") action ProjzDefaultAllFontAction()
for f in projz_fonts:
textbutton f:
text_font projz_font_dir+f
action ProjzAllFontAction(projz_font_dir+f)
vbox:
style_prefix "radio"
label _("Other Font Settings")
textbutton _("Expand") action SetScreenVariable("show_more", True)
textbutton _("Collapse") action SetScreenVariable("show_more", False)
showif show_more == True:
for sf,n in zip(projz_sgui_vars, projz_gui_names):
vbox:
style_prefix "radio"
label _(n)
textbutton _("Default") action ProjzDefaultFontAction(sf)
for f in projz_fonts:
textbutton f:
text_font projz_font_dir+f
action ProjzFontAction(sf, projz_font_dir+f)
null height 10
hbox:
vbox:
style_prefix "radio"
label _("Developer Mode")
textbutton "auto" action [ProjzConfigAction("developer", "auto")]
textbutton "True" action [ProjzConfigAction("developer", True)]
textbutton "False" action [ProjzConfigAction("developer", False)]
text _("Reload Required")
vbox:
style_prefix "radio"
label _("Console (Shift+O)")
textbutton "True" action [ProjzConfigAction("console", True)]
textbutton "False" action [ProjzConfigAction("console", False)]
text _("Reload Required")
vbox:
style_prefix "check"
label _("Reload Game (Shift+R)")
textbutton _("Reload") action[Function(projz_reload_game)]
null height 10
label _("Watch")
# grid 2 12:
grid 2 10:
text _("Language")
text "[_preferences.language]"
text _("Developer Mode")
text "[config.developer]"
text _("Debug Console")
text "[config.console]"
text _("Text Font")
text "[gui.text_font]"
text _("Name Text Font")
text "[gui.name_text_font]"
text _("Interface Text Font")
text "[gui.interface_text_font]"
text _("Button Text Font")
text "[gui.button_text_font]"
text _("Choice Button Text Font")
text "[gui.choice_button_text_font]"
text _("System Font")
text "[gui.system_font]"
text _("Main Font")
text "[gui.main_font]"
null height 10
label _("Note that")
text _("If there exists the font configuration in game/tl/language/style.rpy, it will disable our font setting because of its higher priority. For more information, please see {a=https://www.renpy.org/doc/html/translation.html#style-translations}this{/a}.")
null height 10
text _("Thanks to my sponsors:\n- 799190761\n- ansan\nTo become a sponsor, see {a=https://github.com/abse4411/projz_renpy_translation?tab=readme-ov-file#sponsor}this{a}.")
null height 10
text _("This plugin is injected by the {a=https://github.com/abse4411/projz_renpy_translation}projz_renpy_translation{/a} project under the {a=https://github.com/abse4411/projz_renpy_translation?tab=GPL-3.0-1-ov-file}GPL-3.0 license{/a}.") xalign 1.0
null height 60
bar value XScrollValue("vp")
vbar value YScrollValue("vp")