Added the select and handliing

This commit is contained in:
WBHarry 2025-12-24 17:27:52 +01:00
parent c63ba3b41d
commit f386076264
2 changed files with 71 additions and 14 deletions

View file

@ -34,8 +34,55 @@ export default class DhTokenConfig extends foundry.applications.sheets.TokenConf
async _prepareAppearanceTab() { async _prepareAppearanceTab() {
const context = await super._prepareAppearanceTab(); const context = await super._prepareAppearanceTab();
context.actorSizeUsed = this.token.actor ? Boolean(this.token.actor.system.size) : false; context.tokenSizes = CONFIG.DH.ACTOR.tokenSize;
context.usesActorSize = this.token.actor?.system?.metadata?.usesSize;
context.actorSizeDisable = context.usesActorSize && this.token.actor.system.size !== 'custom';
return context; return context;
} }
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
switch (partId) {
case 'appearance':
htmlElement
.querySelector('#dhTokenSize')
?.addEventListener('change', this.onTokenSizeChange.bind(this));
break;
}
}
async onTokenSizeChange(event) {
const value = event.target.value;
const tokenSizeDimensions = this.element.querySelector('#tokenSizeDimensions');
if (tokenSizeDimensions) {
const disabled = value !== 'custom';
tokenSizeDimensions.dataset.tooltip = disabled
? game.i18n.localize('DAGGERHEART.APPLICATIONS.TokenConfig.actorSizeUsed')
: '';
const disabledIcon = tokenSizeDimensions.querySelector('i');
if (disabledIcon) {
disabledIcon.style.opacity = disabled ? '' : '0';
}
const dimensionsInputs = tokenSizeDimensions.querySelectorAll('.form-fields input');
for (const input of dimensionsInputs) {
input.disabled = disabled;
}
}
}
async _processSubmitData(event, form, submitData, options) {
const tokenSizeSelect = this.element.querySelector('#dhTokenSize');
if (tokenSizeSelect && this.token.actor) {
if (tokenSizeSelect.value !== this.token.actor.system.size) {
this.token.actor.update({ 'system.size': tokenSizeSelect.value });
}
}
super._processSubmitData(event, form, submitData, options);
}
} }

View file

@ -11,21 +11,31 @@
</div> </div>
{{/if}} {{/if}}
<fieldset>
<legend>{{localize "Token Size"}}</legend>
{{#if usesActorSize}}
<div class="form-group lim">
<label>{{localize "Size Category"}}</label>
<div class="form-group slim" {{#if actorSizeUsed}}data-tooltip="{{localize "DAGGERHEART.APPLICATIONS.TokenConfig.actorSizeUsed"}}"{{/if}}> <select id="dhTokenSize" name="actor.system.size">
<label> {{selectOptions tokenSizes selected=document.actor.system.size valueAttr="id" labelAttr="label" localize=true}}
{{localize "TOKEN.Dimensions"}} <span class="units">({{localize "GridSpaces"}})</span> </select>
{{#if actorSizeUsed}} </div>
<i class="fa-solid fa-lock"></i> {{/if}}
{{/if}}
</label> <div id="tokenSizeDimensions" class="form-group slim" {{#if actorSizeDisable}}data-tooltip="{{localize "DAGGERHEART.APPLICATIONS.TokenConfig.actorSizeUsed"}}"{{/if}}>
<div class="form-fields"> <label>
<label for="{{rootId}}-width">{{localize "DOCUMENT.FIELDS.width.label"}}</label> {{localize "TOKEN.Dimensions"}} <span class="units">({{localize "GridSpaces"}})</span>
{{formInput fields.width value=source.width id=(concat rootId "-width") disabled=actorSizeUsed}} <i class="fa-solid fa-lock" {{#unless actorSizeDisable}}style="opacity: 0%;"{{/unless}}></i>
<label for="{{rootId}}-height">{{localize "DOCUMENT.FIELDS.height.label"}}</label> </label>
{{formInput fields.height value=source.height id=(concat rootId "-height") disabled=actorSizeUsed}} <div class="form-fields">
<label for="{{rootId}}-width">{{localize "DOCUMENT.FIELDS.width.label"}}</label>
{{formInput fields.width value=source.width id=(concat rootId "-width") disabled=actorSizeDisable}}
<label for="{{rootId}}-height">{{localize "DOCUMENT.FIELDS.height.label"}}</label>
{{formInput fields.height value=source.height id=(concat rootId "-height") disabled=actorSizeDisable}}
</div>
</div> </div>
</div> </fieldset>
{{#if shapes}} {{#if shapes}}
{{formGroup fields.shape value=source.shape choices=shapes classes="slim" rootId=rootId}} {{formGroup fields.shape value=source.shape choices=shapes classes="slim" rootId=rootId}}