updates
This commit is contained in:
parent
0cba7f5ee0
commit
32ed347b58
172 changed files with 5464 additions and 582 deletions
165
scenes/game.gd
165
scenes/game.gd
|
|
@ -11,7 +11,8 @@ var pool: Dictionary
|
|||
var match_: LocalMatch
|
||||
var table: GameTable
|
||||
var hud: Hud
|
||||
var settings := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45}
|
||||
var presenter: Presenter
|
||||
var settings := GameSettings.DEFAULTS.duplicate()
|
||||
|
||||
## The picked source key, or "".
|
||||
var selected := ""
|
||||
|
|
@ -22,9 +23,10 @@ var _bot_thought := {}
|
|||
var _bot_wait := 0.0
|
||||
var _paused := false
|
||||
var _hover_seen := {}
|
||||
var _combat_seen := 0
|
||||
## Log lines already turned into table pop-ups.
|
||||
var _log_seen := 0
|
||||
## What the mouse is over in the hand-focus row, which wins over the table's hover while open.
|
||||
var _hand_hover := {}
|
||||
## Engine events already acted out by the presenter.
|
||||
var _events_seen := 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -33,6 +35,10 @@ func _ready() -> void:
|
|||
add_child(table)
|
||||
hud = Hud.new()
|
||||
add_child(hud)
|
||||
presenter = Presenter.new()
|
||||
presenter.table = table
|
||||
presenter.hud = hud
|
||||
add_child(presenter)
|
||||
hud.set_settings(settings)
|
||||
hud.move_chosen.connect(_play)
|
||||
hud.source_picked.connect(func(key): _select(key))
|
||||
|
|
@ -41,14 +47,29 @@ func _ready() -> void:
|
|||
hud.view_toggled.connect(func(): table.toggle_view())
|
||||
hud.new_game_requested.connect(start_game)
|
||||
hud.settings_changed.connect(_on_settings)
|
||||
hud.menu_requested.connect(_to_menu)
|
||||
hud.hand_hovered.connect(func(info): _hand_hover = info)
|
||||
hud.hand_picked.connect(_pick)
|
||||
hud.hand_focus_changed.connect(func(open):
|
||||
if not open:
|
||||
_hand_hover = {}
|
||||
table.set_hand_tucked(open))
|
||||
# From the menu, the router brings the game and saved settings. Opened directly (the editor,
|
||||
# tests), it deals a game from --seed or a random seed with the default settings.
|
||||
var routed := SceneRouter.take()
|
||||
if routed.has("settings"):
|
||||
settings = routed.settings.duplicate()
|
||||
hud.set_settings(settings)
|
||||
Motion.speed_scale = GameSettings.anim_scale(settings)
|
||||
if routed.has("game"):
|
||||
start_game(routed.game)
|
||||
return
|
||||
var args := OS.get_cmdline_user_args()
|
||||
var seed := randi_range(1, 999999)
|
||||
var i := args.find("--seed")
|
||||
if i >= 0 and i + 1 < args.size():
|
||||
seed = int(args[i + 1])
|
||||
start_game({"seed": seed, "human": 0, "style": "greedy"})
|
||||
if args.find("--seed") < 0:
|
||||
hud.show_start({"seed": seed, "cancel": true})
|
||||
|
||||
|
||||
## Starts a game from {seed, human, style}.
|
||||
|
|
@ -65,9 +86,10 @@ func start_game(opts: Dictionary) -> void:
|
|||
match_.changed.connect(_on_changed)
|
||||
selected = ""
|
||||
_moves_version = -1
|
||||
_combat_seen = 0
|
||||
_bot_wait = 0.0
|
||||
_log_seen = match_.log_lines().size()
|
||||
# From 0, so the opening deal plays out.
|
||||
_events_seen = 0
|
||||
presenter.skip()
|
||||
hud.reset_for_new_game()
|
||||
table.set_seat(match_.human, true)
|
||||
_on_changed()
|
||||
|
|
@ -75,10 +97,17 @@ func start_game(opts: Dictionary) -> void:
|
|||
|
||||
func _on_settings(s: Dictionary) -> void:
|
||||
settings = s
|
||||
Motion.speed_scale = GameSettings.anim_scale(s)
|
||||
GameSettings.save(s)
|
||||
if match_ != null and _bot_task < 0:
|
||||
match_.set_options({"stops": s.stops, "autoSkip": s.autoSkip, "checkInvariants": s.checkInvariants})
|
||||
|
||||
|
||||
func _to_menu(screen: String) -> void:
|
||||
_join_bot()
|
||||
SceneRouter.to_menu(screen)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
# The bot
|
||||
|
||||
|
|
@ -91,13 +120,14 @@ func _process(delta: float) -> void:
|
|||
_bot_task = -1
|
||||
_bot_wait = 0.0
|
||||
match_.bot_apply(_bot_thought)
|
||||
elif not _paused and not match_.is_over() and match_.bot_to_act() and not hud.modal_open():
|
||||
elif not _paused and not match_.is_over() and match_.bot_to_act() and not hud.modal_open() and not presenter.busy():
|
||||
_bot_wait += delta
|
||||
if _bot_wait >= settings.botDelay:
|
||||
var m := match_
|
||||
_bot_task = WorkerThreadPool.add_task(func(): _bot_thought = m.bot_think(), false, "bot")
|
||||
if table.hovered != _hover_seen:
|
||||
_hover_seen = table.hovered.duplicate()
|
||||
var hover: Dictionary = _hand_hover if hud.hand_focus_open() else table.hovered
|
||||
if hover != _hover_seen:
|
||||
_hover_seen = hover.duplicate()
|
||||
_inspect(_hover_seen)
|
||||
_refresh()
|
||||
|
||||
|
|
@ -124,57 +154,14 @@ func _on_changed() -> void:
|
|||
if selected != "" and not moves.any(func(mv): return mv.source == selected):
|
||||
selected = ""
|
||||
hud.hide_popover()
|
||||
var c = match_.combat()
|
||||
if c != null and c.id != _combat_seen:
|
||||
_combat_seen = c.id
|
||||
hud.show_combat_tab()
|
||||
# The show for this change: the presenter plans it before the table syncs, then cues what
|
||||
# needs the new positions.
|
||||
# A new game starts from nothing, not from the last game's table.
|
||||
var before := table.shown_view() if _events_seen > 0 else {}
|
||||
presenter.stage(match_.events_since(_events_seen), before, match_.view(), match_.human)
|
||||
_events_seen = match_.event_count()
|
||||
_refresh()
|
||||
_pop_new_lines()
|
||||
|
||||
|
||||
## Shows what the newest log lines did on the table: damage, roll results, captures. Several from
|
||||
## one move come one after another; after a long run of moves at once, only the last few show.
|
||||
func _pop_new_lines() -> void:
|
||||
var lines := match_.log_lines()
|
||||
var pops := []
|
||||
for i in range(_log_seen, lines.size()):
|
||||
var l: Dictionary = lines[i]
|
||||
var loc = l.get("loc")
|
||||
if loc == null or not BoardLayout.at.has(loc):
|
||||
continue
|
||||
var at: Vector3 = BoardLayout.at[loc]
|
||||
var p = l.get("player")
|
||||
var color: Color = GameTable.OWNER_COLORS[p].lightened(0.3) if p != null else Color("#d7dee6")
|
||||
if l.get("ref") != null and l.get("amount") != null:
|
||||
pops.append(func(delay): table.pop_damage(l.ref, l.amount, l.text.contains("destroyed"), loc, delay))
|
||||
elif l.get("tag") == "capture" and l.text.contains(" captures "):
|
||||
pops.append(func(delay):
|
||||
table.flash_capture(loc, p)
|
||||
table.pop_text(at, "%s takes %s" % [State.player_name(p), loc], color, delay))
|
||||
elif l.get("tag") == "combat" and l.text.contains(" wins the roll"):
|
||||
var t := _roll_score(l.text)
|
||||
pops.append(func(delay): table.pop_text(at, "%s wins %s" % [State.player_name(p), t], color, delay))
|
||||
elif l.get("tag") == "combat" and l.text.begins_with("Tie,"):
|
||||
pops.append(func(delay): table.pop_text(at, "Stalemate", color, delay))
|
||||
elif l.get("tag") == "combat" and l.text.contains(" ends: "):
|
||||
pops.append(func(delay): table.pop_text(at, "Combat ends", Color("#ffb454"), delay))
|
||||
_log_seen = lines.size()
|
||||
pops = pops.slice(maxi(0, pops.size() - 5))
|
||||
for i in pops.size():
|
||||
pops[i].call(i * 0.45)
|
||||
|
||||
|
||||
static var _roll_re := RegEx.create_from_string("wins the roll, (\\d+) to (\\d+)")
|
||||
|
||||
|
||||
## "14–7" from "North wins the roll, 7 to 14: 7 damage.", the winner's total first.
|
||||
static func _roll_score(text: String) -> String:
|
||||
var m := _roll_re.search(text)
|
||||
if m == null:
|
||||
return ""
|
||||
var a := int(m.get_string(1))
|
||||
var b := int(m.get_string(2))
|
||||
return "%d–%d" % [maxi(a, b), mini(a, b)]
|
||||
presenter.run()
|
||||
|
||||
|
||||
func _refresh() -> void:
|
||||
|
|
@ -182,7 +169,7 @@ func _refresh() -> void:
|
|||
var marks := _marks(v)
|
||||
table.sync(v, marks)
|
||||
hud.refresh({"match": match_, "view": v, "moves": moves, "selected": selected, "marks": marks,
|
||||
"thinking": _thinking(), "paused": _paused, "preview": _preview(v)})
|
||||
"thinking": _thinking(), "paused": _paused, "preview": _preview(v), "show_left": presenter.time_left()})
|
||||
|
||||
|
||||
## How each key glows: the combat, your sources, and the selected source's targets.
|
||||
|
|
@ -204,6 +191,11 @@ func _marks(v: Dictionary) -> Dictionary:
|
|||
for mv in moves:
|
||||
if mv.source == selected and mv.target != "none":
|
||||
marks[mv.target] = "attack" if mv.action.type == "attack" else "target"
|
||||
# Its defenders glow too: clicking one attacks where it stands (see _hits_on).
|
||||
if mv.action.type == "attack":
|
||||
for r in State.anomalies_at(v, mv.action.to):
|
||||
if not marks.has(Moves.anomaly_key(r)):
|
||||
marks[Moves.anomaly_key(r)] = "attack"
|
||||
return marks
|
||||
|
||||
|
||||
|
|
@ -211,8 +203,8 @@ func _marks(v: Dictionary) -> Dictionary:
|
|||
func _preview(v: Dictionary) -> String:
|
||||
if selected == "" or _thinking() or _hover_seen.is_empty():
|
||||
return ""
|
||||
for mv in moves:
|
||||
if mv.source == selected and mv.target == _hover_seen.key and mv.action.type == "attack":
|
||||
for mv in _hits_on(_hover_seen.key):
|
||||
if mv.action.type == "attack":
|
||||
var me := match_.human
|
||||
var from = State.anomaly(v, State.ref(me, mv.action.slot)).at
|
||||
var to: String = mv.action.to
|
||||
|
|
@ -260,14 +252,15 @@ func _inspect(h: Dictionary) -> void:
|
|||
var pl: Dictionary = v.players[int(parts[1])]
|
||||
text = "[b]%s's %s[/b]\n%d cards in hand, %d in the deck, %d Servers in the pile, %d in the discard pile." % [
|
||||
State.player_name(int(parts[1])), parts[2], pl.hand.size(), pl.deck.size(), pl.serverPile.size(), pl.discard.size()]
|
||||
hud.inspect({"art": card, "text": text})
|
||||
hud.inspect({"art": card, "text": text, "key": key})
|
||||
|
||||
|
||||
static func _card_info(v: Dictionary, card: String) -> String:
|
||||
var d: Dictionary = v.defs.get(card, {})
|
||||
if d.is_empty():
|
||||
return "[b]%s[/b]" % card
|
||||
var out := "[b]%s[/b]\n[color=#7d8a97]%s%s · %d Gb[/color]" % [d.name, d.kind.capitalize(), " (%s)" % d.type if d.type != "" else "", d.bandwidth]
|
||||
var type := " · %s" % Style.CLASS_NAMES.get(d.type, d.type) if d.type != "" else ""
|
||||
var out := "[b]%s[/b]\n[color=%s]%s%s · %d Gb[/color]" % [d.name, Style.hex(Style.card_accent(d)), d.kind.capitalize(), type, d.bandwidth]
|
||||
if d.kind == "anomaly":
|
||||
out += "\n%d Cores · %d Health · %d Expansion Slots" % [d.cores, d.health, d.slots]
|
||||
if d.text != "":
|
||||
|
|
@ -342,7 +335,7 @@ func _pick(key: String, at: Vector2) -> void:
|
|||
if match_.human_to_act() and v.choice != null:
|
||||
return
|
||||
if selected != "":
|
||||
var hits := moves.filter(func(mv): return mv.source == selected and mv.target == key)
|
||||
var hits := _hits_on(key)
|
||||
if hits.size() == 1:
|
||||
_play(hits[0])
|
||||
return
|
||||
|
|
@ -355,11 +348,35 @@ func _pick(key: String, at: Vector2) -> void:
|
|||
_select(key)
|
||||
|
||||
|
||||
## The selected source's moves onto `key`. An Anomaly on the board that isn't one of your sources
|
||||
## also stands for its location: its card covers most of the tile, so clicking the defender you
|
||||
## want to attack attacks its location.
|
||||
func _hits_on(key: String) -> Array:
|
||||
var hits := moves.filter(func(mv): return mv.source == selected and mv.target == key)
|
||||
if not hits.is_empty() or moves.any(func(mv): return mv.source == key):
|
||||
return hits
|
||||
var r = Moves.ref_of_key(key)
|
||||
var v := match_.view()
|
||||
if r == null or r.slot > v.players[r.player].anomalies.size():
|
||||
return hits
|
||||
var at = State.anomaly(v, r).at
|
||||
if at == null:
|
||||
return hits
|
||||
return moves.filter(func(mv): return mv.source == selected and mv.target == Moves.loc_key(at))
|
||||
|
||||
|
||||
func _unhandled_input(e: InputEvent) -> void:
|
||||
if match_ == null:
|
||||
return
|
||||
if e is InputEventMouseButton and e.pressed:
|
||||
if e.button_index == MOUSE_BUTTON_LEFT:
|
||||
# A click while the game acts itself out skips to the end of the show. On your
|
||||
# decision it still picks what's under the mouse: the show is of moves already made,
|
||||
# and a click on your attacker or its target shouldn't be lost to it.
|
||||
if presenter.busy():
|
||||
presenter.skip()
|
||||
if not match_.human_to_act():
|
||||
return
|
||||
_pick(table.hovered.get("key", "none"), e.position)
|
||||
elif e.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_cancel()
|
||||
|
|
@ -377,10 +394,22 @@ func _unhandled_input(e: InputEvent) -> void:
|
|||
return
|
||||
match e.keycode:
|
||||
KEY_ESCAPE:
|
||||
if hud.modal_open() and match_.view().choice == null and not match_.is_over():
|
||||
if hud.hand_focus_open():
|
||||
hud.set_hand_focus(false)
|
||||
elif hud.drawer_open() and not hud.modal_open():
|
||||
hud.set_drawer(false)
|
||||
elif hud.modal_open() and match_.view().choice == null and not match_.is_over():
|
||||
hud.close_modal()
|
||||
_cancel()
|
||||
KEY_TAB:
|
||||
if not hud.modal_open():
|
||||
hud.toggle_hand_focus()
|
||||
KEY_QUOTELEFT:
|
||||
hud.toggle_drawer()
|
||||
KEY_SPACE:
|
||||
if presenter.busy():
|
||||
presenter.skip()
|
||||
return
|
||||
var v := match_.view()
|
||||
if v.choice == null and not hud.modal_open():
|
||||
for t in ["pass", "end"]:
|
||||
|
|
|
|||
254
scenes/menu.gd
Normal file
254
scenes/menu.gd
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
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)
|
||||
1
scenes/menu.gd.uid
Normal file
1
scenes/menu.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://blhshidutfacv
|
||||
6
scenes/menu.tscn
Normal file
6
scenes/menu.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/menu.gd" id="1_menu"]
|
||||
|
||||
[node name="Menu" type="Node"]
|
||||
script = ExtResource("1_menu")
|
||||
33
scenes/scene_router.gd
Normal file
33
scenes/scene_router.gd
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
class_name SceneRouter
|
||||
## Moves between the menu and a game (the project's only scene changes), carrying what the next
|
||||
## scene needs in `args`.
|
||||
|
||||
const MENU := "res://scenes/menu.tscn"
|
||||
const GAME := "res://scenes/game.tscn"
|
||||
|
||||
## What the scene being entered should start with, e.g. {game: {seed, human, style}, settings}.
|
||||
## The scene takes it with take().
|
||||
static var args := {}
|
||||
|
||||
|
||||
## Opens a game with `opts` ({seed, human, style}) and `settings`.
|
||||
static func to_game(opts: Dictionary, settings: Dictionary) -> void:
|
||||
args = {"game": opts, "settings": settings}
|
||||
_tree().change_scene_to_file.call_deferred(GAME)
|
||||
|
||||
|
||||
## Back to the menu; `screen` is "" for the title or "setup" for the new-game screen.
|
||||
static func to_menu(screen := "") -> void:
|
||||
args = {"screen": screen}
|
||||
_tree().change_scene_to_file.call_deferred(MENU)
|
||||
|
||||
|
||||
## The args left for this scene, cleared so a reload doesn't reuse them.
|
||||
static func take() -> Dictionary:
|
||||
var out := args
|
||||
args = {}
|
||||
return out
|
||||
|
||||
|
||||
static func _tree() -> SceneTree:
|
||||
return Engine.get_main_loop() as SceneTree
|
||||
1
scenes/scene_router.gd.uid
Normal file
1
scenes/scene_router.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cyrdo7nvlfwrg
|
||||
Loading…
Add table
Add a link
Reference in a new issue