From 6cdcdbbeab1300cc01be713fc34028754fbef0b5 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Tue, 14 Nov 2023 01:07:06 +0100 Subject: [PATCH 01/12] Add dynamical placement of the menue button --- Spatial.gd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Spatial.gd b/Spatial.gd index 0c02c809..ed8129c4 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -47,6 +47,10 @@ var taco_parser: TacoParser var x11_window_id_burrito: int var is_transient:bool = false +# Variables that store informations about ui scaling +var icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger +var button_position = 11 # Place the main menue button on 11th position + # Called when the node enters the scene tree for the first time. func _ready(): get_tree().get_root().set_transparent_background(true) @@ -319,6 +323,14 @@ func decode_context_packet(spb: StreamPeerBuffer): # vs radians. 70deg = 1.22173rad and 25deg = 0.4363323rad. We should redo # this to just be a radian to degree conversion. + # Calculations to dynamically place the main menue button + # First we will calculate how much space every button needs depending on the actual ui scale. + # Then we can calculate how many buttons could fit on the screen and place our button at given position. + if $Control/GlobalMenuButton.margin_left != icon_size_preset[identity["uisz"]] * button_position: + $Control/GlobalMenuButton.margin_left = icon_size_preset[identity["uisz"]] * button_position + $Control/GlobalMenuButton.margin_right = (icon_size_preset[identity["uisz"]] * (button_position + 1)) + set_minimal_mouse_block() + if self.map_id != old_map_id: print("New Map") From 206f56ee8030021d3060c4c2b3532abda8e109f0 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Tue, 14 Nov 2023 11:32:34 +0000 Subject: [PATCH 02/12] Improve comments --- Spatial.gd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index ed8129c4..3f6e0d64 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -48,8 +48,11 @@ var x11_window_id_burrito: int var is_transient:bool = false # Variables that store informations about ui scaling +# This array holds the width of one menue item for every ui-scale var icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger -var button_position = 11 # Place the main menue button on 11th position +# The position indicates how many buttons will be there. +# e.g. if the native ui has 10 buttons we want to be on position 11. +var button_position = 11 # Place the main menue button on n..th position # Called when the node enters the scene tree for the first time. func _ready(): @@ -324,8 +327,9 @@ func decode_context_packet(spb: StreamPeerBuffer): # this to just be a radian to degree conversion. # Calculations to dynamically place the main menue button - # First we will calculate how much space every button needs depending on the actual ui scale. - # Then we can calculate how many buttons could fit on the screen and place our button at given position. + # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. + # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. + # TODO: Check if the calculated position is inside the window. if $Control/GlobalMenuButton.margin_left != icon_size_preset[identity["uisz"]] * button_position: $Control/GlobalMenuButton.margin_left = icon_size_preset[identity["uisz"]] * button_position $Control/GlobalMenuButton.margin_right = (icon_size_preset[identity["uisz"]] * (button_position + 1)) From f5753b6c347ba50d5a2e2fd192ae63d43d96c855 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Tue, 14 Nov 2023 11:39:54 +0000 Subject: [PATCH 03/12] Fix typos --- Spatial.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 3f6e0d64..25c26a2a 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -48,11 +48,11 @@ var x11_window_id_burrito: int var is_transient:bool = false # Variables that store informations about ui scaling -# This array holds the width of one menue item for every ui-scale +# This array holds the width of one item for every ui-scale var icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger # The position indicates how many buttons will be there. # e.g. if the native ui has 10 buttons we want to be on position 11. -var button_position = 11 # Place the main menue button on n..th position +var button_position = 11 # Place the icon/button on n..th position # Called when the node enters the scene tree for the first time. func _ready(): @@ -326,7 +326,7 @@ func decode_context_packet(spb: StreamPeerBuffer): # vs radians. 70deg = 1.22173rad and 25deg = 0.4363323rad. We should redo # this to just be a radian to degree conversion. - # Calculations to dynamically place the main menue button + # Calculations to dynamically place the main icon/button # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. # TODO: Check if the calculated position is inside the window. From 4dc4da4321b3567004fa4013ce17771867834894 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Thu, 16 Nov 2023 10:44:58 +0100 Subject: [PATCH 04/12] Add a global variable for the ui-size This information may be usefull elsewhere. The value is checked to be inside the expected range. --- Spatial.gd | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 25c26a2a..a5a45ac5 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -48,6 +48,8 @@ var x11_window_id_burrito: int var is_transient:bool = false # Variables that store informations about ui scaling +# The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger] +var ui_size = 1 # This array holds the width of one item for every ui-scale var icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger # The position indicates how many buttons will be there. @@ -330,9 +332,15 @@ func decode_context_packet(spb: StreamPeerBuffer): # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. # TODO: Check if the calculated position is inside the window. - if $Control/GlobalMenuButton.margin_left != icon_size_preset[identity["uisz"]] * button_position: - $Control/GlobalMenuButton.margin_left = icon_size_preset[identity["uisz"]] * button_position - $Control/GlobalMenuButton.margin_right = (icon_size_preset[identity["uisz"]] * (button_position + 1)) + + ui_size = identity["uisz"] + # If the value is outside of the expected range use the "normal" size. + if (ui_size < 0) or (ui_size > 3): + ui_size = 1 + + if $Control/GlobalMenuButton.margin_left != icon_size_preset[ui_size] * button_position: + $Control/GlobalMenuButton.margin_left = icon_size_preset[ui_size] * button_position + $Control/GlobalMenuButton.margin_right = (icon_size_preset[ui_size] * (button_position + 1)) set_minimal_mouse_block() if self.map_id != old_map_id: From f01c76d038b18a0b36ea569eb8307225f6903f3f Mon Sep 17 00:00:00 2001 From: Masgalor Date: Thu, 16 Nov 2023 11:30:17 +0100 Subject: [PATCH 05/12] Add checks to keep the button inside the window --- Spatial.gd | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index a5a45ac5..b68d7add 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -331,16 +331,20 @@ func decode_context_packet(spb: StreamPeerBuffer): # Calculations to dynamically place the main icon/button # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. - # TODO: Check if the calculated position is inside the window. - ui_size = identity["uisz"] # If the value is outside of the expected range use the "normal" size. if (ui_size < 0) or (ui_size > 3): ui_size = 1 - if $Control/GlobalMenuButton.margin_left != icon_size_preset[ui_size] * button_position: - $Control/GlobalMenuButton.margin_left = icon_size_preset[ui_size] * button_position - $Control/GlobalMenuButton.margin_right = (icon_size_preset[ui_size] * (button_position + 1)) + var button_position_max = floor(OS.window_size.x / icon_size_preset[ui_size]) - 1 + # Make sure the expected position is inside the window. + if (button_position > button_position_max): + button_position = button_position_max + + var button_margin_left = icon_size_preset[ui_size] * button_position + if $Control/GlobalMenuButton.margin_left != button_margin_left: + $Control/GlobalMenuButton.margin_left = button_margin_left + $Control/GlobalMenuButton.margin_right = button_margin_left + icon_size_preset[ui_size] set_minimal_mouse_block() if self.map_id != old_map_id: From dc9ad3591e483aab07f5b60ecedc117154d30ded Mon Sep 17 00:00:00 2001 From: Masgalor Date: Thu, 16 Nov 2023 16:50:53 +0100 Subject: [PATCH 06/12] Declare constants correctly --- Spatial.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index b68d7add..4fbf6adc 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -51,10 +51,10 @@ var is_transient:bool = false # The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger] var ui_size = 1 # This array holds the width of one item for every ui-scale -var icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger +const icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger # The position indicates how many buttons will be there. # e.g. if the native ui has 10 buttons we want to be on position 11. -var button_position = 11 # Place the icon/button on n..th position +const button_position = 11 # Place the icon/button on n..th position # Called when the node enters the scene tree for the first time. func _ready(): From 68ec0943faeac57d55b48fbe56c639c08c628f86 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Thu, 16 Nov 2023 18:02:41 +0100 Subject: [PATCH 07/12] Change the way an position outside the window is handled. --- Spatial.gd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 4fbf6adc..195b39eb 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -337,11 +337,13 @@ func decode_context_packet(spb: StreamPeerBuffer): ui_size = 1 var button_position_max = floor(OS.window_size.x / icon_size_preset[ui_size]) - 1 + var button_margin_left = $Control/GlobalMenuButton.margin_left # Make sure the expected position is inside the window. if (button_position > button_position_max): - button_position = button_position_max + button_margin_left = icon_size_preset[ui_size] * button_position_max + else: + button_margin_left = icon_size_preset[ui_size] * button_position - var button_margin_left = icon_size_preset[ui_size] * button_position if $Control/GlobalMenuButton.margin_left != button_margin_left: $Control/GlobalMenuButton.margin_left = button_margin_left $Control/GlobalMenuButton.margin_right = button_margin_left + icon_size_preset[ui_size] From 8e9b986057d736a8175bc097adefd80908508128 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Mon, 20 Nov 2023 15:30:51 +0100 Subject: [PATCH 08/12] Adopt projects coding standards --- Spatial.gd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 195b39eb..43f82e24 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -49,7 +49,7 @@ var is_transient:bool = false # Variables that store informations about ui scaling # The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger] -var ui_size = 1 +var ui_size: int = 1 # This array holds the width of one item for every ui-scale const icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger # The position indicates how many buttons will be there. @@ -331,22 +331,22 @@ func decode_context_packet(spb: StreamPeerBuffer): # Calculations to dynamically place the main icon/button # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. - ui_size = identity["uisz"] + self.ui_size = int(identity["uisz"]) # If the value is outside of the expected range use the "normal" size. - if (ui_size < 0) or (ui_size > 3): - ui_size = 1 + if (self.ui_size < 0) or (self.ui_size > 3): + self.ui_size = 1 - var button_position_max = floor(OS.window_size.x / icon_size_preset[ui_size]) - 1 + var button_position_max = floor(OS.window_size.x / self.icon_size_preset[self.ui_size]) - 1 var button_margin_left = $Control/GlobalMenuButton.margin_left # Make sure the expected position is inside the window. - if (button_position > button_position_max): - button_margin_left = icon_size_preset[ui_size] * button_position_max + if (self.button_position > button_position_max): + button_margin_left = self.icon_size_preset[self.ui_size] * button_position_max else: - button_margin_left = icon_size_preset[ui_size] * button_position + button_margin_left = self.icon_size_preset[self.ui_size] * self.button_position if $Control/GlobalMenuButton.margin_left != button_margin_left: $Control/GlobalMenuButton.margin_left = button_margin_left - $Control/GlobalMenuButton.margin_right = button_margin_left + icon_size_preset[ui_size] + $Control/GlobalMenuButton.margin_right = button_margin_left + self.icon_size_preset[self.ui_size] set_minimal_mouse_block() if self.map_id != old_map_id: From 6b17e811cbd986de30ab3f103b9dac16460651bc Mon Sep 17 00:00:00 2001 From: Masgalor Date: Mon, 20 Nov 2023 16:03:07 +0100 Subject: [PATCH 09/12] Add proper check if a dialog is visible To avoid code duplication the core functionality of _on_Dialog_hide was moved to an independet function. --- Spatial.gd | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 43f82e24..4225b9e6 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -330,7 +330,6 @@ func decode_context_packet(spb: StreamPeerBuffer): # Calculations to dynamically place the main icon/button # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. - # set_minimal_mouse_block() should be called only once, if it is called while any burrito windows is open it will become unclickable. self.ui_size = int(identity["uisz"]) # If the value is outside of the expected range use the "normal" size. if (self.ui_size < 0) or (self.ui_size > 3): @@ -344,9 +343,9 @@ func decode_context_packet(spb: StreamPeerBuffer): else: button_margin_left = self.icon_size_preset[self.ui_size] * self.button_position - if $Control/GlobalMenuButton.margin_left != button_margin_left: - $Control/GlobalMenuButton.margin_left = button_margin_left - $Control/GlobalMenuButton.margin_right = button_margin_left + self.icon_size_preset[self.ui_size] + $Control/GlobalMenuButton.margin_left = button_margin_left + $Control/GlobalMenuButton.margin_right = button_margin_left + self.icon_size_preset[self.ui_size] + if !is_any_dialog_visible(): set_minimal_mouse_block() if self.map_id != old_map_id: @@ -712,11 +711,16 @@ func clear_adjustment_nodes(): child.queue_free() -func _on_Dialog_hide(): +func is_any_dialog_visible(): for dialog in $Control/Dialogs.get_children(): if dialog.visible: - return - set_minimal_mouse_block() + return true + return false + + +func _on_Dialog_hide(): + if !is_any_dialog_visible(): + set_minimal_mouse_block() func _on_LoadPath_pressed(): From 601cead6944c788b7afb284a5027bf7d9d0b6fbf Mon Sep 17 00:00:00 2001 From: Masgalor Date: Mon, 20 Nov 2023 17:07:01 +0100 Subject: [PATCH 10/12] Change the type of icon_size_preset from array to dictionary --- Spatial.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 4225b9e6..43890700 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -51,7 +51,7 @@ var is_transient:bool = false # The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger] var ui_size: int = 1 # This array holds the width of one item for every ui-scale -const icon_size_preset = [26.5, 29.5, 33.0, 36.0] # 0=small; 1=normal; 2=large; 3=larger +const icon_size_preset = {0: 26.5, 1: 29.5, 2: 33.0, 3: 36.0} # 0=small; 1=normal; 2=large; 3=larger # The position indicates how many buttons will be there. # e.g. if the native ui has 10 buttons we want to be on position 11. const button_position = 11 # Place the icon/button on n..th position @@ -331,8 +331,8 @@ func decode_context_packet(spb: StreamPeerBuffer): # Calculations to dynamically place the main icon/button # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. self.ui_size = int(identity["uisz"]) - # If the value is outside of the expected range use the "normal" size. - if (self.ui_size < 0) or (self.ui_size > 3): + # If the value is not part of the dictionary use the "normal" size. + if !self.icon_size_preset.has(self.ui_size): self.ui_size = 1 var button_position_max = floor(OS.window_size.x / self.icon_size_preset[self.ui_size]) - 1 From a06daf3f584a5f962e44e11f1277d13e429948a7 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Mon, 20 Nov 2023 23:04:05 +0100 Subject: [PATCH 11/12] Remove the window-width check. This check does not hold a real value while most components of burrito only work reliable on fullscreen anyway. --- Spatial.gd | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 43890700..3c14f6a1 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -335,14 +335,7 @@ func decode_context_packet(spb: StreamPeerBuffer): if !self.icon_size_preset.has(self.ui_size): self.ui_size = 1 - var button_position_max = floor(OS.window_size.x / self.icon_size_preset[self.ui_size]) - 1 - var button_margin_left = $Control/GlobalMenuButton.margin_left - # Make sure the expected position is inside the window. - if (self.button_position > button_position_max): - button_margin_left = self.icon_size_preset[self.ui_size] * button_position_max - else: - button_margin_left = self.icon_size_preset[self.ui_size] * self.button_position - + var button_margin_left = self.icon_size_preset[self.ui_size] * self.button_position $Control/GlobalMenuButton.margin_left = button_margin_left $Control/GlobalMenuButton.margin_right = button_margin_left + self.icon_size_preset[self.ui_size] if !is_any_dialog_visible(): From 3c81e5b5bc8d54bc0b601453992db75ca43549c5 Mon Sep 17 00:00:00 2001 From: Masgalor Date: Tue, 21 Nov 2023 21:45:22 +0100 Subject: [PATCH 12/12] Change the way the button position is determined Instead of calculating the position it is now directly read from a dictionary as an absolute value. --- Spatial.gd | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 3c14f6a1..e99ee745 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -50,11 +50,13 @@ var is_transient:bool = false # Variables that store informations about ui scaling # The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger] var ui_size: int = 1 -# This array holds the width of one item for every ui-scale -const icon_size_preset = {0: 26.5, 1: 29.5, 2: 33.0, 3: 36.0} # 0=small; 1=normal; 2=large; 3=larger -# The position indicates how many buttons will be there. -# e.g. if the native ui has 10 buttons we want to be on position 11. -const button_position = 11 # Place the icon/button on n..th position +# This dictionary holds the left and right margin for the main button for every ui-scale +const button_margin = { + 0: {"left": 292, "right": 318}, # small + 1: {"left": 323, "right": 352}, # normal + 2: {"left": 361, "right": 394}, # large + 3: {"left": 395, "right": 431} # larger +} # Called when the node enters the scene tree for the first time. func _ready(): @@ -329,15 +331,13 @@ func decode_context_packet(spb: StreamPeerBuffer): # this to just be a radian to degree conversion. # Calculations to dynamically place the main icon/button - # The left- and right-margin can be calculated from the ui-scale combined with the preset icon width and the desired position. self.ui_size = int(identity["uisz"]) # If the value is not part of the dictionary use the "normal" size. - if !self.icon_size_preset.has(self.ui_size): + if !self.button_margin.has(self.ui_size): self.ui_size = 1 - var button_margin_left = self.icon_size_preset[self.ui_size] * self.button_position - $Control/GlobalMenuButton.margin_left = button_margin_left - $Control/GlobalMenuButton.margin_right = button_margin_left + self.icon_size_preset[self.ui_size] + $Control/GlobalMenuButton.margin_left = self.button_margin[self.ui_size]["left"] + $Control/GlobalMenuButton.margin_right = self.button_margin[self.ui_size]["right"] if !is_any_dialog_visible(): set_minimal_mouse_block()