Alt greetings restyle (#2902)

* Slight QoL restyle of alternate greetings
* Update to new popup
* Add visible labels to buttons
This commit is contained in:
Cohee
2024-09-26 23:56:38 +03:00
committed by GitHub
parent 38660df93f
commit 75308bfe7f
3 changed files with 65 additions and 15 deletions

View File

@ -6090,7 +6090,10 @@
<div class="alternate_grettings flexFlowColumn flex-container"> <div class="alternate_grettings flexFlowColumn flex-container">
<div class="title_restorable"> <div class="title_restorable">
<h3><span data-i18n="Alternate Greetings" class="mdhotkey_location">Alternate Greetings</span></h3> <h3><span data-i18n="Alternate Greetings" class="mdhotkey_location">Alternate Greetings</span></h3>
<div title="Add" class="menu_button fa-solid fa-plus add_alternate_greeting" data-i18n="[title]Add"></div> <div class="menu_button menu_button_icon add_alternate_greeting">
<i class="fa-solid fa-plus"></i>
<span data-i18n="Add">Add</span>
</div>
</div> </div>
<small class="justifyLeft" data-i18n="Alternate_Greetings_desc"> <small class="justifyLeft" data-i18n="Alternate_Greetings_desc">
These will be displayed as swipes on the first message when starting a new chat. These will be displayed as swipes on the first message when starting a new chat.
@ -6106,11 +6109,18 @@
</div> </div>
<div id="alternate_greeting_form_template" class="template_element"> <div id="alternate_greeting_form_template" class="template_element">
<div class="alternate_greeting"> <div class="alternate_greeting">
<div class="title_restorable"> <details open>
<strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong> <summary>
<div class="menu_button fa-solid fa-trash-alt delete_alternate_greeting"></div> <div class="title_restorable">
</div> <strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong>
<textarea name="alternate_greetings" data-i18n="[placeholder](This will be the first message from the character that starts every chat)" placeholder="(This will be the first message from the character that starts every chat)" class="text_pole textarea_compact alternate_greeting_text mdHotkeys" value="" autocomplete="off" rows="16"></textarea> <div class="menu_button menu_button_icon delete_alternate_greeting">
<i class="fa-solid fa-trash-alt"></i>
<span data-i18n="Delete">Delete</span>
</div>
</div>
</summary>
<textarea name="alternate_greetings" data-i18n="[placeholder](This will be the first message from the character that starts every chat)" placeholder="(This will be the first message from the character that starts every chat)" class="text_pole textarea_compact alternate_greeting_text mdHotkeys" value="" autocomplete="off" rows="12"></textarea>
</details>
</div> </div>
</div> </div>

View File

@ -7390,7 +7390,7 @@ function onScenarioOverrideRemoveClick() {
*/ */
export function callPopup(text, type, inputValue = '', { okButton, rows, wide, wider, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) { export function callPopup(text, type, inputValue = '', { okButton, rows, wide, wider, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) {
function getOkButtonText() { function getOkButtonText() {
if (['text', 'alternate_greeting', 'char_not_selected'].includes(popup_type)) { if (['text', 'char_not_selected'].includes(popup_type)) {
$dialoguePopupCancel.css('display', 'none'); $dialoguePopupCancel.css('display', 'none');
return okButton ?? 'Ok'; return okButton ?? 'Ok';
} else if (['delete_extension'].includes(popup_type)) { } else if (['delete_extension'].includes(popup_type)) {
@ -7827,24 +7827,42 @@ function openAlternateGreetings() {
const template = $('#alternate_greetings_template .alternate_grettings').clone(); const template = $('#alternate_greetings_template .alternate_grettings').clone();
const getArray = () => menu_type == 'create' ? create_save.alternate_greetings : characters[chid].data.alternate_greetings; const getArray = () => menu_type == 'create' ? create_save.alternate_greetings : characters[chid].data.alternate_greetings;
const popup = new Popup(template, POPUP_TYPE.TEXT, '', {
wide: true,
large: true,
allowVerticalScrolling: true,
onClose: async () => {
if (menu_type !== 'create') {
await createOrEditCharacter();
}
}
});
for (let index = 0; index < getArray().length; index++) { for (let index = 0; index < getArray().length; index++) {
addAlternateGreeting(template, getArray()[index], index, getArray); addAlternateGreeting(template, getArray()[index], index, getArray, popup);
} }
template.find('.add_alternate_greeting').on('click', function () { template.find('.add_alternate_greeting').on('click', function () {
const array = getArray(); const array = getArray();
const index = array.length; const index = array.length;
array.push(''); array.push('');
addAlternateGreeting(template, '', index, getArray); addAlternateGreeting(template, '', index, getArray, popup);
updateAlternateGreetingsHintVisibility(template); updateAlternateGreetingsHintVisibility(template);
}); });
updateAlternateGreetingsHintVisibility(template); updateAlternateGreetingsHintVisibility(template);
callPopup(template, 'alternate_greeting', '', { wide: true, large: true }); popup.show();
} }
function addAlternateGreeting(template, greeting, index, getArray) { /**
* Adds an alternate greeting to the template.
* @param {JQuery<HTMLElement>} template
* @param {string} greeting
* @param {number} index
* @param {() => any[]} getArray
* @param {Popup} popup
*/
function addAlternateGreeting(template, greeting, index, getArray, popup) {
const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone(); const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone();
greetingBlock.find('.alternate_greeting_text').on('input', async function () { greetingBlock.find('.alternate_greeting_text').on('input', async function () {
const value = $(this).val(); const value = $(this).val();
@ -7852,11 +7870,16 @@ function addAlternateGreeting(template, greeting, index, getArray) {
array[index] = value; array[index] = value;
}).val(greeting); }).val(greeting);
greetingBlock.find('.greeting_index').text(index + 1); greetingBlock.find('.greeting_index').text(index + 1);
greetingBlock.find('.delete_alternate_greeting').on('click', async function () { greetingBlock.find('.delete_alternate_greeting').on('click', async function (event) {
event.preventDefault();
event.stopPropagation();
if (confirm('Are you sure you want to delete this alternate greeting?')) { if (confirm('Are you sure you want to delete this alternate greeting?')) {
const array = getArray(); const array = getArray();
array.splice(index, 1); array.splice(index, 1);
// We need to reopen the popup to update the index numbers // We need to reopen the popup to update the index numbers
await popup.complete(POPUP_RESULT.AFFIRMATIVE);
openAlternateGreetings(); openAlternateGreetings();
} }
}); });
@ -9574,9 +9597,6 @@ jQuery(async function () {
}, 2000); }, 2000);
} }
} }
if (popup_type == 'alternate_greeting' && menu_type !== 'create') {
createOrEditCharacter();
}
if (dialogueResolve) { if (dialogueResolve) {
if (popup_type == 'input') { if (popup_type == 'input') {

View File

@ -3154,6 +3154,26 @@ grammarly-extension {
align-items: center; align-items: center;
} }
.alternate_greeting details {
padding: 2px;
}
.alternate_greeting summary {
list-style-position: outside;
margin-left: 1em;
padding-left: 1em;
}
.alternate_greeting textarea {
field-sizing: content;
max-height: 50dvh;
}
.alternate_greeting summary::marker,
.alternate_greeting summary strong {
cursor: pointer;
}
#rm_characters_block .form_create_bottom_buttons_block { #rm_characters_block .form_create_bottom_buttons_block {
justify-content: space-evenly !important; justify-content: space-evenly !important;
flex-grow: 0; flex-grow: 0;