211 lines
6.6 KiB
GDScript
211 lines
6.6 KiB
GDScript
extends Control
|
|
|
|
static var volume: float = 100.0
|
|
|
|
var settings_panel: Panel
|
|
var difficulty_panel: Panel
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_build_ui()
|
|
_apply_volume(volume)
|
|
|
|
func _build_ui() -> void:
|
|
var bg := ColorRect.new()
|
|
bg.color = Color(0.06, 0.04, 0.10)
|
|
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
add_child(bg)
|
|
|
|
var title := Label.new()
|
|
title.text = "KickSurvivors"
|
|
title.add_theme_font_size_override("font_size", 52)
|
|
title.add_theme_color_override("font_color", Color.WHITE)
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
title.anchor_left = 0.5
|
|
title.anchor_right = 0.5
|
|
title.anchor_top = 0.0
|
|
title.offset_left = -200
|
|
title.offset_right = 200
|
|
title.offset_top = 110
|
|
add_child(title)
|
|
|
|
var vbox := VBoxContainer.new()
|
|
vbox.add_theme_constant_override("separation", 14)
|
|
vbox.anchor_left = 0.5
|
|
vbox.anchor_right = 0.5
|
|
vbox.anchor_top = 0.5
|
|
vbox.anchor_bottom = 0.5
|
|
vbox.offset_left = -110
|
|
vbox.offset_right = 110
|
|
vbox.offset_top = -90
|
|
vbox.offset_bottom = 90
|
|
add_child(vbox)
|
|
|
|
vbox.add_child(_btn("Играть", _on_play))
|
|
vbox.add_child(_btn("Настройки", _on_settings))
|
|
vbox.add_child(_btn("Выход", _on_exit))
|
|
|
|
_build_settings_panel()
|
|
_build_difficulty_panel()
|
|
|
|
func _btn(text: String, cb: Callable) -> Button:
|
|
var b := Button.new()
|
|
b.text = text
|
|
b.custom_minimum_size = Vector2(220, 54)
|
|
b.add_theme_font_size_override("font_size", 20)
|
|
for state in ["normal", "hover", "pressed", "focus", "disabled"]:
|
|
var sb := StyleBoxFlat.new()
|
|
sb.bg_color = Color(0.18, 0.13, 0.30) if state == "normal" else (
|
|
Color(0.28, 0.20, 0.46) if state == "hover" else
|
|
Color(0.12, 0.09, 0.22))
|
|
sb.border_width_left = 1
|
|
sb.border_width_right = 1
|
|
sb.border_width_top = 1
|
|
sb.border_width_bottom = 1
|
|
sb.border_color = Color(0.50, 0.38, 0.75)
|
|
sb.corner_radius_top_left = 6
|
|
sb.corner_radius_top_right = 6
|
|
sb.corner_radius_bottom_left = 6
|
|
sb.corner_radius_bottom_right = 6
|
|
sb.content_margin_left = 20
|
|
sb.content_margin_right = 20
|
|
sb.content_margin_top = 12
|
|
sb.content_margin_bottom = 12
|
|
b.add_theme_stylebox_override(state, sb)
|
|
b.connect("pressed", cb)
|
|
return b
|
|
|
|
static func _make_opaque_panel() -> Panel:
|
|
var p := Panel.new()
|
|
var sb := StyleBoxFlat.new()
|
|
sb.bg_color = Color(0.08, 0.06, 0.14)
|
|
sb.border_width_left = 2
|
|
sb.border_width_right = 2
|
|
sb.border_width_top = 2
|
|
sb.border_width_bottom = 2
|
|
sb.border_color = Color(0.35, 0.28, 0.55)
|
|
sb.corner_radius_top_left = 8
|
|
sb.corner_radius_top_right = 8
|
|
sb.corner_radius_bottom_left = 8
|
|
sb.corner_radius_bottom_right = 8
|
|
sb.content_margin_left = 24
|
|
sb.content_margin_right = 24
|
|
sb.content_margin_top = 20
|
|
sb.content_margin_bottom = 20
|
|
p.add_theme_stylebox_override("panel", sb)
|
|
return p
|
|
|
|
func _build_settings_panel() -> void:
|
|
settings_panel = _make_opaque_panel()
|
|
settings_panel.visible = false
|
|
settings_panel.anchor_left = 0.5
|
|
settings_panel.anchor_right = 0.5
|
|
settings_panel.anchor_top = 0.5
|
|
settings_panel.anchor_bottom = 0.5
|
|
settings_panel.offset_left = -200
|
|
settings_panel.offset_right = 200
|
|
settings_panel.offset_top = -130
|
|
settings_panel.offset_bottom = 130
|
|
add_child(settings_panel)
|
|
|
|
var vbox := VBoxContainer.new()
|
|
vbox.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
vbox.add_theme_constant_override("separation", 18)
|
|
settings_panel.add_child(vbox)
|
|
|
|
var lbl := Label.new()
|
|
lbl.text = "Настройки"
|
|
lbl.add_theme_font_size_override("font_size", 26)
|
|
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
vbox.add_child(lbl)
|
|
|
|
var vol_lbl := Label.new()
|
|
vol_lbl.name = "VolumeLabel"
|
|
vol_lbl.text = "Громкость: %d" % int(volume)
|
|
vol_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
vbox.add_child(vol_lbl)
|
|
|
|
var slider := HSlider.new()
|
|
slider.min_value = 0
|
|
slider.max_value = 100
|
|
slider.step = 1
|
|
slider.value = volume
|
|
slider.custom_minimum_size = Vector2(320, 32)
|
|
slider.connect("value_changed", func(v: float) -> void:
|
|
volume = v
|
|
vol_lbl.text = "Громкость: %d" % int(v)
|
|
_apply_volume(v)
|
|
)
|
|
vbox.add_child(slider)
|
|
|
|
vbox.add_child(_btn("Назад", func(): settings_panel.visible = false))
|
|
|
|
func _apply_volume(v: float) -> void:
|
|
var db := linear_to_db(v / 100.0) if v > 0.0 else -80.0
|
|
AudioServer.set_bus_volume_db(0, db)
|
|
|
|
func _build_difficulty_panel() -> void:
|
|
difficulty_panel = _make_opaque_panel()
|
|
difficulty_panel.visible = false
|
|
difficulty_panel.anchor_left = 0.5
|
|
difficulty_panel.anchor_right = 0.5
|
|
difficulty_panel.anchor_top = 0.5
|
|
difficulty_panel.anchor_bottom = 0.5
|
|
difficulty_panel.offset_left = -230
|
|
difficulty_panel.offset_right = 230
|
|
difficulty_panel.offset_top = -160
|
|
difficulty_panel.offset_bottom = 160
|
|
add_child(difficulty_panel)
|
|
|
|
var margin := MarginContainer.new()
|
|
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
margin.add_theme_constant_override("margin_left", 24)
|
|
margin.add_theme_constant_override("margin_right", 24)
|
|
margin.add_theme_constant_override("margin_top", 20)
|
|
margin.add_theme_constant_override("margin_bottom", 20)
|
|
difficulty_panel.add_child(margin)
|
|
|
|
var vbox := VBoxContainer.new()
|
|
vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
vbox.add_theme_constant_override("separation", 16)
|
|
margin.add_child(vbox)
|
|
|
|
var title := Label.new()
|
|
title.text = "Выберите сложность"
|
|
title.add_theme_font_size_override("font_size", 26)
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
vbox.add_child(title)
|
|
|
|
var immortal_btn := Button.new()
|
|
immortal_btn.text = "Бессмертный\nНет урона · тир пинков от мелких врагов"
|
|
immortal_btn.custom_minimum_size = Vector2(380, 72)
|
|
immortal_btn.add_theme_font_size_override("font_size", 18)
|
|
immortal_btn.connect("pressed", func() -> void:
|
|
GameSettings.difficulty = "immortal"
|
|
get_tree().change_scene_to_file("res://scenes/Main.tscn")
|
|
)
|
|
vbox.add_child(immortal_btn)
|
|
|
|
var survival_btn := Button.new()
|
|
survival_btn.text = "Выживание\nПолучаешь урон · фиксированная сила пинка"
|
|
survival_btn.custom_minimum_size = Vector2(380, 72)
|
|
survival_btn.add_theme_font_size_override("font_size", 18)
|
|
survival_btn.connect("pressed", func() -> void:
|
|
GameSettings.difficulty = "survival"
|
|
get_tree().change_scene_to_file("res://scenes/Main.tscn")
|
|
)
|
|
vbox.add_child(survival_btn)
|
|
|
|
vbox.add_child(_btn("Назад", func(): difficulty_panel.visible = false))
|
|
|
|
func _on_play() -> void:
|
|
difficulty_panel.visible = true
|
|
|
|
func _on_settings() -> void:
|
|
settings_panel.visible = true
|
|
|
|
func _on_exit() -> void:
|
|
get_tree().quit()
|