3#include "imgui/imgui.h"
23#include <imgui_widgets/gizmo.h>
27#include <filedialog/filedialog.h>
39 auto is_active() const ->
bool
41 return ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsAnyItemActive();
46 const bool down = is_active();
49 if(!ImGui::IsAnyItemActive())
52 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
53 ImGui::GetIO().AppFocusLost)
58 if(ImGui::IsMouseReleased(ImGuiMouseButton_Left))
71 auto current_merge_key() const -> uint64_t
77 static merge_session session;
82 auto& ev = ctx.get_cached<
events>();
101 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
103 waiting_for_compilation_before_play_ =
true;
114 for(
auto scn : scenes)
116 auto&
cache = caches_[scn->tag];
118 save_checkpoint(ctx,
cache);
126 scripting.unload_app_domain();
130 scripting.wait_for_jobs_to_finish(ctx);
134 scripting.load_app_domain(ctx,
true);
140 for(
auto scn : scenes)
142 auto&
cache = caches_[scn->tag];
144 load_checkpoint(ctx,
cache,
true);
148 waiting_for_compilation_before_play_ =
false;
154 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
158 for(
auto scn : scenes)
160 if(scn->tag ==
"game")
165 auto&
cache = caches_[scn->tag];
167 save_checkpoint(ctx,
cache);
172 scripting.load_app_domain(ctx,
false);
174 for(
auto scn : scenes)
176 auto&
cache = caches_[scn->tag];
178 load_checkpoint(ctx,
cache,
true);
194 if(waiting_for_compilation_before_play_)
203 for(
auto scn : scenes)
205 auto&
cache = caches_[scn->tag];
207 save_checkpoint(ctx,
cache);
213 scripting.load_app_domain(ctx,
false);
215 for(
auto scn : scenes)
217 auto&
cache = caches_[scn->tag];
219 load_checkpoint(ctx,
cache,
true);
227 selection_cache_ = {};
234 auto& id_comp = sel->get_or_emplace<id_component>();
235 id_comp.generate_if_nil();
236 selection_cache_.uids.emplace_back(id_comp.id);
259void editing_manager::load_checkpoint(
rtti::context& ctx, scene_cache&
cache,
bool recover_selection)
277 std::vector<entt::handle> entities;
282 cache.scn->registry->view<id_component>().each(
283 [&](
auto e,
auto&& comp)
286 if(std::find(selection_cache_.uids.begin(), selection_cache_.uids.end(), uid) != selection_cache_.uids.end())
288 entities.emplace_back(
cache.scn->create_handle(e));
292 for(
auto entity : entities)
294 if(recover_selection)
296 entity.remove<id_component>();
307 auto& rpath = ctx.
get_cached<rendering_system>();
308 rpath.on_frame_update(*
cache.scn, dt);
309 rpath.on_frame_before_render(*
cache.scn, dt);
327 auto& scn = ec.get_scene();
329 std::vector<entt::handle> affected_entities;
331 [&](
auto e,
auto&& prefab_comp)
333 auto entity = scn.create_handle(e);
334 if(prefab_comp.source == pfb)
336 affected_entities.emplace_back(
entity);
340 for(
auto&
entity : affected_entities)
349 [&ctx,
entity, pfb]()
mutable
369 auto& scn = ec.get_scene();
370 if(
auto trans_comp =
entity.template try_get<transform_component>())
372 auto parent = trans_comp->get_parent();
373 auto pos = trans_comp->get_position_local();
374 auto rot = trans_comp->get_rotation_local();
381 return !prefab_comp.has_serialization_override(property_path);
383 path_ctx.enable_recording();
388 if(scn.instantiate_out(pfb,
entity))
392 new_trans.set_rotation_local(rot);
394 new_trans.set_parent(parent,
false);
408 [&](
auto e,
auto&& comp)
419 if(ImGui::IsKeyDown(ImGuiKey_LeftShift))
423 if(ImGui::IsKeyDown(ImGuiKey_LeftCtrl))
462 if(clear_selection_tools)
464 ImGuizmo::Enable(
false);
465 ImGuizmo::Enable(
true);
484 auto on_continue = [
this,&ctx,
prefab]()
516 auto on_save = [
this,&ctx]()
527 prompt_save_changes(ctx, on_save, on_continue);
545auto editing_manager::prompt_save_changes(
rtti::context& ctx,
const std::function<
void()>& on_save,
const std::function<
void()>& on_continue) ->
bool
548 "Do you want to save the changes you made?",
572 auto on_save = [
this,&ctx]()
577 auto on_continue = [
this, &ctx]()
591 switch (save_changes)
603 prompt_save_changes(ctx, on_save, on_continue);
651 if (is_prefab_mode())
653 return &prefab_scene;
724 has_unsaved_changes_ =
true;
727 action->merge_key = session.current_merge_key();
736 action->undoable =
false;
770 action->execution_count++;
774 if (action->is_undoable())
790 has_unsaved_changes_ =
true;
799 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.
Class responsible for timers.
void push_if_undoable(std::shared_ptr< editing_action_t > action)
auto can_undo() const -> bool
auto can_redo() const -> bool