Add possibility to delete and edit effects in the actor sheet

This commit is contained in:
Johannes Loher 2021-07-22 02:02:35 +02:00
parent 4d2a7d1686
commit 808dab7f5a
15 changed files with 91 additions and 51 deletions

View file

@ -130,7 +130,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
html.find(".item-change").on("change", this.onItemChange.bind(this)); html.find(".item-change").on("change", this.onItemChange.bind(this));
html.find(".effect-create").on("click", this.onEffectCreate.bind(this)); html.find(".control-effect").on("click", this.onControlEffect.bind(this));
html.find(".rollable-item").on("click", this.onRollItem.bind(this)); html.find(".rollable-item").on("click", this.onRollItem.bind(this));
@ -244,17 +244,44 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
} }
} }
protected onEffectCreate(event: JQuery.ClickEvent): void { protected onControlEffect(event: JQuery.ClickEvent): void {
event.preventDefault(); event.preventDefault();
const a = event.currentTarget;
switch (a.dataset["action"]) {
case "create":
return this.onCreateEffect();
case "edit":
return this.onEditEffect(event);
case "delete":
return this.onDeleteEffect(event);
}
}
protected onCreateEffect(): void {
const createData = { const createData = {
label: "New Effect", label: "New Effect",
icon: "icons/svg/aura.svg", icon: "icons/svg/aura.svg",
origin: this.actor.uuid, origin: this.actor.uuid,
}; };
ActiveEffect.create(createData, { parent: this.actor }); ActiveEffect.create(createData, { parent: this.actor });
} }
protected onEditEffect(event: JQuery.ClickEvent): void {
const id = $(event.currentTarget).parents(".effect").data("effectId");
const effect = this.actor.effects.get(id);
if (!effect) {
throw new Error(getGame().i18n.format("DS4.ErrorActorDoesNotHaveEffect", { id, actor: this.actor.name }));
}
effect.sheet.render(true);
}
protected onDeleteEffect(event: JQuery.ClickEvent): void {
const li = $(event.currentTarget).parents(".effect");
const id = li.data("effectId");
this.actor.deleteEmbeddedDocuments("ActiveEffect", [id]);
li.slideUp(200, () => this.render(false));
}
/** /**
* Handle clickable item rolls. * Handle clickable item rolls.
* @param event - The originating click event * @param event - The originating click event

View file

@ -15,6 +15,7 @@ export default async function registerHandlebarsPartials(): Promise<void> {
"systems/ds4/templates/sheets/actor/components/checks.hbs", "systems/ds4/templates/sheets/actor/components/checks.hbs",
"systems/ds4/templates/sheets/actor/components/combat-value.hbs", "systems/ds4/templates/sheets/actor/components/combat-value.hbs",
"systems/ds4/templates/sheets/actor/components/combat-values.hbs", "systems/ds4/templates/sheets/actor/components/combat-values.hbs",
"systems/ds4/templates/sheets/actor/components/control-button-group.hbs",
"systems/ds4/templates/sheets/actor/components/core-value.hbs", "systems/ds4/templates/sheets/actor/components/core-value.hbs",
"systems/ds4/templates/sheets/actor/components/core-values.hbs", "systems/ds4/templates/sheets/actor/components/core-values.hbs",
"systems/ds4/templates/sheets/actor/components/creature-properties.hbs", "systems/ds4/templates/sheets/actor/components/creature-properties.hbs",
@ -24,7 +25,6 @@ export default async function registerHandlebarsPartials(): Promise<void> {
"systems/ds4/templates/sheets/actor/components/item-list-entry.hbs", "systems/ds4/templates/sheets/actor/components/item-list-entry.hbs",
"systems/ds4/templates/sheets/actor/components/item-list-header.hbs", "systems/ds4/templates/sheets/actor/components/item-list-header.hbs",
"systems/ds4/templates/sheets/actor/components/items-overview.hbs", "systems/ds4/templates/sheets/actor/components/items-overview.hbs",
"systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs",
"systems/ds4/templates/sheets/actor/components/profile.hbs", "systems/ds4/templates/sheets/actor/components/profile.hbs",
"systems/ds4/templates/sheets/actor/components/rollable-image.hbs", "systems/ds4/templates/sheets/actor/components/rollable-image.hbs",
"systems/ds4/templates/sheets/actor/components/talent-rank-equation.hbs", "systems/ds4/templates/sheets/actor/components/talent-rank-equation.hbs",

View file

@ -0,0 +1,17 @@
/*
* SPDX-FileCopyrightText: 2021 Johannes Loher
*
* SPDX-License-Identifier: MIT
*/
@use "../utils/variables";
.ds4-control-button-group {
display: flex;
text-align: center;
width: 100%;
padding: 0 calc(1em / 3);
&__button {
flex: 1;
}
}

View file

@ -96,14 +96,6 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
} }
&__control-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
text-align: center;
width: 100%;
padding: 0 calc(1em / 3);
}
} }
.ds4-item-list-title { .ds4-item-list-title {

View file

@ -29,6 +29,7 @@
@include meta.load-css("components/checks"); @include meta.load-css("components/checks");
@include meta.load-css("components/combat_value"); @include meta.load-css("components/combat_value");
@include meta.load-css("components/combat_values"); @include meta.load-css("components/combat_values");
@include meta.load-css("components/control_button_group");
@include meta.load-css("components/core_value"); @include meta.load-css("components/core_value");
@include meta.load-css("components/core_values"); @include meta.load-css("components/core_values");
@include meta.load-css("components/currency"); @include meta.load-css("components/currency");

View file

@ -7,12 +7,13 @@ SPDX-License-Identifier: MIT
{{! {{!
!-- Render an "add" button. !-- Render an "add" button.
!-- @param class: The css class to use for the link element !-- @param documentType: The type of document this button controls, item or effect
!-- @param title: The title to use for the link element (will be localized) !-- @param title: The title to use for the link element (will be localized)
!-- @param type: An optional property to use as data-type attribute !-- @param type: An optional property to use as data-type attribute
}} }}
<div> <div>
<a class="{{class}}" title="{{localize title}}" {{#if type}}data-type="{{type}}" {{/if}}> <a class="control-{{documentType}} {{documentType}}-create" title="{{localize title}}" data-action="create" {{#if
type}}data-type="{{type}}" {{/if}}>
<i class="fas fa-plus"></i> <i class="fas fa-plus"></i>
{{localize "DS4.UserInteractionAdd"}} {{localize "DS4.UserInteractionAdd"}}
</a> </a>

View file

@ -0,0 +1,20 @@
{{!--
SPDX-FileCopyrightText: 2021 Johannes Loher
SPDX-FileCopyrightText: 2021 Gesina Schwalbe
SPDX-License-Identifier: MIT
--}}
{{!--
!-- Render a group of an "edit" and a "delete" button.
!-- The current item is defined by the data-item-id HTML property of the parent li element.
!-- @param documentType: The type of document that is controlled by this button group, item or effect
!-- @param editTitle: The title to use for the edit link element (will be localized)
!-- @param deleteTitle: The title to use for the delete link element (will be localized)
--}}
<div class="ds4-control-button-group">
<a class="ds4-control-button-group__button control-{{documentType}} {{documentType}}-edit" data-action="edit"
title="{{localize editTitle}}"><i class="fas fa-edit"></i></a>
<a class="ds4-control-button-group__button control-{{documentType}} {{documentType}}-delete" data-action="delete"
title="{{localize deleteTitle}}"><i class="fas fa-trash"></i></a>
</div>

View file

@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT
!-- Render an effect list entry row. !-- Render an effect list entry row.
!-- @param effectData: The data of the item. !-- @param effectData: The data of the item.
--}} --}}
<li class="ds4-effect-list__row item" data-item-id="{{itemData._id}}"> <li class="ds4-effect-list__row effect" data-effect-id="{{effectData._id}}">
{{!-- enabled --}} {{!-- enabled --}}
<input class="ds4-effect-list__editable ds4-effect-list__editable--checkbox effect-change" type="checkbox" {{checked <input class="ds4-effect-list__editable ds4-effect-list__editable--checkbox effect-change" type="checkbox" {{checked
(ne effectData.disabled)}} data-dtype="Boolean" data-property="disabled" (ne effectData.disabled)}} data-dtype="Boolean" data-property="disabled"
@ -25,7 +25,7 @@ SPDX-License-Identifier: MIT
{{!-- source name --}} {{!-- source name --}}
<div>{{effectData.sourceName}}</div> <div>{{effectData.sourceName}}</div>
{{!-- control buttons --}} {{!-- control button group --}}
{{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs {{> systems/ds4/templates/sheets/actor/components/control-button-group.hbs documentType="effect"
class="ds4-effect-list__control-buttons" }} editTitle="DS4.UserInteractionEditEffectTitle" deleteTitle="DS4.UserInteractionDeleteEffectTitle"}}
</li> </li>

View file

@ -49,7 +49,7 @@ SPDX-License-Identifier: MIT
{{{itemData.data.description}}}</div> {{{itemData.data.description}}}</div>
{{/unless}} {{/unless}}
{{!-- control buttons --}} {{!-- control button group --}}
{{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs {{> systems/ds4/templates/sheets/actor/components/control-button-group.hbs documentType="item"
class="ds4-item-list__control-buttons" }} editTitle="DS4.UserInteractionEditItemTitle" deleteTitle="DS4.UserInteractionDeleteItemTitle"}}
</li> </li>

View file

@ -42,7 +42,7 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='weapon'}} documentType='item' type='weapon'}}
{{!-- ARMOR --}} {{!-- ARMOR --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeArmorPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeArmorPlural'}}</h4>
@ -81,7 +81,7 @@ class='item-create' type='weapon'}}
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='armor'}} documentType='item' type='armor'}}
{{!-- SHIELD --}} {{!-- SHIELD --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeShieldPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeShieldPlural'}}</h4>
@ -103,7 +103,7 @@ class='item-create' type='armor'}}
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='shield'}} documentType='item' type='shield'}}
{{!-- EQUIPMENT --}} {{!-- EQUIPMENT --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeEquipmentPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeEquipmentPlural'}}</h4>
@ -124,7 +124,7 @@ class='item-create' type='shield'}}
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='equipment'}} documentType='item' type='equipment'}}
{{!-- LOOT --}} {{!-- LOOT --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLootPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLootPlural'}}</h4>
@ -144,4 +144,4 @@ class='item-create' type='equipment'}}
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='loot'}} documentType='item' type='loot'}}

View file

@ -1,18 +0,0 @@
{{!--
SPDX-FileCopyrightText: 2021 Johannes Loher
SPDX-FileCopyrightText: 2021 Gesina Schwalbe
SPDX-License-Identifier: MIT
--}}
{{!--
!-- Render a group of an "edit" and a "delete" button for the current item.
!-- The current item is defined by the data-item-id HTML property of the parent li element.
!-- @param class: Additional CSS class(es) for the controls
--}}
<div class="item-controls {{class}}">
<a class="item-control item-edit" title="{{localize 'DS4.UserInteractionEditItemTitle'}}"><i
class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="{{localize 'DS4.UserInteractionDeleteItemTitle'}}"><i
class="fas fa-trash"></i></a>
</div>

View file

@ -23,7 +23,7 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='talent'}} documentType='item' type='talent'}}
{{!-- RACIAL ABILITY --}} {{!-- RACIAL ABILITY --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeRacialAbilityPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeRacialAbilityPlural'}}</h4>
@ -36,7 +36,7 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='racialAbility'}} documentType='item' type='racialAbility'}}
{{!-- LANGUAGE --}} {{!-- LANGUAGE --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLanguagePlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLanguagePlural'}}</h4>
@ -49,7 +49,7 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='language'}} documentType='item' type='language'}}
{{!-- ALPHABET --}} {{!-- ALPHABET --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeAlphabetPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeAlphabetPlural'}}</h4>
@ -62,5 +62,5 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='alphabet'}} documentType='item' type='alphabet'}}
</div> </div>

View file

@ -15,5 +15,5 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddEffectTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddEffectTitle'
class='effect-create'}} documentType='effect'}}
</div> </div>

View file

@ -15,5 +15,5 @@ SPDX-License-Identifier: MIT
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='specialCreatureAbility'}} documentType='item' type='specialCreatureAbility'}}
</div> </div>

View file

@ -94,5 +94,5 @@ titleKey=titleKey}}
</ol> </ol>
{{/unless}} {{/unless}}
{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle'
class='item-create' type='spell'}} documentType='item' type='spell'}}
</div> </div>