40 lines
1.9 KiB
GDScript3
40 lines
1.9 KiB
GDScript3
|
|
class_name LoreEntryActions
|
||
|
|
extends RefCounted
|
||
|
|
## The buttons under a Lore Entry in the page editor: copy it to the other
|
||
|
|
## Lore Index level (This spread ↔ My library), and its item sheet: "Make a
|
||
|
|
## sheet for this entry" (SheetItems.make_sheet) or "Open its sheet".
|
||
|
|
|
||
|
|
|
||
|
|
static func make(lore: LoreList, page: BookPage) -> Control:
|
||
|
|
var row := HFlowContainer.new()
|
||
|
|
row.add_theme_constant_override("h_separation", 6)
|
||
|
|
row.add_theme_constant_override("v_separation", 6)
|
||
|
|
var other_key := LoreLevel.LIBRARY if lore.level.key == LoreLevel.SPREAD else LoreLevel.SPREAD
|
||
|
|
var other: LoreLevel = lore.levels[other_key]
|
||
|
|
var copy := Style.bar_button("Copy to %s" % other.title())
|
||
|
|
copy.name = "CopyToLevel"
|
||
|
|
copy.tooltip_text = "My library is shared by every spread and sheet" if other_key == LoreLevel.LIBRARY else "Add a copy to this spread's Lore Index"
|
||
|
|
copy.pressed.connect(func() -> void: copy_to(lore, page, other))
|
||
|
|
row.add_child(copy)
|
||
|
|
var sheet := Style.bar_button("Open its sheet" if page.sheet != "" else "Make a sheet for this entry")
|
||
|
|
sheet.name = "ItemSheet"
|
||
|
|
sheet.tooltip_text = "Its item sheet, e.g. Damage, Charges and Notes. Drag the entry into a character's inventory to take it along."
|
||
|
|
sheet.pressed.connect(func() -> void: open_or_make_sheet(lore, page))
|
||
|
|
row.add_child(sheet)
|
||
|
|
return row
|
||
|
|
|
||
|
|
|
||
|
|
static func copy_to(lore: LoreList, page: BookPage, other: LoreLevel) -> BookPage:
|
||
|
|
var added := other.add_copy(page)
|
||
|
|
lore.m.toast("Copied “%s” to %s" % [page.label(), other.title()])
|
||
|
|
return added
|
||
|
|
|
||
|
|
|
||
|
|
## Opens the entry's item sheet, making one first when it has none.
|
||
|
|
static func open_or_make_sheet(lore: LoreList, page: BookPage) -> void:
|
||
|
|
if page.sheet == "" or lore.m.screens.sheets.store.load_sheet(page.sheet) == null:
|
||
|
|
lore.level.edit(func() -> void: SheetItems.make_sheet(lore.m.screens.sheets.store, page))
|
||
|
|
lore.refresh()
|
||
|
|
if lore.open_sheet.is_valid():
|
||
|
|
lore.open_sheet.call(page.sheet)
|