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()

View file

@ -15,6 +15,11 @@ var expected_rotation: float = 0.0:
expected_rotation = value
func _physics_process(_delta) -> void:
if ship.selected_node is Base:
if Input.is_action_just_released("dock"):
ship.selected_node.dock_requested.emit()
if ship.selected_node.dock_state == Base.DockState.Busy:
return
ship.engine.acceleration_axis = Input.get_axis("deccelerate", "accelerate")
ship.engine.rotation_axis = Input.get_axis("rotateleft", "rotateright")
for weapon in ship.weapons.list:
@ -29,5 +34,3 @@ func _physics_process(_delta) -> void:
weapon.gun_rotation = expected_rotation
if Input.is_action_just_released("select_target"):
ship.selected_node = star_system.targeted_node
if ship.selected_node is Base and Input.is_action_just_released("dock"):
ship.selected_node.dock_requested.emit()

View file

@ -6,6 +6,8 @@ class_name PlayerShip
@onready var camera = $Camera
## Player colorable GUI reference
@onready var colorable_gui = $ColorableGUI
## Player non-colorable GUI reference
@onready var non_colorable_gui = $NonColorableGUI
## Node which was selected by input
var selected_node: Node2D = null
## Currency variable