Compare commits
2 Commits
cb234f64f0
...
2e33adf4a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e33adf4a9 | |||
| c67a805bd7 |
@@ -22,15 +22,15 @@ DockId=0x00000009,0
|
|||||||
|
|
||||||
[Window][Objects]
|
[Window][Objects]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=251,774
|
Size=15,22
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000000B,1
|
DockId=0x0000000B,0
|
||||||
|
|
||||||
[Window][Terrain]
|
[Window][Terrain]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=251,774
|
Size=15,22
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000000B,0
|
DockId=0x0000000B,1
|
||||||
|
|
||||||
[Window][Log Window]
|
[Window][Log Window]
|
||||||
Pos=0,630
|
Pos=0,630
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ struct ComponentEntry {
|
|||||||
std::function<void()> addFunc;
|
std::function<void()> addFunc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CachedEntity
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
int id;
|
||||||
|
};
|
||||||
|
|
||||||
class imguiManager
|
class imguiManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -175,6 +181,10 @@ private:
|
|||||||
// --------------------------------------------- //
|
// --------------------------------------------- //
|
||||||
// ----------------- Functions ----------------- //
|
// ----------------- Functions ----------------- //
|
||||||
// --------------------------------------------- //
|
// --------------------------------------------- //
|
||||||
|
/**
|
||||||
|
* Update the cached entity list if there is a new, delete or rename entity
|
||||||
|
*/
|
||||||
|
void UpdateCachedEntitiesIfNeeded();
|
||||||
|
|
||||||
// --------------------------------------------- //
|
// --------------------------------------------- //
|
||||||
// ----------------- Variables ----------------- //
|
// ----------------- Variables ----------------- //
|
||||||
@@ -232,6 +242,8 @@ private:
|
|||||||
std::string version_driver_;
|
std::string version_driver_;
|
||||||
|
|
||||||
ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity
|
ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity
|
||||||
|
std::vector<CachedEntity> cachedEntities_;
|
||||||
|
bool entityListDirty = true;
|
||||||
|
|
||||||
int BUILD_VERSION_VER = -1;
|
int BUILD_VERSION_VER = -1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -502,6 +502,8 @@ void imguiManager::WidgetAddObject()
|
|||||||
// Remplacer les antislashs par des slashs
|
// Remplacer les antislashs par des slashs
|
||||||
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
||||||
app_->add_kobject(relativePath);
|
app_->add_kobject(relativePath);
|
||||||
|
// set entities list as dirty
|
||||||
|
entityListDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -596,32 +598,26 @@ void imguiManager::WidgetObjectWindow()
|
|||||||
// Remplacer les antislashs par des slashs
|
// Remplacer les antislashs par des slashs
|
||||||
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
||||||
app_->add_kobject(relativePath);
|
app_->add_kobject(relativePath);
|
||||||
|
// set list as dirty since new entity has been added to the scene
|
||||||
|
entityListDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
S_LINE
|
S_LINE
|
||||||
TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount())
|
TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount())
|
||||||
SEP
|
SEP
|
||||||
|
|
||||||
auto entities = entity_manager_->GetAllEntities();
|
UpdateCachedEntitiesIfNeeded();
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2));
|
||||||
|
|
||||||
for (auto& entity : entities)
|
for (auto& cachedEntitie : cachedEntities_)
|
||||||
{
|
{
|
||||||
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
bool isSelected = (cachedEntitie.id == m_selected_entity_id);
|
||||||
if (identity)
|
if (SEL(cachedEntitie.name.c_str(), isSelected))
|
||||||
{
|
{
|
||||||
std::string name = identity->GetName();
|
m_selected_entity_id = cachedEntitie.id;
|
||||||
if (name.empty()) name = "Entity #" + std::to_string(identity->GetId());
|
show_inspector_window_ = true;
|
||||||
// avoid same label by adding the ID at the end
|
|
||||||
name += "##" + std::to_string(identity->GetId());
|
|
||||||
bool isSelected = (entity->GetID() == m_selected_entity_id);
|
|
||||||
if (SEL(name.c_str(), isSelected))
|
|
||||||
{
|
|
||||||
m_selected_entity_id = entity->GetID();
|
|
||||||
show_inspector_window_ = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,6 +664,7 @@ void imguiManager::WidgetInspectorWindow()
|
|||||||
entity_manager_->DestroyEntity(m_selected_entity_id);
|
entity_manager_->DestroyEntity(m_selected_entity_id);
|
||||||
m_selected_entity_id = -1;
|
m_selected_entity_id = -1;
|
||||||
show_inspector_window_ = false;
|
show_inspector_window_ = false;
|
||||||
|
entityListDirty = true;
|
||||||
}
|
}
|
||||||
S_LINE
|
S_LINE
|
||||||
|
|
||||||
@@ -1223,3 +1220,19 @@ void imguiManager::WidgetRenderStats()
|
|||||||
END
|
END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void imguiManager::UpdateCachedEntitiesIfNeeded() {
|
||||||
|
if (!entityListDirty) return;
|
||||||
|
cachedEntities_.clear();
|
||||||
|
auto entities = entity_manager_->GetAllEntities();
|
||||||
|
for (auto& entity : entities) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity) {
|
||||||
|
std::string name = identity->GetName();
|
||||||
|
auto id = identity->GetId();
|
||||||
|
if (name.empty())
|
||||||
|
name = "Entity " + std::to_string(identity->GetId());
|
||||||
|
cachedEntities_.push_back({name,id});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entityListDirty = false;
|
||||||
|
}
|
||||||
BIN
x64/Debug/config.txt
(Stored with Git LFS)
BIN
x64/Debug/config.txt
(Stored with Git LFS)
Binary file not shown.
BIN
x64/Release/config.txt
(Stored with Git LFS)
BIN
x64/Release/config.txt
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user