From 8c8fc8058d52c5d7b00a809f81352a7cfcd6b2bc Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:11:16 -0700 Subject: [PATCH 01/14] Use _gui_input for header drag Before this, if you moved a window's header to overlap the game window's header, dragging the window again would drag the window and the game window. --- RetroWindowsGUI/Window.tscn | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/RetroWindowsGUI/Window.tscn b/RetroWindowsGUI/Window.tscn index 03c9777..016ee65 100644 --- a/RetroWindowsGUI/Window.tscn +++ b/RetroWindowsGUI/Window.tscn @@ -38,6 +38,14 @@ func getwinmosposi() -> Vector2i: return DisplayServer.window_get_position() + Vector2i(floori(mospos.x), floori(mospos.y)) func _input(event: InputEvent): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if event.is_released(): + dragging = false + elif dragging and event is InputEventMouseMotion: + DisplayServer.window_set_position(begwinpos + getwinmosposi() - begwinmosposi) + +func _gui_input(event: InputEvent): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if event.double_click: @@ -51,11 +59,6 @@ func _input(event: InputEvent): dragging = true begwinmosposi = getwinmosposi() begwinpos = DisplayServer.window_get_position() - elif event.is_released(): - dragging = false - elif dragging and event is InputEventMouseMotion: - DisplayServer.window_set_position(begwinpos + getwinmosposi() - begwinmosposi) - " [sub_resource type="GDScript" id="GDScript_2514r"] From 0c00aaf3c1a0f08bb96ee0f131f5bd8b3167cace Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:13:05 -0700 Subject: [PATCH 02/14] Borderless=false, default project=thirdPerson.tscn I'd changed the borderless and default project settings earlier to showcase the addition of the virtual desktop, but it wasn't intented to be a persistent change. The change got committed anyways, so here I'm reverting it. --- project.godot | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/project.godot b/project.godot index 9fa0f03..de86cb8 100644 --- a/project.godot +++ b/project.godot @@ -11,15 +11,11 @@ config_version=5 [application] config/name="LgdgExampleProject" -run/main_scene="res://RetroWindowsGUI/Window.tscn" +run/main_scene="res://thirdPerson.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" run/size/borderless=false -[display] - -window/size/borderless=true - [input] ui_accept={ From 359e60d10867ef8e25c5d82fc2253ed771e5e18b Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:17:42 -0700 Subject: [PATCH 03/14] Move window into PackedScene The Inventory window was created directly in the desktop scene but it needs to be a template we can instantiate so I've moved it into its own PackedScene. --- RetroWindowsGUI/DesktopWindow.tscn | 336 +++++++++++++++++++++++++++++ RetroWindowsGUI/Window.tscn | 327 ++-------------------------- 2 files changed, 354 insertions(+), 309 deletions(-) create mode 100644 RetroWindowsGUI/DesktopWindow.tscn diff --git a/RetroWindowsGUI/DesktopWindow.tscn b/RetroWindowsGUI/DesktopWindow.tscn new file mode 100644 index 0000000..4ab78a9 --- /dev/null +++ b/RetroWindowsGUI/DesktopWindow.tscn @@ -0,0 +1,336 @@ +[gd_scene load_steps=19 format=3 uid="uid://bedj3x7821sbp"] + +[ext_resource type="Script" path="res://RetroWindowsGUI/DesktopWindow.gd" id="1_1566a"] +[ext_resource type="Theme" uid="uid://c23xui480a6b6" path="res://RetroWindowsGUI/RetroWindowsTheme.tres" id="1_clavd"] +[ext_resource type="Script" path="res://RetroWindowsGUI/RetroWindow.gd" id="2_5apeq"] +[ext_resource type="Texture2D" uid="uid://byysuusmylpjo" path="res://RetroWindowsGUI/Images/Window_Header_Inner.png" id="3_o2go2"] +[ext_resource type="Texture2D" uid="uid://f572ckglau50" path="res://RetroWindowsGUI/Images/Windows_Icon_Minimize.png" id="4_p55hd"] +[ext_resource type="Texture2D" uid="uid://bir5p8cnwtwrn" path="res://RetroWindowsGUI/Images/Windows_Icon_Maximize.png" id="5_6yn4a"] +[ext_resource type="Texture2D" uid="uid://lfo3fn4qyl3g" path="res://RetroWindowsGUI/Images/Windows_Icon_Question.png" id="6_0uvav"] +[ext_resource type="Texture2D" uid="uid://bluatk0bspn3x" path="res://RetroWindowsGUI/Images/Windows_Icon_Close.png" id="7_r5i4b"] +[ext_resource type="Texture2D" uid="uid://dxtjm7ivsy8s1" path="res://RetroWindowsGUI/Images/Windows_Inner_Frame_Inverted.png" id="8_lxvf8"] +[ext_resource type="Script" path="res://RetroWindowsGUI/ResizeHandle.gd" id="9_b570p"] + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_gihe0"] +texture = ExtResource("3_o2go2") + +[sub_resource type="GDScript" id="GDScript_ly7j8"] +script/source = "extends PanelContainer + +@export var window: DesktopWindow +var dragging: bool = false +var begmosposi: Vector2i # beginning mouse position integer +var begwndpos: Vector2i # beginning window position + +# get windows mouse position integer +func getmosposi() -> Vector2i: + var mospos := get_global_mouse_position() + return Vector2i(floori(mospos.x), floori(mospos.y)) + +func _input(event: InputEvent): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if event.double_click: + if get_global_rect().has_point(get_global_mouse_position()): + window.toggle_maximized() + elif event.pressed: + if get_global_rect().has_point(get_global_mouse_position()): + dragging = true + begmosposi = getmosposi() + begwndpos = window.get_global_rect().position + elif event.is_released(): + dragging = false + # snap within game window + var rect = window.get_global_rect() + if rect.position.x < 0: + rect.position.x = 0 + if rect.position.y < 0: + rect.position.y = 0 + window.position = rect.position + elif event is InputEventMouseMotion: + if dragging: + window.global_position = begwndpos + getmosposi() - begmosposi +" + +[sub_resource type="GDScript" id="GDScript_fvsxv"] +script/source = "extends Button + +@export var window: DesktopWindow + +func _ready(): + pressed.connect(_on_pressed) + +func _on_pressed(): + window.minimize() +" + +[sub_resource type="GDScript" id="GDScript_orv1v"] +script/source = "extends Button + +@export var window: DesktopWindow + +func _ready(): + pressed.connect(_on_pressed) + +func _on_pressed(): + window.toggle_maximized() +" + +[sub_resource type="GDScript" id="GDScript_go6nd"] +script/source = "extends Button + +@export var window: DesktopWindow + +func _ready(): + pressed.connect(_on_pressed) + +func _on_pressed(): + window.close() +" + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yu144"] +bg_color = Color(0.831373, 0.815686, 0.784314, 1) + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_eejdr"] +texture = ExtResource("8_lxvf8") +texture_margin_left = 2.0 +texture_margin_top = 2.0 +texture_margin_right = 2.0 +texture_margin_bottom = 2.0 + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_sn8k8"] +texture = ExtResource("8_lxvf8") +texture_margin_left = 3.0 +texture_margin_top = 3.0 +texture_margin_right = 3.0 +texture_margin_bottom = 3.0 + +[node name="DesktopWindow" type="Control"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 161.0 +offset_bottom = 135.0 +size_flags_vertical = 3 +theme = ExtResource("1_clavd") +script = ExtResource("1_1566a") + +[node name="PanelContainer" type="PanelContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("2_5apeq") + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/separation = 2 + +[node name="PanelContainer (Header)" type="PanelContainer" parent="PanelContainer/VBoxContainer" node_paths=PackedStringArray("window")] +custom_minimum_size = Vector2(0, 25) +layout_mode = 2 +theme_type_variation = &"HeaderPanelContainer" +theme_override_styles/panel = SubResource("StyleBoxTexture_gihe0") +script = SubResource("GDScript_ly7j8") +window = NodePath("../../..") + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)"] +custom_minimum_size = Vector2(0, 26) +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="MarginContainer (Title)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_right = 5 + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Title)"] +layout_mode = 2 +theme_override_colors/font_color = Color(1, 1, 1, 1) +theme_override_font_sizes/font_size = 16 +text = "Inventory" + +[node name="MarginContainer (Minimize)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 6 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Minimize)" node_paths=PackedStringArray("window")] +custom_minimum_size = Vector2(15, 15) +layout_mode = 2 +size_flags_vertical = 0 +expand_icon = true +script = SubResource("GDScript_fvsxv") +window = NodePath("../../../../../..") + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Minimize)"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +mouse_filter = 2 +texture = ExtResource("4_p55hd") + +[node name="MarginContainer (Maximize)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 6 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Maximize)" node_paths=PackedStringArray("window")] +custom_minimum_size = Vector2(15, 15) +layout_mode = 2 +size_flags_vertical = 0 +expand_icon = true +script = SubResource("GDScript_orv1v") +window = NodePath("../../../../../..") + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Maximize)"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +mouse_filter = 2 +texture = ExtResource("5_6yn4a") + +[node name="MarginContainer (Help)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 6 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Help)"] +custom_minimum_size = Vector2(15, 15) +layout_mode = 2 +size_flags_vertical = 0 +expand_icon = true + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Help)"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +mouse_filter = 2 +texture = ExtResource("6_0uvav") + +[node name="MarginContainer (Close)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 2 +theme_override_constants/margin_top = 6 +theme_override_constants/margin_right = 2 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Close)" node_paths=PackedStringArray("window")] +custom_minimum_size = Vector2(15, 15) +layout_mode = 2 +size_flags_vertical = 0 +expand_icon = true +script = SubResource("GDScript_go6nd") +window = NodePath("../../../../../..") + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Close)"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +mouse_filter = 2 +texture = ExtResource("7_r5i4b") + +[node name="PanelContainer (Menu Bar)" type="PanelContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_yu144") + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Menu Bar)"] +custom_minimum_size = Vector2(0, 16) +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer"] +layout_mode = 2 +theme_type_variation = &"FlatButton" +theme_override_colors/font_color = Color(0, 0, 0, 0) +theme_override_colors/font_pressed_color = Color(0, 0, 0, 0) +theme_override_colors/font_hover_color = Color(0, 0, 0, 0) +theme_override_colors/font_focus_color = Color(0, 0, 0, 0) +theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 0) +theme_override_colors/font_disabled_color = Color(0, 0, 0, 0) +theme_override_colors/font_outline_color = Color(0, 0, 0, 0) +text = "File" + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_top = 0 + +[node name="CenterContainer" type="CenterContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button/MarginContainer"] +layout_mode = 2 + +[node name="RichTextLabel" type="RichTextLabel" parent="PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button/MarginContainer/CenterContainer"] +layout_mode = 2 +size_flags_vertical = 8 +mouse_filter = 2 +bbcode_enabled = true +text = "[u]F[/u]ile" +fit_content = true +autowrap_mode = 0 + +[node name="PanelContainer (Body)" type="PanelContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_type_variation = &"InvertedInnerPanelContainer" +theme_override_styles/panel = SubResource("StyleBoxTexture_eejdr") + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Body)"] +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 0 + +[node name="MarginContainer (Content)" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="VScrollBar" type="VScrollBar" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 1 +size_flags_vertical = 3 +page = 100.0 + +[node name="HBoxContainer2" type="HBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer"] +custom_minimum_size = Vector2(0, 15) +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="HScrollBar" type="HScrollBar" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer2"] +custom_minimum_size = Vector2(16, 16) +layout_mode = 2 +size_flags_horizontal = 3 +page = 100.0 + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer2"] +custom_minimum_size = Vector2(16, 0) +layout_mode = 2 + +[node name="PanelContainer (Status Bar)" type="PanelContainer" parent="PanelContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 16) +layout_mode = 2 +size_flags_vertical = 8 +theme_override_styles/panel = SubResource("StyleBoxTexture_sn8k8") + +[node name="Button (Resize Handle)" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -17.0 +offset_top = -18.0 +offset_right = -5.0 +offset_bottom = -6.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_type_variation = &"ResizeButton" +action_mode = 0 +keep_pressed_outside = true +script = ExtResource("9_b570p") diff --git a/RetroWindowsGUI/Window.tscn b/RetroWindowsGUI/Window.tscn index 016ee65..ed9fc82 100644 --- a/RetroWindowsGUI/Window.tscn +++ b/RetroWindowsGUI/Window.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=28 format=3 uid="uid://bvc6sgiglgspt"] +[gd_scene load_steps=23 format=3 uid="uid://bvc6sgiglgspt"] [ext_resource type="Theme" uid="uid://c23xui480a6b6" path="res://RetroWindowsGUI/RetroWindowsTheme.tres" id="1_2cwqu"] [ext_resource type="Script" path="res://RetroWindowsGUI/Desktop.gd" id="2_1wlr7"] @@ -10,9 +10,8 @@ [ext_resource type="Texture2D" uid="uid://lfo3fn4qyl3g" path="res://RetroWindowsGUI/Images/Windows_Icon_Question.png" id="6_byeim"] [ext_resource type="Texture2D" uid="uid://dxtjm7ivsy8s1" path="res://RetroWindowsGUI/Images/Windows_Inner_Frame_Inverted.png" id="8_75uw4"] [ext_resource type="PackedScene" uid="uid://dviuoownyvrke" path="res://thirdPerson.tscn" id="9_o80ae"] -[ext_resource type="Script" path="res://RetroWindowsGUI/DesktopWindow.gd" id="11_7veoj"] +[ext_resource type="PackedScene" uid="uid://bedj3x7821sbp" path="res://RetroWindowsGUI/DesktopWindow.tscn" id="11_m0w0q"] [ext_resource type="AudioStream" uid="uid://c51m7ngf7kjdq" path="res://RetroWindowsGUI/me.ogg" id="12_16brn"] -[ext_resource type="Script" path="res://RetroWindowsGUI/ResizeHandle.gd" id="12_k07jd"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_74f3x"] bg_color = Color(0, 0, 0, 0.47451) @@ -128,81 +127,7 @@ func _on_pressed(): invwin.visible = true " -[sub_resource type="GDScript" id="GDScript_ly7j8"] -script/source = "extends PanelContainer - -@export var window: DesktopWindow -var dragging: bool = false -var begmosposi: Vector2i # beginning mouse position integer -var begwndpos: Vector2i # beginning window position - -# get windows mouse position integer -func getmosposi() -> Vector2i: - var mospos := get_global_mouse_position() - return Vector2i(floori(mospos.x), floori(mospos.y)) - -func _input(event: InputEvent): - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_LEFT: - if event.double_click: - if get_global_rect().has_point(get_global_mouse_position()): - window.toggle_maximized() - elif event.pressed: - if get_global_rect().has_point(get_global_mouse_position()): - dragging = true - begmosposi = getmosposi() - begwndpos = window.get_global_rect().position - elif event.is_released(): - dragging = false - # snap within game window - var rect = window.get_global_rect() - if rect.position.x < 0: - rect.position.x = 0 - if rect.position.y < 0: - rect.position.y = 0 - window.position = rect.position - elif event is InputEventMouseMotion: - if dragging: - window.global_position = begwndpos + getmosposi() - begmosposi -" - -[sub_resource type="GDScript" id="GDScript_fvsxv"] -script/source = "extends Button - -@export var window: DesktopWindow - -func _ready(): - pressed.connect(_on_pressed) - -func _on_pressed(): - window.minimize() -" - -[sub_resource type="GDScript" id="GDScript_orv1v"] -script/source = "extends Button - -@export var window: DesktopWindow - -func _ready(): - pressed.connect(_on_pressed) - -func _on_pressed(): - window.toggle_maximized() -" - -[sub_resource type="GDScript" id="GDScript_go6nd"] -script/source = "extends Button - -@export var window: DesktopWindow - -func _ready(): - pressed.connect(_on_pressed) - -func _on_pressed(): - window.close() -" - -[node name="Desktop" type="Control"] +[node name="Desktop" type="Control" node_paths=PackedStringArray("the_game")] texture_filter = 1 layout_mode = 3 anchors_preset = 15 @@ -212,6 +137,7 @@ grow_horizontal = 2 grow_vertical = 2 theme = ExtResource("1_2cwqu") script = ExtResource("2_1wlr7") +the_game = NodePath("VBoxContainer/MaximizedWindows/TheGame") metadata/_edit_lock_ = true [node name="BrightnessFilter" type="Panel" parent="."] @@ -484,246 +410,29 @@ text = "Start" layout_mode = 2 text = "The Game" -[node name="Button (Inventory)" type="Button" parent="VBoxContainer/TaskBar/HBoxContainer" node_paths=PackedStringArray("invwin")] +[node name="Button (Inventory)" type="Button" parent="VBoxContainer/TaskBar/HBoxContainer"] layout_mode = 2 text = "Inventory " script = SubResource("GDScript_2vlp5") -invwin = NodePath("../../../../Inventory") -[node name="Inventory" type="Control" parent="." node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar")] -layout_mode = 2 -anchors_preset = 0 -offset_left = 100.0 -offset_top = 100.0 -offset_right = 261.0 -offset_bottom = 282.0 -size_flags_vertical = 3 -script = ExtResource("11_7veoj") +[node name="DesktopWindow" parent="." node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] +offset_left = 132.0 +offset_top = 185.0 +offset_right = 293.0 +offset_bottom = 320.0 desktop = NodePath("..") maximized_windows = NodePath("../VBoxContainer/MaximizedWindows") taskbar = NodePath("../VBoxContainer/TaskBar") -[node name="PanelContainer" type="PanelContainer" parent="Inventory"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -script = ExtResource("2_5t0g8") - -[node name="VBoxContainer" type="VBoxContainer" parent="Inventory/PanelContainer"] -layout_mode = 2 -theme_override_constants/separation = 2 - -[node name="PanelContainer (Header)" type="PanelContainer" parent="Inventory/PanelContainer/VBoxContainer" node_paths=PackedStringArray("window")] -custom_minimum_size = Vector2(0, 25) -layout_mode = 2 -theme_type_variation = &"HeaderPanelContainer" -theme_override_styles/panel = SubResource("StyleBoxTexture_gihe0") -script = SubResource("GDScript_ly7j8") -window = NodePath("../../..") - -[node name="HBoxContainer" type="HBoxContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)"] -custom_minimum_size = Vector2(0, 26) -layout_mode = 2 -theme_override_constants/separation = 0 - -[node name="MarginContainer (Title)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_constants/margin_left = 5 -theme_override_constants/margin_right = 5 - -[node name="Label" type="Label" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Title)"] -layout_mode = 2 -theme_override_colors/font_color = Color(1, 1, 1, 1) -theme_override_font_sizes/font_size = 16 -text = "Inventory" - -[node name="MarginContainer (Minimize)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] -layout_mode = 2 -theme_override_constants/margin_top = 6 - -[node name="Button" type="Button" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Minimize)" node_paths=PackedStringArray("window")] -custom_minimum_size = Vector2(15, 15) -layout_mode = 2 -size_flags_vertical = 0 -expand_icon = true -script = SubResource("GDScript_fvsxv") -window = NodePath("../../../../../..") - -[node name="TextureRect" type="TextureRect" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Minimize)"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 0 -mouse_filter = 2 -texture = ExtResource("2_2k613") - -[node name="MarginContainer (Maximize)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] -layout_mode = 2 -theme_override_constants/margin_top = 6 - -[node name="Button" type="Button" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Maximize)" node_paths=PackedStringArray("window")] -custom_minimum_size = Vector2(15, 15) -layout_mode = 2 -size_flags_vertical = 0 -expand_icon = true -script = SubResource("GDScript_orv1v") -window = NodePath("../../../../../..") - -[node name="TextureRect" type="TextureRect" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Maximize)"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 0 -mouse_filter = 2 -texture = ExtResource("3_6tl28") - -[node name="MarginContainer (Help)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] -layout_mode = 2 -theme_override_constants/margin_top = 6 - -[node name="Button" type="Button" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Help)"] -custom_minimum_size = Vector2(15, 15) -layout_mode = 2 -size_flags_vertical = 0 -expand_icon = true - -[node name="TextureRect" type="TextureRect" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Help)"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 0 -mouse_filter = 2 -texture = ExtResource("6_byeim") - -[node name="MarginContainer (Close)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer"] -layout_mode = 2 -theme_override_constants/margin_left = 2 -theme_override_constants/margin_top = 6 -theme_override_constants/margin_right = 2 - -[node name="Button" type="Button" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Close)" node_paths=PackedStringArray("window")] -custom_minimum_size = Vector2(15, 15) -layout_mode = 2 -size_flags_vertical = 0 -expand_icon = true -script = SubResource("GDScript_go6nd") -window = NodePath("../../../../../..") - -[node name="TextureRect" type="TextureRect" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Header)/HBoxContainer/MarginContainer (Close)"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 0 -mouse_filter = 2 -texture = ExtResource("4_b1wjg") - -[node name="PanelContainer (Menu Bar)" type="PanelContainer" parent="Inventory/PanelContainer/VBoxContainer"] -layout_mode = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_yu144") - -[node name="HBoxContainer" type="HBoxContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Menu Bar)"] -custom_minimum_size = Vector2(0, 16) -layout_mode = 2 -theme_override_constants/separation = 0 - -[node name="Button" type="Button" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer"] -layout_mode = 2 -theme_type_variation = &"FlatButton" -theme_override_colors/font_color = Color(0, 0, 0, 0) -theme_override_colors/font_pressed_color = Color(0, 0, 0, 0) -theme_override_colors/font_hover_color = Color(0, 0, 0, 0) -theme_override_colors/font_focus_color = Color(0, 0, 0, 0) -theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 0) -theme_override_colors/font_disabled_color = Color(0, 0, 0, 0) -theme_override_colors/font_outline_color = Color(0, 0, 0, 0) -text = "File" - -[node name="MarginContainer" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -theme_override_constants/margin_top = 0 - -[node name="CenterContainer" type="CenterContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button/MarginContainer"] -layout_mode = 2 - -[node name="RichTextLabel" type="RichTextLabel" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Menu Bar)/HBoxContainer/Button/MarginContainer/CenterContainer"] -layout_mode = 2 -size_flags_vertical = 8 -mouse_filter = 2 -bbcode_enabled = true -text = "[u]F[/u]ile" -fit_content = true -autowrap_mode = 0 - -[node name="PanelContainer (Body)" type="PanelContainer" parent="Inventory/PanelContainer/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -theme_type_variation = &"InvertedInnerPanelContainer" -theme_override_styles/panel = SubResource("StyleBoxTexture_eejdr") - -[node name="VBoxContainer" type="VBoxContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)"] -layout_mode = 2 -theme_override_constants/separation = 0 - -[node name="HBoxContainer" type="HBoxContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -theme_override_constants/separation = 0 - -[node name="MarginContainer (Content)" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 - -[node name="VScrollBar" type="VScrollBar" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 1 -size_flags_vertical = 3 -page = 100.0 - -[node name="HBoxContainer2" type="HBoxContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer"] -custom_minimum_size = Vector2(0, 15) -layout_mode = 2 -theme_override_constants/separation = 0 - -[node name="HScrollBar" type="HScrollBar" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer2"] -custom_minimum_size = Vector2(16, 16) -layout_mode = 2 -size_flags_horizontal = 3 -page = 100.0 - -[node name="MarginContainer" type="MarginContainer" parent="Inventory/PanelContainer/VBoxContainer/PanelContainer (Body)/VBoxContainer/HBoxContainer2"] -custom_minimum_size = Vector2(16, 0) -layout_mode = 2 - -[node name="PanelContainer (Status Bar)" type="PanelContainer" parent="Inventory/PanelContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 16) -layout_mode = 2 -size_flags_vertical = 8 -theme_override_styles/panel = SubResource("StyleBoxTexture_sn8k8") - -[node name="Button (Resize Handle)" type="Button" parent="Inventory"] -layout_mode = 1 -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -17.0 -offset_top = -18.0 -offset_right = -5.0 -offset_bottom = -6.0 -grow_horizontal = 0 -grow_vertical = 0 -theme_type_variation = &"ResizeButton" -action_mode = 0 -keep_pressed_outside = true -script = ExtResource("12_k07jd") +[node name="DesktopWindow2" parent="." node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] +offset_left = 190.0 +offset_top = 197.0 +offset_right = 351.0 +offset_bottom = 332.0 +desktop = NodePath("..") +maximized_windows = NodePath("../VBoxContainer/MaximizedWindows") +taskbar = NodePath("../VBoxContainer/TaskBar") [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] stream = ExtResource("12_16brn") From 845a09a62bb545d3214cea62d4464893ff863d9c Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:27:27 -0700 Subject: [PATCH 04/14] Prevent multiple windows from being dragged at the same time Before this, if the headers of two windows overlapped and you clicked and dragged in that overlap, both windows would move at the same time. After this, only the front window gets dragged. The way that this works is that we use _gui_input instead of _input. This works because _gui_input is only sent to the top-level control. --- RetroWindowsGUI/DesktopWindow.tscn | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/RetroWindowsGUI/DesktopWindow.tscn b/RetroWindowsGUI/DesktopWindow.tscn index 4ab78a9..73aeebe 100644 --- a/RetroWindowsGUI/DesktopWindow.tscn +++ b/RetroWindowsGUI/DesktopWindow.tscn @@ -30,15 +30,7 @@ func getmosposi() -> Vector2i: func _input(event: InputEvent): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - if event.double_click: - if get_global_rect().has_point(get_global_mouse_position()): - window.toggle_maximized() - elif event.pressed: - if get_global_rect().has_point(get_global_mouse_position()): - dragging = true - begmosposi = getmosposi() - begwndpos = window.get_global_rect().position - elif event.is_released(): + if event.is_released(): dragging = false # snap within game window var rect = window.get_global_rect() @@ -50,6 +42,18 @@ func _input(event: InputEvent): elif event is InputEventMouseMotion: if dragging: window.global_position = begwndpos + getmosposi() - begmosposi + +func _gui_input(event: InputEvent): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if event.double_click: + if get_global_rect().has_point(get_global_mouse_position()): + window.toggle_maximized() + elif event.pressed: + if get_global_rect().has_point(get_global_mouse_position()): + dragging = true + begmosposi = getmosposi() + begwndpos = window.get_global_rect().position " [sub_resource type="GDScript" id="GDScript_fvsxv"] From 64a311a253aaf1e707686c05c54add56ae5bd9be Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:46:36 -0700 Subject: [PATCH 05/14] Fix the 9-slice of the window content panel --- RetroWindowsGUI/DesktopWindow.tscn | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/RetroWindowsGUI/DesktopWindow.tscn b/RetroWindowsGUI/DesktopWindow.tscn index 73aeebe..887687e 100644 --- a/RetroWindowsGUI/DesktopWindow.tscn +++ b/RetroWindowsGUI/DesktopWindow.tscn @@ -96,11 +96,15 @@ func _on_pressed(): bg_color = Color(0.831373, 0.815686, 0.784314, 1) [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_eejdr"] +content_margin_left = 2.0 +content_margin_top = 2.0 +content_margin_right = 2.0 +content_margin_bottom = 2.0 texture = ExtResource("8_lxvf8") -texture_margin_left = 2.0 -texture_margin_top = 2.0 -texture_margin_right = 2.0 -texture_margin_bottom = 2.0 +texture_margin_left = 3.0 +texture_margin_top = 3.0 +texture_margin_right = 3.0 +texture_margin_bottom = 3.0 [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_sn8k8"] texture = ExtResource("8_lxvf8") @@ -113,7 +117,7 @@ texture_margin_bottom = 3.0 layout_mode = 3 anchors_preset = 0 offset_right = 161.0 -offset_bottom = 135.0 +offset_bottom = 137.0 size_flags_vertical = 3 theme = ExtResource("1_clavd") script = ExtResource("1_1566a") From 65414609bc39157d9c5ddd385aa87f8948b60fa8 Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 12:54:17 -0700 Subject: [PATCH 06/14] Make VirtualDesktop enable borderless --- RetroWindowsGUI/Desktop.gd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RetroWindowsGUI/Desktop.gd b/RetroWindowsGUI/Desktop.gd index e4d7858..e6cacd7 100644 --- a/RetroWindowsGUI/Desktop.gd +++ b/RetroWindowsGUI/Desktop.gd @@ -4,6 +4,9 @@ extends Control @export var the_game: Control # TheGame var current_window: Control = the_game # current window +func _ready() -> void: + DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true) + func _process(_delta): #get_window().grab_focus() pass From 23f77441bcee7b5e8fc73245121d8f4ed5bfae6e Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:07:30 -0700 Subject: [PATCH 07/14] Move fullscreen toggle from _process to _input For whatever reason, the check being in _process prevented it from working consistently. --- FullscreenToggler.gd | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/FullscreenToggler.gd b/FullscreenToggler.gd index b5a3456..b682ccf 100644 --- a/FullscreenToggler.gd +++ b/FullscreenToggler.gd @@ -1,29 +1,29 @@ extends Node - # Called when the node enters the scene tree for the first time. func _ready(): #InputMap.action_get_events() var hotkey = ProjectSettings.get_setting("input/HotKey_ToggleFullscreen") - print(InputMap.action_get_events("character_forwards")) - print(InputMap.action_get_events("HotKey_ToggleFullscreen")) + #print(InputMap.action_get_events("character_forwards")) + #print(InputMap.action_get_events("HotKey_ToggleFullscreen")) if hotkey == null: print("PLEASE GO Project->Project Settings... , Input Map, and add HotKey_ToggleFullscreen") InputMap.add_action("HotKey_ToggleFullscreen") #InputMap.action_add_event() - print(hotkey) + #print(hotkey) -var temporarl_deadzone : float = 0 +var temporal_deadzone : float = 0 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): + if temporal_deadzone > 0.0: + temporal_deadzone -= delta + +func _input(event: InputEvent) -> void: #Returns true when the user has started pressing the action event in the current frame or physics tick. It will only return true on the frame or tick that the user pressed down the button. #This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed. - if Input.is_action_just_pressed("HotKey_ToggleFullscreen") and temporarl_deadzone <= 0.0: + if event.is_action_pressed("HotKey_ToggleFullscreen") and temporal_deadzone <= 0.0: if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - temporarl_deadzone = 0.5 - if temporarl_deadzone > 0.0: - temporarl_deadzone -= delta - + temporal_deadzone = 0.5 From cc629bfc428b4b58d908dd5439c82844635ac7c1 Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:19:35 -0700 Subject: [PATCH 08/14] Move windows into Windows control It's annoying to find all the windows so I'd like them to be childed under one node to make that easier. --- RetroWindowsGUI/Window.tscn | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/RetroWindowsGUI/Window.tscn b/RetroWindowsGUI/Window.tscn index ed9fc82..d79e5ba 100644 --- a/RetroWindowsGUI/Window.tscn +++ b/RetroWindowsGUI/Window.tscn @@ -416,23 +416,32 @@ text = "Inventory " script = SubResource("GDScript_2vlp5") -[node name="DesktopWindow" parent="." node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] +[node name="Windows" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +metadata/_edit_lock_ = true + +[node name="DesktopWindow" parent="Windows" node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] offset_left = 132.0 offset_top = 185.0 offset_right = 293.0 offset_bottom = 320.0 -desktop = NodePath("..") -maximized_windows = NodePath("../VBoxContainer/MaximizedWindows") -taskbar = NodePath("../VBoxContainer/TaskBar") +desktop = NodePath("../..") +maximized_windows = NodePath("../../VBoxContainer/MaximizedWindows") +taskbar = NodePath("../../VBoxContainer/TaskBar") -[node name="DesktopWindow2" parent="." node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] +[node name="DesktopWindow2" parent="Windows" node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] offset_left = 190.0 offset_top = 197.0 offset_right = 351.0 offset_bottom = 332.0 -desktop = NodePath("..") -maximized_windows = NodePath("../VBoxContainer/MaximizedWindows") -taskbar = NodePath("../VBoxContainer/TaskBar") +desktop = NodePath("../..") +maximized_windows = NodePath("../../VBoxContainer/MaximizedWindows") +taskbar = NodePath("../../VBoxContainer/TaskBar") [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] stream = ExtResource("12_16brn") From b83bd2074ae393538a794d0097f282a9fa33842a Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:29:18 -0700 Subject: [PATCH 09/14] Move windows into foreground when selected --- RetroWindowsGUI/DesktopWindow.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/RetroWindowsGUI/DesktopWindow.gd b/RetroWindowsGUI/DesktopWindow.gd index 549488f..5cf792f 100755 --- a/RetroWindowsGUI/DesktopWindow.gd +++ b/RetroWindowsGUI/DesktopWindow.gd @@ -12,6 +12,7 @@ func _input(event: InputEvent): if event.pressed: if get_global_rect().has_point(get_global_mouse_position()): desktop.current_window = self + get_parent().move_child(self, get_parent().get_child_count()) elif event is InputEventKey: if event.keycode == KEY_F11: if event.pressed: From 5bdca00c5ec6bb10290861485b4b96adb2addbd4 Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:30:08 -0700 Subject: [PATCH 10/14] Fix game window not receiving inputs When I added the "Windows" node to contain all the windows, it started blocking the inputs to the game window because it covers the entire window and its mouse_filter was set to block. --- RetroWindowsGUI/Window.tscn | 1 + 1 file changed, 1 insertion(+) diff --git a/RetroWindowsGUI/Window.tscn b/RetroWindowsGUI/Window.tscn index d79e5ba..8801529 100644 --- a/RetroWindowsGUI/Window.tscn +++ b/RetroWindowsGUI/Window.tscn @@ -423,6 +423,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 metadata/_edit_lock_ = true [node name="DesktopWindow" parent="Windows" node_paths=PackedStringArray("desktop", "maximized_windows", "taskbar") instance=ExtResource("11_m0w0q")] From d47c6ed9358350b1c8453dbb9300241b3bcbff48 Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:42:53 -0700 Subject: [PATCH 11/14] Change maximizing logic Before this, maximizing a window functioned by reparenting it to a margincontainer. Now, maximizing a window is a matter of setting its anchors and offsets. It will require more code but the reparenting strategy was causing problems because maximized windows were always displayed below windowed ones. This could technically be solved by modifying z-indexes of windows individually but this seems like a less annoying solution than that in the long run. --- RetroWindowsGUI/DesktopWindow.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RetroWindowsGUI/DesktopWindow.gd b/RetroWindowsGUI/DesktopWindow.gd index 5cf792f..43ee0e6 100755 --- a/RetroWindowsGUI/DesktopWindow.gd +++ b/RetroWindowsGUI/DesktopWindow.gd @@ -21,13 +21,13 @@ func _input(event: InputEvent): # toggle maximized func toggle_maximized(): - if get_parent() == maximized_windows: + if anchors_preset == Control.PRESET_FULL_RECT: + set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) position = windowed_rect.position size = windowed_rect.size - reparent(desktop) else: windowed_rect = get_global_rect() - reparent(maximized_windows) + set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) func close(): visible = false From 6286d4338ae484d157c7ad661669819092e3a08f Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 14:27:51 -0700 Subject: [PATCH 12/14] Alt+up/down minimize/windowed/maximized shortcuts Instead of the same way that you can win+up/down in windows. --- RetroWindowsGUI/DesktopWindow.gd | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/RetroWindowsGUI/DesktopWindow.gd b/RetroWindowsGUI/DesktopWindow.gd index 43ee0e6..f50b428 100755 --- a/RetroWindowsGUI/DesktopWindow.gd +++ b/RetroWindowsGUI/DesktopWindow.gd @@ -18,6 +18,23 @@ func _input(event: InputEvent): if event.pressed: if desktop.current_window == self: toggle_maximized() + elif event.alt_pressed and event.keycode == KEY_UP: + if event.pressed: + if desktop.current_window == self: + if not visible: + visible = true + elif not anchors_preset == Control.PRESET_FULL_RECT: + windowed_rect = get_global_rect() + set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + elif event.alt_pressed and event.keycode == KEY_DOWN: + if event.pressed: + if desktop.current_window == self: + if anchors_preset == Control.PRESET_FULL_RECT: + set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) + position = windowed_rect.position + size = windowed_rect.size + elif visible: + visible = false # toggle maximized func toggle_maximized(): From 35a8fc2f1a70a80c7d8320453f339bcf2920beb5 Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 15:17:22 -0700 Subject: [PATCH 13/14] Fix window-clickthrough What was happening here is that because we were detecting window clicks inside _input, when you clicked overlapping windows, all of them would receive the click, and all of them would set themselves to active and move to the foreground. The solution to this was to move the click-detection into _gui_input instead, which stops the event from traveling to the back elements. There is, however, a gotcha. Because _gui_input only fires on the topmost element clicked, the window itself doesn't receive the event because its children are covering it up and receive the event instead. To work around this I iterated all the children of the window, connecting to and forwarding their _gui_input events to the window root. Thus, buttons still work when you click on them, but the window also gets to respond as it needs to. --- RetroWindowsGUI/DesktopWindow.gd | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/RetroWindowsGUI/DesktopWindow.gd b/RetroWindowsGUI/DesktopWindow.gd index f50b428..dc39e13 100755 --- a/RetroWindowsGUI/DesktopWindow.gd +++ b/RetroWindowsGUI/DesktopWindow.gd @@ -7,13 +7,31 @@ extends Control var windowed_rect: Rect2 -func _input(event: InputEvent): +func get_descendants(node: Node) -> Array[Node]: + var nodes: Array[Node] = [] + + for child in node.get_children(): + if child.get_child_count() > 0: + nodes.append(child) + nodes.append_array(get_descendants(child)) + else: + nodes.append(child) + + return nodes + +func _ready() -> void: + for descendant in get_descendants(self): + descendant.gui_input.connect(_gui_input) + +func _gui_input(event: InputEvent) -> void: if event is InputEventMouseButton: if event.pressed: if get_global_rect().has_point(get_global_mouse_position()): desktop.current_window = self get_parent().move_child(self, get_parent().get_child_count()) - elif event is InputEventKey: + +func _input(event: InputEvent): + if event is InputEventKey: if event.keycode == KEY_F11: if event.pressed: if desktop.current_window == self: From 1801c8e5ba633bf8add8d0072105f9eeb0f7d94f Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 15:43:20 -0700 Subject: [PATCH 14/14] Remove superfluous alt+enter fullscreen controls --- RetroWindowsGUI/Desktop.gd | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/RetroWindowsGUI/Desktop.gd b/RetroWindowsGUI/Desktop.gd index e6cacd7..a54f1ec 100644 --- a/RetroWindowsGUI/Desktop.gd +++ b/RetroWindowsGUI/Desktop.gd @@ -6,19 +6,4 @@ var current_window: Control = the_game # current window func _ready() -> void: DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true) - -func _process(_delta): - #get_window().grab_focus() - pass - -func _input(event: InputEvent): - if event.is_action_pressed("HotKey_ToggleFullscreen"): - # we can't maximize because godot considers borderless maximized to be fullscreen - if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) - else: - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - - -