9#include <unordered_set>
12#include "absl/strings/ascii.h"
13#include "absl/strings/match.h"
14#include "absl/strings/str_format.h"
26#include "imgui/imgui.h"
27#include "imgui/misc/cpp/imgui_stdlib.h"
62 std::string trimmed = token;
63 if (absl::StartsWithIgnoreCase(trimmed,
"0x")) {
64 trimmed = trimmed.substr(2);
66 if (trimmed.empty()) {
70 unsigned long value = std::strtoul(trimmed.c_str(), &end, 16);
71 if (end ==
nullptr || *end !=
'\0') {
74 if (value > 0xFFFFu) {
77 *out =
static_cast<uint16_t
>(value);
81bool ParseHexList(
const std::string& input, std::vector<uint16_t>* out,
94 std::string normalized = input;
95 for (
char& c : normalized) {
96 if (c ==
',' || c ==
';') {
101 std::stringstream ss(normalized);
103 std::unordered_set<uint16_t> seen;
104 while (ss >> token) {
105 auto dash = token.find(
'-');
106 if (dash != std::string::npos) {
107 std::string left = token.substr(0, dash);
108 std::string right = token.substr(dash + 1);
113 *error = absl::StrFormat(
"Invalid range: %s", token);
119 *error = absl::StrFormat(
"Range end before start: %s", token);
123 for (uint16_t value = start; value <= end; ++value) {
124 if (seen.insert(value).second) {
125 out->push_back(value);
127 if (value == 0xFFFF) {
135 *error = absl::StrFormat(
"Invalid hex value: %s", token);
139 if (seen.insert(value).second) {
140 out->push_back(value);
147std::string FormatHexList(
const std::vector<uint16_t>& values) {
149 result.reserve(values.size() * 6);
150 for (
size_t i = 0; i < values.size(); ++i) {
151 const uint16_t value = values[i];
152 std::string token = value <= 0xFF ? absl::StrFormat(
"0x%02X", value)
153 : absl::StrFormat(
"0x%04X", value);
154 if (!result.empty()) {
157 result.append(token);
163 std::vector<uint16_t> values;
164 for (uint16_t tile = 0xB0; tile <= 0xBE; ++tile) {
165 values.push_back(tile);
171 return {0xB7, 0xB8, 0xB9, 0xBA};
175 return {0xD0, 0xD1, 0xD2, 0xD3};
186bool IsLocalEndpoint(
const std::string& base_url) {
187 if (base_url.empty()) {
190 std::string lower = absl::AsciiStrToLower(base_url);
191 return absl::StrContains(lower,
"localhost") ||
192 absl::StrContains(lower,
"127.0.0.1") ||
193 absl::StrContains(lower,
"::1") ||
194 absl::StrContains(lower,
"0.0.0.0") ||
195 absl::StrContains(lower,
"192.168.") || absl::StartsWith(lower,
"10.");
198bool IsTailscaleEndpoint(
const std::string& base_url) {
199 if (base_url.empty()) {
202 std::string lower = absl::AsciiStrToLower(base_url);
203 return absl::StrContains(lower,
".ts.net") ||
204 absl::StrContains(lower,
"100.64.");
208 std::vector<std::string> tags;
209 if (IsLocalEndpoint(host.
base_url)) {
210 tags.push_back(
"local");
212 if (IsTailscaleEndpoint(host.
base_url)) {
213 tags.push_back(
"tailscale");
215 if (absl::StartsWith(absl::AsciiStrToLower(host.
base_url),
"https://")) {
216 tags.push_back(
"https");
217 }
else if (absl::StartsWith(absl::AsciiStrToLower(host.
base_url),
220 !IsTailscaleEndpoint(host.
base_url)) {
221 tags.push_back(
"http");
224 tags.push_back(
"vision");
227 tags.push_back(
"tools");
230 tags.push_back(
"stream");
235 std::string result =
"[";
236 for (
size_t i = 0; i < tags.size(); ++i) {
238 if (i + 1 < tags.size()) {
246bool AddUniquePath(std::vector<std::string>* paths,
const std::string& path) {
247 if (!paths || path.empty()) {
250 auto it = std::find(paths->begin(), paths->end(), path);
251 if (it != paths->end()) {
254 paths->push_back(path);
262 ImGui::TextDisabled(
"Settings not available");
269 ImGuiTreeNodeFlags_DefaultOpen)) {
277 if (ImGui::CollapsingHeader(
ICON_MD_FOLDER " Project Configuration")) {
298 if (ImGui::CollapsingHeader(
ICON_MD_TUNE " Editor Behavior")) {
337 ImGui::TextDisabled(
"Feature Flags configuration");
345 if (ImGui::TreeNode(
ICON_MD_MAP " Overworld Flags")) {
368 ImGui::TextDisabled(
"No active project.");
382 const char* roles[] = {
"base",
"dev",
"patched",
"release"};
384 if (ImGui::Combo(
"Role", &role_index, roles, IM_ARRAYSIZE(roles))) {
389 const char* policies[] = {
"allow",
"warn",
"block"};
391 if (ImGui::Combo(
"Write Policy", &policy_index, policies,
392 IM_ARRAYSIZE(policies))) {
399 if (ImGui::InputText(
"Expected Hash", &expected_hash)) {
404 static std::string cached_rom_hash;
405 static std::string cached_rom_path;
411 ImGui::Text(
"Current ROM Hash: %s", cached_rom_hash.empty()
413 : cached_rom_hash.c_str());
414 if (ImGui::Button(
"Use Current ROM Hash")) {
419 ImGui::TextDisabled(
"Current ROM Hash: (no ROM loaded)");
428 if (ImGui::InputText(
"Output Folder", &output_folder)) {
435 if (ImGui::InputText(
"Git Repository", &git_repo)) {
446 if (ImGui::InputText(
"Build Target (ROM)", &build_target)) {
453 if (ImGui::InputText(
"Symbols File", &symbols_file)) {
462 "Optional: load a hack manifest JSON (generated by an ASM project) to "
463 "annotate room tags, show feature flags, and surface which ROM regions "
464 "are owned by ASM vs safe to edit in yaze.");
467 if (ImGui::InputText(
"Hack Manifest File", &manifest_file)) {
475 ImGui::TextDisabled(manifest_loaded ?
"(loaded)" :
"(not loaded)");
476 if (ImGui::Button(
"Reload Manifest")) {
480 if (manifest_loaded) {
483 ImGui::Text(
"Manifest Version: %d",
488 if (!pipeline.dev_rom.empty()) {
489 ImGui::Text(
"Dev ROM: %s", pipeline.dev_rom.c_str());
491 if (!pipeline.patched_rom.empty()) {
492 ImGui::Text(
"Patched ROM: %s", pipeline.patched_rom.c_str());
494 if (!pipeline.build_script.empty()) {
495 ImGui::Text(
"Build Script: %s", pipeline.build_script.c_str());
499 if (msg_layout.first_expanded_id != 0 || msg_layout.last_expanded_id != 0) {
500 ImGui::Text(
"Expanded Messages: 0x%03X-0x%03X (%d)",
501 msg_layout.first_expanded_id, msg_layout.last_expanded_id,
502 msg_layout.expanded_count);
505 if (ImGui::TreeNode(
ICON_MD_FLAG " Hack Feature Flags")) {
507 ImGui::BulletText(
"%s = %d (%s)", flag.name.c_str(), flag.value,
508 flag.enabled ?
"enabled" :
"disabled");
509 if (!flag.source.empty()) {
511 ImGui::TextDisabled(
"%s", flag.source.c_str());
517 if (ImGui::TreeNode(
ICON_MD_LABEL " Room Tags (Dispatch)")) {
519 ImGui::BulletText(
"0x%02X: %s", tag.tag_id, tag.name.c_str());
520 if (!tag.enabled && !tag.feature_flag.empty()) {
522 ImGui::TextDisabled(
"(disabled by %s)", tag.feature_flag.c_str());
524 if (!tag.purpose.empty() && ImGui::IsItemHovered()) {
525 ImGui::SetTooltip(
"%s", tag.purpose.c_str());
537 if (ImGui::InputText(
"Backup Folder", &backup_folder)) {
543 if (ImGui::Checkbox(
"Backup Before Save", &backup_on_save)) {
549 if (ImGui::InputInt(
"Retention Count", &retention)) {
551 std::max(0, retention);
556 if (ImGui::Checkbox(
"Keep Daily Snapshots", &keep_daily)) {
562 if (ImGui::InputInt(
"Keep Daily Days", &keep_days)) {
564 std::max(1, keep_days);
572 "Configure collision/object IDs used by minecart overlays and audits. "
573 "Hex values, ranges allowed (e.g. B0-BE).");
575 static std::string overlay_project_path;
576 static HexListEditorState track_tiles_state;
577 static HexListEditorState stop_tiles_state;
578 static HexListEditorState switch_tiles_state;
579 static HexListEditorState track_object_state;
580 static HexListEditorState minecart_sprite_state;
584 track_tiles_state.text =
586 stop_tiles_state.text =
588 switch_tiles_state.text =
590 track_object_state.text =
592 minecart_sprite_state.text =
594 track_tiles_state.error.clear();
595 stop_tiles_state.error.clear();
596 switch_tiles_state.error.clear();
597 track_object_state.error.clear();
598 minecart_sprite_state.error.clear();
601 auto draw_hex_list = [&](
const char* label,
const char* hint,
602 HexListEditorState& state,
603 const std::vector<uint16_t>& defaults,
604 std::vector<uint16_t>* target) {
610 ImGui::PushItemWidth(-180.0f);
611 if (ImGui::InputTextWithHint(label, hint, &state.text)) {
614 ImGui::PopItemWidth();
615 if (ImGui::IsItemDeactivatedAfterEdit()) {
620 if (ImGui::SmallButton(absl::StrFormat(
"Apply##%s", label).c_str())) {
624 if (ImGui::SmallButton(absl::StrFormat(
"Defaults##%s", label).c_str())) {
625 state.text = FormatHexList(defaults);
628 if (ImGui::IsItemHovered()) {
629 ImGui::SetTooltip(
"Reset to defaults");
632 if (ImGui::SmallButton(absl::StrFormat(
"Clear##%s", label).c_str())) {
636 if (ImGui::IsItemHovered()) {
637 ImGui::SetTooltip(
"Clear list (empty uses defaults)");
640 const bool uses_defaults = target->empty();
641 const std::vector<uint16_t>& effective_values =
642 uses_defaults ? defaults : *target;
645 if (ImGui::IsItemHovered()) {
646 ImGui::BeginTooltip();
647 ImGui::Text(
"Effective: %s", FormatHexList(effective_values).c_str());
649 ImGui::TextDisabled(
"Using defaults (list is empty)");
655 std::vector<uint16_t> parsed;
657 if (ParseHexList(state.text, &parsed, &error)) {
661 state.text = FormatHexList(parsed);
667 if (!state.error.empty()) {
668 ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.4f, 1.0f),
"%s",
669 state.error.c_str());
673 draw_hex_list(
"Track Tiles",
"0xB0-0xBE", track_tiles_state,
675 draw_hex_list(
"Stop Tiles",
"0xB7, 0xB8, 0xB9, 0xBA", stop_tiles_state,
678 draw_hex_list(
"Switch Tiles",
"0xD0-0xD3", switch_tiles_state,
679 DefaultSwitchTiles(),
681 draw_hex_list(
"Track Object IDs",
"0x31", track_object_state,
682 DefaultTrackObjectIds(),
684 draw_hex_list(
"Minecart Sprite IDs",
"0xA3", minecart_sprite_state,
685 DefaultMinecartSpriteIds(),
696 static int selected_root_index = -1;
697 static std::string new_root_path;
703 ImGui::TextDisabled(
"No project roots configured.");
706 if (ImGui::BeginChild(
"ProjectRootsList", ImVec2(0, 140),
true)) {
707 for (
size_t i = 0; i < roots.size(); ++i) {
708 const bool is_default = roots[i] == prefs.default_project_root;
712 label +=
" (default)";
714 if (ImGui::Selectable(label.c_str(),
715 selected_root_index ==
static_cast<int>(i))) {
716 selected_root_index =
static_cast<int>(i);
722 const bool has_selection =
723 selected_root_index >= 0 &&
724 selected_root_index < static_cast<int>(roots.size());
726 if (ImGui::Button(
"Set Default")) {
727 prefs.default_project_root = roots[selected_root_index];
732 const std::string removed = roots[selected_root_index];
733 roots.erase(roots.begin() + selected_root_index);
734 if (prefs.default_project_root == removed) {
735 prefs.default_project_root = roots.empty() ?
"" : roots.front();
737 selected_root_index = roots.empty()
739 : std::min(selected_root_index,
740 static_cast<int>(roots.size() - 1));
749 ImGui::InputTextWithHint(
"##project_root_add",
"Add folder path...",
752 const std::string trimmed =
753 std::string(absl::StripAsciiWhitespace(new_root_path));
754 if (!trimmed.empty()) {
755 if (AddUniquePath(&roots, trimmed) &&
756 prefs.default_project_root.empty()) {
757 prefs.default_project_root = trimmed;
765 if (!folder.empty()) {
766 if (AddUniquePath(&roots, folder) && prefs.default_project_root.empty()) {
767 prefs.default_project_root = folder;
780 if (AddUniquePath(&roots, docs_dir->string()) &&
781 prefs.default_project_root.empty()) {
782 prefs.default_project_root = docs_dir->string();
791 if (icloud_dir.ok()) {
792 if (AddUniquePath(&roots, icloud_dir->string())) {
793 prefs.default_project_root = icloud_dir->string();
799 "iCloud projects live in Documents/Yaze/iCloud on this Mac.");
805 bool use_icloud_sync = prefs.use_icloud_sync;
806 if (ImGui::Checkbox(
"Use iCloud sync (Documents)", &use_icloud_sync)) {
807 prefs.use_icloud_sync = use_icloud_sync;
808 if (use_icloud_sync) {
811 if (icloud_dir.ok()) {
812 AddUniquePath(&roots, icloud_dir->string());
813 prefs.default_project_root = icloud_dir->string();
819 bool use_files_app = prefs.use_files_app;
820 if (ImGui::Checkbox(
"Prefer Files app on iOS", &use_files_app)) {
821 prefs.use_files_app = use_files_app;
833 const auto& current = theme_manager.GetCurrentThemeName();
834 const auto& current_theme = theme_manager.GetCurrentTheme();
836 ImGui::Text(
"Current Theme:");
841 ImDrawList* draw_list = ImGui::GetWindowDrawList();
842 ImVec2 cursor = ImGui::GetCursorScreenPos();
843 const float swatch_size = 12.0f;
844 const float spacing = 2.0f;
846 auto draw_swatch = [&](
const gui::Color& color,
float offset_x) {
847 ImVec2 p_min(cursor.x + offset_x, cursor.y);
848 ImVec2 p_max(p_min.x + swatch_size, p_min.y + swatch_size);
851 draw_list->AddRectFilled(p_min, p_max, col);
854 ImGui::ColorConvertFloat4ToU32(ImVec4(0.5f, 0.5f, 0.5f, 0.6f)));
857 draw_swatch(current_theme.primary, 0.0f);
858 draw_swatch(current_theme.surface, swatch_size + spacing);
859 draw_swatch(current_theme.accent, 2.0f * (swatch_size + spacing));
863 ImVec2(3.0f * swatch_size + 2.0f * spacing + 4.0f, swatch_size));
867 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
"%s", current.c_str());
872 ImGui::Text(
"Available Themes:");
874 bool any_theme_hovered =
false;
875 if (ImGui::BeginChild(
"ThemeList", ImVec2(0, 200),
true)) {
876 for (
const auto& theme_name : theme_manager.GetAvailableThemes()) {
877 ImGui::PushID(theme_name.c_str());
878 bool is_current = (theme_name == current);
881 const gui::Theme* theme_data = theme_manager.GetTheme(theme_name);
883 ImDrawList* draw_list = ImGui::GetWindowDrawList();
884 ImVec2 cursor = ImGui::GetCursorScreenPos();
885 const float swatch_size = 10.0f;
886 const float swatch_spacing = 2.0f;
887 const float total_swatch_width =
888 3.0f * swatch_size + 2.0f * swatch_spacing + 6.0f;
890 auto draw_small_swatch = [&](
const gui::Color& color,
float offset_x) {
891 ImVec2 p_min(cursor.x + offset_x, cursor.y + 2.0f);
892 ImVec2 p_max(p_min.x + swatch_size, p_min.y + swatch_size);
895 draw_list->AddRectFilled(p_min, p_max, col);
898 ImGui::ColorConvertFloat4ToU32(ImVec4(0.4f, 0.4f, 0.4f, 0.5f)));
901 draw_small_swatch(theme_data->
primary, 0.0f);
902 draw_small_swatch(theme_data->
surface, swatch_size + swatch_spacing);
903 draw_small_swatch(theme_data->
accent,
904 2.0f * (swatch_size + swatch_spacing));
907 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + total_swatch_width);
911 std::string label = is_current
913 : std::string(
" ") + theme_name;
915 if (ImGui::Selectable(label.c_str(), is_current)) {
919 if (theme_manager.IsPreviewActive()) {
920 theme_manager.EndPreview();
922 theme_manager.LoadTheme(theme_name);
926 if (ImGui::IsItemHovered()) {
927 any_theme_hovered =
true;
928 theme_manager.StartPreview(theme_name);
937 if (!any_theme_hovered && theme_manager.IsPreviewActive()) {
938 theme_manager.EndPreview();
943 theme_manager.RefreshAvailableThemes();
945 if (ImGui::IsItemHovered()) {
946 ImGui::SetTooltip(
"Re-scan theme directories for new or changed themes");
950 ImGui::SeparatorText(
"Display Density");
953 auto preset = theme_manager.GetCurrentTheme().density_preset;
954 int density =
static_cast<int>(preset);
955 bool changed =
false;
956 changed |= ImGui::RadioButton(
"Compact (0.75x)", &density, 0);
958 changed |= ImGui::RadioButton(
"Normal (1.0x)", &density, 1);
960 changed |= ImGui::RadioButton(
"Comfortable (1.25x)", &density, 2);
964 auto theme = theme_manager.GetCurrentTheme();
965 theme.ApplyDensityPreset(new_preset);
966 theme_manager.ApplyTheme(theme);
971 ImGui::SeparatorText(
"Editor/Workspace Motion");
975 if (ImGui::Checkbox(
"Reduced Motion", &reduced_motion)) {
976 prefs.reduced_motion = reduced_motion;
978 prefs.reduced_motion,
982 if (ImGui::IsItemHovered()) {
984 "Disable panel/editor transition animations for a calmer editing "
988 int switch_profile = std::clamp(prefs.switch_motion_profile, 0, 2);
989 const char* switch_profile_labels[] = {
"Snappy",
"Standard",
"Relaxed"};
990 if (ImGui::Combo(
"Switch Motion Profile", &switch_profile,
991 switch_profile_labels,
992 IM_ARRAYSIZE(switch_profile_labels))) {
993 prefs.switch_motion_profile = switch_profile;
995 prefs.reduced_motion,
999 if (ImGui::IsItemHovered()) {
1001 "Controls editor/workspace switch timing and easing for panel fades "
1002 "and sidebar slides.");
1011 ImGui::Text(
"Global Font Scale");
1013 if (ImGui::SliderFloat(
"##global_font_scale", &scale, 0.5f, 2.0f,
"%.2f")) {
1015 ImGui::GetIO().FontGlobalScale = scale;
1025 if (ImGui::Checkbox(
"Show Status Bar", &show_status_bar)) {
1033 if (ImGui::IsItemHovered()) {
1035 "Display ROM, session, cursor, and zoom info at bottom of window");
1046 if (ImGui::Checkbox(
"Enable Auto-Save",
1054 if (ImGui::SliderInt(
"Interval (sec)", &interval, 60, 600)) {
1059 if (ImGui::Checkbox(
"Backup Before Save",
1079 const char* editors[] = {
"None",
"Overworld",
"Dungeon",
"Graphics"};
1081 editors, IM_ARRAYSIZE(editors))) {
1088 if (ImGui::Checkbox(
"Use HMagic sprite names (expanded)",
1116 if (ImGui::SliderInt(
"Cache Size (MB)",
1121 if (ImGui::SliderInt(
"Undo History",
1128 ImGui::Text(
"Current FPS: %.1f", ImGui::GetIO().Framerate);
1129 ImGui::Text(
"Frame Time: %.3f ms", 1000.0f / ImGui::GetIO().Framerate);
1138 static int selected_host_index = -1;
1140 auto draw_key_row = [&](
const char* label, std::string* key,
1141 const char* env_var,
const char* id) {
1143 ImGui::Text(
"%s", label);
1144 const ImVec2 button_size = ImGui::CalcTextSize(
ICON_MD_SYNC " Env");
1145 float env_button_width =
1146 button_size.x + ImGui::GetStyle().FramePadding.x * 2.0f;
1147 float input_width = ImGui::GetContentRegionAvail().x - env_button_width -
1148 ImGui::GetStyle().ItemSpacing.x;
1149 bool stack = input_width < 160.0f;
1150 ImGui::SetNextItemWidth(stack ? -1.0f : input_width);
1151 if (ImGui::InputTextWithHint(
"##key",
"API key...", key,
1152 ImGuiInputTextFlags_Password)) {
1159 const char* env_key = std::getenv(env_var);
1171 draw_key_row(
"OpenAI", &prefs.openai_api_key,
"OPENAI_API_KEY",
"openai_key");
1172 draw_key_row(
"Anthropic", &prefs.anthropic_api_key,
"ANTHROPIC_API_KEY",
1174 draw_key_row(
"Google (Gemini)", &prefs.gemini_api_key,
"GEMINI_API_KEY",
1179 ImGui::Text(
"%s Provider Defaults (legacy)",
ICON_MD_CLOUD);
1182 const char* providers[] = {
"Ollama (Local)",
"Gemini (Cloud)",
1184 if (ImGui::Combo(
"##Provider", &prefs.ai_provider, providers,
1185 IM_ARRAYSIZE(providers))) {
1193 const char* active_preview =
"None";
1194 const char* remote_preview =
"None";
1195 for (
const auto& host : hosts) {
1196 if (!prefs.active_ai_host_id.empty() &&
1197 host.id == prefs.active_ai_host_id) {
1198 active_preview = host.label.c_str();
1200 if (!prefs.remote_build_host_id.empty() &&
1201 host.id == prefs.remote_build_host_id) {
1202 remote_preview = host.label.c_str();
1206 if (ImGui::BeginCombo(
"Active Host", active_preview)) {
1207 for (
size_t i = 0; i < hosts.size(); ++i) {
1208 const bool is_selected = (!prefs.active_ai_host_id.empty() &&
1209 hosts[i].id == prefs.active_ai_host_id);
1210 if (ImGui::Selectable(hosts[i].label.c_str(), is_selected)) {
1211 prefs.active_ai_host_id = hosts[i].id;
1212 if (prefs.remote_build_host_id.empty()) {
1213 prefs.remote_build_host_id = hosts[i].id;
1218 ImGui::SetItemDefaultFocus();
1224 if (ImGui::BeginCombo(
"Remote Build Host", remote_preview)) {
1225 for (
size_t i = 0; i < hosts.size(); ++i) {
1226 const bool is_selected = (!prefs.remote_build_host_id.empty() &&
1227 hosts[i].id == prefs.remote_build_host_id);
1228 if (ImGui::Selectable(hosts[i].label.c_str(), is_selected)) {
1229 prefs.remote_build_host_id = hosts[i].id;
1233 ImGui::SetItemDefaultFocus();
1243 if (selected_host_index >=
static_cast<int>(hosts.size())) {
1244 selected_host_index = hosts.empty() ? -1 : 0;
1246 if (selected_host_index < 0 && !hosts.empty()) {
1247 for (
size_t i = 0; i < hosts.size(); ++i) {
1248 if (!prefs.active_ai_host_id.empty() &&
1249 hosts[i].id == prefs.active_ai_host_id) {
1250 selected_host_index =
static_cast<int>(i);
1254 if (selected_host_index < 0) {
1255 selected_host_index = 0;
1259 ImGui::BeginChild(
"##ai_host_list", ImVec2(0, 150),
true);
1260 for (
size_t i = 0; i < hosts.size(); ++i) {
1261 const bool is_selected =
static_cast<int>(i) == selected_host_index;
1262 std::string label = hosts[i].label;
1263 if (hosts[i].
id == prefs.active_ai_host_id) {
1264 label +=
" (active)";
1266 if (hosts[i].
id == prefs.remote_build_host_id) {
1267 label +=
" (build)";
1269 if (ImGui::Selectable(label.c_str(), is_selected)) {
1270 selected_host_index =
static_cast<int>(i);
1272 std::string tags = BuildHostTagString(hosts[i]);
1273 if (!tags.empty()) {
1275 ImGui::TextDisabled(
"%s", tags.c_str());
1281 if (host.id.empty()) {
1282 host.id = absl::StrFormat(
"host-%zu", hosts.size() + 1);
1284 hosts.push_back(host);
1285 selected_host_index =
static_cast<int>(hosts.size() - 1);
1286 if (prefs.active_ai_host_id.empty()) {
1287 prefs.active_ai_host_id = host.id;
1289 if (prefs.remote_build_host_id.empty()) {
1290 prefs.remote_build_host_id = host.id;
1297 host.
label =
"New Host";
1298 host.
base_url =
"http://localhost:1234";
1303 if (ImGui::Button(
ICON_MD_DELETE " Remove") && selected_host_index >= 0 &&
1304 selected_host_index <
static_cast<int>(hosts.size())) {
1305 const std::string removed_id = hosts[selected_host_index].id;
1306 hosts.erase(hosts.begin() + selected_host_index);
1307 if (prefs.active_ai_host_id == removed_id) {
1308 prefs.active_ai_host_id = hosts.empty() ?
"" : hosts.front().id;
1310 if (prefs.remote_build_host_id == removed_id) {
1311 prefs.remote_build_host_id = prefs.active_ai_host_id;
1313 selected_host_index =
1316 : std::min(selected_host_index,
static_cast<int>(hosts.size() - 1));
1321 if (ImGui::Button(
"Add LM Studio")) {
1323 host.
label =
"LM Studio (local)";
1324 host.
base_url =
"http://localhost:1234";
1331 if (ImGui::Button(
"Add AFS Bridge")) {
1333 host.
label =
"halext AFS Bridge";
1334 host.
base_url =
"https://halext.org";
1341 if (ImGui::Button(
"Add Ollama")) {
1343 host.
label =
"Ollama (local)";
1344 host.
base_url =
"http://localhost:11434";
1351 static std::string tailscale_host;
1352 ImGui::InputTextWithHint(
"##tailscale_host",
"host.ts.net:1234",
1355 if (ImGui::Button(
"Add Tailscale Host")) {
1356 std::string trimmed =
1357 std::string(absl::StripAsciiWhitespace(tailscale_host));
1358 if (!trimmed.empty()) {
1360 host.
label =
"Tailscale Host";
1361 if (absl::StrContains(trimmed,
"://")) {
1364 host.
base_url =
"http://" + trimmed;
1371 tailscale_host.clear();
1375 if (selected_host_index >= 0 &&
1376 selected_host_index <
static_cast<int>(hosts.size())) {
1377 auto& host = hosts[
static_cast<size_t>(selected_host_index)];
1379 ImGui::Text(
"Host Details");
1381 if (ImGui::InputText(
"Label", &host.label)) {
1384 if (ImGui::InputText(
"Base URL", &host.base_url)) {
1388 const char* api_types[] = {
"openai",
"ollama",
"gemini",
1389 "anthropic",
"lmstudio",
"grpc"};
1391 for (
int i = 0; i < IM_ARRAYSIZE(api_types); ++i) {
1392 if (host.api_type == api_types[i]) {
1397 if (ImGui::Combo(
"API Type", &api_index, api_types,
1398 IM_ARRAYSIZE(api_types))) {
1399 host.api_type = api_types[api_index];
1403 if (ImGui::InputText(
"API Key", &host.api_key,
1404 ImGuiInputTextFlags_Password)) {
1407 if (ImGui::InputText(
"Keychain ID", &host.credential_id)) {
1411 if (ImGui::SmallButton(
"Use Host ID")) {
1412 host.credential_id = host.id;
1415 if (!host.credential_id.empty() && host.api_key.empty()) {
1416 ImGui::TextDisabled(
"Keychain lookup enabled (leave API key empty).");
1419 if (ImGui::Checkbox(
"Supports Vision", &host.supports_vision)) {
1423 if (ImGui::Checkbox(
"Supports Tools", &host.supports_tools)) {
1427 if (ImGui::Checkbox(
"Supports Streaming", &host.supports_streaming)) {
1430 if (ImGui::Checkbox(
"Allow Insecure HTTP", &host.allow_insecure)) {
1439 auto& model_paths = prefs.ai_model_paths;
1440 static int selected_model_path = -1;
1441 static std::string new_model_path;
1443 if (model_paths.empty()) {
1444 ImGui::TextDisabled(
"No model paths configured.");
1447 if (ImGui::BeginChild(
"ModelPathsList", ImVec2(0, 120),
true)) {
1448 for (
size_t i = 0; i < model_paths.size(); ++i) {
1451 if (ImGui::Selectable(label.c_str(),
1452 selected_model_path ==
static_cast<int>(i))) {
1453 selected_model_path =
static_cast<int>(i);
1459 const bool has_model_selection =
1460 selected_model_path >= 0 &&
1461 selected_model_path < static_cast<int>(model_paths.size());
1462 if (has_model_selection) {
1464 model_paths.erase(model_paths.begin() + selected_model_path);
1465 selected_model_path =
1468 : std::min(selected_model_path,
1469 static_cast<int>(model_paths.size() - 1));
1475 ImGui::InputTextWithHint(
"##model_path_add",
"Add folder path...",
1478 const std::string trimmed =
1479 std::string(absl::StripAsciiWhitespace(new_model_path));
1480 if (!trimmed.empty() && AddUniquePath(&model_paths, trimmed)) {
1482 new_model_path.clear();
1488 if (!folder.empty() && AddUniquePath(&model_paths, folder)) {
1498 if (!home_dir.empty() && home_dir !=
".") {
1499 if (AddUniquePath(&model_paths, (home_dir /
"models").
string())) {
1505 if (ImGui::Button(
"Add ~/.lmstudio/models")) {
1506 if (!home_dir.empty() && home_dir !=
".") {
1507 if (AddUniquePath(&model_paths,
1508 (home_dir /
".lmstudio" /
"models").
string())) {
1514 if (ImGui::Button(
"Add ~/.ollama/models")) {
1515 if (!home_dir.empty() && home_dir !=
".") {
1516 if (AddUniquePath(&model_paths,
1517 (home_dir /
".ollama" /
"models").
string())) {
1531 ImGui::TextDisabled(
"Higher = more creative");
1542 if (ImGui::Checkbox(
"Proactive Suggestions",
1547 if (ImGui::Checkbox(
"Auto-Learn Preferences",
1552 if (ImGui::Checkbox(
"Enable Vision",
1561 const char* log_levels[] = {
"Debug",
"Info",
"Warning",
"Error",
"Fatal"};
1563 IM_ARRAYSIZE(log_levels))) {
1571 ImGuiTreeNodeFlags_DefaultOpen)) {
1572 ImGui::InputTextWithHint(
"##shortcut_filter",
"Filter shortcuts...",
1574 if (ImGui::IsItemHovered()) {
1575 ImGui::SetTooltip(
"Filter by action name or key combo");
1579 if (ImGui::TreeNode(
"Global Shortcuts")) {
1583 if (ImGui::TreeNode(
"Editor Shortcuts")) {
1587 if (ImGui::TreeNode(
"Panel Shortcuts")) {
1591 ImGui::TextDisabled(
1592 "Tip: Use Cmd/Opt labels on macOS or Ctrl/Alt on Windows/Linux. "
1593 "Function keys and symbols (/, -) are supported.");
1602 std::string haystack = absl::AsciiStrToLower(text);
1604 return absl::StrContains(haystack, needle);
1609 ImGui::TextDisabled(
"Not available");
1615 if (shortcuts.empty()) {
1616 ImGui::TextDisabled(
"No global shortcuts registered.");
1620 static std::unordered_map<std::string, std::string> editing;
1622 bool has_match =
false;
1623 for (
const auto& sc : shortcuts) {
1624 std::string label = sc.name;
1630 auto it = editing.find(sc.name);
1631 if (it == editing.end()) {
1636 current = u->second;
1638 editing[sc.name] = current;
1641 ImGui::PushID(sc.name.c_str());
1642 ImGui::Text(
"%s", sc.name.c_str());
1644 ImGui::SetNextItemWidth(180);
1645 std::string& value = editing[sc.name];
1646 if (ImGui::InputText(
"##global", &value,
1647 ImGuiInputTextFlags_EnterReturnsTrue |
1648 ImGuiInputTextFlags_AutoSelectAll)) {
1650 if (!parsed.empty() || value.empty()) {
1653 if (value.empty()) {
1664 ImGui::TextDisabled(
"No shortcuts match the current filter.");
1670 ImGui::TextDisabled(
"Not available");
1676 std::map<std::string, std::vector<Shortcut>> grouped;
1677 static std::unordered_map<std::string, std::string> editing;
1679 for (
const auto& sc : shortcuts) {
1680 auto pos = sc.name.find(
".");
1682 pos != std::string::npos ? sc.name.substr(0, pos) :
"general";
1683 grouped[group].push_back(sc);
1685 bool has_match =
false;
1686 for (
const auto& [group, list] : grouped) {
1687 std::vector<Shortcut> filtered;
1688 filtered.reserve(list.size());
1689 for (
const auto& sc : list) {
1692 filtered.push_back(sc);
1695 if (filtered.empty()) {
1699 if (ImGui::TreeNode(group.c_str())) {
1700 for (
const auto& sc : filtered) {
1701 ImGui::PushID(sc.name.c_str());
1702 ImGui::Text(
"%s", sc.name.c_str());
1704 ImGui::SetNextItemWidth(180);
1705 std::string& value = editing[sc.name];
1706 if (value.empty()) {
1714 if (ImGui::InputText(
"##editor", &value,
1715 ImGuiInputTextFlags_EnterReturnsTrue |
1716 ImGuiInputTextFlags_AutoSelectAll)) {
1718 if (!parsed.empty() || value.empty()) {
1720 if (value.empty()) {
1734 ImGui::TextDisabled(
"No shortcuts match the current filter.");
1740 ImGui::TextDisabled(
"Registry not available");
1747 bool has_match =
false;
1748 for (
const auto& category : categories) {
1750 std::vector<
decltype(cards)::value_type> filtered_cards;
1751 filtered_cards.reserve(cards.size());
1752 for (
const auto& card : cards) {
1755 filtered_cards.push_back(card);
1758 if (filtered_cards.empty()) {
1762 if (ImGui::TreeNode(category.c_str())) {
1764 for (
const auto& card : filtered_cards) {
1765 ImGui::PushID(card.card_id.c_str());
1767 ImGui::Text(
"%s %s", card.icon.c_str(), card.display_name.c_str());
1769 std::string current_shortcut;
1772 current_shortcut = it->second;
1773 }
else if (!card.shortcut_hint.empty()) {
1774 current_shortcut = card.shortcut_hint;
1776 current_shortcut =
"None";
1780 std::string display_shortcut = current_shortcut;
1782 if (!parsed.empty()) {
1787 ImGui::SetNextItemWidth(120);
1788 ImGui::SetKeyboardFocusHere();
1791 ImGuiInputTextFlags_EnterReturnsTrue)) {
1808 if (ImGui::Button(display_shortcut.c_str(), ImVec2(120, 0))) {
1814 if (ImGui::IsItemHovered()) {
1815 ImGui::SetTooltip(
"Click to edit shortcut");
1826 ImGui::TextDisabled(
"No shortcuts match the current filter.");
1835 if (patches_dir_status.ok()) {
1850 ImGui::TextDisabled(
"No patches loaded");
1851 ImGui::TextDisabled(
"Place .asm patches in assets/patches/");
1853 if (ImGui::Button(
"Browse for Patches Folder...")) {
1862 ImGui::Text(
"Loaded: %d patches (%d enabled)", total_count, enabled_count);
1868 ImGuiTabBarFlags_FittingPolicyScroll)) {
1870 if (ImGui::BeginTabItem(folder.c_str())) {
1873 ImGui::EndTabItem();
1886 ImGui::TextDisabled(
"Select a patch to view details");
1895#ifdef YAZE_WITH_Z3DK
1913 for (
const auto& range :
z3dk.prohibited_memory_ranges) {
1915 {.start = range.start, .end = range.end, .reason = range.reason});
1923 if (!
z3dk.rom_path.empty()) {
1934 LOG_ERROR(
"Settings",
"Failed to apply patches: %s", status.message());
1936 LOG_INFO(
"Settings",
"Applied %d patches successfully", enabled_count);
1939 LOG_WARN(
"Settings",
"No ROM loaded");
1942 if (ImGui::IsItemHovered()) {
1943 ImGui::SetTooltip(
"Apply all enabled patches to the loaded ROM");
1950 LOG_ERROR(
"Settings",
"Failed to save patches: %s", status.message());
1963 if (patches.empty()) {
1964 ImGui::TextDisabled(
"No patches in this folder");
1969 float available_height = std::min(200.0f, patches.size() * 25.0f + 10.0f);
1970 if (ImGui::BeginChild(
"##PatchList", ImVec2(0, available_height),
true)) {
1971 for (
auto* patch : patches) {
1972 ImGui::PushID(patch->filename().c_str());
1974 bool enabled = patch->enabled();
1975 if (ImGui::Checkbox(
"##Enabled", &enabled)) {
1976 patch->set_enabled(enabled);
1983 if (ImGui::Selectable(patch->name().c_str(), is_selected)) {
2016 if (!params.empty()) {
2021 for (
auto& param : params) {
2033 switch (param->
type) {
2037 int value = param->
value;
2038 const char* format = param->
use_decimal ?
"%d" :
"$%X";
2041 ImGui::SetNextItemWidth(100);
2042 if (ImGui::InputInt(
"##Value", &value, 1, 16)) {
2056 if (ImGui::Checkbox(param->
display_name.c_str(), &checked)) {
2064 for (
size_t i = 0; i < param->
choices.size(); ++i) {
2065 bool selected = (param->
value ==
static_cast<int>(i));
2066 if (ImGui::RadioButton(param->
choices[i].c_str(), selected)) {
2067 param->
value =
static_cast<int>(i);
2075 for (
size_t i = 0; i < param->
choices.size(); ++i) {
2076 if (param->
choices[i].empty() || param->
choices[i] ==
"_EMPTY") {
2079 bool bit_set = (param->
value & (1 << i)) != 0;
2080 if (ImGui::Checkbox(param->
choices[i].c_str(), &bit_set)) {
2082 param->
value |= (1 << i);
2084 param->
value &= ~(1 << i);
2094 ImGui::SetNextItemWidth(150);
2095 if (ImGui::InputInt(
"Item ID", ¶m->
value)) {
2096 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)
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()
bool MatchesShortcutFilter(const std::string &text) const
void DrawParameterWidget(core::PatchParameter *param)
void DrawEditorBehavior()
core::AsmPatch * selected_patch_
void DrawGeneralSettings()
core::PatchManager patch_manager_
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::string shortcut_filter_
void SetProject(project::YazeProject *project)
WorkspaceWindowManager * window_manager_
void DrawPanelShortcuts()
void DrawAIAgentSettings()
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
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_VIDEOGAME_ASSET
#define ICON_MD_EXTENSION
#define ICON_MD_PSYCHOLOGY
#define ICON_MD_HORIZONTAL_RULE
#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[]
std::vector< uint16_t > DefaultTrackTiles()
bool ParseHexToken(const std::string &token, uint16_t *out)
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()
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
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.
std::string ComputeRomHash(const uint8_t *data, size_t size)
void SetPreferHmagicSpriteNames(bool prefer)
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
std::unordered_map< std::string, std::string > editor_shortcuts
std::vector< AiHost > ai_hosts
std::unordered_map< std::string, std::string > global_shortcuts
bool prefer_hmagic_sprite_names
Comprehensive theme structure for YAZE.
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