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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# Hurry Curry! - a game about cooking
# Copyright 2024 tpart
# Copyright 2024 nokoe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
extends MarginContainer
class_name PopupMessage
var is_ingame := false
var is_joined := false
@onready var server_msg = $VBox/ServerMessage
@onready var server_msg_positional = $ServerMessagePositional
@onready var hint_msg = $VBox/HintMessage
@onready var server_msg_timer: Timer = $ServerTimer
@onready var hint_msg_timer: Timer = $HintTimer
@onready var server_msg_label: Label = $VBox/ServerMessage/CenterContainer/Label
@onready var server_msg_positional_label: Label = $ServerMessagePositional/ServerMessage/CenterContainer/Label
@onready var hint_msg_label: Label = $VBox/HintMessage/CenterContainer/Label
@onready var server_msg_positional_panel: PanelContainer = $ServerMessagePositional/ServerMessage
@onready var auto_hint_timers: Node = $AutoHintTimers
@onready var reset_timer = $Reset
@onready var join_while_running_timer = $JoinWhileRunning
@onready var game: Game = $"../Game"
var server_message_position := Vector2.ZERO
var last_server_message_panel_size := Vector2.ZERO
func _ready():
game.joined.connect(
func player_joined():
is_joined = true
update_state()
)
game.left.connect(
func player_joined():
is_joined = false
update_state()
)
game.update_tutorial_running.connect(
func a(running: bool):
if running:
stop_game_hints()
else:
update_state()
)
func _process(_delta: float):
if server_msg_positional.visible:
var pos_3d = Vector3(server_message_position.x + 0.5, 1.5, server_message_position.y + 0.5)
var pos_2d = get_viewport().get_camera_3d().unproject_position(pos_3d)
var server_message_panel_size = server_msg_positional_panel.size
server_msg_positional.position = pos_2d.clamp(Vector2.ZERO + 0.5 * server_message_panel_size, Vector2(get_viewport_rect().size) - 0.5 * server_message_panel_size)
if server_message_panel_size != last_server_message_panel_size:
last_server_message_panel_size = server_message_panel_size
server_msg_positional_panel.position = -0.5 * last_server_message_panel_size
func ingame():
is_ingame = true
update_state()
func lobby():
is_ingame = false
update_state()
func update_state():
if is_ingame and is_joined:
start_game_hints()
elif is_ingame:
stop_game_hints()
join_while_running_timer.start()
else:
stop_game_hints()
func display_server_msg(msg: String, auto_remove := true):
clear_server_msg()
server_msg.show()
server_msg_label.text = msg
if auto_remove:
server_msg_timer.start()
func display_server_msg_positional(msg: String, pos: Vector2, auto_remove := true):
clear_server_msg()
server_msg_positional.show()
server_message_position = pos
server_msg_positional_label.text = msg
server_msg_positional_panel.size = Vector2.ZERO
if auto_remove:
server_msg_timer.start()
func clear_server_msg():
server_msg_timer.stop()
server_msg.hide()
server_msg_positional.hide()
func _on_server_timer_timeout():
clear_server_msg()
func display_hint_msg(msg: String):
hint_msg.show()
hint_msg_label.text = msg
hint_msg_timer.start()
func _on_hint_timer_timeout():
hint_msg.hide()
func start_game_hints():
for c: Timer in auto_hint_timers.get_children():
c.start()
func stop_game_hints():
_on_hint_timer_timeout()
for c: Timer in auto_hint_timers.get_children():
c.stop()
reset_timer.stop()
join_while_running_timer.stop()
func _input(_event):
if Input.is_action_just_pressed("boost"):
Global.set_hint("has_boosted", true)
if any_action_just_pressed(["forwards", "backwards", "left", "right"]):
Global.set_hint("has_moved", true)
if any_action_just_pressed(["rotate_left", "rotate_right", "rotate_up", "rotate_down"]):
if not Global.get_hint("has_reset"):
reset_timer.start()
Global.set_hint("has_rotated", true)
if any_action_just_pressed(["zoom_in", "zoom_out"]):
Global.set_hint("has_zoomed", true)
if Input.is_action_just_pressed("interact"):
Global.set_hint("has_interacted", true)
if Input.is_action_just_pressed("reset"):
Global.set_hint("has_reset", true)
func _on_boost_timeout():
if not Global.get_hint("has_boosted") and not Global.using_touch:
display_hint_msg(tr("c.hint.boost").format([display_keybind("boost")]))
func _on_move_timeout():
if not Global.get_hint("has_moved") and not Global.using_touch:
display_hint_msg(tr("c.hint.movement").format([", ".join(
[
display_keybind("forwards"),
display_keybind("left"),
display_keybind("backwards"),
display_keybind("right")
]
)]))
func _on_interact_timeout():
if not Global.get_hint("has_interacted") and not Global.using_touch:
display_hint_msg(tr("c.hint.interact").format([display_keybind("interact")]))
func _on_reset_timeout():
if not Global.get_hint("has_reset") and not Global.using_touch:
display_hint_msg(tr("c.hint.reset_camera").format([display_keybind("reset")]))
func _on_zoom_timeout():
if not Global.get_hint("has_zoomed") and not Global.using_touch:
display_hint_msg(tr("c.hint.zoom_camera").format([", ".join(
[
display_keybind("zoom_in"),
display_keybind("zoom_out")
]
)]))
func display_keybind(action_name: String) -> String:
var events := InputManager.get_events(action_name)
if events.size() == 0:
# There are no events which match the action
return tr("c.settings.input.unknown_event")
for event: InputEvent in events:
# Try to find event which matches input method
var type := InputManager.get_event_type(event)
if Global.using_joypad and type != InputManager.EventType.JOYPAD:
continue
if Global.using_touch and type != InputManager.EventType.TOUCH:
continue
return InputManager.display_input_event(event)
# No matching event found. Just show any event.
return InputManager.display_input_event(events[0])
func any_action_just_pressed(actions: Array) -> bool:
for a: String in actions:
if Input.is_action_just_pressed(a):
return true
return false
func _on_rotate_camera_timeout():
if not Global.get_hint("has_rotated") and not Global.using_touch:
display_hint_msg(tr("c.hint.rotate").format([", ".join(
[
display_keybind("rotate_up"),
display_keybind("rotate_left"),
display_keybind("rotate_down"),
display_keybind("rotate_right")
]
)]))
func _on_join_while_running_timeout():
if not game.is_joined and not Global.get_hint("has_seen_join_while_running"):
Global.set_hint("has_seen_join_while_running", true)
display_hint_msg(tr("c.hint.join_while_running").format([display_keybind("menu")]))
func _on_performance_timeout() -> void:
if not Global.get_hint("has_seen_performance") and Engine.get_frames_per_second() < DisplayServer.screen_get_refresh_rate() * 0.75:
Global.set_hint("has_seen_performance", true)
display_hint_msg(tr("c.hint.framerate_low"))
|