Added weapon selection
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
class_name WeaponSelectionScreen
|
||||
extends Control
|
||||
|
||||
|
||||
signal weapon_selected(weapon_data: WeaponData)
|
||||
|
||||
|
||||
const WEAPON_SELECTOR = preload("res://menu/ingame/weapon_selector.tscn")
|
||||
|
||||
|
||||
@export var world_data : WorldData:
|
||||
set = _set_world_data
|
||||
|
||||
|
||||
@onready var weapon_selectors : Control = $%WeaponSelectors
|
||||
|
||||
|
||||
func _set_world_data(data: WorldData) -> void:
|
||||
world_data = data
|
||||
|
||||
for child in weapon_selectors.get_children():
|
||||
child.queue_free()
|
||||
|
||||
if world_data == null: return
|
||||
|
||||
var selectors : Array[WeaponSelector] = []
|
||||
for weapon_data in world_data.player_start_weapons:
|
||||
var selector : WeaponSelector = WEAPON_SELECTOR.instantiate()
|
||||
weapon_selectors.add_child(selector)
|
||||
selector.weapon_data = weapon_data
|
||||
selectors.append(selector)
|
||||
selector.weapon_selected.connect(_on_weapon_selected)
|
||||
|
||||
if selectors.size() > 0:
|
||||
selectors[0].button.grab_focus()
|
||||
|
||||
|
||||
func _on_weapon_selected(weapon_data: WeaponData) -> void:
|
||||
weapon_selected.emit(weapon_data)
|
||||
@@ -0,0 +1 @@
|
||||
uid://6isk1tmc2ik1
|
||||
@@ -0,0 +1,38 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cv122gw47cnun"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://6isk1tmc2ik1" path="res://menu/ingame/weapon_selection_screen.gd" id="1_hl2ql"]
|
||||
|
||||
[node name="WeaponSelectionScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_hl2ql")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 640.0
|
||||
offset_bottom = 360.0
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_top = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
theme_override_constants/margin_bottom = 16
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
text = "Select your first weapon"
|
||||
|
||||
[node name="WeaponSelectors" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
alignment = 1
|
||||
@@ -0,0 +1,25 @@
|
||||
class_name WeaponSelector
|
||||
extends Control
|
||||
|
||||
|
||||
signal weapon_selected(weapon_data: WeaponData)
|
||||
|
||||
|
||||
@export var weapon_data: WeaponData:
|
||||
set = _set_weapon_data
|
||||
|
||||
|
||||
@onready var name_label : Label = $%NameLabel
|
||||
@onready var button : Button = $%Button
|
||||
|
||||
|
||||
func _set_weapon_data(data: WeaponData) -> void:
|
||||
weapon_data = data
|
||||
|
||||
if weapon_data == null: return
|
||||
|
||||
name_label.text = weapon_data.name
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
weapon_selected.emit(weapon_data)
|
||||
@@ -0,0 +1 @@
|
||||
uid://beiydi6w6gqqc
|
||||
@@ -0,0 +1,32 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://1o3idp54lil2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://beiydi6w6gqqc" path="res://menu/ingame/weapon_selector.gd" id="1_4acia"]
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://images/menu_button.tres" id="2_g83h6"]
|
||||
|
||||
[node name="WeaponSelector" type="MarginContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_4acia")
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_g83h6")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="NameLabel" type="Label" parent="MarginContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_g83h6")
|
||||
horizontal_alignment = 1
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
||||
Reference in New Issue
Block a user