mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Sample Character browser to onboarding
This commit is contained in:
parent
c4ade296ae
commit
9ed6ee2161
@ -5512,8 +5512,14 @@
|
||||
<b data-i18n="SillyTavern is aimed at advanced users.">
|
||||
SillyTavern is aimed at advanced users.
|
||||
</b>
|
||||
<div data-i18n="If you're new to this, enable the simplified UI mode below.">
|
||||
If you're new to this, enable the simplified UI mode below.
|
||||
<div>
|
||||
<span data-i18n="If you're new to this, enable the simplified UI mode below.">
|
||||
If you're new to this, enable the simplified UI mode below.
|
||||
</span>
|
||||
<br>
|
||||
<span data-i18n="Change it later in the 'User Settings' panel.">
|
||||
Change it later in the 'User Settings' panel.
|
||||
</span>
|
||||
</div>
|
||||
<label class="checkbox_label">
|
||||
<input type="checkbox" name="enable_simple_mode" />
|
||||
@ -5521,6 +5527,24 @@
|
||||
Enable simple UI mode
|
||||
</span>
|
||||
</label>
|
||||
<div class="textAlignCenter">
|
||||
<h3 data-i18n="Looking for AI characters?">
|
||||
Looking for AI characters?
|
||||
</h3>
|
||||
<span>
|
||||
<span class="menu_button menu_button_icon external_import_button">
|
||||
<i class="fa-solid fa-cloud-arrow-down"></i>
|
||||
<span>Import</span>
|
||||
</span>
|
||||
<span data-i18n="from supported sources or view">
|
||||
from supported sources or view
|
||||
</span>
|
||||
<span class="open_characters_library menu_button menu_button_icon">
|
||||
<i class="fa-solid fa-image-portrait"></i>
|
||||
<span data-i18n="Sample characters">Sample characters</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<h3 data-i18n="Your Persona">
|
||||
Your Persona
|
||||
</h3>
|
||||
@ -5528,6 +5552,7 @@
|
||||
<span data-i18n="Before you get started, you must select a persona name.">
|
||||
Before you get started, you must select a persona name.
|
||||
</span>
|
||||
<br>
|
||||
<span data-i18n="welcome_message_part_8">This can be changed at any time via the</span> <code><i class="fa-solid fa-face-smile"></i></code> <span data-i18n="welcome_message_part_9">icon.</span>
|
||||
</div>
|
||||
<h4 data-i18n="Persona Name:">Persona Name:</h4>
|
||||
|
@ -224,7 +224,7 @@ import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, de
|
||||
import { initPresetManager } from './scripts/preset-manager.js';
|
||||
import { evaluateMacros } from './scripts/macros.js';
|
||||
import { currentUser, setUserControls } from './scripts/user.js';
|
||||
import { callGenericPopup } from './scripts/popup.js';
|
||||
import { POPUP_TYPE, callGenericPopup } from './scripts/popup.js';
|
||||
import { renderTemplate, renderTemplateAsync } from './scripts/templates.js';
|
||||
import { ScraperManager } from './scripts/scrapers.js';
|
||||
|
||||
@ -418,6 +418,7 @@ export const event_types = {
|
||||
SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received',
|
||||
FILE_ATTACHMENT_DELETED: 'file_attachment_deleted',
|
||||
WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate',
|
||||
OPEN_CHARACTER_LIBRARY: 'open_character_library',
|
||||
};
|
||||
|
||||
export const eventSource = new EventEmitter();
|
||||
@ -5932,7 +5933,7 @@ async function doOnboarding(avatarId) {
|
||||
template.find('input[name="enable_simple_mode"]').on('input', function () {
|
||||
simpleUiMode = $(this).is(':checked');
|
||||
});
|
||||
let userName = await callPopup(template, 'input', currentUser?.name || name1);
|
||||
let userName = await callGenericPopup(template, POPUP_TYPE.INPUT, currentUser?.name || name1, { rows: 2 });
|
||||
|
||||
if (userName) {
|
||||
userName = userName.replace('\n', ' ');
|
||||
@ -6110,15 +6111,6 @@ export async function getSettings() {
|
||||
|
||||
//Load User's Name and Avatar
|
||||
initUserAvatar(settings.user_avatar);
|
||||
|
||||
firstRun = !!settings.firstRun;
|
||||
|
||||
if (firstRun) {
|
||||
hideLoader();
|
||||
await doOnboarding(user_avatar);
|
||||
firstRun = false;
|
||||
}
|
||||
|
||||
setPersonaDescription();
|
||||
|
||||
//Load the active character and group
|
||||
@ -6138,6 +6130,14 @@ export async function getSettings() {
|
||||
await loadExtensionSettings(settings, isVersionChanged);
|
||||
eventSource.emit(event_types.EXTENSION_SETTINGS_LOADED);
|
||||
}
|
||||
|
||||
firstRun = !!settings.firstRun;
|
||||
|
||||
if (firstRun) {
|
||||
hideLoader();
|
||||
await doOnboarding(user_avatar);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
settingsReady = true;
|
||||
@ -10254,7 +10254,7 @@ jQuery(async function () {
|
||||
userStatsHandler();
|
||||
});
|
||||
|
||||
$('#external_import_button').on('click', async () => {
|
||||
$(document).on('click', '.external_import_button, #external_import_button', async () => {
|
||||
const html = `<h3>Enter the URL of the content to import</h3>
|
||||
Supported sources:<br>
|
||||
<ul class="justifyLeft">
|
||||
@ -10265,7 +10265,7 @@ jQuery(async function () {
|
||||
<li>AICharacterCard.com Character (Direct Link or ID)<br>Example: <tt>AICC/aicharcards/the-game-master</tt></li>
|
||||
<li>Direct PNG Link (refer to <code>config.yaml</code> for allowed hosts)<br>Example: <tt>https://files.catbox.moe/notarealfile.png</tt></li>
|
||||
<ul>`;
|
||||
const input = await callPopup(html, 'input', '', { okButton: 'Import', rows: 4 });
|
||||
const input = await callGenericPopup(html, POPUP_TYPE.INPUT, '', { okButton: 'Import', rows: 4 });
|
||||
|
||||
if (!input) {
|
||||
console.debug('Custom content import cancelled');
|
||||
@ -10355,6 +10355,11 @@ jQuery(async function () {
|
||||
showMoreMessages();
|
||||
});
|
||||
|
||||
$(document).on('click', '.open_characters_library', async function () {
|
||||
await getCharacters();
|
||||
eventSource.emit(event_types.OPEN_CHARACTER_LIBRARY);
|
||||
});
|
||||
|
||||
// Added here to prevent execution before script.js is loaded and get rid of quirky timeouts
|
||||
await firstLoadInit();
|
||||
|
||||
|
9
public/scripts/extensions/assets/character.html
Normal file
9
public/scripts/extensions/assets/character.html
Normal file
@ -0,0 +1,9 @@
|
||||
<div class="characterAsset">
|
||||
<div class="characterAssetName">{{name}}</div>
|
||||
<img class="characterAssetImage" alt="{{name}}" src="{{url}}" />
|
||||
<div class="characterAssetDescription">{{description}}</div>
|
||||
<div class="characterAssetButtons flex-container">
|
||||
<div class="characterAssetDownloadButton right_menu_button fa-fw fa-solid fa-download" title="Download"></div>
|
||||
<div class="characterAssetCheckMark right_menu_button fa-fw fa-solid fa-check" title="Installed"></div>
|
||||
</div>
|
||||
</div>
|
@ -3,8 +3,9 @@ TODO:
|
||||
*/
|
||||
//const DEBUG_TONY_SAMA_FORK_MODE = true
|
||||
|
||||
import { getRequestHeaders, callPopup, processDroppedFiles } from '../../../script.js';
|
||||
import { getRequestHeaders, callPopup, processDroppedFiles, eventSource, event_types } from '../../../script.js';
|
||||
import { deleteExtension, extensionNames, getContext, installExtension, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import { POPUP_TYPE, callGenericPopup } from '../../popup.js';
|
||||
import { executeSlashCommands } from '../../slash-commands.js';
|
||||
import { getStringHash, isValidUrl } from '../../utils.js';
|
||||
export { MODULE_NAME };
|
||||
@ -328,6 +329,41 @@ async function deleteAsset(assetType, filename) {
|
||||
}
|
||||
}
|
||||
|
||||
async function openCharacterBrowser(forceDefault) {
|
||||
const url = forceDefault ? ASSETS_JSON_URL : String($('#assets-json-url-field').val());
|
||||
const fetchResult = await fetch(url, { cache: 'no-cache' });
|
||||
const json = await fetchResult.json();
|
||||
const characters = json.filter(x => x.type === 'character');
|
||||
|
||||
if (!characters.length) {
|
||||
toastr.error('No characters found in the assets list', 'Character browser');
|
||||
return;
|
||||
}
|
||||
|
||||
const listElement = $(document.createElement('div'));
|
||||
listElement.addClass('characterAssetList');
|
||||
|
||||
for (const character of characters) {
|
||||
const characterElement = $(await renderExtensionTemplateAsync(MODULE_NAME, 'character', character));
|
||||
const downloadButton = characterElement.find('.characterAssetDownloadButton');
|
||||
const checkMark = characterElement.find('.characterAssetCheckMark');
|
||||
const isInstalled = isAssetInstalled('character', character.id);
|
||||
|
||||
downloadButton.toggle(!isInstalled).on('click', async () => {
|
||||
downloadButton.toggleClass('fa-download fa-spinner fa-spin');
|
||||
await installAsset(character.url, 'character', character.id);
|
||||
downloadButton.hide();
|
||||
checkMark.show();
|
||||
});
|
||||
|
||||
checkMark.toggle(isInstalled);
|
||||
|
||||
listElement.append(characterElement);
|
||||
}
|
||||
|
||||
callGenericPopup(listElement, POPUP_TYPE.TEXT, '', { okButton: 'Close', wide: true, large: true, allowVerticalScrolling: true, allowHorizontalScrolling: false });
|
||||
}
|
||||
|
||||
//#############################//
|
||||
// API Calls //
|
||||
//#############################//
|
||||
@ -397,4 +433,8 @@ jQuery(async () => {
|
||||
|
||||
windowHtml.find('#assets_filters').hide();
|
||||
$('#extensions_settings').append(windowHtml);
|
||||
|
||||
eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => {
|
||||
openCharacterBrowser(forceDefault);
|
||||
});
|
||||
});
|
||||
|
@ -105,3 +105,55 @@
|
||||
transform: rotate(1turn);
|
||||
}
|
||||
}
|
||||
|
||||
.characterAssetList {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
|
||||
.characterAsset {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
gap: 10px;
|
||||
border: 1px solid var(--SmartThemeBorderColor);
|
||||
background-color: var(--black30a);
|
||||
border-radius: 10px;
|
||||
width: 17%;
|
||||
min-width: 150px;
|
||||
margin: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.characterAssetName {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.characterAssetImage {
|
||||
aspect-ratio: 3/4;
|
||||
max-height: 140px;
|
||||
object-fit: cover;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.characterAssetDescription {
|
||||
font-size: 0.75em;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 4;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.characterAssetButtons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 5px;
|
||||
align-items: center;
|
||||
}
|
||||
|
@ -1629,6 +1629,10 @@ select option:not(:checked) {
|
||||
max-width: 4em;
|
||||
}
|
||||
|
||||
#persona-management-block .paginationjs-nav {
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
input[type=search]::-webkit-search-cancel-button {
|
||||
-webkit-appearance: none;
|
||||
height: 1em;
|
||||
@ -4001,6 +4005,10 @@ body:not(.movingUI) .drawer-content.maximized {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.onboarding span.menu_button {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.onboarding>h3 {
|
||||
align-self: center;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user