254 lines
8.6 KiB
GDScript
254 lines
8.6 KiB
GDScript
extends Node
|
|
## The title screen (ui-plan.md §A2): the logo over the same black-and-grid world as the table,
|
|
## with START (to the new-game screen), SETTINGS and QUIT, and slots for the deck builder (M6),
|
|
## multiplayer and accounts (M8). The game itself starts through SceneRouter.
|
|
|
|
## Slots for what later milestones add: shown, but not clickable yet.
|
|
const LATER := [["DECK BUILDER", "M6"], ["MULTIPLAYER", "M8"], ["ACCOUNT", "M8"]]
|
|
|
|
var settings: Dictionary
|
|
var _camera: Camera3D
|
|
var _floor: ShaderMaterial
|
|
var _cards: Array[Node3D] = []
|
|
var _title: Control
|
|
var _setup: Control
|
|
var _modal: Control
|
|
var _time := 0.0
|
|
|
|
|
|
func _ready() -> void:
|
|
settings = GameSettings.load_saved()
|
|
Motion.speed_scale = GameSettings.anim_scale(settings)
|
|
_build_world()
|
|
var layer := CanvasLayer.new()
|
|
add_child(layer)
|
|
var root := Control.new()
|
|
root.theme = Style.theme()
|
|
root.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
root.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
layer.add_child(root)
|
|
root.add_child(_vignette())
|
|
_title = _build_title()
|
|
root.add_child(_title)
|
|
_setup = _build_setup()
|
|
root.add_child(_setup)
|
|
root.add_child(_footer())
|
|
_modal = Control.new()
|
|
_modal.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
_modal.visible = false
|
|
root.add_child(_modal)
|
|
var routed := SceneRouter.take()
|
|
_show(_setup if routed.get("screen", "") == "setup" else _title, true)
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------
|
|
# The world behind the menu
|
|
|
|
func _build_world() -> void:
|
|
add_child(GameTable.make_environment())
|
|
var sun := DirectionalLight3D.new()
|
|
sun.light_color = Color(0.9, 0.95, 1.0)
|
|
sun.light_energy = 1.1
|
|
add_child(sun)
|
|
sun.look_at_from_position(Vector3(4, 12, 10), Vector3.ZERO, Vector3.UP)
|
|
var ground := GameTable.make_floor(900.0)
|
|
_floor = ground.material_override
|
|
_floor.set_shader_parameter("fade_from", 20.0)
|
|
_floor.set_shader_parameter("fade_to", 190.0)
|
|
_floor.set_shader_parameter("energy", 0.42)
|
|
_floor.set_shader_parameter("pitch", Vector2(2.96, 2.18))
|
|
add_child(ground)
|
|
_camera = Camera3D.new()
|
|
_camera.fov = 52.0
|
|
_camera.far = 400.0
|
|
add_child(_camera)
|
|
_camera.current = true
|
|
_camera.position = Vector3(0, 3.2, 14)
|
|
_camera.look_at(Vector3(0, 1.4, -30), Vector3.UP)
|
|
# A few cards adrift over the grid, to the right of the menu.
|
|
var scene: PackedScene = load("res://table/card_3d.tscn")
|
|
var faces := ["Code Zero", "Pingable Server", "Hotfix"]
|
|
var spots := [Vector3(3.3, 2.3, 5.2), Vector3(6.9, 3.1, 0.8), Vector3(11.0, 2.5, -4.6)]
|
|
for i in faces.size():
|
|
var c: Node3D = scene.instantiate()
|
|
c.card_name = faces[i]
|
|
add_child(c)
|
|
c.set_meta("base", spots[i])
|
|
c.set_meta("phase", i * 1.7)
|
|
c.scale = Vector3.ONE * 1.6
|
|
_cards.append(c)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
_time += delta
|
|
# Fly slowly over the grid: slide the grid toward the camera.
|
|
_floor.set_shader_parameter("origin", Vector2(0.0, fmod(_time * 1.4, 2.18)))
|
|
for c in _cards:
|
|
var base: Vector3 = c.get_meta("base")
|
|
var ph: float = c.get_meta("phase")
|
|
c.position = base + Vector3(0, sin(_time * 0.6 + ph) * 0.18, 0)
|
|
c.rotation = Vector3(PI / 2 - 0.35 + sin(_time * 0.3 + ph) * 0.08, -0.5 + sin(_time * 0.25 + ph) * 0.25, 0.12)
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------
|
|
# Screens
|
|
|
|
func _vignette() -> TextureRect:
|
|
var t := TextureRect.new()
|
|
t.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
t.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
var g := Gradient.new()
|
|
g.set_color(0, Color(Style.BG, 0.94))
|
|
g.set_color(1, Color(Style.BG, 0.0))
|
|
g.add_point(0.45, Color(Style.BG, 0.7))
|
|
var gt := GradientTexture2D.new()
|
|
gt.gradient = g
|
|
gt.fill_from = Vector2(0, 0)
|
|
gt.fill_to = Vector2(1, 0)
|
|
gt.width = 128
|
|
gt.height = 4
|
|
t.texture = gt
|
|
t.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
t.stretch_mode = TextureRect.STRETCH_SCALE
|
|
return t
|
|
|
|
|
|
func _build_title() -> Control:
|
|
var box := VBoxContainer.new()
|
|
box.anchor_top = 0.5
|
|
box.anchor_bottom = 0.5
|
|
box.offset_left = 110
|
|
box.offset_top = -270
|
|
box.add_theme_constant_override("separation", 12)
|
|
box.add_child(_logo())
|
|
var spacer := Control.new()
|
|
spacer.custom_minimum_size = Vector2(0, 26)
|
|
box.add_child(spacer)
|
|
box.add_child(_menu_button("START", func(): _show(_setup)))
|
|
for item in LATER:
|
|
var b := _menu_button("%s" % item[0], func(): pass)
|
|
b.disabled = true
|
|
b.tooltip_text = "Coming in %s." % item[1]
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 10)
|
|
row.add_child(b)
|
|
var tag := Widgets.label("// %s" % item[1], "Micro")
|
|
tag.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
row.add_child(tag)
|
|
box.add_child(row)
|
|
box.add_child(_menu_button("SETTINGS", _show_settings))
|
|
box.add_child(_menu_button("QUIT", func(): get_tree().quit()))
|
|
return box
|
|
|
|
|
|
func _logo() -> Control:
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 2)
|
|
var logo := RichTextLabel.new()
|
|
logo.bbcode_enabled = true
|
|
logo.fit_content = true
|
|
logo.scroll_active = false
|
|
logo.autowrap_mode = TextServer.AUTOWRAP_OFF
|
|
logo.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
logo.custom_minimum_size = Vector2(620, 0)
|
|
logo.add_theme_font_override("normal_font", Style.display_font(900))
|
|
logo.add_theme_font_size_override("normal_font_size", 76)
|
|
logo.add_theme_color_override("font_shadow_color", Color(Style.ACCENT, 0.55))
|
|
logo.add_theme_constant_override("shadow_outline_size", 18)
|
|
logo.add_theme_constant_override("shadow_offset_x", 0)
|
|
logo.add_theme_constant_override("shadow_offset_y", 0)
|
|
logo.text = "[color=%s]FILES[/color][color=%s]//[/color][color=%s]TCG[/color]" % [
|
|
Style.hex(Style.ACCENT), Style.hex(Style.ACCENT_DK), Style.hex(Style.SCREEN)]
|
|
v.add_child(logo)
|
|
var sub := Widgets.label("// A TRADING CARD GAME OF ANOMALIES, SERVERS AND FIREWALLS · SET 1", "Muted")
|
|
sub.add_theme_font_size_override("font_size", 13)
|
|
v.add_child(sub)
|
|
return v
|
|
|
|
|
|
func _menu_button(text: String, fn: Callable) -> Button:
|
|
var b := Widgets.button(text, fn, "BigButton")
|
|
b.custom_minimum_size = Vector2(340, 0)
|
|
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
return b
|
|
|
|
|
|
func _build_setup() -> Control:
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
var pc := PanelContainer.new()
|
|
pc.custom_minimum_size = Vector2(560, 0)
|
|
var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.9), 1.5, 16.0, 16.0)
|
|
box.ticks = true
|
|
box.set_content_margin_all(24)
|
|
pc.add_theme_stylebox_override("panel", box)
|
|
center.add_child(pc)
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 12)
|
|
pc.add_child(v)
|
|
v.add_child(Widgets.label("round@files:~$ ./new-game --vs bot", "Micro"))
|
|
v.add_child(Widgets.heading("NEW GAME"))
|
|
v.add_child(Widgets.muted("Both decks are dealt at random from Set 1, from the seed."))
|
|
Widgets.start_form(v, {"seed": randi_range(1, 999999)}, func(opts): SceneRouter.to_game(opts, settings),
|
|
func(): _show(_title))
|
|
return center
|
|
|
|
|
|
func _footer() -> Label:
|
|
var l := Widgets.label("round@files:~$ ./files-tcg · v0.1 · Godot %s" % Engine.get_version_info().string, "Micro")
|
|
l.anchor_top = 1.0
|
|
l.anchor_bottom = 1.0
|
|
l.offset_left = 24
|
|
l.offset_top = -30
|
|
return l
|
|
|
|
|
|
## Shows one screen, rushing it in.
|
|
func _show(screen: Control, instant := false) -> void:
|
|
for s in [_title, _setup]:
|
|
s.visible = s == screen
|
|
if instant or Motion.instant():
|
|
screen.modulate.a = 1.0
|
|
return
|
|
screen.modulate.a = 0.0
|
|
var tw := create_tween()
|
|
Motion.rush_in(tw, screen, "modulate:a", 1.0, 0.35)
|
|
|
|
|
|
func _show_settings() -> void:
|
|
for c in _modal.get_children():
|
|
c.queue_free()
|
|
var dim := ColorRect.new()
|
|
dim.color = Color(Style.BG, 0.6)
|
|
dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
_modal.add_child(dim)
|
|
_modal.add_child(Widgets.scanlines(0.1))
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
_modal.add_child(center)
|
|
var pc := PanelContainer.new()
|
|
pc.custom_minimum_size = Vector2(520, 0)
|
|
var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.93), 1.5, 16.0, 16.0)
|
|
box.ticks = true
|
|
box.set_content_margin_all(20)
|
|
pc.add_theme_stylebox_override("panel", box)
|
|
center.add_child(pc)
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 10)
|
|
pc.add_child(v)
|
|
v.add_child(Widgets.heading("SETTINGS"))
|
|
Widgets.settings_form(v, settings, func(out):
|
|
settings = out
|
|
GameSettings.save(out)
|
|
Motion.speed_scale = GameSettings.anim_scale(out)
|
|
_modal.visible = false)
|
|
_modal.visible = true
|
|
|
|
|
|
func _unhandled_input(e: InputEvent) -> void:
|
|
if e is InputEventKey and e.pressed and not e.echo and e.keycode == KEY_ESCAPE:
|
|
if _modal.visible:
|
|
_modal.visible = false
|
|
elif _setup.visible:
|
|
_show(_title)
|