From d6a355142aec13ed3074ef35d8b451bc2f01342d Mon Sep 17 00:00:00 2001 From: osquallo Date: Wed, 15 Aug 2018 13:00:30 +0200 Subject: [PATCH] ajout GUI: un clic sur la barre de titre d'une fenetre la place au dessus des autre. --- scenes/GUI/GUI.tscn | 2 +- scenes/GUI/HUD/HUD.tscn | 86 +++++++++++++++++---------------- scenes/GUI/HUD/WindowControl.gd | 45 ++++++++++++++--- scenes/GUI/HUD/Windows.gd | 14 ++++++ 4 files changed, 96 insertions(+), 51 deletions(-) create mode 100644 scenes/GUI/HUD/Windows.gd diff --git a/scenes/GUI/GUI.tscn b/scenes/GUI/GUI.tscn index 5d42853..9ad24a2 100644 --- a/scenes/GUI/GUI.tscn +++ b/scenes/GUI/GUI.tscn @@ -19,7 +19,7 @@ _sections_unfolded = [ "Font", "Settings" ] default_font = SubResource( 1 ) -[node name="GUI" type="MarginContainer" index="0"] +[node name="GUI" type="MarginContainer"] pause_mode = 2 anchor_left = 0.0 diff --git a/scenes/GUI/HUD/HUD.tscn b/scenes/GUI/HUD/HUD.tscn index 9683426..793bb5c 100644 --- a/scenes/GUI/HUD/HUD.tscn +++ b/scenes/GUI/HUD/HUD.tscn @@ -1,20 +1,21 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://scenes/GUI/HUD/HUD.gd" type="Script" id=1] -[ext_resource path="res://scenes/GUI/HUD/WindowControl.gd" type="Script" id=2] -[ext_resource path="res://assets/GUI/images/bg2.jpg" type="Texture" id=3] -[ext_resource path="res://assets/GUI/images/button_quit.png" type="Texture" id=4] -[ext_resource path="res://assets/GUI/images/button_close.png" type="Texture" id=5] -[ext_resource path="res://assets/GUI/images/button_open.png" type="Texture" id=6] -[ext_resource path="res://assets/GUI/images/button_resize.png" type="Texture" id=7] -[ext_resource path="res://scenes/GUI/MusicControls/MusicControls.tscn" type="PackedScene" id=8] -[ext_resource path="res://addons/ui_window/ui_window.gd" type="Script" id=9] -[ext_resource path="res://addons/ui_window/icon.png" type="Texture" id=10] -[ext_resource path="res://scenes/GUI/HUD/oubli.gd" type="Script" id=11] -[ext_resource path="res://scenes/GUI/HUD/trauma.gd" type="Script" id=12] -[ext_resource path="res://scenes/GUI/HUD/douleur.gd" type="Script" id=13] +[ext_resource path="res://scenes/GUI/HUD/Windows.gd" type="Script" id=2] +[ext_resource path="res://scenes/GUI/HUD/WindowControl.gd" type="Script" id=3] +[ext_resource path="res://assets/GUI/images/bg2.jpg" type="Texture" id=4] +[ext_resource path="res://assets/GUI/images/button_quit.png" type="Texture" id=5] +[ext_resource path="res://assets/GUI/images/button_close.png" type="Texture" id=6] +[ext_resource path="res://assets/GUI/images/button_open.png" type="Texture" id=7] +[ext_resource path="res://assets/GUI/images/button_resize.png" type="Texture" id=8] +[ext_resource path="res://scenes/GUI/MusicControls/MusicControls.tscn" type="PackedScene" id=9] +[ext_resource path="res://addons/ui_window/ui_window.gd" type="Script" id=10] +[ext_resource path="res://addons/ui_window/icon.png" type="Texture" id=11] +[ext_resource path="res://scenes/GUI/HUD/oubli.gd" type="Script" id=12] +[ext_resource path="res://scenes/GUI/HUD/trauma.gd" type="Script" id=13] +[ext_resource path="res://scenes/GUI/HUD/douleur.gd" type="Script" id=14] -[node name="HUD" type="MarginContainer"] +[node name="HUD" type="MarginContainer" index="0"] anchor_left = 0.0 anchor_top = 0.0 @@ -81,6 +82,7 @@ mouse_filter = 1 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 3 +script = ExtResource( 2 ) _sections_unfolded = [ "Mouse", "Size Flags", "Theme", "Visibility", "custom_styles" ] [node name="Test" type="MarginContainer" parent="Windows" index="0"] @@ -104,8 +106,8 @@ custom_constants/margin_right = 0 custom_constants/margin_top = 0 custom_constants/margin_left = 0 custom_constants/margin_bottom = 0 -script = ExtResource( 2 ) -_sections_unfolded = [ "Mouse", "Size Flags", "Theme", "custom_constants" ] +script = ExtResource( 3 ) +_sections_unfolded = [ "Focus", "Mouse", "Size Flags", "Theme", "custom_constants" ] __meta__ = { "_edit_group_": true } @@ -123,11 +125,11 @@ margin_right = 289.0 margin_bottom = 128.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false -mouse_filter = 2 +mouse_filter = 1 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource( 3 ) +texture = ExtResource( 4 ) patch_margin_left = 4 patch_margin_top = 32 patch_margin_right = 4 @@ -164,7 +166,7 @@ margin_right = 289.0 margin_bottom = 24.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false -mouse_filter = 0 +mouse_filter = 1 mouse_default_cursor_shape = 13 size_flags_horizontal = 1 size_flags_vertical = 4 @@ -212,7 +214,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 4 ) +texture_normal = ExtResource( 5 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Close" type="TextureButton" parent="Windows/Test/VBoxContainer/Header/HBoxContainer" index="1"] @@ -235,7 +237,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 5 ) +texture_normal = ExtResource( 6 ) _sections_unfolded = [ "Margin", "Size Flags", "Textures", "custom_constants" ] [node name="Open" type="TextureButton" parent="Windows/Test/VBoxContainer/Header/HBoxContainer" index="2"] @@ -259,7 +261,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 6 ) +texture_normal = ExtResource( 7 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Label" type="Label" parent="Windows/Test/VBoxContainer/Header/HBoxContainer" index="3"] @@ -397,7 +399,7 @@ action_mode = 0 enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 7 ) +texture_normal = ExtResource( 8 ) _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ] [node name="TestBorderless" type="MarginContainer" parent="Windows" index="1"] @@ -422,7 +424,7 @@ custom_constants/margin_right = 0 custom_constants/margin_top = 0 custom_constants/margin_left = 0 custom_constants/margin_bottom = 0 -script = ExtResource( 2 ) +script = ExtResource( 3 ) _sections_unfolded = [ "Mouse", "Size Flags", "Theme", "custom_constants" ] __meta__ = { "_edit_group_": true @@ -445,7 +447,7 @@ mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource( 3 ) +texture = ExtResource( 4 ) patch_margin_left = 4 patch_margin_top = 32 patch_margin_right = 4 @@ -530,7 +532,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 4 ) +texture_normal = ExtResource( 5 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Close" type="TextureButton" parent="Windows/TestBorderless/VBoxContainer/Header/HBoxContainer" index="1"] @@ -553,7 +555,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 5 ) +texture_normal = ExtResource( 6 ) _sections_unfolded = [ "Margin", "Size Flags", "Textures", "custom_constants" ] [node name="Open" type="TextureButton" parent="Windows/TestBorderless/VBoxContainer/Header/HBoxContainer" index="2"] @@ -577,7 +579,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 6 ) +texture_normal = ExtResource( 7 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Label" type="Label" parent="Windows/TestBorderless/VBoxContainer/Header/HBoxContainer" index="3"] @@ -759,7 +761,7 @@ action_mode = 0 enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 7 ) +texture_normal = ExtResource( 8 ) _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ] [node name="Music" type="MarginContainer" parent="Windows" index="2"] @@ -783,7 +785,7 @@ custom_constants/margin_right = 0 custom_constants/margin_top = 0 custom_constants/margin_left = 0 custom_constants/margin_bottom = 0 -script = ExtResource( 2 ) +script = ExtResource( 3 ) _sections_unfolded = [ "Anchor", "Focus", "Hint", "Margin", "Mouse", "Rect", "Size Flags", "Theme", "custom_constants" ] __meta__ = { "_edit_group_": true @@ -806,7 +808,7 @@ mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource( 3 ) +texture = ExtResource( 4 ) patch_margin_left = 4 patch_margin_top = 32 patch_margin_right = 4 @@ -893,7 +895,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 4 ) +texture_normal = ExtResource( 5 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Close" type="TextureButton" parent="Windows/Music/VBoxContainer/Header/HBoxContainer" index="1"] @@ -916,7 +918,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 5 ) +texture_normal = ExtResource( 6 ) _sections_unfolded = [ "Margin", "Size Flags", "Textures", "custom_constants" ] [node name="Open" type="TextureButton" parent="Windows/Music/VBoxContainer/Header/HBoxContainer" index="2"] @@ -940,7 +942,7 @@ toggle_mode = false enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 6 ) +texture_normal = ExtResource( 7 ) _sections_unfolded = [ "Size Flags", "Textures", "custom_constants" ] [node name="Label" type="Label" parent="Windows/Music/VBoxContainer/Header/HBoxContainer" index="3"] @@ -1018,7 +1020,7 @@ selection_enabled = true override_selected_font_color = false _sections_unfolded = [ "BBCode", "Rect", "Size Flags" ] -[node name="Music" parent="Windows/Music/VBoxContainer/Content" index="1" instance=ExtResource( 8 )] +[node name="Music" parent="Windows/Music/VBoxContainer/Content" index="1" instance=ExtResource( 9 )] margin_left = 8.0 margin_top = 8.0 @@ -1086,7 +1088,7 @@ action_mode = 0 enabled_focus_mode = 2 shortcut = null group = null -texture_normal = ExtResource( 7 ) +texture_normal = ExtResource( 8 ) _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ] [node name="ui_window" type="MarginContainer" parent="Windows" index="3"] @@ -1105,9 +1107,9 @@ mouse_filter = 0 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 1 -script = ExtResource( 9 ) +script = ExtResource( 10 ) __meta__ = { -"_editor_icon": ExtResource( 10 ) +"_editor_icon": ExtResource( 11 ) } is_movable = true is_resizable = true @@ -1115,7 +1117,7 @@ is_borderless = false title = "Window test" background_color = Color( 0.808594, 0.808594, 0.808594, 1 ) -[node name="Music" parent="." index="3" instance=ExtResource( 8 )] +[node name="Music" parent="." index="3" instance=ExtResource( 9 )] margin_left = 942.0 margin_right = 1024.0 @@ -1159,7 +1161,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 11 ) +script = ExtResource( 12 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/oubli" index="0"] @@ -1225,7 +1227,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 12 ) +script = ExtResource( 13 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/trauma" index="0"] @@ -1291,7 +1293,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 13 ) +script = ExtResource( 14 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/douleur" index="0"] diff --git a/scenes/GUI/HUD/WindowControl.gd b/scenes/GUI/HUD/WindowControl.gd index 172f203..959e432 100644 --- a/scenes/GUI/HUD/WindowControl.gd +++ b/scenes/GUI/HUD/WindowControl.gd @@ -4,6 +4,7 @@ export(bool) var is_movable = true export(bool) var is_resizable = true export(bool) var is_borderless = false +signal window_clicked( window ) var current_rect_size = Vector2( 0, 0 ) var current_rect_position = Vector2( -1, -1 ) @@ -28,7 +29,6 @@ func _ready(): if not is_resizable: $VBoxContainer/Footer/HBoxContainer/Resize.visible = false - func _on_Window_mouse_entered(): print("mouse_entered") @@ -85,7 +85,10 @@ func _on_Open_pressed(): func _on_Resize_pressed(): is_resizing = true -func _input( event ): +func _input( event ): + + + if is_resizable: if is_resizing and event is InputEventMouseButton and not event.pressed: is_resizing = false @@ -93,16 +96,23 @@ func _input( event ): var delta = event.relative self.rect_size += delta -func _on_Header_gui_input(ev): +func _on_Header_gui_input( event ): + + if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 : + put_above_other() + + if is_movable: - if is_moving and ev is InputEventMouseButton and not ev.pressed: + if is_moving and event is InputEventMouseButton and not event.pressed: is_moving = false - elif not is_moving and ev is InputEventMouseButton and ev.pressed: + elif not is_moving and event is InputEventMouseButton and event.pressed: is_moving = true - if ev is InputEventMouseMotion and is_moving: - var delta = ev.relative + if event is InputEventMouseMotion and is_moving: + var delta = event.relative self.rect_position += delta + + func load_from_file( config_file ): if config_file.has_section( self.name ): self.rect_position = config_file.get_value( self.name, "position" ) @@ -133,4 +143,23 @@ func save_to_file( config_file ): config_file.set_value(self.name, "opened", false) config_file.set_value(self.name, "borderless", is_borderless) - \ No newline at end of file + +func put_above_other(): +# var index = 0 +# for child in get_parent().get_children(): +# get_parent().move_child(child, index) +# index += 1 +# get_parent().move_child(self, index) + +# var parent = self.get_parent() +# var last_child = parent.get_child( parent.get_child_count()-1 ) +# if not self.is_greater_than( last_child ): +# parent.remove_child( self ) +# parent.add_child_below_node( last_child, self ) + +# self.raise() + emit_signal( "window_clicked", self ) + pass + + + diff --git a/scenes/GUI/HUD/Windows.gd b/scenes/GUI/HUD/Windows.gd new file mode 100644 index 0000000..4830532 --- /dev/null +++ b/scenes/GUI/HUD/Windows.gd @@ -0,0 +1,14 @@ +extends ReferenceRect + +func _ready(): + + for child in self.get_children(): + child.connect( "window_clicked", self, "_on_window_clicked" ) + + +func _on_window_clicked( window ): + var index = 0 + for child in self.get_children(): + self.move_child(child, index) + index += 1 + self.move_child(window, index) \ No newline at end of file