Add window panning

This commit is contained in:
Ategon 2024-10-07 18:44:32 -04:00
parent 355e699601
commit aa07378fc6
13 changed files with 132 additions and 36 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
# Godot 4+ specific ignores
.godot/
/android/
builds/

View file

@ -9,7 +9,7 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4cq27"]
size = Vector2(4, 4)
[node name="Cursor" type="CanvasLayer"]
[node name="Cursor" type="CanvasLayer" groups=["Cursor"]]
process_mode = 3
script = ExtResource("1_nmkwm")

64
export_presets.cfg Normal file
View file

@ -0,0 +1,64 @@
[preset.0]
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*.txt"
exclude_filter=""
export_path="builds/window-creatures.exe"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.0.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=true
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
codesign/enable=false
codesign/timestamp=true
codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=true
application/icon=""
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version=""
application/product_version=""
application/company_name=""
application/product_name=""
application/file_description=""
application/copyright=""
application/trademarks=""
application/export_angle=0
application/export_d3d12=0
application/d3d12_agility_sdk_multiarch=true
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
Start-ScheduledTask -TaskName godot_remote_debug
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"

View file

@ -29,6 +29,8 @@ func _ready() -> void:
get_viewport().transparent_bg = true
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, true)
upgrade_pool.shuffle()
zone_pool.shuffle()
var new_buttons = UI_BUTTONS.instantiate()
var new_cursor = CURSOR.instantiate()
new_buttons.add_child(new_cursor)

View file

@ -3,4 +3,4 @@ description: 10% higher chance for a creature to drop coins ev
property: creature_resource_spawn_rate
type: percent
amount: 10
cost: 5
cost: 3

View file

@ -2,4 +2,4 @@ name: Creature Bait
description: 2 More creatures will wander onto your property every day
property: creature_amount
amount: 2
cost: 7
cost: 3

View file

@ -201,6 +201,7 @@ volume_db = -10.0
stream = ExtResource("9_fxutd")
volume_db = 5.0
[connection signal="close_requested" from="." to="Control" method="_on_build_window_close_requested"]
[connection signal="clicked" from="Control/Upgrade/MouseHandler" to="Control" method="_on_mouse_handler_clicked"]
[connection signal="hovered" from="Control/Upgrade/MouseHandler" to="Control" method="_on_mouse_handler_hovered"]
[connection signal="unhovered" from="Control/Upgrade/MouseHandler" to="Control" method="_on_mouse_handler_unhovered"]

View file

@ -31,29 +31,5 @@ wait_time = 6.0
one_shot = true
autostart = true
[node name="Timer3" type="Timer" parent="."]
wait_time = 12.0
one_shot = true
autostart = true
[node name="Timer4" type="Timer" parent="."]
wait_time = 20.0
one_shot = true
autostart = true
[node name="Timer5" type="Timer" parent="."]
wait_time = 30.0
one_shot = true
autostart = true
[node name="Timer6" type="Timer" parent="."]
wait_time = 50.0
one_shot = true
autostart = true
[connection signal="timeout" from="Timer" to="Node2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Timer2" to="Node2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Timer3" to="Node2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Timer4" to="Node2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Timer5" to="Node2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Timer6" to="Node2D" method="_on_timer_timeout"]

View file

@ -56,14 +56,15 @@ var buying = [
]
func _ready() -> void:
main.upgrade_pool.shuffle()
main.zone_pool.shuffle()
var screen_size = DisplayServer.screen_get_size(0)
get_window().position = DisplayServer.screen_get_position(0) + screen_size / 2 - Vector2i(450, 250)
_refresh_cards()
func _process(delta: float) -> void:
if get_window().mode == Window.MODE_MINIMIZED:
get_window().mode = Window.MODE_WINDOWED
func _refresh_cards():
for i in range(0, 3):
@ -89,11 +90,15 @@ func _update_card(index):
main.upgrade_pool.shuffle()
choice = main.upgrade_pool.pop_back()
card_data = Data.data.upgrades[choice]
cost = card_data.cost + (round(card_data.cost / 2) * Persister.get_value(choice, PersisterEnums.Scope.UNKNOWN, 0))
cost = card_data.cost
for i in range(0, Persister.get_value(choice, PersisterEnums.Scope.UNKNOWN, 0)):
cost += round(cost / 2)
cards[index].title.text = "[center]%s" % [card_data.name]
cards[index].cost.text = "[center]%d G" % [cost]
card_data.key = choice
card_data.actual_cost = cost
chosen_cards[index] = card_data
if (index == 1 and chosen_cards[0].key == choice) or (index == 0 and chosen_cards[1] and chosen_cards[1].key == choice):
@ -133,8 +138,8 @@ func _buy_upgrade(index):
return
var card_data = chosen_cards[index]
if Persister.get_value("gold", PersisterEnums.Scope.UNKNOWN, 0) >= (card_data.cost if card_data.has("cost") else 10 + (5 * Persister.get_value("zones_bought", PersisterEnums.Scope.UNKNOWN, 0))):
Persister.change_value("gold", -(card_data.cost if card_data.has("cost") else 10 + (5 * Persister.get_value("zones_bought", PersisterEnums.Scope.UNKNOWN, 0))))
if Persister.get_value("gold", PersisterEnums.Scope.UNKNOWN, 0) >= (card_data.actual_cost if card_data.has("actual_cost") else 10 + (5 * Persister.get_value("zones_bought", PersisterEnums.Scope.UNKNOWN, 0))):
Persister.change_value("gold", -(card_data.actual_cost if card_data.has("actual_cost") else 10 + (5 * Persister.get_value("zones_bought", PersisterEnums.Scope.UNKNOWN, 0))))
buying[index] = true
@ -195,3 +200,8 @@ func _on_mouse_handler_unhovered() -> void:
tweens[index].set_parallel()
tweens[index].tween_property(cards[index].title, "modulate", Color.WHITE, 0.25)
tweens[index].tween_property(cards[index].object, "position:y", 42.5, 0.25)
func _on_build_window_close_requested() -> void:
get_window().queue_free()
Triggerer.trigger("window_close_icon")

View file

@ -9,7 +9,7 @@ const CREATURE = preload("res://src/Creature.tscn")
var mouse_in_window = false
func _ready() -> void:
Persister.change_value("creature_amount", 4)
Persister.change_value("creature_amount", 8)
Triggerer.listen("minutes", _on_minutes)
Triggerer.listen("day", _on_day)
_generate_spawn_times()
@ -18,7 +18,9 @@ func _ready() -> void:
get_window().position = Vector2i(50, screen_size.y - 300 - 50) + DisplayServer.screen_get_position(0)
func _process(delta: float) -> void:
if get_window().mode == Window.MODE_MINIMIZED:
get_window().mode = Window.MODE_WINDOWED
func _on_minutes(_data):
minutes_left -= 1
@ -50,7 +52,7 @@ func _on_day(_data):
func _generate_spawn_times():
spawn_times = []
for i in range(0, 4):
for i in range(0, Persister.get_value("creature_amount")):
spawn_times.push_back(randi_range(2, 6 * 24 - 2))

View file

@ -12,9 +12,17 @@ var mouse_in_window
#print("EXITED")
#mouse_in_window = false
var last_mouse = Vector2.ZERO
var cursor
var diff = Vector2.ZERO
var following = false
func _ready() -> void:
Triggerer.listen("released", _on_released)
var children = get_parent().get_children()
for child in children:
if child.is_in_group("Cursor"):
cursor = child
func _on_released(_data):
@ -22,6 +30,27 @@ func _on_released(_data):
get_window().grab_focus()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("right_click") and mouse_in_window:
following = true
if Input.is_action_just_released("right_click"):
following = false
var mouse = get_tree().root.get_mouse_position()
if following:
diff += (mouse - last_mouse) * 4
var x = floor(diff.x)
var y = floor(diff.y)
get_parent().position += Vector2i(x, y)
diff -= Vector2(x, y)
last_mouse = mouse
func _notification(blah):
match blah:
NOTIFICATION_WM_MOUSE_EXIT:

View file

@ -13,6 +13,13 @@ var size_tween
func _ready() -> void:
sprite_2d.texture = image
Triggerer.listen("window_close_icon", _on_window_close_icon)
func _on_window_close_icon(_data):
if key == "upgrade_menu":
sprite_2d.texture = image
func _on_mouse_handler_clicked() -> void:
if value == "toggle":

View file

@ -12,6 +12,10 @@ const CREATURE = preload("res://src/Creature.tscn")
var tiles = []
var newt = []
func _process(delta: float) -> void:
if mode == Window.MODE_MINIMIZED:
mode = Window.MODE_WINDOWED
func _ready() -> void:
var window_size = get_tree().root.get_window().size