Refactor pause handling; implement GameBus for pause state management and update event popup behavior
This commit is contained in:
@@ -50,7 +50,7 @@ public partial class EventManager : Node
|
||||
|
||||
private void FireEvent(EventDefinition eventDef)
|
||||
{
|
||||
GetTree().Paused = true;
|
||||
GameBus.Instance.SetPause(true);
|
||||
|
||||
var popup = _eventPopupScene.Instantiate<EventPopup>();
|
||||
_eventPopupContainer.AddChild(popup);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using ParasiticGod.Scripts.Singletons;
|
||||
|
||||
namespace ParasiticGod.Scripts.Components;
|
||||
|
||||
@@ -13,17 +14,30 @@ public partial class PauseManager : CanvasLayer
|
||||
ProcessMode = ProcessModeEnum.Always;
|
||||
_pauseMenu.Hide();
|
||||
_pauseButton.Pressed += TogglePause;
|
||||
|
||||
GameBus.Instance.PauseStateChanged += OnPauseStateChanged;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("pause")) TogglePause();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (GameBus.Instance != null)
|
||||
{
|
||||
GameBus.Instance.PauseStateChanged -= OnPauseStateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void TogglePause()
|
||||
{
|
||||
var isPaused = !GetTree().Paused;
|
||||
GetTree().Paused = isPaused;
|
||||
GameBus.Instance.SetPause(!GetTree().Paused);
|
||||
}
|
||||
|
||||
private void OnPauseStateChanged(bool isPaused)
|
||||
{
|
||||
_pauseMenu.Visible = isPaused;
|
||||
}
|
||||
}
|
@@ -32,6 +32,7 @@ public partial class GameBus : Node
|
||||
public event Action PopulationVisualsUpdated;
|
||||
public event Action<string> AgeAdvanced;
|
||||
public event Action GameWon;
|
||||
public event Action<bool> PauseStateChanged;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
@@ -133,12 +134,18 @@ public partial class GameBus : Node
|
||||
{
|
||||
effect.Execute(_gameState);
|
||||
}
|
||||
GetTree().Paused = false;
|
||||
SetPause(false);
|
||||
}
|
||||
|
||||
public void SubscribeToStat(Stat stat, Action<double> listener) => _gameState.Subscribe(stat, listener);
|
||||
public void UnsubscribeFromStat(Stat stat, Action<double> listener) => _gameState.Unsubscribe(stat, listener);
|
||||
|
||||
public void SetPause(bool isPaused)
|
||||
{
|
||||
GetTree().Paused = isPaused;
|
||||
PauseStateChanged?.Invoke(isPaused);
|
||||
}
|
||||
|
||||
public GameState CurrentState => _gameState;
|
||||
|
||||
[ConsoleCommand("set_stat", "Sets the value of a specified stat.")]
|
||||
|
@@ -16,7 +16,12 @@ public partial class EventPopup : PanelContainer
|
||||
private EventDefinition _eventDef;
|
||||
private Timer _timeoutTimer;
|
||||
private readonly RandomNumberGenerator _rng = new();
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ProcessMode = ProcessModeEnum.Always;
|
||||
}
|
||||
|
||||
public void DisplayEvent(EventDefinition eventDef)
|
||||
{
|
||||
_eventDef = eventDef;
|
||||
|
@@ -42,3 +42,73 @@ rm -rf \"{temp_dir}\""
|
||||
dotnet/include_scripts_content=false
|
||||
dotnet/include_debug_symbols=false
|
||||
dotnet/embed_build_outputs=false
|
||||
|
||||
[preset.1]
|
||||
|
||||
name="Windows Desktop"
|
||||
platform="Windows Desktop"
|
||||
runnable=true
|
||||
advanced_options=false
|
||||
dedicated_server=false
|
||||
custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path=""
|
||||
patches=PackedStringArray()
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
seed=0
|
||||
encrypt_pck=false
|
||||
encrypt_directory=false
|
||||
script_export_mode=2
|
||||
|
||||
[preset.1.options]
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=1
|
||||
binary_format/embed_pck=false
|
||||
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 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
||||
$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}'"
|
||||
dotnet/include_scripts_content=false
|
||||
dotnet/include_debug_symbols=true
|
||||
dotnet/embed_build_outputs=false
|
||||
|
Reference in New Issue
Block a user