10#include "absl/strings/ascii.h"
11#include "absl/strings/match.h"
12#include "absl/strings/str_cat.h"
13#include "absl/strings/str_format.h"
33#include "imgui/imgui.h"
34#include "imgui/misc/cpp/imgui_stdlib.h"
35#include "nlohmann/json.hpp"
58std::string FormatHexList(
const std::vector<uint16_t>& values) {
60 result.reserve(values.size() * 6);
61 for (
size_t i = 0; i < values.size(); ++i) {
62 const uint16_t value = values[i];
63 std::string token = value <= 0xFF ? absl::StrFormat(
"0x%02X", value)
64 : absl::StrFormat(
"0x%04X", value);
65 if (!result.empty()) {
74 std::vector<uint16_t> values;
75 for (uint16_t tile = 0xB0; tile <= 0xBE; ++tile) {
76 values.push_back(tile);
82 return {0xB7, 0xB8, 0xB9, 0xBA};
86 return {0xD0, 0xD1, 0xD2, 0xD3};
97bool IsLocalEndpoint(
const std::string& base_url) {
98 if (base_url.empty()) {
101 std::string lower = absl::AsciiStrToLower(base_url);
102 return absl::StrContains(lower,
"localhost") ||
103 absl::StrContains(lower,
"127.0.0.1") ||
104 absl::StrContains(lower,
"::1") ||
105 absl::StrContains(lower,
"0.0.0.0") ||
106 absl::StrContains(lower,
"192.168.") || absl::StartsWith(lower,
"10.");
109bool IsTailscaleEndpoint(
const std::string& base_url) {
110 if (base_url.empty()) {
113 std::string lower = absl::AsciiStrToLower(base_url);
114 return absl::StrContains(lower,
".ts.net") ||
115 absl::StrContains(lower,
"100.64.");
119 std::vector<std::string> tags;
120 if (IsLocalEndpoint(host.
base_url)) {
121 tags.push_back(
"local");
123 if (IsTailscaleEndpoint(host.
base_url)) {
124 tags.push_back(
"tailscale");
126 if (absl::StartsWith(absl::AsciiStrToLower(host.
base_url),
"https://")) {
127 tags.push_back(
"https");
128 }
else if (absl::StartsWith(absl::AsciiStrToLower(host.
base_url),
131 !IsTailscaleEndpoint(host.
base_url)) {
132 tags.push_back(
"http");
135 tags.push_back(
"vision");
138 tags.push_back(
"tools");
141 tags.push_back(
"stream");
146 std::string result =
"[";
147 for (
size_t i = 0; i < tags.size(); ++i) {
149 if (i + 1 < tags.size()) {
160 if (path.empty() || path.front() !=
'~') {
164 if (home_dir.empty() || home_dir ==
".") {
167 if (path.size() == 1) {
168 return home_dir.string();
170 if (path[1] ==
'/' || path[1] ==
'\\') {
171 return (home_dir / path.substr(2)).string();
173 return (home_dir / path.substr(1)).string();
176bool AddUniquePath(std::vector<std::string>* paths,
const std::string& path) {
177 if (!paths || path.empty()) {
181 auto it = std::find(paths->begin(), paths->end(), expanded);
182 if (it != paths->end()) {
185 paths->push_back(expanded);
193 const auto summarize = [](
const std::vector<uint16_t>& configured,
194 const std::vector<uint16_t>& standard) {
195 const bool uses_standard_values =
196 configured.empty() || configured == standard;
197 return std::pair<std::string, bool>(
198 FormatHexList(configured.empty() ? standard : configured),
199 uses_standard_values);
202 return {summarize(overlay.
track_tiles, DefaultTrackTiles()),
222 return absl::OkStatus();
227 ImGui::TextDisabled(tr(
"Settings not available"));
234 ImGuiTreeNodeFlags_DefaultOpen)) {
242 if (ImGui::CollapsingHeader(
ICON_MD_FOLDER " Project Configuration")) {
264 " Workspace Layout")) {
271 if (ImGui::CollapsingHeader(
ICON_MD_TUNE " Editor Behavior")) {
310 ImGui::TextDisabled(tr(
"Feature Flags configuration"));
318 if (ImGui::TreeNode(
ICON_MD_MAP " Overworld Flags")) {
341 ImGui::TextDisabled(tr(
"No active project."));
355 const char* roles[] = {
"base",
"dev",
"patched",
"release"};
357 if (ImGui::Combo(tr(
"Role"), &role_index, roles, IM_ARRAYSIZE(roles))) {
362 const char* policies[] = {
"allow",
"warn",
"block"};
364 if (ImGui::Combo(tr(
"Write Policy"), &policy_index, policies,
365 IM_ARRAYSIZE(policies))) {
372 if (ImGui::InputText(tr(
"Expected Hash"), &expected_hash)) {
377 static std::string cached_rom_hash;
378 static std::string cached_rom_path;
384 ImGui::Text(tr(
"Current ROM Hash: %s"), cached_rom_hash.empty()
386 : cached_rom_hash.c_str());
387 if (ImGui::Button(tr(
"Use Current ROM Hash"))) {
392 ImGui::TextDisabled(tr(
"Current ROM Hash: (no ROM loaded)"));
401 if (ImGui::InputText(tr(
"Output Folder"), &output_folder)) {
408 if (ImGui::InputText(tr(
"Git Repository"), &git_repo)) {
419 if (ImGui::InputText(tr(
"Build Target (ROM)"), &build_target)) {
426 if (ImGui::InputText(tr(
"Symbols File"), &symbols_file)) {
432 ImGui::Text(tr(
"%s ASM / Hack Manifest"),
ICON_MD_CODE);
434 ImGui::TextWrapped(tr(
435 "Optional: load a hack manifest JSON (generated by an ASM project) to "
436 "annotate room tags, show feature flags, and surface which ROM regions "
437 "are owned by ASM vs safe to edit in yaze."));
440 if (ImGui::InputText(tr(
"Hack Manifest File"), &manifest_file)) {
448 ImGui::TextDisabled(manifest_loaded ?
"(loaded)" :
"(not loaded)");
449 if (ImGui::Button(tr(
"Reload Manifest"))) {
453 if (manifest_loaded) {
456 ImGui::Text(tr(
"Manifest Version: %d"),
461 if (!pipeline.dev_rom.empty()) {
462 ImGui::Text(tr(
"Dev ROM: %s"), pipeline.dev_rom.c_str());
464 if (!pipeline.patched_rom.empty()) {
465 ImGui::Text(tr(
"Patched ROM: %s"), pipeline.patched_rom.c_str());
467 if (!pipeline.build_script.empty()) {
468 ImGui::Text(tr(
"Build Script: %s"), pipeline.build_script.c_str());
472 if (msg_layout.first_expanded_id != 0 || msg_layout.last_expanded_id != 0) {
473 ImGui::Text(tr(
"Expanded Messages: 0x%03X-0x%03X (%d)"),
474 msg_layout.first_expanded_id, msg_layout.last_expanded_id,
475 msg_layout.expanded_count);
478 if (ImGui::TreeNode(
ICON_MD_FLAG " Hack Feature Flags")) {
480 ImGui::BulletText(
"%s = %d (%s)", flag.name.c_str(), flag.value,
481 flag.enabled ?
"enabled" :
"disabled");
482 if (!flag.source.empty()) {
484 ImGui::TextDisabled(
"%s", flag.source.c_str());
490 if (ImGui::TreeNode(
ICON_MD_LABEL " Room Tags (Dispatch)")) {
492 ImGui::BulletText(tr(
"0x%02X: %s"), tag.tag_id, tag.name.c_str());
493 if (!tag.enabled && !tag.feature_flag.empty()) {
495 ImGui::TextDisabled(tr(
"(disabled by %s)"), tag.feature_flag.c_str());
497 if (!tag.purpose.empty() && ImGui::IsItemHovered()) {
498 ImGui::SetTooltip(
"%s", tag.purpose.c_str());
510 if (ImGui::InputText(tr(
"Backup Folder"), &backup_folder)) {
523 {.min = 0, .max = 10000})) {
536 {.min = 1, .max = 3650})) {
545 tr(
"Read-only here. Edit collision and object IDs in Minecart Tracks > "
548 constexpr std::array<const char*, 5> kLabels = {
549 "Track Tiles",
"Stop Tiles",
"Switch Tiles",
"Track Object IDs",
550 "Minecart Sprite IDs"};
553 if (ImGui::BeginTable(
"DungeonOverlaySummary", 2,
554 ImGuiTableFlags_SizingStretchProp)) {
555 ImGui::TableSetupColumn(
"Field", ImGuiTableColumnFlags_WidthFixed, 132.0f);
556 ImGui::TableSetupColumn(
"Value", ImGuiTableColumnFlags_WidthStretch);
557 for (
size_t i = 0; i < summary.size(); ++i) {
558 ImGui::TableNextRow();
559 ImGui::TableSetColumnIndex(0);
560 ImGui::TextDisabled(
"%s", tr(kLabels[i]));
561 ImGui::TableSetColumnIndex(1);
562 ImGui::TextWrapped(
"%s", summary[i].first.c_str());
563 ImGui::TextDisabled(
"%s", summary[i].second
564 ? tr(
"Standard values")
565 : tr(
"Custom project values"));
571 const bool custom_objects_enabled =
573 const bool can_open = custom_objects_enabled &&
575 ImGui::BeginDisabled(!can_open);
579 ImGui::EndDisabled();
581 if (!custom_objects_enabled) {
583 tr(
"Enable Custom Dungeon Objects in General Settings first."));
585 ImGui::TextDisabled(tr(
"Minecart Tracks navigation is unavailable."));
601 static int selected_root_index = -1;
602 static std::string new_root_path;
608 ImGui::TextDisabled(tr(
"No project roots configured."));
611 if (ImGui::BeginChild(
"ProjectRootsList", ImVec2(0, 140),
true)) {
612 for (
size_t i = 0; i < roots.size(); ++i) {
613 const bool is_default = roots[i] == prefs.default_project_root;
617 label +=
" (default)";
619 if (ImGui::Selectable(label.c_str(),
620 selected_root_index ==
static_cast<int>(i))) {
621 selected_root_index =
static_cast<int>(i);
627 const bool has_selection =
628 selected_root_index >= 0 &&
629 selected_root_index < static_cast<int>(roots.size());
631 if (ImGui::Button(tr(
"Set Default"))) {
632 prefs.default_project_root = roots[selected_root_index];
637 const std::string removed = roots[selected_root_index];
638 roots.erase(roots.begin() + selected_root_index);
639 if (prefs.default_project_root == removed) {
640 prefs.default_project_root = roots.empty() ?
"" : roots.front();
642 selected_root_index = roots.empty()
644 : std::min(selected_root_index,
645 static_cast<int>(roots.size() - 1));
654 ImGui::InputTextWithHint(
"##project_root_add",
"Add folder path...",
657 const std::string trimmed =
658 std::string(absl::StripAsciiWhitespace(new_root_path));
659 if (!trimmed.empty()) {
660 if (AddUniquePath(&roots, trimmed) &&
661 prefs.default_project_root.empty()) {
662 prefs.default_project_root = trimmed;
670 if (!folder.empty()) {
671 if (AddUniquePath(&roots, folder) && prefs.default_project_root.empty()) {
672 prefs.default_project_root = folder;
685 if (AddUniquePath(&roots, docs_dir->string()) &&
686 prefs.default_project_root.empty()) {
687 prefs.default_project_root = docs_dir->string();
696 if (icloud_dir.ok()) {
697 if (AddUniquePath(&roots, icloud_dir->string())) {
698 prefs.default_project_root = icloud_dir->string();
704 tr(
"iCloud projects live in Documents/Yaze/iCloud on this Mac."));
710 bool use_icloud_sync = prefs.use_icloud_sync;
711 if (ImGui::Checkbox(tr(
"Use iCloud sync (Documents)"), &use_icloud_sync)) {
712 prefs.use_icloud_sync = use_icloud_sync;
713 if (use_icloud_sync) {
716 if (icloud_dir.ok()) {
717 AddUniquePath(&roots, icloud_dir->string());
718 prefs.default_project_root = icloud_dir->string();
724 bool use_files_app = prefs.use_files_app;
725 if (ImGui::Checkbox(tr(
"Prefer Files app on iOS"), &use_files_app)) {
726 prefs.use_files_app = use_files_app;
733 auto theme = theme_manager.GetCurrentTheme();
734 theme.ApplyDensityPreset(preset);
737 theme_manager.ReapplyTheme(theme);
746 const std::string current = theme_manager.GetCurrentThemeName();
747 const auto& current_theme = theme_manager.GetCurrentTheme();
749 ImGui::SetNextItemWidth(-1.0f);
750 if (ImGui::BeginCombo(
"##AppearanceTheme", current.c_str())) {
751 for (
const auto& theme_name : theme_manager.GetAvailableThemes()) {
752 const bool is_current = theme_name == current;
753 if (ImGui::Selectable(theme_name.c_str(), is_current)) {
754 if (theme_manager.IsPreviewActive()) {
755 theme_manager.EndPreview();
757 theme_manager.ApplyTheme(theme_name);
760 ImGui::SetItemDefaultFocus();
766 const ImGuiColorEditFlags swatch_flags = ImGuiColorEditFlags_NoTooltip |
767 ImGuiColorEditFlags_NoDragDrop |
768 ImGuiColorEditFlags_NoPicker;
769 const float swatch_size = std::max(12.0f, ImGui::GetFrameHeight() * 0.62f);
770 ImGui::TextDisabled(
"%s", tr(
"Palette"));
771 ImGui::SameLine(0.0f, 6.0f);
772 ImGui::PushID(
"CurrentThemeSwatches");
773 ImGui::ColorButton(
"Primary",
775 swatch_flags, ImVec2(swatch_size, swatch_size));
776 ImGui::SameLine(0.0f, 3.0f);
777 ImGui::ColorButton(
"Surface",
779 swatch_flags, ImVec2(swatch_size, swatch_size));
780 ImGui::SameLine(0.0f, 3.0f);
782 swatch_flags, ImVec2(swatch_size, swatch_size));
784 if (!current_theme.description.empty()) {
785 ImGui::PushTextWrapPos(0.0f);
786 ImGui::TextDisabled(
"%s", current_theme.description.c_str());
787 ImGui::PopTextWrapPos();
791 theme_manager.RefreshAvailableThemes();
793 if (ImGui::IsItemHovered()) {
794 ImGui::SetTooltip(tr(
"Re-scan theme folders for new or changed themes"));
798 ImGui::SeparatorText(tr(
"Density"));
801 auto preset = theme_manager.GetCurrentTheme().density_preset;
802 int density =
static_cast<int>(preset);
803 const char* density_labels[] = {tr(
"Compact"), tr(
"Normal"),
805 ImGui::SetNextItemWidth(-1.0f);
806 if (ImGui::Combo(
"##DisplayDensity", &density, density_labels,
807 IM_ARRAYSIZE(density_labels))) {
811 "%s", density == 0 ? tr(
"Tighter controls and more visible content")
812 : density == 2 ? tr(
"Larger controls with more breathing room")
813 : tr(
"Balanced spacing for everyday editing"));
817 ImGui::SeparatorText(tr(
"Motion"));
821 if (ImGui::Checkbox(tr(
"Reduced Motion"), &reduced_motion)) {
822 prefs.reduced_motion = reduced_motion;
824 prefs.reduced_motion,
828 if (ImGui::IsItemHovered()) {
830 tr(
"Disable panel/editor transition animations for a calmer editing "
834 int switch_profile = std::clamp(prefs.switch_motion_profile, 0, 2);
835 const char* switch_profile_labels[] = {
"Snappy",
"Standard",
"Relaxed"};
836 if (ImGui::Combo(tr(
"Switch Motion Profile"), &switch_profile,
837 switch_profile_labels,
838 IM_ARRAYSIZE(switch_profile_labels))) {
839 prefs.switch_motion_profile = switch_profile;
841 prefs.reduced_motion,
845 if (ImGui::IsItemHovered()) {
847 tr(
"Controls editor/workspace switch timing and easing for panel fades "
848 "and sidebar slides."));
863 ImGui::Text(tr(
"Global Font Scale"));
865 if (ImGui::SliderFloat(
"##global_font_scale", &scale, 0.5f, 2.0f,
"%.2f")) {
867 ImGui::GetIO().FontGlobalScale = scale;
877 if (ImGui::Checkbox(tr(
"Show Status Bar"), &show_status_bar)) {
885 if (ImGui::IsItemHovered()) {
887 tr(
"Display ROM, session, cursor, and zoom info at bottom of window"));
896 if (ImGui::Checkbox(tr(
"Keep Emulator Running in Background"),
901 if (ImGui::IsItemHovered()) {
902 ImGui::SetTooltip(tr(
903 "When off (default), hiding emulator panels pauses the SNES tick and "
904 "audio. Music playback still drives its own frames."));
908 if (ImGui::Checkbox(tr(
"Show Experimental Editors"), &show_experimental)) {
912 if (ImGui::IsItemHovered()) {
914 tr(
"Enable Screen, Music, and Agent editors marked in development."));
920 ImGui::TextDisabled(tr(
"UserSettings unavailable."));
929 if (prefs.named_layouts.empty()) {
931 tr(
"No saved layouts yet. Open the Layout Designer to capture one."));
935 std::vector<std::string> names;
936 names.reserve(prefs.named_layouts.size());
937 for (
const auto& entry : prefs.named_layouts) {
938 names.push_back(entry.first);
940 std::sort(names.begin(), names.end());
942 const std::string&
active = prefs.last_applied_layout_name;
943 const char* preview =
944 active.empty() ?
"(select a layout…)" :
active.c_str();
946 if (ImGui::BeginCombo(tr(
"Active Layout"), preview)) {
947 for (
const auto& name : names) {
948 const bool is_selected = (name ==
active);
949 if (ImGui::Selectable(name.c_str(), is_selected)) {
958 ImGui::SetItemDefaultFocus();
965 ImGui::BeginDisabled(
active.empty() ||
966 prefs.named_layouts.count(
active) == 0);
967 if (ImGui::SmallButton(tr(
"Re-apply"))) {
970 ImGui::EndDisabled();
971 if (ImGui::IsItemHovered()) {
973 tr(
"Re-apply the active layout (useful after closing or rearranging "
974 "panels manually)."));
990 "Open failed: \"layout.designer\" panel is not registered.";
998 if (ImGui::IsItemHovered()) {
1000 tr(
"Open the Layout Designer panel to author or capture a workspace "
1025 if (it == prefs.named_layouts.end()) {
1027 absl::StrCat(
"Apply failed: \"", name,
"\" not found.");
1032 nlohmann::json parsed;
1034 parsed = nlohmann::json::parse(it->second);
1035 }
catch (
const nlohmann::json::parse_error& e) {
1037 absl::StrCat(
"Apply failed: invalid JSON (", e.what(),
").");
1043 if (!tree_or.ok()) {
1045 absl::StrCat(
"Apply failed: ", tree_or.status().message());
1050 std::string validation_error;
1051 if (!tree_or->Validate(&validation_error)) {
1053 absl::StrCat(
"Apply failed: invalid layout (", validation_error,
").");
1059 if (manager ==
nullptr) {
1065 if (dockspace_id == 0) {
1071 const absl::Status apply_status =
1073 if (!apply_status.ok()) {
1075 absl::StrCat(
"Apply failed: ", apply_status.message());
1080 prefs.last_applied_layout_name = name;
1093 if (ImGui::Checkbox(tr(
"Enable Auto-Save"),
1101 if (ImGui::SliderInt(tr(
"Interval (sec)"), &interval, 60, 600)) {
1106 if (ImGui::Checkbox(tr(
"Backup Before Save"),
1126 const char* editors[] = {
"None",
"Overworld",
"Dungeon",
"Graphics"};
1128 editors, IM_ARRAYSIZE(editors))) {
1135 if (ImGui::Checkbox(tr(
"Use HMagic sprite names (expanded)"),
1163 if (ImGui::SliderInt(tr(
"Cache Size (MB)"),
1168 if (ImGui::SliderInt(tr(
"Undo History"),
1175 ImGui::Text(tr(
"Current FPS: %.1f"), ImGui::GetIO().Framerate);
1176 ImGui::Text(tr(
"Frame Time: %.3f ms"), 1000.0f / ImGui::GetIO().Framerate);
1185 static int selected_host_index = -1;
1187 auto draw_key_row = [&](
const char* label, std::string* key,
1188 const char* env_var,
const char* id) {
1190 ImGui::Text(
"%s", label);
1191 const ImVec2 button_size = ImGui::CalcTextSize(
ICON_MD_SYNC " Env");
1192 float env_button_width =
1193 button_size.x + ImGui::GetStyle().FramePadding.x * 2.0f;
1194 float input_width = ImGui::GetContentRegionAvail().x - env_button_width -
1195 ImGui::GetStyle().ItemSpacing.x;
1196 bool stack = input_width < 160.0f;
1197 ImGui::SetNextItemWidth(stack ? -1.0f : input_width);
1198 if (ImGui::InputTextWithHint(
"##key",
"API key...", key,
1199 ImGuiInputTextFlags_Password)) {
1206 const char* env_key = std::getenv(env_var);
1218 draw_key_row(
"OpenAI", &prefs.openai_api_key,
"OPENAI_API_KEY",
"openai_key");
1219 draw_key_row(
"Anthropic", &prefs.anthropic_api_key,
"ANTHROPIC_API_KEY",
1221 draw_key_row(
"Google (Gemini)", &prefs.gemini_api_key,
"GEMINI_API_KEY",
1226 ImGui::Text(tr(
"%s Provider Defaults (legacy)"),
ICON_MD_CLOUD);
1229 const char* providers[] = {
"Ollama (Local)",
"Gemini (Cloud)",
1231 if (ImGui::Combo(
"##Provider", &prefs.ai_provider, providers,
1232 IM_ARRAYSIZE(providers))) {
1240 const char* active_preview =
"None";
1241 const char* remote_preview =
"None";
1242 for (
const auto& host : hosts) {
1243 if (!prefs.active_ai_host_id.empty() &&
1244 host.id == prefs.active_ai_host_id) {
1245 active_preview = host.label.c_str();
1247 if (!prefs.remote_build_host_id.empty() &&
1248 host.id == prefs.remote_build_host_id) {
1249 remote_preview = host.label.c_str();
1253 if (ImGui::BeginCombo(tr(
"Active Host"), active_preview)) {
1254 for (
size_t i = 0; i < hosts.size(); ++i) {
1255 const bool is_selected = (!prefs.active_ai_host_id.empty() &&
1256 hosts[i].id == prefs.active_ai_host_id);
1257 if (ImGui::Selectable(hosts[i].label.c_str(), is_selected)) {
1258 prefs.active_ai_host_id = hosts[i].id;
1259 if (prefs.remote_build_host_id.empty()) {
1260 prefs.remote_build_host_id = hosts[i].id;
1265 ImGui::SetItemDefaultFocus();
1271 if (ImGui::BeginCombo(tr(
"Remote Build Host"), remote_preview)) {
1272 for (
size_t i = 0; i < hosts.size(); ++i) {
1273 const bool is_selected = (!prefs.remote_build_host_id.empty() &&
1274 hosts[i].id == prefs.remote_build_host_id);
1275 if (ImGui::Selectable(hosts[i].label.c_str(), is_selected)) {
1276 prefs.remote_build_host_id = hosts[i].id;
1280 ImGui::SetItemDefaultFocus();
1290 if (selected_host_index >=
static_cast<int>(hosts.size())) {
1291 selected_host_index = hosts.empty() ? -1 : 0;
1293 if (selected_host_index < 0 && !hosts.empty()) {
1294 for (
size_t i = 0; i < hosts.size(); ++i) {
1295 if (!prefs.active_ai_host_id.empty() &&
1296 hosts[i].id == prefs.active_ai_host_id) {
1297 selected_host_index =
static_cast<int>(i);
1301 if (selected_host_index < 0) {
1302 selected_host_index = 0;
1306 ImGui::BeginChild(
"##ai_host_list", ImVec2(0, 150),
true);
1307 for (
size_t i = 0; i < hosts.size(); ++i) {
1308 const bool is_selected =
static_cast<int>(i) == selected_host_index;
1309 std::string label = hosts[i].label;
1310 if (hosts[i].
id == prefs.active_ai_host_id) {
1311 label +=
" (active)";
1313 if (hosts[i].
id == prefs.remote_build_host_id) {
1314 label +=
" (build)";
1316 if (ImGui::Selectable(label.c_str(), is_selected)) {
1317 selected_host_index =
static_cast<int>(i);
1319 std::string tags = BuildHostTagString(hosts[i]);
1320 if (!tags.empty()) {
1322 ImGui::TextDisabled(
"%s", tags.c_str());
1328 if (host.id.empty()) {
1329 host.id = absl::StrFormat(
"host-%zu", hosts.size() + 1);
1331 hosts.push_back(host);
1332 selected_host_index =
static_cast<int>(hosts.size() - 1);
1333 if (prefs.active_ai_host_id.empty()) {
1334 prefs.active_ai_host_id = host.id;
1336 if (prefs.remote_build_host_id.empty()) {
1337 prefs.remote_build_host_id = host.id;
1344 host.
label =
"New Host";
1345 host.
base_url =
"http://localhost:1234";
1350 if (ImGui::Button(
ICON_MD_DELETE " Remove") && selected_host_index >= 0 &&
1351 selected_host_index <
static_cast<int>(hosts.size())) {
1352 const std::string removed_id = hosts[selected_host_index].id;
1353 hosts.erase(hosts.begin() + selected_host_index);
1354 if (prefs.active_ai_host_id == removed_id) {
1355 prefs.active_ai_host_id = hosts.empty() ?
"" : hosts.front().id;
1357 if (prefs.remote_build_host_id == removed_id) {
1358 prefs.remote_build_host_id = prefs.active_ai_host_id;
1360 selected_host_index =
1363 : std::min(selected_host_index,
static_cast<int>(hosts.size() - 1));
1368 if (ImGui::Button(tr(
"Add LM Studio"))) {
1370 host.
label =
"LM Studio (local)";
1371 host.
base_url =
"http://localhost:1234";
1378 if (ImGui::Button(tr(
"Add AFS Bridge"))) {
1380 host.
label =
"halext AFS Bridge";
1381 host.
base_url =
"https://halext.org";
1388 if (ImGui::Button(tr(
"Add Ollama"))) {
1390 host.
label =
"Ollama (local)";
1391 host.
base_url =
"http://localhost:11434";
1398 static std::string tailscale_host;
1399 ImGui::InputTextWithHint(
"##tailscale_host",
"host.ts.net:1234",
1402 if (ImGui::Button(tr(
"Add Tailscale Host"))) {
1403 std::string trimmed =
1404 std::string(absl::StripAsciiWhitespace(tailscale_host));
1405 if (!trimmed.empty()) {
1407 host.
label =
"Tailscale Host";
1408 if (absl::StrContains(trimmed,
"://")) {
1411 host.
base_url =
"http://" + trimmed;
1418 tailscale_host.clear();
1422 if (selected_host_index >= 0 &&
1423 selected_host_index <
static_cast<int>(hosts.size())) {
1424 auto& host = hosts[
static_cast<size_t>(selected_host_index)];
1426 ImGui::Text(tr(
"Host Details"));
1428 if (ImGui::InputText(tr(
"Label"), &host.label)) {
1431 if (ImGui::InputText(tr(
"Base URL"), &host.base_url)) {
1435 const char* api_types[] = {
"openai",
"ollama",
"gemini",
1436 "anthropic",
"lmstudio",
"grpc"};
1438 for (
int i = 0; i < IM_ARRAYSIZE(api_types); ++i) {
1439 if (host.api_type == api_types[i]) {
1444 if (ImGui::Combo(tr(
"API Type"), &api_index, api_types,
1445 IM_ARRAYSIZE(api_types))) {
1446 host.api_type = api_types[api_index];
1450 if (ImGui::InputText(tr(
"API Key"), &host.api_key,
1451 ImGuiInputTextFlags_Password)) {
1454 if (ImGui::InputText(tr(
"Keychain ID"), &host.credential_id)) {
1458 if (ImGui::SmallButton(tr(
"Use Host ID"))) {
1459 host.credential_id = host.id;
1462 if (!host.credential_id.empty() && host.api_key.empty()) {
1463 ImGui::TextDisabled(tr(
"Keychain lookup enabled (leave API key empty)."));
1466 if (ImGui::Checkbox(tr(
"Supports Vision"), &host.supports_vision)) {
1470 if (ImGui::Checkbox(tr(
"Supports Tools"), &host.supports_tools)) {
1474 if (ImGui::Checkbox(tr(
"Supports Streaming"), &host.supports_streaming)) {
1477 if (ImGui::Checkbox(tr(
"Allow Insecure HTTP"), &host.allow_insecure)) {
1486 auto& model_paths = prefs.ai_model_paths;
1487 static int selected_model_path = -1;
1488 static std::string new_model_path;
1490 if (model_paths.empty()) {
1491 ImGui::TextDisabled(tr(
"No model paths configured."));
1494 if (ImGui::BeginChild(
"ModelPathsList", ImVec2(0, 120),
true)) {
1495 for (
size_t i = 0; i < model_paths.size(); ++i) {
1498 if (ImGui::Selectable(label.c_str(),
1499 selected_model_path ==
static_cast<int>(i))) {
1500 selected_model_path =
static_cast<int>(i);
1506 const bool has_model_selection =
1507 selected_model_path >= 0 &&
1508 selected_model_path < static_cast<int>(model_paths.size());
1509 if (has_model_selection) {
1511 model_paths.erase(model_paths.begin() + selected_model_path);
1512 selected_model_path =
1515 : std::min(selected_model_path,
1516 static_cast<int>(model_paths.size() - 1));
1522 ImGui::InputTextWithHint(
"##model_path_add",
"Add folder path...",
1525 const std::string trimmed =
1526 std::string(absl::StripAsciiWhitespace(new_model_path));
1527 if (!trimmed.empty() && AddUniquePath(&model_paths, trimmed)) {
1529 new_model_path.clear();
1535 if (!folder.empty() && AddUniquePath(&model_paths, folder)) {
1545 if (!home_dir.empty() && home_dir !=
".") {
1546 if (AddUniquePath(&model_paths, (home_dir /
"models").
string())) {
1552 if (ImGui::Button(tr(
"Add ~/.lmstudio/models"))) {
1553 if (!home_dir.empty() && home_dir !=
".") {
1554 if (AddUniquePath(&model_paths,
1555 (home_dir /
".lmstudio" /
"models").
string())) {
1561 if (ImGui::Button(tr(
"Add ~/.ollama/models"))) {
1562 if (!home_dir.empty() && home_dir !=
".") {
1563 if (AddUniquePath(&model_paths,
1564 (home_dir /
".ollama" /
"models").
string())) {
1574 if (ImGui::SliderFloat(tr(
"Temperature"),
1578 ImGui::TextDisabled(tr(
"Higher = more creative"));
1589 if (ImGui::Checkbox(tr(
"Proactive Suggestions"),
1594 if (ImGui::Checkbox(tr(
"Auto-Learn Preferences"),
1599 if (ImGui::Checkbox(tr(
"Enable Vision"),
1608 const char* log_levels[] = {
"Debug",
"Info",
"Warning",
"Error",
"Fatal"};
1610 log_levels, IM_ARRAYSIZE(log_levels))) {
1618 ImGuiTreeNodeFlags_DefaultOpen)) {
1619 ImGui::InputTextWithHint(
"##shortcut_filter",
"Filter shortcuts...",
1621 if (ImGui::IsItemHovered()) {
1622 ImGui::SetTooltip(tr(
"Filter by action name or key combo"));
1626 if (ImGui::TreeNode(
"Global Shortcuts")) {
1630 if (ImGui::TreeNode(
"Editor Shortcuts")) {
1634 if (ImGui::TreeNode(
"Panel Shortcuts")) {
1638 ImGui::TextDisabled(
1639 tr(
"Tip: Use Cmd/Opt labels on macOS or Ctrl/Alt on Windows/Linux. "
1640 "Function keys and symbols (/, -) are supported."));
1649 std::string haystack = absl::AsciiStrToLower(text);
1651 return absl::StrContains(haystack, needle);
1656 ImGui::TextDisabled(tr(
"Not available"));
1662 if (shortcuts.empty()) {
1663 ImGui::TextDisabled(tr(
"No global shortcuts registered."));
1667 static std::unordered_map<std::string, std::string> editing;
1669 bool has_match =
false;
1670 for (
const auto& sc : shortcuts) {
1671 std::string label = sc.name;
1677 auto it = editing.find(sc.name);
1678 if (it == editing.end()) {
1683 current = u->second;
1685 editing[sc.name] = current;
1688 ImGui::PushID(sc.name.c_str());
1689 ImGui::Text(
"%s", sc.name.c_str());
1691 ImGui::SetNextItemWidth(180);
1692 std::string& value = editing[sc.name];
1693 if (ImGui::InputText(
"##global", &value,
1694 ImGuiInputTextFlags_EnterReturnsTrue |
1695 ImGuiInputTextFlags_AutoSelectAll)) {
1697 if (!parsed.empty() || value.empty()) {
1700 if (value.empty()) {
1711 ImGui::TextDisabled(tr(
"No shortcuts match the current filter."));
1717 ImGui::TextDisabled(tr(
"Not available"));
1723 std::map<std::string, std::vector<Shortcut>> grouped;
1724 static std::unordered_map<std::string, std::string> editing;
1726 for (
const auto& sc : shortcuts) {
1727 auto pos = sc.name.find(
".");
1729 pos != std::string::npos ? sc.name.substr(0, pos) :
"general";
1730 grouped[group].push_back(sc);
1732 bool has_match =
false;
1733 for (
const auto& [group, list] : grouped) {
1734 std::vector<Shortcut> filtered;
1735 filtered.reserve(list.size());
1736 for (
const auto& sc : list) {
1739 filtered.push_back(sc);
1742 if (filtered.empty()) {
1746 if (ImGui::TreeNode(group.c_str())) {
1747 for (
const auto& sc : filtered) {
1748 ImGui::PushID(sc.name.c_str());
1749 ImGui::Text(
"%s", sc.name.c_str());
1751 ImGui::SetNextItemWidth(180);
1752 std::string& value = editing[sc.name];
1753 if (value.empty()) {
1761 if (ImGui::InputText(
"##editor", &value,
1762 ImGuiInputTextFlags_EnterReturnsTrue |
1763 ImGuiInputTextFlags_AutoSelectAll)) {
1765 if (!parsed.empty() || value.empty()) {
1767 if (value.empty()) {
1781 ImGui::TextDisabled(tr(
"No shortcuts match the current filter."));
1787 ImGui::TextDisabled(tr(
"Registry not available"));
1794 bool has_match =
false;
1795 for (
const auto& category : categories) {
1797 std::vector<
decltype(cards)::value_type> filtered_cards;
1798 filtered_cards.reserve(cards.size());
1799 for (
const auto& card : cards) {
1802 filtered_cards.push_back(card);
1805 if (filtered_cards.empty()) {
1809 if (ImGui::TreeNode(category.c_str())) {
1811 for (
const auto& card : filtered_cards) {
1812 ImGui::PushID(card.card_id.c_str());
1814 ImGui::Text(
"%s %s", card.icon.c_str(), card.display_name.c_str());
1816 std::string current_shortcut;
1819 current_shortcut = it->second;
1820 }
else if (!card.shortcut_hint.empty()) {
1821 current_shortcut = card.shortcut_hint;
1823 current_shortcut =
"None";
1827 std::string display_shortcut = current_shortcut;
1829 if (!parsed.empty()) {
1834 ImGui::SetNextItemWidth(120);
1835 ImGui::SetKeyboardFocusHere();
1838 ImGuiInputTextFlags_EnterReturnsTrue)) {
1855 if (ImGui::Button(display_shortcut.c_str(), ImVec2(120, 0))) {
1861 if (ImGui::IsItemHovered()) {
1862 ImGui::SetTooltip(tr(
"Click to edit shortcut"));
1873 ImGui::TextDisabled(tr(
"No shortcuts match the current filter."));
1882 if (patches_dir_status.ok()) {
1897 ImGui::TextDisabled(tr(
"No patches loaded"));
1898 ImGui::TextDisabled(tr(
"Place .asm patches in assets/patches/"));
1900 if (ImGui::Button(tr(
"Browse for Patches Folder..."))) {
1909 ImGui::Text(tr(
"Loaded: %d patches (%d enabled)"), total_count,
1916 ImGuiTabBarFlags_FittingPolicyScroll)) {
1918 if (ImGui::BeginTabItem(folder.c_str())) {
1921 ImGui::EndTabItem();
1934 ImGui::TextDisabled(tr(
"Select a patch to view details"));
1943#ifdef YAZE_WITH_Z3DK
1961 for (
const auto& range :
z3dk.prohibited_memory_ranges) {
1963 {.start = range.start, .end = range.end, .reason = range.reason});
1971 if (!
z3dk.rom_path.empty()) {
1982 LOG_ERROR(
"Settings",
"Failed to apply patches: %s", status.message());
1984 LOG_INFO(
"Settings",
"Applied %d patches successfully", enabled_count);
1987 LOG_WARN(
"Settings",
"No ROM loaded");
1990 if (ImGui::IsItemHovered()) {
1991 ImGui::SetTooltip(tr(
"Apply all enabled patches to the loaded ROM"));
1998 LOG_ERROR(
"Settings",
"Failed to save patches: %s", status.message());
2011 if (patches.empty()) {
2012 ImGui::TextDisabled(tr(
"No patches in this folder"));
2017 float available_height = std::min(200.0f, patches.size() * 25.0f + 10.0f);
2018 if (ImGui::BeginChild(
"##PatchList", ImVec2(0, available_height),
true)) {
2019 for (
auto* patch : patches) {
2020 ImGui::PushID(patch->filename().c_str());
2022 bool enabled = patch->enabled();
2023 if (ImGui::Checkbox(
"##Enabled", &enabled)) {
2024 patch->set_enabled(enabled);
2031 if (ImGui::Selectable(patch->name().c_str(), is_selected)) {
2064 if (!params.empty()) {
2069 for (
auto& param : params) {
2081 switch (param->
type) {
2085 int value = param->
value;
2086 const char* format = param->
use_decimal ?
"%d" :
"$%X";
2089 ImGui::SetNextItemWidth(100);
2090 if (ImGui::InputInt(
"##Value", &value, 1, 16)) {
2104 if (ImGui::Checkbox(param->
display_name.c_str(), &checked)) {
2112 for (
size_t i = 0; i < param->
choices.size(); ++i) {
2113 bool selected = (param->
value ==
static_cast<int>(i));
2114 if (ImGui::RadioButton(param->
choices[i].c_str(), selected)) {
2115 param->
value =
static_cast<int>(i);
2123 for (
size_t i = 0; i < param->
choices.size(); ++i) {
2124 if (param->
choices[i].empty() || param->
choices[i] ==
"_EMPTY") {
2127 bool bit_set = (param->
value & (1 << i)) != 0;
2128 if (ImGui::Checkbox(param->
choices[i].c_str(), &bit_set)) {
2130 param->
value |= (1 << i);
2132 param->
value &= ~(1 << i);
2142 ImGui::SetNextItemWidth(150);
2143 if (ImGui::InputInt(tr(
"Item ID"), ¶m->
value)) {
2144 param->
value = std::clamp(param->
value, 0, 255);
const std::string & version() const
std::vector< PatchParameter > & mutable_parameters()
const std::string & author() const
const std::string & description() const
const std::string & name() const
const std::vector< FeatureFlag > & feature_flags() const
const MessageLayout & message_layout() const
const std::vector< RoomTagEntry > & room_tags() const
Get all room tags.
const std::string & hack_name() const
bool loaded() const
Check if the manifest has been loaded.
int manifest_version() const
const BuildPipeline & build_pipeline() const
absl::Status ApplyEnabledPatches(Rom *rom)
Apply all enabled patches to a ROM.
absl::Status SaveAllPatches()
Save all patches to their files.
const std::vector< std::string > & folders() const
Get list of patch folder names.
int GetEnabledPatchCount() const
Get count of enabled patches.
std::vector< AsmPatch * > GetPatchesInFolder(const std::string &folder)
Get all patches in a specific folder.
const std::vector< std::unique_ptr< AsmPatch > > & patches() const
Get all loaded patches.
absl::Status LoadPatches(const std::string &patches_dir)
Load all patches from a directory structure.
virtual void SetDependencies(const EditorDependencies &deps)
Manages ImGui DockBuilder layouts for each editor type.
absl::Status ApplyDockTree(const layout_designer::DockTree &tree, ImGuiID dockspace_id)
Apply a DockTree to the given dockspace.
ImGuiID GetMainDockspaceId() const
Get the cached main dockspace ID.
void DrawPerformanceSettings()
std::string editing_card_id_
void SetStatusBar(StatusBar *bar)
void DrawProjectSettings()
void DrawPatchList(const std::string &folder)
void DrawFilesystemSettings()
void SetWindowManager(WorkspaceWindowManager *registry)
void DrawAppearanceSettings()
char shortcut_edit_buffer_[64]
ShortcutManager * shortcut_manager_
void SetDependencies(const EditorDependencies &deps) override
void DrawEditorShortcuts()
void DrawGlobalShortcuts()
void ApplyNamedLayoutToDockspace(const std::string &name)
bool MatchesShortcutFilter(const std::string &text) const
void DrawParameterWidget(core::PatchParameter *param)
void DrawEditorBehavior()
static DungeonOverlaySummary BuildDungeonOverlaySummary(const project::DungeonOverlaySettings &overlay)
core::AsmPatch * selected_patch_
void DrawGeneralSettings()
void DrawWorkspaceSettings()
core::PatchManager patch_manager_
OpenMinecartTracksCallback open_minecart_tracks_callback_
project::YazeProject * project_
void SetShortcutManager(ShortcutManager *manager)
void SetUserSettings(UserSettings *settings)
std::string selected_folder_
UserSettings * user_settings_
void DrawKeyboardShortcuts()
bool is_editing_shortcut_
std::array< std::pair< std::string, bool >, 5 > DungeonOverlaySummary
std::string workspace_status_message_
std::string shortcut_filter_
void SetProject(project::YazeProject *project)
void ApplyDisplayDensity(gui::DensityPreset preset)
absl::Status RequestOpenMinecartTracks()
WorkspaceWindowManager * window_manager_
bool workspace_status_is_error_
void DrawPanelShortcuts()
void DrawAIAgentSettings()
std::string project_status_message_
std::vector< Shortcut > GetShortcutsByScope(Shortcut::Scope scope) const
bool UpdateShortcutKeys(const std::string &name, const std::vector< ImGuiKey > &keys)
void SetEnabled(bool enabled)
Enable or disable the status bar.
std::vector< WindowDescriptor > GetWindowsInCategory(size_t session_id, const std::string &category) const
void SetWindowPinned(size_t session_id, const std::string &base_window_id, bool pinned)
bool IsWindowOpen(size_t session_id, const std::string &base_window_id) const
bool OpenWindow(size_t session_id, const std::string &base_window_id)
std::vector< std::string > GetAllCategories(size_t session_id) const
static MotionProfile ClampMotionProfile(int raw_profile)
void SetMotionPreferences(bool reduced_motion, MotionProfile profile)
static ThemeManager & Get()
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path. Uses global feature fl...
#define ICON_MD_FOLDER_OPEN
#define ICON_MD_FOLDER_SPECIAL
#define ICON_MD_TEXT_FIELDS
#define ICON_MD_VIDEOGAME_ASSET
#define ICON_MD_EXTENSION
#define ICON_MD_DASHBOARD_CUSTOMIZE
#define ICON_MD_PSYCHOLOGY
#define ICON_MD_HORIZONTAL_RULE
#define ICON_MD_DASHBOARD
#define ICON_MD_SMART_TOY
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
constexpr char kProviderOpenAi[]
constexpr char kProviderOllama[]
constexpr char kProviderLmStudio[]
LayoutManager * layout_manager()
Get the shared LayoutManager instance.
std::vector< uint16_t > DefaultTrackTiles()
std::string ExpandLeadingTilde(const std::string &path)
bool AddUniquePath(std::vector< std::string > *paths, const std::string &path)
std::vector< uint16_t > DefaultSwitchTiles()
std::vector< uint16_t > DefaultStopTiles()
std::string BuildHostTagString(const UserSettings::Preferences::AiHost &host)
std::vector< uint16_t > DefaultMinecartSpriteIds()
std::vector< uint16_t > DefaultTrackObjectIds()
absl::StatusOr< DockTree > DockTreeFromJson(const nlohmann::json &j)
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
bool DrawProperty(const char *label, bool *value, const PropertyOptions &opts)
ImVec4 ConvertColorToImVec4(const Color &color)
bool BeginThemedTabBar(const char *id, ImGuiTabBarFlags flags)
A stylized tab bar with "Mission Control" branding.
DensityPreset
Typography and spacing density presets.
bool FontPicker(const char *label, int *index)
std::string ComputeRomHash(const uint8_t *data, size_t size)
void SetPreferHmagicSpriteNames(bool prefer)
void SetActiveFontIndex(int index)
bool kEnableCustomObjects
Represents a configurable parameter within an ASM patch.
std::vector< std::string > choices
bool warn_branch_outside_bank
std::vector< Z3dkMemoryRange > prohibited_memory_ranges
bool capture_nocash_symbols
std::vector< std::string > include_paths
std::vector< std::pair< std::string, std::string > > defines
std::string std_defines_path
bool warn_unauthorized_hook
std::string std_includes_path
std::string hooks_rom_path
Unified dependency container for all editor types.
project::YazeProject * project
ShortcutManager * shortcut_manager
UserSettings * user_settings
WorkspaceWindowManager * window_manager
std::vector< std::string > project_root_paths
std::unordered_map< std::string, std::string > panel_shortcuts
bool show_experimental_editors
std::unordered_map< std::string, std::string > named_layouts
std::unordered_map< std::string, std::string > editor_shortcuts
std::vector< AiHost > ai_hosts
std::unordered_map< std::string, std::string > global_shortcuts
bool emulator_keep_running_in_background
bool prefer_hmagic_sprite_names
Dungeon overlay configuration (per-project).
std::vector< uint16_t > track_object_ids
std::vector< uint16_t > minecart_sprite_ids
std::vector< uint16_t > track_stop_tiles
std::vector< uint16_t > track_tiles
std::vector< uint16_t > track_switch_tiles
int backup_keep_daily_days
int backup_retention_count
std::string rom_backup_folder
std::string git_repository
core::HackManifest hack_manifest
void ReloadHackManifest()
std::string hack_manifest_file
WorkspaceSettings workspace_settings
std::string output_folder
DungeonOverlaySettings dungeon_overlay
std::string symbols_filename
Z3dkSettings z3dk_settings