Skip to content
  • Sponsor GDQuest/learn-gdscript

  • Notifications You must be signed in to change notification settings
  • Fork 182
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 08fe53b

Browse files
Wolfy7NathanLovato
andauthoredOct 10, 2022
feat: add option to lower the main text's brightness (#689)
First part of #623 Co-authored-by: Nathan Lovato <12694995+NathanLovato@users.noreply.github.com>
1 parent f29b88e commit 08fe53b

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
lines changed
 

‎autoload/ThemeManager.gd

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ extends Node
33
const THEME_ROOT := "res://ui/theme/"
44
const THEME_FONTS_ROOT := "res://ui/theme/fonts/"
55

6+
const COLOR_TEXT_DEFAULT := Color(0.960784, 0.980392, 0.980392)
7+
const COLOR_TEXT_LOWER_CONTRAST := Color(0.736288, 0.728113, 0.839844)
8+
9+
onready var _theme = preload("res://ui/theme/gdscript_app_theme.tres")
10+
611
var _font_size_defaults := {}
712

813

@@ -11,6 +16,7 @@ func _ready() -> void:
1116

1217
var current_profile := UserProfiles.get_profile()
1318
scale_all_font_sizes(current_profile.font_size_scale, false)
19+
set_lower_contrast(current_profile.lower_contrast, false)
1420

1521

1622
func _cache_font_size_defaults() -> void:
@@ -57,3 +63,14 @@ func scale_all_font_sizes(size_scale: int, and_save: bool = true) -> void:
5763
current_profile.font_size_scale = size_scale
5864
current_profile.save()
5965
Events.emit_signal("font_size_scale_changed", size_scale)
66+
67+
68+
func set_lower_contrast(lower_contrast: bool, and_save: bool = true) -> void:
69+
var color := COLOR_TEXT_LOWER_CONTRAST if lower_contrast else COLOR_TEXT_DEFAULT
70+
_theme.set_color("font_color", "Label", color)
71+
_theme.set_color("default_color", "RichTextLabel", color)
72+
73+
if and_save:
74+
var current_profile := UserProfiles.get_profile()
75+
current_profile.lower_contrast = lower_contrast
76+
current_profile.save()

‎resources/Profile.gd

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export var is_sponsored_profile := true
2020
export var language := "en"
2121
# Relative size adjustment of all fonts, in integer numbers.
2222
export var font_size_scale := 0
23+
# Lower contrast enabled
24+
export var lower_contrast := false
2325
# Sensitivity when scrolling with the mouse wheel or touchpad.
2426
export var scroll_sensitivity := 1.0 setget set_scroll_sensitivity
2527
# Target framerate for the application, to reduce update intensity on lower end devices.

‎ui/components/popups/SettingsPopup.gd

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ onready var _font_size_sample := $PanelContainer/Column/Margin/Column/Settings/F
1919
onready var _scroll_sensitivity_slider := $PanelContainer/Column/Margin/Column/Settings/ScrollSensitivitySetting/Value as HSlider
2020
onready var _framerate_option := $PanelContainer/Column/Margin/Column/Settings/FramerateSetting/Value as OptionButton
2121

22+
onready var _lower_contrast := $PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting/CheckBox as CheckBox
23+
2224
onready var _apply_button := $PanelContainer/Column/Margin/Column/Buttons/ApplyButton as Button
2325
onready var _cancel_button := $PanelContainer/Column/Margin/Column/Buttons/CancelButton as Button
2426

@@ -74,6 +76,8 @@ func _init_values() -> void:
7476
)
7577
_scroll_sensitivity_slider.value = current_profile.scroll_sensitivity
7678
_framerate_option.selected = FRAMERATE_MAP.values().find(current_profile.framerate_limit)
79+
80+
_lower_contrast.pressed = current_profile.lower_contrast
7781

7882

7983
func _on_apply_settings() -> void:
@@ -82,6 +86,8 @@ func _on_apply_settings() -> void:
8286
var size_scale := int(_font_size_value.value)
8387
ThemeManager.scale_all_font_sizes(size_scale)
8488

89+
ThemeManager.set_lower_contrast(_lower_contrast.pressed)
90+
8591
current_profile.set_scroll_sensitivity(_scroll_sensitivity_slider.value)
8692
current_profile.set_framerate_limit(FRAMERATE_MAP[_framerate_option.selected])
8793

@@ -94,7 +100,6 @@ func _on_font_size_changed(value: int) -> void:
94100
font_override.size += 2 * value
95101
_font_size_sample.add_font_override("font", font_override)
96102

97-
98103
func _on_visibility_changed() -> void:
99104
if _panel.visible:
100105
_font_size_value.grab_focus()

‎ui/components/popups/SettingsPopup.tscn

+40-23
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ anchor_right = 1.0
2323
anchor_bottom = 1.0
2424
theme = ExtResource( 7 )
2525
color = Color( 0.0352941, 0.0392157, 0.129412, 0.627451 )
26-
__meta__ = {
27-
"_edit_use_anchors_": false
28-
}
2926

3027
[node name="PanelContainer" type="PanelContainer" parent="."]
3128
anchor_left = 0.5
@@ -44,12 +41,12 @@ __meta__ = {
4441

4542
[node name="Panel" type="Panel" parent="PanelContainer"]
4643
margin_right = 720.0
47-
margin_bottom = 540.0
44+
margin_bottom = 599.0
4845
custom_styles/panel = ExtResource( 5 )
4946

5047
[node name="Column" type="VBoxContainer" parent="PanelContainer"]
5148
margin_right = 720.0
52-
margin_bottom = 540.0
49+
margin_bottom = 599.0
5350
custom_constants/separation = 0
5451

5552
[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/Column"]
@@ -62,14 +59,14 @@ percent_visible = false
6259
[node name="Margin" type="MarginContainer" parent="PanelContainer/Column"]
6360
margin_top = 16.0
6461
margin_right = 720.0
65-
margin_bottom = 540.0
62+
margin_bottom = 599.0
6663
size_flags_vertical = 3
6764

6865
[node name="Column" type="VBoxContainer" parent="PanelContainer/Column/Margin"]
6966
margin_left = 20.0
7067
margin_top = 20.0
7168
margin_right = 700.0
72-
margin_bottom = 504.0
69+
margin_bottom = 563.0
7370
custom_constants/separation = 12
7471

7572
[node name="Title" type="Label" parent="PanelContainer/Column/Margin/Column"]
@@ -90,33 +87,33 @@ size_flags_horizontal = 4
9087
[node name="Settings" type="VBoxContainer" parent="PanelContainer/Column/Margin/Column"]
9188
margin_top = 63.0
9289
margin_right = 680.0
93-
margin_bottom = 372.0
90+
margin_bottom = 431.0
9491
size_flags_vertical = 3
9592
custom_constants/separation = 32
9693

9794
[node name="LanguageSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
9895
margin_right = 680.0
99-
margin_bottom = 47.0
96+
margin_bottom = 44.0
10097

10198
[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/LanguageSetting"]
102-
margin_top = 9.0
99+
margin_top = 8.0
103100
margin_right = 332.0
104-
margin_bottom = 37.0
101+
margin_bottom = 36.0
105102
size_flags_horizontal = 3
106103
text = "Language"
107104

108105
[node name="Value" type="OptionButton" parent="PanelContainer/Column/Margin/Column/Settings/LanguageSetting"]
109106
margin_left = 348.0
110107
margin_right = 680.0
111-
margin_bottom = 47.0
108+
margin_bottom = 44.0
112109
hint_tooltip = "Change the course's language. We plan to add other languages, but only English is available for now."
113110
size_flags_horizontal = 3
114111
text = "English"
115112

116113
[node name="FontSizeSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
117-
margin_top = 79.0
114+
margin_top = 76.0
118115
margin_right = 680.0
119-
margin_bottom = 155.0
116+
margin_bottom = 152.0
120117

121118
[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/FontSizeSetting"]
122119
margin_right = 332.0
@@ -155,9 +152,9 @@ text = "Sample text"
155152
align = 1
156153

157154
[node name="ScrollSensitivitySetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
158-
margin_top = 187.0
155+
margin_top = 184.0
159156
margin_right = 680.0
160-
margin_bottom = 215.0
157+
margin_bottom = 212.0
161158

162159
[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/ScrollSensitivitySetting"]
163160
margin_right = 332.0
@@ -181,9 +178,9 @@ tick_count = 2
181178
ticks_on_borders = true
182179

183180
[node name="FramerateSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
184-
margin_top = 247.0
181+
margin_top = 244.0
185182
margin_right = 680.0
186-
margin_bottom = 294.0
183+
margin_bottom = 288.0
187184

188185
[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/FramerateSetting"]
189186
margin_right = 332.0
@@ -195,23 +192,43 @@ text = "Framerate cap"
195192
[node name="Value" type="OptionButton" parent="PanelContainer/Column/Margin/Column/Settings/FramerateSetting"]
196193
margin_left = 348.0
197194
margin_right = 680.0
198-
margin_bottom = 47.0
195+
margin_bottom = 44.0
199196
hint_tooltip = "Limit the app's framerate. Lower values make the app use less resources, especially when running in the browser, but may feel less fluid."
200197
size_flags_horizontal = 3
201198
text = "60 FPS"
202199
items = [ "60 FPS", null, false, 0, false, "30 FPS", null, false, 0, false, "No limit", null, false, 0, false ]
203200
selected = 0
204201

202+
[node name="LowerContrasSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
203+
margin_top = 320.0
204+
margin_right = 680.0
205+
margin_bottom = 368.0
206+
207+
[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting"]
208+
margin_right = 332.0
209+
margin_bottom = 28.0
210+
size_flags_horizontal = 3
211+
size_flags_vertical = 0
212+
text = "Lower contrast"
213+
214+
[node name="CheckBox" type="CheckBox" parent="PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting"]
215+
margin_left = 348.0
216+
margin_right = 680.0
217+
margin_bottom = 48.0
218+
hint_tooltip = "Lower the text's brightness."
219+
size_flags_horizontal = 3
220+
text = "Enabled"
221+
205222
[node name="Spacer" type="Control" parent="PanelContainer/Column/Margin/Column"]
206-
margin_top = 384.0
223+
margin_top = 443.0
207224
margin_right = 680.0
208-
margin_bottom = 404.0
225+
margin_bottom = 463.0
209226
rect_min_size = Vector2( 400, 20 )
210227

211228
[node name="Buttons" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column"]
212-
margin_top = 416.0
229+
margin_top = 475.0
213230
margin_right = 680.0
214-
margin_bottom = 484.0
231+
margin_bottom = 543.0
215232
alignment = 1
216233

217234
[node name="CancelButton" type="Button" parent="PanelContainer/Column/Margin/Column/Buttons"]

0 commit comments

Comments
 (0)