Skip to content

Commit 781862d

Browse files
committed
start working on more clear map selector and map clear menu option:
1 parent bfab9eb commit 781862d

File tree

9 files changed

+165
-33
lines changed

9 files changed

+165
-33
lines changed

include/DOM/MapDOMNode.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class LMapDOMNode : public LDOMNodeBase
4141
std::shared_ptr<LRoomDOMNode> GetRoomByID(int32_t id);
4242
std::shared_ptr<LRoomDOMNode> GetRoomByIndex(int32_t index);
4343
std::weak_ptr<Archive::Rarc> GetArchive() { return mMapArchive; };
44+
void SetArchive(std::shared_ptr<Archive::Rarc> arc) { mMapArchive = arc; };
4445

4546
/*=== Type operations ===*/
4647
// Returns whether this node is of the given type, or derives from a node of that type.

include/io/BinIO.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class BinScenegraphNode {
136136

137137

138138
glm::mat4 transform;
139+
glm::vec3 mScale, mRotation, mTranslation;
139140
float mBoundingSphereRadius;
140141

141142
void ResetAnimation();

include/ui/BooldozerEditor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class LBooldozerEditor
5252
bool bInitialized { false };
5353

5454
bool mOnStartPopup { false };
55+
bool mClickedMapSelect { false };
56+
bool mClickedMapClear { false };
5557

5658
uint32_t mMainDockSpaceID { 0 };
5759
uint32_t mDockNodeLeftID { 0 };
@@ -91,6 +93,8 @@ class LBooldozerEditor
9193

9294
void onAppendMapCB();
9395

96+
void onClearMapCB();
97+
9498
// Callback for when the user requests to open one or more room arcs.
9599
void onOpenRoomsCB();
96100

src/DOM/MapDOMNode.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool LMapDOMNode::SaveMapToArchive(std::filesystem::path file_path)
368368
// skip polygoninfo and soundpolygoninfo, they should only be edited by changes to collision
369369
if(static_cast<LEntityType>(entityType) == LEntityType_Polygons || static_cast<LEntityType>(entityType) == LEntityType_SoundPolygons) continue;
370370

371-
std::vector<std::shared_ptr<LEntityDOMNode>> entitiesOfType;
371+
std::vector<std::shared_ptr<LEntityDOMNode>> entitiesOfType = {};
372372

373373
if (entityType == LEntityType_Characters || entityType == LEntityType_Enemies || entityType == LEntityType_Observers || entityType == LEntityType_Keys){
374374
entitiesOfType = GetChildrenOfType<LEntityDOMNode>(LEntityDOMNode::EntityTypeToDOMNodeType((LEntityType)entityType), isNotBlackoutFilter);
@@ -470,9 +470,6 @@ bool LMapDOMNode::SaveMapToFiles(std::filesystem::path folder_path)
470470
else
471471
{
472472
entitiesOfType = GetChildrenOfType<LEntityDOMNode>(LEntityDOMNode::EntityTypeToDOMNodeType((LEntityType)entityType));
473-
474-
if (entitiesOfType.size() == 0)
475-
continue;
476473
}
477474

478475
for (auto ent : entitiesOfType)

src/io/BinIO.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,19 @@ void BinScenegraphNode::AddMesh(int16_t material, int16_t mesh){
576576
meshes.push_back(std::pair(material, mesh));
577577
}
578578

579-
float MixTrack(LTrackCommon* track, float curFrame, uint32_t& mNextKey){
579+
float MixTrack(LTrackCommon* track, uint32_t frameCount, float curFrame, uint32_t& mNextKey){
580580
if(mNextKey < track->mKeys.size()){
581581
float v = InterpolateHermite(
582-
(curFrame - track->mFrames[track->mKeys[mNextKey - 1]].frame) / (track->mFrames[track->mKeys[mNextKey]].frame - track->mFrames[track->mKeys[mNextKey - 1]].frame),
582+
(uint32_t)(((uint32_t)curFrame - track->mFrames[track->mKeys[mNextKey - 1]].frame) / (track->mFrames[track->mKeys[mNextKey]].frame - track->mFrames[track->mKeys[mNextKey - 1]].frame)),
583583
track->mFrames[track->mKeys[mNextKey - 1]].frame,
584584
track->mFrames[track->mKeys[mNextKey - 1]].value,
585585
track->mFrames[track->mKeys[mNextKey - 1]].outslope,
586586
track->mFrames[track->mKeys[mNextKey]].frame,
587587
track->mFrames[track->mKeys[mNextKey]].value,
588588
track->mFrames[track->mKeys[mNextKey]].inslope
589589
);
590-
if(std::floor(curFrame) >= track->mKeys[mNextKey]){
590+
591+
if(std::floor(curFrame) >= track->mFrames[track->mKeys[mNextKey]].frame){
591592
mNextKey += 1;
592593
}
593594
return v;
@@ -606,24 +607,24 @@ void BinScenegraphNode::Draw(glm::mat4 localTransform, glm::mat4* instance, BinM
606607
if(animate && bin->mAnimationInformation.mLoaded && bin->mAnimationInformation.mPlaying){
607608
//modify mtx based off of current frame
608609

609-
float sx = -MixTrack(&mXScaleTrack, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyX);
610-
float sy = MixTrack(&mYScaleTrack, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyY);
611-
float sz = MixTrack(&mZScaleTrack, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyZ);
610+
float sx = MixTrack(&mXScaleTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyX);
611+
float sy = MixTrack(&mYScaleTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyY);
612+
float sz = MixTrack(&mZScaleTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextScaleKeyZ);
612613

613-
float rz = MixTrack(&mXRotTrack, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyX) * 0.0001533981f;
614-
float ry = MixTrack(&mYRotTrack, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyY) * 0.0001533981f;
615-
float rx = MixTrack(&mZRotTrack, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyZ) * 0.0001533981f;
614+
float rz = MixTrack(&mXRotTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyX);
615+
float ry = MixTrack(&mYRotTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyY);
616+
float rx = MixTrack(&mZRotTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextRotKeyZ);
616617

617-
float px = -MixTrack(&mXPosTrack, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyX);
618-
float py = MixTrack(&mYPosTrack, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyY);
619-
float pz = MixTrack(&mZPosTrack, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyZ);
618+
float pz = MixTrack(&mXPosTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyX);
619+
float py = MixTrack(&mYPosTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyY);
620+
float px = MixTrack(&mZPosTrack, bin->mAnimationInformation.mFrameCount, bin->mAnimationInformation.mCurrentFrame, mNextPosKeyZ);
620621

621622
glm::mat4 animTrasform(1.0f);
622623

623624
//animTrasform = glm::scale(animTrasform, glm::vec3(sx, sy, sz));
624-
animTrasform = glm::rotate(animTrasform, rx, glm::vec3(1, 0, 0));
625-
animTrasform = glm::rotate(animTrasform, ry, glm::vec3(0, 1, 0));
626-
animTrasform = glm::rotate(animTrasform, rz, glm::vec3(0, 0, 1));
625+
animTrasform = glm::rotate(animTrasform, glm::radians(rx * 0.0001533981f), glm::vec3(1, 0, 0));
626+
animTrasform = glm::rotate(animTrasform, glm::radians(ry * 0.0001533981f), glm::vec3(0, 1, 0));
627+
animTrasform = glm::rotate(animTrasform, glm::radians(rz * 0.0001533981f), glm::vec3(0, 0, 1));
627628
animTrasform = glm::translate(animTrasform, glm::vec3(px, py, pz));
628629

629630
mtx = *instance * localTransform * (transform * animTrasform);
@@ -806,9 +807,9 @@ std::shared_ptr<BinScenegraphNode> BinModel::ParseSceneraph(bStream::CStream* st
806807

807808

808809
current->transform = glm::scale(current->transform, scale);
809-
current->transform = glm::rotate(current->transform, glm::radians(rotation.x) * 0.0001533981f, glm::vec3(1, 0, 0));
810-
current->transform = glm::rotate(current->transform, glm::radians(rotation.y) * 0.0001533981f, glm::vec3(0, 1, 0));
811-
current->transform = glm::rotate(current->transform, glm::radians(rotation.z) * 0.0001533981f, glm::vec3(0, 0, 1));
810+
current->transform = glm::rotate(current->transform, glm::radians(rotation.x * 0.0001533981f), glm::vec3(1, 0, 0));
811+
current->transform = glm::rotate(current->transform, glm::radians(rotation.y * 0.0001533981f), glm::vec3(0, 1, 0));
812+
current->transform = glm::rotate(current->transform, glm::radians(rotation.z * 0.0001533981f), glm::vec3(0, 0, 1));
812813
current->transform = glm::translate(current->transform, translation);
813814

814815
stream->skip(4*7);

src/modes/ActorMode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void LActorMode::RenderSceneHierarchy(std::shared_ptr<LMapDOMNode> current_map)
4848
arc->SaveToFile(std::filesystem::path(resPathInRoot).string());
4949
}
5050

51-
newRoomData->SetRoomID(rooms.size());
52-
newRoomData->SetRoomIndex(rooms.size());
51+
newRoomData->SetRoomID(rooms.size()-1);
52+
newRoomData->SetRoomIndex(rooms.size()-1);
5353
newRoom->AddChild(newRoomData);
5454

5555
newRoom->SetRoomNumber(rooms.size());

src/scene/EditorScene.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ void LEditorScene::UpdateRenderers(){
217217
}
218218
}
219219

220-
if(auto firstRoom = mCurrentRooms[0].lock()){
220+
if(!mCurrentRooms[0].expired()){
221+
std::shared_ptr<LRoomDOMNode> firstRoom = mCurrentRooms[0].lock();
221222
std::shared_ptr<LMapDOMNode> mapNode = firstRoom->GetParentOfType<LMapDOMNode>(EDOMNodeType::Map).lock();
222223
std::shared_ptr<LMapCollisionDOMNode> col = mapNode->GetChildrenOfType<LMapCollisionDOMNode>(EDOMNodeType::MapCollision)[0];
223224
if(col->GetIsRendered()){
@@ -297,7 +298,8 @@ void LEditorScene::RenderSubmit(uint32_t m_width, uint32_t m_height){
297298
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
298299

299300
for(std::weak_ptr<LDoorDOMNode> doorRef : mRoomDoors){
300-
if (std::shared_ptr<LDoorDOMNode> door = doorRef.lock())
301+
std::shared_ptr<LDoorDOMNode> door = doorRef.lock();
302+
if (!doorRef.expired())
301303
{
302304
EDoorModel doorType = door->GetModel();
303305
if (doorType == EDoorModel::None)
@@ -438,8 +440,9 @@ void LEditorScene::SetRoom(std::shared_ptr<LRoomDOMNode> room)
438440
//This is ensured to exist, but check it anyway
439441
if(roomData.size() != 0)
440442
{
443+
mCurrentRooms.push_back(room);
441444
mCurrentRooms = roomData.front()->GetAdjacencyList();
442-
445+
443446
mRoomDoors = roomData.front()->GetDoorList();
444447

445448
for (std::weak_ptr<LRoomDOMNode>& adjacentRoomRef : roomData.front()->GetAdjacencyList())

src/ui/BooldozerApp.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,23 @@ void LBooldozerApp::RenderUI(float deltaTime) {
182182
// Menu bar
183183
if (ImGui::BeginMainMenuBar())
184184
{
185-
if (ImGui::BeginMenu("File"))
185+
if (ImGui::BeginMenu("Map"))
186186
{
187-
if (ImGui::MenuItem("Open Map..."))
187+
if (ImGui::MenuItem("Open..."))
188188
mEditorContext.onOpenMapCB();
189-
if (ImGui::MenuItem("Append Map..."))
189+
if (ImGui::MenuItem("Append..."))
190190
mEditorContext.onAppendMapCB();
191191

192192
ImGui::Separator();
193+
if (ImGui::MenuItem("Clear..."))
194+
mEditorContext.onClearMapCB();
193195

194-
if (ImGui::MenuItem("Save Map..."))
196+
ImGui::Separator();
197+
198+
if (ImGui::MenuItem("Save..."))
195199
mEditorContext.onSaveMapArchiveCB();
196200

201+
197202
ImGui::EndMenu();
198203
}
199204
if (ImGui::BeginMenu("Edit"))

src/ui/BooldozerEditor.cpp

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "DOM/CameraAnimationDOMNode.hpp"
2828
#include "scene/ModelViewer.hpp"
29+
#include <format>
2930

3031
namespace {
3132
char* patchErrorMsg { nullptr };
@@ -189,6 +190,119 @@ void LBooldozerEditor::Render(float dt, LEditorScene* renderer_scene)
189190
ImGui::EndPopup();
190191
}
191192

193+
if(mClickedMapSelect){
194+
ImGui::OpenPopup("Map Select");
195+
mClickedMapSelect = false;
196+
}
197+
198+
if(mClickedMapClear){
199+
ImGui::OpenPopup("Clear Map");
200+
mClickedMapClear = false;
201+
}
202+
203+
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
204+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
205+
ImGui::SetNextWindowSize({ImGui::GetMainViewport()->Size.x * 0.25, ImGui::GetMainViewport()->Size.y * 0.75}, ImGuiCond_Appearing);
206+
if (ImGui::BeginPopupModal("Map Select", NULL, ImGuiWindowFlags_AlwaysAutoResize))
207+
{
208+
for(int x = 0; x <= 13; x++){
209+
ImGui::BeginChild(std::format("##map{}Select", x).data(), ImVec2(ImGui::GetContentRegionAvail().x, 80.0f), ImGuiChildFlags_Border);
210+
if(ImGui::IsWindowHovered()){
211+
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10);
212+
if(ImGui::IsMouseClicked(ImGuiMouseButton_Left)){
213+
ImGui::CloseCurrentPopup();
214+
GetSelectionManager()->ClearSelection();
215+
renderer_scene->Clear();
216+
217+
loadLock.lock();
218+
mapLoading = true;
219+
loadLock.unlock();
220+
221+
mapOperationThread = std::thread(&LBooldozerEditor::LoadMap, std::ref(*this), (std::filesystem::path(OPTIONS.mRootPath) / "files" / "Map" / std::format("map{}.szp", x)).string(), renderer_scene);
222+
ImGui::OpenPopup("Loading Map");
223+
}
224+
}
225+
// TODO: thumbnails - from starforge
226+
//uint32_t imgId = mCurrentProject->GetThumbnail(galaxy["internalName"].get<std::string>());
227+
//if(imgId != 0xFFFFFFFF){
228+
// ImGui::Image((ImTextureID)imgId, ImVec2(84, 64));
229+
//} else {
230+
// ImGui::Image((ImTextureID)mProjImageID, ImVec2(64, 64));
231+
//}
232+
ImGui::SameLine();
233+
ImGui::BeginGroup();
234+
ImGui::Text(std::format("Map {}", x).data()); // map config? so they can be named?
235+
ImGui::EndGroup();
236+
ImGui::EndChild();
237+
}
238+
ImGui::EndPopup();
239+
}
240+
241+
center = ImGui::GetMainViewport()->GetCenter();
242+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
243+
if (ImGui::BeginPopupModal("Clear Map", NULL, ImGuiWindowFlags_AlwaysAutoResize))
244+
{
245+
ImGui::Text("You are about to clear *everything* from this map, including all room archives, are you sure?");
246+
247+
ImGui::Separator();
248+
if (ImGui::Button("Yes")) {
249+
renderer_scene->Clear();
250+
auto rooms = mLoadedMap->GetChildrenOfType<LRoomDOMNode>(EDOMNodeType::Room);
251+
252+
std::shared_ptr<LRoomDOMNode> newRoom = std::make_shared<LRoomDOMNode>("Room 0");
253+
std::shared_ptr<LRoomDataDOMNode> newRoomData = std::make_shared<LRoomDataDOMNode>("Room 0");
254+
255+
std::string resourcePathRoot = std::filesystem::path(rooms[0]->GetChildrenOfType<LRoomDataDOMNode>(EDOMNodeType::RoomData)[0]->GetResourcePath()).parent_path().string();
256+
newRoomData->SetRoomResourcePath(std::format("{}/room_00.arc", resourcePathRoot));
257+
258+
std::string resPathInRoot = std::format("{}/{}{}", OPTIONS.mRootPath, "files", newRoomData->GetResourcePath());
259+
260+
for(auto room : rooms){
261+
mLoadedMap->RemoveChild(room);
262+
}
263+
264+
for(auto door : mLoadedMap->GetChildrenOfType<LDoorDOMNode>(EDOMNodeType::Door)){
265+
mLoadedMap->RemoveChild(door);
266+
}
267+
268+
// Clear all room resources
269+
std::filesystem::remove_all(std::filesystem::path(resPathInRoot).parent_path());
270+
271+
if(!std::filesystem::exists(std::filesystem::path(resPathInRoot).parent_path())){
272+
std::filesystem::create_directories(std::filesystem::path(resPathInRoot).parent_path());
273+
}
274+
275+
std::cout << "[Editor]: Room resource path " << resPathInRoot << std::endl;
276+
if(!std::filesystem::exists(resPathInRoot)){
277+
std::shared_ptr<Archive::Rarc> arc = Archive::Rarc::Create();
278+
std::shared_ptr<Archive::Folder> root = Archive::Folder::Create(arc);
279+
arc->SetRoot(root);
280+
// now before save, construct as path to replace directory seperators with proper system seps
281+
arc->SaveToFile(std::filesystem::path(resPathInRoot).string());
282+
}
283+
284+
// Setup default room
285+
newRoomData->SetRoomID(0);
286+
newRoomData->SetRoomIndex(0);
287+
288+
newRoomData->SetMin({-550, 0, 0});
289+
newRoomData->SetMax({550, 500, 800});
290+
newRoom->AddChild(newRoomData);
291+
newRoom->SetRoomNumber(0);
292+
newRoomData->GetAdjacencyList().push_back(newRoom);
293+
294+
mLoadedMap->AddChild(newRoom);
295+
296+
ImGui::CloseCurrentPopup();
297+
}
298+
299+
ImGui::SameLine();
300+
if (ImGui::Button("No")) {
301+
ImGui::CloseCurrentPopup();
302+
}
303+
ImGui::EndPopup();
304+
}
305+
192306
if (ImGui::BeginPopupModal("Unpatched DOL", NULL, ImGuiWindowFlags_AlwaysAutoResize))
193307
{
194308
ImGui::Text("This root has a clean DOL. Certain edits will not be reflected in game!");
@@ -255,7 +369,7 @@ void LBooldozerEditor::Render(float dt, LEditorScene* renderer_scene)
255369
ImGui::EndPopup();
256370
}
257371

258-
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
372+
center = ImGui::GetMainViewport()->GetCenter();
259373
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
260374
if (ImGui::BeginPopupModal("Loading Map", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar))
261375
{
@@ -487,11 +601,17 @@ void LBooldozerEditor::SaveMapToArchive(std::string file_path){
487601
void LBooldozerEditor::onOpenMapCB()
488602
{
489603
ImGuiFileDialog::Instance()->OpenDialog("OpenMapDlg", "Open map archive", "Archives (*.arc *.szs *.szp){.arc,.szs,.szp}", OPTIONS.mLastOpenedMap);
604+
//mClickedMapSelect = true;
490605
}
491606

492607
void LBooldozerEditor::onAppendMapCB()
493608
{
494-
ImGuiFileDialog::Instance()->OpenDialog("AppendMapDlg", "Open map archive", "Archives (*.arc *.szs *.szp){.arc,.szs,.szp}", OPTIONS.mLastOpenedMap);
609+
ImGuiFileDialog::Instance()->OpenDialog("AppendMapDlg", "Append Map Archive to Current Map", "Archives (*.arc *.szs *.szp){.arc,.szs,.szp}", OPTIONS.mLastOpenedMap);
610+
}
611+
612+
void LBooldozerEditor::onClearMapCB()
613+
{
614+
mClickedMapClear = true;
495615
}
496616

497617
void LBooldozerEditor::onOpenRoomsCB()

0 commit comments

Comments
 (0)