import { UiSounds, UiCue } from "audio.slint";
import { Nine, Label, Theme } from "base.slint";
import { Pieces } from "pieces.slint";
import { Icons } from "icons.slint";
import { Button } from "button.slint";
import { ModAction } from "mod-action.slint";
// One Explore result: the game's `mods_explore_results_table` cell (same states as the Manage table) with the
// `mod_explore_thumbnail_image` shadow ring around a 48 px thumbnail, title / owner / summary lines and a
// right-hand stats column.
export component ExploreResultRow {
in property <bool> warning;
in property <int> action;
in property <bool> busy;
in property <bool> downloading;
in property <bool> failed;
in property <bool> dimmed;
in property <bool> pending;
in property <float> fraction;
in property <string> progress-label;
callback activate(bool);
callback cancel();
callback action-tooltip(string);
in property <string> title;
in property <string> owner;
in property <string> summary;
in property <string> downloads;
in property <string> version;
in property <bool> installed;
in property <bool> selected;
in property <image> thumbnail;
in property <bool> missing: true;
in property <string> update-badge;
in property <string> state: "auto";
callback clicked();
preferred-height: 64px;
property <string> visual: root.state != "auto" ? root.state : touch.pressed ? "clicked" : touch.has-hover ? "hovered" : "default";
property <bool> lit: root.selected || root.visual == "hovered" || root.visual == "clicked";
property <bool> stats-visible: root.width >= 272px;
property <length> stats-width: root.stats-visible ? 190px : 0px;
pure function compact(s: string) -> string {
if (!s.is-float()) { return s; }
if (s.to-float() >= 1000000) { return round(s.to-float() / 100000) / 10 + "M"; }
if (s.to-float() >= 1000) { return round(s.to-float() / 100) / 10 + "k"; }
return s;
}
pure function face(sel: bool, v: string) -> image {
if (v == "clicked") { return sel ? Pieces.mods-explore-results-table-selected-clicked-base : Pieces.mods-explore-results-table-clicked-base; }
if (sel) { return v == "hovered" ? Pieces.mods-explore-results-table-selected-hovered-base : Pieces.mods-explore-results-table-selected-base; }
return v == "hovered" ? Pieces.mods-explore-results-table-hovered-base : Pieces.mods-explore-results-table-default-base;
}
Nine { width: root.width; height: root.height; source: root.warning && !root.lit ? Pieces.negative-message-frame-default-base : root.face(root.selected, root.visual); }
Rectangle { x: 8px; y: 8px; width: 48px; height: 48px; background: Theme.pane-bg; }
Nine { x: 4px; y: 4px; width: 56px; height: 56px; source: Pieces.mod-explore-thumbnail-image-default-shadow; }
Image { x: 8px; y: 8px; width: 48px; height: 48px; source: root.missing ? Icons.missing-thumbnail : root.thumbnail; image-fit: contain; }
Label { x: 68px; y: 6px; width: max(0px, root.width - 68px - root.stats-width); height: 18px; text: root.title; font-weight: 700; color: root.lit ? Theme.black : root.pending ? Theme.pending : root.dimmed ? Theme.disabled-text : Theme.caption; opacity: root.pending && root.dimmed && !root.lit ? Theme.disabled-row-opacity : 1; overflow: elide; }
Label { x: 68px; y: 24px; width: max(0px, root.width - 68px - root.stats-width); height: 18px; text: root.owner; color: root.lit ? Theme.black : Theme.text; overflow: elide; }
Label { x: 68px; y: 42px; width: max(0px, root.width - 84px); height: 18px; text: root.summary; color: root.lit ? Theme.black : Theme.disabled-text; overflow: elide; }
if root.stats-visible && root.downloads != "": Label { x: root.width - root.stats-width; y: 7px; width: root.stats-width - 52px; height: 18px; horizontal-alignment: right; text: root.compact(root.downloads) + " downloads"; color: root.lit ? Theme.black : Theme.text; overflow: elide; }
if root.stats-visible && !root.downloading: Label { x: root.width - root.stats-width; y: 25px; width: root.stats-width - 52px; height: 18px; horizontal-alignment: right; text: root.update-badge != "" ? root.update-badge : root.installed ? "Installed " + root.version : root.version; font-weight: 700; color: root.lit ? Theme.black : root.pending ? Theme.pending : root.dimmed ? Theme.disabled-text : root.action == 2 ? Theme.orange : Theme.text; opacity: root.pending && root.dimmed && !root.lit ? Theme.disabled-row-opacity : 1; overflow: elide; }
if root.stats-visible && root.downloading: Rectangle {
x: root.width - root.stats-width; y: 31px; width: root.stats-width - 52px; height: 8px;
if !root.failed: Nine { width: parent.width; height: parent.height; source: Pieces.progressbar-background-default-base; }
if !root.failed && root.fraction > 0: Nine { x: 0px; width: max(8px, parent.width * clamp(root.fraction, 0, 1)); height: parent.height; source: Pieces.progressbar-fill-default-base; }
if !root.failed: Nine { x: -4px; y: -4px; width: parent.width + 8px; height: parent.height + 8px; source: Pieces.progressbar-background-default-shadow; }
}
if root.downloading: Label { x: root.width - root.stats-width; y: 22px; width: root.stats-width - 52px; height: 26px; vertical-alignment: center; text: root.progress-label; color: root.failed ? #ff8e8e : Theme.text; font-size: 12px; overflow: elide; }
// Select before a drag or a release over a different row can cancel the click.
touch := TouchArea { pointer-event(e) => { if (e.kind == PointerEventKind.down && e.button == PointerEventButton.left) { UiSounds.begin(); root.clicked(); UiSounds.finish(UiCue.selection); } } }
if !root.downloading: ModAction { x: root.width - root.stats-width; y: 11px; width: root.stats-width - 12px; height: 28px;
action: root.action; busy: root.busy; downloading: false; fraction: root.fraction; progress-label: root.progress-label; compact: true;
version: root.version;
tooltip(text) => { root.action-tooltip(text); }
activate(remove) => { root.activate(remove); } cancel => { root.cancel(); }
}
if root.downloading: Button { sound: UiCue.tool; x: root.width - 40px; y: 11px; width: 28px; min-width: 0px; height: 28px; text: "X"; transparent-background: true; clicked => { root.cancel(); } }
}