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/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/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 ca443464..b12dc0a1 100644 --- a/frontend/Savor-22b/scenes/shop/systemshop.gd +++ b/frontend/Savor-22b/scenes/shop/systemshop.gd @@ -4,11 +4,15 @@ 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 var shopitems = [] + + func _ready(): print("shop opened") shopitems = SceneContext.shop @@ -21,14 +25,55 @@ func _ready(): singleitem.set_item(item) singleitem.button_down.connect(buy_item) shoplist.add_child(singleitem) + 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 = 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(), + 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({}) + + 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()