add animations and train selector logic
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
class_name ArrowButton
|
||||
|
||||
signal on_pressed
|
||||
|
||||
@export var image: Texture:
|
||||
set(value):
|
||||
image = value
|
||||
@@ -19,3 +23,7 @@ func _ready():
|
||||
$%Texture.texture = image
|
||||
$%Texture.flip_h = flip_h
|
||||
|
||||
|
||||
func _on_gui_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
on_pressed.emit()
|
||||
|
||||
@@ -34,3 +34,5 @@ metadata/_edit_use_anchors_ = true
|
||||
[node name="HooverTween" parent="." unique_id=2115829120 node_paths=PackedStringArray("detector_node", "visual_node") instance=ExtResource("3_hu4cn")]
|
||||
detector_node = NodePath("..")
|
||||
visual_node = NodePath("../Texture")
|
||||
|
||||
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
class_name TrainColorPicker
|
||||
|
||||
signal on_color_selected(color_picker: TrainColorPicker)
|
||||
|
||||
@export var image: Texture:
|
||||
set(value):
|
||||
image = value
|
||||
@@ -9,6 +13,8 @@ extends Control
|
||||
|
||||
@onready var color: Color
|
||||
|
||||
var selected: bool = false
|
||||
|
||||
func _ready():
|
||||
if image != null and has_node("%Texture"):
|
||||
$%Texture.texture = image
|
||||
@@ -17,3 +23,18 @@ func _ready():
|
||||
color = img.get_pixel(0, 0)
|
||||
else:
|
||||
color = Color.BLACK
|
||||
|
||||
|
||||
func _on_gui_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
on_color_selected.emit(self)
|
||||
|
||||
|
||||
func select() -> void:
|
||||
selected = true
|
||||
$%Border.color.a = 1
|
||||
|
||||
|
||||
func deselect() -> void:
|
||||
selected = false
|
||||
$%Border.color.a = 0
|
||||
|
||||
@@ -15,9 +15,25 @@ grow_vertical = 2
|
||||
script = ExtResource("2_323rd")
|
||||
image = ExtResource("1_us0rx")
|
||||
|
||||
[node name="Texture" type="TextureRect" parent="." unique_id=329703623]
|
||||
[node name="Border" type="ColorRect" parent="." unique_id=1774696864]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -30.0
|
||||
offset_top = -30.0
|
||||
offset_right = 30.0
|
||||
offset_bottom = 30.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
pivot_offset_ratio = Vector2(0.5, 0.5)
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Texture" type="TextureRect" parent="Border" unique_id=329703623]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(53, 53)
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
@@ -36,4 +52,6 @@ texture = ExtResource("1_us0rx")
|
||||
|
||||
[node name="HooverTween" parent="." unique_id=160227524 node_paths=PackedStringArray("detector_node", "visual_node") instance=ExtResource("3_264kt")]
|
||||
detector_node = NodePath("..")
|
||||
visual_node = NodePath("../Texture")
|
||||
visual_node = NodePath("../Border")
|
||||
|
||||
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
|
||||
|
||||
@@ -16,9 +16,6 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Background" parent="." index="0" unique_id=1203110384]
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="ChooseyourtrainText" type="TextureRect" parent="." index="1" unique_id=1883940124]
|
||||
layout_mode = 0
|
||||
offset_left = 350.0
|
||||
@@ -29,10 +26,10 @@ texture = ExtResource("3_t5hmd")
|
||||
|
||||
[node name="TrainSelector" parent="." index="2" unique_id=1039769375 instance=ExtResource("3_ijm38")]
|
||||
layout_mode = 0
|
||||
offset_left = 246.0
|
||||
offset_left = 211.0
|
||||
offset_top = 469.0
|
||||
offset_right = 814.0
|
||||
offset_bottom = 758.0
|
||||
offset_right = 871.0
|
||||
offset_bottom = 778.0
|
||||
|
||||
[node name="ChooseyourbiomeText" type="TextureRect" parent="." index="3" unique_id=1133714914]
|
||||
layout_mode = 0
|
||||
|
||||
38
core/game_menu/train_selector.gd
Normal file
38
core/game_menu/train_selector.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends VBoxContainer
|
||||
|
||||
@onready var color_pickers: Array[TrainColorPicker] = [$%ColorPicker1, $%ColorPicker2, $%ColorPicker3, $%ColorPicker4, $%ColorPicker5, $%ColorPicker6]
|
||||
@onready var left_arrow: ArrowButton = $%ArrowButtonLeft
|
||||
@onready var right_arrow: ArrowButton = $%ArrowButtonRight
|
||||
var selected_color: Color
|
||||
var selected_color_index: int = 0
|
||||
|
||||
func _ready() -> void:
|
||||
for color_picker in color_pickers:
|
||||
color_picker.on_color_selected.connect(_on_color_selected)
|
||||
color_picker.deselect()
|
||||
|
||||
selected_color = color_pickers[0].color
|
||||
color_pickers[0].select()
|
||||
|
||||
left_arrow.on_pressed.connect(_select_prev_color)
|
||||
right_arrow.on_pressed.connect(_select_next_color)
|
||||
|
||||
func _on_color_selected(selected_color_picker: TrainColorPicker) -> void:
|
||||
for i in range(color_pickers.size()):
|
||||
if color_pickers[i].color == selected_color_picker.color:
|
||||
selected_color_picker.select()
|
||||
selected_color_index = i
|
||||
else:
|
||||
color_pickers[i].deselect()
|
||||
|
||||
func _select_prev_color() -> void:
|
||||
for color_picker in color_pickers:
|
||||
color_picker.deselect()
|
||||
selected_color_index = (selected_color_index - 1 + color_pickers.size()) % color_pickers.size()
|
||||
color_pickers[selected_color_index].select()
|
||||
|
||||
func _select_next_color() -> void:
|
||||
for color_picker in color_pickers:
|
||||
color_picker.deselect()
|
||||
selected_color_index = (selected_color_index + 1) % color_pickers.size()
|
||||
color_pickers[selected_color_index].select()
|
||||
1
core/game_menu/train_selector.gd.uid
Normal file
1
core/game_menu/train_selector.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://8k1msabobhks
|
||||
@@ -1,5 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://bh1kxsp5jyxfx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://8k1msabobhks" path="res://core/game_menu/train_selector.gd" id="1_puip6"]
|
||||
[ext_resource type="Texture2D" uid="uid://cqvani6n2h3fw" path="res://core/game_menu/assets/page_1/train_texture.png" id="1_wfiis"]
|
||||
[ext_resource type="PackedScene" uid="uid://dm3skv22c60tm" path="res://core/game_menu/arrow_button.tscn" id="2_puip6"]
|
||||
[ext_resource type="PackedScene" uid="uid://ch1st1oryjoio" path="res://core/game_menu/color_picker.tscn" id="3_i2rs1"]
|
||||
@@ -10,8 +11,9 @@
|
||||
[ext_resource type="Texture2D" uid="uid://d4l5ih723j3md" path="res://core/game_menu/assets/page_1/customizecolor-2.png" id="8_tuh6m"]
|
||||
|
||||
[node name="TrainSelector" type="VBoxContainer" unique_id=1039769375]
|
||||
offset_right = 568.0
|
||||
offset_bottom = 289.0
|
||||
offset_right = 625.0
|
||||
offset_bottom = 309.0
|
||||
script = ExtResource("1_puip6")
|
||||
|
||||
[node name="TrainTexture" type="TextureRect" parent="." unique_id=2095010706]
|
||||
layout_mode = 2
|
||||
@@ -22,6 +24,7 @@ stretch_mode = 3
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ArrowButtonLeft" parent="HBoxContainer2" unique_id=103192648 instance=ExtResource("2_puip6")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
flip_h = true
|
||||
|
||||
@@ -29,34 +32,47 @@ flip_h = true
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 18
|
||||
|
||||
[node name="ColorPicker" parent="HBoxContainer2/HBoxContainer" unique_id=59169767 instance=ExtResource("3_i2rs1")]
|
||||
[node name="ColorPicker1" parent="HBoxContainer2/HBoxContainer" unique_id=59169767 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
image = ExtResource("4_cfvtr")
|
||||
|
||||
[node name="ColorPicker2" parent="HBoxContainer2/HBoxContainer" unique_id=584054476 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
image = ExtResource("5_jnto8")
|
||||
|
||||
[node name="ColorPicker3" parent="HBoxContainer2/HBoxContainer" unique_id=889429149 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
image = ExtResource("6_dxnpq")
|
||||
|
||||
[node name="ColorPicker4" parent="HBoxContainer2/HBoxContainer" unique_id=466686411 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
image = ExtResource("7_d1sdr")
|
||||
|
||||
[node name="ColorPicker5" parent="HBoxContainer2/HBoxContainer" unique_id=675841518 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="ColorPicker6" parent="HBoxContainer2/HBoxContainer" unique_id=1698412911 instance=ExtResource("3_i2rs1")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(60, 60)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
image = ExtResource("8_tuh6m")
|
||||
|
||||
[node name="ArrowButtonRight" parent="HBoxContainer2" unique_id=68298624 instance=ExtResource("2_puip6")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
Reference in New Issue
Block a user