Skip to content

Commit

Permalink
Minor Actor Viewer tweaks and fixes (#491)
Browse files Browse the repository at this point in the history
* Show new Actor description, fix window opening

* Play error sound when spawning invalid actor

* Add reset button, don't reset actor when changing scene
  • Loading branch information
ajanhallinta authored Jun 20, 2022
1 parent b56426a commit 950f954
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions soh/soh/Enhancements/debugger/actorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <bit>
#include <map>
#include <string>
#include <Cvar.h>

extern "C" {
#include <z64.h>
Expand Down Expand Up @@ -483,7 +484,7 @@ std::map<u16, const char*> actorDescriptions = {
};

const std::string GetActorDescription(u16 id) {
return actorDescriptions[id];
return actorDescriptions[id] != NULL ? actorDescriptions[id] : "???";
}

template <typename T> void DrawGroupWithBorder(T&& drawFunc) {
Expand Down Expand Up @@ -530,6 +531,7 @@ void PopulateActorDropdown(int i, std::vector<Actor*>& data) {

void DrawActorViewer(bool& open) {
if (!open) {
CVar_SetS32("gActorViewerEnabled", 0);
return;
}

Expand Down Expand Up @@ -559,7 +561,6 @@ void DrawActorViewer(bool& open) {
display = empty;
fetch = nullptr;
dispOverlay = nullptr;
newActor = { 0, 0, { 0, 0, 0 }, { 0, 0, 0 } };
actor = category = 0;
filler = "Please Select";
list.clear();
Expand Down Expand Up @@ -696,6 +697,7 @@ void DrawActorViewer(bool& open) {
if (ImGui::TreeNode("New...")) {
ImGui::PushItemWidth(ImGui::GetFontSize() * 10);

ImGui::Text(GetActorDescription(newActor.id).c_str());
ImGui::InputScalar("ID", ImGuiDataType_S16, &newActor.id, &one);
ImGui::InputScalar("params", ImGuiDataType_S16, &newActor.params, &one);

Expand Down Expand Up @@ -728,27 +730,39 @@ void DrawActorViewer(bool& open) {
}

if (ImGui::Button("Spawn")) {
Actor_Spawn(&gGlobalCtx->actorCtx, gGlobalCtx, newActor.id, newActor.pos.x, newActor.pos.y,
newActor.pos.z, newActor.rot.x, newActor.rot.y, newActor.rot.z, newActor.params);
if (newActor.id >= 0 && newActor.id < ACTOR_ID_MAX && gActorOverlayTable[newActor.id].initInfo != NULL) {
Actor_Spawn(&gGlobalCtx->actorCtx, gGlobalCtx, newActor.id, newActor.pos.x, newActor.pos.y,
newActor.pos.z, newActor.rot.x, newActor.rot.y, newActor.rot.z, newActor.params);
} else {
func_80078884(NA_SE_SY_ERROR);
}
}

if (ImGui::Button("Spawn as Child")) {
Actor* parent = &display;
if (parent != NULL) {
Actor_SpawnAsChild(&gGlobalCtx->actorCtx, parent, gGlobalCtx, newActor.id, newActor.pos.x,
newActor.pos.y, newActor.pos.z, newActor.rot.x, newActor.rot.y, newActor.rot.z,
newActor.params);
if (newActor.id >= 0 && newActor.id < ACTOR_ID_MAX &&
gActorOverlayTable[newActor.id].initInfo != NULL) {
Actor_SpawnAsChild(&gGlobalCtx->actorCtx, parent, gGlobalCtx, newActor.id, newActor.pos.x,
newActor.pos.y, newActor.pos.z, newActor.rot.x, newActor.rot.y,
newActor.rot.z, newActor.params);
} else {
func_80078884(NA_SE_SY_ERROR);
}
}
}

if (ImGui::Button("Reset")) {
newActor = { 0, 0, { 0, 0, 0 }, { 0, 0, 0 } };
}

ImGui::TreePop();
}
} else {
ImGui::Text("Global Context needed for actor info!");
if (needs_reset) {
fetch = nullptr;
dispOverlay = nullptr;
newActor = { 0, 0, { 0, 0, 0 }, { 0, 0, 0 } };
actor = category = 0;
filler = "Please Select";
list.clear();
Expand Down

0 comments on commit 950f954

Please sign in to comment.