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

@ -7390,7 +7390,7 @@ function onScenarioOverrideRemoveClick() {
*/
export function callPopup(text, type, inputValue = '', { okButton, rows, wide, wider, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) {
function getOkButtonText() {
if (['text', 'alternate_greeting', 'char_not_selected'].includes(popup_type)) {
if (['text', 'char_not_selected'].includes(popup_type)) {
$dialoguePopupCancel.css('display', 'none');
return okButton ?? 'Ok';
} else if (['delete_extension'].includes(popup_type)) {
@ -7827,24 +7827,42 @@ function openAlternateGreetings() {
const template = $('#alternate_greetings_template .alternate_grettings').clone();
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++) {
addAlternateGreeting(template, getArray()[index], index, getArray);
addAlternateGreeting(template, getArray()[index], index, getArray, popup);
}
template.find('.add_alternate_greeting').on('click', function () {
const array = getArray();
const index = array.length;
array.push('');
addAlternateGreeting(template, '', index, getArray);
addAlternateGreeting(template, '', index, getArray, popup);
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();
greetingBlock.find('.alternate_greeting_text').on('input', async function () {
const value = $(this).val();
@ -7852,11 +7870,16 @@ function addAlternateGreeting(template, greeting, index, getArray) {
array[index] = value;
}).val(greeting);
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?')) {
const array = getArray();
array.splice(index, 1);
// We need to reopen the popup to update the index numbers
await popup.complete(POPUP_RESULT.AFFIRMATIVE);
openAlternateGreetings();
}
});
@ -9574,9 +9597,6 @@ jQuery(async function () {
}, 2000);
}
}
if (popup_type == 'alternate_greeting' && menu_type !== 'create') {
createOrEditCharacter();
}
if (dialogueResolve) {
if (popup_type == 'input') {