-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #942 from UFOMelkor/hotbar
Update Hotbar
- Loading branch information
Showing
3 changed files
with
173 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,155 @@ | ||
/** | ||
* The global action bar displayed at the bottom of the game view. | ||
* The Hotbar is a UI element at the bottom of the screen which contains Macros as interactive buttons. | ||
* The Hotbar supports 5 pages of global macros which can be dragged and dropped to organize as you wish. | ||
* | ||
* Left clicking a Macro button triggers its effect. | ||
* Right clicking the button displays a context menu of Macro options. | ||
* The number keys 1 through 0 activate numbered hotbar slots. | ||
* Pressing the delete key while hovering over a Macro will remove it from the bar. | ||
* | ||
* @see {@link Macros} | ||
* @see {@link Macro} | ||
*/ | ||
|
||
declare class Hotbar extends Application { | ||
/** | ||
* The currently viewed macro page | ||
* @defaultValue `1` | ||
*/ | ||
page: number; | ||
|
||
/** | ||
* The currently displayed set of macros | ||
* @defaultValue `[]` | ||
*/ | ||
macros: Macro[]; | ||
|
||
/** | ||
* Track collapsed state | ||
* @defaultValue `false` | ||
*/ | ||
protected _collapsed: boolean; | ||
|
||
/** | ||
* Track which hotbar slot is the current hover target, if any | ||
* @defaultValue `null` | ||
*/ | ||
protected _hover: number | null; | ||
|
||
/** | ||
* @override | ||
* @defaultValue | ||
* ```typescript | ||
* mergeObject(super.defaultOptions, { | ||
* id: "hotbar", | ||
* template: "templates/hud/hotbar.html", | ||
* popOut: false, | ||
* dragDrop: [{ dragSelector: ".macro-icon", dropSelector: "#macro-list" }] | ||
* }) | ||
* ``` | ||
*/ | ||
static get defaultOptions(): typeof Application['defaultOptions']; | ||
|
||
/** @override */ | ||
getData(options?: Application.RenderOptions): Hotbar.Data | Promise<Hotbar.Data>; | ||
|
||
/** | ||
* Get the Array of Macro (or null) values that should be displayed on a numbered page of the bar | ||
* @param page - | ||
*/ | ||
protected _getMacrosByPage(page: number): Macro[]; | ||
|
||
/** | ||
* Collapse the Hotbar, minimizing its display. | ||
* @returns A promise which resolves once the collapse animation completes | ||
*/ | ||
collapse(): Promise<boolean>; | ||
|
||
/** | ||
* Expand the Hotbar, displaying it normally. | ||
* @returns A promise which resolves once the expand animation completes | ||
*/ | ||
expand(): Promise<boolean> | boolean; | ||
|
||
/** | ||
* Change to a specific numbered page from 1 to 5 | ||
* @param page - The page number to change to. | ||
* (default: `1` ) | ||
*/ | ||
changePage(page?: number): void; | ||
|
||
/** | ||
* Change the page of the hotbar by cycling up (positive) or down (negative) | ||
* @param direction - The direction to cycle | ||
*/ | ||
cyclePage(direction: number): void; | ||
|
||
/** @override */ | ||
activateListeners(html: JQuery): void; | ||
|
||
/** | ||
* Create a Context Menu attached to each Macro button | ||
* @param html - | ||
*/ | ||
protected _contextMenu(html: JQuery): void; | ||
|
||
/** | ||
* Handle left-click events to | ||
* @param event - | ||
*/ | ||
protected _onClickMacro(event: JQuery.ClickEvent): Promise<void>; | ||
|
||
/** | ||
* Handle hover events on a macro button to track which slot is the hover target | ||
* @param event - The originating mouseover or mouseleave event | ||
*/ | ||
protected _onHoverMacro(event: JQuery.MouseEnterEvent | JQuery.MouseLeaveEvent): void; | ||
|
||
/** | ||
* Handle pagination controls | ||
* @param event - The originating click event | ||
*/ | ||
protected _onClickPageControl(event: JQuery.ClickEvent): void; | ||
|
||
/** @override */ | ||
protected _canDragStart(selector: string | null): boolean; | ||
|
||
/** @override */ | ||
protected _canDragDrop(selector: string | null): boolean; | ||
|
||
/** @override */ | ||
protected _onDrop(event: DragEvent): void; | ||
|
||
/** | ||
* Get the Macro entity being dropped in the Hotbar. If the data comes from a non-World source, create the Macro | ||
* @param data - The data transfer attached to the DragEvent | ||
* @returns A Promise which returns the dropped Macro, or null | ||
*/ | ||
protected _getDropMacro(data: Hotbar.DropData): Promise<Macro | null>; | ||
|
||
/** | ||
* Handle click events to toggle display of the macro bar | ||
* @param event - | ||
*/ | ||
protected _onToggleBar(event: JQuery.ClickEvent): void; | ||
} | ||
|
||
declare namespace Hotbar { | ||
interface Data { | ||
import { ConfiguredDocumentClass } from '../../../types/helperTypes'; | ||
|
||
declare global { | ||
/** | ||
* The global action bar displayed at the bottom of the game view. | ||
* The Hotbar is a UI element at the bottom of the screen which contains Macros as interactive buttons. | ||
* The Hotbar supports 5 pages of global macros which can be dragged and dropped to organize as you wish. | ||
* | ||
* Left clicking a Macro button triggers its effect. | ||
* Right clicking the button displays a context menu of Macro options. | ||
* The number keys 1 through 0 activate numbered hotbar slots. | ||
* Pressing the delete key while hovering over a Macro will remove it from the bar. | ||
* | ||
* @see {@link Macros} | ||
* @see {@link Macro} | ||
* | ||
* @typeParam Options - the type of the options object | ||
*/ | ||
class Hotbar<Options extends Application.Options = Application.Options> extends Application<Options> { | ||
constructor(options?: Partial<Options>); | ||
|
||
/** | ||
* The currently viewed macro page | ||
* @defaultValue `1` | ||
*/ | ||
page: number; | ||
macros: Macro[]; | ||
barClass: 'collapsed' | ''; | ||
|
||
/** | ||
* The currently displayed set of macros | ||
* @defaultValue `[]` | ||
*/ | ||
macros: InstanceType<ConfiguredDocumentClass<typeof Macro>>[]; | ||
|
||
/** | ||
* Track collapsed state | ||
* @defaultValue `false` | ||
*/ | ||
protected _collapsed: boolean; | ||
|
||
/** | ||
* Track which hotbar slot is the current hover target, if any | ||
* @defaultValue `null` | ||
*/ | ||
protected _hover: number | null; | ||
|
||
/** | ||
* @override | ||
* @defaultValue | ||
* ```typescript | ||
* mergeObject(super.defaultOptions, { | ||
* id: "hotbar", | ||
* template: "templates/hud/hotbar.html", | ||
* popOut: false, | ||
* dragDrop: [{ dragSelector: ".macro-icon", dropSelector: "#macro-list" }] | ||
* }) | ||
* ``` | ||
*/ | ||
static get defaultOptions(): Application.Options; | ||
|
||
/** @override */ | ||
getData(options?: Application.RenderOptions): Hotbar.Data | Promise<Hotbar.Data>; | ||
|
||
/** | ||
* Get the Array of Macro (or null) values that should be displayed on a numbered page of the bar | ||
* @param page - | ||
*/ | ||
protected _getMacrosByPage(page: number): InstanceType<ConfiguredDocumentClass<typeof Macro>>[]; | ||
|
||
/** | ||
* Collapse the Hotbar, minimizing its display. | ||
* @returns A promise which resolves once the collapse animation completes | ||
*/ | ||
collapse(): Promise<boolean>; | ||
|
||
/** | ||
* Expand the Hotbar, displaying it normally. | ||
* @returns A promise which resolves once the expand animation completes | ||
*/ | ||
expand(): Promise<boolean>; | ||
|
||
/** | ||
* Change to a specific numbered page from 1 to 5 | ||
* @param page - The page number to change to. | ||
* (default: `1` ) | ||
*/ | ||
changePage(page?: number): void; | ||
|
||
/** | ||
* Change the page of the hotbar by cycling up (positive) or down (negative) | ||
* @param direction - The direction to cycle | ||
*/ | ||
cyclePage(direction?: number): void; | ||
|
||
/** @override */ | ||
activateListeners(html: JQuery): void; | ||
|
||
/** | ||
* Create a Context Menu attached to each Macro button | ||
* @param html - The HTML being rendered for the hotbar | ||
*/ | ||
protected _contextMenu(html: JQuery): void; | ||
|
||
/** | ||
* Handle left-click events to | ||
* @param event - The originating click event | ||
*/ | ||
protected _onClickMacro(event: JQuery.ClickEvent): Promise<void>; | ||
|
||
/** | ||
* Handle hover events on a macro button to track which slot is the hover target | ||
* @param event - The originating mouseover or mouseleave event | ||
*/ | ||
protected _onHoverMacro(event: JQuery.MouseEnterEvent | JQuery.MouseLeaveEvent): void; | ||
|
||
/** | ||
* Handle pagination controls | ||
* @param event - The originating click event | ||
*/ | ||
protected _onClickPageControl(event: JQuery.ClickEvent): void; | ||
|
||
/** | ||
* @override | ||
* @param selector - (unused) | ||
*/ | ||
protected _canDragStart(selector: string): boolean; | ||
|
||
/** @override */ | ||
protected _onDragStart(event: DragEvent): false | void; | ||
|
||
/** | ||
* @override | ||
* @param selector - (unused) | ||
*/ | ||
protected _canDragDrop(selector: string): boolean; | ||
|
||
/** @override */ | ||
protected _onDrop( | ||
event: DragEvent | ||
): void | ReturnType<InstanceType<ConfiguredDocumentClass<typeof User>>['assignHotbarMacro']>; | ||
|
||
/** | ||
* Handle click events to toggle display of the macro bar | ||
* @param event - | ||
*/ | ||
protected _onToggleBar(event: JQuery.ClickEvent): void; | ||
} | ||
|
||
interface DropData { | ||
type?: string; | ||
data?: DeepPartial<foundry.data.MacroData>; // TODO: Might be incorrect, revisit this!! | ||
id?: string; | ||
pack?: string; | ||
slot?: number; | ||
namespace Hotbar { | ||
interface Data { | ||
page: number; | ||
macros: Macro[]; | ||
barClass: 'collapsed' | ''; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expectType } from 'tsd'; | ||
|
||
const hotbar = new Hotbar(); | ||
expectType<number>(hotbar.page); | ||
expectType<Macro[]>(hotbar.macros); | ||
expectType< | ||
| { page: number; macros: Macro[]; barClass: 'collapsed' | '' } | ||
| Promise<{ page: number; macros: Macro[]; barClass: 'collapsed' | '' }> | ||
>(hotbar.getData()); | ||
|
||
expectType<Promise<boolean>>(hotbar.collapse()); | ||
expectType<Promise<boolean>>(hotbar.expand()); | ||
expectType<void>(hotbar.changePage()); | ||
expectType<void>(hotbar.changePage(5)); | ||
expectType<void>(hotbar.cyclePage()); | ||
expectType<void>(hotbar.cyclePage(1)); | ||
expectType<void>(hotbar.cyclePage(-1)); |