198 lines
6.3 KiB
C++
198 lines
6.3 KiB
C++
// MassBuilderSaveTool
|
|
// Copyright (C) 2021-2022 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/>.
|
|
|
|
#include "../FontAwesome/IconsFontAwesome5.h"
|
|
|
|
#include "../Maps/ArmourSets.h"
|
|
#include "../Maps/StyleNames.h"
|
|
|
|
#include "SaveTool.h"
|
|
|
|
void SaveTool::drawArmour() {
|
|
if(!_currentMass || _currentMass->state() != Mass::State::Valid) {
|
|
return;
|
|
}
|
|
|
|
if(ImGui::Button(ICON_FA_UNDO_ALT " Reset all")) {
|
|
_currentMass->getArmourParts();
|
|
}
|
|
|
|
if(!ImGui::BeginChild("##ArmourParts")) {
|
|
ImGui::EndChild();
|
|
return;
|
|
}
|
|
|
|
static const char* slot_labels[] = {
|
|
#define c(enumerator, strenum, name) name,
|
|
#include "../Maps/ArmourSlots.hpp"
|
|
#undef c
|
|
};
|
|
|
|
for(UnsignedInt i = 0; i < _currentMass->armourParts().size(); i++) {
|
|
ImGui::PushID(i);
|
|
|
|
auto& part = _currentMass->armourParts()[i];
|
|
|
|
static char header[129] = {'\0'};
|
|
|
|
std::memset(header, '\0', 129);
|
|
|
|
if(armour_sets.find(part.id) != armour_sets.cend()) {
|
|
std::snprintf(header, 128, "%s: %s###%u", slot_labels[UnsignedInt(part.slot)], armour_sets.at(part.id).name, UnsignedInt(part.slot));
|
|
}
|
|
else {
|
|
std::snprintf(header, 128, "%s: %i###%u", slot_labels[UnsignedInt(part.slot)], part.id, UnsignedInt(part.slot));
|
|
}
|
|
|
|
if(ImGui::CollapsingHeader(header)) {
|
|
ImGui::BeginGroup();
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.491f);
|
|
if(ImGui::BeginListBox("##ChangePart")) {
|
|
if(std::strncmp("Neck", slot_labels[UnsignedInt(part.slot)], 4) != 0) {
|
|
for(auto& set : armour_sets) {
|
|
if(ImGui::Selectable(set.second.name, set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) {
|
|
part.id = set.first;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
for(auto& set : armour_sets) {
|
|
if(!set.second.neck_compatible) {
|
|
continue;
|
|
}
|
|
|
|
if(ImGui::Selectable(set.second.name, set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) {
|
|
part.id = set.first;
|
|
}
|
|
}
|
|
}
|
|
ImGui::EndListBox();
|
|
}
|
|
|
|
ImGui::EndGroup();
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
ImGui::TextUnformatted("Styles:");
|
|
|
|
for(Int j = 0; j < 4; j++) {
|
|
drawAlignedText("Slot %d:", j + 1);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::PushID(j);
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() - 2.0f);
|
|
if(ImGui::BeginCombo("##Style", getStyleName(part.styles[j], _currentMass->armourCustomStyles()))) {
|
|
for(const auto& style : style_names) {
|
|
if(ImGui::Selectable(getStyleName(style.first, _currentMass->armourCustomStyles()), part.styles[j] == style.first)) {
|
|
part.styles[j] = style.first;
|
|
}
|
|
}
|
|
|
|
ImGui::EndCombo();
|
|
}
|
|
|
|
ImGui::PopID();
|
|
}
|
|
|
|
ImGui::EndGroup();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::PushID("Decal");
|
|
|
|
drawAlignedText("Showing/editing decal");
|
|
for(UnsignedInt j = 0; j < part.decals.size(); j++) {
|
|
ImGui::SameLine();
|
|
ImGui::RadioButton(std::to_string(j + 1).c_str(), &_selectedArmourDecals[i], j);
|
|
}
|
|
|
|
drawDecalEditor(part.decals[_selectedArmourDecals[i]]);
|
|
|
|
ImGui::PopID();
|
|
|
|
if(!part.accessories.size()) {
|
|
ImGui::Separator();
|
|
|
|
ImGui::PushID("Accessory");
|
|
|
|
drawAlignedText("Showing/editing accessory");
|
|
for(UnsignedInt j = 0; j < part.accessories.size(); j++) {
|
|
ImGui::SameLine();
|
|
ImGui::RadioButton(std::string{char(65 + j)}.c_str(), &_selectedArmourAccessories[i], j);
|
|
}
|
|
|
|
drawAccessoryEditor(part.accessories[_selectedArmourAccessories[i]], _currentMass->armourCustomStyles());
|
|
|
|
ImGui::PopID();
|
|
}
|
|
|
|
ImGui::Separator();
|
|
|
|
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
|
if(!_currentMass->writeArmourPart(part.slot)) {
|
|
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
|
}
|
|
}
|
|
}
|
|
|
|
ImGui::PopID();
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
}
|
|
|
|
void SaveTool::drawCustomArmourStyles() {
|
|
if(!_currentMass || _currentMass->state() != Mass::State::Valid) {
|
|
return;
|
|
}
|
|
|
|
if(!ImGui::BeginChild("##ArmourStyles")) {
|
|
ImGui::EndChild();
|
|
return;
|
|
}
|
|
|
|
ImGui::TextWrapped("In-game values are multiplied by 100. For example, 0.500 here is equal to 50 in-game.");
|
|
|
|
for(UnsignedInt i = 0; i < _currentMass->armourCustomStyles().size(); i++) {
|
|
ImGui::PushID(i);
|
|
DCSResult result;
|
|
result = drawCustomStyle(_currentMass->armourCustomStyles()[i]);
|
|
switch(result) {
|
|
case DCS_ResetStyle:
|
|
_currentMass->getArmourCustomStyles();
|
|
break;
|
|
case DCS_Save:
|
|
if(_currentMass->writeArmourCustomStyle(i)) {
|
|
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
ImGui::PopID();
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
}
|