From 6891870200373491b06b03d540684ee311c402f5 Mon Sep 17 00:00:00 2001 From: Atralupus Date: Mon, 22 Apr 2024 00:33:46 +0900 Subject: [PATCH] Implement relocation --- frontend/Savor-22b/gql/query.gd | 16 ++++++ frontend/Savor-22b/gql/svr_gql_client_2.gd | 6 +-- frontend/Savor-22b/scenes/select_house.tscn | 7 +++ frontend/Savor-22b/scripts/scenes/intro.gd | 3 ++ .../Savor-22b/scripts/scenes/select_house.gd | 32 +++++++++++- frontend/Savor-22b/ui/confirm_popup.gd | 25 +++++++++ frontend/Savor-22b/ui/confirm_popup.tscn | 51 +++++++++++++++++++ frontend/Savor-22b/ui/notice_popup.gd | 3 ++ 8 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 frontend/Savor-22b/ui/confirm_popup.gd create mode 100644 frontend/Savor-22b/ui/confirm_popup.tscn diff --git a/frontend/Savor-22b/gql/query.gd b/frontend/Savor-22b/gql/query.gd index a08abf6d..b99948d1 100644 --- a/frontend/Savor-22b/gql/query.gd +++ b/frontend/Savor-22b/gql/query.gd @@ -78,3 +78,19 @@ var install_kitchen_equipment_query_format = "query { spaceNumber: {} ) }" + +var calculate_relocation_cost_query_template = GQLQuery.new("calculateRelocationCost").set_args({ + "villageId": "villageId", + "relocationVillageId": "relocationVillageId", +}).set_props([ + "durationBlocks", + "price", +]) + +var calculate_relocation_cost_query = SvrGqlClient.query( + 'CalculateRelocationCost', + { + "villageId": "Int!", + "relocationVillageId": "Int!", + }, + calculate_relocation_cost_query_template) diff --git a/frontend/Savor-22b/gql/svr_gql_client_2.gd b/frontend/Savor-22b/gql/svr_gql_client_2.gd index e86cb900..f9c98502 100644 --- a/frontend/Savor-22b/gql/svr_gql_client_2.gd +++ b/frontend/Savor-22b/gql/svr_gql_client_2.gd @@ -1,11 +1,11 @@ -extends GQLClient2 +extends GQLClient func _ready(): print("client 2 ready") #set_endpoint(false, "1.230.253.103", 38080, "/graphql") - set_endpoint_2(false, "localhost", 38080, "/graphql/explorer") + set_endpoint(false, "localhost", 38080, "/graphql/explorer") func raw_mutation(query:String): - return GQLQueryExecuter2.new(endpoint, use_ssl, Mutation.new(query)) + return GQLQueryExecuter.new(endpoint, use_ssl, Mutation.new(query)) diff --git a/frontend/Savor-22b/scenes/select_house.tscn b/frontend/Savor-22b/scenes/select_house.tscn index c0dc9667..a970e0b3 100644 --- a/frontend/Savor-22b/scenes/select_house.tscn +++ b/frontend/Savor-22b/scenes/select_house.tscn @@ -165,6 +165,13 @@ offset_top = 300.0 offset_right = 640.0 offset_bottom = 340.0 +[node name="ConfirmPopup" type="Control" parent="MarginContainer/Background"] +anchors_preset = 0 +offset_left = 600.0 +offset_top = 300.0 +offset_right = 640.0 +offset_bottom = 340.0 + [connection signal="pressed" from="TopMenuMarginContainer/HBoxContainer/HomeButton" to="." method="_on_button_pressed"] [connection signal="button_down" from="TopMenuMarginContainer/HBoxContainer/BackButton" to="." method="_on_back_button_button_down"] [connection signal="button_down" from="BottomMenuMarginContainer/Control/BuildButtonContainer/BuildButton" to="." method="_on_build_button_button_down"] diff --git a/frontend/Savor-22b/scripts/scenes/intro.gd b/frontend/Savor-22b/scripts/scenes/intro.gd index eedcc2c6..3b7bfdae 100644 --- a/frontend/Savor-22b/scripts/scenes/intro.gd +++ b/frontend/Savor-22b/scripts/scenes/intro.gd @@ -127,6 +127,9 @@ func _query_user_state(): ]), ]), GQLQuery.new("villageState").set_props([ + GQLQuery.new("houseState").set_props([ + "villageId", + ]), GQLQuery.new("houseFieldStates").set_props([ "installedSeedGuid", "seedID", diff --git a/frontend/Savor-22b/scripts/scenes/select_house.gd b/frontend/Savor-22b/scripts/scenes/select_house.gd index f8379c02..a6436dc5 100644 --- a/frontend/Savor-22b/scripts/scenes/select_house.gd +++ b/frontend/Savor-22b/scripts/scenes/select_house.gd @@ -2,9 +2,11 @@ extends Control const SELECT_HOUSE_BUTTON = preload("res://ui/house_slot_button.tscn") const SLOT_IS_FULL = preload("res://ui/notice_popup.tscn") +const ConfirmPopupResource = preload("res://ui/confirm_popup.tscn") const Gql_query = preload("res://gql/query.gd") @onready var noticepopup = $MarginContainer/Background/Noticepopup +@onready var confirmPopup = $MarginContainer/Background/ConfirmPopup @onready var gridcontainer = $MarginContainer/Background/MarginContainer/ScrollContainer/HomeGridContainer var houses = [] @@ -72,9 +74,37 @@ func _on_build_button_button_down(): if (SceneContext.selected_house_location["owner"] != "none"): print_notice() else: - build_house() + var isHouseOwner = false + var villageState = SceneContext.user_state["villageState"] + if(villageState != null): + isHouseOwner = true + print(isHouseOwner) + + if (isHouseOwner): + _query_relocation_cost_and_open() + else: + build_house() +func _query_relocation_cost_and_open(): + var gql_query = Gql_query.new() + gql_query.calculate_relocation_cost_query.graphql_response.connect( + func(data): + var confirmPopupResource = ConfirmPopupResource.instantiate() + + confirmPopupResource.set_label("%s 블록이 소요되며 %sBBG 가 필요합니다." % [ + str(data.data.calculateRelocationCost.durationBlocks), + str(data.data.calculateRelocationCost.price) + ]) + confirmPopupResource.ok_button_clicked_signal.connect(build_house) + confirmPopup.add_child(confirmPopupResource) + ) + add_child(gql_query.calculate_relocation_cost_query) + gql_query.calculate_relocation_cost_query.run({ + "villageId": SceneContext.user_state["villageState"]["houseState"]["villageId"], + "relocationVillageId": SceneContext.get_selected_village()["id"] + }) + func print_notice(): var box = SLOT_IS_FULL.instantiate() diff --git a/frontend/Savor-22b/ui/confirm_popup.gd b/frontend/Savor-22b/ui/confirm_popup.gd new file mode 100644 index 00000000..3e4e6a1f --- /dev/null +++ b/frontend/Savor-22b/ui/confirm_popup.gd @@ -0,0 +1,25 @@ +extends ColorRect + +signal ok_button_clicked_signal +signal cancel_button_clicked_signal + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func set_label(text): + $VBoxContainer/Label.text = text + +func _on_ok_button_pressed(): + ok_button_clicked_signal.emit() + queue_free() + + +func _on_cancel_button_pressed(): + cancel_button_clicked_signal.emit() + queue_free() diff --git a/frontend/Savor-22b/ui/confirm_popup.tscn b/frontend/Savor-22b/ui/confirm_popup.tscn new file mode 100644 index 00000000..185a2b54 --- /dev/null +++ b/frontend/Savor-22b/ui/confirm_popup.tscn @@ -0,0 +1,51 @@ +[gd_scene load_steps=2 format=3 uid="uid://dmgv25t8i3882"] + +[ext_resource type="Script" path="res://ui/confirm_popup.gd" id="1_xg6hf"] + +[node name="NoticePopup" type="ColorRect"] +offset_left = 5.0 +offset_top = -38.0 +offset_right = 1005.0 +offset_bottom = 362.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +color = Color(1, 1, 0.533333, 1) +script = ExtResource("1_xg6hf") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 30 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0, 0, 0, 1) +theme_override_font_sizes/font_size = 50 +text = "confirm" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="CancelButton" type="Button" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 50 +text = "취소" + +[node name="OkButton" type="Button" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +theme_override_font_sizes/font_size = 50 +text = " 확인 " + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/OkButton" to="." method="_on_ok_button_pressed"] diff --git a/frontend/Savor-22b/ui/notice_popup.gd b/frontend/Savor-22b/ui/notice_popup.gd index 1bb5a0eb..287dc378 100644 --- a/frontend/Savor-22b/ui/notice_popup.gd +++ b/frontend/Savor-22b/ui/notice_popup.gd @@ -4,3 +4,6 @@ extends ColorRect func _on_button_pressed(): queue_free() + +func set_label(text): + $MarginContainer/Label.text = text