Skip to content

Commit

Permalink
buttons: Fix single group behaviours
Browse files Browse the repository at this point in the history
  • Loading branch information
flamewave000 committed Nov 23, 2022
1 parent ac3c264 commit c8d6169
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions lib-df-buttons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# DragonFlagon Module Buttons Library

## Release 1.4.2 (2022-11-23)
- **FIX:** Buttons were disappearing when only one group was available.

## Release 1.4.1 (2022-11-23)
- **UPDATE #391:** You can now declare your button/group as being displayable when there is no canvas. Just add the `"noCanvas": true` to your Tool and ToolGroup declarations.
- **FIX:** The buttons will now automatically refresh when ever the sacene layer changes. This way modules that are trying to display buttons for only certain layers will not need to manually tell the buttons to refresh.
Expand Down
2 changes: 1 addition & 1 deletion lib-df-buttons/module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "lib-df-buttons",
"title": "Library: DF Module Buttons",
"version": "1.4.1",
"version": "1.4.2",
"description": "Library that provides a way for modules to register controls outside of the scene layer controls",
"author": "flamewave000#0001",
"compatibility": {
Expand Down
31 changes: 18 additions & 13 deletions lib-df-buttons/src/ControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export default class ControlManager extends Application implements IControlManag
}
private async completeInitialization() {
this.initializationIncomplete = false;
this.hooksRegister['collapseSidebarPre'] = Hooks.on('collapseSidebarPre', this._handleSidebarCollapse.bind(this));
this.hooksRegister['activateGroupByName'] = Hooks.on('activateGroupByName', this.activateGroupByName.bind(this));
this.hooksRegister['activateToolByName'] = Hooks.on('activateToolByName', this.activateToolByName.bind(this));
this.hooksRegister['reloadModuleButtons'] = Hooks.on('reloadModuleButtons', this.reloadModuleButtons.bind(this));
this.hooksRegister['refreshModuleButtons'] = Hooks.on('refreshModuleButtons', this.refresh.bind(this));
this.hooksRegister['renderSceneControls'] = Hooks.on('renderSceneControls', () => { this.refresh(); this._handleWindowResize(); });
this.hooksRegister['collapseSceneNavigation'] = Hooks.on('collapseSceneNavigation', this._handleWindowResize.bind(this));
this.hooksRegister['renderPlayerList'] = Hooks.on('renderPlayerList', this._handleWindowResize.bind(this));
window.addEventListener('resize', this._handleWindowResize.bind(this));
for (const group of this._groups) {
// Initialize all unset fields to their defaults
ControlManager.initializeFields(group);
Expand Down Expand Up @@ -153,7 +162,14 @@ export default class ControlManager extends Application implements IControlManag
}
groups.push(groupUI);
}
return { groups, singleGroup: groups.length === 1 && !groups[0].button && !groups[0].toggle };
const singleGroup = groups.length === 1 && !groups[0].button && !groups[0].toggle;
if (groups.every(x => !x.active)) {
const firstGroup = groups.find(x => !x.button && !x.toggle);
firstGroup.active = true;
if (firstGroup)
this.activateGroupByName(firstGroup.name);
}
return { groups, singleGroup };
}

/** @inheritdoc */
Expand Down Expand Up @@ -237,22 +253,11 @@ export default class ControlManager extends Application implements IControlManag
async _render(force = false, options = {}): Promise<void> {
// If initialization needs to be completed, invoke the completion
if (this.initializationIncomplete) await this.completeInitialization();
if (this._state !== Application.RENDER_STATES.RENDERED) {
this.hooksRegister['collapseSidebarPre'] = Hooks.on('collapseSidebarPre', this._handleSidebarCollapse.bind(this));
this.hooksRegister['activateGroupByName'] = Hooks.on('activateGroupByName', this.activateGroupByName.bind(this));
this.hooksRegister['activateToolByName'] = Hooks.on('activateToolByName', this.activateToolByName.bind(this));
this.hooksRegister['reloadModuleButtons'] = Hooks.on('reloadModuleButtons', this.reloadModuleButtons.bind(this));
this.hooksRegister['refreshModuleButtons'] = Hooks.on('refreshModuleButtons', this.refresh.bind(this));
this.hooksRegister['renderSceneControls'] = Hooks.on('renderSceneControls', () => { this.refresh(); this._handleWindowResize(); });
this.hooksRegister['collapseSceneNavigation'] = Hooks.on('collapseSceneNavigation', this._handleWindowResize.bind(this));
this.hooksRegister['renderPlayerList'] = Hooks.on('renderPlayerList', this._handleWindowResize.bind(this));
window.addEventListener('resize', this._handleWindowResize.bind(this));
}
if (!game.ready) return;
await super._render(force, options);
if ((<any>ui.sidebar)._collapsed) {
this.element.css('right', '35px');
}

this.element[0].removeAttribute('class');
this.element[0].classList.add('app');
switch (SETTINGS.get('position')) {
Expand Down
5 changes: 2 additions & 3 deletions lib-df-buttons/src/lib-df-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ Hooks.once('setup', () => {
Hooks.once('ready', () => {
(<ControlManagerImpl>(<any>ui).moduleControls).render(true);
});
Hooks.on('renderSceneControls', async (_: any) => {
(<ControlManagerImpl>(<any>ui).moduleControls).refresh();
});
/* Example code for appending ToolGroups and Tools */
/**
//import { Tool, ToolGroup } from "./ToolType";
Expand All @@ -68,6 +65,7 @@ Hooks.on('getModuleToolGroups', (app: ControlManager, groups: ToolGroup[]) => {
name: 'radial1',
icon: '<i class="fas fa-dice-one"></i>',
title: 'radial1',
visible: () => ui.controls.activeControl === 'token',
onClick: handleClick,
tools: [
{ name: 'tool1-1', title: 'tool1-1', onClick: handleClick, icon: '<i class="fas fa-dice-one"></i>' },
Expand All @@ -80,6 +78,7 @@ Hooks.on('getModuleToolGroups', (app: ControlManager, groups: ToolGroup[]) => {
name: 'radial2',
icon: '<i class="fas fa-dice-two"></i>',
title: 'radial2',
visible: () => ui.controls.activeControl === 'walls',
onClick: handleClick,
tools: [
{ name: 'tool2-1', title: 'tool2-1', onClick: handleClick, icon: '<i class="fas fa-dice-two"></i>' },
Expand Down

0 comments on commit c8d6169

Please sign in to comment.