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

[무역 상점] 인벤토리 및 판매목록 구현 #190

Merged
merged 6 commits into from
May 29, 2024
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
35 changes: 35 additions & 0 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,38 @@ var uninstall_kitchen_equipment_query = GQLQuery.new("createAction_UninstallKitc
"publicKey": "publicKey",
"spaceNumber": "spaceNumber"
});

var register_trade_good_query = GQLQuery.new("createAction_RegisterTradeGoodAction").set_args({
"publicKey": "publicKey",
"price": "price",
"foodStateId": "foodStateId",
"itemStateIds": "itemStateIds"
});

var trade_inventory_state_query = GQLQuery.new("tradeInventoryState").set_props([
GQLQuery.new("tradeGoods").set_props([
"sellerAddress",
"productStateId",
"price",
"type",
GQLQuery.new("food").set_props([
"stateId",
"ingredientId",
"foodID",
"name",
"grade",
"hp",
"attack",
"defense",
"speed",
"isSuperFood",
"level",
"isAvailable"
]),
GQLQuery.new("items").set_props([
"stateID",
"itemID",
"itemName"
])
])
])
21 changes: 20 additions & 1 deletion frontend/Savor-22b/gql/query_executor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var plant_seed_query_executor = SvrGqlClient.query(
{
"publicKey": "String!",
"fieldIndex": "Int!",
"itemStateIdToUse": "Int!"
"itemStateIdToUse": "Guid!"
},
gql_query.plant_seed_query
);
Expand Down Expand Up @@ -125,6 +125,25 @@ var uninstall_kitchen_equipment_query_executor = SvrGqlClient.query(
gql_query.uninstall_kitchen_equipment_query
);


var register_trade_good_query_executor = SvrGqlClient.query(
'RegisterTradeGood',
{
"publicKey": "String!",
"price": "Int!",
"foodStateId": "Guid",
"itemStateIds": "[Guid]"
},
gql_query.register_trade_good_query
);

var trade_inventory_state_executor = SvrGqlClient.query(
'tradeInventoryState',
{},
gql_query.trade_inventory_state_query
);


func stage_action(params, query_executor, mutation_executor):
query_executor.graphql_response.connect(
func(data):
Expand Down
3 changes: 3 additions & 0 deletions frontend/Savor-22b/scenes/farm/farm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,6 @@ func _on_refresh_button_down():

func _on_home_button_down():
get_tree().change_scene_to_file("res://scenes/house/house.tscn")

func _on_market_button_down():
get_tree().change_scene_to_file("res://scenes/market/market.tscn")
7 changes: 7 additions & 0 deletions frontend/Savor-22b/scenes/farm/farm.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
text = "부엌으로"

[node name="MarketButton" type="Button" parent="MC/HC/VBoxContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
text = "무역 상점"

[node name="InventoryButton" type="Button" parent="MC/HC/VBoxContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 0
Expand All @@ -112,4 +118,5 @@ offset_right = 40.0
offset_bottom = 40.0

[connection signal="button_down" from="MC/HC/VBoxContainer/MarginContainer/VBoxContainer/HomeButton" to="." method="_on_home_button_down"]
[connection signal="button_down" from="MC/HC/VBoxContainer/MarginContainer/VBoxContainer/MarketButton" to="." method="_on_market_button_down"]
[connection signal="button_down" from="MC/HC/VBoxContainer/MarginContainer/VBoxContainer/RefreshButton" to="." method="_on_refresh_button_down"]
1 change: 0 additions & 1 deletion frontend/Savor-22b/scenes/house/cook/cook_book.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://bb0hth2o7k30q"]

[ext_resource type="Script" path="res://scenes/house/cook/cook_book.gd" id="1_q1ejr"]
[ext_resource type="Script" path="res://scenes/house/recipe_book/recipe_book.gd" id="1_2wc5e"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tvose"]
bg_color = Color(0.94902, 0.694118, 0.0784314, 1)
Expand Down
2 changes: 1 addition & 1 deletion frontend/Savor-22b/scenes/house/food.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ func _update_info():

func set_info(info: Dictionary):
self.info = info


3 changes: 3 additions & 0 deletions frontend/Savor-22b/scenes/house/house.gd
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func _on_farm_button_down():
func _on_village_button_down():
get_tree().change_scene_to_file("res://scenes/village/village_view.tscn")

func _on_market_button_down():
get_tree().change_scene_to_file("res://scenes/market/market.tscn")

func _on_refresh_button_down():
clear_popup()
reload_sub_scene()
Expand Down
24 changes: 16 additions & 8 deletions frontend/Savor-22b/scenes/house/house.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ offset_right = 40.0
offset_bottom = 23.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 60
text = " 집 화면"
text = " 집 "

[node name="M" type="MarginContainer" parent="."]
layout_mode = 1
Expand All @@ -56,47 +56,54 @@ theme_override_constants/margin_bottom = 20
custom_minimum_size = Vector2(500, 2.08165e-12)
layout_mode = 2
size_flags_horizontal = 8
columns = 5
columns = 6

[node name="FarmButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
theme_override_font_sizes/font_size = 45
text = "밭으로"

[node name="VillageButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
theme_override_font_sizes/font_size = 45
text = " 마을로 "

[node name="MarketButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 45
text = " 무역 상점 "

[node name="RecipeButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
theme_override_font_sizes/font_size = 45
text = " 레시피북 "

[node name="InventoryButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
theme_override_font_sizes/font_size = 45
text = " 인벤토리 "

[node name="RefreshButton" type="Button" parent="M/V/menus/V"]
custom_minimum_size = Vector2(200, 2.08165e-12)
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
theme_override_font_sizes/font_size = 45
text = " 새로고침 "

[node name="M" type="MarginContainer" parent="M/V/menus"]
layout_mode = 2
size_flags_horizontal = 0
theme_override_constants/margin_left = 250
theme_override_constants/margin_left = 100

[node name="CookButton" type="Button" parent="M/V/menus/M"]
custom_minimum_size = Vector2(380, 2.08165e-12)
Expand Down Expand Up @@ -132,6 +139,7 @@ offset_bottom = 340.0

[connection signal="button_down" from="M/V/menus/V/FarmButton" to="." method="_on_farm_button_down"]
[connection signal="button_down" from="M/V/menus/V/VillageButton" to="." method="_on_village_button_down"]
[connection signal="button_down" from="M/V/menus/V/MarketButton" to="." method="_on_market_button_down"]
[connection signal="button_down" from="M/V/menus/V/RecipeButton" to="." method="_on_recipe_button_down"]
[connection signal="button_down" from="M/V/menus/V/InventoryButton" to="." method="_on_inventory_button_down"]
[connection signal="button_down" from="M/V/menus/V/RefreshButton" to="." method="_on_refresh_button_down"]
Expand Down
38 changes: 38 additions & 0 deletions frontend/Savor-22b/scenes/market/inventory.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extends Control

const MyItemScn = preload("res://scenes/market/my_item.tscn")

@onready var inventory_container = $MarginContainer/VBoxContainer/InventoryPanel/ScrollContainer/CenterContainer/MarginContainer/GridContainer

var items
var grouped_items = {}

func _ready():
load_items()


func load_items():
items = SceneContext.user_state.inventoryState["refrigeratorStateList"]
sort_inventory_by_items()

for item in grouped_items.values():
for grade in item.values():
var item_scene = MyItemScn.instantiate()
item_scene.set_info(grade)
inventory_container.add_child(item_scene)

func sort_inventory_by_items():
for item in items:
var name = item["name"]
var grade = item["grade"]

# 이름이 존재하지 않으면 새로 추가
if not grouped_items.has(name):
grouped_items[name] = {}

# 등급이 존재하지 않으면 이름 하위에 새로 추가
if not grouped_items[name].has(grade):
grouped_items[name][grade] = []

# 아이템을 등급 배열에 추가
grouped_items[name][grade].append(item)
80 changes: 80 additions & 0 deletions frontend/Savor-22b/scenes/market/inventory.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[gd_scene load_steps=4 format=3 uid="uid://81w3i6nbxjix"]

[ext_resource type="Script" path="res://scenes/market/inventory.gd" id="1_xk4wq"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8vjfi"]
bg_color = Color(0, 0, 0, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_as0cg"]
bg_color = Color(0.94902, 0.694118, 0.243137, 1)

[node name="Inventory" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = -1220.0
offset_bottom = -130.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_xk4wq")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 3

[node name="TitlePanel" type="Panel" parent="MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(200, 70)
layout_mode = 2
size_flags_horizontal = 0
theme_override_styles/panel = SubResource("StyleBoxFlat_8vjfi")

[node name="TitleLabel" type="Label" parent="MarginContainer/VBoxContainer/TitlePanel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 40
text = "인벤토리"
horizontal_alignment = 1
vertical_alignment = 1

[node name="InventoryPanel" type="Panel" parent="MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(2.08165e-12, 750)
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_as0cg")

[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer/InventoryPanel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer/InventoryPanel/ScrollContainer"]
layout_mode = 2

[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer/InventoryPanel/ScrollContainer/CenterContainer"]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 20

[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer/InventoryPanel/ScrollContainer/CenterContainer/MarginContainer"]
layout_mode = 2
theme_override_constants/h_separation = 25
theme_override_constants/v_separation = 50
columns = 2
55 changes: 55 additions & 0 deletions frontend/Savor-22b/scenes/market/market.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
extends Control
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 이미 상점이 있고 여기는 무역상점이라 백엔드에선 TradeStore 라는 용어로 사용 중입니다 헷갈릴 수 있으니 네이밍 전체적으로 변경 부탁드립니다


signal query_received

const InventoryScn = preload("res://scenes/market/inventory.tscn")
const SellListScn = preload("res://scenes/market/trade_inventory.tscn")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SellList


@onready var inventory_container = $VBoxContainer/MarginContainer/SubMenuHBoxContainer/InventoryMarginContainer
@onready var trade_inventory_container = $VBoxContainer/MarginContainer/SubMenuHBoxContainer/SellListMarginContainer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SellList


var query_executor = QueryExecutor.new()
var stage_tx_mutation_executor
var trade_inventory_state_executor

var inventory_state

func _ready():
stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor
trade_inventory_state_executor = query_executor.trade_inventory_state_executor
add_child(stage_tx_mutation_executor)
add_child(trade_inventory_state_executor)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

띄어쓰기를 전체적으로 다 한칸씩만 하도록 해놨습니다. 파일 전체적으로 통일해주세요

load_initial_scene()

func load_initial_scene():
load_inventory()

query_trade_inventory_state()
query_received.connect(load_trade_inventory)

func load_inventory():
var inventory = InventoryScn.instantiate()
inventory_container.add_child(inventory)

func load_trade_inventory():
if (inventory_state != null):
var trade_inventory = SellListScn.instantiate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SellList

trade_inventory_container.add_child(trade_inventory)
trade_inventory.set_list(inventory_state)

func props_only_query_action(query_executor): # query with no args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 이름이 명확하지 않습니다. 또 따로 함수로 존재할 필요가 없어보입니다.
인자로 받는 query_executor가 특정한 query_executor만 사용 가능해보이고 이벤트 리스너를 등록하는 것이기 때문에 해당 함수에서 진행할 이유 또한 없습니다. 결국 해주는건 run 을 실행해주는건데 이걸 따로 해주는 함수가 필요하진 않아보입니다.

query_executor.graphql_response.connect(
func(data):
inventory_state = data["data"]["tradeInventoryState"]["tradeGoods"]
query_received.emit()
)
query_executor.run({})

func query_trade_inventory_state():
props_only_query_action(
trade_inventory_state_executor
)

func _on_village_button_down():
get_tree().change_scene_to_file("res://scenes/village/village_view.tscn")
Loading