MassBuilderSaveTool/src/SaveTool/SaveTool_MassViewer.cpp

424 lines
15 KiB
C++
Raw Normal View History

// MassBuilderSaveTool
// Copyright (C) 2021 Guillaume Jacquemin
//
// 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 <https://www.gnu.org/licenses/>.
2021-09-27 17:54:30 +02:00
#include <Magnum/ImGuiIntegration/Integration.h>
2021-09-10 16:16:21 +02:00
#include "../Maps/StyleNames.h"
#include "../FontAwesome/IconsFontAwesome5.h"
#include "SaveTool.h"
void SaveTool::drawMassViewer() {
if(!_currentMass || _currentMass->state() != Mass::State::Valid) {
_currentMass = nullptr;
_uiState = UiState::MainManager;
2021-09-27 17:54:30 +02:00
_queue.addToast(Toast::Type::Error, "The selected M.A.S.S. isn't valid anymore.");
return;
}
ImGui::SetNextWindowPos({0.0f, ImGui::GetItemRectSize().y}, ImGuiCond_Always);
ImGui::SetNextWindowSize({Float(windowSize().x()), Float(windowSize().y()) - ImGui::GetItemRectSize().y},
ImGuiCond_Always);
if(!ImGui::Begin("##MainWindow", nullptr,
ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_NoMove|
ImGuiWindowFlags_NoBackground|ImGuiWindowFlags_NoBringToFrontOnFocus))
{
ImGui::End();
return;
}
ImGui::Text("Current M.A.S.S.: %s (%s)",
2021-09-27 17:54:30 +02:00
(*_currentMass->name()).c_str(),
_currentMass->filename().c_str());
ImGui::SameLine();
2021-09-27 17:54:30 +02:00
if(ImGui::SmallButton(ICON_FA_ARROW_LEFT " Back to main manager")) {
_currentMass = nullptr;
_uiState = UiState::MainManager;
}
ImGui::TextColored(ImColor(255, 255, 0), ICON_FA_EXCLAMATION_TRIANGLE);
ImGui::SameLine();
ImGui::TextWrapped("WARNING: Colours in this app may look different from in-game colours, due to unavoidable differences in the rendering pipeline.");
2021-09-27 17:54:30 +02:00
ImGui::TextColored(ImColor(255, 255, 0), ICON_FA_EXCLAMATION_TRIANGLE);
ImGui::SameLine();
ImGui::TextWrapped("Real-time updates are disabled while on this screen. %s", _currentMass->dirty() ? "The save file has been changed." : "");
if(_currentMass->dirty()) {
ImGui::SameLine();
if(ImGui::SmallButton(ICON_FA_SYNC_ALT " Refresh")) {
_currentMass->refreshValues();
_currentMass->setDirty(false);
}
}
if(ImGui::BeginChild("##MassInfo",
{ImGui::GetContentRegionAvailWidth() * 0.60f, 0.0f},
true, ImGuiWindowFlags_MenuBar))
{
if(ImGui::BeginMenuBar()) {
ImGui::TextUnformatted("M.A.S.S. Information");
ImGui::EndMenuBar();
}
if(ImGui::BeginTabBar("##MassTabBar")) {
if(ImGui::BeginTabItem("Frame")) {
2021-09-10 16:16:21 +02:00
drawFrameInfo();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
ImGui::EndChild();
ImGui::SameLine();
if(ImGui::BeginChild("##GlobalStyles", {0.0f, 0.0f},
true, ImGuiWindowFlags_MenuBar))
{
if(ImGui::BeginMenuBar()) {
ImGui::TextUnformatted("Global styles");
ImGui::EndMenuBar();
}
ImGui::TextUnformatted("Placeholder");
}
ImGui::EndChild();
ImGui::End();
}
2021-09-10 16:16:21 +02:00
void SaveTool::drawFrameInfo() {
if(!_currentMass || _currentMass->state() != Mass::State::Valid) {
return;
}
ImGui::TextUnformatted("Frame type: Skeleton"); // Placeholder for now, replace with actual code once other frames are implemented.
2021-09-27 17:54:30 +02:00
drawJointSliders();
drawFramePaint();
}
void SaveTool::drawJointSliders() {
if(!ImGui::CollapsingHeader("Joint sliders")) {
return;
}
static Joints sliders = _currentMass->jointSliders();
static bool joints_edit = false;
static bool joints_dirty = false;
ImGui::TextWrapped("In-game values are multiplied by 100.\nFor example, 0.500 here is equal to 50 in-game.");
if(ImGui::BeginTable("##JointSliderTable", 2, ImGuiTableFlags_Borders)) {
ImGui::TableSetupColumn("##SliderLabel", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("##Sliders", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Neck");
ImGui::TableSetColumnIndex(1);
if(joints_edit) {
ImGui::SetNextItemWidth(-1.0f);
if(ImGui::SliderFloat("##NeckSlider", &sliders.neck, 0.0f, 1.0f)) {
joints_dirty = true;
}
}
else {
ImGui::AlignTextToFramePadding();
ImGui::Text("%.3f", Double(_currentMass->jointSliders().neck));
}
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Body");
ImGui::TableSetColumnIndex(1);
if(joints_edit) {
ImGui::SetNextItemWidth(-1.0f);
if(ImGui::SliderFloat("##BodySlider", &sliders.body, 0.0f, 1.0f)) {
joints_dirty = true;
}
}
else {
ImGui::AlignTextToFramePadding();
ImGui::Text("%.3f", Double(_currentMass->jointSliders().body));
}
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Shoulders");
ImGui::TableSetColumnIndex(1);
if(joints_edit) {
ImGui::SetNextItemWidth(-1.0f);
if(ImGui::SliderFloat("##ShouldersSlider", &sliders.shoulders, 0.0f, 1.0f)) {
joints_dirty = true;
}
}
else {
ImGui::AlignTextToFramePadding();
ImGui::Text("%.3f", Double(_currentMass->jointSliders().shoulders));
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Hips");
ImGui::TableSetColumnIndex(1);
if(joints_edit) {
ImGui::SetNextItemWidth(-1.0f);
if(ImGui::SliderFloat("##HipsSlider", &sliders.hips, 0.0f, 1.0f)) {
joints_dirty = true;
}
}
else {
ImGui::AlignTextToFramePadding();
ImGui::Text("%.3f", Double(_currentMass->jointSliders().hips));
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
if(ImGui::BeginTable("##UpperLowerLayoutTable", 2, ImGuiTableFlags_BordersInnerV)) {
ImGui::TableSetupColumn("##Upper", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##Lower", ImGuiTableColumnFlags_WidthStretch);
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Upper");
ImGui::TableNextColumn();
2021-09-10 16:16:21 +02:00
ImGui::AlignTextToFramePadding();
2021-09-27 17:54:30 +02:00
ImGui::TextUnformatted("Lower");
ImGui::EndTable();
}
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Arms");
ImGui::TableSetColumnIndex(1);
if(ImGui::BeginTable("##UpperLowerArmsLayoutTable", 2, ImGuiTableFlags_BordersInnerV)) {
ImGui::TableSetupColumn("##UpperArms", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##LowerArms", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextColumn();
if(joints_edit) {
2021-09-10 16:16:21 +02:00
ImGui::SetNextItemWidth(-1.0f);
2021-09-27 17:54:30 +02:00
if(ImGui::SliderFloat("##UpperArmsSlider", &sliders.upperArms, 0.0f, 1.0f)) {
joints_dirty = true;
2021-09-10 16:16:21 +02:00
}
}
else {
ImGui::AlignTextToFramePadding();
2021-09-27 17:54:30 +02:00
ImGui::Text("%.3f", Double(_currentMass->jointSliders().upperArms));
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::TableNextColumn();
if(joints_edit) {
2021-09-10 16:16:21 +02:00
ImGui::SetNextItemWidth(-1.0f);
2021-09-27 17:54:30 +02:00
if(ImGui::SliderFloat("##LowerArmsSlider", &sliders.lowerArms, 0.0f, 1.0f)) {
joints_dirty = true;
2021-09-10 16:16:21 +02:00
}
}
else {
ImGui::AlignTextToFramePadding();
2021-09-27 17:54:30 +02:00
ImGui::Text("%.3f", Double(_currentMass->jointSliders().lowerArms));
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::EndTable();
}
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Legs");
ImGui::TableSetColumnIndex(1);
if(ImGui::BeginTable("##UpperLowerLegsLayoutTable", 2, ImGuiTableFlags_BordersInnerV)) {
ImGui::TableSetupColumn("##UpperLegs", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##LowerLegs", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextColumn();
if(joints_edit) {
2021-09-10 16:16:21 +02:00
ImGui::SetNextItemWidth(-1.0f);
2021-09-27 17:54:30 +02:00
if(ImGui::SliderFloat("##UpperLegsSlider", &sliders.upperLegs, 0.0f, 1.0f)) {
joints_dirty = true;
2021-09-10 16:16:21 +02:00
}
}
else {
ImGui::AlignTextToFramePadding();
2021-09-27 17:54:30 +02:00
ImGui::Text("%.3f", Double(_currentMass->jointSliders().upperLegs));
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::TableNextColumn();
if(joints_edit) {
2021-09-10 16:16:21 +02:00
ImGui::SetNextItemWidth(-1.0f);
2021-09-27 17:54:30 +02:00
if(ImGui::SliderFloat("##LowerLegsSlider", &sliders.lowerLegs, 0.0f, 1.0f)) {
joints_dirty = true;
2021-09-10 16:16:21 +02:00
}
}
else {
ImGui::AlignTextToFramePadding();
2021-09-27 17:54:30 +02:00
ImGui::Text("%.3f", Double(_currentMass->jointSliders().lowerLegs));
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::EndTable();
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::EndTable();
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
if(joints_edit) {
if(!joints_dirty) {
ImGui::BeginDisabled();
ImGui::Button(ICON_FA_SAVE " Save changes");
ImGui::SameLine();
ImGui::Button(ICON_FA_UNDO " Reset sliders");
ImGui::EndDisabled();
}
else {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save changes"); })) {
if(!_currentMass->setSliders(sliders)) {
_queue.addToast(Toast::Type::Error, "Error writing the joint sliders.");
}
joints_dirty = false;
joints_edit = false;
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::SameLine();
if(ImGui::Button(ICON_FA_UNDO " Reset sliders")) {
sliders = _currentMass->jointSliders();
joints_dirty = false;
}
}
ImGui::SameLine();
if(ImGui::Button(ICON_FA_TIMES " Cancel editing")) {
sliders = _currentMass->jointSliders();
joints_dirty = false;
joints_edit = false;
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::TextUnformatted("To input out-of-range values, hold Ctrl and click on a slider.");
}
else {
if(ImGui::Button(ICON_FA_EDIT " Edit sliders")) {
sliders = _currentMass->jointSliders();
joints_edit = true;
}
}
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
void SaveTool::drawFramePaint() {
if(!ImGui::CollapsingHeader("Paint")) {
return;
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::TextUnformatted("Frame styles:");
for(Int i = 0; i < 4; i++) {
ImGui::AlignTextToFramePadding();
ImGui::Text("Slot %d:", i + 1);
ImGui::SameLine();
ImGui::PushID(i);
GameState game_state = _gameState;
if(!_unsafeMode && game_state != GameState::NotRunning) {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f);
}
if(ImGui::BeginCombo("##Style", style_names.at(_currentMass->frameStyles()[i]))) {
for(const auto& style : style_names) {
if(ImGui::Selectable(style.second, _currentMass->frameStyles()[i] == style.first)) {
if(!_currentMass->setFrameStyle(i, style.first)) {
_queue.addToast(Toast::Type::Error, Mass::lastError());
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
else {
_currentMass->refreshValues();
2021-09-10 16:16:21 +02:00
}
}
}
2021-09-27 17:54:30 +02:00
ImGui::EndCombo();
}
if(!_unsafeMode && game_state != GameState::NotRunning) {
ImGui::PopItemFlag();
ImGui::PopStyleVar();
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::PopID();
}
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
ImGui::Separator();
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
static bool eye_flare_edit = false;
static bool eye_flare_dirty = false;
static Color4 eye_flare = _currentMass->eyeFlareColour();
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Eye flare colour:");
ImGui::SameLine();
ImGui::BeginGroup();
if(eye_flare_edit) {
if(ImGui::ColorEdit3("##EyeFlarePicker", &eye_flare.x())) {
eye_flare_dirty = true;
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::SameLine();
drawHelpMarker("Right-click for more option, click the coloured square for the full picker.", 250.0f);
2021-09-10 16:16:21 +02:00
2021-09-27 17:54:30 +02:00
if(!eye_flare_dirty) {
ImGui::BeginDisabled();
ImGui::Button(ICON_FA_SAVE " Save");
2021-09-10 16:16:21 +02:00
ImGui::SameLine();
2021-09-27 17:54:30 +02:00
ImGui::Button(ICON_FA_UNDO " Reset");
ImGui::EndDisabled();
}
else {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
if(!_currentMass->setEyeFlareColour(eye_flare)) {
_queue.addToast(Toast::Type::Error, "Error writing the eye flare colour.");
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
eye_flare_dirty = false;
eye_flare_edit = false;
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::SameLine();
if(ImGui::Button(ICON_FA_UNDO " Reset")) {
eye_flare = _currentMass->eyeFlareColour();
eye_flare_dirty = false;
2021-09-10 16:16:21 +02:00
}
}
ImGui::SameLine();
2021-09-27 17:54:30 +02:00
if(ImGui::Button(ICON_FA_TIMES " Cancel")) {
eye_flare = _currentMass->eyeFlareColour();
eye_flare_dirty = false;
eye_flare_edit = false;
}
}
else {
ImGui::BeginDisabled();
ImColor colour{_currentMass->eyeFlareColour()};
ImGui::ColorEdit3("##EyeFlarePicker", &colour.Value.x);
ImGui::EndDisabled();
if(ImGui::Button(ICON_FA_EDIT " Edit")) {
eye_flare = _currentMass->eyeFlareColour();
eye_flare_edit = true;
}
2021-09-10 16:16:21 +02:00
}
2021-09-27 17:54:30 +02:00
ImGui::EndGroup();
2021-09-10 16:16:21 +02:00
}