Skip to content

Commit

Permalink
feat: farm weed remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
kth1888 committed Apr 15, 2024
1 parent f764320 commit 28178e7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
8 changes: 8 additions & 0 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ var remove_seed_query_format = "query {
)
}"

var remove_weed_query_format = "query {
createAction_RemoveWeed(
publicKey: {},
fieldIndex: {}
)
}"



var buy_shop_item_query_format = "query {
createAction_BuyShopItem(
Expand Down
38 changes: 33 additions & 5 deletions frontend/Savor-22b/scripts/scenes/farm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,19 @@ func harvest_seed():
actionSuccess = true
fetch_new()

func action_popup():
func action_popup(weed : bool):
print("행동 팝업")
if is_instance_valid(popuparea):
for child in popuparea.get_children():
child.queue_free()

var actionpopup = ACTION_POPUP.instantiate()
actionpopup.set_weed_button(weed)
popuparea.add_child(actionpopup)
actionpopup.set_position(Vector2(700,500))
var mousepos = get_local_mouse_position() + Vector2(0, -200)
actionpopup.set_position(mousepos)
actionpopup.button_down_remove.connect(remove_popup)
actionpopup.weed_action_signal.connect(remove_weed)

func remove_popup():
if is_instance_valid(popuparea):
Expand All @@ -214,9 +217,9 @@ func remove_done_popup():
donepopup.set_position(Vector2(700,500))
donepopup.refresh_me.connect(fetch_new)

func control_seed():
func control_seed(weed : bool):
#code here
action_popup()
action_popup(weed)

func remove_seed():
var gql_query = Gql_query.new()
Expand Down Expand Up @@ -246,6 +249,7 @@ func remove_seed():
func fetch_new():
# fetch datas
Intro._query_user_state()
Intro.get_current_block()

# done popup
if(actionSuccess):
Expand All @@ -262,10 +266,34 @@ func fetch_new():

_ready()

func _on_refresh_button_button_down():
func remove_weed():
var gql_query = Gql_query.new()
var query_string = gql_query.remove_weed_query_format.format([
"\"%s\"" % GlobalSigner.signer.GetPublicKey(),
SceneContext.selected_field_index], "{}")
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_RemoveWeed"]
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({})
fetch_new()


func _on_refresh_button_button_down():
fetch_new()

func _on_home_button_button_down():
get_tree().change_scene_to_file("res://scenes/house/house.tscn")
9 changes: 9 additions & 0 deletions frontend/Savor-22b/ui/farm_action_popup.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
extends ColorRect

signal button_down_remove
signal weed_action_signal


func _ready():
pass # Replace with function body.

func set_weed_button(weed : bool):
if (weed):
$M/V/Weed.visible = true

func _on_remove_button_down():
button_down_remove.emit()
Expand All @@ -14,3 +18,8 @@ func _on_remove_button_down():

func _on_cancel_button_down():
queue_free()


func _on_weed_button_down():
weed_action_signal.emit()
queue_free()
13 changes: 11 additions & 2 deletions frontend/Savor-22b/ui/farm_action_popup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
bg_color = Color(0, 0, 0, 1)

[node name="ActionPopup" type="ColorRect"]
custom_minimum_size = Vector2(400, 100)
custom_minimum_size = Vector2(400, 200)
offset_right = 400.0
offset_bottom = 200.0
offset_bottom = 300.0
color = Color(0.866667, 0.498039, 0.215686, 1)
script = ExtResource("1_ma8qk")

Expand All @@ -34,11 +34,20 @@ theme_override_font_sizes/font_size = 50
theme_override_styles/normal = SubResource("StyleBoxFlat_yesvl")
text = "종자 제거하기"

[node name="Weed" type="Button" parent="M/V"]
visible = false
layout_mode = 2
theme_override_colors/font_color = Color(0, 1, 0, 1)
theme_override_font_sizes/font_size = 50
theme_override_styles/normal = SubResource("StyleBoxFlat_yesvl")
text = "잡초 제거하기"

[node name="Cancel" type="Button" parent="M/V"]
layout_mode = 2
theme_override_font_sizes/font_size = 50
theme_override_styles/normal = SubResource("StyleBoxFlat_yesvl")
text = "행동 취소"

[connection signal="button_down" from="M/V/Remove" to="." method="_on_remove_button_down"]
[connection signal="button_down" from="M/V/Weed" to="." method="_on_weed_button_down"]
[connection signal="button_down" from="M/V/Cancel" to="." method="_on_cancel_button_down"]
6 changes: 3 additions & 3 deletions frontend/Savor-22b/ui/farm_slot_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends ColorRect

signal button_down(child_index: int)
signal button_down_action
signal weed_action


@onready var button = $V/Button

Expand All @@ -25,7 +25,7 @@ func _update_button():
button.text = format_string % [farm_slot.seedName, "자라는 중", timeleft, "블록 남음"]

if (farm_slot.weedRemovalAble):
pass
$Weed.visible = true

func set_farm_slot(farm_slot: Dictionary):
self.farm_slot = farm_slot
Expand All @@ -36,7 +36,7 @@ func _on_button_button_down():
button_down.emit(get_index())
else:
button_down.emit(get_index()+5)
button_down_action.emit()
button_down_action.emit(farm_slot.weedRemovalAble)


func im_right():
Expand Down
18 changes: 11 additions & 7 deletions frontend/Savor-22b/ui/farm_slot_button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ theme_override_styles/pressed = SubResource("StyleBoxFlat_ctkwv")
text = "[벼] 자라는 중
[N 블록 남음]"

[node name="Label" type="Label" parent="V/Button"]
layout_mode = 2
offset_top = 245.0
offset_right = 500.0
offset_bottom = 300.0
[node name="Weed" type="Label" parent="."]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(0, 1, 0, 1)
theme_override_font_sizes/font_size = 40
theme_override_font_sizes/font_size = 28
text = "[잡초 제거 필요]"
horizontal_alignment = 1
horizontal_alignment = 2
vertical_alignment = 2

[connection signal="button_down" from="V/Button" to="." method="_on_button_button_down"]

0 comments on commit 28178e7

Please sign in to comment.