Rework/fix expression checkboxes

This commit is contained in:
Llennpie 2024-01-14 16:59:00 -05:00
parent 5cc45a7c9b
commit 074c65cd3f
2 changed files with 40 additions and 20 deletions

View file

@ -199,36 +199,41 @@ void OpenExpressionSelector() {
for (int i = 0; i < current_model.Expressions.size(); i++) {
Expression expression = current_model.Expressions[i];
if (expression.Name == "eyes") continue;
if (expression.Textures.size() <= 1) continue;
std::string label_name = "###exp_label_" + expression.Name;
ImGui::Text(expression.Name.c_str());
ImGui::SameLine(75);
ImGui::PushItemWidth(120);
// Use checkbox
if (expression.Textures.size() == 2 && (
expression.Textures[0].FileName.find("default") != std::string::npos ||
expression.Textures[1].FileName.find("default") != std::string::npos )) {
// Check which index "default.png" is (0 or 1) to determine default value
int select_index = (expression.Textures[0].FileName.find("default") != std::string::npos) ? 0 : 1;
int deselect_index = (expression.Textures[0].FileName.find("default") != std::string::npos) ? 1 : 0;
bool is_selected = (expression.CurrentIndex == select_index);
if (expression.Textures.size() >= 2) {
if (expression.IsToggleFormat() &&
// Use checkbox
(expression.Textures[0].FileName.find("default") != std::string::npos ||
expression.Textures[1].FileName.find("default") != std::string::npos)) {
if (ImGui::Checkbox(label_name.c_str(), &is_selected)) {
if (is_selected) current_model.Expressions[i].CurrentIndex = select_index;
else current_model.Expressions[i].CurrentIndex = deselect_index;
// Check which index "default.png" is (0 or 1) to determine default value
int select_index = (expression.Textures[0].FileName.find("default") != std::string::npos) ? 0 : 1;
int deselect_index = (select_index == 0) ? 1 : 0;
bool is_selected = (expression.CurrentIndex == select_index);
if (ImGui::Checkbox(label_name.c_str(), &is_selected)) {
if (is_selected) current_model.Expressions[i].CurrentIndex = select_index;
else current_model.Expressions[i].CurrentIndex = deselect_index;
}
// Popout showing the checkbox's actively displayed value
// This is technically the opposite of the dropdowns and selectables, which shows the value-that-will-be, not current
ShowTextureContextMenu(&current_model.Expressions[i], current_model.Expressions[i].Textures[expression.CurrentIndex], i);
} else {
// Use dropdown
std::string defaultLabel = ((expression.Textures.size() > 0) ? expression.Textures[expression.CurrentIndex].FileName : expression.Name) + "###combo_" + expression.Name.c_str();
if (ImGui::BeginCombo(label_name.c_str(), defaultLabel.c_str(), ImGuiComboFlags_None)) {
RecursiveSelector(&current_model.Expressions[i], 0, expression.FolderPath, i);
ImGui::EndCombo();
}
// Popout showing the checkbox's actively displayed value
// This is technically the opposite of the dropdowns and selectables, which shows the value-that-will-be, not current
ShowTextureContextMenu(&current_model.Expressions[i], current_model.Expressions[i].Textures[expression.CurrentIndex], i);
} else {
// Use dropdown
std::string defaultLabel = ((expression.Textures.size() > 0) ? expression.Textures[expression.CurrentIndex].FileName : expression.Name) + "###combo_" + expression.Name.c_str();
if (ImGui::BeginCombo(label_name.c_str(), defaultLabel.c_str(), ImGuiComboFlags_None)) {
RecursiveSelector(&current_model.Expressions[i], 0, expression.FolderPath, i);
ImGui::EndCombo();
}
ShowTextureContextMenu(&current_model.Expressions[i], current_model.Expressions[i].Textures[expression.CurrentIndex], i);
}
ImGui::PopItemWidth();
}

View file

@ -48,6 +48,21 @@ public:
path.find(prefix + this->Name + "_s") != std::string::npos ||
path.find(prefix + this->Name.substr(0, this->Name.size() - 1) + "_") != std::string::npos);
}
/* Returns true if the expression's textures are formatted for a checkbox
This is when an expression has two non-model textures and no subfolders */
bool IsToggleFormat() {
if (this->Textures.size() >= 2 && this->Folders.size() == 0) {
int countWithoutModelTextures = 0;
for (int i = 0; i < this->Textures.size(); i++) {
// Exclude model textures
if (this->Textures[i].IsModelTexture) continue;
countWithoutModelTextures++;
}
return(countWithoutModelTextures == 2);
}
return false;
}
};
extern bool custom_eyes_enabled;