[Refactor/TMP5] Refactor UI components and connect to backend APIs. (VR(Overlay))

This commit is contained in:
Sakamoto Shiina
2025-10-22 17:34:57 +09:00
parent e9287318c3
commit d3ef567ef2
3 changed files with 59 additions and 49 deletions

View File

@@ -298,31 +298,31 @@ export const { atomInstance: Atom_IsOpenedMicWordFilterList, useHook: useStore_I
// VR
export const { atomInstance: Atom_OverlaySmallLogSettings, useHook: useStore_OverlaySmallLogSettings } = createAtomWithHook({
x_pos: 0.0,
y_pos: 0.0,
z_pos: 0.0,
x_rotation: 0.0,
y_rotation: 0.0,
z_rotation: 0.0,
display_duration: 5,
fadeout_duration: 2,
tracker: "HMD",
}, "OverlaySmallLogSettings");
export const { atomInstance: Atom_IsEnabledOverlaySmallLog, useHook: useStore_IsEnabledOverlaySmallLog } = createAtomWithHook(false, "IsEnabledOverlaySmallLog");
export const { atomInstance: Atom_OverlayLargeLogSettings, useHook: useStore_OverlayLargeLogSettings } = createAtomWithHook({
x_pos: 0.0,
y_pos: 0.0,
z_pos: 0.0,
x_rotation: 0.0,
y_rotation: 0.0,
z_rotation: 0.0,
display_duration: 5,
fadeout_duration: 2,
tracker: "HMD",
}, "OverlayLargeLogSettings");
export const { atomInstance: Atom_IsEnabledOverlayLargeLog, useHook: useStore_IsEnabledOverlayLargeLog } = createAtomWithHook(false, "IsEnabledOverlayLargeLog");
export const { atomInstance: Atom_OverlayShowOnlyTranslatedMessages, useHook: useStore_OverlayShowOnlyTranslatedMessages } = createAtomWithHook(false, "OverlayShowOnlyTranslatedMessages");
// export const { atomInstance: Atom_OverlaySmallLogSettings, useHook: useStore_OverlaySmallLogSettings } = createAtomWithHook({
// x_pos: 0.0,
// y_pos: 0.0,
// z_pos: 0.0,
// x_rotation: 0.0,
// y_rotation: 0.0,
// z_rotation: 0.0,
// display_duration: 5,
// fadeout_duration: 2,
// tracker: "HMD",
// }, "OverlaySmallLogSettings");
// export const { atomInstance: Atom_IsEnabledOverlaySmallLog, useHook: useStore_IsEnabledOverlaySmallLog } = createAtomWithHook(false, "IsEnabledOverlaySmallLog");
// export const { atomInstance: Atom_OverlayLargeLogSettings, useHook: useStore_OverlayLargeLogSettings } = createAtomWithHook({
// x_pos: 0.0,
// y_pos: 0.0,
// z_pos: 0.0,
// x_rotation: 0.0,
// y_rotation: 0.0,
// z_rotation: 0.0,
// display_duration: 5,
// fadeout_duration: 2,
// tracker: "HMD",
// }, "OverlayLargeLogSettings");
// export const { atomInstance: Atom_IsEnabledOverlayLargeLog, useHook: useStore_IsEnabledOverlayLargeLog } = createAtomWithHook(false, "IsEnabledOverlayLargeLog");
// export const { atomInstance: Atom_OverlayShowOnlyTranslatedMessages, useHook: useStore_OverlayShowOnlyTranslatedMessages } = createAtomWithHook(false, "OverlayShowOnlyTranslatedMessages");
// Others
// export const { atomInstance: Atom_EnableAutoClearMessageInputBox, useHook: useStore_EnableAutoClearMessageInputBox } = createAtomWithHook(true, "EnableAutoClearMessageInputBox");

View File

@@ -3,9 +3,13 @@ import { createAtomWithHook } from "@store";
import {
ctranslate2_weight_type_status,
whisper_weight_type_status,
ui_configs,
} from "@ui_configs";
import { useSettingsLogics } from "./useSettingsLogics";
import {
useSettingsLogics,
useConfigFunctions,
} from "./useSettingsLogics";
export const SETTINGS_ARRAY = [
@@ -378,6 +382,14 @@ export const SETTINGS_ARRAY = [
logics_template_id: "toggle_enable_disable",
base_endpoint_name: "overlay_small_log",
},
{
Category: "Vr",
Base_Name: "OverlaySmallLogSettings",
default_value: ui_configs.overlay_small_log_default_settings,
ui_template_id: "object",
logics_template_id: "get_set",
base_endpoint_name: "overlay_small_log_settings",
},
{
Category: "Vr",
Base_Name: "IsEnabledOverlayLargeLog",
@@ -386,18 +398,10 @@ export const SETTINGS_ARRAY = [
logics_template_id: "toggle_enable_disable",
base_endpoint_name: "overlay_large_log",
},
{
Category: "Vr",
Base_Name: "OverlaySmallLogSettings",
default_value: {},
ui_template_id: "object",
logics_template_id: "get_set",
base_endpoint_name: "overlay_small_log_settings",
},
{
Category: "Vr",
Base_Name: "OverlayLargeLogSettings",
default_value: {},
default_value: ui_configs.overlay_large_log_default_settings,
ui_template_id: "object",
logics_template_id: "get_set",
base_endpoint_name: "overlay_large_log_settings",
@@ -501,16 +505,6 @@ export const SETTINGS_ARRAY = [
base_endpoint_name: "convert_message_to_hiragana",
},
// Hotkeys
// {
// Category: "Hotkeys",
// Base_Name: "SendMessageHotkey",
// default_value: "",
// ui_template_id: "input",
// logics_template_id: "get_set",
// base_endpoint_name: "send_message_hotkey",
// },
// AdvancedSettings
{
Category: "AdvancedSettings",
@@ -561,7 +555,7 @@ for (const setting_data of SETTINGS_ARRAY) {
createAtomWithHook(setting_data.default_value, setting_data.Base_Name);
}
const buildCategoryApiFromSettings = (settings, settingsArray, Category) => {
const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFunctions = {}) => {
const api = {};
const filtered = settingsArray.filter((s) => s.Category === Category);
@@ -598,14 +592,14 @@ const buildCategoryApiFromSettings = (settings, settingsArray, Category) => {
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
}
}
return api;
return { ...api, ...extraFunctions };
};
const createCategoryHook = (Category) => {
return () => {
const { settings } = useSettingsLogics(SETTINGS_ARRAY, Category);
const autoApi = buildCategoryApiFromSettings(settings, SETTINGS_ARRAY, Category);
const extraFunctions = useConfigFunctions(Category);
const autoApi = buildCategoryApiFromSettings(settings, SETTINGS_ARRAY, Category, extraFunctions);
return { ...autoApi };
};
};

View File

@@ -185,3 +185,19 @@ export const useSettingsLogics = (settingsArray, Category) => {
return { settings: result };
};
export const useConfigFunctions = (Category) => {
const { asyncStdoutToPython } = useStdoutToPython();
switch (Category) {
case "Vr":
return {
sendTextToOverlay: (text) => {
asyncStdoutToPython("/run/send_text_overlay", text);
},
};
default:
return {};
}
};