3#include "imgui/imgui.h"
22#include <imgui_widgets/gizmo.h>
26#include <filedialog/filedialog.h>
38 auto is_active() const ->
bool
40 return ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsAnyItemActive();
45 const bool down = is_active();
48 if(!ImGui::IsAnyItemActive())
51 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
52 ImGui::GetIO().AppFocusLost)
57 if(ImGui::IsMouseReleased(ImGuiMouseButton_Left))
70 auto current_merge_key() const -> uint64_t
76 static merge_session session;
81 auto& ev = ctx.get_cached<
events>();
100 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
102 waiting_for_compilation_before_play_ =
true;
113 for(
auto scn : scenes)
115 auto&
cache = caches_[scn->tag];
117 save_checkpoint(ctx,
cache);
125 scripting.unload_app_domain();
129 scripting.wait_for_jobs_to_finish(ctx);
133 scripting.load_app_domain(ctx,
true);
139 for(
auto scn : scenes)
141 auto&
cache = caches_[scn->tag];
143 load_checkpoint(ctx,
cache,
true);
147 waiting_for_compilation_before_play_ =
false;
153 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
157 for(
auto scn : scenes)
159 if(scn->tag ==
"game")
164 auto&
cache = caches_[scn->tag];
166 save_checkpoint(ctx,
cache);
171 scripting.load_app_domain(ctx,
false);
173 for(
auto scn : scenes)
175 auto&
cache = caches_[scn->tag];
177 load_checkpoint(ctx,
cache,
true);
191 if(waiting_for_compilation_before_play_)
200 for(
auto scn : scenes)
202 auto&
cache = caches_[scn->tag];
204 save_checkpoint(ctx,
cache);
210 scripting.load_app_domain(ctx,
false);
212 for(
auto scn : scenes)
214 auto&
cache = caches_[scn->tag];
216 load_checkpoint(ctx,
cache,
true);
224 selection_cache_ = {};
231 auto& id_comp = sel->get_or_emplace<id_component>();
232 id_comp.generate_if_nil();
233 selection_cache_.uids.emplace_back(id_comp.id);
256void editing_manager::load_checkpoint(
rtti::context& ctx, scene_cache&
cache,
bool recover_selection)
274 std::vector<entt::handle> entities;
279 cache.scn->registry->view<id_component>().each(
280 [&](
auto e,
auto&& comp)
283 if(std::find(selection_cache_.uids.begin(), selection_cache_.uids.end(), uid) != selection_cache_.uids.end())
285 entities.emplace_back(
cache.scn->create_handle(e));
289 for(
auto entity : entities)
291 if(recover_selection)
293 entity.remove<id_component>();
304 auto& rpath = ctx.
get_cached<rendering_system>();
305 rpath.on_frame_update(*
cache.scn, dt);
306 rpath.on_frame_before_render(*
cache.scn, dt);
324 auto& scn = ec.get_scene();
326 std::vector<entt::handle> affected_entities;
328 [&](
auto e,
auto&& prefab_comp)
330 auto entity = scn.create_handle(e);
331 if(prefab_comp.source == pfb)
333 affected_entities.emplace_back(
entity);
337 for(
auto&
entity : affected_entities)
346 [&ctx,
entity, pfb]()
mutable
366 auto& scn = ec.get_scene();
367 if(
auto trans_comp =
entity.template try_get<transform_component>())
369 auto parent = trans_comp->get_parent();
370 auto pos = trans_comp->get_position_local();
371 auto rot = trans_comp->get_rotation_local();
378 return !prefab_comp.has_serialization_override(property_path);
380 path_ctx.enable_recording();
385 if(scn.instantiate_out(pfb,
entity))
389 new_trans.set_rotation_local(rot);
391 new_trans.set_parent(parent,
false);
405 [&](
auto e,
auto&& comp)
416 if(ImGui::IsKeyDown(ImGuiKey_LeftShift))
420 if(ImGui::IsKeyDown(ImGuiKey_LeftCtrl))
459 if(clear_selection_tools)
461 ImGuizmo::Enable(
false);
462 ImGuizmo::Enable(
true);
481 auto on_continue = [
this,&ctx,
prefab]()
513 auto on_save = [
this,&ctx]()
524 prompt_save_changes(ctx, on_save, on_continue);
542auto editing_manager::prompt_save_changes(
rtti::context& ctx,
const std::function<
void()>& on_save,
const std::function<
void()>& on_continue) ->
bool
545 "Do you want to save the changes you made?",
569 auto on_save = [
this,&ctx]()
574 auto on_continue = [
this, &ctx]()
588 switch (save_changes)
600 prompt_save_changes(ctx, on_save, on_continue);
648 if (is_prefab_mode())
650 return &prefab_scene;
721 has_unsaved_changes_ =
true;
724 action->merge_key = session.current_merge_key();
733 action->undoable =
false;
767 action->execution_count++;
771 if (action->is_undoable())
787 has_unsaved_changes_ =
true;
796 has_unsaved_changes_ =
true;
const btCollisionObject * object
std::chrono::duration< float > delta_t
#define APPLOG_ERROR(...)
#define APPLOG_TRACE(...)
ModalResult
Modal result flags for message box buttons.
auto ShowSaveConfirmation(const std::string &title, const std::string &message, std::function< void(ModalResult)> callback) -> std::shared_ptr< MsgBox >
Show a save confirmation dialog with Save/Don't Save/Cancel buttons.
NOTIFY_INLINE void PushNotification(const ImGuiToast &toast)
Insert a new toast in the list.
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
void set_path_context(path_context *ctx)
auto get_path_context() -> path_context *
auto atomic_save_to_file(const fs::path &key, const asset_handle< T > &obj) -> bool
auto load_from_stream(std::istream &stream, entt::handle e, script_component::script_object &obj) -> bool
auto save_to_stream(std::ostream &stream, entt::const_handle e, const script_component::script_object &obj) -> bool
Represents a handle to an asset, providing access and management functions.
auto is_valid() const -> bool
Checks if the handle is valid.
std::function< bool(const std::string &)> should_serialize_property_callback
static void create_default_3d_scene_for_editing(rtti::context &ctx, scene &scn)
Creates a default 3D scene for editing.
Manages the entity-component-system (ECS) operations for the ACE framework.
auto get_scene() -> scene &
Gets the current scene.
auto is_prefab_mode() const -> bool
auto get_active_scene(rtti::context &ctx) -> scene *
void on_play_after_end(rtti::context &ctx)
auto try_get_selections_as() const -> std::vector< const T * >
auto get_select_mode() const -> select_mode
void push_undo_stack_enabled(bool enabled)
ImGuizmo::MODE mode
current manipulation gizmo space.
void focus_path(const fs::path &object)
void pop_undo_stack_enabled()
auto init(rtti::context &ctx) -> bool
void on_play_before_begin(rtti::context &ctx)
void on_frame_update(rtti::context &ctx, delta_t)
void on_script_recompile(rtti::context &ctx, const std::string &protocol, uint64_t version)
std::vector< std::shared_ptr< editing_action_t > > pending_actions
entt::handle prefab_entity
void sync_prefab_entity(rtti::context &ctx, entt::handle entity, const asset_handle< prefab > &pfb)
void clear_unsaved_changes()
selection selection_data
selection data containing selected object
void queue_action(const std::string &name, const std::function< void()> &action)
void do_action(const std::string &name, const std::function< void()> &action)
void sync_prefab_instances(rtti::context &ctx, scene *scn)
void on_prefab_updated(const asset_handle< prefab > &pfb)
void enter_prefab_mode(rtti::context &ctx, const asset_handle< prefab > &prefab, bool auto_save=false)
std::stack< bool > undo_stack_enabled
void select(const T &entry, select_mode mode=select_mode::normal)
auto deinit(rtti::context &ctx) -> bool
void add_action(const std::string &name, std::shared_ptr< editing_action_t > action, bool immediate=true)
void focus(entt::meta_any object)
Selects an object. Can be anything.
void exit_prefab_mode(rtti::context &ctx, save_option save_changes=save_option::prompt)
undo_redo_stack undo_stack
void save_prefab_changes(rtti::context &ctx)
editing_mode current_mode
asset_handle< prefab > edited_prefab
void unselect(bool clear_selection_tools=true)
Clears the selection data.
static auto context() -> rtti::context &
hpp::event< void(rtti::context &)> on_play_before_begin
engine play events
Component that holds a reference to a prefab asset and tracks property overrides.
Represents a generic prefab with a buffer for serialized data.
Represents a scene in the ACE framework, managing entities and their relationships.
auto instantiate(const asset_handle< prefab > &pfb) -> entt::handle
static auto get_all_scenes() -> const std::vector< scene * > &
void unload()
Unloads the scene, removing all entities.
std::unique_ptr< entt::registry > registry
The registry that manages all entities in the scene.
void push_if_undoable(std::shared_ptr< editing_action_t > action)
auto can_undo() const -> bool
auto can_redo() const -> bool