import { UiSounds, UiCue } from "audio.slint";
import { ListView } from "std-widgets.slint";
import { ExploreRow } from "rich-model.slint";
import { Nine, Label, Theme } from "base.slint";
import { Pieces } from "pieces.slint";
import { Icons } from "icons.slint";
import { Checkbox } from "checkbox.slint";
import { ModAction } from "mod-action.slint";
import { ExploreResultRow } from "explore-row.slint";
import { Scrollbar } from "scrollbar.slint";
import { GameTooltip } from "tooltip.slint";
component RichCard {
in property <ExploreRow> item;
in property <bool> checks;
in property <bool> busy;
in property <bool> tall-thumbnail;
callback selected(); callback toggled(); callback activate(bool); callback cancel();
property <bool> lit: root.item.selected || touch.has-hover || touch.pressed;
Nine { width: root.width; height: root.height; source: root.item.selected ? (touch.pressed ? Pieces.mods-explore-results-table-selected-clicked-base : touch.has-hover ? Pieces.mods-explore-results-table-selected-hovered-base : Pieces.mods-explore-results-table-selected-base) : touch.pressed ? Pieces.mods-explore-results-table-clicked-base : touch.has-hover ? Pieces.mods-explore-results-table-hovered-base : root.item.warning ? Pieces.negative-message-frame-default-base : Pieces.mods-explore-results-table-default-base; }
if root.item.pending: Rectangle { x: 0px; y: 1px; width: 3px; height: root.height - 2px; background: Theme.pending-accent; }
property <length> image-x: root.checks ? 30px : 10px;
property <length> action-y: root.height - 33px;
property <length> image-size: root.tall-thumbnail ? max(0px, root.action-y - 16px) : 64px;
Rectangle { x: root.image-x; y: 12px; width: root.image-size; height: root.image-size; background: Theme.pane-bg; }
Nine { x: root.image-x - 4px; y: 8px; width: root.image-size + 8px; height: root.image-size + 8px; source: Pieces.mod-explore-thumbnail-image-default-shadow; }
Image { x: root.image-x; y: 12px; width: root.image-size; height: root.image-size; source: root.item.missing ? Icons.missing-thumbnail : root.item.thumbnail; image-fit: contain; horizontal-alignment: center; vertical-alignment: center; }
property <length> text-x: root.image-x + root.image-size + 12px;
property <length> text-width: max(0px, root.width - root.text-x - 12px);
Label { x: root.text-x; y: 8px; width: root.text-width; height: 20px; text: root.item.title; font-weight: 700; color: root.lit ? Theme.black : root.item.pending ? Theme.pending : root.item.dimmed ? Theme.disabled-text : Theme.caption; opacity: root.item.pending && root.item.dimmed && !root.lit ? Theme.disabled-row-opacity : 1; overflow: elide; }
Label { x: root.text-x; y: 29px; width: root.text-width; height: 18px; text: root.item.owner; color: root.lit ? Theme.black : root.item.placeholder ? Theme.disabled-text : Theme.text; overflow: elide; }
Label { x: root.text-x; y: 49px; width: root.text-width; height: 18px; text: root.item.version + (root.item.downloads-count == "" ? "" : " ยท " + root.item.downloads-count + " downloads"); color: root.lit ? Theme.black : root.item.pending ? Theme.pending : root.item.dimmed ? Theme.disabled-text : Theme.text; opacity: root.item.pending && root.item.dimmed && !root.lit ? Theme.disabled-row-opacity : 1; overflow: elide; }
Label { x: root.text-x; y: 70px; width: root.text-width; height: 40px; text: root.item.summary; wrap: word-wrap; overflow: clip; line-height-factor: 20 / 21.294; color: root.lit ? Theme.black : Theme.disabled-text; }
if !root.item.downloading: Label { x: root.text-x; y: 115px; width: max(0px, root.text-width - 44px); height: 20px; text: root.item.warning ? "Missing dependencies" : root.item.update-badge; color: root.lit ? Theme.black : root.item.warning ? #ff8e8e : root.item.pending ? Theme.pending : Theme.orange; opacity: root.item.pending && root.item.dimmed && !root.item.warning && !root.lit ? Theme.disabled-row-opacity : 1; overflow: elide; }
touch := TouchArea { pointer-event(e) => { if (e.kind == PointerEventKind.down && e.button == PointerEventButton.left) { UiSounds.begin(); root.selected(); UiSounds.finish(UiCue.selection); } } }
if root.checks && !root.item.placeholder: Checkbox { x: 7px; y: 14px; width: 17px; height: 17px; checked: root.item.checked; enabled: !root.busy && !root.item.locked; toggled => { root.toggled(); } }
ModAction { x: root.text-x; y: root.action-y; width: root.text-width; height: 28px; action: root.item.action; busy: root.busy;
compact: true; downloading: root.item.downloading; fraction: root.item.fraction; version: root.item.version; progress-label: root.item.progress-label; failed: root.item.failed;
activate(remove) => { root.activate(remove); } cancel => { root.cancel(); }
}
}
// Only visible fixed-height bands are instantiated; a band contains at most `columns` cards.
export component RichList inherits Rectangle {
in property <[ExploreRow]> rows;
in property <bool> grid;
in property <bool> checks;
in property <bool> busy;
in property <bool> tall-thumbnails;
in property <int> reset-tick;
callback selected(string); callback toggled(string); callback activate(string, bool); callback cancel(string);
callback viewport(int, int);
property <int> columns: root.grid ? max(1, floor((root.width - 12px) / 304px)) : 1;
property <length> pitch: root.grid ? 152px : 64px;
property <int> bands: ceil(root.rows.length / root.columns);
property <length> content: root.bands * root.pitch;
in-out property <length> list-y;
property <string> tip;
property <length> tip-y;
changed reset-tick => { root.list-y = 0px; }
changed columns => { root.list-y = 0px; root.report(); }
changed height => { root.report(); }
changed list-y => { root.report(); }
init => { root.report(); }
function report() { root.viewport(max(0, floor(-root.list-y / root.pitch)) * root.columns, (ceil(root.height / root.pitch) + 1) * root.columns); }
clip: true;
list := ListView {
width: root.width - 12px; height: root.height; content-y <=> root.list-y;
mouse-drag-pan-enabled: false;
horizontal-scrollbar-policy: always-off; vertical-scrollbar-policy: always-off;
for band in root.bands: Rectangle {
width: list.visible-width; height: root.pitch;
for col in root.columns: cell := Rectangle {
property <int> index: band * root.columns + col;
property <ExploreRow> item: root.rows[self.index];
x: col * (list.visible-width / root.columns); width: list.visible-width / root.columns; height: root.pitch;
if self.index < root.rows.length && root.grid: RichCard {
width: parent.width - 6px; height: 146px; item: cell.item; checks: root.checks; busy: root.busy; tall-thumbnail: root.tall-thumbnails;
selected => { root.selected(cell.item.name); } toggled => { root.toggled(cell.item.name); }
activate(remove) => { root.activate(cell.item.name, remove); } cancel => { root.cancel(cell.item.name); }
}
if self.index < root.rows.length && !root.grid: Rectangle {
width: parent.width; height: 64px;
ExploreResultRow {
x: root.checks ? 28px : 0px; width: parent.width - self.x; height: 64px;
title: cell.item.title; owner: cell.item.owner; summary: cell.item.summary;
downloads: cell.item.downloads-count; version: cell.item.version; installed: cell.item.installed;
thumbnail: cell.item.thumbnail; missing: cell.item.missing; selected: cell.item.selected;
update-badge: cell.item.warning ? "Missing dependencies" : cell.item.update-badge;
warning: cell.item.warning; action: cell.item.action; busy: root.busy; downloading: cell.item.downloading; fraction: cell.item.fraction; progress-label: cell.item.progress-label; failed: cell.item.failed; dimmed: cell.item.dimmed; pending: cell.item.pending;
clicked => { root.selected(cell.item.name); }
activate(remove) => { root.activate(cell.item.name, remove); } cancel => { root.cancel(cell.item.name); }
action-tooltip(text) => { root.tip = text; root.tip-y = band * root.pitch + root.list-y + 32px; }
}
if cell.item.pending: Rectangle { x: 0px; y: 1px; width: 3px; height: parent.height - 2px; background: Theme.pending-accent; }
if root.checks && !cell.item.placeholder: Checkbox { x: 7px; y: 24px; width: 17px; height: 17px; checked: cell.item.checked; enabled: !root.busy && !cell.item.locked; toggled => { root.toggled(cell.item.name); } }
}
}
}
}
if root.content > root.height: Scrollbar {
x: root.width - 12px; width: 12px; height: root.height;
thumb-height: min(self.height, max(24px, self.height * self.height / max(1px, root.content)));
thumb-position: -root.list-y / max(1px, root.content - root.height) * (self.height - self.thumb-height);
scroll(delta) => { root.list-y = clamp(root.list-y + delta, -max(0px, root.content - root.height), 0px); }
moved(y) => { root.list-y = -clamp((y - self.thumb-height / 2) / max(1px, self.height - self.thumb-height), 0, 1) * max(0px, root.content - root.height); }
}
if root.tip != "": GameTooltip { x: max(0px, root.width - self.width - 12px); y: clamp(root.tip-y, 0px, root.height - self.height); text: root.tip; }
}