Skip to content

Commit

Permalink
feat: trade shop sell list implement
Browse files Browse the repository at this point in the history
  • Loading branch information
kth1888 committed May 26, 2024
1 parent 41677cd commit adc978b
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 16 deletions.
28 changes: 28 additions & 0 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,31 @@ var register_trade_good_query = GQLQuery.new("createAction_RegisterTradeGoodActi
"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"
])
])
])
16 changes: 12 additions & 4 deletions 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 @@ -131,15 +131,23 @@ var register_trade_good_query_executor = SvrGqlClient.query(
{
"publicKey": "String!",
"price": "Int!",
"foodStateId": "Int!",
"itemStateIds": "Int!"
"foodStateId": "Guid",
"itemStateIds": "[Guid]"
},
gql_query.uninstall_kitchen_equipment_query
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):
print(data) # 지워야함
var unsigned_tx = data["data"][data["data"].keys()[0]]
var signature = GlobalSigner.sign(unsigned_tx)
mutation_executor.run({
Expand Down
48 changes: 41 additions & 7 deletions frontend/Savor-22b/scenes/market/market.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Control

signal query_received

const TradeInventoryScn = preload("res://scenes/market/trade_inventory.tscn")
const SellListScn = preload("res://scenes/market/sell_list.tscn")

Expand All @@ -9,44 +11,76 @@ const SellListScn = preload("res://scenes/market/sell_list.tscn")
var query_executor = QueryExecutor.new()
var register_trade_good_query_executor
var stage_tx_mutation_executor
var trade_inventory_state_executor

var inventory_state


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


load_initial_scene()
test_register()

print(inventory_state)


func load_initial_scene():
load_inventory()
load_sell_list()

query_trade_inventory_state()
query_received.connect(load_sell_list)


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

func load_sell_list():
var sell_list = SellListScn.instantiate()
sell_list_container.add_child(sell_list)
print(inventory_state)
if (inventory_state != null):
var sell_list = SellListScn.instantiate()
sell_list_container.add_child(sell_list)
sell_list.set_list(inventory_state)





func test_register():
var food_id = "0cffada3-dccf-48ee-942c-2617ac46952b"
query_executor.stage_action(
{
"publicKey": GlobalSigner.signer.GetPublicKey(),
"price": 10,
"foodStateId": "8ef2aa23-3595-4036-9ee9-7802d4663891",
"price": 150,
"foodStateId": food_id,
"itemStateIds": []
},
register_trade_good_query_executor,
stage_tx_mutation_executor
)

func query_action(query_executor): # query with no args
query_executor.graphql_response.connect(
func(data):
inventory_state = data["data"]["tradeInventoryState"]["tradeGoods"]
query_received.emit()
)
query_executor.run({})

func query_trade_inventory_state():
query_action(
trade_inventory_state_executor
)

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


func _on_test_button_down():
test_register()
5 changes: 5 additions & 0 deletions frontend/Savor-22b/scenes/market/market.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ grow_horizontal = 2
grow_vertical = 2

[node name="Title" type="Label" parent="Background"]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
Expand Down Expand Up @@ -73,6 +74,9 @@ size_flags_vertical = 0
theme_override_font_sizes/font_size = 50
text = " 마을로 "

[node name="TestButton" type="Button" parent="VBoxContainer/MarginContainer2/TopMenuHBoxContainer"]
layout_mode = 2

[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
custom_minimum_size = Vector2(1920, 950)
layout_mode = 2
Expand All @@ -97,3 +101,4 @@ theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50

[connection signal="button_down" from="VBoxContainer/MarginContainer2/TopMenuHBoxContainer/VillageButton" to="." method="_on_village_button_down"]
[connection signal="button_down" from="VBoxContainer/MarginContainer2/TopMenuHBoxContainer/TestButton" to="." method="_on_test_button_down"]
28 changes: 28 additions & 0 deletions frontend/Savor-22b/scenes/market/posted_item.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends Control

#@onready var food_name = $M/V/Name
#@onready var food_description = $M/V/Desc

@onready var item_button = $ItemSelectButton
@onready var description_label = $BackgroundPanel/MarginContainer/VBoxContainer/DescriptionLabel

var info
var desc_format_string = "%s : %s
%s : %s%s
%s : %s"

func _ready():
_update_info()

func _update_info():
if description_label == null:
return
description_label.text = desc_format_string % ["품목명",info.food["name"],"가격",info.price," BBG","게시자",info.sellerAddress]


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


func _on_item_select_button_down():
print(info)
11 changes: 8 additions & 3 deletions frontend/Savor-22b/scenes/market/posted_item.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://crw3yutudcodf"]
[gd_scene load_steps=4 format=3 uid="uid://crw3yutudcodf"]

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

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3bs65"]
bg_color = Color(0, 0, 0, 1)
Expand All @@ -20,7 +22,7 @@ corner_radius_bottom_right = 15
corner_radius_bottom_left = 15

[node name="PostedItem" type="Control"]
custom_minimum_size = Vector2(380, 410)
custom_minimum_size = Vector2(410, 410)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
Expand All @@ -29,6 +31,7 @@ offset_right = -1540.0
offset_bottom = -670.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_3mj4d")

[node name="BackgroundPanel" type="Panel" parent="."]
layout_mode = 1
Expand Down Expand Up @@ -60,8 +63,10 @@ layout_mode = 2
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_font_sizes/font_size = 40
text = "품목명 : 참치
가격 : 10
게시자 : 맛도리 해적단
게시 마을 : 외로운 섬"
"
text_overrun_behavior = 1

[node name="BuyButton" type="Button" parent="BackgroundPanel/MarginContainer/VBoxContainer"]
layout_mode = 2
Expand Down
45 changes: 45 additions & 0 deletions frontend/Savor-22b/scenes/market/sell_list.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends Control

const PostedItemScn = preload("res://scenes/market/posted_item.tscn")

@onready var list_container = $MarginContainer/VBoxContainer/ListPanel/ScrollContainer/MarginContainer/CenterContainer/GridContainer

var goods
var my_address = GlobalSigner.signer_address

func _ready():
pass

func set_list(data: Array):
goods = data
load_list()


func load_list():
clear_list_panel()

for good in goods:
if(good["sellerAddress"] != my_address):
add_lists(good)


func _on_my_sell_list_button_down():
clear_list_panel()

for good in goods:
if(good["sellerAddress"] == my_address):
add_lists(good)

func clear_list_panel():
if is_instance_valid(list_container):
for posted_item in list_container.get_children():
posted_item.queue_free()

func add_lists(good: Dictionary):
var posted_item_scene = PostedItemScn.instantiate()
posted_item_scene.set_info(good)
list_container.add_child(posted_item_scene)


func _on_whole_sell_list_button_down():
load_list()
22 changes: 20 additions & 2 deletions frontend/Savor-22b/scenes/market/sell_list.tscn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://bu43d13qwmtcr"]
[gd_scene load_steps=7 format=3 uid="uid://bu43d13qwmtcr"]

[ext_resource type="Script" path="res://scenes/market/sell_list.gd" id="1_n5ek1"]
[ext_resource type="ButtonGroup" uid="uid://di66p0jb8cdpk" path="res://scenes/market/sell_list_button_group.tres" id="1_vyf2b"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4l2s6"]
Expand Down Expand Up @@ -29,6 +30,7 @@ offset_right = -700.0
offset_bottom = -130.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_n5ek1")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
Expand Down Expand Up @@ -83,5 +85,21 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

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

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

[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer/ListPanel/ScrollContainer/MarginContainer/CenterContainer"]
layout_mode = 2
theme_override_constants/h_separation = 50
theme_override_constants/v_separation = 50
columns = 2

[connection signal="button_down" from="MarginContainer/VBoxContainer/HBoxContainer/WholeSellListButton" to="." method="_on_whole_sell_list_button_down"]
[connection signal="button_down" from="MarginContainer/VBoxContainer/HBoxContainer/MySellListButton" to="." method="_on_my_sell_list_button_down"]
1 change: 1 addition & 0 deletions frontend/Savor-22b/scenes/village/village_view.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ theme_override_font_sizes/font_size = 70
text = " 내 밭으로 가기 "

[node name="MarketButtonContainer" type="ColorRect" parent="TopMenuMarginContainer/Control"]
layout_mode = 0
offset_left = 920.0
offset_right = 1370.0
offset_bottom = 100.0
Expand Down

0 comments on commit adc978b

Please sign in to comment.