diff --git a/addons/ui_window/icon.png b/addons/ui_window/icon.png new file mode 100644 index 0000000..71d2090 Binary files /dev/null and b/addons/ui_window/icon.png differ diff --git a/addons/ui_window/plugin.cfg b/addons/ui_window/plugin.cfg new file mode 100644 index 0000000..5b9d606 --- /dev/null +++ b/addons/ui_window/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="UI Window" +description="A custom window control." +author="Osquallo" +version="1.0.0" +script="ui_window_plugin.gd" \ No newline at end of file diff --git a/addons/ui_window/ui_window.gd b/addons/ui_window/ui_window.gd new file mode 100644 index 0000000..b593b6f --- /dev/null +++ b/addons/ui_window/ui_window.gd @@ -0,0 +1,326 @@ +extends MarginContainer + +export(bool) var is_movable = true +export(bool) var is_resizable = true +export(bool) var is_borderless = false +export(String) var title = "Window" +export(Color) var background_color = Color( 1.0, 1.0, 1.0, 1.0 ) +var current_rect_size = Vector2( 0, 0 ) +var current_rect_position = Vector2( -1, -1 ) +var is_resizing = false +var is_moving = false + +func _ready(): + + ### + # self + self.size_flags_horizontal = SIZE_EXPAND + self.size_flags_vertical = SIZE_EXPAND + + self.set( "custom_constants/margin_right", 0) + self.set( "custom_constants/margin_top", 0) + self.set( "custom_constants/margin_left", 0) + self.set( "custom_constants/margin_bottom", 0) + ### + ### + # Background + var background = NinePatchRect.new() + background.name = "Background" + var background_image = Image.new() + if not background_image.load( "res://assets/GUI/images/bg2.jpg" ): + print("Errur lors du chargement de l'image: res://assets/GUI/images/bg2.jpg" ) + background.texture = ImageTexture.new() + background.texture.create_from_image( background_image ) + + background.axis_stretch_horizontal = NinePatchRect.AXIS_STRETCH_MODE_TILE + background.axis_stretch_vertical = NinePatchRect.AXIS_STRETCH_MODE_TILE + + background.size_flags_horizontal = SIZE_EXPAND_FILL + background.size_flags_vertical = SIZE_EXPAND_FILL + + background.region_rect = Rect2( 0, 0, 0, 0 ) + background.patch_margin_left = 4 + background.patch_margin_top = 32 + background.patch_margin_right = 4 + background.patch_margin_bottom = 3 + + background.self_modulate = background_color + + self.add_child( background ) + background.set_owner( self ) + ### + + ### + # VBoxContainer + var v_box_container = VBoxContainer.new() + v_box_container.name = "VBoxContainer" + v_box_container.size_flags_horizontal = SIZE_EXPAND_FILL + v_box_container.size_flags_vertical = SIZE_EXPAND_FILL + self.add_child( v_box_container ) + v_box_container.set_owner( self ) + ### + + ### + # Header + var header = MarginContainer.new() + header.name = "Header" + header.size_flags_horizontal = SIZE_EXPAND_FILL + header.size_flags_vertical = SIZE_SHRINK_CENTER + + header.set( "custom_constants/margin_right", 0) + header.set( "custom_constants/margin_top", 4) + header.set( "custom_constants/margin_left", 4) + header.set( "custom_constants/margin_bottom", 4) + + header.mouse_default_cursor_shape = CURSOR_MOVE + v_box_container.add_child( header ) + header.set_owner( v_box_container ) + header.connect ( "gui_input", self, "_on_Header_gui_input" ) + ### + ### + # Header/HBoxContainer + var header_box = HBoxContainer.new() + header_box.name = "HBoxContainer" + header_box.size_flags_horizontal = SIZE_EXPAND_FILL + header_box.size_flags_vertical = SIZE_EXPAND | SIZE_SHRINK_CENTER + header.mouse_default_cursor_shape = CURSOR_MOVE + header.add_child( header_box ) + header_box.set_owner( header ) + ### + ### + # Quit + var quit_button = TextureButton.new() + quit_button.name = "Quit" + quit_button.size_flags_horizontal = SIZE_SHRINK_END + quit_button.size_flags_vertical = SIZE_SHRINK_CENTER + + var tex_quit = ImageTexture.new() + var img_quit = Image.new() + img_quit.load( "res://assets/GUI/images/button_quit.png" ) + tex_quit.create_from_image( img_quit ) + quit_button.texture_normal = tex_quit + + header_box.add_child( quit_button ) + quit_button.set_owner( header_box ) + quit_button.connect ( "pressed", self, "_on_Quit_pressed" ) + ### + # Close + var close_button = TextureButton.new() + close_button.name = "Close" + close_button.size_flags_horizontal = SIZE_SHRINK_END + close_button.size_flags_vertical = SIZE_SHRINK_CENTER + + var tex_close = ImageTexture.new() + var img_close = Image.new() + img_close.load( "res://assets/GUI/images/button_close.png" ) + tex_close.create_from_image( img_close ) + close_button.texture_normal = tex_close + + header_box.add_child( close_button ) + close_button.set_owner( header_box ) + close_button.connect ( "pressed", self, "_on_Close_pressed" ) + ### + # Open + var open_button = TextureButton.new() + open_button.name = "Open" + open_button.size_flags_horizontal = SIZE_SHRINK_END + open_button.size_flags_vertical = SIZE_SHRINK_CENTER + + var tex_open = ImageTexture.new() + var img_open = Image.new() + img_open.load( "res://assets/GUI/images/button_open.png" ) + tex_open.create_from_image( img_open ) + open_button.texture_normal = tex_open + open_button.visible = false + header_box.add_child( open_button ) + open_button.set_owner( header_box ) + open_button.connect ( "pressed", self, "_on_Open_pressed" ) + ### + ### + # Title Label + var title_label = Label.new() + title_label.name = "Label" + title_label.text = title + title_label.size_flags_horizontal = SIZE_EXPAND_FILL + title_label.size_flags_vertical = SIZE_SHRINK_CENTER + title_label.mouse_default_cursor_shape = CURSOR_MOVE + header_box.add_child( title_label ) + title_label.set_owner( header_box ) + ### + ### + # Content + var content = MarginContainer.new() + content.name = "Content" + content.size_flags_horizontal = SIZE_EXPAND_FILL + content.size_flags_vertical = SIZE_EXPAND_FILL + content.set( "custom_constants/margin_right", 8) + content.set( "custom_constants/margin_top", 8) + content.set( "custom_constants/margin_left", 8) + content.set( "custom_constants/margin_bottom", 8) + v_box_container.add_child( content ) + content.set_owner( v_box_container ) + ### + ### + # Footer + var footer = MarginContainer.new() + footer.name = "Footer" + footer.size_flags_horizontal = SIZE_FILL + footer.size_flags_vertical = SIZE_FILL + footer.set( "custom_constants/margin_right", 6) + footer.set( "custom_constants/margin_top", 2) + footer.set( "custom_constants/margin_left", 6) + footer.set( "custom_constants/margin_bottom", 6) + v_box_container.add_child( footer ) + footer.set_owner( v_box_container ) + ### + ### + # Header/HBoxContainer + var footer_box = HBoxContainer.new() + footer_box.name = "HBoxContainer" + footer_box.size_flags_horizontal = SIZE_FILL + footer_box.size_flags_vertical = SIZE_FILL + footer.add_child( footer_box ) + footer_box.set_owner( footer ) + ### + ### + # Open + var resize_button = TextureButton.new() + resize_button.name = "Resize" + resize_button.size_flags_horizontal = SIZE_EXPAND | SIZE_SHRINK_END + resize_button.size_flags_vertical = SIZE_EXPAND + + var tex_resize = ImageTexture.new() + var img_resize = Image.new() + img_resize.load( "res://assets/GUI/images/button_resize.png" ) + tex_resize.create_from_image( img_resize ) + resize_button.texture_normal = tex_resize + resize_button.mouse_default_cursor_shape = CURSOR_FDIAGSIZE + resize_button.action_mode = Button.ACTION_MODE_BUTTON_PRESS + footer_box.add_child( resize_button ) + resize_button.set_owner( footer_box ) + resize_button.connect ( "pressed", self, "_on_Resize_pressed" ) + ### + + current_rect_size = self.rect_min_size + + if is_borderless: + $Background.region_rect = Rect2( 3, 28+3, 512-6, 512-28-6 ) + $VBoxContainer/Header/HBoxContainer/Close.visible = false + $VBoxContainer/Header/HBoxContainer/Open.visible = false + $VBoxContainer/Header/HBoxContainer/Quit.visible = false + $VBoxContainer/Header/HBoxContainer/Label.visible = false +# else: +# $Background.region_rect = Rect2( 0, 0, 512, 512 ) +# $VBoxContainer/Header/HBoxContainer/Close.visible = true +# $VBoxContainer/Header/HBoxContainer/Open.visible = false +# $VBoxContainer/Header/HBoxContainer/Quit.visible = true +# $VBoxContainer/Header/HBoxContainer/Label.visible = true + if not is_resizable: + $VBoxContainer/Footer/HBoxContainer/Resize.visible = false + + +func _on_Window_mouse_entered(): + print("mouse_entered") + + +func _on_Window_focus_entered(): + print("focus_entered") + + +func _on_Quit_pressed(): + self.visible = false + +func get_content(): + return $VBoxContainer/Content + + + +func close(): + if not is_borderless: + $VBoxContainer/Header/HBoxContainer/Close.visible = false + $VBoxContainer/Header/HBoxContainer/Open.visible = true + $VBoxContainer/Content.visible = false + $VBoxContainer/Footer.visible = false + current_rect_size = self.rect_size + self.rect_size = Vector2( 0, 0 ) + else: + $VBoxContainer/Header/HBoxContainer/Close.visible = false + $VBoxContainer/Header/HBoxContainer/Open.visible = false + $VBoxContainer/Content.visible = false + $VBoxContainer/Footer.visible = false + current_rect_size = self.rect_size + self.rect_size = Vector2( 0, 0 ) + + +func _on_Close_pressed(): + close() + +func open(): + if not is_borderless: + $VBoxContainer/Header/HBoxContainer/Close.visible = true + $VBoxContainer/Header/HBoxContainer/Open.visible = false + $VBoxContainer/Content.visible = true + $VBoxContainer/Footer.visible = true + self.rect_size = current_rect_size + else: + $VBoxContainer/Header/HBoxContainer/Close.visible = false + $VBoxContainer/Header/HBoxContainer/Open.visible = false + $VBoxContainer/Content.visible = true + $VBoxContainer/Footer.visible = true + self.rect_size = current_rect_size + +func _on_Open_pressed(): + open() + +func _on_Resize_pressed(): + is_resizing = true + +func _input( event ): + if is_resizable: + if is_resizing and event is InputEventMouseButton and not event.pressed: + is_resizing = false + if event is InputEventMouseMotion and is_resizing: + var delta = event.relative + self.rect_size += delta + +func _on_Header_gui_input(ev): + if is_movable: + if is_moving and ev is InputEventMouseButton and not ev.pressed: + is_moving = false + elif not is_moving and ev is InputEventMouseButton and ev.pressed: + is_moving = true + if ev is InputEventMouseMotion and is_moving: + var delta = ev.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" ) + self.rect_size = config_file.get_value( self.name, "size" ) + self.is_borderless = config_file.get_value( self.name, "borderless" ) + current_rect_position = self.rect_position + current_rect_size = self.rect_size + if config_file.get_value( self.name, "opened" ): + open() + else: + close() + + +func save_to_file( config_file ): + + var is_open = $VBoxContainer/Content.visible + + config_file.set_value(self.name, "position", self.rect_position) + + if not is_open: + config_file.set_value(self.name, "size", current_rect_size) + else: + config_file.set_value(self.name, "size", self.rect_size) + + if is_open: + config_file.set_value(self.name, "opened", true) + else: + config_file.set_value(self.name, "opened", false) + + config_file.set_value(self.name, "borderless", is_borderless) + \ No newline at end of file diff --git a/addons/ui_window/ui_window_plugin.gd b/addons/ui_window/ui_window_plugin.gd new file mode 100644 index 0000000..74c09e5 --- /dev/null +++ b/addons/ui_window/ui_window_plugin.gd @@ -0,0 +1,12 @@ +tool +extends EditorPlugin + +func _enter_tree(): + # Initialization of the plugin goes here + # Add the new type with a name, a parent type, a script and an icon + add_custom_type("ui_window", "MarginContainer", preload("ui_window.gd"), preload("icon.png")) + +func _exit_tree(): + # Clean-up of the plugin goes here + # Always remember to remove it from the engine when deactivated + remove_custom_type("ui_window") \ No newline at end of file diff --git a/project.godot b/project.godot index 6f895b1..5e2ce36 100644 --- a/project.godot +++ b/project.godot @@ -22,7 +22,7 @@ window/size/test_height=600 [editor_plugins] -enabled=PoolStringArray( "input_map_button" ) +enabled=PoolStringArray( "input_map_button", "ui_window" ) [input] diff --git a/scenes/GUI/HUD/HUD.tscn b/scenes/GUI/HUD/HUD.tscn index c5f3c9f..e9851da 100644 --- a/scenes/GUI/HUD/HUD.tscn +++ b/scenes/GUI/HUD/HUD.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=14 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] @@ -8,11 +8,13 @@ [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://scenes/GUI/HUD/oubli.gd" type="Script" id=9] -[ext_resource path="res://scenes/GUI/HUD/trauma.gd" type="Script" id=10] -[ext_resource path="res://scenes/GUI/HUD/douleur.gd" type="Script" id=11] +[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] -[node name="HUD" type="MarginContainer"] +[node name="HUD" type="MarginContainer" index="0"] anchor_left = 0.0 anchor_top = 0.0 @@ -113,7 +115,6 @@ is_borderless = false [node name="Background" type="NinePatchRect" parent="Windows/Test" index="0"] -self_modulate = Color( 0.21875, 0.157921, 0.157921, 1 ) anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -133,11 +134,10 @@ patch_margin_right = 4 patch_margin_bottom = 4 axis_stretch_horizontal = 1 axis_stretch_vertical = 1 -_sections_unfolded = [ "Axis Stretch", "Material", "Patch Margin", "Rect", "Size Flags", "Theme", "Visibility" ] +_sections_unfolded = [ "Axis Stretch", "Material", "Mouse", "Patch Margin", "Rect", "Size Flags", "Theme", "Visibility" ] [node name="VBoxContainer" type="VBoxContainer" parent="Windows/Test" index="1"] -editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -152,7 +152,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 custom_constants/separation = 0 alignment = 0 -_sections_unfolded = [ "Rect", "Size Flags", "Visibility", "custom_constants" ] +_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "Visibility", "custom_constants" ] [node name="Header" type="MarginContainer" parent="Windows/Test/VBoxContainer" index="0"] @@ -172,11 +172,10 @@ custom_constants/margin_right = 4 custom_constants/margin_top = 4 custom_constants/margin_left = 4 custom_constants/margin_bottom = 4 -_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ] +_sections_unfolded = [ "Margin", "Mouse", "Rect", "Size Flags", "custom_constants" ] [node name="HBoxContainer" type="HBoxContainer" parent="Windows/Test/VBoxContainer/Header" index="0"] -editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -339,7 +338,6 @@ _sections_unfolded = [ "BBCode", "Rect", "Size Flags" ] [node name="Footer" type="MarginContainer" parent="Windows/Test/VBoxContainer" index="2"] -editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -357,7 +355,7 @@ custom_constants/margin_right = 6 custom_constants/margin_top = 2 custom_constants/margin_left = 6 custom_constants/margin_bottom = 6 -_sections_unfolded = [ "custom_constants" ] +_sections_unfolded = [ "Size Flags", "custom_constants" ] [node name="HBoxContainer" type="HBoxContainer" parent="Windows/Test/VBoxContainer/Footer" index="0"] @@ -376,6 +374,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 1 alignment = 0 +_sections_unfolded = [ "Mouse", "Size Flags" ] [node name="Resize" type="TextureButton" parent="Windows/Test/VBoxContainer/Footer/HBoxContainer" index="0"] @@ -434,7 +433,6 @@ is_borderless = true [node name="Background" type="NinePatchRect" parent="Windows/TestBorderless" index="0"] -self_modulate = Color( 0.21875, 0.157921, 0.157921, 1 ) anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -606,6 +604,7 @@ _sections_unfolded = [ "Hint", "Mouse", "Size Flags" ] [node name="Content" type="MarginContainer" parent="Windows/TestBorderless/VBoxContainer" index="1"] +editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -796,7 +795,6 @@ is_borderless = true [node name="Background" type="NinePatchRect" parent="Windows/Music" index="0"] -self_modulate = Color( 0.21875, 0.157921, 0.157921, 1 ) anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -838,6 +836,7 @@ _sections_unfolded = [ "Rect", "Size Flags", "Visibility", "custom_constants" ] [node name="Header" type="MarginContainer" parent="Windows/Music/VBoxContainer" index="0"] +editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -850,7 +849,7 @@ mouse_filter = 0 mouse_default_cursor_shape = 13 size_flags_horizontal = 1 size_flags_vertical = 0 -custom_constants/margin_right = 4 +custom_constants/margin_right = 0 custom_constants/margin_top = 4 custom_constants/margin_left = 4 custom_constants/margin_bottom = 4 @@ -858,13 +857,14 @@ _sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ] [node name="HBoxContainer" type="HBoxContainer" parent="Windows/Music/VBoxContainer/Header" index="0"] +editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 4.0 margin_top = 4.0 -margin_right = 125.0 +margin_right = 129.0 margin_bottom = 20.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -952,7 +952,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 40.0 margin_top = 1.0 -margin_right = 121.0 +margin_right = 125.0 margin_bottom = 15.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -968,6 +968,7 @@ _sections_unfolded = [ "Hint", "Mouse", "Size Flags" ] [node name="Content" type="MarginContainer" parent="Windows/Music/VBoxContainer" index="1"] +editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -1027,6 +1028,7 @@ margin_bottom = 74.0 [node name="Footer" type="MarginContainer" parent="Windows/Music/VBoxContainer" index="2"] +editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -1088,6 +1090,32 @@ group = null texture_normal = ExtResource( 7 ) _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ] +[node name="ui_window" type="MarginContainer" parent="Windows" index="3"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 534.0 +margin_top = 175.0 +margin_right = 986.0 +margin_bottom = 527.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +script = ExtResource( 9 ) +__meta__ = { +"_editor_icon": ExtResource( 10 ) +} +is_movable = true +is_resizable = true +is_borderless = false +title = "Window test !!!!!" +background_color = Color( 0.496094, 0.496094, 0.496094, 1 ) + [node name="Music" parent="." index="3" instance=ExtResource( 8 )] margin_left = 942.0 @@ -1132,7 +1160,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 9 ) +script = ExtResource( 11 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/oubli" index="0"] @@ -1198,7 +1226,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 10 ) +script = ExtResource( 12 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/trauma" index="0"] @@ -1264,7 +1292,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 9 alignment = 0 -script = ExtResource( 11 ) +script = ExtResource( 13 ) _sections_unfolded = [ "Size Flags", "Visibility" ] [node name="ProgressBar" type="ProgressBar" parent="Jauges/douleur" index="0"] diff --git a/scenes/GUI/Settings/Settings.tscn b/scenes/GUI/Settings/Settings.tscn index c1b165e..199a839 100644 --- a/scenes/GUI/Settings/Settings.tscn +++ b/scenes/GUI/Settings/Settings.tscn @@ -148,7 +148,7 @@ use_filter = false font_data = ExtResource( 2 ) _sections_unfolded = [ "Font", "Settings" ] -[node name="Settings" type="MarginContainer" index="0"] +[node name="Settings" type="MarginContainer"] anchor_left = 0.0 anchor_top = 0.0 @@ -618,7 +618,6 @@ _sections_unfolded = [ "Size Flags" ] [node name="Controles" type="VBoxContainer" parent="Menus/TabContainer" index="1"] -editor/display_folded = true visible = false anchor_left = 0.0 anchor_top = 0.0 diff --git a/scenes/Main.tscn b/scenes/Main.tscn index f5b4f9a..3ef210f 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://scenes/Game/Game.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/GUI/GUI.tscn" type="PackedScene" id=3] -[node name="Main" type="Node" index="0"] +[node name="Main" type="Node"] script = ExtResource( 1 ) _sections_unfolded = [ "Pause" ]