From b628c92c1adfdc4a53c2b22db9d7bea254265fe0 Mon Sep 17 00:00:00 2001 From: antoine giego Date: Sun, 21 Jul 2019 19:48:47 +0200 Subject: [PATCH] menu de selection des personnages : begin --- .../OwnedCheckButton.gd | 35 ++++++++ .../Scenes/MainMenu.tscn | 13 ++- .../Scenes/OwnedCheckButton.tscn | 27 +++++++ .../Scenes/Selection.gd | 79 +++++++++++++++++++ .../Scenes/Selection.tscn | 51 ++++++++++++ .../Scripts/MainMenu.gd | 14 ++-- .../Scripts/Selection.gd | 17 ++++ 7 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/OwnedCheckButton.gd create mode 100644 Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/OwnedCheckButton.tscn create mode 100644 Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.gd create mode 100644 Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.tscn create mode 100644 Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/Selection.gd diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/OwnedCheckButton.gd b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/OwnedCheckButton.gd new file mode 100644 index 0000000..9f0ffaf --- /dev/null +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/OwnedCheckButton.gd @@ -0,0 +1,35 @@ +extends Control + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +onready var colorRect = get_node("ColorRect") +onready var checkButton = get_node("CheckButton") +onready var colorPicker = get_node("ColorPickerButton") + +signal owner_set +signal owner_unset + +var player = "" + +# Called when the node enters the scene tree for the first time. +func _ready(): + var random = RandomNumberGenerator.new() + random.randomize() + colorRect.set_frame_color(Color(random.randi())) + colorPicker.set_pick_color(colorRect.get_frame_color()) + +func _on_CheckButton_toggled(button_pressed): + if button_pressed : + emit_signal("owner_set", self) + else : + emit_signal("owner_unset", self) + +func set_player(value): + player = value + +func get_player(): + return player + +func _on_ColorPickerButton_color_changed(color): + colorRect.set_frame_color(color) diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/MainMenu.tscn b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/MainMenu.tscn index 4cbaf31..68f1106 100644 --- a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/MainMenu.tscn +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/MainMenu.tscn @@ -10,7 +10,6 @@ script = ExtResource( 1 ) [node name="Menu" type="Node2D" parent="."] -editor/display_folded = true [node name="Smash" type="Button" parent="Menu"] margin_left = 466.0 @@ -40,8 +39,17 @@ margin_right = 617.0 margin_bottom = 446.0 text = "Quit" +[node name="Selection" type="Button" parent="Menu"] +margin_left = 446.331 +margin_top = 564.971 +margin_right = 640.331 +margin_bottom = 622.971 +text = "Sélection des personnages" +clip_text = true + [node name="Options menu" type="Node2D" parent="."] editor/display_folded = true +visible = false [node name="Musique" type="RichTextLabel" parent="Options menu"] margin_left = 491.0 @@ -100,6 +108,7 @@ text = "Retour" [node name="Lobby" parent="." instance=ExtResource( 2 )] editor/display_folded = true +visible = false [node name="BeforeConnection" type="MarginContainer" parent="Lobby"] editor/display_folded = true @@ -234,6 +243,7 @@ mouse_default_cursor_shape = 0 [node name="controls_ui" parent="." instance=ExtResource( 5 )] editor/display_folded = true +visible = false [node name="Node" parent="controls_ui" index="1"] editor/display_folded = true @@ -282,6 +292,7 @@ one_shot = true [connection signal="focus_entered" from="Menu/Quit" to="." method="_on_Quit_focus_entered"] [connection signal="focus_exited" from="Menu/Quit" to="." method="_on_Quit_focus_exited"] [connection signal="pressed" from="Menu/Quit" to="." method="_on_Quit_pressed"] +[connection signal="pressed" from="Menu/Selection" to="." method="_on_Selection_pressed"] [connection signal="value_changed" from="Options menu/Volume Musique" to="." method="_on_Volume_value_changed"] [connection signal="value_changed" from="Options menu/Volume Effets" to="." method="_on_Volume_Effets_value_changed"] [connection signal="pressed" from="Options menu/Commandes" to="." method="_on_Commandes_pressed"] diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/OwnedCheckButton.tscn b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/OwnedCheckButton.tscn new file mode 100644 index 0000000..fa1f5e8 --- /dev/null +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/OwnedCheckButton.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://OwnedCheckButton.gd" type="Script" id=1] + +[node name="OwnedCheckButton" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -1184.0 +margin_bottom = -663.0 +rect_min_size = Vector2( 96, 57 ) +script = ExtResource( 1 ) + +[node name="ColorRect" type="ColorRect" parent="."] +margin_right = 80.0 +margin_bottom = 40.0 + +[node name="CheckButton" type="CheckButton" parent="."] +margin_right = 76.0 +margin_bottom = 40.0 + +[node name="ColorPickerButton" type="ColorPickerButton" parent="."] +margin_left = 66.3421 +margin_top = 31.8442 +margin_right = 89.3421 +margin_bottom = 51.8442 +[connection signal="toggled" from="CheckButton" to="." method="_on_CheckButton_toggled"] +[connection signal="color_changed" from="ColorPickerButton" to="." method="_on_ColorPickerButton_color_changed"] diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.gd b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.gd new file mode 100644 index 0000000..45b0fb2 --- /dev/null +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.gd @@ -0,0 +1,79 @@ +extends Node2D + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var OwnedCheckButton = preload("res://Scenes/OwnedCheckButton.tscn") +var n_selectables = 0 +var characters_path = "res://Scenes/Characters/" +onready var grid_selectables = get_node("GridContainer") +onready var player_container = get_node("HBoxContainer") + +var characters_selectable_spritesheet = preload("res://Sprites/ProtoChar/Stand.png") + +var n_player = 4 + +# Called when the node enters the scene tree for the first time. +func _ready(): + var files = list_files_in_directory(characters_path) + var tscn_files = [] + for file in files : + if file.ends_with(".tscn") : + tscn_files.append(file.replace(".tscn","")) + n_selectables = tscn_files.size() + grid_selectables.set_columns(n_selectables) + for file in tscn_files : + var charac_button = TextureButton.new() + charac_button.connect("pressed", self, "on_character_pressed", [charac_button, file]) + charac_button.set_normal_texture(characters_selectable_spritesheet) + grid_selectables.add_child(charac_button) + for id in Input.get_connected_joypads() : + add_player(id) + for child in player_container.get_children(): + child.connect("owner_set",self,"on_owner_set",[child]) + child.connect("owner_unset",self,"on_owner_unset",[child]) + +func _input(event): + print(event.device) + +func on_character_pressed(button, file_name): + print(file_name) + +func on_owner_set(ownedCheckButton): + pass + +func on_owner_unset(ownedCheckButton): + pass + +func _on_Button_pressed(): + get_tree().change_scene("res://Scenes/MainMenu.tscn") + +func add_player(value=""): + var button = OwnedCheckButton.instance() + button.set_player(value) + player_container.add_child(button) + +func remove_player(): + player_container.remove_child(player_container.get_children()[-1]) + +func list_files_in_directory(path): + var files = [] + var dir = Directory.new() + dir.open(path) + dir.list_dir_begin() + while true: + var file = dir.get_next() + if file == "": + break + elif not file.begins_with("."): + files.append(file) + return files + +func _on_Button2_pressed(): + add_player() + +func _on_Button3_pressed(): + remove_player() + +func _on_Button4_pressed(): + get_tree().change_scene("res://Scenes/Instancing_Test.tscn") diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.tscn b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.tscn new file mode 100644 index 0000000..12220ce --- /dev/null +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scenes/Selection.tscn @@ -0,0 +1,51 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Scenes/Selection.gd" type="Script" id=1] + +[node name="Selection" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Button" type="Button" parent="."] +margin_left = 409.996 +margin_top = 596.906 +margin_right = 700.996 +margin_bottom = 705.906 +text = "Retour" + +[node name="Button4" type="Button" parent="."] +margin_left = 719.653 +margin_top = 589.353 +margin_right = 1010.65 +margin_bottom = 698.353 +text = "Smash" + +[node name="GridContainer" type="GridContainer" parent="."] +margin_left = 226.101 +margin_top = 66.323 +margin_right = 898.101 +margin_bottom = 435.323 + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_left = 183.211 +margin_top = 483.012 +margin_right = 915.211 +margin_bottom = 589.012 +rect_scale = Vector2( 1, 0.843615 ) + +[node name="Button2" type="Button" parent="."] +margin_left = 946.0 +margin_top = 483.0 +margin_right = 970.0 +margin_bottom = 509.0 +text = "+" + +[node name="Button3" type="Button" parent="."] +margin_left = 946.0 +margin_top = 520.05 +margin_right = 970.0 +margin_bottom = 546.05 +text = "-" +[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] +[connection signal="pressed" from="Button4" to="." method="_on_Button4_pressed"] +[connection signal="pressed" from="Button2" to="." method="_on_Button2_pressed"] +[connection signal="pressed" from="Button3" to="." method="_on_Button3_pressed"] diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/MainMenu.gd b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/MainMenu.gd index aae078e..0b20a49 100644 --- a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/MainMenu.gd +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/MainMenu.gd @@ -24,7 +24,11 @@ const main_btns = { }, "Menu/Quit":{ "down":"Menu/Smash", - "up":"Menu/Options" + "up":"Menu/Selection" + }, + "Menu/Selection":{ + "down":"Menu/Smash", + "up":"Menu/Quit", } } @@ -340,9 +344,6 @@ func _on_Commandes_pressed(): func _on_Smash_pressed(): get_tree().change_scene("res://Scenes/Instancing_Test.tscn") - pass # replace with function body - - func _on_Retour_b_pressed(): get_node("controls_ui").visible=false @@ -354,4 +355,7 @@ func _on_Retour_b_pressed(): get_node(current_focused_button).grab_focus() btns = options_btns - pass # replace with function body + + +func _on_Selection_pressed(): + get_tree().change_scene("res://Scenes/Selection.tscn") diff --git a/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/Selection.gd b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/Selection.gd new file mode 100644 index 0000000..1092761 --- /dev/null +++ b/Menu-X-Smash-Engine 3.1/Godot-Smash-Engine-master/Scripts/Selection.gd @@ -0,0 +1,17 @@ +extends Node2D + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + + +func _on_Button_toggled(button_pressed): + get_tree().change_scene("res://Scenes/MainMenu.tscn")