/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "common/debug-channels.h"
#include "imgui/imgui.h"
#include "twp/twp.h"
#include "twp/debugtools.h"
#include "twp/thread.h"
#include "twp/lighting.h"
#include "twp/squtil.h"
namespace Twp {
static struct {
bool _showThreads = false;
bool _showObjects = false;
bool _showStack = false;
bool _showAudio = false;
bool _showResources = false;
bool _showScenegraph = false;
bool _showActor = false;
Node *_node = nullptr;
ImGuiTextFilter _objFilter;
ImGuiTextFilter _actorFilter;
int _fadeEffect = 0;
float _fadeDuration = 0.f;
bool _fadeToSepia = false;
Common::String _textureSelected;
int _selectedActor = 0;
} state;
ImVec4 gray(0.6f, 0.6f, 0.6f, 1.f);
static void drawThreads() {
if (!state._showThreads)
return;
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
const auto &threads = g_twp->_threads;
if (ImGui::Begin("Threads", &state._showThreads)) {
ImGui::Text("# threads: %u", threads.size());
ImGui::Separator();
if (ImGui::BeginTable("Threads", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Id");
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("Func");
ImGui::TableSetupColumn("Src");
ImGui::TableSetupColumn("Line");
ImGui::TableHeadersRow();
if (g_twp->_cutscene) {
Common::SharedPtr thread(g_twp->_cutscene);
SQStackInfos infos;
sq_stackinfos(thread->getThread(), 0, &infos);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%5d", thread->getId());
ImGui::TableNextColumn();
ImGui::Text("%-56s", thread->getName().c_str());
ImGui::TableNextColumn();
ImGui::Text("%-6s", "cutscene");
ImGui::TableNextColumn();
ImGui::Text("%-9s", infos.funcname);
ImGui::TableNextColumn();
ImGui::Text("%-9s", infos.source);
ImGui::TableNextColumn();
ImGui::Text("%5lld", infos.line);
}
for (const auto &thread : threads) {
SQStackInfos infos;
sq_stackinfos(thread->getThread(), 0, &infos);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%5d", thread->getId());
ImGui::TableNextColumn();
ImGui::Text("%-56s", thread->getName().c_str());
ImGui::TableNextColumn();
ImGui::Text("%-6s", thread->isGlobal() ? "global" : "local");
ImGui::TableNextColumn();
ImGui::Text("%-9s", infos.funcname);
ImGui::TableNextColumn();
ImGui::Text("%-9s", infos.source);
ImGui::TableNextColumn();
ImGui::Text("%5lld", infos.line);
}
ImGui::EndTable();
}
}
ImGui::End();
}
static void drawObjects() {
if (!state._showObjects)
return;
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
ImGui::Begin("Objects", &state._showObjects);
state._objFilter.Draw();
// show object list
for (auto &layer : g_twp->_room->_layers) {
for (auto &obj : layer->_objects) {
if (state._objFilter.PassFilter(obj->_key.c_str())) {
ImGui::PushID(obj->getId());
bool visible = obj->_node->isVisible();
if (ImGui::Checkbox("", &visible)) {
obj->_node->setVisible(visible);
}
ImGui::SameLine();
Common::String name = obj->_key.empty() ? obj->getName() : Common::String::format("%s(%s) %d", obj->getName().c_str(), obj->_key.c_str(), obj->getId());
bool selected = false;
if (ImGui::Selectable(name.c_str(), &selected)) {
// gObject = obj;
}
ImGui::PopID();
}
}
}
ImGui::End();
}
static Common::String toString(Audio::Mixer::SoundType type) {
switch (type) {
case Audio::Mixer::kPlainSoundType:
return "sound";
case Audio::Mixer::kMusicSoundType:
return "music";
case Audio::Mixer::kSFXSoundType:
return "sfx";
case Audio::Mixer::kSpeechSoundType:
return "speech";
}
return "?";
}
static ImVec4 getCategoryColor(Audio::Mixer::SoundType type) {
switch (type) {
case Audio::Mixer::kPlainSoundType:
return ImVec4(0.f, 1.f, 0.f, 1.f);
case Audio::Mixer::kMusicSoundType:
return ImVec4(1.f, 0.f, 0.f, 1.f);
case Audio::Mixer::kSFXSoundType:
return ImVec4(1.f, 0.f, 1.f, 1.f);
case Audio::Mixer::kSpeechSoundType:
return ImVec4(1.f, 1.f, 0.f, 1.f);
}
return ImVec4(1.f, 1.f, 1.f, 1.f);
}
static void drawActors() {
if (!state._showActor)
return;
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
ImGui::Begin("Actors", &state._showStack);
state._actorFilter.Draw();
ImGui::BeginChild("Actor_List");
for (auto &actor : g_twp->_actors) {
bool selected = actor->getId() == state._selectedActor;
Common::String key(actor->_key);
if (state._actorFilter.PassFilter(actor->_key.c_str())) {
if (key.empty()) {
key = "??";
}
if (ImGui::Selectable(key.c_str(), &selected)) {
state._selectedActor = actor->getId();
}
}
}
ImGui::EndChild();
ImGui::End();
}
static void drawActor() {
if (!state._showActor)
return;
Common::SharedPtr