New base menu template

This commit is contained in:
2ndbeam 2024-05-15 07:48:03 +03:00
commit f2cff37a22
12 changed files with 185 additions and 16 deletions

View file

@ -2,21 +2,25 @@ extends StaticBody2D
class_name Base
enum DockState { Ready, Process, Busy }
enum DockState { Ready, Process, Busy, Leave }
signal dock_requested
## Reference to star system
@onready var star_system: StarSystem = get_tree().current_scene
## Physical gate
@onready var gate_static = $Gate
## Logical gate for docking
@onready var gate_area = $GateArea
## Docking area
@onready var dock_area = $DockingArea
## Menu which will instantiate on docking
@export var menu: PackedScene
@export var faction: Game.Faction
## Decides whether ship is docked or in process
var dock_state: DockState = DockState.Ready
var touching_gate = false
@ -66,6 +70,9 @@ func _process(_delta):
dock_busy()
if !touching_dock and !touching_gate and distance_to_player > 2048:
dock_ready()
if dock_state == DockState.Leave:
if !touching_dock and !touching_gate:
dock_ready()
## Sets dock state to Ready
func dock_ready():
@ -74,8 +81,6 @@ func dock_ready():
gate_static.process_mode = Node.PROCESS_MODE_INHERIT
gate_area.visible = false
dock_area.visible = false
touching_gate = false
touching_dock = false
## Sets dock state to Process
func dock_process():
dock_state = DockState.Process
@ -83,8 +88,6 @@ func dock_process():
gate_static.process_mode = Node.PROCESS_MODE_DISABLED
gate_area.visible = true
dock_area.visible = true
touching_gate = false
touching_dock = false
## Sets dock state to Busy
func dock_busy():
dock_state = DockState.Busy
@ -92,6 +95,14 @@ func dock_busy():
gate_static.process_mode = Node.PROCESS_MODE_INHERIT
gate_area.visible = false
dock_area.visible = false
touching_gate = false
touching_dock = true
# TODO: implement opening the base menu
# opening base menu
var menu_instance = menu.instantiate()
menu_instance.base = self
player_ship.non_colorable_gui.add_child(menu_instance)
func dock_leave():
dock_state = DockState.Leave
gate_static.visible = false
gate_static.process_mode = Node.PROCESS_MODE_DISABLED
gate_area.visible = true
dock_area.visible = true

View file

@ -0,0 +1,4 @@
extends Control
## Base which provided this menu
var base: Base

View file

@ -0,0 +1,7 @@
extends Button
@onready var menu = $"../../.."
func _on_button_up():
menu.base.dock_leave()
menu.queue_free()