yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_rom_sync_panel.cc
Go to the documentation of this file.
2
3#include <string>
4
5#include "absl/strings/str_format.h"
6#include "absl/time/clock.h"
7#include "absl/time/time.h"
12#include "imgui/imgui.h"
13
14namespace yaze {
15namespace editor {
16
18 const RomSyncCallbacks& callbacks,
19 ToastManager* toast_manager) {
20 auto& state = context->rom_sync_state();
21 auto& collab_state = context->collaboration_state();
22
23 gui::StyleColorGuard rom_bg(ImGuiCol_ChildBg,
24 ImVec4(0.18f, 0.14f, 0.12f, 1.0f));
25 ImGui::BeginChild("RomSync", ImVec2(0, 130), true);
26
27 ImGui::Text(ICON_MD_STORAGE " ROM State");
28 ImGui::Separator();
29
30 // Display current ROM hash
31 if (!state.current_rom_hash.empty()) {
32 ImGui::Text("Hash: %s", state.current_rom_hash.substr(0, 16).c_str());
33 ImGui::SameLine();
34 if (ImGui::SmallButton(ICON_MD_CONTENT_COPY)) {
35 ImGui::SetClipboardText(state.current_rom_hash.c_str());
36 if (toast_manager) {
37 toast_manager->Show("ROM hash copied", ToastType::kInfo, 2.0f);
38 }
39 }
40 } else {
41 // Child is short (~130px); keep title-only compact empty state.
42 gui::EmptyStateOptions opts = gui::EmptyNoRom(/*compact=*/true);
43 opts.detail = nullptr;
45 }
46
47 if (state.last_sync_time != absl::InfinitePast()) {
48 ImGui::Text("Last Sync: %s",
49 absl::FormatTime("%H:%M:%S", state.last_sync_time,
50 absl::LocalTimeZone())
51 .c_str());
52 }
53
54 ImGui::Spacing();
55 ImGui::Checkbox("Auto-sync ROM changes", &state.auto_sync_enabled);
56
57 if (state.auto_sync_enabled) {
58 ImGui::SliderInt("Sync Interval (seconds)", &state.sync_interval_seconds,
59 10, 120);
60 }
61
62 ImGui::Spacing();
63 ImGui::Separator();
64
65 bool can_sync = static_cast<bool>(callbacks.generate_rom_diff) &&
66 collab_state.active &&
67 collab_state.mode == CollaborationMode::kNetwork;
68
69 if (!can_sync)
70 ImGui::BeginDisabled();
71
72 if (ImGui::Button(ICON_MD_CLOUD_UPLOAD " Send ROM Sync", ImVec2(-1, 0))) {
73 if (callbacks.generate_rom_diff) {
74 auto diff_result = callbacks.generate_rom_diff();
75 if (diff_result.ok()) {
76 std::string hash =
77 callbacks.get_rom_hash ? callbacks.get_rom_hash() : "";
78
79 state.current_rom_hash = hash;
80 state.last_sync_time = absl::Now();
81
82 // TODO: Send via network coordinator (handled by caller usually)
83 if (toast_manager) {
84 toast_manager->Show(ICON_MD_CLOUD_DONE " ROM synced to collaborators",
86 }
87 } else if (toast_manager) {
88 toast_manager->Show(absl::StrFormat(ICON_MD_ERROR " Sync failed: %s",
89 diff_result.status().message()),
90 ToastType::kError, 5.0f);
91 }
92 }
93 }
94
95 if (!can_sync) {
96 ImGui::EndDisabled();
97 if (ImGui::IsItemHovered()) {
98 ImGui::SetTooltip("Connect to a network session to sync ROM");
99 }
100 }
101
102 // Show pending syncs
103 if (!state.pending_syncs.empty()) {
104 ImGui::Spacing();
105 ImGui::Text(ICON_MD_PENDING " Pending Syncs (%zu)",
106 state.pending_syncs.size());
107 ImGui::Separator();
108
109 ImGui::BeginChild("PendingSyncs", ImVec2(0, 80), true);
110 for (const auto& sync : state.pending_syncs) {
111 ImGui::BulletText("%s", sync.substr(0, 40).c_str());
112 }
113 ImGui::EndChild();
114 }
115
116 ImGui::EndChild();
117}
118
119} // namespace editor
120} // namespace yaze
void Draw(AgentUIContext *context, const RomSyncCallbacks &callbacks, ToastManager *toast_manager)
Unified context for agent UI components.
RomSyncState & rom_sync_state()
CollaborationState & collaboration_state()
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
RAII guard for ImGui style colors.
Definition style_guard.h:27
#define ICON_MD_STORAGE
Definition icons.h:1865
#define ICON_MD_CLOUD_DONE
Definition icons.h:425
#define ICON_MD_ERROR
Definition icons.h:686
#define ICON_MD_PENDING
Definition icons.h:1398
#define ICON_MD_CONTENT_COPY
Definition icons.h:465
#define ICON_MD_CLOUD_UPLOAD
Definition icons.h:430
bool DrawEmptyState(const EmptyStateOptions &options)
Draw a centered empty-state block.
EmptyStateOptions EmptyNoRom(bool compact)
Callbacks for ROM sync operations.
std::function< std::string()> get_rom_hash
std::function< absl::StatusOr< std::string >()> generate_rom_diff
Shared empty / disabled panel presentation.
Definition empty_state.h:15