metaforce/Runtime/ImGuiConsole.cpp

1514 lines
61 KiB
C++
Raw Normal View History

2021-05-25 16:24:05 +00:00
#include "ImGuiConsole.hpp"
#include "../version.h"
#include "MP1/MP1.hpp"
2021-05-27 04:56:25 +00:00
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/World/CPlayer.hpp"
2021-05-25 16:24:05 +00:00
2021-05-27 04:56:25 +00:00
#include "ImGuiEngine.hpp"
2021-05-31 00:50:24 +00:00
#include "magic_enum.hpp"
2021-05-25 16:24:05 +00:00
2021-05-29 06:04:02 +00:00
namespace ImGui {
// Internal functions
void ClearIniSettings();
} // namespace ImGui
2021-05-29 06:04:02 +00:00
2021-05-25 16:24:05 +00:00
#include "TCastTo.hpp" // Generated file, do not modify include path
namespace metaforce {
2021-05-27 04:56:25 +00:00
std::array<ImGuiEntityEntry, 1024> ImGuiConsole::entities;
2021-05-26 16:23:44 +00:00
std::set<TUniqueId> ImGuiConsole::inspectingEntities;
2021-05-31 05:14:07 +00:00
ImGuiPlayerLoadouts ImGuiConsole::loadouts;
2021-05-25 16:24:05 +00:00
2021-05-27 16:57:50 +00:00
void ImGuiStringViewText(std::string_view text) {
// begin()/end() do not work on MSVC
ImGui::TextUnformatted(text.data(), text.data() + text.size());
}
2021-05-25 19:58:18 +00:00
2021-05-27 04:56:25 +00:00
void ImGuiTextCenter(std::string_view text) {
ImGui::NewLine();
float fontSize = ImGui::GetFontSize() * float(text.size()) / 2;
2021-05-27 04:56:25 +00:00
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - fontSize + fontSize / 2);
ImGuiStringViewText(text);
}
2021-05-25 19:58:18 +00:00
2021-05-27 04:56:25 +00:00
static std::unordered_map<CAssetId, std::unique_ptr<CDummyWorld>> dummyWorlds;
static std::unordered_map<CAssetId, TCachedToken<CStringTable>> stringTables;
2021-05-25 19:58:18 +00:00
std::string ImGuiLoadStringTable(CAssetId stringId, int idx) {
2021-05-31 00:29:27 +00:00
if (!stringId.IsValid()) {
return ""s;
}
if (!stringTables.contains(stringId)) {
stringTables[stringId] = g_SimplePool->GetObj(SObjectTag{SBIG('STRG'), stringId});
}
2021-05-31 00:50:24 +00:00
return hecl::Char16ToUTF8(stringTables[stringId].GetObj()->GetString(idx));
2021-05-31 00:29:27 +00:00
}
2021-05-27 04:56:25 +00:00
static bool ContainsCaseInsensitive(std::string_view str, std::string_view val) {
return std::search(str.begin(), str.end(), val.begin(), val.end(),
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }) != str.end();
}
static std::vector<std::pair<std::string, CAssetId>> ListWorlds() {
2021-05-25 19:58:18 +00:00
std::vector<std::pair<std::string, CAssetId>> worlds;
for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) {
if (!pak->IsWorldPak()) {
continue;
}
CAssetId worldId = pak->GetMLVLId();
if (!dummyWorlds.contains(worldId)) {
dummyWorlds[worldId] = std::make_unique<CDummyWorld>(worldId, false);
}
auto& world = dummyWorlds[worldId];
bool complete = world->ICheckWorldComplete();
if (!complete) {
continue;
}
CAssetId stringId = world->IGetStringTableAssetId();
if (!stringId.IsValid()) {
continue;
}
worlds.emplace_back(ImGuiLoadStringTable(stringId, 0), worldId);
2021-05-25 19:58:18 +00:00
}
return worlds;
}
static std::vector<std::pair<std::string, TAreaId>> ListAreas(CAssetId worldId) {
2021-05-25 19:58:18 +00:00
std::vector<std::pair<std::string, TAreaId>> areas;
const auto& world = dummyWorlds[worldId];
2021-05-31 00:50:24 +00:00
for (TAreaId i = 0; i < world->IGetAreaCount(); ++i) {
2021-05-25 19:58:18 +00:00
const auto* area = world->IGetAreaAlways(i);
if (area == nullptr) {
continue;
}
CAssetId stringId = area->IGetStringTableAssetId();
if (!stringId.IsValid()) {
continue;
}
areas.emplace_back(ImGuiLoadStringTable(stringId, 0), i);
2021-05-25 19:58:18 +00:00
}
return areas;
}
2021-05-26 02:49:24 +00:00
static void Warp(const CAssetId worldId, TAreaId aId) {
2021-05-25 19:58:18 +00:00
g_GameState->SetCurrentWorldId(worldId);
g_GameState->GetWorldTransitionManager()->DisableTransition();
if (aId >= g_GameState->CurrentWorldState().GetLayerState()->GetAreaCount()) {
aId = 0;
}
g_GameState->CurrentWorldState().SetAreaId(aId);
g_Main->SetFlowState(EFlowState::None);
2021-05-26 02:49:24 +00:00
if (g_StateManager != nullptr) {
g_StateManager->SetWarping(true);
g_StateManager->SetShouldQuitGame(true);
} else {
// TODO(encounter): warp from menu?
2021-05-26 02:49:24 +00:00
}
2021-05-25 19:58:18 +00:00
}
2021-05-27 04:56:25 +00:00
void ImGuiConsole::ShowMenuGame() {
m_paused = g_Main->IsPaused();
if (ImGui::MenuItem("Paused", "F5", &m_paused)) {
2021-05-27 04:56:25 +00:00
g_Main->SetPaused(m_paused);
2021-05-25 16:24:05 +00:00
}
if (ImGui::MenuItem("Step Frame", "F6", &m_stepFrame, m_paused)) {
2021-05-26 14:00:57 +00:00
g_Main->SetPaused(false);
}
2021-05-26 02:49:24 +00:00
if (ImGui::BeginMenu("Warp", g_StateManager != nullptr && g_ResFactory != nullptr &&
g_ResFactory->GetResLoader() != nullptr)) {
for (const auto& world : ListWorlds()) {
2021-05-25 19:58:18 +00:00
if (ImGui::BeginMenu(world.first.c_str())) {
2021-05-26 02:49:24 +00:00
for (const auto& area : ListAreas(world.second)) {
2021-05-25 19:58:18 +00:00
if (ImGui::MenuItem(area.first.c_str())) {
2021-05-26 02:49:24 +00:00
Warp(world.second, area.second);
2021-05-25 19:58:18 +00:00
}
}
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
2021-05-25 16:24:05 +00:00
if (ImGui::MenuItem("Quit", "Alt+F4")) {
g_Main->Quit();
}
}
void ImGuiConsole::LerpDebugColor(CActor* act) {
2021-05-27 08:30:40 +00:00
if (!act->m_debugSelected && !act->m_debugHovered) {
act->m_debugAddColorTime = 0.f;
act->m_debugAddColor = zeus::skClear;
return;
}
2021-05-31 15:03:41 +00:00
act->m_debugAddColorTime += ImGui::GetIO().DeltaTime;
2021-05-26 15:11:21 +00:00
float lerp = act->m_debugAddColorTime;
if (lerp > 2.f) {
lerp = 0.f;
act->m_debugAddColorTime = 0.f;
} else if (lerp > 1.f) {
lerp = 2.f - lerp;
}
act->m_debugAddColor = zeus::CColor::lerp(zeus::skClear, zeus::skBlue, lerp);
}
void ImGuiConsole::UpdateEntityEntries() {
CObjectList& list = g_StateManager->GetAllObjectList();
s16 uid = list.GetFirstObjectIndex();
while (uid != -1) {
ImGuiEntityEntry& entry = ImGuiConsole::entities[uid];
if (entry.uid == kInvalidUniqueId || entry.ent == nullptr) {
CEntity* ent = list.GetObjectByIndex(uid);
entry.uid = ent->GetUniqueId();
entry.ent = ent;
entry.type = ent->ImGuiType();
entry.name = ent->GetName();
entry.isActor = TCastToPtr<CActor>(ent).IsValid();
} else {
entry.active = entry.ent->GetActive();
}
2021-05-27 08:30:40 +00:00
if (entry.isActor) {
LerpDebugColor(entry.AsActor());
}
2021-05-27 16:27:31 +00:00
entry.ent->m_debugHovered = false;
uid = list.GetNextObjectIndex(uid);
}
}
void ImGuiConsole::BeginEntityRow(const ImGuiEntityEntry& entry) {
ImGui::PushID(entry.uid.Value());
ImGui::TableNextRow();
bool isActive = entry.active;
ImVec4 textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
if (!isActive) {
textColor.w = 0.5f;
}
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
if (ImGui::TableNextColumn()) {
auto text = fmt::format(FMT_STRING("0x{:04X}"), entry.uid.Value());
ImGui::Selectable(text.c_str(), &entry.ent->m_debugSelected,
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap);
2021-05-27 12:25:55 +00:00
if (ImGui::IsItemHovered()) {
entry.ent->m_debugHovered = true;
}
if (ImGui::BeginPopupContextItem(text.c_str())) {
ImGui::PopStyleColor();
if (ImGui::MenuItem(isActive ? "Deactivate" : "Activate")) {
entry.ent->SetActive(!isActive);
}
if (ImGui::MenuItem("Highlight", nullptr, &entry.ent->m_debugSelected)) {
entry.ent->SetActive(!isActive);
}
// Only allow deletion if none of the objects are player related
// The player objects will always be in the first 6 slots
if (entry.uid.Value() > 6) {
ImGui::Separator();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{0.77f, 0.12f, 0.23f, 1.f});
if (ImGui::MenuItem("Delete")) {
g_StateManager->FreeScriptObject(entry.uid);
}
ImGui::PopStyleColor();
}
ImGui::EndPopup();
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
}
}
}
void ImGuiConsole::EndEntityRow(const ImGuiEntityEntry& entry) {
2021-05-30 12:09:33 +00:00
ImGui::PopStyleColor();
if (ImGui::TableNextColumn()) {
if (ImGui::SmallButton("View")) {
ImGuiConsole::inspectingEntities.insert(entry.uid);
}
}
ImGui::PopID();
}
static void RenderEntityColumns(const ImGuiEntityEntry& entry) {
ImGuiConsole::BeginEntityRow(entry);
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(entry.type);
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(entry.name);
}
ImGuiConsole::EndEntityRow(entry);
}
void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
2021-05-30 22:04:44 +00:00
float initialWindowSize = 400.f * ImGui::GetIO().DisplayFramebufferScale.x;
ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize * 1.5f}, ImGuiCond_FirstUseEver);
2021-05-25 16:24:05 +00:00
if (ImGui::Begin("Inspect", isOpen)) {
CObjectList& list = g_StateManager->GetAllObjectList();
2021-05-26 16:23:44 +00:00
ImGui::Text("Objects: %d / 1024", list.size());
2021-05-28 15:57:23 +00:00
ImGui::SameLine();
if (ImGui::SmallButton("Deselect all")) {
for (auto* const ent : list) {
ent->m_debugSelected = false;
2021-05-26 16:23:44 +00:00
}
}
2021-05-28 15:57:23 +00:00
if (ImGui::Button("Clear")) {
m_inspectFilterText.clear();
2021-05-28 15:57:23 +00:00
}
ImGui::SameLine();
ImGui::InputText("Filter", &m_inspectFilterText);
2021-05-27 04:56:25 +00:00
ImGui::Checkbox("Active", &m_inspectActiveOnly);
2021-05-28 15:57:23 +00:00
ImGui::SameLine();
ImGui::Checkbox("Current area", &m_inspectCurrentAreaOnly);
2021-05-26 02:49:24 +00:00
if (ImGui::BeginTable("Entities", 4,
2021-05-25 16:24:05 +00:00
ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_RowBg |
ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupColumn("ID",
ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_DefaultSort |
ImGuiTableColumnFlags_WidthFixed,
0, 'id');
2021-05-26 02:49:24 +00:00
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed, 0, 'type');
2021-05-25 16:24:05 +00:00
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0, 'name');
2021-05-27 05:25:20 +00:00
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed |
ImGuiTableColumnFlags_NoResize);
2021-05-25 16:24:05 +00:00
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow();
ImGuiTableSortSpecs* sortSpecs = ImGui::TableGetSortSpecs();
bool hasSortSpec = sortSpecs != nullptr &&
// no multi-sort
sortSpecs->SpecsCount == 1 &&
// We can skip sorting if we just want uid ascending,
// since that's how we iterate over CObjectList
(sortSpecs->Specs[0].ColumnUserID != 'id' ||
sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending);
if (!m_inspectFilterText.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) {
std::vector<s16> sortedList;
sortedList.reserve(list.size());
s16 uid = list.GetFirstObjectIndex();
2021-05-28 15:57:23 +00:00
auto currAreaId = kInvalidAreaId;
2021-05-31 00:50:24 +00:00
CPlayer* player = nullptr;
2021-05-28 15:57:23 +00:00
if (m_inspectCurrentAreaOnly && (player = g_StateManager->Player()) != nullptr) {
currAreaId = player->GetAreaIdAlways();
}
while (uid != -1) {
ImGuiEntityEntry& entry = ImGuiConsole::entities[uid];
2021-05-28 15:57:23 +00:00
if ((!m_inspectActiveOnly || entry.active) &&
(!m_inspectCurrentAreaOnly || entry.ent->x4_areaId == currAreaId) &&
(m_inspectFilterText.empty() || ContainsCaseInsensitive(entry.type, m_inspectFilterText) ||
ContainsCaseInsensitive(entry.name, m_inspectFilterText))) {
2021-05-28 15:57:23 +00:00
sortedList.push_back(uid);
2021-05-25 16:24:05 +00:00
}
uid = list.GetNextObjectIndex(uid);
2021-05-25 16:24:05 +00:00
}
if (hasSortSpec) {
const auto& spec = sortSpecs->Specs[0];
if (spec.ColumnUserID == 'id') {
if (spec.SortDirection == ImGuiSortDirection_Ascending) {
// no-op
} else {
std::sort(sortedList.begin(), sortedList.end(), [&](s16 a, s16 b) { return a < b; });
}
} else if (spec.ColumnUserID == 'name') {
std::sort(sortedList.begin(), sortedList.end(), [&](s16 a, s16 b) {
int compare = ImGuiConsole::entities[a].name.compare(ImGuiConsole::entities[b].name);
return spec.SortDirection == ImGuiSortDirection_Ascending ? compare < 0 : compare > 0;
});
} else if (spec.ColumnUserID == 'type') {
std::sort(sortedList.begin(), sortedList.end(), [&](s16 a, s16 b) {
int compare = ImGuiConsole::entities[a].type.compare(ImGuiConsole::entities[b].type);
return spec.SortDirection == ImGuiSortDirection_Ascending ? compare < 0 : compare > 0;
});
2021-05-26 15:11:21 +00:00
}
2021-05-25 16:24:05 +00:00
}
for (const auto& item : sortedList) {
RenderEntityColumns(ImGuiConsole::entities[item]);
2021-05-25 16:24:05 +00:00
}
} else {
// Render uid ascending
s16 uid = list.GetFirstObjectIndex();
while (uid != -1) {
RenderEntityColumns(ImGuiConsole::entities[uid]);
uid = list.GetNextObjectIndex(uid);
}
2021-05-25 16:24:05 +00:00
}
2021-05-25 16:24:05 +00:00
ImGui::EndTable();
}
}
2021-05-25 17:56:01 +00:00
ImGui::End();
2021-05-25 16:24:05 +00:00
}
bool ImGuiConsole::ShowEntityInfoWindow(TUniqueId uid) {
2021-05-25 17:56:01 +00:00
bool open = true;
ImGuiEntityEntry& entry = ImGuiConsole::entities[uid.Value()];
2021-05-31 20:11:01 +00:00
if (entry.ent == nullptr) {
return false;
}
auto name = fmt::format(FMT_STRING("{}##0x{:04X}"), !entry.name.empty() ? entry.name : entry.type, uid.Value());
2021-05-25 17:56:01 +00:00
if (ImGui::Begin(name.c_str(), &open, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::PushID(uid.Value());
entry.ent->ImGuiInspect();
2021-05-26 16:23:44 +00:00
ImGui::PopID();
2021-05-25 16:24:05 +00:00
}
2021-05-25 17:56:01 +00:00
ImGui::End();
return open;
2021-05-25 16:24:05 +00:00
}
2021-05-31 00:15:22 +00:00
void ImGuiConsole::ShowConsoleVariablesWindow() {
// For some reason the window shows up tiny without this
float initialWindowSize = 350.f * ImGui::GetIO().DisplayFramebufferScale.x;
ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize}, ImGuiCond_FirstUseEver);
if (ImGui::Begin("Console Variables", &m_showConsoleVariablesWindow)) {
if (ImGui::Button("Clear")) {
m_cvarFiltersText.clear();
2021-05-31 00:15:22 +00:00
}
ImGui::SameLine();
ImGui::InputText("Filter", &m_cvarFiltersText);
2021-05-31 00:15:22 +00:00
auto cvars = m_cvarMgr.cvars(hecl::CVar::EFlags::Any & ~hecl::CVar::EFlags::Hidden);
if (ImGui::BeginTable("ConsoleVariables", 2,
ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_RowBg |
ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupColumn("Name",
ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_DefaultSort |
ImGuiTableColumnFlags_WidthFixed,
0, 'name');
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch, 0, 'val');
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow();
ImGuiTableSortSpecs* sortSpecs = ImGui::TableGetSortSpecs();
bool hasSortSpec = sortSpecs != nullptr &&
// no multi-sort
sortSpecs->SpecsCount == 1;
std::vector<hecl::CVar*> sortedList;
sortedList.reserve(cvars.size());
for (auto* cvar : cvars) {
if (!m_cvarFiltersText.empty()) {
if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), m_cvarFiltersText) ||
ContainsCaseInsensitive(cvar->name(), m_cvarFiltersText)) {
2021-05-31 00:15:22 +00:00
sortedList.push_back(cvar);
}
} else {
sortedList.push_back(cvar);
}
}
if (hasSortSpec) {
const auto& spec = sortSpecs->Specs[0];
if (spec.ColumnUserID == 'name') {
std::sort(sortedList.begin(), sortedList.end(), [&](hecl::CVar* a, hecl::CVar* b) {
int compare = a->name().compare(b->name());
return spec.SortDirection == ImGuiSortDirection_Ascending ? compare < 0 : compare > 0;
});
} else if (spec.ColumnUserID == 'val') {
std::sort(sortedList.begin(), sortedList.end(), [&](hecl::CVar* a, hecl::CVar* b) {
int compare = a->value().compare(b->value());
return spec.SortDirection == ImGuiSortDirection_Ascending ? compare < 0 : compare > 0;
});
}
for (auto* cv : sortedList) {
ImGui::PushID(cv);
ImGui::TableNextRow();
// Name
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(cv->name());
if (ImGui::IsItemHovered() && !cv->rawHelp().empty()) {
std::string sv(cv->rawHelp());
ImGui::SetTooltip("%s", sv.c_str());
}
}
// Value
if (ImGui::TableNextColumn()) {
switch (cv->type()) {
case hecl::CVar::EType::Boolean: {
bool b = cv->toBoolean();
if (ImGui::Checkbox("", &b)) {
cv->fromBoolean(b);
}
break;
}
case hecl::CVar::EType::Real: {
float f = cv->toReal();
if (ImGui::DragFloat("", &f)) {
cv->fromReal(f);
}
break;
}
case hecl::CVar::EType::Signed: {
std::array<s32, 1> i{cv->toSigned()};
if (ImGui::DragScalar("", ImGuiDataType_S32, i.data(), i.size())) {
cv->fromInteger(i[0]);
}
break;
}
case hecl::CVar::EType::Unsigned: {
std::array<u32, 1> i{cv->toUnsigned()};
if (ImGui::DragScalar("", ImGuiDataType_U32, i.data(), i.size())) {
cv->fromInteger(i[0]);
}
break;
}
case hecl::CVar::EType::Literal: {
char buf[4096];
strcpy(buf, cv->value().c_str());
if (ImGui::InputText("", buf, 4096, ImGuiInputTextFlags_EnterReturnsTrue)) {
cv->fromLiteral(buf);
}
break;
}
case hecl::CVar::EType::Vec2f: {
auto vec = cv->toVec2f();
std::array<float, 2> scalars = {vec.simd[0], vec.simd[1]};
if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
cv->fromVec2f(vec);
}
break;
}
case hecl::CVar::EType::Vec2d: {
auto vec = cv->toVec2d();
std::array<double, 2> scalars = {vec.simd[0], vec.simd[1]};
if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
cv->fromVec2d(vec);
}
break;
}
case hecl::CVar::EType::Vec3f: {
auto vec = cv->toVec3f();
std::array<float, 3> scalars = {vec.simd[0], vec.simd[1]};
if (cv->isColor()) {
if (ImGui::ColorEdit3("", scalars.data())) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
cv->fromVec3f(vec);
}
} else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
cv->fromVec3f(vec);
}
break;
}
case hecl::CVar::EType::Vec3d: {
auto vec = cv->toVec3d();
std::array<double, 3> scalars = {vec.simd[0], vec.simd[1], vec.simd[2]};
if (cv->isColor()) {
std::array<float, 3> color{static_cast<float>(scalars[0]), static_cast<float>(scalars[1]),
static_cast<float>(scalars[2])};
if (ImGui::ColorEdit3("", color.data())) {
vec.simd[0] = color[0];
vec.simd[1] = color[1];
vec.simd[2] = color[2];
cv->fromVec3d(vec);
}
} else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
cv->fromVec3d(vec);
}
break;
}
case hecl::CVar::EType::Vec4f: {
auto vec = cv->toVec4f();
std::array<float, 4> scalars = {vec.simd[0], vec.simd[1], vec.simd[2], vec.simd[3]};
if (cv->isColor()) {
if (ImGui::ColorEdit4("", scalars.data())) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
2021-05-31 00:18:43 +00:00
vec.simd[3] = scalars[3];
2021-05-31 00:15:22 +00:00
cv->fromVec4f(vec);
}
} else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
vec.simd[3] = scalars[3];
cv->fromVec4f(vec);
}
break;
}
case hecl::CVar::EType::Vec4d: {
auto vec = cv->toVec4d();
std::array<double, 4> scalars = {vec.simd[0], vec.simd[1], vec.simd[2], vec.simd[3]};
if (cv->isColor()) {
std::array<float, 4> color{static_cast<float>(scalars[0]), static_cast<float>(scalars[1]),
static_cast<float>(scalars[2]), static_cast<float>(scalars[3])};
if (ImGui::ColorEdit4("", color.data())) {
vec.simd[0] = color[0];
vec.simd[1] = color[1];
vec.simd[2] = color[2];
vec.simd[3] = color[3];
cv->fromVec4d(vec);
}
} else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) {
vec.simd[0] = scalars[0];
vec.simd[1] = scalars[1];
vec.simd[2] = scalars[2];
vec.simd[3] = scalars[3];
cv->fromVec4d(vec);
}
break;
}
default:
ImGui::Text("lawl wut? Please contact a developer, your copy of Metaforce is cursed!");
break;
}
if (ImGui::IsItemHovered()) {
2021-05-31 00:15:22 +00:00
std::string sv(cv->defaultValue());
ImGui::SetTooltip("Default: %s", sv.c_str());
}
}
ImGui::PopID();
}
}
ImGui::EndTable();
}
}
ImGui::End();
}
void ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString) {
2021-05-27 04:56:25 +00:00
// Center window
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ImVec4& windowBg = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
ImGui::PushStyleColor(ImGuiCol_TitleBg, windowBg);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, windowBg);
bool* open = nullptr;
ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoSavedSettings;
if (canClose) {
open = &m_showAboutWindow;
} else {
flags |= ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove;
}
if (ImGui::Begin("About", open, flags)) {
2021-05-27 14:47:33 +00:00
float iconSize = 128.f * ImGui::GetIO().DisplayFramebufferScale.x;
2021-05-27 04:56:25 +00:00
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - iconSize + (iconSize / 2));
ImGui::Image(ImGuiUserTextureID_MetaforceIcon, ImVec2{iconSize, iconSize});
ImGui::PushFont(ImGuiEngine::fontLarge);
ImGuiTextCenter("Metaforce");
ImGui::PopFont();
ImGuiTextCenter(METAFORCE_WC_DESCRIBE);
const ImVec2& padding = ImGui::GetStyle().WindowPadding;
ImGui::Dummy(padding);
if (!errorString.empty()) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{0.77f, 0.12f, 0.23f, 1.f});
ImGuiTextCenter(errorString);
ImGui::PopStyleColor();
ImGui::Dummy(padding);
}
2021-05-27 12:25:55 +00:00
ImGuiTextCenter("2015-2021");
2021-05-30 22:04:44 +00:00
ImGui::BeginGroup();
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 200));
ImGuiStringViewText("Development & Research");
ImGui::PopStyleColor();
ImGuiStringViewText("Phillip Stephens (Antidote)");
ImGuiStringViewText("Jack Andersen (jackoalan)");
ImGuiStringViewText("Luke Street (encounter)");
ImGuiStringViewText("Lioncache");
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 200));
ImGuiStringViewText("Testing");
ImGui::PopStyleColor();
ImGuiStringViewText("Tom Lube");
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 200));
ImGuiStringViewText("Contributions");
ImGui::PopStyleColor();
ImGuiStringViewText("Darkszero (Profiling)");
ImGuiStringViewText("shio (Flamethrower)");
ImGui::EndGroup();
2021-05-27 04:56:25 +00:00
ImGui::Dummy(padding);
ImGui::Separator();
if (ImGui::BeginTable("Version Info", 2, ImGuiTableFlags_BordersInnerV)) {
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Branch");
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(METAFORCE_WC_BRANCH);
}
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Revision");
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(METAFORCE_WC_REVISION);
}
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Build");
2021-05-27 04:56:25 +00:00
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(METAFORCE_DLPACKAGE);
2021-05-27 04:56:25 +00:00
}
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Date");
2021-05-27 04:56:25 +00:00
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(METAFORCE_WC_DATE);
2021-05-27 04:56:25 +00:00
}
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Type");
2021-05-27 04:56:25 +00:00
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(METAFORCE_BUILD_TYPE);
2021-05-27 04:56:25 +00:00
}
if (g_Main != nullptr) {
ImGui::TableNextRow();
if (ImGui::TableNextColumn()) {
ImGuiStringViewText("Game");
}
if (ImGui::TableNextColumn()) {
ImGuiStringViewText(g_Main->GetVersionString());
}
2021-05-27 12:25:55 +00:00
}
2021-05-27 04:56:25 +00:00
ImGui::EndTable();
}
}
ImGui::End();
ImGui::PopStyleColor(2);
2021-05-27 04:56:25 +00:00
}
2021-05-26 16:23:44 +00:00
2021-05-27 04:56:25 +00:00
void ImGuiConsole::ShowDebugOverlay() {
if (!m_frameCounter && !m_frameRate && !m_inGameTime && !m_roomTimer && !m_playerInfo && !m_areaInfo &&
!m_worldInfo && !m_randomStats && !m_resourceStats && !m_showInput) {
2021-05-27 04:56:25 +00:00
return;
}
ImGuiIO& io = ImGui::GetIO();
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoNav;
if (m_debugOverlayCorner != -1) {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImVec2 workPos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
ImVec2 workSize = viewport->WorkSize;
ImVec2 windowPos;
ImVec2 windowPosPivot;
constexpr float padding = 10.0f;
windowPos.x = (m_debugOverlayCorner & 1) != 0 ? (workPos.x + workSize.x - padding) : (workPos.x + padding);
windowPos.y = (m_debugOverlayCorner & 2) != 0 ? (workPos.y + workSize.y - padding) : (workPos.y + padding);
windowPosPivot.x = (m_debugOverlayCorner & 1) != 0 ? 1.0f : 0.0f;
windowPosPivot.y = (m_debugOverlayCorner & 2) != 0 ? 1.0f : 0.0f;
2021-05-27 04:56:25 +00:00
ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always, windowPosPivot);
windowFlags |= ImGuiWindowFlags_NoMove;
}
ImGui::SetNextWindowBgAlpha(0.65f);
if (ImGui::Begin("Debug Overlay", nullptr, windowFlags)) {
bool hasPrevious = false;
if (m_frameCounter && g_StateManager != nullptr) {
2021-05-27 04:56:25 +00:00
ImGuiStringViewText(fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex()));
hasPrevious = true;
}
if (m_frameRate) {
if (hasPrevious) {
ImGui::Separator();
}
hasPrevious = true;
2021-05-31 00:29:27 +00:00
ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {}\n"), metaforce::CGraphics::GetFPS()));
2021-05-27 04:56:25 +00:00
}
if (m_inGameTime && g_GameState != nullptr) {
2021-05-27 04:56:25 +00:00
if (hasPrevious) {
ImGui::Separator();
}
2021-05-31 00:29:27 +00:00
hasPrevious = true;
2021-05-27 04:56:25 +00:00
double igt = g_GameState->GetTotalPlayTime();
u32 ms = u64(igt * 1000) % 1000;
auto pt = std::div(int(igt), 3600);
2021-05-27 04:56:25 +00:00
ImGuiStringViewText(
fmt::format(FMT_STRING("Play Time: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms));
}
if (m_roomTimer && g_StateManager != nullptr) {
2021-05-27 04:56:25 +00:00
if (hasPrevious) {
ImGui::Separator();
}
2021-05-31 00:29:27 +00:00
hasPrevious = true;
2021-05-27 04:56:25 +00:00
double igt = g_GameState->GetTotalPlayTime();
double currentRoomTime = igt - m_currentRoomStart;
u32 curFrames = u32(std::round(u32(currentRoomTime * 60)));
u32 lastFrames = u32(std::round(u32(m_lastRoomTime * 60)));
ImGuiStringViewText(fmt::format(FMT_STRING("Room Time: {:7.3f} / {:5d} | Last Room:{:7.3f} / {:5d}\n"),
currentRoomTime, curFrames, m_lastRoomTime, lastFrames));
}
if (m_playerInfo && g_StateManager != nullptr && g_StateManager->Player() != nullptr) {
2021-05-27 04:56:25 +00:00
if (hasPrevious) {
ImGui::Separator();
}
2021-05-31 00:29:27 +00:00
hasPrevious = true;
2021-05-27 04:56:25 +00:00
const CPlayer& pl = g_StateManager->GetPlayer();
const zeus::CQuaternion plQ = zeus::CQuaternion(pl.GetTransform().getRotation().buildMatrix3f());
const zeus::CTransform camXf = g_StateManager->GetCameraManager()->GetCurrentCameraTransform(*g_StateManager);
const zeus::CQuaternion camQ = zeus::CQuaternion(camXf.getRotation().buildMatrix3f());
ImGuiStringViewText(
fmt::format(FMT_STRING("Player Position x: {: .2f}, y: {: .2f}, z: {: .2f}\n"
" Roll: {: .2f}, Pitch: {: .2f}, Yaw: {: .2f}\n"
" Momentum x: {: .2f}, y: {: .2f}, z: {: .2f}\n"
" Velocity x: {: .2f}, y: {: .2f}, z: {: .2f}\n"
"Camera Position x: {: .2f}, y: {: .2f}, z {: .2f}\n"
" Roll: {: .2f}, Pitch: {: .2f}, Yaw: {: .2f}\n"),
pl.GetTranslation().x(), pl.GetTranslation().y(), pl.GetTranslation().z(),
zeus::radToDeg(plQ.roll()), zeus::radToDeg(plQ.pitch()), zeus::radToDeg(plQ.yaw()),
pl.GetMomentum().x(), pl.GetMomentum().y(), pl.GetMomentum().z(), pl.GetVelocity().x(),
pl.GetVelocity().y(), pl.GetVelocity().z(), camXf.origin.x(), camXf.origin.y(), camXf.origin.z(),
zeus::radToDeg(camQ.roll()), zeus::radToDeg(camQ.pitch()), zeus::radToDeg(camQ.yaw())));
}
if (m_worldInfo && g_StateManager != nullptr) {
2021-05-27 04:56:25 +00:00
if (hasPrevious) {
ImGui::Separator();
}
hasPrevious = true;
2021-05-31 00:29:27 +00:00
const std::string name = ImGuiLoadStringTable(g_StateManager->GetWorld()->IGetStringTableAssetId(), 0);
2021-05-31 00:29:27 +00:00
ImGuiStringViewText(
fmt::format(FMT_STRING("World Asset ID: 0x{}, Name: {}\n"), g_GameState->CurrentWorldAssetId(), name));
2021-05-27 04:56:25 +00:00
}
if (m_areaInfo && g_StateManager != nullptr) {
2021-05-27 04:56:25 +00:00
const metaforce::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId();
if (g_StateManager->GetWorld() != nullptr && g_StateManager->GetWorld()->DoesAreaExist(aId)) {
2021-05-31 00:29:27 +00:00
if (hasPrevious) {
ImGui::Separator();
}
hasPrevious = true;
2021-05-27 04:56:25 +00:00
const auto& layerStates = g_GameState->CurrentWorldState().GetLayerState();
std::string layerBits;
u32 totalActive = 0;
for (int i = 0; i < layerStates->GetAreaLayerCount(aId); ++i) {
2021-05-27 04:56:25 +00:00
if (layerStates->IsLayerActive(aId, i)) {
++totalActive;
layerBits += "1";
} else {
layerBits += "0";
}
}
CGameArea* pArea = g_StateManager->GetWorld()->GetArea(aId);
CAssetId stringId = pArea->IGetStringTableAssetId();
2021-05-31 00:29:27 +00:00
ImGuiStringViewText(
fmt::format(FMT_STRING("Area Asset ID: 0x{}, Name: {}\nArea ID: {}, Active Layer bits: {}\n"),
pArea->GetAreaAssetId(), ImGuiLoadStringTable(stringId, 0), pArea->GetAreaId(), layerBits));
2021-05-31 00:29:27 +00:00
}
}
if (m_layerInfo && g_StateManager != nullptr) {
const metaforce::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId();
const auto* world = g_StateManager->GetWorld();
if (world != nullptr && world->DoesAreaExist(aId) && world->GetWorldLayers()) {
if (hasPrevious) {
ImGui::Separator();
}
2021-05-27 04:56:25 +00:00
hasPrevious = true;
2021-05-31 00:29:27 +00:00
ImGuiStringViewText("Area Layers:");
ImVec4 activeColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
ImVec4 inactiveColor = activeColor;
inactiveColor.w = 0.5f;
const CWorldLayers& layers = world->GetWorldLayers().value();
const auto& layerStates = g_GameState->CurrentWorldState().GetLayerState();
2021-05-31 00:50:24 +00:00
int layerCount = int(layerStates->GetAreaLayerCount(aId));
u32 startNameIdx = layers.m_areas[aId].m_startNameIdx;
if (startNameIdx + layerCount > layers.m_names.size()) {
ImGui::Text("Broken layer data, please re-package");
} else {
for (int i = 0; i < layerCount; ++i) {
ImGui::PushStyleColor(ImGuiCol_Text, layerStates->IsLayerActive(aId, i) ? activeColor : inactiveColor);
ImGuiStringViewText(" " + layers.m_names[startNameIdx + i]);
ImGui::PopStyleColor();
}
2021-05-31 00:29:27 +00:00
}
2021-05-27 04:56:25 +00:00
}
}
if (m_randomStats) {
if (hasPrevious) {
ImGui::Separator();
}
2021-05-31 00:29:27 +00:00
hasPrevious = true;
2021-05-27 04:56:25 +00:00
ImGuiStringViewText(
fmt::format(FMT_STRING("CRandom16::Next calls: {}\n"), metaforce::CRandom16::GetNumNextCalls()));
}
if (m_resourceStats) {
if (hasPrevious) {
ImGui::Separator();
}
hasPrevious = true;
2021-05-31 00:29:27 +00:00
ImGuiStringViewText(fmt::format(FMT_STRING("Resource Objects: {}\n"), g_SimplePool->GetLiveObjects()));
2021-05-27 04:56:25 +00:00
}
// Code -stolen- borrowed from Practice Mod
if (m_showInput && g_InputGenerator != nullptr) {
auto input = g_InputGenerator->GetLastInput();
if (input.x4_controllerIdx == 0) {
if (hasPrevious) {
ImGui::Separator();
}
2021-05-31 00:29:27 +00:00
hasPrevious = true;
ImDrawList* dl = ImGui::GetWindowDrawList();
2021-05-30 12:02:45 +00:00
zeus::CVector2f p = ImGui::GetCursorScreenPos();
2021-05-30 12:45:49 +00:00
float scale = ImGui::GetIO().DisplayFramebufferScale.x;
float leftStickRadius = 30 * scale;
p = p + zeus::CVector2f{20, 20} * scale; // Pad p so we don't clip outside our rect
zeus::CVector2f leftStickCenter = p + zeus::CVector2f(30, 45) * scale;
float dpadRadius = 15 * scale;
float dpadWidth = 8 * scale;
zeus::CVector2f dpadCenter = p + zeus::CVector2f(80, 90) * scale;
float rightStickRadius = 20 * scale;
zeus::CVector2f rightStickCenter = p + zeus::CVector2f(160, 90) * scale;
float startButtonRadius = 8 * scale;
zeus::CVector2f startButtonCenter = p + zeus::CVector2f(120, 55) * scale;
float aButtonRadius = 16 * scale;
zeus::CVector2f aButtonCenter = p + zeus::CVector2f(210, 48) * scale;
float bButtonRadius = 8 * scale;
zeus::CVector2f bButtonCenter = aButtonCenter + zeus::CVector2f(-24, 16) * scale;
float xButtonRadius = 8 * scale;
zeus::CVector2f xButtonCenter = aButtonCenter + zeus::CVector2f(24, -16) * scale;
float yButtonRadius = 8 * scale;
zeus::CVector2f yButtonCenter = aButtonCenter + zeus::CVector2f(-12, -24) * scale;
float triggerWidth = leftStickRadius * 2;
float triggerHeight = 8 * scale;
zeus::CVector2f lCenter = leftStickCenter + zeus::CVector2f(0, -60) * scale;
2021-05-30 12:02:45 +00:00
zeus::CVector2f rCenter = zeus::CVector2f(aButtonCenter.x(), lCenter.y());
2021-05-30 12:45:49 +00:00
const auto zButtonCenter = rCenter + zeus::CVector2f{0, 24 * scale};
const float zButtonHalfWidth = triggerWidth / 2;
2021-05-30 12:45:49 +00:00
const float zButtonHalfHeight = 4 * scale;
constexpr ImU32 stickGray = IM_COL32(150, 150, 150, 255);
constexpr ImU32 darkGray = IM_COL32(60, 60, 60, 255);
constexpr ImU32 red = IM_COL32(255, 0, 0, 255);
constexpr ImU32 green = IM_COL32(0, 255, 0, 255);
// left stick
{
dl->AddCircleFilled(leftStickCenter, leftStickRadius, stickGray, 8);
float x = input.ALeftX();
float y = -input.ALeftY();
2021-05-30 12:02:45 +00:00
dl->AddCircleFilled(leftStickCenter + (zeus::CVector2f{x, y} * leftStickRadius), leftStickRadius / 3, red);
2021-05-30 12:05:37 +00:00
dl->AddLine(leftStickCenter, leftStickCenter + zeus::CVector2f(x * leftStickRadius, y * leftStickRadius),
IM_COL32(255, 244, 0, 255), 1.5f);
}
// right stick
{
dl->AddCircleFilled(rightStickCenter, rightStickRadius, stickGray, 8);
float x = input.ARightX();
float y = -input.ARightY();
2021-05-30 12:02:45 +00:00
dl->AddCircleFilled(rightStickCenter + (zeus::CVector2f{x, y} * rightStickRadius), rightStickRadius / 3, red);
2021-05-30 12:05:37 +00:00
dl->AddLine(rightStickCenter, rightStickCenter + zeus::CVector2f(x * rightStickRadius, y * rightStickRadius),
IM_COL32(255, 244, 0, 255), 1.5f);
}
// dpad
{
2021-05-30 12:45:49 +00:00
float halfWidth = dpadWidth / 2;
dl->AddRectFilled(dpadCenter + zeus::CVector2f(-halfWidth, -dpadRadius),
dpadCenter + zeus::CVector2f(halfWidth, dpadRadius), stickGray);
dl->AddRectFilled(dpadCenter + zeus::CVector2f(-dpadRadius, -halfWidth),
dpadCenter + zeus::CVector2f(dpadRadius, halfWidth), stickGray);
if (input.DDPUp()) {
2021-05-30 12:05:37 +00:00
dl->AddRectFilled(dpadCenter + zeus::CVector2f(-halfWidth, -dpadRadius),
dpadCenter + zeus::CVector2f(halfWidth, -dpadRadius / 2), red);
}
if (input.DDPDown()) {
2021-05-30 12:05:37 +00:00
dl->AddRectFilled(dpadCenter + zeus::CVector2f(-halfWidth, dpadRadius),
dpadCenter + zeus::CVector2f(halfWidth, dpadRadius / 2), red);
}
if (input.DDPLeft()) {
2021-05-30 12:05:37 +00:00
dl->AddRectFilled(dpadCenter + zeus::CVector2f(-dpadRadius, -halfWidth),
dpadCenter + zeus::CVector2f(-dpadRadius / 2, halfWidth), red);
}
if (input.DDPRight()) {
2021-05-30 12:05:37 +00:00
dl->AddRectFilled(dpadCenter + zeus::CVector2f(dpadRadius, -halfWidth),
dpadCenter + zeus::CVector2f(dpadRadius / 2, halfWidth), red);
}
}
// buttons
{
// start
dl->AddCircleFilled(startButtonCenter, startButtonRadius, input.DStart() ? red : stickGray);
// a
dl->AddCircleFilled(aButtonCenter, aButtonRadius, input.DA() ? green : stickGray);
// b
dl->AddCircleFilled(bButtonCenter, bButtonRadius, input.DB() ? red : stickGray);
// x
dl->AddCircleFilled(xButtonCenter, xButtonRadius, input.DX() ? red : stickGray);
// y
dl->AddCircleFilled(yButtonCenter, yButtonRadius, input.DY() ? red : stickGray);
// z
2021-05-30 12:05:37 +00:00
dl->AddRectFilled(zButtonCenter - zeus::CVector2f{zButtonHalfWidth, zButtonHalfHeight},
zButtonCenter + zeus::CVector2f{zButtonHalfWidth, zButtonHalfHeight},
input.DZ() ? IM_COL32(128, 0, 128, 255) : stickGray, 16);
}
// triggers
{
float halfTriggerWidth = triggerWidth / 2;
2021-05-30 12:05:37 +00:00
zeus::CVector2f lStart = lCenter - zeus::CVector2f(halfTriggerWidth, 0);
zeus::CVector2f lEnd = lCenter + zeus::CVector2f(halfTriggerWidth, triggerHeight);
float lValue = triggerWidth * input.ALTrigger();
2021-05-30 12:02:45 +00:00
dl->AddRectFilled(lStart, lStart + zeus::CVector2f(lValue, triggerHeight), input.DL() ? red : stickGray);
dl->AddRectFilled(lStart + zeus::CVector2f(lValue, 0), lEnd, darkGray);
2021-05-30 12:05:37 +00:00
zeus::CVector2f rStart = rCenter - zeus::CVector2f(halfTriggerWidth, 0);
zeus::CVector2f rEnd = rCenter + zeus::CVector2f(halfTriggerWidth, triggerHeight);
float rValue = triggerWidth * input.ARTrigger();
2021-05-30 12:02:45 +00:00
dl->AddRectFilled(rEnd - zeus::CVector2f(rValue, triggerHeight), rEnd, input.DR() ? red : stickGray);
dl->AddRectFilled(rStart, rEnd - zeus::CVector2f(rValue, 0), darkGray);
}
2021-05-30 12:45:49 +00:00
ImGui::Dummy(zeus::CVector2f(270, 130) * scale);
}
}
2021-05-27 04:56:25 +00:00
if (ImGui::BeginPopupContextWindow()) {
if (ImGui::MenuItem("Custom", nullptr, m_debugOverlayCorner == -1)) {
m_debugOverlayCorner = -1;
}
if (ImGui::MenuItem("Top-left", nullptr, m_debugOverlayCorner == 0)) {
m_debugOverlayCorner = 0;
}
if (ImGui::MenuItem("Top-right", nullptr, m_debugOverlayCorner == 1)) {
m_debugOverlayCorner = 1;
}
if (ImGui::MenuItem("Bottom-left", nullptr, m_debugOverlayCorner == 2)) {
m_debugOverlayCorner = 2;
}
if (ImGui::MenuItem("Bottom-right", nullptr, m_debugOverlayCorner == 3)) {
m_debugOverlayCorner = 3;
}
ImGui::EndPopup();
}
}
ImGui::End();
}
void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) {
2021-05-25 16:24:05 +00:00
if (ImGui::BeginMainMenuBar()) {
2021-05-25 17:56:01 +00:00
if (ImGui::BeginMenu("Game")) {
ShowMenuGame();
2021-05-25 16:24:05 +00:00
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools")) {
2021-05-31 00:15:22 +00:00
ImGui::MenuItem("Inspect", nullptr, &m_showInspectWindow, canInspect && m_developer);
ImGui::MenuItem("Items", nullptr, &m_showItemsWindow, canInspect && m_developer && m_cheats);
ImGui::MenuItem("Layers", nullptr, &m_showLayersWindow, canInspect && m_developer);
ImGui::MenuItem("Console Variables", nullptr, &m_showConsoleVariablesWindow);
2021-05-27 04:56:25 +00:00
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Debug")) {
if (ImGui::MenuItem("Frame Counter", nullptr, &m_frameCounter)) {
m_cvarCommons.m_debugOverlayShowFrameCounter->fromBoolean(m_frameCounter);
}
if (ImGui::MenuItem("Frame Rate", nullptr, &m_frameRate)) {
m_cvarCommons.m_debugOverlayShowFramerate->fromBoolean(m_frameRate);
}
if (ImGui::MenuItem("In-Game Time", nullptr, &m_inGameTime)) {
m_cvarCommons.m_debugOverlayShowInGameTime->fromBoolean(m_inGameTime);
}
if (ImGui::MenuItem("Room Timer", nullptr, &m_roomTimer)) {
m_cvarCommons.m_debugOverlayShowRoomTimer->fromBoolean(m_roomTimer);
}
if (ImGui::MenuItem("Player Info", nullptr, &m_playerInfo)) {
m_cvarCommons.m_debugOverlayPlayerInfo->fromBoolean(m_playerInfo);
}
if (ImGui::MenuItem("World Info", nullptr, &m_worldInfo)) {
m_cvarCommons.m_debugOverlayWorldInfo->fromBoolean(m_worldInfo);
}
if (ImGui::MenuItem("Area Info", nullptr, &m_areaInfo)) {
m_cvarCommons.m_debugOverlayAreaInfo->fromBoolean(m_areaInfo);
}
2021-05-31 00:29:27 +00:00
if (ImGui::MenuItem("Layer Info", nullptr, &m_layerInfo)) {
m_cvarCommons.m_debugOverlayLayerInfo->fromBoolean(m_layerInfo);
}
2021-05-27 04:56:25 +00:00
if (ImGui::MenuItem("Random Stats", nullptr, &m_randomStats)) {
m_cvarCommons.m_debugOverlayShowRandomStats->fromBoolean(m_randomStats);
}
if (ImGui::MenuItem("Resource Stats", nullptr, &m_resourceStats)) {
m_cvarCommons.m_debugOverlayShowResourceStats->fromBoolean(m_resourceStats);
}
if (ImGui::MenuItem("Show Input", nullptr, &m_showInput)) {
m_cvarCommons.m_debugOverlayShowInput->fromBoolean(m_showInput);
}
2021-05-27 04:56:25 +00:00
ImGui::EndMenu();
}
ImGui::Spacing();
if (ImGui::BeginMenu("Help")) {
ImGui::MenuItem("About", nullptr, &m_showAboutWindow);
2021-05-29 06:04:02 +00:00
ImGui::Separator();
if (ImGui::BeginMenu("ImGui")) {
if (ImGui::MenuItem("Clear Settings")) {
ImGui::ClearIniSettings();
}
ImGui::MenuItem("Show Demo", nullptr, &m_showDemoWindow);
ImGui::EndMenu();
}
2021-05-25 16:24:05 +00:00
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
2021-05-26 16:23:44 +00:00
}
s32 TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast<int>(key); }
void ImGuiConsole::PreUpdate() {
2021-05-31 01:23:20 +00:00
if (!m_isInitialized) {
m_isInitialized = true;
m_cvarCommons.m_debugOverlayShowFrameCounter->addListener(
[this](hecl::CVar* c) { m_frameCounter = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowFramerate->addListener([this](hecl::CVar* c) { m_frameRate = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowInGameTime->addListener([this](hecl::CVar* c) { m_inGameTime = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowRoomTimer->addListener([this](hecl::CVar* c) { m_roomTimer = c->toBoolean(); });
m_cvarCommons.m_debugOverlayPlayerInfo->addListener([this](hecl::CVar* c) { m_playerInfo = c->toBoolean(); });
m_cvarCommons.m_debugOverlayWorldInfo->addListener([this](hecl::CVar* c) { m_worldInfo = c->toBoolean(); });
m_cvarCommons.m_debugOverlayAreaInfo->addListener([this](hecl::CVar* c) { m_areaInfo = c->toBoolean(); });
m_cvarCommons.m_debugOverlayLayerInfo->addListener([this](hecl::CVar* c) { m_layerInfo = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowRandomStats->addListener([this](hecl::CVar* c) { m_randomStats = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowResourceStats->addListener(
[this](hecl::CVar* c) { m_resourceStats = c->toBoolean(); });
m_cvarCommons.m_debugOverlayShowInput->addListener([this](hecl::CVar* c) { m_showInput = c->toBoolean(); });
m_cvarMgr.findCVar("developer")->addListener([this](hecl::CVar* c) { m_developer = c->toBoolean(); });
m_cvarMgr.findCVar("cheats")->addListener([this](hecl::CVar* c) { m_cheats = c->toBoolean(); });
}
// We ned to make sure we have a valid CRandom16 at all times, so lets do that here
2021-05-31 00:15:22 +00:00
if (g_StateManager != nullptr && g_StateManager->GetActiveRandom() == nullptr) {
g_StateManager->SetActiveRandomToDefault();
}
if (ImGui::IsKeyReleased('`')) {
m_isVisible ^= 1;
}
2021-05-27 04:56:25 +00:00
if (m_stepFrame) {
2021-05-26 16:23:44 +00:00
g_Main->SetPaused(true);
2021-05-27 04:56:25 +00:00
m_stepFrame = false;
2021-05-26 16:23:44 +00:00
}
if (m_paused && !m_stepFrame && ImGui::IsKeyPressed(TranslateBooSpecialKey(boo::ESpecialKey::F6))) {
g_Main->SetPaused(false);
m_stepFrame = true;
}
if (ImGui::IsKeyReleased(TranslateBooSpecialKey(boo::ESpecialKey::F5))) {
m_paused ^= 1;
g_Main->SetPaused(m_paused);
}
2021-05-26 16:23:44 +00:00
bool canInspect = g_StateManager != nullptr && g_StateManager->GetObjectList();
if (m_isVisible) {
ShowAppMainMenuBar(canInspect);
2021-05-31 15:03:41 +00:00
} else if (m_developer) {
ShowMenuHint();
}
2021-05-27 04:56:25 +00:00
if (canInspect && (m_showInspectWindow || !inspectingEntities.empty())) {
UpdateEntityEntries();
2021-05-27 04:56:25 +00:00
if (m_showInspectWindow) {
ShowInspectWindow(&m_showInspectWindow);
2021-05-26 02:49:24 +00:00
}
2021-05-25 16:24:05 +00:00
auto iter = inspectingEntities.begin();
while (iter != inspectingEntities.end()) {
if (!ShowEntityInfoWindow(*iter)) {
2021-05-25 16:24:05 +00:00
iter = inspectingEntities.erase(iter);
} else {
iter++;
}
}
}
2021-05-31 00:15:22 +00:00
if (canInspect && m_showItemsWindow && m_cvarMgr.findCVar("cheats")->toBoolean()) {
2021-05-27 14:26:13 +00:00
ShowItemsWindow();
}
2021-05-27 20:55:30 +00:00
if (canInspect && m_showLayersWindow) {
ShowLayersWindow();
}
2021-05-27 04:56:25 +00:00
if (m_showAboutWindow) {
ShowAboutWindow(true);
2021-05-27 04:56:25 +00:00
}
if (m_showDemoWindow) {
ImGui::ShowDemoWindow(&m_showDemoWindow);
}
2021-05-31 00:15:22 +00:00
if (m_showConsoleVariablesWindow) {
ShowConsoleVariablesWindow();
}
2021-05-27 04:56:25 +00:00
ShowDebugOverlay();
}
void ImGuiConsole::PostUpdate() {
if (g_StateManager != nullptr && g_StateManager->GetObjectList()) {
// Clear deleted objects
CObjectList& list = g_StateManager->GetAllObjectList();
for (s16 uid = 0; uid < s16(entities.size()); uid++) {
ImGuiEntityEntry& item = entities[uid];
if (item.uid == kInvalidUniqueId) {
continue; // already cleared
}
CEntity* ent = list.GetObjectByIndex(uid);
if (ent == nullptr || ent != item.ent) {
// Remove inspect windows for deleted entities
inspectingEntities.erase(item.uid);
item.uid = kInvalidUniqueId;
item.ent = nullptr; // for safety
2021-05-26 16:23:44 +00:00
}
}
2021-05-26 02:49:24 +00:00
} else {
entities.fill(ImGuiEntityEntry{});
2021-05-26 02:49:24 +00:00
inspectingEntities.clear();
2021-05-25 16:24:05 +00:00
}
// Always calculate room time regardless of if the overlay is displayed, this allows us have an accurate display if
// the user chooses to display it later on during gameplay
if (g_StateManager && m_currentRoom != g_StateManager->GetCurrentArea()) {
const double igt = g_GameState->GetTotalPlayTime();
m_currentRoom = static_cast<const void*>(g_StateManager->GetCurrentArea());
m_lastRoomTime = igt - m_currentRoomStart;
m_currentRoomStart = igt;
}
2021-05-25 16:24:05 +00:00
}
void ImGuiConsole::Shutdown() {
2021-05-25 19:58:18 +00:00
dummyWorlds.clear();
stringTables.clear();
}
2021-05-27 14:26:13 +00:00
2021-05-27 22:06:45 +00:00
static constexpr std::array GeneralItems{
CPlayerState::EItemType::EnergyTanks, CPlayerState::EItemType::CombatVisor, CPlayerState::EItemType::ScanVisor,
CPlayerState::EItemType::ThermalVisor, CPlayerState::EItemType::XRayVisor, CPlayerState::EItemType::GrappleBeam,
CPlayerState::EItemType::SpaceJumpBoots, CPlayerState::EItemType::PowerSuit, CPlayerState::EItemType::VariaSuit,
CPlayerState::EItemType::GravitySuit, CPlayerState::EItemType::PhazonSuit,
};
static constexpr std::array WeaponItems{
CPlayerState::EItemType::Missiles, CPlayerState::EItemType::PowerBeam, CPlayerState::EItemType::IceBeam,
CPlayerState::EItemType::WaveBeam, CPlayerState::EItemType::PlasmaBeam, CPlayerState::EItemType::SuperMissile,
CPlayerState::EItemType::Flamethrower, CPlayerState::EItemType::IceSpreader, CPlayerState::EItemType::Wavebuster,
2021-05-27 14:26:13 +00:00
CPlayerState::EItemType::ChargeBeam,
};
2021-05-27 22:06:45 +00:00
static constexpr std::array MorphBallItems{
CPlayerState::EItemType::PowerBombs, CPlayerState::EItemType::MorphBall, CPlayerState::EItemType::MorphBallBombs,
CPlayerState::EItemType::BoostBall, CPlayerState::EItemType::SpiderBall,
};
static constexpr std::array ArtifactItems{
CPlayerState::EItemType::Truth, CPlayerState::EItemType::Strength, CPlayerState::EItemType::Elder,
CPlayerState::EItemType::Wild, CPlayerState::EItemType::Lifegiver, CPlayerState::EItemType::Warrior,
CPlayerState::EItemType::Chozo, CPlayerState::EItemType::Nature, CPlayerState::EItemType::Sun,
CPlayerState::EItemType::World, CPlayerState::EItemType::Spirit, CPlayerState::EItemType::Newborn,
};
2021-05-30 22:37:07 +00:00
static constexpr std::array ItemLoadout21Percent{
std::make_pair(CPlayerState::EItemType::PowerSuit, 1), std::make_pair(CPlayerState::EItemType::CombatVisor, 1),
std::make_pair(CPlayerState::EItemType::ScanVisor, 1), std::make_pair(CPlayerState::EItemType::PowerBeam, 1),
std::make_pair(CPlayerState::EItemType::WaveBeam, 1), std::make_pair(CPlayerState::EItemType::IceBeam, 1),
std::make_pair(CPlayerState::EItemType::PlasmaBeam, 1), std::make_pair(CPlayerState::EItemType::XRayVisor, 1),
std::make_pair(CPlayerState::EItemType::Missiles, 5), std::make_pair(CPlayerState::EItemType::VariaSuit, 1),
std::make_pair(CPlayerState::EItemType::PhazonSuit, 1), std::make_pair(CPlayerState::EItemType::MorphBall, 1),
std::make_pair(CPlayerState::EItemType::MorphBallBombs, 1), std::make_pair(CPlayerState::EItemType::PowerBombs, 4),
};
static constexpr std::array ItemLoadoutAnyPercent{
std::make_pair(CPlayerState::EItemType::PowerSuit, 1), std::make_pair(CPlayerState::EItemType::CombatVisor, 1),
std::make_pair(CPlayerState::EItemType::ScanVisor, 1), std::make_pair(CPlayerState::EItemType::EnergyTanks, 3),
std::make_pair(CPlayerState::EItemType::PowerBeam, 1), std::make_pair(CPlayerState::EItemType::WaveBeam, 1),
std::make_pair(CPlayerState::EItemType::IceBeam, 1), std::make_pair(CPlayerState::EItemType::PlasmaBeam, 1),
std::make_pair(CPlayerState::EItemType::ChargeBeam, 1), std::make_pair(CPlayerState::EItemType::XRayVisor, 1),
std::make_pair(CPlayerState::EItemType::ThermalVisor, 1), std::make_pair(CPlayerState::EItemType::Missiles, 25),
std::make_pair(CPlayerState::EItemType::VariaSuit, 1), std::make_pair(CPlayerState::EItemType::PhazonSuit, 1),
std::make_pair(CPlayerState::EItemType::MorphBall, 1), std::make_pair(CPlayerState::EItemType::BoostBall, 1),
std::make_pair(CPlayerState::EItemType::MorphBallBombs, 1), std::make_pair(CPlayerState::EItemType::PowerBombs, 4),
std::make_pair(CPlayerState::EItemType::SpaceJumpBoots, 1),
};
int roundMultiple(int value, int multiple) {
if (multiple == 0) {
return value;
}
return static_cast<int>(std::round(static_cast<double>(value) / static_cast<double>(multiple)) *
static_cast<double>(multiple));
}
2021-05-27 22:06:45 +00:00
static void RenderItemType(CPlayerState& pState, CPlayerState::EItemType itemType) {
u32 maxValue = CPlayerState::GetPowerUpMaxValue(itemType);
std::string name{CPlayerState::ItemTypeToName(itemType)};
if (maxValue == 1) {
bool enabled = pState.GetItemCapacity(itemType) == 1;
if (ImGui::Checkbox(name.c_str(), &enabled)) {
if (enabled) {
pState.ReInitializePowerUp(itemType, 1);
pState.ResetAndIncrPickUp(itemType, 1);
} else {
pState.ReInitializePowerUp(itemType, 0);
}
if (itemType == CPlayerState::EItemType::VariaSuit || itemType == CPlayerState::EItemType::PowerSuit ||
itemType == CPlayerState::EItemType::GravitySuit || itemType == CPlayerState::EItemType::PhazonSuit) {
g_StateManager->Player()->AsyncLoadSuit(*g_StateManager);
}
}
} else if (maxValue > 1) {
2021-05-31 00:50:24 +00:00
int capacity = int(pState.GetItemCapacity(itemType));
int amount = int(pState.GetItemAmount(itemType));
if (ImGui::SliderInt((name + " (Capacity)").c_str(), &capacity, 0, int(maxValue), "%d",
ImGuiSliderFlags_AlwaysClamp)) {
if (itemType == CPlayerState::EItemType::Missiles) {
2021-05-30 23:03:23 +00:00
capacity = roundMultiple(capacity, 5);
}
2021-05-30 23:03:23 +00:00
pState.ReInitializePowerUp(itemType, u32(capacity));
pState.ResetAndIncrPickUp(itemType, u32(capacity));
}
if (capacity > 0) {
if (ImGui::SliderInt((name + " (Amount)").c_str(), &amount, 0, capacity, "%d", ImGuiSliderFlags_AlwaysClamp)) {
2021-05-30 23:03:23 +00:00
if (itemType == CPlayerState::EItemType::Missiles) {
amount = roundMultiple(amount, 5);
}
pState.ResetAndIncrPickUp(itemType, u32(amount));
}
} else {
ImGui::Dummy(ImGui::GetItemRectSize());
2021-05-27 22:06:45 +00:00
}
}
}
template <size_t N>
static inline void RenderItemsDualColumn(CPlayerState& pState, const std::array<CPlayerState::EItemType, N>& items,
int start) {
ImGui::BeginGroup();
// Render left group
for (int i = start; i < items.size(); i += 2) {
RenderItemType(pState, items[i]);
}
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
// Render right group
for (int i = start + 1; i < items.size(); i += 2) {
RenderItemType(pState, items[i]);
}
ImGui::EndGroup();
}
2021-05-27 14:26:13 +00:00
void ImGuiConsole::ShowItemsWindow() {
CPlayerState& pState = *g_StateManager->GetPlayerState();
2021-05-27 22:06:45 +00:00
if (ImGui::Begin("Items", &m_showItemsWindow, ImGuiWindowFlags_AlwaysAutoResize)) {
2021-05-27 14:26:13 +00:00
if (ImGui::Button("Refill")) {
2021-05-27 22:06:45 +00:00
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
auto itemType = static_cast<CPlayerState::EItemType>(i);
2021-05-27 14:26:13 +00:00
u32 maxValue = CPlayerState::GetPowerUpMaxValue(itemType);
pState.ResetAndIncrPickUp(itemType, maxValue);
}
}
2021-05-27 15:56:32 +00:00
auto& mapWorldInfo = *g_GameState->CurrentWorldState().MapWorldInfo();
ImGui::SameLine();
bool mapStationUsed = mapWorldInfo.GetMapStationUsed();
if (ImGui::Checkbox("Area map", &mapStationUsed)) {
mapWorldInfo.SetMapStationUsed(mapStationUsed);
2021-05-27 14:26:13 +00:00
}
if (ImGui::Button("All")) {
2021-05-27 22:06:45 +00:00
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
auto itemType = static_cast<CPlayerState::EItemType>(i);
2021-05-27 14:26:13 +00:00
u32 maxValue = CPlayerState::GetPowerUpMaxValue(itemType);
pState.ReInitializePowerUp(itemType, maxValue);
pState.ResetAndIncrPickUp(itemType, maxValue);
}
2021-05-27 15:56:32 +00:00
mapWorldInfo.SetMapStationUsed(true);
2021-05-27 14:26:13 +00:00
}
ImGui::SameLine();
if (ImGui::Button("None")) {
2021-05-27 22:06:45 +00:00
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
auto itemType = static_cast<CPlayerState::EItemType>(i);
2021-05-27 14:26:13 +00:00
pState.ReInitializePowerUp(itemType, 0);
}
2021-05-27 15:56:32 +00:00
mapWorldInfo.SetMapStationUsed(false);
2021-05-27 14:26:13 +00:00
}
2021-05-30 22:37:07 +00:00
ImGui::SameLine();
if (ImGui::Button("21%")) {
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
auto itemType = static_cast<CPlayerState::EItemType>(i);
pState.ReInitializePowerUp(itemType, 0);
}
mapWorldInfo.SetMapStationUsed(false);
for (const auto& [item, count] : ItemLoadout21Percent) {
pState.ReInitializePowerUp(item, count);
pState.IncrPickup(item, count);
}
for (const auto& item : ArtifactItems) {
pState.ReInitializePowerUp(item, 1);
}
}
ImGui::SameLine();
if (ImGui::Button("Any%")) {
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
auto itemType = static_cast<CPlayerState::EItemType>(i);
pState.ReInitializePowerUp(itemType, 0);
}
mapWorldInfo.SetMapStationUsed(false);
for (const auto& [item, count] : ItemLoadoutAnyPercent) {
pState.ReInitializePowerUp(item, count);
pState.IncrPickup(item, count);
}
for (const auto& item : ArtifactItems) {
pState.ReInitializePowerUp(item, 1);
}
}
2021-05-27 22:06:45 +00:00
if (ImGui::BeginTabBar("Items")) {
if (ImGui::BeginTabItem("General")) {
RenderItemType(pState, GeneralItems[0]); // full width
RenderItemsDualColumn(pState, GeneralItems, 1);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Weapons")) {
RenderItemType(pState, WeaponItems[0]); // full width
RenderItemsDualColumn(pState, WeaponItems, 1);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Morph Ball")) {
RenderItemType(pState, MorphBallItems[0]); // full width
RenderItemsDualColumn(pState, MorphBallItems, 1);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Artifacts")) {
2021-05-27 22:16:19 +00:00
ImGui::Text("NOTE: This doesn't affect Artifact Temple layers");
ImGui::Text("Use the Layers window to set them for progression");
2021-05-27 22:06:45 +00:00
RenderItemsDualColumn(pState, ArtifactItems, 0);
ImGui::EndTabItem();
2021-05-27 14:26:13 +00:00
}
2021-05-27 22:06:45 +00:00
ImGui::EndTabBar();
2021-05-27 14:26:13 +00:00
}
}
ImGui::End();
}
2021-05-27 20:55:30 +00:00
void ImGuiConsole::ShowLayersWindow() {
2021-05-27 22:25:33 +00:00
// For some reason the window shows up tiny without this
2021-05-29 05:40:04 +00:00
float initialWindowSize = 350.f * ImGui::GetIO().DisplayFramebufferScale.x;
2021-05-27 22:25:33 +00:00
ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize}, ImGuiCond_FirstUseEver);
2021-05-27 20:55:30 +00:00
if (ImGui::Begin("Layers", &m_showLayersWindow)) {
2021-05-29 05:40:04 +00:00
if (ImGui::Button("Clear")) {
m_layersFilterText.clear();
2021-05-29 05:40:04 +00:00
}
ImGui::SameLine();
ImGui::InputText("Filter", &m_layersFilterText);
bool hasSearch = !m_layersFilterText.empty();
if (hasSearch) {
2021-05-29 05:40:04 +00:00
// kinda hacky way reset the tree state when search changes
ImGui::PushID(m_layersFilterText.c_str());
2021-05-29 05:40:04 +00:00
}
2021-05-27 20:55:30 +00:00
for (const auto& world : ListWorlds()) {
const auto& layers = dummyWorlds[world.second]->GetWorldLayers();
if (!layers) {
continue;
}
2021-05-27 21:24:08 +00:00
2021-05-29 05:40:04 +00:00
auto worldLayerState = g_GameState->StateForWorld(world.second).GetLayerState();
auto areas = ListAreas(world.second);
auto iter = areas.begin();
while (iter != areas.end()) {
if (hasSearch && !ContainsCaseInsensitive(iter->first, m_layersFilterText)) {
2021-05-29 05:40:04 +00:00
iter = areas.erase(iter);
} else {
iter++;
}
}
if (areas.empty()) {
continue;
}
2021-05-27 20:55:30 +00:00
if (ImGui::TreeNodeEx(world.first.c_str(), hasSearch ? ImGuiTreeNodeFlags_DefaultOpen : 0)) {
2021-05-29 05:40:04 +00:00
for (const auto& area : areas) {
2021-05-27 20:55:30 +00:00
u32 layerCount = worldLayerState->GetAreaLayerCount(area.second);
if (layerCount == 0) {
continue;
}
if (ImGui::TreeNode(area.first.c_str())) {
2021-05-29 05:40:04 +00:00
if (ImGui::Button("Warp here")) {
Warp(world.second, area.second);
}
u32 startNameIdx = layers->m_areas[area.second].m_startNameIdx;
if (startNameIdx + layerCount > layers->m_names.size()) {
ImGui::Text("Broken layer data, please re-package");
} else {
2021-05-31 00:50:24 +00:00
for (int layer = 0; layer < layerCount; ++layer) {
bool active = worldLayerState->IsLayerActive(area.second, layer);
if (ImGui::Checkbox(layers->m_names[startNameIdx + layer].c_str(), &active)) {
worldLayerState->SetLayerActive(area.second, layer, active);
}
2021-05-27 20:55:30 +00:00
}
}
ImGui::TreePop();
}
}
ImGui::TreePop();
}
}
if (hasSearch) {
2021-05-29 05:40:04 +00:00
ImGui::PopID();
}
2021-05-27 20:55:30 +00:00
}
ImGui::End();
}
2021-05-31 15:03:41 +00:00
void ImGuiConsole::ShowMenuHint() {
if (m_menuHintTime <= 0.f) {
return;
}
m_menuHintTime -= ImGui::GetIO().DeltaTime;
const ImGuiViewport* viewport = ImGui::GetMainViewport();
2021-05-31 15:13:22 +00:00
const ImVec2 workPos = viewport->WorkPos;
const ImVec2 workSize = viewport->WorkSize;
2021-05-31 15:03:41 +00:00
constexpr float padding = 10.0f;
2021-05-31 15:13:22 +00:00
const ImVec2 windowPos{workPos.x + workSize.x / 2, workPos.y + workSize.y - padding};
ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always, ImVec2{0.5f, 1.f});
2021-05-31 15:03:41 +00:00
2021-05-31 15:13:22 +00:00
const float alpha = std::min(m_menuHintTime, 1.f);
2021-05-31 15:03:41 +00:00
ImGui::SetNextWindowBgAlpha(alpha * 0.65f);
ImVec4 textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
textColor.w *= alpha;
ImVec4 borderColor = ImGui::GetStyleColorVec4(ImGuiCol_Border);
borderColor.w *= alpha;
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
ImGui::PushStyleColor(ImGuiCol_Border, borderColor);
if (ImGui::Begin("Menu Hint", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove)) {
2021-05-31 15:13:22 +00:00
ImGuiStringViewText("Press ` to toggle menu"sv);
2021-05-31 15:03:41 +00:00
}
ImGui::End();
ImGui::PopStyleColor(2);
}
2021-05-26 02:49:24 +00:00
} // namespace metaforce