120 lines
3.7 KiB
GDScript
120 lines
3.7 KiB
GDScript
extends CanvasLayer
|
|
|
|
@onready var _spawn_control = get_node("/root/Game/SpawnControl")
|
|
@onready var _witch = get_node("/root/Game/Witch")
|
|
@onready var _drop_manager = get_node("/root/Game/DropManager")
|
|
|
|
var _spell_dispatch: Dictionary
|
|
var _lvl_disable_btn: Button
|
|
|
|
func _ready() -> void:
|
|
layer = 10
|
|
_spell_dispatch = {
|
|
SpellLibrary.FIREBALL: _witch.shoot_fireballs,
|
|
SpellLibrary.SHURIKEN: _witch.shoot_shuriken,
|
|
SpellLibrary.FIRE_SWIRL: _witch.shoot_fire_swirl,
|
|
SpellLibrary.TORNADO: _witch.shoot_tornado,
|
|
SpellLibrary.LASER: _witch.shoot_laser,
|
|
}
|
|
_build_ui()
|
|
hide()
|
|
|
|
func _exit_tree() -> void:
|
|
Engine.time_scale = 1.0
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed and not event.echo:
|
|
if event.keycode == KEY_D and event.ctrl_pressed:
|
|
visible = not visible
|
|
get_viewport().set_input_as_handled()
|
|
|
|
func _build_ui() -> void:
|
|
var panel := PanelContainer.new()
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color(0.0, 0.0, 0.0, 0.75)
|
|
panel.add_theme_stylebox_override("panel", style)
|
|
panel.anchor_left = 1.0
|
|
panel.anchor_right = 1.0
|
|
panel.anchor_top = 0.0
|
|
panel.anchor_bottom = 1.0
|
|
panel.offset_left = -220
|
|
panel.offset_right = 0
|
|
add_child(panel)
|
|
|
|
var scroll := ScrollContainer.new()
|
|
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
|
panel.add_child(scroll)
|
|
|
|
var vbox := VBoxContainer.new()
|
|
vbox.custom_minimum_size = Vector2(210, 0)
|
|
vbox.add_theme_constant_override("separation", 4)
|
|
scroll.add_child(vbox)
|
|
|
|
_add_section(vbox, "ENEMIES")
|
|
_add_button(vbox, "Kill All", _kill_all_enemies)
|
|
|
|
_add_section(vbox, "TIME SCALE")
|
|
var hbox_scale := HBoxContainer.new()
|
|
vbox.add_child(hbox_scale)
|
|
for s in [1, 2, 5, 10]:
|
|
var btn := Button.new()
|
|
btn.text = "%dx" % s
|
|
btn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
btn.pressed.connect(_set_time_scale.bind(float(s)))
|
|
hbox_scale.add_child(btn)
|
|
|
|
_add_section(vbox, "SKIP TIME")
|
|
var hbox_time := HBoxContainer.new()
|
|
vbox.add_child(hbox_time)
|
|
for secs in [30, 60]:
|
|
var btn := Button.new()
|
|
btn.text = "+%ds" % secs
|
|
btn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
btn.pressed.connect(_skip_time.bind(float(secs)))
|
|
hbox_time.add_child(btn)
|
|
|
|
_add_section(vbox, "SPELLS")
|
|
for spell_id in SpellLibrary.recipes.keys():
|
|
if _spell_dispatch.has(spell_id):
|
|
_add_button(vbox, spell_id.capitalize(), _spell_dispatch[spell_id])
|
|
|
|
_add_section(vbox, "LEVEL")
|
|
_add_button(vbox, "Level Up", _force_level_up)
|
|
_lvl_disable_btn = Button.new()
|
|
_lvl_disable_btn.text = "Disable Level Up: OFF"
|
|
_lvl_disable_btn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
_lvl_disable_btn.pressed.connect(_toggle_level_up_disabled)
|
|
vbox.add_child(_lvl_disable_btn)
|
|
|
|
func _add_section(parent: VBoxContainer, title: String) -> void:
|
|
var label := Label.new()
|
|
label.text = title
|
|
label.add_theme_color_override("font_color", Color.YELLOW)
|
|
label.add_theme_font_size_override("font_size", 11)
|
|
parent.add_child(label)
|
|
|
|
func _add_button(parent: VBoxContainer, label: String, callback: Callable) -> void:
|
|
var btn := Button.new()
|
|
btn.text = label
|
|
btn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
btn.pressed.connect(callback)
|
|
parent.add_child(btn)
|
|
|
|
func _kill_all_enemies() -> void:
|
|
for enemy in get_tree().get_nodes_in_group("enemies"):
|
|
if is_instance_valid(enemy):
|
|
enemy.die()
|
|
|
|
func _set_time_scale(scale: float) -> void:
|
|
Engine.time_scale = scale
|
|
|
|
func _skip_time(secs: float) -> void:
|
|
_spawn_control.elapsed_time += secs
|
|
|
|
func _force_level_up() -> void:
|
|
_drop_manager.force_level_up()
|
|
|
|
func _toggle_level_up_disabled() -> void:
|
|
_drop_manager.level_up_disabled = not _drop_manager.level_up_disabled
|
|
_lvl_disable_btn.text = "Disable Level Up: " + ("ON" if _drop_manager.level_up_disabled else "OFF")
|