2026-11-29 14:58:56 -06:00
class_name CardPalette
extends VBoxContainer
## The Cards tab of the left dock: every kind of card (CardCatalog) and your
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
## templates in a PaletteList. Click an item to add it in the middle of the
## view; drag it to place it on the spread.
2026-11-29 14:58:56 -06:00
## In Play the items are greyed under a notice with "Switch to Build"
## (BuildModeHint), so players learn where cards are added.
## Palette-only items that aren't card kinds.
const GROUP_ITEM : = { " label " : " Empty group " , " group " : CardCatalog . GROUP_OTHER ,
" tip " : " A new, empty group. Drag cards onto it. " , " words " : " group frame folder " }
const ALL_TEMPLATES : = { " label " : " All templates… " , " group " : CardCatalog . GROUP_TEMPLATES ,
" tip " : " Search, import, rename and delete templates " , " words " : " import manage " }
var m : Main
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
var list : PaletteList
2026-11-29 14:58:56 -06:00
var search : LineEdit
var notice : PanelContainer
var _templates : Array [ Dictionary ] = [ ]
2026-11-29 16:52:41 -06:00
var _sheets : Array [ Dictionary ] = [ ]
2026-11-29 14:58:56 -06:00
func setup ( p_main : Main ) - > void :
m = p_main
add_theme_constant_override ( " separation " , 8 )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
notice = BuildModeHint . make_notice ( m , func ( ) - > void : m . set_mode ( Main . Mode . BUILD ) )
2026-11-29 14:58:56 -06:00
add_child ( notice )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
list = PaletteList . new ( )
list . setup ( " Search cards and templates " , " Drag onto the spread, or click to add " , " Add a card " , " “dice”, “choice” or “if” " )
list . size_flags_vertical = SIZE_EXPAND_FILL
list . sections_for = _sections
list . can_use = func ( ) - > bool : return m . mode == Main . Mode . BUILD
list . on_blocked = BuildModeHint . explain . bind ( m )
list . drop_at = drop_at
list . after_use = func ( ) - > void :
if m . mobile :
m . mobile . show_list ( false )
add_child ( list )
search = list . search
list . rebuild ( )
2026-11-29 14:58:56 -06:00
func _process ( _delta : float ) - > void :
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
notice . visible = m . mode != Main . Mode . BUILD
2026-11-29 14:58:56 -06:00
## Reads the template list again (it lives in files, so not on every keystroke).
func refresh_templates ( ) - > void :
_templates = m . templating . templates ( ) . list ( ) if m . templating else [ ]
2026-11-29 16:52:41 -06:00
_sheets . clear ( )
if m . screens :
_sheets = m . screens . sheets . store . list ( )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
list . rebuild ( )
2026-11-29 14:58:56 -06:00
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
func _sections ( query : String ) - > Array :
var out : Array = [ ]
2026-11-29 14:58:56 -06:00
for group in CardCatalog . groups ( ) :
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
var entries : Array = [ ]
for item : Dictionary in CardCatalog . ITEMS :
if item [ " group " ] == group and PaletteList . matches ( item , query ) :
entries . append ( [ item , _add_card . bind ( item ) ] )
2026-11-29 16:52:41 -06:00
if group == CardCatalog . GROUP_SHEETS :
entries . append_array ( _sheet_entries ( query ) )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
out . append ( [ group , entries ] )
2026-11-29 14:58:56 -06:00
var templates : Array = [ ]
for row : Dictionary in _templates :
var item : = { " label " : row [ " name " ] , " group " : CardCatalog . GROUP_TEMPLATES , " tip " : row . get ( " description " , " " ) , " words " : " template " }
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
if PaletteList . matches ( item , query ) :
2026-11-29 14:58:56 -06:00
templates . append ( [ item , _add_template . bind ( str ( row [ " id " ] ) ) ] )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
if PaletteList . matches ( ALL_TEMPLATES , query ) :
2026-11-29 14:58:56 -06:00
templates . append ( [ ALL_TEMPLATES , func ( _at : Vector2 ) - > void : m . templating . open_template_picker ( ) ] )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
out . append ( [ CardCatalog . GROUP_TEMPLATES , templates ] )
out . append ( [ CardCatalog . GROUP_OTHER , [ [ GROUP_ITEM , _add_group_card ] ] if PaletteList . matches ( GROUP_ITEM , query ) else [ ] ] )
return out
2026-11-29 14:58:56 -06:00
2026-11-29 16:52:41 -06:00
## Your sheets, to place on the spread as Sheet cards.
func _sheet_entries ( query : String ) - > Array :
var out : Array = [ ]
for row : Dictionary in _sheets :
var item : = { " label " : row [ " name " ] , " group " : CardCatalog . GROUP_SHEETS , " tip " : " Place this sheet on the spread; tables can then use its boxes " , " words " : " sheet character " }
if PaletteList . matches ( item , query ) :
out . append ( [ item , func ( at : Vector2 ) - > void : m . sheet_links . add_card ( str ( row [ " id " ] ) , at ) ] )
return out
2026-11-29 14:58:56 -06:00
## Adds through `on_add` with its top-left corner under a screen point on the spread.
func drop_at ( on_add : Callable , screen_point : Vector2 ) - > bool :
var board : = m . board
if not board . is_visible_in_tree ( ) or not board . get_global_rect ( ) . has_point ( screen_point ) :
return false
var world : = board . screen_to_world ( screen_point - board . global_position )
Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00
list . use ( on_add , ( world - Vector2 ( 128 , 20 ) ) . round ( ) )
2026-11-29 14:58:56 -06:00
return true
func _add_card ( at : Vector2 , item : Dictionary ) - > void :
m . editing . add_table ( str ( item [ " kind " ] ) , str ( item [ " sub " ] ) , at , str ( item [ " variant " ] ) )
func _add_template ( at : Vector2 , id : String ) - > void :
var tpl : = m . templating . templates ( ) . get_template ( id )
if tpl . is_empty ( ) :
m . toast ( " Couldn ' t read that template " )
return
m . templating . begin_template_insert ( tpl , at )
func _add_group_card ( at : Vector2 ) - > void :
m . list_view . new_group ( at )