Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
67
scripts/menu/BuyMenuButton.gd
Normal file
67
scripts/menu/BuyMenuButton.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends NinePatchRect
|
||||
|
||||
@export var data : Dictionary = {"id" : ""} ## Contains all buy options. Must have "id" key.
|
||||
@export var price : float
|
||||
@export var clickable : BaseButton
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
if ship.money >= price:
|
||||
ship.money -= price
|
||||
bought_action()
|
||||
|
||||
func bought_action():
|
||||
match data["id"]:
|
||||
"hp":
|
||||
if ship.hull.hp >= ship.hull.max_hp:
|
||||
ship.hull.hp = ship.hull.max_hp
|
||||
ship.money += price
|
||||
return
|
||||
ship.hull.hp += 1
|
||||
while(ship.hull.hp < ship.hull.max_hp and ship.money >= price):
|
||||
ship.hull.hp += 1
|
||||
ship.money -= price
|
||||
if ship.hull.hp > ship.hull.max_hp: ship.hull.hp = ship.hull.max_hp
|
||||
"rockets":
|
||||
if ship.hull.ammunition["Rockets"] == ship.hull.max_ammunition["Rockets"]:
|
||||
ship.money += price
|
||||
return
|
||||
var rocket_price : float = price / data["amount"]
|
||||
if ship.hull.ammunition["Rockets"] + data["amount"] > ship.hull.max_ammunition["Rockets"]:
|
||||
var rockets_left = ship.hull.max_ammunition["Rockets"] - ship.hull.ammunition["Rockets"]
|
||||
for i in range(rockets_left + 1):
|
||||
ship.money += rocket_price
|
||||
ship.hull.ammunition["Rockets"] = ship.hull.max_ammunition["Rockets"]
|
||||
else:
|
||||
ship.hull.ammunition["Rockets"] += data["amount"]
|
||||
"fuel":
|
||||
if ship.hull.fuel == ship.hull.max_fuel:
|
||||
ship.money += price
|
||||
return
|
||||
if ship.hull.fuel + data["amount"] > ship.hull.max_fuel:
|
||||
ship.hull.fuel = ship.hull.max_fuel
|
||||
else:
|
||||
ship.hull.fuel += data["amount"]
|
||||
"weapon":
|
||||
var primary_slot = ship.get_node("PrimaryWeapon")
|
||||
var secondary_slot = ship.get_node("SecondaryWeapon")
|
||||
var bought_weapon = get_tree().current_scene.bought_weapon
|
||||
var weapon_dict = get_tree().current_scene.weapon_dict
|
||||
var slot = primary_slot if data["slot"] == "primary" else secondary_slot
|
||||
if !bought_weapon[data["weapon"]]:
|
||||
bought_weapon[data["weapon"]] = true
|
||||
else:
|
||||
ship.money += price
|
||||
if slot.get_child_count() == 0:
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
else:
|
||||
for node in slot.get_children():
|
||||
node.queue_free()
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
38
scripts/menu/MainMenu.gd
Normal file
38
scripts/menu/MainMenu.gd
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
extends Node2D
|
||||
|
||||
var map_width = 1280
|
||||
var map_height = 720
|
||||
@onready var b1 = $Control/MenuButton1
|
||||
@onready var b2 = $Control/MenuButton2
|
||||
@onready var b3 = $Control/MenuButton3
|
||||
@onready var b4 = $Control/MenuButton4
|
||||
@onready var b5 = $Control/MenuButton5
|
||||
|
||||
func _ready():
|
||||
change_menu(0)
|
||||
|
||||
func change_menu(id):
|
||||
match id:
|
||||
0:
|
||||
b1.id = "NewGame"
|
||||
b2.id = "Profiles"
|
||||
b3.id = "Settings"
|
||||
b4.id = "Credits"
|
||||
b5.id = "ExitGame"
|
||||
1:
|
||||
b1.id = "CreateProfile"
|
||||
b2.id = "LoadProfile"
|
||||
b3.id = "DeleteProfile"
|
||||
b4.id = "Back"
|
||||
b5.id = "Null"
|
||||
2:
|
||||
b1.id = ""
|
||||
b2.id = ""
|
||||
b3.id = ""
|
||||
b4.id = ""
|
||||
b5.id = ""
|
||||
b1.change_name()
|
||||
b2.change_name()
|
||||
b3.change_name()
|
||||
b4.change_name()
|
||||
b5.change_name()
|
||||
47
scripts/menu/MainMenuButton.gd
Normal file
47
scripts/menu/MainMenuButton.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
extends Button
|
||||
|
||||
@export var id = "Null"
|
||||
|
||||
@onready var сontroller = $"../.."
|
||||
|
||||
func _ready():
|
||||
button_up.connect(_on_button_up)
|
||||
change_name()
|
||||
|
||||
func _on_button_up():
|
||||
match id:
|
||||
"NewGame":
|
||||
get_tree().change_scene_to_file("res://scenes/Space.tscn")
|
||||
"CreateProfile":
|
||||
Game.profile_create("1")
|
||||
"LoadProfile":
|
||||
Game.profile_load("1")
|
||||
"ExitGame":
|
||||
get_tree().quit()
|
||||
|
||||
func change_name():
|
||||
visible = true
|
||||
match id:
|
||||
"NewGame":
|
||||
text = "New Game"
|
||||
"CreateProfile":
|
||||
text = "Create Profile"
|
||||
"LoadProfile":
|
||||
text = "Load Profile"
|
||||
"DeleteProfile":
|
||||
text = "Delete Profile"
|
||||
"ExitGame":
|
||||
text = "Exit Game"
|
||||
"Settings":
|
||||
text = "Settings (WIP)"
|
||||
"AudioSettings":
|
||||
text = "Audio (WIP)"
|
||||
"VideoSettings":
|
||||
text = "Video (WIP)"
|
||||
"Profiles":
|
||||
text = "Profiles (WIP)"
|
||||
"Back":
|
||||
text = "Back"
|
||||
"Null":
|
||||
text = Game.gameversion
|
||||
visible = false
|
||||
16
scripts/menu/MenuButton.gd
Normal file
16
scripts/menu/MenuButton.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends NinePatchRect
|
||||
|
||||
class_name MenuDefaultButton
|
||||
|
||||
@export var clickable : BaseButton
|
||||
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
action()
|
||||
|
||||
func action():
|
||||
pass
|
||||
4
scripts/menu/OptionsColors.gd
Normal file
4
scripts/menu/OptionsColors.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
get_tree().current_scene.recolor()
|
||||
4
scripts/menu/ResetMainShip.gd
Normal file
4
scripts/menu/ResetMainShip.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
ship.destroy()
|
||||
Loading…
Add table
Add a link
Reference in a new issue