aboutsummaryrefslogtreecommitdiff
path: root/main.gd
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-06-16 01:43:21 +0000
committerdam <dam@gudinoff>2022-06-16 01:43:21 +0000
commit3026d4b71ded2cfc3123eb92a6a13d4e51e5aa68 (patch)
tree952b368a18aaa2ae08f0fb956b6d16205b5c8681 /main.gd
parenta4b9a04763bb60c45300a267778f6586e43ce454 (diff)
downloadsurgery-log-3026d4b71ded2cfc3123eb92a6a13d4e51e5aa68.tar.zst
surgery-log-3026d4b71ded2cfc3123eb92a6a13d4e51e5aa68.zip
Added settings; Fixed virtual keyboard height bug with hack; Initial support of multiple themes.
Diffstat (limited to 'main.gd')
-rw-r--r--main.gd31
1 files changed, 29 insertions, 2 deletions
diff --git a/main.gd b/main.gd
index ec449df..c054940 100644
--- a/main.gd
+++ b/main.gd
@@ -1,7 +1,17 @@
extends Control
-var power_throttle_timeout: float
+var power_throttle_timeout : float
+var keyboard_height_offset : int
+var themes := [
+ preload("res://themes/day.tres") as Theme,
+ preload("res://themes/night.tres") as Theme
+]
+var themes_color := [
+ Color.white,
+ Color.black
+]
+onready var settings := Settings.new()
onready var popup := get_node("/root/main/popup") as ModalPopup
onready var file_picker := get_node("/root/main/file_picker") as FileDialog
onready var stage := get_node("/root/main/stage") as Stage
@@ -13,7 +23,6 @@ onready var controls_sensible_to_keyboard := [
func _init():
-
Physics2DServer.set_active(false)
PhysicsServer.set_active(false)
@@ -26,10 +35,13 @@ func _init():
func _ready():
Input.set_use_accumulated_input(false)
+ apply_theme(settings.get_value("theme_index", 0))
+ keyboard_height_offset = OS.get_virtual_keyboard_height()
func _process(delta: float):
var keyboard_height: int = OS.get_virtual_keyboard_height()
+ keyboard_height = max(0, keyboard_height - keyboard_height_offset)
for it in controls_sensible_to_keyboard:
it.margin_bottom = -keyboard_height
@@ -47,6 +59,9 @@ func _input(event: InputEvent):
func _unhandled_input(event: InputEvent):
Engine.target_fps = 0
power_throttle_timeout = 3.5
+
+ if event is InputEventKey && event.is_echo() == false && event.is_pressed() && event.scancode == KEY_ESCAPE:
+ _notification(MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST)
func _notification(what: int):
@@ -63,3 +78,15 @@ func _notification(what: int):
get_tree().quit()
+func toggle_theme():
+ var theme_idx := settings.get_value("theme_index", 0) as int
+ var next_theme_idx = (theme_idx + 1) % themes.size()
+ apply_theme(next_theme_idx)
+ settings.set_value("theme_index", next_theme_idx)
+
+
+func apply_theme(theme_idx: int) -> void:
+ self.theme = themes[theme_idx]
+ VisualServer.set_default_clear_color(themes_color[theme_idx])
+
+