From 2c08f3de95e7013add99ac91133087c90c2d4cc2 Mon Sep 17 00:00:00 2001 From: moreal Date: Wed, 20 Dec 2023 20:13:28 +0900 Subject: [PATCH] Implement Inventory --- frontend/Saver-22b-godot/project.godot | 1 + .../scenes/inventory/Inventory.gd | 43 +++++++++++++++++++ .../Saver-22b-godot/scenes/inventory/Kind.gd | 18 ++++++++ .../Saver-22b-godot/scenes/inventory/Slot.gd | 14 ++++++ .../scenes/inventory/SlotModel.gd | 5 +++ .../scenes/inventory/inventory.tscn | 36 ++++++++++++++++ .../scenes/inventory/kind.tscn | 27 ++++++++++++ .../scenes/inventory/slot.tscn | 23 ++++++++++ .../scripts/global/inventory.gd | 9 ++++ 9 files changed, 176 insertions(+) create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Inventory.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Kind.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Slot.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/inventory.tscn create mode 100644 frontend/Saver-22b-godot/scenes/inventory/kind.tscn create mode 100644 frontend/Saver-22b-godot/scenes/inventory/slot.tscn create mode 100644 frontend/Saver-22b-godot/scripts/global/inventory.gd diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index fad1888e..50f721d6 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -21,6 +21,7 @@ config/icon="res://icon.svg" GlobalSigner="*res://scripts/sign/Signer.gd" SvrGqlClient="*res://gql/svr_gql_client.gd" SceneContext="*res://scripts/global/scene_context.gd" +GlobalInventory="*res://scripts/global/inventory.gd" [display] diff --git a/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd b/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd new file mode 100644 index 00000000..45b2ed72 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd @@ -0,0 +1,43 @@ +extends Node + +class_name Inventory; + +const kind_scene = preload("res://scenes/inventory/kind.tscn"); +const slot_scene = preload("res://scenes/inventory/slot.tscn"); + +# Input: +# Godot이 지원하지 않아서 주석으로 타입을 남깁니다. +# Dictionary[String, Array[SlotModel]] +var data: Dictionary; + +# State: +var current_kind: String; + +# Derived: +var kinds: Array; +var current_slots: Array; + +# Called when the node enters the scene tree for the first time. +func _ready(): + assert (data.size() > 0); + + kinds = data.keys(); + current_kind = kinds[0] + current_slots = data[current_kind]; + + for kind in kinds: + var kind_instance := kind_scene.instantiate() + kind_instance.title = kind + kind_instance.enabled = kind == current_kind + $"./ColorRect/VBoxContainer/Kinds".add_child(kind_instance) + + for slot in current_slots: + var slot_instance := slot_scene.instantiate() + slot_instance.title = slot.title + slot_instance.icon = slot.icon + slot_instance.count = slot.count + $"./ColorRect/VBoxContainer/Slots".add_child(slot_instance) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/Kind.gd b/frontend/Saver-22b-godot/scenes/inventory/Kind.gd new file mode 100644 index 00000000..d66dff7f --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Kind.gd @@ -0,0 +1,18 @@ +extends Node + +var title: String; +var enabled: bool; + +# Called when the node enters the scene tree for the first time. +func _ready(): + $"./Label".set_text(title) + if enabled: + $Label.label_settings.set_font_color(Color(255, 255, 255)) + $ColorRect.set_color(Color(0, 0, 0)) + else: + $Label.label_settings.set_font_color(Color(0, 0, 0)) + $ColorRect.set_color(Color(255, 255, 255)) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/Slot.gd b/frontend/Saver-22b-godot/scenes/inventory/Slot.gd new file mode 100644 index 00000000..0a93ae96 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Slot.gd @@ -0,0 +1,14 @@ +extends Node + +var title: String; +var icon: String; +var count: int; + +# Called when the node enters the scene tree for the first time. +func _ready(): + $Title.set_text("%s - %d" % [title, count]) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd b/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd new file mode 100644 index 00000000..ed3c9928 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd @@ -0,0 +1,5 @@ +class_name SlotModel; + +var title: String; +var icon: String; +var count: int; diff --git a/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn b/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn new file mode 100644 index 00000000..6ae5583c --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=2 format=3 uid="uid://riiie4g746ea"] + +[ext_resource type="Script" path="res://scenes/inventory/Inventory.gd" id="1_swc55"] + +[node name="Inventory" type="Control"] +custom_minimum_size = Vector2(1000, 700) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_swc55") + +[node name="ColorRect" type="ColorRect" parent="."] +custom_minimum_size = Vector2(1000, 800) +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect"] +custom_minimum_size = Vector2(1000, 800) +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Kinds" type="HBoxContainer" parent="ColorRect/VBoxContainer"] +custom_minimum_size = Vector2(1000, 200) +layout_mode = 2 + +[node name="Slots" type="GridContainer" parent="ColorRect/VBoxContainer"] +custom_minimum_size = Vector2(1000, 500) +layout_mode = 2 + +[node name="CloseButton" type="TextureButton" parent="ColorRect/VBoxContainer"] +layout_mode = 2 diff --git a/frontend/Saver-22b-godot/scenes/inventory/kind.tscn b/frontend/Saver-22b-godot/scenes/inventory/kind.tscn new file mode 100644 index 00000000..f0c75567 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/kind.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://bjmiaawy6ktrp"] + +[ext_resource type="Script" path="res://scenes/inventory/Kind.gd" id="1_y1brs"] + +[sub_resource type="LabelSettings" id="LabelSettings_4vsh2"] + +[node name="Kind" type="Control"] +custom_minimum_size = Vector2(200, 100) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_y1brs") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 +color = Color(0.2, 0.2, 0.2, 1) + +[node name="Label" type="Label" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +label_settings = SubResource("LabelSettings_4vsh2") diff --git a/frontend/Saver-22b-godot/scenes/inventory/slot.tscn b/frontend/Saver-22b-godot/scenes/inventory/slot.tscn new file mode 100644 index 00000000..b6d8bd5b --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/slot.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=2 format=3 uid="uid://b86kl35ac31iq"] + +[ext_resource type="Script" path="res://scenes/inventory/Slot.gd" id="1_jurhm"] + +[node name="Slot" type="Control"] +custom_minimum_size = Vector2(100, 100) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_jurhm") + +[node name="Title" type="RichTextLabel" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Count" type="RichTextLabel" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 diff --git a/frontend/Saver-22b-godot/scripts/global/inventory.gd b/frontend/Saver-22b-godot/scripts/global/inventory.gd new file mode 100644 index 00000000..925eca88 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/global/inventory.gd @@ -0,0 +1,9 @@ +extends Node + +const inventory_scene = preload("res://scenes/inventory/inventory.tscn"); + +func open_inventory(data: Dictionary): + var inventory_instance := inventory_scene.instantiate() + inventory_instance.data = data; + + get_tree().root.add_child(inventory_instance)