-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcanvas_layer.gd
More file actions
162 lines (137 loc) · 5.42 KB
/
canvas_layer.gd
File metadata and controls
162 lines (137 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
extends CanvasLayer
@onready var topsoil_label = $LabelSoilMoisture
@onready var subsoil_label = $LabelSubSoilMoisture
@onready var ndvi_label = $LabelNDVI
var active_tool: String = ""
func _ready():
# Connect to World Signals
var world = get_parent() # World is the parent
world.connect("toggle_topsoil_label_requested", Callable(self, "toggle_topsoil_label"))
world.connect("toggle_subsoil_label_requested", Callable(self, "toggle_subsoil_label"))
world.connect("toggle_ndvi_label_requested", Callable(self, "toggle_ndvi_label"))
# Labels should be hidden initially
topsoil_label.visible = false
subsoil_label.visible = false
ndvi_label.visible = false
# Connect toolbar buttons
$PanelContainer/VBoxContainer/WheatButton.pressed.connect(func(): set_tool("wheat"))
$PanelContainer/VBoxContainer/CornButton.pressed.connect(func(): set_tool("corn"))
$PanelContainer/VBoxContainer/WaterJugButton.pressed.connect(func(): set_tool("water"))
func set_tool(tool_name: String):
active_tool = tool_name
Global.current_tool = tool_name
# Update button appearances to show which is active
update_button_states(tool_name)
func update_button_states(active_tool_name: String):
# Reset all button modulations
$PanelContainer/VBoxContainer/WheatButton.modulate = Color.WHITE
$PanelContainer/VBoxContainer/CornButton.modulate = Color.WHITE
$PanelContainer/VBoxContainer/WaterJugButton.modulate = Color.WHITE
# Highlight the active tool
match active_tool_name:
"wheat":
$PanelContainer/VBoxContainer/WheatButton.modulate = Color.YELLOW
"corn":
$PanelContainer/VBoxContainer/CornButton.modulate = Color.YELLOW
"water":
$PanelContainer/VBoxContainer/WaterJugButton.modulate = Color.YELLOW
func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
var world = get_tree().get_first_node_in_group("world")
if world and active_tool != "":
var tile_pos = world.get_snapped_position(world.get_global_mouse_position())
# Check if clicking on a valid tile (not UI elements)
var mask_data = world.ground_mask.get_cell_tile_data(tile_pos)
if mask_data:
var mask_name = mask_data.get_custom_data("mask_type")
if mask_name == "no_crops":
return
if active_tool == "water":
# Water the tile
var data = world.ground.get_cell_tile_data(tile_pos)
if data:
var tile_name = data.get_custom_data("tile_name")
world.watering_tile(tile_name, tile_pos, 1.0)
if Global.water > 0:
Global.water -= 1
elif active_tool in ["corn", "wheat"]:
# Plant the crop
var planted = world.plant_crop(tile_pos)
if planted:
world.get_node("Crops/plant_audio").pitch_scale = randf_range(0.9, 1.1)
world.get_node("Crops/plant_audio").play()
else:
world.get_node("Crops/unplant_audio").pitch_scale = randf_range(0.9, 1.1)
world.get_node("Crops/unplant_audio").play()
func toggle_topsoil_label(state: bool):
topsoil_label.visible = state
if state == true:
subsoil_label.visible = false
ndvi_label.visible = false
func toggle_subsoil_label(state: bool):
subsoil_label.visible = state
if state == true:
topsoil_label.visible = false
ndvi_label.visible = false
func toggle_ndvi_label(state: bool):
ndvi_label.visible = state
if state == true:
topsoil_label.visible = false
subsoil_label.visible = false
func _on_topsoil_button_pressed():
var world_scene = get_tree().get_first_node_in_group("world")
if world_scene:
world_scene.subsoil.visible = false
world_scene.topsoil.visible = true
$LabelSubSoilMoisture.visible = false
$LabelSoilMoisture.visible = true
func _on_subsoil_button_pressed():
var world_scene = get_tree().get_first_node_in_group("world")
if world_scene:
world_scene.topsoil.visible = false
world_scene.subsoil.visible = true
$LabelSoilMoisture.visible = false
$LabelSubSoilMoisture.visible = true
func _on_hide_moisture_button_pressed():
var world_scene = get_tree().get_first_node_in_group("world")
if world_scene:
world_scene.topsoil.visible = false
world_scene.subsoil.visible = false
$LabelSoilMoisture.visible = false
$LabelSubSoilMoisture.visible = false
func _on_settings_button_pressed():
var settings_panel = $SettingsPanel
if settings_panel:
settings_panel.visible = !settings_panel.visible
func _on_close_settings_button_pressed():
var settings_panel = $SettingsPanel
if settings_panel:
settings_panel.visible = false
func _on_save_quit_button_pressed():
Global.save_game()
get_tree().change_scene_to_file("res://scenes/MainMenu.tscn")
func _on_export_button_pressed():
var export_code = Global.export_game_state()
var export_dialog = $ExportDialog
var export_code_edit = $ExportDialog/VBoxContainer/ExportCodeEdit
if export_dialog and export_code_edit:
export_code_edit.text = export_code
export_dialog.visible = true
# Close settings panel
var settings_panel = $SettingsPanel
if settings_panel:
settings_panel.visible = false
func _on_copy_code_button_pressed():
var export_code_edit = $ExportDialog/VBoxContainer/ExportCodeEdit
if export_code_edit:
DisplayServer.clipboard_set(export_code_edit.text)
print("Export code copied to clipboard!")
func _on_close_export_button_pressed():
var export_dialog = $ExportDialog
if export_dialog:
export_dialog.visible = false
func _on_share_button_pressed():
var share_text = Global.generate_share_text()
# Copy to clipboard
DisplayServer.clipboard_set(share_text)
print("Share text copied to clipboard: ", share_text)