2023-07-02 22:21:26 +02:00
|
|
|
//
|
|
|
|
|
// Created by tv on 21.05.23.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "ObjectSelectWidget.h"
|
|
|
|
|
#include "imgui.h"
|
|
|
|
|
#include "misc/cpp/imgui_stdlib.h"
|
|
|
|
|
#include "boost/filesystem.hpp"
|
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<fstream>
|
2023-08-28 22:36:11 +02:00
|
|
|
#include"InstanceVars.h"
|
|
|
|
|
#include<virintox/gcore/Graphics.h>
|
|
|
|
|
#include "IconsFontAwesome6.h"
|
2023-07-02 22:21:26 +02:00
|
|
|
|
|
|
|
|
ObjectSelectWidget* ObjectSelectWidgetInstance = nullptr;
|
|
|
|
|
|
2023-08-28 22:36:11 +02:00
|
|
|
MENU_ITEM_DISPLAY(Widgets,Objects,ICON_FA_CUBES " Objects"){
|
|
|
|
|
Graphics::window->WidgetByName.find("Objects")->second->Active ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 22:21:26 +02:00
|
|
|
|
|
|
|
|
ObjectSelectWidget::ObjectSelectWidget(): Graphics::Widget("Object Select",true) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectSelectWidget::Draw() {
|
|
|
|
|
static unsigned int counter = 0;
|
|
|
|
|
counter = 0;
|
|
|
|
|
|
2023-11-12 16:29:22 +01:00
|
|
|
for(auto iter = loadedMap.Objects.begin(); iter != loadedMap.Objects.end();iter++){
|
|
|
|
|
LevelObject& obj = *iter;
|
2023-08-28 22:36:11 +02:00
|
|
|
if(ImGui::Selectable((obj.Name + ": " + obj.Type + "##" + std::to_string(obj.runtimeID)).c_str(),selectedElem == &obj)){
|
|
|
|
|
selectedElem = &obj;
|
2023-07-02 22:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ImGui::IsMouseClicked(ImGuiMouseButton_Right) && ImGui::IsItemHovered()){
|
|
|
|
|
ImGui::OpenPopup((std::string("Right Click Menu: ObjSelect ") + std::to_string(obj.runtimeID)).c_str());
|
|
|
|
|
//ImGui::OpenPopup((std::string("Change Name##: ObjSelect ") + (std::to_string(obj.runtimeID))).c_str());
|
|
|
|
|
}
|
|
|
|
|
if(ImGui::BeginPopup((std::string("Right Click Menu: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){
|
|
|
|
|
std::string newmodal;
|
|
|
|
|
|
|
|
|
|
if(ImGui::MenuItem((std::string("Delete##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){
|
|
|
|
|
std::cout << "Deleting " + obj.Name << std::endl;
|
2023-11-12 16:29:22 +01:00
|
|
|
auto itertemp = iter;
|
|
|
|
|
iter--;
|
|
|
|
|
loadedMap.Objects.erase(itertemp);
|
2023-08-28 22:36:11 +02:00
|
|
|
selectedElem = nullptr;
|
2023-07-02 22:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ImGui::MenuItem((std::string("Duplicate##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){
|
|
|
|
|
LevelObject dublObj = LevelObject(obj);
|
|
|
|
|
dublObj.runtimeID = rand();
|
|
|
|
|
|
2023-08-28 22:36:11 +02:00
|
|
|
loadedMap.Objects.emplace_back(dublObj);
|
|
|
|
|
selectedElem = nullptr;
|
2023-07-02 22:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ImGui::MenuItem((std::string("Export##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){
|
|
|
|
|
YAML::Emitter emitter;
|
|
|
|
|
|
|
|
|
|
obj.YamlInsert(emitter);
|
|
|
|
|
|
|
|
|
|
auto fstr = std::ofstream((boost::filesystem::current_path() / "Presets" / (obj.Name + ".yaml")).string());
|
|
|
|
|
|
|
|
|
|
fstr << emitter.c_str();
|
|
|
|
|
fstr.flush();
|
|
|
|
|
fstr.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectSelectWidget* GetObjectSelectWidget(){
|
|
|
|
|
return ObjectSelectWidgetInstance;
|
2023-08-28 22:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
REGISTERVCLASS(ObjectSelectWidget)
|