From 2164223cc27f79298e1d3ba624d440612284afcd Mon Sep 17 00:00:00 2001 From: Tae Hyoung Kang <78776542+kth1888@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:51:14 +0900 Subject: [PATCH 1/2] feat: shop item buy query --- frontend/Savor-22b/gql/query.gd | 8 ++++++ frontend/Savor-22b/scenes/shop/systemshop.gd | 28 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/frontend/Savor-22b/gql/query.gd b/frontend/Savor-22b/gql/query.gd index 5c1979d2..ac3ef4c1 100644 --- a/frontend/Savor-22b/gql/query.gd +++ b/frontend/Savor-22b/gql/query.gd @@ -47,3 +47,11 @@ var remove_seed_query_format = "query { fieldIndex: {} ) }" + + +var buy_shop_item_query_format = "query { + createAction_BuyShopItem( + publicKey: {}, + desiredShopItemID: {} + ) +}" diff --git a/frontend/Savor-22b/scenes/shop/systemshop.gd b/frontend/Savor-22b/scenes/shop/systemshop.gd index ca443464..df8eb4fc 100644 --- a/frontend/Savor-22b/scenes/shop/systemshop.gd +++ b/frontend/Savor-22b/scenes/shop/systemshop.gd @@ -4,6 +4,8 @@ const ITEM = preload("res://scenes/shop/shop_item.tscn") const SHOP_ASK_POPUP = preload("res://scenes/shop/ask_popup.tscn") const SHOP_DONE_POPUP = preload("res://scenes/shop/done_popup.tscn") +const Gql_query = preload("res://gql/query.gd") + @onready var shoplist = $M/H/C/M/Lists @onready var popup = $Popups @@ -21,6 +23,7 @@ func _ready(): singleitem.set_item(item) singleitem.button_down.connect(buy_item) shoplist.add_child(singleitem) + func buy_item(): @@ -30,5 +33,30 @@ func buy_item(): popup.add_child(askpopup) +func buyquery(): + var itemnum = 1 + var gql_query = Gql_query.new() + var query_string = gql_query.buy_shop_item_query_format.format([ + "\"%s\"" % GlobalSigner.signer.GetPublicKey(), + itemnum], "{}") + print(query_string) + + var query_executor = SvrGqlClient.raw(query_string) + query_executor.graphql_response.connect(func(data): + print("gql response: ", data) + var unsigned_tx = data["data"]["createAction_BuyShopItem"] + print("unsigned tx: ", unsigned_tx) + var signature = GlobalSigner.sign(unsigned_tx) + print("signed tx: ", signature) + var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) + mutation_executor.graphql_response.connect(func(data): + print("mutation res: ", data) + ) + add_child(mutation_executor) + mutation_executor.run({}) + ) + add_child(query_executor) + query_executor.run({}) + func _on_close_button_down(): queue_free() From 91db15ed2508c8a8a1d54869b5031941ea4906a0 Mon Sep 17 00:00:00 2001 From: Tae Hyoung Kang <78776542+kth1888@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:43:13 +0900 Subject: [PATCH 2/2] feat: buy items in ui impl --- frontend/Savor-22b/Asset.gd | 1 + frontend/Savor-22b/scenes/shop/ask_popup.gd | 18 +++++++++++++--- frontend/Savor-22b/scenes/shop/done_popup.gd | 5 +++++ .../Savor-22b/scenes/shop/done_popup.tscn | 9 ++++++-- frontend/Savor-22b/scenes/shop/shop_item.gd | 6 ++++-- frontend/Savor-22b/scenes/shop/systemshop.gd | 21 +++++++++++++++++-- .../Savor-22b/scripts/global/scene_context.gd | 3 +++ frontend/Savor-22b/scripts/scenes/intro.gd | 5 ----- 8 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 frontend/Savor-22b/scenes/shop/done_popup.gd diff --git a/frontend/Savor-22b/Asset.gd b/frontend/Savor-22b/Asset.gd index 7ac9b906..637c5ed0 100644 --- a/frontend/Savor-22b/Asset.gd +++ b/frontend/Savor-22b/Asset.gd @@ -6,6 +6,7 @@ var asset var format_string = "%s : %s" func _ready(): + Intro._query_assets() asset = SceneContext.user_asset update_asset() diff --git a/frontend/Savor-22b/scenes/shop/ask_popup.gd b/frontend/Savor-22b/scenes/shop/ask_popup.gd index 4e1a7087..490149d9 100644 --- a/frontend/Savor-22b/scenes/shop/ask_popup.gd +++ b/frontend/Savor-22b/scenes/shop/ask_popup.gd @@ -2,16 +2,28 @@ extends ColorRect signal buy_button_down -func _ready(): - pass # Replace with function body. +@onready var Itemname = $M/V/Itemname + +var itemname +var format_string = "%s %s" +func _ready(): + update_info() +func update_info(): + if itemname == null: + return + + Itemname.text = format_string % [itemname, "을(를) + 구매하시겠습니까?"] func _on_buy_button_down(): buy_button_down.emit() - +func set_itemname(itemname: String): + self.itemname = itemname + func _on_cancel_button_down(): queue_free() diff --git a/frontend/Savor-22b/scenes/shop/done_popup.gd b/frontend/Savor-22b/scenes/shop/done_popup.gd new file mode 100644 index 00000000..e876a1a2 --- /dev/null +++ b/frontend/Savor-22b/scenes/shop/done_popup.gd @@ -0,0 +1,5 @@ +extends ColorRect + + +func _on_ok_button_down(): + queue_free() diff --git a/frontend/Savor-22b/scenes/shop/done_popup.tscn b/frontend/Savor-22b/scenes/shop/done_popup.tscn index d8dda168..aa50f87f 100644 --- a/frontend/Savor-22b/scenes/shop/done_popup.tscn +++ b/frontend/Savor-22b/scenes/shop/done_popup.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=2 format=3 uid="uid://e4jeslfxnied"] +[gd_scene load_steps=3 format=3 uid="uid://e4jeslfxnied"] + +[ext_resource type="Script" path="res://scenes/shop/done_popup.gd" id="1_brj1d"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xo5gb"] bg_color = Color(0, 0, 0, 1) @@ -8,6 +10,7 @@ offset_right = 600.0 offset_bottom = 200.0 pivot_offset = Vector2(-716, 741) color = Color(1, 0.541176, 0, 1) +script = ExtResource("1_brj1d") [node name="M" type="MarginContainer" parent="."] layout_mode = 1 @@ -34,9 +37,11 @@ theme_override_font_sizes/font_size = 50 text = "구매가 완료되었습니다." horizontal_alignment = 1 -[node name="Cancel" type="Button" parent="M/V"] +[node name="Ok" type="Button" parent="M/V"] layout_mode = 2 size_flags_horizontal = 4 theme_override_font_sizes/font_size = 40 theme_override_styles/normal = SubResource("StyleBoxFlat_xo5gb") text = " 확인 " + +[connection signal="button_down" from="M/V/Ok" to="." method="_on_ok_button_down"] diff --git a/frontend/Savor-22b/scenes/shop/shop_item.gd b/frontend/Savor-22b/scenes/shop/shop_item.gd index e209b4c7..5c429266 100644 --- a/frontend/Savor-22b/scenes/shop/shop_item.gd +++ b/frontend/Savor-22b/scenes/shop/shop_item.gd @@ -1,6 +1,6 @@ extends ColorRect -signal button_down(item_id: int) +signal button_down @onready var itemname = $M/V/Itemname @onready var desc = $M/V/Description/Text @@ -26,4 +26,6 @@ func set_item(info: Dictionary): func _on_buy_button_down(): - button_down.emit(item.id) + SceneContext.selected_item_index = item.id + SceneContext.selected_item_name = item.name + button_down.emit() diff --git a/frontend/Savor-22b/scenes/shop/systemshop.gd b/frontend/Savor-22b/scenes/shop/systemshop.gd index df8eb4fc..b12dc0a1 100644 --- a/frontend/Savor-22b/scenes/shop/systemshop.gd +++ b/frontend/Savor-22b/scenes/shop/systemshop.gd @@ -11,6 +11,8 @@ const Gql_query = preload("res://gql/query.gd") var shopitems = [] + + func _ready(): print("shop opened") shopitems = SceneContext.shop @@ -29,12 +31,13 @@ func _ready(): func buy_item(): print("buy item") var askpopup = SHOP_ASK_POPUP.instantiate() - + askpopup.buy_button_down.connect(buyquery) + askpopup.set_itemname(SceneContext.selected_item_name) popup.add_child(askpopup) func buyquery(): - var itemnum = 1 + var itemnum = SceneContext.selected_item_index var gql_query = Gql_query.new() var query_string = gql_query.buy_shop_item_query_format.format([ "\"%s\"" % GlobalSigner.signer.GetPublicKey(), @@ -57,6 +60,20 @@ func buyquery(): ) add_child(query_executor) query_executor.run({}) + + print_done_popup() + +func print_done_popup(): + clear_popup() + var pop = SHOP_DONE_POPUP.instantiate() + popup.add_child(pop) + + + +func clear_popup(): + if is_instance_valid(popup): + for pop in popup.get_children(): + pop.queue_free() func _on_close_button_down(): queue_free() diff --git a/frontend/Savor-22b/scripts/global/scene_context.gd b/frontend/Savor-22b/scripts/global/scene_context.gd index 3c889746..73df3e86 100644 --- a/frontend/Savor-22b/scripts/global/scene_context.gd +++ b/frontend/Savor-22b/scripts/global/scene_context.gd @@ -52,6 +52,9 @@ var selected_village_height := 0 var selected_field_index := 0 +var selected_item_index := 0 +var selected_item_name : String + #func _ready(): #var json = JSON.new() #var error = json.parse(villages_json_string) diff --git a/frontend/Savor-22b/scripts/scenes/intro.gd b/frontend/Savor-22b/scripts/scenes/intro.gd index da1290af..12b28257 100644 --- a/frontend/Savor-22b/scripts/scenes/intro.gd +++ b/frontend/Savor-22b/scripts/scenes/intro.gd @@ -167,8 +167,3 @@ func _query_shop(): add_child(query_executor) query_executor.run({}) - -func reload_datas(): - _query_villages() - _query_user_state() - _query_assets()