From 7564d115703d555223676ef9a60f5326d014ba73 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 14 Nov 2017 09:31:12 +0000 Subject: [PATCH] add message when failed to load thumbs from cloud --- engine/app_cloud.cpp | 15 ++++++++++++++- engine/node.cpp | 16 ++++++++++++++++ engine/node.h | 13 +++++++++++++ engine/node_dialog_cloud.cpp | 18 ++++++++++++++++++ engine/node_text.cpp | 17 ++++++++++++++--- engine/node_text.h | 1 + 6 files changed, 76 insertions(+), 4 deletions(-) diff --git a/engine/app_cloud.cpp b/engine/app_cloud.cpp index b058f9d..c944cb5 100644 --- a/engine/app_cloud.cpp +++ b/engine/app_cloud.cpp @@ -112,18 +112,31 @@ void App::cloud_browse() dialog->btn_ok->on_click = [this, dialog](Node*) { + dialog->destroy(); std::thread([this, dialog] { + async_start(); + auto* m = layout[main_id]->add_child(); + m->m_title->set_text("Downloading"); + m->m_message->set_text("Download in progress, please wait..."); + async_update(); + async_end(); + download(dialog->selected_file); + async_start(); canvas->reset_camera(); layers->clear(); + async_end(); + canvas->m_canvas->project_open_thread(dialog->selected_path); + + async_start(); doc_name = dialog->selected_name; title_update(doc_name, canvas->m_canvas->m_width); for (auto& i : canvas->m_canvas->m_order) layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str()); - dialog->destroy(); ActionManager::clear(); + m->destroy(); async_update(); async_end(); }).detach(); diff --git a/engine/node.cpp b/engine/node.cpp index efc1132..8249566 100644 --- a/engine/node.cpp +++ b/engine/node.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "app.h" #include "log.h" #include "node.h" #include "layout.h" @@ -28,6 +29,21 @@ #include "node_dialog_cloud.h" #include "node_combobox.h" +void Node::async_start() +{ + App::I.async_start(); +} + +void Node::async_update() +{ + App::I.async_update(); +} + +void Node::async_end() +{ + App::I.async_end(); +} + void Node::watch(std::function observer) { observer(this); diff --git a/engine/node.h b/engine/node.h index 7c75b73..eb66f5b 100644 --- a/engine/node.h +++ b/engine/node.h @@ -173,6 +173,16 @@ public: return static_cast(found); return nullptr; } + template T* add_child() + { + auto* n = new T; + n->init(); + n->create(); + n->loaded(); + add_child(n); + return n; + } + virtual kEventResult on_event(Event* e); virtual kEventResult handle_event(Event* e); virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size);; @@ -180,6 +190,9 @@ public: virtual void init(); virtual void loaded(); const Node* init_template(const char* id); + void async_start(); + void async_update(); + void async_end(); void add_child(Node* n); void add_child(Node* n, int index); void add_child(std::shared_ptr n); diff --git a/engine/node_dialog_cloud.cpp b/engine/node_dialog_cloud.cpp index 413c3d1..fc68a6d 100644 --- a/engine/node_dialog_cloud.cpp +++ b/engine/node_dialog_cloud.cpp @@ -53,6 +53,22 @@ void NodeDialogCloud::load_thumbs_thread() curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler); curl_easy_setopt(curl, CURLOPT_URL, "http://omigamedev.ddns.net:8080/panoview/cloud-list.php"); auto err = curl_easy_perform(curl); + if (err != CURLE_OK) + { + async_start(); + auto* align = container->add_child(); + align->SetWidthP(100.f); + align->SetHeightP(100.f); + align->SetAlign(YGAlignCenter); + align->SetJustify(YGJustifyCenter); + auto* t = align->add_child(); + t->set_font(kFont::Arial_30); + t->set_text("Could not connect to the server"); + async_update(); + async_end(); + return; + } + LOG("CLOUD LIST: %s", res.c_str()); auto names = split(res, ','); @@ -62,6 +78,8 @@ void NodeDialogCloud::load_thumbs_thread() std::string url = "http://omigamedev.ddns.net:8080/panoview/cloud-info.php?file=" + n; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); auto err = curl_easy_perform(curl); + if (err != CURLE_OK) + break; // TODO: handle this error with a message or something auto info = split(res, ',', 3); int width = atoi(info[0].c_str()); int height = atoi(info[1].c_str()); diff --git a/engine/node_text.cpp b/engine/node_text.cpp index fbfef2f..9e2446e 100644 --- a/engine/node_text.cpp +++ b/engine/node_text.cpp @@ -23,9 +23,20 @@ void NodeText::clone_copy(Node* dest) const void NodeText::create() { - char font[64]; - sprintf(font, "%s-%d", m_font.c_str(), m_font_size); - font_id = (kFont)const_hash(font); + if (!m_font.empty()) + { + char font[64]; + sprintf(font, "%s-%d", m_font.c_str(), m_font_size); + font_id = (kFont)const_hash(font); + m_text_mesh.create(); + m_text_mesh.update(font_id, m_text.c_str()); + SetSize(m_text_mesh.bb); + } +} + +void NodeText::set_font(kFont fontID) +{ + font_id = fontID; m_text_mesh.create(); m_text_mesh.update(font_id, m_text.c_str()); SetSize(m_text_mesh.bb); diff --git a/engine/node_text.h b/engine/node_text.h index 47cefc1..d65b955 100644 --- a/engine/node_text.h +++ b/engine/node_text.h @@ -17,5 +17,6 @@ public: virtual void restore_context() override; virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override; void set_text(const char* s); + void set_font(kFont fontID); virtual void draw() override; };