Skip to content

feat: add option to change text color #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions autoload/ThemeManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ extends Node
const THEME_ROOT := "res://ui/theme/"
const THEME_FONTS_ROOT := "res://ui/theme/fonts/"

const COLOR_TEXT_DEFAULT := Color(0.960784, 0.980392, 0.980392)
const COLOR_TEXT_LOWER_CONTRAST := Color(0.736288, 0.728113, 0.839844)

onready var _theme = preload("res://ui/theme/gdscript_app_theme.tres")

var _font_size_defaults := {}


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

var current_profile := UserProfiles.get_profile()
scale_all_font_sizes(current_profile.font_size_scale, false)
set_lower_contrast(current_profile.lower_contrast, false)


func _cache_font_size_defaults() -> void:
Expand Down Expand Up @@ -57,3 +63,14 @@ func scale_all_font_sizes(size_scale: int, and_save: bool = true) -> void:
current_profile.font_size_scale = size_scale
current_profile.save()
Events.emit_signal("font_size_scale_changed", size_scale)


func set_lower_contrast(lower_contrast: bool, and_save: bool = true) -> void:
var color := COLOR_TEXT_LOWER_CONTRAST if lower_contrast else COLOR_TEXT_DEFAULT
_theme.set_color("font_color", "Label", color)
_theme.set_color("default_color", "RichTextLabel", color)

if and_save:
var current_profile := UserProfiles.get_profile()
current_profile.lower_contrast = lower_contrast
current_profile.save()
2 changes: 2 additions & 0 deletions resources/Profile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export var is_sponsored_profile := true
export var language := "en"
# Relative size adjustment of all fonts, in integer numbers.
export var font_size_scale := 0
# Lower contrast enabled
export var lower_contrast := false
# Sensitivity when scrolling with the mouse wheel or touchpad.
export var scroll_sensitivity := 1.0 setget set_scroll_sensitivity
# Target framerate for the application, to reduce update intensity on lower end devices.
Expand Down
7 changes: 6 additions & 1 deletion ui/components/popups/SettingsPopup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ onready var _font_size_sample := $PanelContainer/Column/Margin/Column/Settings/F
onready var _scroll_sensitivity_slider := $PanelContainer/Column/Margin/Column/Settings/ScrollSensitivitySetting/Value as HSlider
onready var _framerate_option := $PanelContainer/Column/Margin/Column/Settings/FramerateSetting/Value as OptionButton

onready var _lower_contrast := $PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting/CheckBox as CheckBox

onready var _apply_button := $PanelContainer/Column/Margin/Column/Buttons/ApplyButton as Button
onready var _cancel_button := $PanelContainer/Column/Margin/Column/Buttons/CancelButton as Button

Expand Down Expand Up @@ -74,6 +76,8 @@ func _init_values() -> void:
)
_scroll_sensitivity_slider.value = current_profile.scroll_sensitivity
_framerate_option.selected = FRAMERATE_MAP.values().find(current_profile.framerate_limit)

_lower_contrast.pressed = current_profile.lower_contrast


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

ThemeManager.set_lower_contrast(_lower_contrast.pressed)

current_profile.set_scroll_sensitivity(_scroll_sensitivity_slider.value)
current_profile.set_framerate_limit(FRAMERATE_MAP[_framerate_option.selected])

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


func _on_visibility_changed() -> void:
if _panel.visible:
_font_size_value.grab_focus()
63 changes: 40 additions & 23 deletions ui/components/popups/SettingsPopup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 7 )
color = Color( 0.0352941, 0.0392157, 0.129412, 0.627451 )
__meta__ = {
"_edit_use_anchors_": false
}

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

[node name="Panel" type="Panel" parent="PanelContainer"]
margin_right = 720.0
margin_bottom = 540.0
margin_bottom = 599.0
custom_styles/panel = ExtResource( 5 )

[node name="Column" type="VBoxContainer" parent="PanelContainer"]
margin_right = 720.0
margin_bottom = 540.0
margin_bottom = 599.0
custom_constants/separation = 0

[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/Column"]
Expand All @@ -62,14 +59,14 @@ percent_visible = false
[node name="Margin" type="MarginContainer" parent="PanelContainer/Column"]
margin_top = 16.0
margin_right = 720.0
margin_bottom = 540.0
margin_bottom = 599.0
size_flags_vertical = 3

[node name="Column" type="VBoxContainer" parent="PanelContainer/Column/Margin"]
margin_left = 20.0
margin_top = 20.0
margin_right = 700.0
margin_bottom = 504.0
margin_bottom = 563.0
custom_constants/separation = 12

[node name="Title" type="Label" parent="PanelContainer/Column/Margin/Column"]
Expand All @@ -90,33 +87,33 @@ size_flags_horizontal = 4
[node name="Settings" type="VBoxContainer" parent="PanelContainer/Column/Margin/Column"]
margin_top = 63.0
margin_right = 680.0
margin_bottom = 372.0
margin_bottom = 431.0
size_flags_vertical = 3
custom_constants/separation = 32

[node name="LanguageSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
margin_right = 680.0
margin_bottom = 47.0
margin_bottom = 44.0

[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/LanguageSetting"]
margin_top = 9.0
margin_top = 8.0
margin_right = 332.0
margin_bottom = 37.0
margin_bottom = 36.0
size_flags_horizontal = 3
text = "Language"

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

[node name="FontSizeSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
margin_top = 79.0
margin_top = 76.0
margin_right = 680.0
margin_bottom = 155.0
margin_bottom = 152.0

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

[node name="ScrollSensitivitySetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
margin_top = 187.0
margin_top = 184.0
margin_right = 680.0
margin_bottom = 215.0
margin_bottom = 212.0

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

[node name="FramerateSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
margin_top = 247.0
margin_top = 244.0
margin_right = 680.0
margin_bottom = 294.0
margin_bottom = 288.0

[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/FramerateSetting"]
margin_right = 332.0
Expand All @@ -195,23 +192,43 @@ text = "Framerate cap"
[node name="Value" type="OptionButton" parent="PanelContainer/Column/Margin/Column/Settings/FramerateSetting"]
margin_left = 348.0
margin_right = 680.0
margin_bottom = 47.0
margin_bottom = 44.0
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."
size_flags_horizontal = 3
text = "60 FPS"
items = [ "60 FPS", null, false, 0, false, "30 FPS", null, false, 0, false, "No limit", null, false, 0, false ]
selected = 0

[node name="LowerContrasSetting" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column/Settings"]
margin_top = 320.0
margin_right = 680.0
margin_bottom = 368.0

[node name="Label" type="Label" parent="PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting"]
margin_right = 332.0
margin_bottom = 28.0
size_flags_horizontal = 3
size_flags_vertical = 0
text = "Lower contrast"

[node name="CheckBox" type="CheckBox" parent="PanelContainer/Column/Margin/Column/Settings/LowerContrasSetting"]
margin_left = 348.0
margin_right = 680.0
margin_bottom = 48.0
hint_tooltip = "Lower the text's brightness."
size_flags_horizontal = 3
text = "Enabled"

[node name="Spacer" type="Control" parent="PanelContainer/Column/Margin/Column"]
margin_top = 384.0
margin_top = 443.0
margin_right = 680.0
margin_bottom = 404.0
margin_bottom = 463.0
rect_min_size = Vector2( 400, 20 )

[node name="Buttons" type="HBoxContainer" parent="PanelContainer/Column/Margin/Column"]
margin_top = 416.0
margin_top = 475.0
margin_right = 680.0
margin_bottom = 484.0
margin_bottom = 543.0
alignment = 1

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