-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathFontsUI.gd
215 lines (160 loc) · 8.82 KB
/
FontsUI.gd
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
extends VBoxContainer
const _PREVIEW_TEXT_EN := [
"A quick brown fox jumps over the lazy dog.",
"A quart jar of oil mixed with zinc oxide makes a very bright paint.",
"A quick movement of the enemy will jeopardize six gunboats.",
"A wizard’s job is to vex chumps quickly in fog.",
"Amazingly few discotheques provide jukeboxes.",
"Few black taxis drive up major roads on quiet hazy nights.",
"Jack quietly moved up front and seized the big ball of wax.",
"Just keep examining every low bid quoted for zinc etchings.",
"Just work for improved basic techniques to maximize your typing skill.",
"My faxed joke won a pager in the cable TV quiz show.",
"My girl wove six dozen plaid jackets before she quit.",
"Pack my box with five dozen liquor jugs.",
"Six big devils from Japan quickly forgot how to waltz.",
"Six boys guzzled cheap raw plum vodka quite joyfully.",
"Sixty zippers were quickly picked from the woven jute bag.",
"The five boxing wizards jump quickly.",
"The lazy major was fixing Cupid’s broken quiver.",
"The public was amazed to view the quickness and dexterity of the juggler.",
"We promptly judged antique ivory buckles for the next prize.",
"Whenever the black fox jumped the squirrel gazed suspiciously.",
]
const _PREVIEW_TEXT_RU := [
"Аэрофотосъёмка ландшафта уже выявила земли богачей и процветающих крестьян.",
"Блеф разъедает ум, чаще цыгана живёшь беспокойно, юля — грех это!",
"В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!",
"Вопрос футбольных энциклопедий замещая чушью: эй, где съеден ёж?",
"Лингвисты в ужасе: фиг выговоришь этюд: «подъём челябинский, запах щец».",
"Обдав его удушающей пылью, множество ярких фаэтонов исчезло из цирка.",
"Однажды съев фейхоа, я, как зацикленный, ностальгирую всё чаще и больше по этому чуду.",
"Пиши: зять съел яйцо, ещё чан брюквы… эх! Ждём фигу!",
"Подъехал шофёр на рефрижераторе грузить яйца для обучающихся элитных медиков.",
"Расчешись! Объявляю: туфли у камина, где этот хищный ёж цаплю задел.",
"Съел бы ёж лимонный пьезокварц, где электрическая юла яшму с туфом похищает.",
"Съешь ещё этих мягких французских булок, да выпей же чаю.",
"Флегматичная эта верблюдица жуёт у подъезда засыхающий горький шиповник.",
"Художник-эксперт с компьютером всего лишь яйца в объёмный низкий ящик чохом фасовал.",
"Шалящий фавн прикинул объём горячих звезд этих вьюжных царств.",
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.",
"Шифровальщица попросту забыла ряд ключевых множителей и тэгов.",
"Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф.",
"Эй, цирюльникъ, ёжик выстриги, да щетину ряхи сбрей, феном вошь за печь гони!",
"Эти ящерицы чешут вперёд за ключом, но багаж в сейфах, поди подъедь…",
"Южно-эфиопский грач увёл мышь за хобот на съезд ящериц.",
]
const _PREVIEW_TEXT_NUM := "1234567890 !@#$ %^&* ()[]{}"
onready var _rng := RandomNumberGenerator.new()
onready var _tabs := $".."
onready var _fonts := $"/root/Catapult/Fonts"
onready var _list := $FontSelection/RightPane/FontsList
onready var _btn_set_ui := $FontSelection/RightPane/Buttons/BtnSetFontUI
onready var _btn_set_map := $FontSelection/RightPane/Buttons/BtnSetFontMap
onready var _btn_set_om := $FontSelection/RightPane/Buttons/BtnSetFontOvermap
onready var _btn_set_all := $FontSelection/RightPane/Buttons/BtnSetFontAll
onready var _preview := $FontSelection/LeftPane/Preview
onready var _cbox_cyrillic = $FontSelection/LeftPane/PreviewCyrillic
onready var _info := $FontConfigInfo
onready var _sb_font_ui := $FontSelection/LeftPane/FontSizeUI/sbFontSizeUI
onready var _sb_font_map := $FontSelection/LeftPane/FontSizeMap/sbFontSizeMap
onready var _sb_font_om := $FontSelection/LeftPane/FontSizeOvermap/sbFontSizeOM
onready var _cbtn_blending := $FontSelection/LeftPane/FontBlending
onready var _help_dlg := $FontSizeHelpDialog
func _make_preview_string(cyrillic: bool = false) -> String:
var index = _rng.randi_range(0, len(_PREVIEW_TEXT_NUM) - 1)
var result = _PREVIEW_TEXT_NUM
if Settings.read("font_preview_cyrillic"):
index = _rng.randi_range(0, len(_PREVIEW_TEXT_RU) - 1)
result += "\n\n" + _PREVIEW_TEXT_RU[index]
else:
index = _rng.randi_range(0, len(_PREVIEW_TEXT_EN) - 1)
result += "\n\n" + _PREVIEW_TEXT_EN[index]
return result
func _show_current_config_info() -> void:
var config: Dictionary = _fonts.font_config
var fields := {
"typeface": tr("str_curr_font_config_ui"),
"map_typeface": tr("str_curr_font_config_map"),
"overmap_typeface": tr("str_curr_font_config_omap")}
var text := "[u]%s[/u]\n[table=2]" % tr("str_curr_font_config")
for field in fields:
var list: Array = config[field]
var row: String = "\n[cell]%s: [/cell]" % fields[field]
var fonts := ""
for i in len(list):
if i > 0:
fonts += " =>"
fonts += " [i]%s[/i]" % list[i].get_file().get_basename()
row += "[cell]%s[/cell]" % fonts
text += row
text += "\n[/table]"
_info.bbcode_text = text
func _load_font_options() -> void:
_fonts.load_game_options()
_sb_font_ui.value = _fonts.get_game_option("FONT_SIZE") as int
_sb_font_map.value = _fonts.get_game_option("MAP_FONT_SIZE") as int
_sb_font_om.value = _fonts.get_game_option("OVERMAP_FONT_SIZE") as int
_cbtn_blending.pressed = (_fonts.get_game_option("FONT_BLENDING").to_lower() == "true")
func _on_Tabs_tab_changed(tab: int) -> void:
if tab != 3:
return
if not _fonts.font_config_file_exists():
Status.post(tr("msg_no_font_config_file"), Enums.MSG_WARN)
_tabs.current_tab = 0
return
if not _fonts.options_file_exists():
Status.post(tr("msg_no_game_options_file"), Enums.MSG_WARN)
_tabs.current_tab = 0
return
_fonts.load_available_fonts()
_fonts.load_font_config()
for btn in [_btn_set_ui, _btn_set_map, _btn_set_om, _btn_set_all]:
btn.disabled = true
_list.clear()
for font in _fonts.available_fonts:
_list.add_item(font["name"])
_list.set_item_tooltip(_list.get_item_count() - 1, tr(font["desc_key"]))
_cbox_cyrillic.pressed = Settings.read("font_preview_cyrillic")
_load_font_options()
_preview.bbcode_text = ""
_show_current_config_info()
func _on_FontsList_item_selected(index: int) -> void:
var font_info = _fonts.available_fonts[index]
var font_path := "res://fonts/ingame".plus_file(font_info["file"])
var font_res = DynamicFont.new()
font_res.font_data = load(font_path)
font_res.size = 15.0 * Geom.scale
font_res.use_filter = true
_preview.add_font_override("normal_font", font_res)
_preview.bbcode_text = _make_preview_string(Settings.read("font_preview_cyrillic"))
for btn in [_btn_set_ui, _btn_set_map, _btn_set_om, _btn_set_all]:
btn.disabled = false
func _on_BtnSetFontX_pressed(ui: bool, map: bool, overmap: bool) -> void:
var index = _list.get_selected_items()[0]
var name = _fonts.available_fonts[index]["name"]
if ui:
Status.post(tr("msg_setting_ui_font") % name)
if map:
Status.post(tr("msg_setting_map_font") % name)
if overmap:
Status.post(tr("msg_setting_omap_font") % name)
_fonts.set_font(index, ui, map, overmap)
_on_BtnSaveFontOptions_pressed()
_show_current_config_info()
func _on_BtnResetFont_pressed() -> void:
_fonts.reset_font()
_on_BtnSaveFontOptions_pressed()
_show_current_config_info()
func _on_PreviewCyrillic_toggled(button_pressed: bool) -> void:
Settings.store("font_preview_cyrillic", button_pressed)
_preview.bbcode_text = _make_preview_string(Settings.read("font_preview_cyrillic"))
func _on_BtnSaveFontOptions_pressed() -> void:
var size_ui := int(_sb_font_ui.value)
var size_map := int(_sb_font_map.value)
var size_om := int(_sb_font_om.value)
_fonts.set_font_sizes(size_ui, size_map, size_om)
_fonts.set_game_option("FONT_BLENDING", str(_cbtn_blending.pressed))
_fonts.write_game_options()
func _on_HelpIcon_pressed() -> void:
_help_dlg.open()