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
18
20{
21 show_request_ = s;
22
23 if(!s)
24 {
25 deploy_jobs_.clear();
26 }
27}
28
30{
31 if(show_request_)
32 {
33 ImGui::OpenPopup(name);
34 show_request_ = false;
35 }
36
37 ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size * 0.5f);
38 bool show = true;
39 if(ImGui::BeginPopupModal(name, &show))
40 {
41 // ImGui::WindowTimeBlock block(ImGui::GetFont(ImGui::Font::Mono));
42
43 draw_ui(ctx);
44
45 ImGui::EndPopup();
46 }
47}
48
49auto deploy_panel::get_progress() const -> float
50{
51 if(deploy_jobs_.empty())
52 {
53 return 1.0f;
54 }
55
56
57 size_t ready = 0;
58 for(const auto& kvp : deploy_jobs_)
59 {
60 if(kvp.second.is_ready())
61 {
62 ready++;
63 }
64 }
65
66 return float(ready) / float(deploy_jobs_.size());
67}
68
69
70auto deploy_panel::is_deploying() const -> bool
71{
72 float progress = get_progress();
73 bool is_in_progress = progress < 0.99f;
74 return is_in_progress;
75}
76
78{
79 bool is_in_progress = is_deploying();
80 if(!is_in_progress && editor_actions::can_deploy_project(ctx, params))
81 {
82 deploy_jobs_ = editor_actions::deploy_project(ctx, params);
83 }
84 else
85 {
86 show(true);
87 }
88}
89
90void deploy_panel::draw_ui(rtti::context& ctx)
91{
92 auto& pm = ctx.get_cached<project_manager>();
93 auto& settings = pm.get_settings();
94 auto& deploy_settings = pm.get_deploy_settings();
95
96 if(inspect(ctx, settings.app).edit_finished)
97 {
98 pm.save_project_settings(ctx);
99 }
100
101 if(inspect(ctx, settings.standalone).edit_finished)
102 {
103 pm.save_project_settings(ctx);
104 }
105
106 if(inspect(ctx, deploy_settings).edit_finished)
107 {
108 pm.save_deploy_settings();
109 }
110
111 bool is_in_progress = is_deploying();
112 if(!is_in_progress && editor_actions::can_deploy_project(ctx, deploy_settings))
113 {
114 ImGui::AlignedItem(0.5f,
115 ImGui::GetContentRegionAvail().x,
116 300.0f,
117 [&]()
118 {
119 if(ImGui::Button("Deploy", ImVec2(300.0f, 0.0f)))
120 {
121 deploy_jobs_ = editor_actions::deploy_project(ctx, deploy_settings);
122 }
123
124 });
125 }
126
127 if(is_in_progress)
128 {
129 auto sz = ImGui::GetContentRegionAvail().x * 0.6f;
130 ImGui::AlignedItem(0.5f,
131 ImGui::GetContentRegionAvail().x,
132 sz,
133 [&]()
134 {
135 ImGui::ProgressBar(get_progress(), ImVec2(sz, 0.0f));
136 });
137
138 for(const auto& kvp : deploy_jobs_)
139 {
140 const auto& name = kvp.first;
141 const auto& job = kvp.second;
142
143 auto text = fmt::format("{} - {}", name.c_str(), (job.is_ready() ? "Done." : "In Progress..."));
144 auto sz = ImGui::CalcTextSize(text.c_str()).x;
145 ImGui::AlignedItem(0.5f,
146 ImGui::GetContentRegionAvail().x,
147 sz,
148 [&]()
149 {
150 ImGui::TextUnformatted(text.c_str());
151 });
152 }
153 }
154}
155
156} // namespace unravel
deploy_panel(imgui_panels *parent)
auto is_deploying() const -> bool
void deploy_and_run(rtti::context &ctx, const deploy_settings &params)
void on_frame_ui_render(rtti::context &ctx, const char *name)
float x
std::string name
Definition hub.cpp:33
std::vector< size_t > parent_
auto inspect(rtti::context &ctx, T &obj, const std::string &name={}) -> inspect_result
Convenience template function for inspecting objects of known type.
Definition inspectors.h:402
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 > >
static auto can_deploy_project(rtti::context &ctx, const deploy_settings &params) -> bool
struct unravel::settings::app_settings app