|
@@ -1,105 +0,0 @@
|
|
|
-#include "ui.hpp"
|
|
|
|
|
-
|
|
|
|
|
-#include <imgui.h>
|
|
|
|
|
-#include <imgui_internal.h>
|
|
|
|
|
-
|
|
|
|
|
-#include <cstdint>
|
|
|
|
|
-#include <vector>
|
|
|
|
|
-
|
|
|
|
|
-#include "saura/core/server/server.hpp"
|
|
|
|
|
-
|
|
|
|
|
-namespace saura {
|
|
|
|
|
-UI::UI(std::shared_ptr<ServerAPI> server_api_ctx) {
|
|
|
|
|
- current_ent = nullptr;
|
|
|
|
|
- server_info = {};
|
|
|
|
|
- deps.server_api_ctx = server_api_ctx;
|
|
|
|
|
-
|
|
|
|
|
- auto items = std::vector<Entity>{
|
|
|
|
|
- {
|
|
|
|
|
- .uuid = "0",
|
|
|
|
|
- .title = "Talltale Online",
|
|
|
|
|
- .url = "https://talltale.online/",
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- .uuid = "1",
|
|
|
|
|
- .title = "Google",
|
|
|
|
|
- .url = "https://google.com/",
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- .uuid = "2",
|
|
|
|
|
- .title = "Arch Linux",
|
|
|
|
|
- .url = "https://archlinux.org/",
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- .uuid = "3",
|
|
|
|
|
- .title = "GitHub",
|
|
|
|
|
- .url = "https://github.com/",
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- for (uint32_t i = 0; i < items.size(); i += 1) {
|
|
|
|
|
- entities.push_back(items[i]);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-UI::~UI() {}
|
|
|
|
|
-
|
|
|
|
|
-void UI::draw() {
|
|
|
|
|
- server_info.is_connect = deps.server_api_ctx.lock()->get_is_live();
|
|
|
|
|
-
|
|
|
|
|
- ImGui::SetNextWindowPos({0.0f, 0.0f});
|
|
|
|
|
- ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
|
|
|
|
|
- ImGui::Begin("Drag & Drop List", 0, ImGuiWindowFlags_NoDecoration);
|
|
|
|
|
-
|
|
|
|
|
- {
|
|
|
|
|
- ImGui::Text("server.is_connect:");
|
|
|
|
|
- ImVec2 text_pos = ImGui::GetItemRectMax();
|
|
|
|
|
- float spacing = 5.0f;
|
|
|
|
|
- ImVec2 center = ImVec2(text_pos.x + spacing + 4.0f,
|
|
|
|
|
- text_pos.y - ImGui::GetTextLineHeight() * 0.5f);
|
|
|
|
|
- float radius = 4.0f;
|
|
|
|
|
- ImU32 color = IM_COL32(255, 0, 0, 255);
|
|
|
|
|
- if (server_info.is_connect == true) {
|
|
|
|
|
- color = IM_COL32(0, 255, 0, 255);
|
|
|
|
|
- }
|
|
|
|
|
- ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
|
|
|
|
- draw_list->AddCircleFilled(center, radius, color, 16);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- ImGui::Text("ent.count: %d", (int)entities.size());
|
|
|
|
|
- if (current_ent != nullptr) {
|
|
|
|
|
- ImGui::Text("current_ent_uuid: %s", current_ent->uuid.c_str());
|
|
|
|
|
- } else {
|
|
|
|
|
- ImGui::Text("current_ent_uuid: None");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- ImVec2 mouse = ImGui::GetMousePos();
|
|
|
|
|
- uint32_t rect_count = 0;
|
|
|
|
|
-
|
|
|
|
|
- // --- Render ---
|
|
|
|
|
- for (auto &ent : entities) {
|
|
|
|
|
- ImGui::PushID(ent.uuid.c_str());
|
|
|
|
|
- ImGui::Button(ent.title.c_str(), {150, 22});
|
|
|
|
|
- ent.local_tmp_id = ImGui::GetItemID();
|
|
|
|
|
- ent.rect.min = ImGui::GetItemRectMin();
|
|
|
|
|
- ent.rect.max = ImGui::GetItemRectMax();
|
|
|
|
|
- ImGui::PopID();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // --- Logic ---
|
|
|
|
|
- for (auto &ent : entities) {
|
|
|
|
|
- ImGuiID ent_hovered_id = ImGui::GetCurrentContext()->HoveredId;
|
|
|
|
|
-
|
|
|
|
|
- // --- Handle drag start ---
|
|
|
|
|
- if (ImGui::IsMouseDown(ImGuiMouseButton_Left) &&
|
|
|
|
|
- ent.local_tmp_id == ent_hovered_id) {
|
|
|
|
|
- current_ent = &ent;
|
|
|
|
|
- } else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
|
|
|
|
|
- current_ent = nullptr;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- ImGui::End();
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-} // namespace saura
|
|
|