From 117bcfe7ee523620859a497ffd787a583aa34752 Mon Sep 17 00:00:00 2001 From: Valentin Stark Date: Sun, 21 Aug 2022 20:22:43 +0200 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20du=20menu=20principal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- menu/LoadWorld.gd | 18 +++++++++++ menu/LoadWorld.tscn | 53 ++++++++++++++++++++++++++++++++ menu/MainMenu.gd | 4 +-- menu/MainMenu.tscn | 21 ++++++++----- menu/NewWorld.gd | 14 +++++++++ menu/NewWorld.tscn | 64 +++++++++++++++++++++++++++++++++++++++ theme/theme.tres | 74 +++++++++++++++++++++++++++++++++++++++++++-- utils/Global.gd | 3 +- world/game.gd | 21 +++++++------ 9 files changed, 250 insertions(+), 22 deletions(-) create mode 100644 menu/LoadWorld.gd create mode 100644 menu/LoadWorld.tscn create mode 100644 menu/NewWorld.gd create mode 100644 menu/NewWorld.tscn diff --git a/menu/LoadWorld.gd b/menu/LoadWorld.gd new file mode 100644 index 0000000..9b434ec --- /dev/null +++ b/menu/LoadWorld.gd @@ -0,0 +1,18 @@ +extends Control + + +func _ready(): + for terrain in Global.terrain.list(): + var name = terrain.name + var button = Button.new() + button.text = terrain.name + button.connect("pressed", self, "_button_pressed", [name]) + $VBoxContainer/ScrollContainer/WorldList.add_child(button) + +func _on_CancelButton_pressed(): + get_tree().change_scene("res://menu/MainMenu.tscn") + + +func _button_pressed(name): + Global.terrain_name = name + get_tree().change_scene("res://world/game.tscn") diff --git a/menu/LoadWorld.tscn b/menu/LoadWorld.tscn new file mode 100644 index 0000000..49e59ce --- /dev/null +++ b/menu/LoadWorld.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://theme/theme.tres" type="Theme" id=1] +[ext_resource path="res://menu/LoadWorld.gd" type="Script" id=2] + +[node name="LoadWorld" type="Control"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -512.0 +margin_top = -300.0 +margin_right = 512.0 +margin_bottom = 300.0 +theme = ExtResource( 1 ) +script = ExtResource( 2 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -240.0 +margin_top = -131.5 +margin_right = 240.0 +margin_bottom = 131.5 + +[node name="Title" type="Label" parent="VBoxContainer"] +margin_right = 480.0 +margin_bottom = 64.0 +text = "Charger un monde" +align = 1 + +[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"] +margin_top = 68.0 +margin_right = 480.0 +margin_bottom = 218.0 +rect_min_size = Vector2( 0, 150 ) + +[node name="WorldList" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"] + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_top = 222.0 +margin_right = 480.0 +margin_bottom = 263.0 + +[node name="CancelButton" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_right = 480.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +text = "Annuler" + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_CancelButton_pressed"] diff --git a/menu/MainMenu.gd b/menu/MainMenu.gd index 2348f08..b34cc0d 100644 --- a/menu/MainMenu.gd +++ b/menu/MainMenu.gd @@ -6,11 +6,11 @@ func _ready(): func _on_NewButton_pressed(): - get_tree().change_scene("res://world/game.tscn") + get_tree().change_scene("res://menu/NewWorld.tscn") func _on_LoadButton_pressed(): - pass # Replace with function body. + get_tree().change_scene("res://menu/LoadWorld.tscn") func _on_QuitButton_pressed(): diff --git a/menu/MainMenu.tscn b/menu/MainMenu.tscn index e447b5c..cd65497 100644 --- a/menu/MainMenu.tscn +++ b/menu/MainMenu.tscn @@ -21,26 +21,31 @@ margin_top = -74.5 margin_right = 158.0 margin_bottom = 74.5 +[node name="Title" type="Label" parent="VBoxContainer"] +margin_right = 316.0 +margin_bottom = 131.0 +text = "Societer +" +align = 1 + [node name="NewButton" type="Button" parent="VBoxContainer"] +margin_top = 135.0 margin_right = 316.0 -margin_bottom = 47.0 +margin_bottom = 176.0 theme = SubResource( 1 ) text = "Nouveau monde" -flat = true [node name="LoadButton" type="Button" parent="VBoxContainer"] -margin_top = 51.0 +margin_top = 180.0 margin_right = 316.0 -margin_bottom = 98.0 +margin_bottom = 221.0 text = "Charger un monde" -flat = true [node name="QuitButton" type="Button" parent="VBoxContainer"] -margin_top = 102.0 +margin_top = 225.0 margin_right = 316.0 -margin_bottom = 149.0 +margin_bottom = 266.0 text = "Quitter" -flat = true [connection signal="pressed" from="VBoxContainer/NewButton" to="." method="_on_NewButton_pressed"] [connection signal="pressed" from="VBoxContainer/LoadButton" to="." method="_on_LoadButton_pressed"] diff --git a/menu/NewWorld.gd b/menu/NewWorld.gd new file mode 100644 index 0000000..3f30e31 --- /dev/null +++ b/menu/NewWorld.gd @@ -0,0 +1,14 @@ +extends Control + + +func _ready(): + pass + + +func _on_CancelButton_pressed(): + get_tree().change_scene("res://menu/MainMenu.tscn") + + +func _on_CreateButton_pressed(): + Global.terrain_name = $VBoxContainer/LineEdit.text + get_tree().change_scene("res://world/game.tscn") diff --git a/menu/NewWorld.tscn b/menu/NewWorld.tscn new file mode 100644 index 0000000..6486cc1 --- /dev/null +++ b/menu/NewWorld.tscn @@ -0,0 +1,64 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://theme/theme.tres" type="Theme" id=1] +[ext_resource path="res://theme/fonts/monogram.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://menu/NewWorld.gd" type="Script" id=3] + +[sub_resource type="DynamicFont" id=1] +size = 35 +font_data = ExtResource( 2 ) + +[node name="NewWorld" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_pivot_offset = Vector2( -383, -181 ) +theme = ExtResource( 1 ) +script = ExtResource( 3 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -195.0 +margin_top = -85.0 +margin_right = 195.0 +margin_bottom = 85.0 + +[node name="Title" type="Label" parent="VBoxContainer"] +margin_right = 390.0 +margin_bottom = 64.0 +text = "Nouveau monde" +align = 1 + +[node name="Label" type="Label" parent="VBoxContainer"] +margin_top = 68.0 +margin_right = 390.0 +margin_bottom = 97.0 +custom_fonts/font = SubResource( 1 ) +text = "Nom du monde :" + +[node name="LineEdit" type="LineEdit" parent="VBoxContainer"] +margin_top = 101.0 +margin_right = 390.0 +margin_bottom = 125.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_top = 129.0 +margin_right = 390.0 +margin_bottom = 170.0 + +[node name="CreateButton" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_right = 247.0 +margin_bottom = 41.0 +text = "Nouveau monde" + +[node name="CancelButton" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_left = 251.0 +margin_right = 390.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +text = "Annuler" + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/CreateButton" to="." method="_on_CreateButton_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_CancelButton_pressed"] diff --git a/theme/theme.tres b/theme/theme.tres index 2ee92ca..6941bd0 100644 --- a/theme/theme.tres +++ b/theme/theme.tres @@ -1,4 +1,6 @@ -[gd_resource type="Theme" load_steps=3 format=2] +[gd_resource type="Theme" load_steps=21 format=2] + +[ext_resource path="res://theme/fonts/monogram.ttf" type="DynamicFontData" id=1] [sub_resource type="DynamicFontData" id=1] font_path = "res://theme/fonts/monogram.ttf" @@ -7,6 +9,74 @@ font_path = "res://theme/fonts/monogram.ttf" size = 50 font_data = SubResource( 1 ) +[sub_resource type="Gradient" id=12] +interpolation_mode = 1 +colors = PoolColorArray( 0.596078, 0.596078, 0.596078, 1, 1, 1, 1, 1 ) + +[sub_resource type="GradientTexture" id=13] +gradient = SubResource( 12 ) + +[sub_resource type="GradientTexture" id=14] + +[sub_resource type="StyleBoxTexture" id=15] +texture = SubResource( 14 ) +normal_map = SubResource( 13 ) +region_rect = Rect2( 0, 0, 2048, 1 ) + +[sub_resource type="Gradient" id=16] +interpolation_mode = 1 +colors = PoolColorArray( 0.47451, 0.47451, 0.47451, 1, 1, 1, 1, 1 ) + +[sub_resource type="GradientTexture" id=17] +gradient = SubResource( 16 ) + +[sub_resource type="StyleBoxTexture" id=18] +texture = SubResource( 17 ) +region_rect = Rect2( 0, 0, 2048, 1 ) + +[sub_resource type="Gradient" id=19] +interpolation_mode = 1 +colors = PoolColorArray( 0.266667, 0.266667, 0.266667, 1, 1, 1, 1, 1 ) + +[sub_resource type="GradientTexture" id=20] +gradient = SubResource( 19 ) + +[sub_resource type="StyleBoxTexture" id=21] +texture = SubResource( 20 ) +region_rect = Rect2( 0, 0, 2048, 1 ) + +[sub_resource type="Gradient" id=6] +interpolation_mode = 1 +colors = PoolColorArray( 0.47451, 0.47451, 0.47451, 1, 1, 1, 1, 1 ) + +[sub_resource type="GradientTexture" id=7] +gradient = SubResource( 6 ) + +[sub_resource type="StyleBoxTexture" id=5] +texture = SubResource( 7 ) +region_rect = Rect2( 0, 0, 2048, 1 ) + +[sub_resource type="Gradient" id=9] +interpolation_mode = 1 +colors = PoolColorArray( 0.239216, 0.239216, 0.239216, 1, 1, 1, 1, 1 ) + +[sub_resource type="GradientTexture" id=10] +gradient = SubResource( 9 ) + +[sub_resource type="StyleBoxTexture" id=11] +texture = SubResource( 10 ) +region_rect = Rect2( 0, 0, 2048, 1 ) + +[sub_resource type="DynamicFont" id=8] +size = 80 +font_data = ExtResource( 1 ) + [resource] -Button/colors/font_color_hover = Color( 0.819608, 0.211765, 0.211765, 1 ) +Button/colors/font_color_hover = Color( 0.854902, 0.439216, 0.439216, 1 ) Button/fonts/font = SubResource( 2 ) +Button/styles/disabled = SubResource( 15 ) +Button/styles/focus = SubResource( 18 ) +Button/styles/hover = SubResource( 21 ) +Button/styles/normal = SubResource( 5 ) +Button/styles/pressed = SubResource( 11 ) +Label/fonts/font = SubResource( 8 ) diff --git a/utils/Global.gd b/utils/Global.gd index 59cc6a7..67c7fcf 100644 --- a/utils/Global.gd +++ b/utils/Global.gd @@ -1,7 +1,8 @@ extends Node var debug = true -var terrain +var terrain_name = "" +var terrain = Terrain.new() # Debuging messages func print_debug(message): diff --git a/world/game.gd b/world/game.gd index 4dc2ac6..2c99216 100644 --- a/world/game.gd +++ b/world/game.gd @@ -23,18 +23,23 @@ func _ready(): noise.seed = rng.randi() noise.octaves = octaves - var terrain_name="bonjour90" - terrain = Terrain.new() + # var Global.terrain_name="bonjour90" + terrain = Global.terrain print(terrain.list()) - if terrain.exists(terrain_name): - terrain.load(terrain_name) + if terrain.exists(Global.terrain_name): + terrain.load(Global.terrain_name) else: - terrain.create(width,height,spacing,terrain_name) + terrain.create(width,height,spacing,Global.terrain_name) + - if terrain.is_created() or terrain.is_loaded(): + if terrain.is_created(): init_data() + terrain.save_data() + + if terrain.is_created() or terrain.is_loaded(): + add_trees() emit_signal("world_loaded", terrain) else: @@ -58,9 +63,7 @@ func init_data(): # point.set_data("coast", point_is_coast(point)) # if point.get_data("river"): # set_river_path(point) - var triangles = 0 for triangle in terrain.get_triangles(): - triangles += 1 triangle.set_elevation(find_elevation(triangle.center2d())) # triangle.set_data("elevation", triangle_find_elevation(triangle)) triangle.set_data("water", triangle_is_water(triangle)) @@ -76,7 +79,7 @@ func init_data(): # for edge in terrain.get_edges(): # edge.set_data("coast", edge_is_coast(edge)) # edge.set_data("river", edge_is_river(edge)) - print(triangles) + func fill_oceans(): var stack = [] for point in terrain.get_points():