Skip to content

Commit

Permalink
Pause works with reset and menu buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattHolliday committed Apr 22, 2024
1 parent bbf3cda commit ccf3ad2
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 151 deletions.
5 changes: 0 additions & 5 deletions EXIT_TO_MENUButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ func _pressed():
Engine.time_scale = GlobalVariables.time_scale_backup_one
GlobalVariables.time_scale_backup_one = GlobalVariables.time_scale_backup_two

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
4 changes: 0 additions & 4 deletions MenuButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ func _pressed():
Engine.time_scale = GlobalVariables.time_scale_backup_one
GlobalVariables.time_scale_backup_one = GlobalVariables.time_scale_backup_two

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
4 changes: 0 additions & 4 deletions MenuExitButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func _pressed():
Engine.time_scale = GlobalVariables.time_scale_backup_one
GlobalVariables.time_scale_backup_one = GlobalVariables.time_scale_backup_two

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
Expand Down
27 changes: 10 additions & 17 deletions PauseButton.gd
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
extends TextureButton

# Needs a way for c++ scripts to still run when paused for
# things like the fps counter, main menu and reset buttons
#var time_scale_backup_one: float
#var time_scale_backup_two: float
func _pressed():
var rootNode = get_tree().get_root()
var SaveAndQuit = rootNode.get_node("CellSpawner/UI/MenuPanels/SaveAndQuitMenuPanel").visible
var SimSettings = rootNode.get_node("CellSpawner/UI/MenuPanels/SimSettingsMenuPanel").visible
if (!SaveAndQuit and !SimSettings):
get_child(!GlobalVariables.used_pause_button).visible = false # Change pause button visually
get_child(GlobalVariables.used_pause_button).visible = true
GlobalVariables.used_pause_button = !GlobalVariables.used_pause_button
GlobalVariables.time_scale_backup_two = Engine.time_scale
Engine.time_scale = GlobalVariables.time_scale_backup_one

GlobalVariables.used_pause_button = !GlobalVariables.used_pause_button # Note that button was clicked

GlobalVariables.time_scale_backup_two = Engine.time_scale # Save prev delta
Engine.time_scale = GlobalVariables.time_scale_backup_one # Set delta
GlobalVariables.time_scale_backup_one = GlobalVariables.time_scale_backup_two

func getUsedPauseButton():
return GlobalVariables.used_pause_button

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS
#$time_scale_backup = $time_scale
#$time_scale = 0
#$time_scale = $time_scale_backup
#time_scale_backup_one = 0
func unpause(): # If paused, unpause
if (Engine.time_scale == 0):
_pressed()
get_child(0).visible = false # Change pause button to unpaused
get_child(1).visible = true

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
Expand Down
5 changes: 0 additions & 5 deletions SaveAndQuitButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ func _pressed():
root.get_node("CellSpawner/UI/MenuPanels/SaveAndQuitMenuPanel").visible = true
root.get_node("CellSpawner/UI/MenuPanels/SimSettingsMenuPanel").visible = false

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
5 changes: 0 additions & 5 deletions SimSettingsButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ func _pressed():
root.get_node("CellSpawner/UI/MenuPanels/SaveAndQuitMenuPanel").visible = false
root.get_node("CellSpawner/UI/MenuPanels/SimSettingsMenuPanel").visible = true

# Called when the node enters the scene tree for the first time.
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
15 changes: 0 additions & 15 deletions StatsOpenButton.gd

This file was deleted.

1 change: 0 additions & 1 deletion StatsPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var drag_offset = Vector2()
# Called when the node enters the scene tree for the first time.
func _ready():
mouse_filter = Control.MOUSE_FILTER_STOP
process_mode = Node.PROCESS_MODE_ALWAYS

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
Expand Down
176 changes: 88 additions & 88 deletions dark_mode.tres

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/main_menu_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ void MainMenuButton::_pressed() {
// Remove old cells
CellSpawner *spawner = Object::cast_to<CellSpawner>(this->find_parent("CellSpawner"));
spawner->removeAllCells();
// Remove old nutrient zones
CellEnvironment *environment = spawner->get_node<CellEnvironment>("CellEnvironment");
environment->removeAllNutrientZones();

// Close in-simulation display
Node *UI = spawner->get_child(1);
Object::cast_to<CanvasItem>(UI->get_child(5))->set_visible(false); // NavBar
Object::cast_to<CanvasItem>(UI->get_child(2))->set_visible(false); // Stats
Node *UI = spawner->get_node<Node>("UI");
UI->get_node<CanvasItem>("NavBar")->set_visible(false);
UI->get_node<CanvasItem>("StatsPanel")->set_visible(false);
UI->get_node<CanvasItem>("MenuPanels/SaveAndQuitMenuPanel")->set_visible(false);
Object::cast_to<FpsCounter>(UI->find_child("FpsCounter"))->toggle_fps();
Object::cast_to<TimeCounter>(UI->find_child("TimeCounter"))->toggle_time();

Object::cast_to<CanvasItem>(UI->get_child(4))->set_visible(true); // Open menu
UI->get_node<CanvasItem>("BarPanel")->set_visible(true); // Open menu

// Respawn background cells that don't die
spawner->get_node<Node>("UI/NavBar/PauseButton")->call("unpause");
for (int i = 0; i < spawner->getNumCells(); i++) {
spawner->spawnCell(1);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main_menu_button.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "cell_environment.hpp"
#include "cell_spawner.hpp"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/texture_button.hpp>
Expand All @@ -16,8 +17,6 @@ class MainMenuButton : public TextureButton {
MainMenuButton();
~MainMenuButton();

// void _ready() override;

void _pressed();
};

Expand Down
3 changes: 3 additions & 0 deletions src/reset_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void ResetButton::_pressed() {
CellSpawner *spawner = Object::cast_to<CellSpawner>(this->find_parent("CellSpawner"));
spawner->removeAllCells();

spawner->get_node<CanvasItem>("UI/MenuPanels/SaveAndQuitMenuPanel")->set_visible(false);
spawner->get_node<Node>("UI/NavBar/PauseButton")->call("unpause");

// Respawn new cells
Object::cast_to<TimeCounter>(spawner->get_child(1))->reset_time();
for (int i = 0; i < spawner->getNumCells(); i++) {
Expand Down
1 change: 0 additions & 1 deletion src/stats_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void StatsCounter::_process(double delta) {
}

void StatsCounter::_ready() {
set_process_mode(Node::PROCESS_MODE_ALWAYS);
add_label("Click a cell to see information");
}

Expand Down

0 comments on commit ccf3ad2

Please sign in to comment.