Skip to content

Commit

Permalink
Merge pull request #16 from benfrankel/pause-menu-improvements
Browse files Browse the repository at this point in the history
fixed pause menu related bugs/unintended functionalities
  • Loading branch information
QueenOfSquiggles authored Nov 16, 2023
2 parents 982fe52 + c600dcf commit 8d519e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 12 additions & 7 deletions scenes/overworld/gui/pause_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ extends Control

@onready var save_button := $MainPanel/PanelContainer/MarginContainer/VBoxContainer/BtnSave
@onready var inventory_panel := $InventoryPanel
# Called when the node enters the scene tree for the first time.

var prior_mouse_state : Input.MouseMode

func _ready() -> void:
prior_mouse_state = Input.mouse_mode # grab previous state
if not GameManager.pausing_allowed:
# mouse state is automatically applied when leaving the tree for any reason, so we need to know the state before queue free
queue_free()
return
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE # pause menu requires mouse access
get_tree().paused = true
save_button.grab_focus()
inventory_panel.visible = false




func _on_btn_save_pressed() -> void:
pass # Replace with function body.


func _on_btn_inventory_pressed() -> void:
inventory_panel.visible = not inventory_panel.visible


func _on_btn_quit_pressed() -> void:
push_warning("this should move to a main menu once implemented")
get_tree().quit()


func _on_inventory_panel_focus_exited() -> void:
inventory_panel.visible = false

Expand All @@ -32,3 +34,6 @@ func _unhandled_input(event: InputEvent) -> void:
get_viewport().set_input_as_handled()
get_tree().paused = false
queue_free()

func _exit_tree() -> void:
Input.mouse_mode = prior_mouse_state # reset to previous state
9 changes: 7 additions & 2 deletions scripts/globals/game_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const COMBAT_SCENE := preload("res://scenes/combat/combat.tscn") as PackedScene

var viewport: ViewportManager
var scene_backup: Node

var pausing_allowed := true

func enter_room(room_path: String, door_idx: int) -> void:
var room := (load(room_path) as PackedScene).instantiate() # may cause stutter here for large rooms.
Expand All @@ -20,18 +20,23 @@ func enter_room(room_path: String, door_idx: int) -> void:
var door := room.get_node(DOORS_PATH).get_children()[door_idx] as Door
door.is_active = false
player.global_position = door.global_position

pausing_allowed = false
(await viewport.swap_scene(room)).queue_free()
pausing_allowed = true



func enter_combat(enemy_path: String) -> void:
pausing_allowed = false
var combat := COMBAT_SCENE.instantiate()
combat.enemy = load(enemy_path) as Enemy
scene_backup = await viewport.swap_scene(combat)


func exit_combat() -> void:
(await viewport.swap_scene(scene_backup)).queue_free()
pausing_allowed = true



func do_dialog(dialog : Dialog) -> void:
Expand Down

0 comments on commit 8d519e9

Please # to comment.