diff options
Diffstat (limited to 'src/ui')
19 files changed, 461 insertions, 72 deletions
diff --git a/src/ui/UI.tscn b/src/ui/UI.tscn deleted file mode 100644 index 79d8f93..0000000 --- a/src/ui/UI.tscn +++ /dev/null @@ -1,58 +0,0 @@ -[gd_scene load_steps=5 format=2] - -[ext_resource path="res://ui/ui.gd" type="Script" id=1] -[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_icon.png" type="Texture" id=2] -[ext_resource path="res://ui/hud/snake/scenes/SnakeHUD.tscn" type="PackedScene" id=3] -[ext_resource path="res://ui/hud/progress_bars/scenes/GrowthProgress.tscn" type="PackedScene" id=4] - -[node name="UI" type="CanvasLayer"] -script = ExtResource( 1 ) - -[node name="Root" type="Control" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 - -[node name="StatsHUD" type="MarginContainer" parent="Root"] -margin_left = 4.0 -margin_top = 4.0 -margin_right = 124.0 -margin_bottom = 44.0 - -[node name="VBox" type="VBoxContainer" parent="Root/StatsHUD"] -custom_constants/separation = 2 - -[node name="SnakeHUD" parent="Root/StatsHUD/VBox" instance=ExtResource( 3 )] -margin_right = 30.0 -margin_bottom = 8.0 - -[node name="HBoxProgressBars" type="HBoxContainer" parent="Root/StatsHUD/VBox"] -margin_top = 10.0 -margin_right = 30.0 -margin_bottom = 18.0 -custom_constants/separation = 2 - -[node name="GrowthProgressIcon" type="TextureRect" parent="Root/StatsHUD/VBox/HBoxProgressBars"] -margin_right = 8.0 -margin_bottom = 8.0 -texture = ExtResource( 2 ) - -[node name="GrowthProgress" parent="Root/StatsHUD/VBox/HBoxProgressBars" instance=ExtResource( 4 )] -margin_left = 10.0 -margin_right = 30.0 -margin_bottom = 8.0 - -[node name="MarginContainer" type="MarginContainer" parent="Root"] -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_top = -20.0 - -[node name="CenterContainer" type="CenterContainer" parent="Root/MarginContainer"] -margin_right = 320.0 -margin_bottom = 20.0 - -[node name="Start" type="Button" parent="Root/MarginContainer/CenterContainer"] -margin_left = 139.0 -margin_right = 180.0 -margin_bottom = 20.0 -text = "Start" diff --git a/src/ui/hud/HUD.tscn b/src/ui/hud/HUD.tscn new file mode 100644 index 0000000..d30f7f5 --- /dev/null +++ b/src/ui/hud/HUD.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_icon.png" type="Texture" id=2] +[ext_resource path="res://ui/hud/snake/scenes/SnakeHUD.tscn" type="PackedScene" id=3] +[ext_resource path="res://ui/hud/progress_bars/scenes/GrowthProgress.tscn" type="PackedScene" id=4] + +[node name="HUD" type="MarginContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 4.0 +margin_right = -4.0 +margin_bottom = -4.0 + +[node name="StatsHUD" type="MarginContainer" parent="."] +margin_right = 312.0 +margin_bottom = 172.0 + +[node name="VBox" type="VBoxContainer" parent="StatsHUD"] +margin_right = 312.0 +margin_bottom = 172.0 +custom_constants/separation = 2 + +[node name="SnakeHUD" parent="StatsHUD/VBox" instance=ExtResource( 3 )] +margin_right = 312.0 +margin_bottom = 8.0 + +[node name="HBoxProgressBars" type="HBoxContainer" parent="StatsHUD/VBox"] +margin_top = 10.0 +margin_right = 312.0 +margin_bottom = 18.0 +custom_constants/separation = 2 + +[node name="GrowthProgressIcon" type="TextureRect" parent="StatsHUD/VBox/HBoxProgressBars"] +margin_right = 8.0 +margin_bottom = 8.0 +texture = ExtResource( 2 ) + +[node name="GrowthProgress" parent="StatsHUD/VBox/HBoxProgressBars" instance=ExtResource( 4 )] +margin_left = 10.0 +margin_right = 30.0 +margin_bottom = 8.0 diff --git a/src/ui/main_menu/scenes/MainMenu.tscn b/src/ui/main_menu/scenes/MainMenu.tscn new file mode 100644 index 0000000..249885e --- /dev/null +++ b/src/ui/main_menu/scenes/MainMenu.tscn @@ -0,0 +1,66 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://ui/main_menu/scenes/MenuOption.tscn" type="PackedScene" id=1] +[ext_resource path="res://fonts/monogram_extended.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://ui/main_menu/scripts/main_menu.gd" type="Script" id=3] + +[sub_resource type="DynamicFont" id=1] +size = 64 +font_data = ExtResource( 2 ) + +[node name="MainMenu" type="MarginContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 3 ) +START_OPTION_NP = NodePath("Center/VBox/Options/VBox/Start") +SETTINGS_OPTION_NP = NodePath("Center/VBox/Options/VBox/Settings") +EXIT_OPTION_NP = NodePath("Center/VBox/Options/VBox/Exit") + +[node name="Center" type="CenterContainer" parent="."] +margin_right = 320.0 +margin_bottom = 180.0 + +[node name="VBox" type="VBoxContainer" parent="Center"] +margin_left = 64.0 +margin_top = 28.0 +margin_right = 256.0 +margin_bottom = 152.0 +custom_constants/separation = 16 + +[node name="Title" type="CenterContainer" parent="Center/VBox"] +margin_right = 192.0 +margin_bottom = 52.0 + +[node name="Label" type="Label" parent="Center/VBox/Title"] +margin_right = 192.0 +margin_bottom = 52.0 +custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "El Snake" + +[node name="Options" type="CenterContainer" parent="Center/VBox"] +margin_top = 68.0 +margin_right = 192.0 +margin_bottom = 124.0 + +[node name="VBox" type="VBoxContainer" parent="Center/VBox/Options"] +margin_left = 56.0 +margin_right = 136.0 +margin_bottom = 56.0 + +[node name="Start" parent="Center/VBox/Options/VBox" instance=ExtResource( 1 )] +margin_right = 80.0 +label_text = "Start" +selected = true + +[node name="Settings" parent="Center/VBox/Options/VBox" instance=ExtResource( 1 )] +margin_top = 20.0 +margin_right = 80.0 +margin_bottom = 36.0 +label_text = "Settings" + +[node name="Exit" parent="Center/VBox/Options/VBox" instance=ExtResource( 1 )] +margin_top = 40.0 +margin_right = 80.0 +margin_bottom = 56.0 +label_text = "Exit" diff --git a/src/ui/main_menu/scenes/MenuOption.tscn b/src/ui/main_menu/scenes/MenuOption.tscn new file mode 100644 index 0000000..d6bb05f --- /dev/null +++ b/src/ui/main_menu/scenes/MenuOption.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://fonts/MonogramExtended.tres" type="DynamicFont" id=2] +[ext_resource path="res://ui/main_menu/scripts/menu_option.gd" type="Script" id=3] + +[node name="MenuOption" type="CenterContainer"] +margin_right = 49.0 +margin_bottom = 16.0 +script = ExtResource( 3 ) + +[node name="HBox" type="HBoxContainer" parent="."] +margin_right = 80.0 +margin_bottom = 16.0 + +[node name="Selector" type="TextureRect" parent="HBox"] +margin_right = 16.0 +margin_bottom = 16.0 +rect_min_size = Vector2( 16, 16 ) + +[node name="Label" type="Label" parent="HBox"] +margin_left = 20.0 +margin_top = 1.0 +margin_right = 80.0 +margin_bottom = 14.0 +rect_min_size = Vector2( 60, 0 ) +custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) +custom_fonts/font = ExtResource( 2 ) diff --git a/src/ui/main_menu/scripts/main_menu.gd b/src/ui/main_menu/scripts/main_menu.gd new file mode 100644 index 0000000..7077b68 --- /dev/null +++ b/src/ui/main_menu/scripts/main_menu.gd @@ -0,0 +1,81 @@ +extends MarginContainer + +export(NodePath) var START_OPTION_NP: NodePath +export(NodePath) var SETTINGS_OPTION_NP: NodePath +export(NodePath) var EXIT_OPTION_NP: NodePath + +onready var start_option: MenuOption = get_node(START_OPTION_NP) +onready var settings_option: MenuOption = get_node(SETTINGS_OPTION_NP) +onready var exit_option: MenuOption = get_node(EXIT_OPTION_NP) + +onready var main: Node2D = get_parent().get_parent() + + +enum Option { + START, + SETTINGS, + EXIT +} + +enum { + NEXT, + PREV +} + +onready var options: Dictionary = { + Option.START: start_option, + Option.SETTINGS: settings_option, + Option.EXIT: exit_option +} + +var current_selection: int = Option.START + + +func _ready(): + Event.connect("game_start", self, "_on_game_start") + start_option.type = Option.START + settings_option.type = Option.SETTINGS + exit_option.type = Option.EXIT + + +func _input(event: InputEvent) -> void: + if event.is_action_pressed("ui_down"): + _menu_selection(NEXT) + elif event.is_action_pressed("ui_up"): + _menu_selection(PREV) + + + if event.is_action_pressed("ui_accept"): + match current_selection: + Option.START: + Event.emit_signal("game_start") + Option.SETTINGS: + print("Option TEST.") + Option.EXIT: + get_tree().quit() + + +func _menu_selection(selection: int) -> void: + match selection: + NEXT: + current_selection += 1 + if current_selection == Option.size(): + current_selection = 0 + PREV: + current_selection -= 1 + if current_selection == -1: + current_selection = Option.size() - 1 + _update_options() + + +func _update_options() -> void: + for i in options: + if i == current_selection: + options[i].selected = true + else: + options[i].selected = false + + +func _on_game_start() -> void: + print("game_start") + get_tree().change_scene_to(Global.GAME_NODE) diff --git a/src/ui/main_menu/scripts/menu_option.gd b/src/ui/main_menu/scripts/menu_option.gd new file mode 100644 index 0000000..58b4a50 --- /dev/null +++ b/src/ui/main_menu/scripts/menu_option.gd @@ -0,0 +1,35 @@ +class_name MenuOption +extends CenterContainer + +export(String) var label_text: String +export(bool) var selected: bool = false + +onready var label: Label = $HBox/Label +onready var selector: TextureRect = $HBox/Selector +var type: int + +var time_elapsed: float = 0.0 +var timer: float = 0.2 +var last_frame: int = 0 +var frames: Array = [preload("res://ui/main_menu/sprites/selector1.png"), + preload("res://ui/main_menu/sprites/selector2.png"), + preload("res://ui/main_menu/sprites/selector3.png"), + preload("res://ui/main_menu/sprites/selector4.png"), + preload("res://ui/main_menu/sprites/selector5.png")] + + +func _ready(): + label.text = label_text + + +func _process(delta: float) -> void: + if selected: + if time_elapsed >= timer: + selector.texture = frames[last_frame] + last_frame += 1 + if last_frame == frames.size() - 1: + last_frame = 0 + time_elapsed = 0.0 + time_elapsed += delta + else: + selector.texture = frames[4] diff --git a/src/ui/main_menu/sprites/selector.png b/src/ui/main_menu/sprites/selector.png Binary files differnew file mode 100644 index 0000000..48a5678 --- /dev/null +++ b/src/ui/main_menu/sprites/selector.png diff --git a/src/ui/main_menu/sprites/selector.png.import b/src/ui/main_menu/sprites/selector.png.import new file mode 100644 index 0000000..c327b8f --- /dev/null +++ b/src/ui/main_menu/sprites/selector.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector.png-bd5373564ca790ce40721086d248728a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector.png" +dest_files=[ "res://.import/selector.png-bd5373564ca790ce40721086d248728a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/main_menu/sprites/selector1.png b/src/ui/main_menu/sprites/selector1.png Binary files differnew file mode 100644 index 0000000..b516e93 --- /dev/null +++ b/src/ui/main_menu/sprites/selector1.png diff --git a/src/ui/main_menu/sprites/selector1.png.import b/src/ui/main_menu/sprites/selector1.png.import new file mode 100644 index 0000000..322198e --- /dev/null +++ b/src/ui/main_menu/sprites/selector1.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector1.png-b6d09b162403970de2678bdb1de12abb.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector1.png" +dest_files=[ "res://.import/selector1.png-b6d09b162403970de2678bdb1de12abb.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/main_menu/sprites/selector2.png b/src/ui/main_menu/sprites/selector2.png Binary files differnew file mode 100644 index 0000000..93547db --- /dev/null +++ b/src/ui/main_menu/sprites/selector2.png diff --git a/src/ui/main_menu/sprites/selector2.png.import b/src/ui/main_menu/sprites/selector2.png.import new file mode 100644 index 0000000..6bb6018 --- /dev/null +++ b/src/ui/main_menu/sprites/selector2.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector2.png-0419bb1259e0efa492a2ce8346b72d74.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector2.png" +dest_files=[ "res://.import/selector2.png-0419bb1259e0efa492a2ce8346b72d74.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/main_menu/sprites/selector3.png b/src/ui/main_menu/sprites/selector3.png Binary files differnew file mode 100644 index 0000000..0e468c2 --- /dev/null +++ b/src/ui/main_menu/sprites/selector3.png diff --git a/src/ui/main_menu/sprites/selector3.png.import b/src/ui/main_menu/sprites/selector3.png.import new file mode 100644 index 0000000..17be43b --- /dev/null +++ b/src/ui/main_menu/sprites/selector3.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector3.png-e7eb1264fbb84184dcddc29017bcfac0.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector3.png" +dest_files=[ "res://.import/selector3.png-e7eb1264fbb84184dcddc29017bcfac0.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/main_menu/sprites/selector4.png b/src/ui/main_menu/sprites/selector4.png Binary files differnew file mode 100644 index 0000000..7d2ee70 --- /dev/null +++ b/src/ui/main_menu/sprites/selector4.png diff --git a/src/ui/main_menu/sprites/selector4.png.import b/src/ui/main_menu/sprites/selector4.png.import new file mode 100644 index 0000000..5cb135e --- /dev/null +++ b/src/ui/main_menu/sprites/selector4.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector4.png-c3312c451267db277e5279e15c3e9dc2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector4.png" +dest_files=[ "res://.import/selector4.png-c3312c451267db277e5279e15c3e9dc2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/main_menu/sprites/selector5.png b/src/ui/main_menu/sprites/selector5.png Binary files differnew file mode 100644 index 0000000..5e4988e --- /dev/null +++ b/src/ui/main_menu/sprites/selector5.png diff --git a/src/ui/main_menu/sprites/selector5.png.import b/src/ui/main_menu/sprites/selector5.png.import new file mode 100644 index 0000000..9282f51 --- /dev/null +++ b/src/ui/main_menu/sprites/selector5.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/selector5.png-57a6bf00d882484ef5ce3c35f8ecea76.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/main_menu/sprites/selector5.png" +dest_files=[ "res://.import/selector5.png-57a6bf00d882484ef5ce3c35f8ecea76.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/ui/ui.gd b/src/ui/ui.gd deleted file mode 100644 index 1ceff2f..0000000 --- a/src/ui/ui.gd +++ /dev/null @@ -1,14 +0,0 @@ -class_name UI -extends CanvasLayer - -onready var _start_button: Button = $Root/MarginContainer/CenterContainer/Start - - -func _ready(): - _start_button.connect("pressed", self, "_on_start_button_pressed") - - -func _on_start_button_pressed() -> void: - _start_button.disabled = true - _start_button.visible = false - Event.emit_signal("game_start") |