Unravel Engine C++ Reference
Loading...
Searching...
No Matches
deploy_panel.cpp
Go to the documentation of this file.
1#include "deploy_panel.h"
2#include "../panel.h"
3#include "../panels_defs.h"
4
7
8#include <filedialog/filedialog.h>
9#include <imgui/imgui.h>
10#include <imgui/imgui_internal.h>
11
12namespace unravel
13{
14
15deploy_panel::deploy_panel(imgui_panels* parent) : parent_(parent)
16{
17}
18
20{
21 show_request_ = s;
22 deploy_jobs_.clear();
23}
24
26{
27 if(show_request_)
28 {
29 ImGui::OpenPopup(name);
30 show_request_ = false;
31 }
32
33 ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size * 0.5f);
34 bool show = true;
35 if(ImGui::BeginPopupModal(name, &show))
36 {
37 // ImGui::WindowTimeBlock block(ImGui::GetFont(ImGui::Font::Mono));
38
39 draw_ui(ctx);
40
41 ImGui::EndPopup();
42 }
43}
44
45auto deploy_panel::get_progress() const -> float
46{
47 if(deploy_jobs_.empty())
48 {
49 return 1.0f;
50 }
51
52
53 size_t ready = 0;
54 for(const auto& kvp : deploy_jobs_)
55 {
56 if(kvp.second.is_ready())
57 {
58 ready++;
59 }
60 }
61
62 return float(ready) / float(deploy_jobs_.size());
63}
64
65void deploy_panel::draw_ui(rtti::context& ctx)
66{
67 auto& pm = ctx.get_cached<project_manager>();
68 auto& settings = pm.get_settings();
69 auto& deploy_settings = pm.get_deploy_settings();
70
71 if(inspect(ctx, settings.app).edit_finished)
72 {
73 pm.save_project_settings(ctx);
74 }
75
76 if(inspect(ctx, settings.standalone).edit_finished)
77 {
78 pm.save_project_settings(ctx);
79 }
80
81 if(inspect(ctx, deploy_settings).edit_finished)
82 {
83 pm.save_deploy_settings();
84 }
85
86 float progress = get_progress();
87 bool is_in_progress = progress < 0.99f;
88 bool valid_location = fs::is_directory(deploy_settings.deploy_location);
89 bool valid_startup_scene = settings.standalone.startup_scene.is_valid();
90 bool can_deploy = valid_location && valid_startup_scene && !is_in_progress;
91 if(can_deploy)
92 {
93 ImGui::AlignedItem(0.5f,
94 ImGui::GetContentRegionAvail().x,
95 300.0f,
96 [&]()
97 {
98 if(ImGui::Button("Deploy", ImVec2(300.0f, 0.0f)))
99 {
100 deploy_jobs_ = editor_actions::deploy_project(ctx, deploy_settings);
101 }
102
103 });
104 }
105
106 if(is_in_progress)
107 {
108 auto sz = ImGui::GetContentRegionAvail().x * 0.6f;
109 ImGui::AlignedItem(0.5f,
110 ImGui::GetContentRegionAvail().x,
111 sz,
112 [&]()
113 {
114 ImGui::ProgressBar(progress, ImVec2(sz, 0.0f));
115 });
116
117 for(const auto& kvp : deploy_jobs_)
118 {
119 const auto& name = kvp.first;
120 const auto& job = kvp.second;
121
122 auto text = fmt::format("{} - {}", name.c_str(), (job.is_ready() ? "Done." : "In Progress..."));
123 auto sz = ImGui::CalcTextSize(text.c_str()).x;
124 ImGui::AlignedItem(0.5f,
125 ImGui::GetContentRegionAvail().x,
126 sz,
127 [&]()
128 {
129 ImGui::TextUnformatted(text.c_str());
130 });
131 }
132 }
133}
134
135} // namespace unravel
deploy_panel(imgui_panels *parent)
void on_frame_ui_render(rtti::context &ctx, const char *name)
std::string name
Definition hub.cpp:27
auto inspect(rtti::context &ctx, T &obj) -> inspect_result
Convenience template function for inspecting objects of known type.
Definition inspectors.h:393
float x
auto get_cached() -> T &
Definition context.hpp:49
static auto deploy_project(rtti::context &ctx, const deploy_settings &params) -> std::map< std::string, tpp::shared_future< void > >