fixed event handling and a lot of ID stuff OOPS
This commit is contained in:
@@ -40,6 +40,7 @@ namespace anm2ed::anm2
|
|||||||
Spritesheet* spritesheet_get(int);
|
Spritesheet* spritesheet_get(int);
|
||||||
bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&);
|
bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&);
|
||||||
std::vector<std::string> spritesheet_labels_get();
|
std::vector<std::string> spritesheet_labels_get();
|
||||||
|
std::vector<int> spritesheet_ids_get();
|
||||||
std::set<int> spritesheets_unused();
|
std::set<int> spritesheets_unused();
|
||||||
bool spritesheets_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type type,
|
bool spritesheets_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type type,
|
||||||
std::string*);
|
std::string*);
|
||||||
@@ -56,11 +57,13 @@ namespace anm2ed::anm2
|
|||||||
|
|
||||||
void event_add(int&);
|
void event_add(int&);
|
||||||
std::vector<std::string> event_labels_get();
|
std::vector<std::string> event_labels_get();
|
||||||
|
std::vector<int> event_ids_get();
|
||||||
std::set<int> events_unused();
|
std::set<int> events_unused();
|
||||||
bool events_deserialize(const std::string&, types::merge::Type, std::string*);
|
bool events_deserialize(const std::string&, types::merge::Type, std::string*);
|
||||||
|
|
||||||
bool sound_add(const std::filesystem::path& directory, const std::filesystem::path& path, int& id);
|
bool sound_add(const std::filesystem::path& directory, const std::filesystem::path& path, int& id);
|
||||||
std::vector<std::string> sound_labels_get();
|
std::vector<std::string> sound_labels_get();
|
||||||
|
std::vector<int> sound_ids_get();
|
||||||
std::set<int> sounds_unused();
|
std::set<int> sounds_unused();
|
||||||
bool sounds_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type, std::string*);
|
bool sounds_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type, std::string*);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ namespace anm2ed::anm2
|
|||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> Anm2::event_ids_get()
|
||||||
|
{
|
||||||
|
std::vector<int> ids{};
|
||||||
|
ids.emplace_back(-1);
|
||||||
|
for (auto& id : content.events | std::views::keys)
|
||||||
|
ids.emplace_back(id);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
std::set<int> Anm2::events_unused()
|
std::set<int> Anm2::events_unused()
|
||||||
{
|
{
|
||||||
std::set<int> used{};
|
std::set<int> used{};
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ namespace anm2ed::anm2
|
|||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> Anm2::sound_ids_get()
|
||||||
|
{
|
||||||
|
std::vector<int> ids{};
|
||||||
|
ids.emplace_back(-1);
|
||||||
|
for (auto& [id, sound] : content.sounds)
|
||||||
|
ids.emplace_back(id);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
std::set<int> Anm2::sounds_unused()
|
std::set<int> Anm2::sounds_unused()
|
||||||
{
|
{
|
||||||
std::set<int> used;
|
std::set<int> used;
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ namespace anm2ed::anm2
|
|||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> Anm2::spritesheet_ids_get()
|
||||||
|
{
|
||||||
|
std::vector<int> ids{};
|
||||||
|
for (auto& [id, spritesheet] : content.spritesheets)
|
||||||
|
ids.emplace_back(id);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
bool Anm2::spritesheets_deserialize(const std::string& string, const std::filesystem::path& directory,
|
bool Anm2::spritesheets_deserialize(const std::string& string, const std::filesystem::path& directory,
|
||||||
merge::Type type, std::string* errorString)
|
merge::Type type, std::string* errorString)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -103,10 +103,11 @@ namespace anm2ed::anm2
|
|||||||
element->SetAttribute("Interpolated", isInterpolated);
|
element->SetAttribute("Interpolated", isInterpolated);
|
||||||
break;
|
break;
|
||||||
case TRIGGER:
|
case TRIGGER:
|
||||||
element->SetAttribute("EventId", eventID);
|
if (eventID != -1) element->SetAttribute("EventId", eventID);
|
||||||
|
|
||||||
for (auto& id : soundIDs)
|
for (auto& id : soundIDs)
|
||||||
{
|
{
|
||||||
|
if (id == -1) continue;
|
||||||
auto soundChild = element->InsertNewChildElement("Sound");
|
auto soundChild = element->InsertNewChildElement("Sound");
|
||||||
soundChild->SetAttribute("Id", id);
|
soundChild->SetAttribute("Id", id);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -179,7 +179,7 @@ namespace anm2ed
|
|||||||
auto events_set = [&]()
|
auto events_set = [&]()
|
||||||
{
|
{
|
||||||
event.unused = anm2.events_unused();
|
event.unused = anm2.events_unused();
|
||||||
event.labels_set(anm2.event_labels_get());
|
event.labels_set(anm2.event_labels_get(), anm2.event_ids_get());
|
||||||
};
|
};
|
||||||
|
|
||||||
auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); };
|
auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); };
|
||||||
@@ -187,13 +187,13 @@ namespace anm2ed
|
|||||||
auto spritesheets_set = [&]()
|
auto spritesheets_set = [&]()
|
||||||
{
|
{
|
||||||
spritesheet.unused = anm2.spritesheets_unused();
|
spritesheet.unused = anm2.spritesheets_unused();
|
||||||
spritesheet.labels_set(anm2.spritesheet_labels_get());
|
spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get());
|
||||||
};
|
};
|
||||||
|
|
||||||
auto sounds_set = [&]()
|
auto sounds_set = [&]()
|
||||||
{
|
{
|
||||||
sound.unused = anm2.sounds_unused();
|
sound.unused = anm2.sounds_unused();
|
||||||
sound.labels_set(anm2.sound_labels_get());
|
sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get());
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <imgui/imgui_internal.h>
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -106,6 +107,29 @@ namespace anm2ed::imgui
|
|||||||
return isActivated;
|
return isActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool combo_id_mapped(const std::string& label, int* id, const std::vector<int>& ids, std::vector<const char*>& labels)
|
||||||
|
{
|
||||||
|
if (!id) return false;
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
if (!ids.empty())
|
||||||
|
{
|
||||||
|
auto it = std::find(ids.begin(), ids.end(), *id);
|
||||||
|
if (it != ids.end()) index = (int)std::distance(ids.begin(), it);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isActivated = ImGui::Combo(label.c_str(), &index, labels.data(), (int)labels.size());
|
||||||
|
if (isActivated)
|
||||||
|
{
|
||||||
|
if (index >= 0 && index < (int)ids.size())
|
||||||
|
*id = ids[index];
|
||||||
|
else
|
||||||
|
*id = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isActivated;
|
||||||
|
}
|
||||||
|
|
||||||
edit::Type drag_int_persistent(const char* label, int* value, float speed, int min, int max, const char* format,
|
edit::Type drag_int_persistent(const char* label, int* value, float speed, int min, int max, const char* format,
|
||||||
ImGuiSliderFlags flags)
|
ImGuiSliderFlags flags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ namespace anm2ed::imgui
|
|||||||
types::edit::Type color_edit3_persistent(const char*, glm::vec3*, ImGuiColorEditFlags = 0);
|
types::edit::Type color_edit3_persistent(const char*, glm::vec3*, ImGuiColorEditFlags = 0);
|
||||||
types::edit::Type color_edit4_persistent(const char*, glm::vec4*, ImGuiColorEditFlags = 0);
|
types::edit::Type color_edit4_persistent(const char*, glm::vec4*, ImGuiColorEditFlags = 0);
|
||||||
bool combo_negative_one_indexed(const std::string&, int*, std::vector<const char*>&);
|
bool combo_negative_one_indexed(const std::string&, int*, std::vector<const char*>&);
|
||||||
|
bool combo_id_mapped(const std::string&, int*, const std::vector<int>&, std::vector<const char*>&);
|
||||||
std::string& selectable_input_text_id();
|
std::string& selectable_input_text_id();
|
||||||
bool selectable_input_text(const std::string& label, const std::string& id, std::string& text, bool isSelected,
|
bool selectable_input_text(const std::string& label, const std::string& id, std::string& text, bool isSelected,
|
||||||
ImGuiSelectableFlags flags, RenameState& state);
|
ImGuiSelectableFlags flags, RenameState& state);
|
||||||
|
|||||||
@@ -31,9 +31,8 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
if (type == anm2::TRIGGER)
|
if (type == anm2::TRIGGER)
|
||||||
{
|
{
|
||||||
if (combo_negative_one_indexed(localize.get(BASIC_EVENT),
|
if (combo_id_mapped(localize.get(BASIC_EVENT), frame ? &useFrame.eventID : &dummy_value_negative<int>(),
|
||||||
frame ? &useFrame.eventID : &dummy_value_negative<int>(),
|
document.event.ids, document.event.labels) &&
|
||||||
document.event.labels) &&
|
|
||||||
frame)
|
frame)
|
||||||
DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_EVENT), Document::FRAMES,
|
DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_EVENT), Document::FRAMES,
|
||||||
frame->eventID = useFrame.eventID);
|
frame->eventID = useFrame.eventID);
|
||||||
@@ -64,7 +63,7 @@ namespace anm2ed::imgui
|
|||||||
for (auto [i, id] : std::views::enumerate(useFrame.soundIDs))
|
for (auto [i, id] : std::views::enumerate(useFrame.soundIDs))
|
||||||
{
|
{
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
if (combo_negative_one_indexed("##Sound", frame ? &id : &dummy_value_negative<int>(),
|
if (combo_id_mapped("##Sound", frame ? &id : &dummy_value_negative<int>(), document.sound.ids,
|
||||||
document.sound.labels) &&
|
document.sound.labels) &&
|
||||||
frame)
|
frame)
|
||||||
DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_SOUND), Document::FRAMES,
|
DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_SOUND), Document::FRAMES,
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ namespace anm2ed::imgui
|
|||||||
input_text_string(localize.get(BASIC_NAME), &layer.name);
|
input_text_string(localize.get(BASIC_NAME), &layer.name);
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
||||||
|
|
||||||
ImGui::Combo(localize.get(LABEL_SPRITESHEET), &layer.spritesheetID, document.spritesheet.labels.data(),
|
combo_id_mapped(localize.get(LABEL_SPRITESHEET), &layer.spritesheetID, document.spritesheet.ids,
|
||||||
(int)document.spritesheet.labels.size());
|
document.spritesheet.labels);
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|||||||
@@ -1697,8 +1697,8 @@ namespace anm2ed::imgui
|
|||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
||||||
if (type == anm2::LAYER)
|
if (type == anm2::LAYER)
|
||||||
{
|
{
|
||||||
ImGui::Combo(localize.get(LABEL_SPRITESHEET), &addItemSpritesheetID, document.spritesheet.labels.data(),
|
combo_id_mapped(localize.get(LABEL_SPRITESHEET), &addItemSpritesheetID, document.spritesheet.ids,
|
||||||
(int)document.spritesheet.labels.size());
|
document.spritesheet.labels);
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
||||||
}
|
}
|
||||||
else if (type == anm2::NULL_)
|
else if (type == anm2::NULL_)
|
||||||
|
|||||||
+7
-2
@@ -1,12 +1,17 @@
|
|||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace anm2ed
|
namespace anm2ed
|
||||||
{
|
{
|
||||||
void Storage::clear() { *this = Storage(); }
|
void Storage::clear() { *this = Storage(); }
|
||||||
|
|
||||||
void Storage::labels_set(std::vector<std::string> labels)
|
void Storage::labels_set(std::vector<std::string> labels) { labels_set(std::move(labels), {}); }
|
||||||
|
|
||||||
|
void Storage::labels_set(std::vector<std::string> labels, std::vector<int> ids)
|
||||||
{
|
{
|
||||||
labelsString = labels;
|
labelsString = std::move(labels);
|
||||||
|
this->ids = std::move(ids);
|
||||||
this->labels.clear();
|
this->labels.clear();
|
||||||
for (auto& label : labelsString)
|
for (auto& label : labelsString)
|
||||||
this->labels.emplace_back(label.c_str());
|
this->labels.emplace_back(label.c_str());
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ namespace anm2ed
|
|||||||
std::set<int> unused{};
|
std::set<int> unused{};
|
||||||
std::vector<std::string> labelsString{};
|
std::vector<std::string> labelsString{};
|
||||||
std::vector<const char*> labels{};
|
std::vector<const char*> labels{};
|
||||||
|
std::vector<int> ids{};
|
||||||
imgui::MultiSelectStorage selection{};
|
imgui::MultiSelectStorage selection{};
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void labels_set(std::vector<std::string>);
|
void labels_set(std::vector<std::string>);
|
||||||
|
void labels_set(std::vector<std::string>, std::vector<int>);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user