diff options
Diffstat (limited to 'client/gui/overlays/popup_message')
-rw-r--r-- | client/gui/overlays/popup_message/popup_message.gd | 152 | ||||
-rw-r--r-- | client/gui/overlays/popup_message/popup_message.tscn | 128 |
2 files changed, 7 insertions, 273 deletions
diff --git a/client/gui/overlays/popup_message/popup_message.gd b/client/gui/overlays/popup_message/popup_message.gd index 74268958..4ea5aa2f 100644 --- a/client/gui/overlays/popup_message/popup_message.gd +++ b/client/gui/overlays/popup_message/popup_message.gd @@ -18,43 +18,15 @@ class_name PopupMessage const SERVER_MESSAGE_SCENE = preload("res://gui/overlays/popup_message/server_message.tscn") -var is_ingame := false -var is_joined := false - var positional_messages = {} @onready var positional_messages_node: Control = $Positional @onready var server_msg = $Static/VBox/ServerMessage -@onready var hint_msg = $Static/VBox/HintMessage - @onready var server_msg_label: Label = $Static/VBox/ServerMessage/CenterContainer/Label -@onready var hint_msg_label: Label = $Static/VBox/HintMessage/CenterContainer/Label - -@onready var auto_hint_timers: Node = $Timers/AutoHints -@onready var server_msg_timer: Timer = $Timers/Server -@onready var hint_msg_timer: Timer = $Timers/Hint -@onready var reset_timer = $Timers/Reset -@onready var join_while_running_timer = $Timers/JoinWhileRunning +@onready var server_msg_timer: Timer = $ServerMessage @onready var game: Game = $"../../Game" # TODO -func _ready(): - game.join_state_updated.connect(func(state: Game.JoinState): - is_joined = state == Game.JoinState.JOINED - ) - game.update_tutorial_running.connect( - func a(running: bool): - if running: - stop_game_hints() - else: - update_state() - ) - game.in_lobby_updated.connect( - func a(in_lobby): - is_ingame = not in_lobby - update_state() - ) - func _process(_delta: float): for pos: Vector2 in positional_messages.keys(): var msg: PositionalMessage = positional_messages[pos] @@ -70,15 +42,6 @@ func _process(_delta: float): msg.last_size = msg.node.size msg.node.position = -0.5 * msg.last_size -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): server_msg.show() server_msg_label.text = msg @@ -110,119 +73,6 @@ func clear_server_msg(position_ = null): msg.node_2d.queue_free() positional_messages.erase(position_) -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"): - Profile.set_hint("has_boosted", true) - if any_action_just_pressed(["forwards", "backwards", "left", "right"]): - Profile.set_hint("has_moved", true) - if any_action_just_pressed(["rotate_left", "rotate_right", "rotate_up", "rotate_down"]): - if not Profile.get_hint("has_reset"): - reset_timer.start() - Profile.set_hint("has_rotated", true) - if any_action_just_pressed(["zoom_in", "zoom_out"]): - Profile.set_hint("has_zoomed", true) - if Input.is_action_just_pressed("interact_left") or Input.is_action_just_pressed("interact_right"): - Profile.set_hint("has_interacted", true) - if Input.is_action_just_pressed("reset"): - Profile.set_hint("has_reset", true) - -func _on_boost_timeout(): - if not Profile.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 Profile.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 Profile.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 Profile.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 Profile.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 = Settings.read("input.%s" % 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 Profile.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.join_state == Game.JoinState.JOINED and not Profile.get_hint("has_seen_join_while_running"): - Profile.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 Profile.get_hint("has_seen_performance") and Engine.get_frames_per_second() < DisplayServer.screen_get_refresh_rate() * 0.75: - Profile.set_hint("has_seen_performance", true) - display_hint_msg(tr("c.hint.framerate_low")) - class PositionalMessage: var node: ServerMessage var node_2d: Node2D diff --git a/client/gui/overlays/popup_message/popup_message.tscn b/client/gui/overlays/popup_message/popup_message.tscn index 15d56c40..fab35e3e 100644 --- a/client/gui/overlays/popup_message/popup_message.tscn +++ b/client/gui/overlays/popup_message/popup_message.tscn @@ -1,37 +1,8 @@ -[gd_scene load_steps=12 format=3 uid="uid://b21nrnkygiyjt"] +[gd_scene load_steps=4 format=3 uid="uid://b21nrnkygiyjt"] [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://gui/resources/theme/theme.tres" id="1_a1566"] [ext_resource type="Script" uid="uid://c2cx41lrgf5b0" path="res://gui/overlays/popup_message/popup_message.gd" id="2_sbew6"] -[ext_resource type="Shader" uid="uid://cwldxegcj55if" path="res://gui/resources/shaders/blur_mix.gdshader" id="3_2vnom"] [ext_resource type="PackedScene" uid="uid://dq61p3a8og2b6" path="res://gui/overlays/popup_message/server_message.tscn" id="3_m3rok"] -[ext_resource type="Script" uid="uid://cmncjc06kadpe" path="res://gui/components/blur_setup.gd" id="4_pvwmw"] -[ext_resource type="FontFile" uid="uid://bk704sc5gkrb3" path="res://gui/resources/fonts/font-azaret-mono.woff2" id="4_wsrnf"] -[ext_resource type="Texture2D" uid="uid://b2uv5rf0enikf" path="res://gui/resources/icons/hint.svg" id="5_2dxsd"] - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_k0m35"] -shader = ExtResource("3_2vnom") -shader_parameter/blur_amount = 3.5 -shader_parameter/mix_amount = 0.85 -shader_parameter/mix_amount_no_blur = 1.0 -shader_parameter/color_over = Color(0, 0, 0, 1) -shader_parameter/enable_blur = false - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vq4dg"] -bg_color = Color(1, 1, 1, 0.878431) -corner_radius_top_left = 16 -corner_radius_top_right = 16 -corner_radius_bottom_right = 16 -corner_radius_bottom_left = 16 - -[sub_resource type="FontVariation" id="FontVariation_qfltj"] -base_font = ExtResource("4_wsrnf") -variation_embolden = 0.75 - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_3rgop"] -content_margin_left = 32.0 -content_margin_top = 8.0 -content_margin_right = 32.0 -content_margin_bottom = 8.0 [node name="PopupMessage" type="Control"] layout_mode = 3 @@ -43,6 +14,10 @@ grow_vertical = 2 mouse_filter = 2 script = ExtResource("2_sbew6") +[node name="ServerMessage" type="Timer" parent="."] +wait_time = 5.0 +one_shot = true + [node name="Static" type="MarginContainer" parent="."] layout_mode = 1 anchors_preset = 15 @@ -61,44 +36,6 @@ mouse_filter = 2 visible = false layout_mode = 2 -[node name="HintMessage" type="PanelContainer" parent="Static/VBox"] -visible = false -material = SubResource("ShaderMaterial_k0m35") -layout_mode = 2 -size_flags_vertical = 0 -mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_vq4dg") -script = ExtResource("4_pvwmw") - -[node name="CenterContainer" type="HBoxContainer" parent="Static/VBox/HintMessage"] -layout_mode = 2 -mouse_filter = 2 -alignment = 1 - -[node name="MarginContainer" type="MarginContainer" parent="Static/VBox/HintMessage/CenterContainer"] -layout_mode = 2 -mouse_filter = 2 -theme_override_constants/margin_left = 4 -theme_override_constants/margin_top = 4 -theme_override_constants/margin_right = 4 -theme_override_constants/margin_bottom = 4 - -[node name="TextureRect" type="TextureRect" parent="Static/VBox/HintMessage/CenterContainer/MarginContainer"] -custom_minimum_size = Vector2(28, 28) -layout_mode = 2 -mouse_filter = 2 -texture = ExtResource("5_2dxsd") -expand_mode = 1 -stretch_mode = 4 - -[node name="Label" type="Label" parent="Static/VBox/HintMessage/CenterContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_fonts/font = SubResource("FontVariation_qfltj") -theme_override_styles/normal = SubResource("StyleBoxEmpty_3rgop") -text = "A hint is worth more than a thousand manuals" -autowrap_mode = 3 - [node name="Positional" type="Control" parent="."] layout_mode = 1 anchors_preset = 15 @@ -108,57 +45,4 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 -[node name="Timers" type="Node" parent="."] - -[node name="Server" type="Timer" parent="Timers"] -wait_time = 5.0 -one_shot = true - -[node name="Hint" type="Timer" parent="Timers"] -wait_time = 10.0 -one_shot = true - -[node name="AutoHints" type="Node" parent="Timers"] - -[node name="Move" type="Timer" parent="Timers/AutoHints"] -wait_time = 2.0 -one_shot = true - -[node name="Performance" type="Timer" parent="Timers/AutoHints"] -wait_time = 20.0 -one_shot = true - -[node name="Boost" type="Timer" parent="Timers/AutoHints"] -wait_time = 90.0 -one_shot = true - -[node name="Interact" type="Timer" parent="Timers/AutoHints"] -wait_time = 15.0 -one_shot = true - -[node name="RotateCamera" type="Timer" parent="Timers/AutoHints"] -wait_time = 120.0 -one_shot = true - -[node name="Zoom" type="Timer" parent="Timers/AutoHints"] -wait_time = 135.0 -one_shot = true - -[node name="Reset" type="Timer" parent="Timers"] -wait_time = 10.0 -one_shot = true - -[node name="JoinWhileRunning" type="Timer" parent="Timers"] -wait_time = 5.0 -one_shot = true - -[connection signal="timeout" from="Timers/Server" to="." method="_on_server_timeout"] -[connection signal="timeout" from="Timers/Hint" to="Static" method="_on_hint_timer_timeout"] -[connection signal="timeout" from="Timers/AutoHints/Move" to="Static" method="_on_move_timeout"] -[connection signal="timeout" from="Timers/AutoHints/Performance" to="Static" method="_on_performance_timeout"] -[connection signal="timeout" from="Timers/AutoHints/Boost" to="Static" method="_on_boost_timeout"] -[connection signal="timeout" from="Timers/AutoHints/Interact" to="Static" method="_on_interact_timeout"] -[connection signal="timeout" from="Timers/AutoHints/RotateCamera" to="Static" method="_on_rotate_camera_timeout"] -[connection signal="timeout" from="Timers/AutoHints/Zoom" to="Static" method="_on_zoom_timeout"] -[connection signal="timeout" from="Timers/Reset" to="Static" method="_on_reset_timeout"] -[connection signal="timeout" from="Timers/JoinWhileRunning" to="Static" method="_on_join_while_running_timeout"] +[connection signal="timeout" from="ServerMessage" to="." method="_on_server_timeout"] |