Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVR-213 Implement some parts of inventory #104

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/Saver-22b-godot/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
43 changes: 43 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/Inventory.gd
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/Kind.gd
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/Slot.gd
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class_name SlotModel;

var title: String;
var icon: String;
var count: int;
36 changes: 36 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/inventory.tscn
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/kind.tscn
Original file line number Diff line number Diff line change
@@ -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")
23 changes: 23 additions & 0 deletions frontend/Saver-22b-godot/scenes/inventory/slot.tscn
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions frontend/Saver-22b-godot/scripts/global/inventory.gd
Original file line number Diff line number Diff line change
@@ -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)
Loading