Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

SVR-163: 집 화면의 인벤토리 내 상점에서 구매 기능 #136

Merged
merged 2 commits into from
Mar 5, 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
7 changes: 7 additions & 0 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ var buy_shop_item_query_format = "query {
desiredShopItemID: {}
)
}"

var buy_kitchen_equipment_query_format = "query {
createAction_BuyKitchenEquipment(
publicKey: {},
desiredEquipmentID: {}
)
}"
6 changes: 6 additions & 0 deletions frontend/Savor-22b/scenes/house/house.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ theme_override_constants/margin_left = 20
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20

[node name="Popups" type="Control" parent="."]
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0

[connection signal="button_down" from="M/V/menus/V/InventoryButton" to="." method="_on_inventory_button_button_down"]
[connection signal="button_down" from="M/V/menus/V/RefreshButton" to="." method="_on_refresh_button_button_down"]
13 changes: 11 additions & 2 deletions frontend/Savor-22b/scenes/house/house_inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const KITCHEN_SHOP = preload("res://scenes/house/kitchenshop.tscn")

@onready var panel = $M/V/Panel/C

signal buysignal

func _ready():
var kitchens = KITCHEN_TOOLS.instantiate()

Expand All @@ -16,16 +18,23 @@ func _ready():
func _on_tools_button_down():
clear_popup()
var kitchens = KITCHEN_TOOLS.instantiate()

kitchens.closetab.connect(closetab)
panel.add_child(kitchens)

func _on_shop_button_down():
clear_popup()
var kitchens = KITCHEN_SHOP.instantiate()

kitchens.closetab.connect(closetab)
kitchens.buysignal.connect(popup)
panel.add_child(kitchens)

func clear_popup():
if is_instance_valid(panel):
for pop in panel.get_children():
pop.queue_free()

func closetab():
queue_free()

func popup():
buysignal.emit()
11 changes: 11 additions & 0 deletions frontend/Savor-22b/scenes/house/kitchenshop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const TOOL = preload("res://scenes/house/tool.tscn")

@onready var grid = $M/V/Items/G

signal buysignal
signal closetab

var list

func _ready():
Expand All @@ -13,5 +16,13 @@ func _ready():
var toolpanel = TOOL.instantiate()
toolpanel.set_slottype()
toolpanel.set_info(tool)
toolpanel.buysignal.connect(popup)
grid.add_child(toolpanel)

func popup():
buysignal.emit()


func _on_close_button_down():
closetab.emit()
queue_free()
2 changes: 2 additions & 0 deletions frontend/Savor-22b/scenes/house/kitchenshop.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 40
theme_override_styles/normal = SubResource("StyleBoxFlat_rk6tx")
text = " 닫기 "

[connection signal="button_down" from="M/V/Button/Close" to="." method="_on_close_button_down"]
8 changes: 8 additions & 0 deletions frontend/Savor-22b/scenes/house/kitchentools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const TOOL = preload("res://scenes/house/tool.tscn")

@onready var grid = $M/V/Items/G

signal closetab

var tools

func _ready():
Expand All @@ -14,3 +16,9 @@ func _ready():
toolpanel.set_info(tool)
grid.add_child(toolpanel)



func _on_close_button_down():
closetab.emit()
queue_free()

2 changes: 2 additions & 0 deletions frontend/Savor-22b/scenes/house/kitchentools.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 40
theme_override_styles/normal = SubResource("StyleBoxFlat_rk6tx")
text = " 닫기 "

[connection signal="button_down" from="M/V/Button/Close" to="." method="_on_close_button_down"]
10 changes: 10 additions & 0 deletions frontend/Savor-22b/scenes/house/tool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ extends Panel

@onready var toolname = $M/V/Name
@onready var tooldesc = $M/V/Desc
@onready var buybutton = $M/V/Buy

signal buysignal

var info
var isshop: bool = false
Expand All @@ -20,6 +23,7 @@ func _update_info():
if (isshop):
toolname.text = info.name
tooldesc.text = desc_format_string % [info.categoryType, info.categoryLabel, "Price", info.price, "BBG"]
buybutton.visible = true
else:
toolname.text = info.equipmentName
tooldesc.text = info.stateId
Expand All @@ -31,3 +35,9 @@ func set_slottype():
self.isshop = true
_update_info()



func _on_buy_button_down():
SceneContext.selected_item_index = info.id
SceneContext.selected_item_name = info.name
buysignal.emit()
17 changes: 15 additions & 2 deletions frontend/Savor-22b/scenes/house/tool.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://cjlj4mej5h001"]
[gd_scene load_steps=4 format=3 uid="uid://cjlj4mej5h001"]

[ext_resource type="Script" path="res://scenes/house/tool.gd" id="1_fsq81"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x6mfd"]
bg_color = Color(1, 0.541176, 0, 1)

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

[node name="Tool" type="Panel"]
custom_minimum_size = Vector2(300, 200)
offset_right = 300.0
Expand Down Expand Up @@ -38,10 +41,20 @@ theme_override_font_sizes/font_size = 40
text = "조리도구 이름"

[node name="Desc" type="Label" parent="M/V"]
custom_minimum_size = Vector2(260, 132)
custom_minimum_size = Vector2(260, 82)
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 30
text = "조리도구 설명"
autowrap_mode = 1
max_lines_visible = 3

[node name="Buy" type="Button" parent="M/V"]
visible = false
layout_mode = 2
size_flags_horizontal = 8
theme_override_font_sizes/font_size = 20
theme_override_styles/normal = SubResource("StyleBoxFlat_v31jt")
text = " 구매 "

[connection signal="button_down" from="M/V/Buy" to="." method="_on_buy_button_down"]
61 changes: 60 additions & 1 deletion frontend/Savor-22b/scripts/scenes/house.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
extends Control

const HOUSE_INVENTORY = preload("res://scenes/house/house_inventory.tscn")
const ASK_POPUP = preload("res://scenes/shop/ask_popup.tscn")
const DONE_POPUP = preload("res://scenes/shop/done_popup.tscn")
const Gql_query = preload("res://gql/query.gd")

@onready var subscene = $M/V/subscene
@onready var popup = $Popups

func _ready():
pass # Replace with function body.
Expand All @@ -12,5 +16,60 @@ func _ready():

func _on_inventory_button_button_down():
var inventory = HOUSE_INVENTORY.instantiate()

inventory.buysignal.connect(buypopup)
subscene.add_child(inventory)


func buypopup():
var askpopup = ASK_POPUP.instantiate()
askpopup.set_itemname(SceneContext.selected_item_name)
askpopup.buy_button_down.connect(buyaction)
askpopup.set_position(Vector2(900,600))
popup.add_child(askpopup)

func buyaction():
clear_popup()
buytool()

var donepopup = DONE_POPUP.instantiate()
donepopup.set_position(Vector2(900,600))
popup.add_child(donepopup)

func buytool():
var itemnum = SceneContext.selected_item_index
var gql_query = Gql_query.new()
var query_string = gql_query.buy_kitchen_equipment_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_BuyKitchenEquipment"]
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 clear_popup():
if is_instance_valid(popup):
for pop in popup.get_children():
pop.queue_free()



func _on_refresh_button_button_down():
Intro._query_user_state()

if is_instance_valid(subscene):
for scene in subscene.get_children():
scene.queue_free()
Loading