Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by icano on 20/1/20.
- //
- #include <EddieEddieUI/CustomColors.hpp>
- #include "UiEntityListComponentTag.hpp"
- #include <EddieECS/Components/SoundComponent.hpp>
- #include <EddieECS/Components/Video.hpp>
- #include <EddieECS/Components/FSM.hpp>
- #include <EddieECS/Components/RelativeRotationPreservation.hpp>
- #include <EddieECS/Components/Animation.hpp>
- #include <EddieECS/Components/AnimationPlay.hpp>
- #include <EddieECS/Components/Text.hpp>
- #include <EddieECS/Components/NativeReel.hpp>
- #include <EddieECS/Components/IgnoreOnEditor.hpp>
- #include <EddieECS/Components/Sprite.hpp>
- #include <EddieEngine/GameContext/ContextOperations.hpp>
- #include <EddieECS/EcsBaseUtils.hpp>
- namespace {
- constexpr auto ROTATOR_TAG = "Rot";
- constexpr auto ROTATOR_REF_TAG = "RotRef";
- constexpr auto ROTATOR_BASE_TAG = "RotBase";
- constexpr auto SPRITE_TAG = "Sprite";
- constexpr auto ANIMATION_TAG = "Animation";
- constexpr auto ANIMATION_PLAY_TAG = "Playing";
- constexpr auto TEXT_TAG = "DEPRECTAED-TEXT";
- constexpr auto REEL_TAG = "NativeReel";
- constexpr auto SOUND_TAG = "Sound";
- constexpr auto ML_TEXT_TAG = "LayeredDynamicText";
- constexpr auto VIDEO_TAG = "Video";
- constexpr auto FSM_TAG = "Fsm";
- constexpr auto HIDE_ON_EDITOR_TAG = "HideOnEditor";
- }
- void UiEntityListComponentTag::GenericTag(const ECS::Entity& entity, const ECS::Signature& signature, ImColor color, std::string_view text) {
- if (gContext) {
- if (ECS::Match(entity.GetSignature(), signature)) {
- if (keep_line) {
- ImGui::SameLine();
- }
- ImGui::TextColored(color, "+%s", text.data());
- keep_line = true;
- }
- }
- }
- void UiEntityListComponentTag::RotTag(const ECS::Entity &entity) {
- GenericTag(entity, ROT_SIGNATURE, EddieColors().COLOR_ROTATE, ROTATOR_TAG);
- }
- void UiEntityListComponentTag::RotRefTag(const ECS::Entity &entity) {
- GenericTag(entity, ROT_REF_SIGNATURE, EddieColors().COLOR_ROTATE_REF, ROTATOR_REF_TAG);
- }
- void UiEntityListComponentTag::RotBaseTag(const ECS::Entity &entity) {
- GenericTag(entity, ROT_BASE_SIGNATURE, EddieColors().COLOR_ROTATE_BASE, ROTATOR_BASE_TAG);
- }
- void UiEntityListComponentTag::SpriteTag(const ECS::Entity &entity) {
- GenericTag(entity, SPRITE_SIGNATURE, EddieColors().COLOR_SPRITE, SPRITE_TAG);
- }
- void UiEntityListComponentTag::AnimationTag(const ECS::Entity &entity) {
- GenericTag(entity, ANIMATION_SIGNATURE, EddieColors().COLOR_ANIMATION, ANIMATION_TAG);
- }
- void UiEntityListComponentTag::AnimationPlayingTag(const ECS::Entity &entity) {
- GenericTag(entity, ANIMATION_PLAYING_SIGNATURE, EddieColors().COLOR_ANIMATION_PLAYING, ANIMATION_PLAY_TAG);
- }
- void UiEntityListComponentTag::FontTag(const ECS::Entity &entity) {
- GenericTag(entity, FONT_SIGNATURE, EddieColors().COLOR_FONT, TEXT_TAG);
- }
- void UiEntityListComponentTag::NativeReelTag(const ECS::Entity &entity) {
- GenericTag(entity, NATIVE_REEL_SIGNATURE, EddieColors().COLOR_NATIVE_REEL, REEL_TAG);
- }
- void UiEntityListComponentTag::LayeredFontTag(const ECS::Entity &entity) {
- GenericTag(entity, LAYERED_FONT_SIGNATURE, EddieColors().COLOR_FONT, ML_TEXT_TAG);
- }
- void UiEntityListComponentTag::HideOnEditorTag(const ECS::Entity &entity) {
- GenericTag(entity, HIDE_ON_EDITOR_SIGNATURE, EddieColors().COLOR_MISSING_DATA, HIDE_ON_EDITOR_TAG);
- }
- void UiEntityListComponentTag::SoundTag(const ECS::Entity& entity) {
- if (gContext) {
- if (ECS::Match(entity.GetSignature(), SOUND_SIGNATURE)) {
- if (keep_line) {
- ImGui::SameLine();
- }
- const auto is_play = entity.GetComponentHandler<ECS::Comp::SoundComponent>()->mSoundHandler->IsPlayingOnTime();
- if (is_play) {
- ImGui::TextColored(EddieColors().COLOR_SOUND_COMPONENT, "+%s(Playing...)", SOUND_TAG);
- } else {
- ImGui::TextColored(EddieColors().COLOR_SOUND_COMPONENT, "+%s", SOUND_TAG);
- }
- keep_line = true;
- }
- }
- }
- bool UiEntityListComponentTag::FsmTag(const ECS::Entity& entity) {
- if (gContext) {
- if (entity.HasComponent<ECS::Comp::Video>()) {
- if (keep_line) {
- ImGui::SameLine();
- }
- ImGui::TextColored(EddieColors().COLOR_VIDEO, "+%s", VIDEO_TAG);
- keep_line = true;
- }
- if (ECS::Match(entity.GetSignature(), FSM_SIGNATURE)) {
- if (keep_line) {
- ImGui::SameLine();
- }
- auto e = entity.GetComponentHandler<ECS::Comp::Fsm>()->fsmCode;
- auto p_fsm = gContext->GetInternalEcs().FSM().GetFsm(e);
- std::string stateName = "NoFsmState";
- if (p_fsm) {
- auto state = p_fsm->GetCurrentState();
- if (state) {
- stateName = state->GetStateName();
- }
- ImGui::TextColored(EddieColors().COLOR_FSM, "+%s(%s)", FSM_TAG, stateName.data());
- } else {
- stateName = "NO_FSM_LOADED_BUT_ASSIGNED";
- ImGui::TextColored(EddieColors().COLOR_MISSING_DATA, "+%s(%s)", FSM_TAG, stateName.data());
- }
- keep_line = true;
- return true;
- }
- }
- return false;
- }
- EddieFSM::Fsm *UiEntityListComponentTag::GetFsm(EddieFSM::FsmId id) {
- if (this->gContext) {
- return Game::ContextFindFsm(*gContext, id);
- }
- return nullptr;
- }
- void UiEntityListComponentTag::ShowContextualMenu(const std::set<U32>& selected, bool& selectedForRemove) {
- //ImGui::Text("1: %s", ANIMATION_AND_PLAYING_SIGNATURE.to_string().data());
- // ImGui::Text("2: %s", ANIMATION_SIGNATURE.to_string().data());
- //::Text("3: %s", ANIMATION_PLAYING_SIGNATURE.to_string().data());
- mSelectorSystem->ComputeSignature();
- auto signature = mSelectorSystem->GetSelectionCommonSignature();
- auto any_signature = mSelectorSystem->GetSelectionAnySignature();
- if (ImGui::MenuItem("Create Entity")) {
- Game::CreateEntity(*gContext, "EmptyEntity");
- }
- //ImGui::Text("R: %s", signature.to_string().data());
- if (ImGui::MenuItem("Restore TAM Position")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- EddieECS::RestoreTamPosition(*spriteProvider, *videoProvider, e);
- });
- }
- if (selected.size() == 1) {
- if (ECS::Match(signature, FSM_SIGNATURE)) {
- if (ImGui::MenuItem("Capture FSM")) {
- //some thing
- auto CaptureOperation = [&](size_t idx, ECS::Entity &e) {
- auto fsm_cmp = e.GetComponentHandler<ECS::Comp::Fsm>();
- auto fsm = GetFsm(fsm_cmp->fsmCode);
- if (fsm) {
- mTemporalCapturedFsm.reset();
- mTemporalCapturedFsm = data::json();
- fsm->ToJson(*mTemporalCapturedFsm);
- std::cout << mTemporalCapturedFsm->dump(4) << std::endl;
- }
- };
- mSelectorSystem->ForEachSelected(CaptureOperation);
- }
- }
- }
- if (!ECS::Match(any_signature, FSM_SIGNATURE)) {
- if (ImGui::MenuItem("Put captured FSM", nullptr, false, mTemporalCapturedFsm.has_value())) {
- auto &data = mTemporalCapturedFsm->front();
- auto PutCaptureOperation = [&](size_t idx, ECS::Entity &e) {
- auto fsm = Game::ContextCreateNewFsm(*gContext);
- const auto id = fsm->GetFsmIdentity();
- // std::cout << "Created fsm " << id << std::endl;
- Game::ContextRestoreFsmFromJson(*gContext, fsm, data);
- // std::cout << "Loaded in " << fsm->GetFsmIdentity() << std::endl;
- fsm->PrepareAllStates();
- ECS::Comp::Fsm fsmComponent{};
- fsmComponent.fsmCode = id;
- fsm->SetDescriptiveName("COPIED FSM " + fsm->GetDescriptiveName());
- fsm->mOwnership = e.entityId;
- e.AddComponent<ECS::Comp::Fsm>(fsmComponent);
- };
- mSelectorSystem->ForEachSelected(PutCaptureOperation);
- }
- }
- if (ECS::Match(signature, FSM_SIGNATURE)) {
- if (ImGui::MenuItem("Remove FSM")) {
- selectedForRemove = true;
- }
- } else {
- if (ImGui::MenuItem("Add FSM")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- if (!e.HasComponent<ECS::Comp::Fsm>()) {
- auto fsm = Game::ContextCreateNewFsm(*gContext);
- fsm->mOwnership = e.entityId;
- ECS::Comp::Fsm fsmComponent{fsm->GetFsmIdentity()};
- e.AddComponent<ECS::Comp::Fsm>(fsmComponent);
- }
- });
- }
- }
- if (ECS::Match(any_signature, VISIBLE_SIGNATURE)) {
- if (ImGui::MenuItem("Make Invisible")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- if (e.HasComponent<ECS::Comp::OnScene>()) {
- e.Remove<ECS::Comp::OnScene>();
- }
- });
- }
- }
- if (!ECS::Match(signature, VISIBLE_SIGNATURE)) {
- if (ImGui::MenuItem("Make Visible")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- if (!e.HasComponent<ECS::Comp::OnScene>()) {
- e.AddComponent<ECS::Comp::OnScene>();
- }
- });
- }
- }
- ImGui::Separator();
- if (ImGui::MenuItem("Hide on editor")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- if (!e.HasComponent<ECS::Comp::IgnoreOnEditor>()) {
- e.AddComponent<ECS::Comp::IgnoreOnEditor>();
- }
- });
- }
- if (ImGui::MenuItem("Show on editor")) {
- mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity &e) {
- if (e.HasComponent<ECS::Comp::IgnoreOnEditor>()) {
- e.Remove<ECS::Comp::IgnoreOnEditor>();
- }
- });
- }
- if (ImGui::BeginMenu("Add to entity vector")) {
- auto names = gContext->GetInternalVariableManager().GetTypedVariablesName<std::vector<ECS::Entity>>();
- for (auto &n: names) {
- if (ImGui::MenuItem(n.data())) {
- auto collection = gContext->GetInternalVariableManager().GetVariablePtr<std::vector<ECS::Entity>>(n);
- mSelectorSystem->ForEachSelected(
- [&](size_t idx, ECS::Entity &e) {
- collection->emplace_back(e);
- });
- }
- }
- ImGui::EndMenu();
- }
- if (ECS::Match(signature, ANIMATION_AND_PLAYING_SIGNATURE)) {
- if (ImGui::MenuItem("Remove Animation Play")) {
- mSelectorSystem->ForEachSelected([&](size_t, ECS::Entity &e) {
- if (e.HasComponent<ECS::Comp::AnimationPlay>()) {
- e.Remove<ECS::Comp::AnimationPlay>();
- }
- });
- }
- }
- if (ECS::Match(signature, ANIMATION_SIGNATURE) &&
- !ECS::Match(any_signature, ANIMATION_PLAYING_SIGNATURE)) {
- if (ImGui::MenuItem("Add default animation play")) {
- mSelectorSystem->ForEachSelected([&](size_t, ECS::Entity &e) {
- if (!e.HasComponent<ECS::Comp::AnimationPlay>()) {
- ECS::Comp::AnimationPlay play;
- e.AddComponent<ECS::Comp::AnimationPlay>(play);
- }
- });
- }
- }
- }
- void UiEntityListComponentTag::SetGameContext(Game::Context &context) {
- this->gContext = &context;
- ROT_SIGNATURE = gContext->MakeSignature<ECS::Comp::RelativeRotationPreservation>();
- ROT_REF_SIGNATURE = gContext->MakeSignature<ECS::Comp::RelativeRotationReference>();
- ROT_BASE_SIGNATURE = gContext->MakeSignature<ECS::Comp::RelativeRotationBase>();
- SPRITE_SIGNATURE = gContext->MakeSignature<ECS::Comp::Sprite>();
- ANIMATION_SIGNATURE = gContext->MakeSignature<ECS::Comp::Animation>();
- ANIMATION_PLAYING_SIGNATURE = gContext->MakeSignature<ECS::Comp::AnimationPlay>();
- FONT_SIGNATURE = gContext->MakeSignature<ECS::Comp::VeryLargeText2D_Deprectaed>();
- NATIVE_REEL_SIGNATURE = gContext->MakeSignature<ECS::Comp::NativeReel>();
- SOUND_SIGNATURE = gContext->MakeSignature<ECS::Comp::SoundComponent>();
- LAYERED_FONT_SIGNATURE = gContext->MakeSignature<ECS::Comp::MultiLayerVeryLargeText2D>();
- FSM_SIGNATURE = gContext->MakeSignature<ECS::Comp::Fsm>();
- HIDE_ON_EDITOR_SIGNATURE = gContext->MakeSignature<ECS::Comp::IgnoreOnEditor>();
- VISIBLE_SIGNATURE = gContext->MakeSignature<ECS::Comp::OnScene>();
- ANIMATION_AND_PLAYING_SIGNATURE = gContext->MakeSignature<ECS::Comp::Animation, ECS::Comp::AnimationPlay>();
- }
- void UiEntityListComponentTag::SetEditorSelector(const std::shared_ptr<ECS::EditorSelector>& selector) {
- this->mSelectorSystem = selector;
- }
- void UiEntityListComponentTag::SetSpriteProvider(const std::shared_ptr<ECS::SpriteProvider> &provider) {
- this->spriteProvider = provider;
- }
- void UiEntityListComponentTag::SetVideoProvider(const std::shared_ptr<ECS::VideoProvider> &provider) {
- this->videoProvider = provider;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement