Skip to content

Commit 8a6b8da

Browse files
committed
Allow player to pause and speed up time.
1 parent 7c945c4 commit 8a6b8da

File tree

869 files changed

+17062
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

869 files changed

+17062
-70
lines changed

entities/time_component.gd

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
extends Node2D
2+
class_name TimeComponent
23

34
@onready var view_model = TimerViewModel.new()
45

5-
var time_since_last_update = 0
6-
var time = Time.get_unix_time_from_system()
6+
@export var day_update_interval_seconds: int = 1
7+
@export var default_speed: float = 1
8+
@export var fast_speed: float = 3
9+
10+
var time_since_last_update: float = 0
11+
var time: float = Time.get_unix_time_from_system()
12+
var is_paused: bool = false
13+
var speed: float = default_speed
714

815
func _ready():
16+
view_model.initialize(self)
917
ViewModelRegistry.register(ViewModelRegistry.Keys.TIMER, view_model)
1018

11-
func _process(delta: float):
19+
func _process(delta: float):
20+
if is_paused:
21+
return
22+
1223
time_since_last_update += delta
13-
if time_since_last_update > 1:
24+
if time_since_last_update > (day_update_interval_seconds / speed):
1425
time_since_last_update = 0
1526
time += 86400 # seconds in a day
1627
view_model.set_time(time)
28+
29+
func toggle_paused():
30+
is_paused = !is_paused
31+
32+
func toggle_speed_up():
33+
if speed == default_speed:
34+
speed = fast_speed
35+
else:
36+
speed = default_speed
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://2hgdqurtbrxg"]
1+
[gd_scene load_steps=4 format=3 uid="uid://2hgdqurtbrxg"]
22

33
[ext_resource type="Script" path="res://scripts/controllers/player_controller.gd" id="1_86wpr"]
44
[ext_resource type="Texture2D" uid="uid://p0bi3bytr53n" path="res://vendor/kenney_cursor-pack/PNG/Outline/Default/hand_closed.png" id="2_tvrf7"]
55
[ext_resource type="Texture2D" uid="uid://h7bopucdukak" path="res://vendor/kenney_cursor-pack/PNG/Outline/Default/pointer_b.png" id="3_h3cn0"]
6-
[ext_resource type="Texture2D" uid="uid://bjck8jhfqnq0b" path="res://vendor/kenney_cursor-pack/PNG/Outline/Double/arrow_e.png" id="4_sg2mc"]
7-
[ext_resource type="Texture2D" uid="uid://duld2c16y04fr" path="res://vendor/kenney_cursor-pack/PNG/Outline/Double/arrow_n.png" id="5_x6eqs"]
8-
[ext_resource type="Texture2D" uid="uid://ovblhumn68fu" path="res://vendor/kenney_cursor-pack/PNG/Outline/Double/arrow_s.png" id="6_c3rid"]
9-
[ext_resource type="Texture2D" uid="uid://bxw018pmva53p" path="res://vendor/kenney_cursor-pack/PNG/Outline/Double/arrow_w.png" id="7_gew4c"]
106

117
[node name="PlayerController" type="Node2D"]
128
script = ExtResource("1_86wpr")
139
mouse_drag_scroll_speed = 0.7
1410
drag_icon = ExtResource("2_tvrf7")
1511
arrow_icon = ExtResource("3_h3cn0")
16-
scroll_east_icon = ExtResource("4_sg2mc")
17-
scroll_north_icon = ExtResource("5_x6eqs")
18-
scroll_south_icon = ExtResource("6_c3rid")
19-
scroll_west_icon = ExtResource("7_gew4c")

scripts/controllers/player_controller.gd

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ extends Node2D
22

33
@export var keyboard_scroll_speed: float = 7
44
@export var mouse_drag_scroll_speed: float = 1.5
5-
@export var mouse_edge_scroll_speed: float = 6
65
@export var mouse_scroll_threshold: float = 50 # how many pixels from the sides of the screen triggers a mouse scroll
76
@export var drag_icon: Texture2D
87
@export var arrow_icon: Texture2D
9-
@export var scroll_east_icon: Texture2D
10-
@export var scroll_north_icon: Texture2D
11-
@export var scroll_south_icon: Texture2D
12-
@export var scroll_west_icon: Texture2D
138
@export var hud: Control
149
@export var camera_component: CameraComponent
1510
var is_dragging: bool = false
@@ -18,7 +13,7 @@ func _ready():
1813
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
1914
Input.set_custom_mouse_cursor(arrow_icon, Input.CURSOR_ARROW)
2015

21-
func _input(event):
16+
func _unhandled_input(event: InputEvent) -> void:
2217
if event.is_action_pressed("start_drag"):
2318
Input.set_custom_mouse_cursor(drag_icon, Input.CURSOR_DRAG)
2419
is_dragging = true
@@ -42,33 +37,5 @@ func _process(_delta: float) -> void:
4237
camera_movement += Vector2.UP * keyboard_scroll_speed
4338
elif Input.is_action_pressed("move_map_down"):
4439
camera_movement += Vector2.DOWN * keyboard_scroll_speed
45-
46-
var max_x = get_viewport_rect().size.x
47-
var max_y = get_viewport_rect().size.y
48-
var mouse_global_position = get_viewport().get_mouse_position()
49-
if mouse_global_position.x <= mouse_scroll_threshold:
50-
scroll_and_set_cursor(Vector2.LEFT)
51-
elif mouse_global_position.y <= mouse_scroll_threshold:
52-
scroll_and_set_cursor(Vector2.UP)
53-
elif mouse_global_position.y >= max_y - mouse_scroll_threshold:
54-
scroll_and_set_cursor(Vector2.DOWN)
55-
elif mouse_global_position.x >= max_x - mouse_scroll_threshold:
56-
scroll_and_set_cursor(Vector2.RIGHT)
57-
elif !is_dragging:
58-
hud.mouse_default_cursor_shape = Control.CURSOR_ARROW
5940

6041
camera_component.apply_camera_movement(camera_movement)
61-
62-
func scroll_and_set_cursor(direction: Vector2):
63-
match direction:
64-
Vector2.LEFT:
65-
Input.set_custom_mouse_cursor(scroll_west_icon, Input.CURSOR_MOVE)
66-
Vector2.RIGHT:
67-
Input.set_custom_mouse_cursor(scroll_east_icon, Input.CURSOR_MOVE)
68-
Vector2.DOWN:
69-
Input.set_custom_mouse_cursor(scroll_south_icon, Input.CURSOR_MOVE)
70-
Vector2.UP:
71-
Input.set_custom_mouse_cursor(scroll_north_icon, Input.CURSOR_MOVE)
72-
73-
hud.mouse_default_cursor_shape = Control.CURSOR_MOVE
74-
camera_component.apply_camera_movement(direction * mouse_edge_scroll_speed)

ui/viewmodels/vm_timer.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ class_name TimerViewModel
33

44
signal on_formatted_time_updated (new_time: String)
55

6+
var time_component: TimeComponent
7+
8+
func initialize(new_time_component: TimeComponent):
9+
time_component = new_time_component
10+
11+
func toggle_paused():
12+
time_component.toggle_paused()
13+
14+
func toggle_speed_up():
15+
time_component.toggle_speed_up()
16+
617
func set_time(new_timestamp: int):
718
var now_dict := Time.get_datetime_dict_from_unix_time(new_timestamp)
819
var formatted_datetime = _format_datetime(now_dict)

ui/widgets/GameTimeLabel.gd

Lines changed: 0 additions & 10 deletions
This file was deleted.

ui/widgets/hud.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ grow_horizontal = 2
1111
grow_vertical = 2
1212
size_flags_horizontal = 3
1313
size_flags_vertical = 3
14+
mouse_filter = 1
1415

1516
[node name="TopAppBar" parent="." instance=ExtResource("1_kowid")]
1617
layout_mode = 1

ui/widgets/top_app_bar.gd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extends Control
2+
3+
var view_model: TimerViewModel
4+
5+
@export var date_label: Label
6+
@export var pause_button: TextureButton
7+
@export var speed_up_button: TextureButton
8+
9+
func _ready() -> void:
10+
view_model = ViewModelRegistry.retrieve(ViewModelRegistry.Keys.TIMER) as TimerViewModel
11+
view_model.on_formatted_time_updated.connect(_handle_formatted_datetime_changed)
12+
pause_button.toggled.connect(_handle_pause_button_clicked)
13+
speed_up_button.toggled.connect(_handle_speed_up_button_clicked)
14+
15+
func _handle_formatted_datetime_changed(new_datetime: String):
16+
date_label.text = new_datetime
17+
18+
func _handle_pause_button_clicked(_is_toggled: bool):
19+
view_model.toggle_paused()
20+
21+
func _handle_speed_up_button_clicked(_is_toggled: bool):
22+
view_model.toggle_speed_up()

ui/widgets/top_app_bar.tscn

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://ci04dr1xobg8"]
1+
[gd_scene load_steps=8 format=3 uid="uid://ci04dr1xobg8"]
22

3+
[ext_resource type="Script" path="res://ui/widgets/top_app_bar.gd" id="1_7s546"]
34
[ext_resource type="Theme" uid="uid://dxgsaua2q7y8i" path="res://ui/themes/hud.tres" id="2_7qrg5"]
4-
[ext_resource type="Script" path="res://ui/widgets/GameTimeLabel.gd" id="3_08rmb"]
55
[ext_resource type="Texture2D" uid="uid://uwdw62p64s6" path="res://vendor/kenney_ui-pack-pixel-adventure/Tiles/Large tiles/Thick outline/tile_0028.png" id="3_rb1vo"]
6+
[ext_resource type="Texture2D" uid="uid://bef8hwvllnbmj" path="res://vendor/kenney_game-icons/PNG/White/1x/pause.png" id="4_vima0"]
7+
[ext_resource type="Texture2D" uid="uid://dxfxxwbmub6bx" path="res://vendor/kenney_game-icons/PNG/Black/1x/pause.png" id="5_cqa4u"]
8+
[ext_resource type="Texture2D" uid="uid://sjhcl4wxcwkn" path="res://vendor/kenney_game-icons/PNG/White/1x/fastForward.png" id="6_bwov5"]
9+
[ext_resource type="Texture2D" uid="uid://cqs1r264rxtpc" path="res://vendor/kenney_game-icons/PNG/Black/1x/fastForward.png" id="7_tcu34"]
610

7-
[node name="TopAppBar" type="Control"]
11+
[node name="TopAppBar" type="Control" node_paths=PackedStringArray("date_label", "pause_button", "speed_up_button")]
812
layout_mode = 3
913
anchors_preset = 10
1014
anchor_right = 1.0
11-
offset_bottom = 50.0
1215
grow_horizontal = 2
16+
mouse_filter = 2
17+
script = ExtResource("1_7s546")
18+
date_label = NodePath("HBoxContainer/GameTimeLabel")
19+
pause_button = NodePath("HBoxContainer/PauseButton")
20+
speed_up_button = NodePath("HBoxContainer/SpeedUpButton")
1321

1422
[node name="Background" type="NinePatchRect" parent="."]
1523
layout_mode = 1
@@ -23,18 +31,32 @@ patch_margin_top = 11
2331
patch_margin_right = 11
2432
patch_margin_bottom = 11
2533

26-
[node name="GameTimeLabel" type="Label" parent="Background"]
34+
[node name="HBoxContainer" type="HBoxContainer" parent="."]
2735
layout_mode = 1
28-
anchors_preset = 6
36+
anchors_preset = -1
2937
anchor_left = 1.0
30-
anchor_top = 0.5
3138
anchor_right = 1.0
32-
anchor_bottom = 0.5
33-
offset_left = -157.0
34-
offset_top = -12.0
35-
offset_bottom = 12.0
39+
offset_left = -189.0
40+
offset_right = -15.0
41+
offset_bottom = 50.0
3642
grow_horizontal = 0
37-
grow_vertical = 2
43+
mouse_filter = 2
44+
45+
[node name="GameTimeLabel" type="Label" parent="HBoxContainer"]
46+
layout_mode = 2
3847
theme = ExtResource("2_7qrg5")
3948
text = "January 1st, 2022"
40-
script = ExtResource("3_08rmb")
49+
50+
[node name="PauseButton" type="TextureButton" parent="HBoxContainer"]
51+
layout_mode = 2
52+
mouse_filter = 1
53+
toggle_mode = true
54+
texture_normal = ExtResource("4_vima0")
55+
texture_pressed = ExtResource("5_cqa4u")
56+
57+
[node name="SpeedUpButton" type="TextureButton" parent="HBoxContainer"]
58+
layout_mode = 2
59+
mouse_filter = 1
60+
toggle_mode = true
61+
texture_normal = ExtResource("6_bwov5")
62+
texture_pressed = ExtResource("7_tcu34")
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://df4eacllqsgpk"
6+
path="res://.godot/imported/arrowDown.png-1fd1fb734e065a0f923f7caf8e7aa1bd.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://vendor/kenney_game-icons/PNG/Black/1x/arrowDown.png"
14+
dest_files=["res://.godot/imported/arrowDown.png-1fd1fb734e065a0f923f7caf8e7aa1bd.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

0 commit comments

Comments
 (0)