2023-11-27 22:02:28 -05:00
|
|
|
import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.js';
|
|
|
|
|
|
|
|
const Y_POS = 80;
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-01-29 20:56:56 -05:00
|
|
|
import { ConnectFunc, OSD, ProgressBarGeneric } from 'global-types';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-11-27 22:02:28 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
export default ({ stack, icon, info }: OSD) => {
|
|
|
|
let connectFunc: ConnectFunc;
|
2023-11-27 22:02:28 -05:00
|
|
|
|
|
|
|
const osd = Box({
|
|
|
|
css: `margin-bottom: ${Y_POS}px;`,
|
|
|
|
children: [Box({
|
2023-12-21 01:25:59 -05:00
|
|
|
class_name: 'osd',
|
2023-11-27 22:02:28 -05:00
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
hpack: 'start',
|
|
|
|
// Can take a string or an object of props
|
|
|
|
...(typeof icon === 'string' ? { icon } : icon),
|
|
|
|
}),
|
|
|
|
// Can take a static widget instead of a progressbar
|
2024-01-22 10:23:32 -05:00
|
|
|
info.widget ?
|
|
|
|
info.widget :
|
|
|
|
ProgressBar({ vpack: 'center' }),
|
2023-11-27 22:02:28 -05:00
|
|
|
],
|
|
|
|
})],
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle requests to show the OSD
|
|
|
|
// Different wether it's a bar or static
|
|
|
|
if (info.logic) {
|
2024-01-13 11:15:08 -05:00
|
|
|
connectFunc = (self) => new Promise<void>((r) => {
|
|
|
|
if (info.logic && self) {
|
|
|
|
info.logic(self);
|
|
|
|
}
|
2023-11-27 22:02:28 -05:00
|
|
|
r();
|
2023-12-21 01:25:59 -05:00
|
|
|
}).then(() => stack.attribute.popup(osd));
|
2023-11-27 22:02:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-21 01:25:59 -05:00
|
|
|
connectFunc = () => stack.attribute.popup(osd);
|
2023-11-27 22:02:28 -05:00
|
|
|
}
|
|
|
|
|
2024-01-29 20:56:56 -05:00
|
|
|
(osd.children[0].children[1] as ProgressBarGeneric)
|
2024-01-13 11:15:08 -05:00
|
|
|
.hook(info.mod, connectFunc, info.signal);
|
2023-11-27 22:02:28 -05:00
|
|
|
|
|
|
|
return osd;
|
|
|
|
};
|