Skip to content

Commit

Permalink
0.4a
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentalimbed committed May 9, 2022
1 parent fe3fee1 commit ed92c6d
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 265 deletions.
29 changes: 17 additions & 12 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
- 0.1a Copy/paste ref management
- 0.1a Disable unavailable classes options
- 0.1a Display all available classes options in list view
- Loading character file
Editing character file
- 0.3a Loading skeleton file
- 0.3a Bone select edit
- Animation edit
Behaviour diagnosis
- 0.2a Class hint
- 0.1a New file

- 0.2a Class hint
- 0.2a Reindex objects
- 0.2a Navigate to specific object in column view
- 0.2a Automatic state id distribution
- 0.3a Bone weight/index array
- 0.2a Opitimize buildRefList

- 0.3a Loading skeleton file
- 0.3a Bone select button
- 0.3a Bone weight/index array
- 0.3a Edit pointer variable
- 0.3a BlenderGen fix
- Ref list update with pointer variables
Display names within the var/state/ref/evt edit when not editing (using combobox?)
- 0.3a Set keyboard focus when invoking var/evt select popup
- Macros
- Parse trigger macro

- 0.4a Animation select button
- 0.4a Loading character file
- 0.4a Ref list update with pointer variables
- 0.4a Macros
- 0.4a Parse trigger macro

Behaviour diagnosis
Display names within the var/state/ref/evt edit when not editing (using combobox?)
Editing character file
Refactor the shit out of the bloody widgets!
1 change: 1 addition & 0 deletions cmake/headerlist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ set(headers
src/ui/propedit.h
src/ui/columnview.h
src/ui/macros.h
src/ui/charedit.h
)
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ set(sources
src/ui/propedit.cpp
src/ui/columnview.cpp
src/ui/macros.cpp
src/ui/charedit.cpp
)
4 changes: 2 additions & 2 deletions src/hkx/hkxfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void BehaviourFile::loadFile(std::string_view path)
void BehaviourFile::saveFile(std::string_view path)
{
reindexEvents();
reindexProperties();
reindexProps();
reindexVariables();

HkxFile::saveFile(path);
Expand Down Expand Up @@ -474,7 +474,7 @@ void BehaviourFile::reindexEvents()
walker.m_remap = &remap;
m_data_node.traverse(walker);
}
void BehaviourFile::reindexProperties()
void BehaviourFile::reindexProps()
{
auto remap = m_prop_manager.reindex();

Expand Down
6 changes: 3 additions & 3 deletions src/hkx/hkxfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class BehaviourFile : public HkxFile

void reindexVariables();
void reindexEvents();
void reindexProperties();
void reindexProps();

// removed unreferenced
void cleanupVariables();
Expand All @@ -139,6 +139,7 @@ class SkeletonFile : public HkxFile
public:
void loadFile(std::string_view path);

inline pugi::xml_node getBoneNode(bool ragdoll = false) { return (ragdoll ? m_skel_rag_obj : m_skel_obj).getByName("bones"); }
void getBoneList(std::vector<std::string_view>& out, bool ragdoll = false);
inline std::string_view getBone(size_t idx, bool ragdoll = false)
{
Expand All @@ -165,9 +166,8 @@ class CharacterFile : public HkxFile

inline pugi::xml_node getAnimNames() { return m_anim_name_node; }

private:
VariableManager m_prop_manager; // naming a bit confusing but charprops are essentially variables in character files

private:
pugi::xml_node m_anim_name_node;
pugi::xml_node m_char_data_obj, m_char_str_data_obj, m_var_value_obj;
};
Expand Down
2 changes: 2 additions & 0 deletions src/hkx/linkedmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <tuple>

#include <pugixml.hpp>
#include <fmt/format.h>

namespace Haviour
{
Expand Down Expand Up @@ -62,6 +63,7 @@ class LinkedPropertyEntry
constexpr pugi::xml_node get() { return m_props[getTypeIndex<T, Props...>()]; }

std::enable_if_t<IsContained<PropName, Props...>::value, const char*> getName() { return get<PropName>().text().as_string(); }
std::enable_if_t<IsContained<PropName, Props...>::value, std::string> getItemName() { return fmt::format("{:4} {}", m_index, getName()); }

static LinkedPropertyEntry<Props...> create(NodeArray& containers)
{
Expand Down
121 changes: 121 additions & 0 deletions src/ui/charedit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include "charedit.h"
#include "widgets.h"
#include "hkx/hkclass.inl"

#include <memory>

namespace Haviour
{
namespace Ui
{
CharEdit* CharEdit::getSingleton()
{
static CharEdit edit;
return std::addressof(edit);
}

void CharEdit::show()
{
}

void CharEdit::showPropList()
{
ImGui::PushID("propedit");
constexpr auto table_flag =
ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY |
ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody;

bool scroll_to_bottom = false;
auto file_manager = Hkx::HkxFileManager::getSingleton();
auto& current_file = file_manager->m_char_file;

ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Character Property"), ImGui::SameLine();
if (ImGui::Button(ICON_FA_PLUS_CIRCLE))
ImGui::OpenPopup("Type Select");
addTooltip("Add new character property");
if (ImGui::BeginPopup("Type Select"))
{
for (auto data_type : Hkx::e_variableType)
if ((data_type != "VARIABLE_TYPE_INVALID") && ImGui::Selectable(data_type.data()))
{
ImGui::CloseCurrentPopup();
scroll_to_bottom = true;
current_file.m_prop_manager.addEntry(Hkx::getVarTypeEnum(data_type));
break;
}
ImGui::EndPopup();
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_HASHTAG))
current_file.m_prop_manager.reindex();
addTooltip("Reindex variables\nDiscard all variables marked obsolete");

ImGui::InputText("Filter", &m_prop_filter), ImGui::SameLine();
ImGui::Button(ICON_FA_QUESTION_CIRCLE);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::TextColored(g_color_invalid, "Invalid");
ImGui::TextColored(g_color_bool, "Boolean");
ImGui::TextColored(g_color_int, "Int8/16/32");
ImGui::TextColored(g_color_float, "Real");
ImGui::TextColored(g_color_attr, "Pointer");
ImGui::TextColored(g_color_quad, "Vector/Quaternion");
ImGui::EndTooltip();
}
ImGui::Separator();

if (ImGui::BeginTable("##PropList", 2, table_flag, ImVec2(-FLT_MIN, -FLT_MIN)))
{
ImGui::TableSetupColumn("id", ImGuiTableColumnFlags_WidthFixed, 36);
ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextRow();

auto var_list = current_file.m_prop_manager.getEntryList();
std::erase_if(var_list,
[=](auto& var) {
auto disp_name = std::format("{:3} {}", var.m_index, var.get<Hkx::PropName>().text().as_string()); // :3
return !(var.m_valid &&
(m_prop_filter.empty() ||
!std::ranges::search(disp_name, m_prop_filter, [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }).empty()));
});

ImGuiListClipper clipper;
clipper.Begin(var_list.size());
while (clipper.Step())
for (int row_n = clipper.DisplayStart; row_n < clipper.DisplayEnd; row_n++)
{
auto& var = var_list[row_n];

ImGui::TableNextColumn();

auto var_type = var.get<Hkx::PropVarInfo>().getByName("type").text().as_string();
ImGui::PushStyleColor(ImGuiCol_Text, getVarColor(var));
ImGui::Text("%d", var.m_index);
addTooltip(var_type);
ImGui::PopStyleColor();

ImGui::TableNextColumn();
const bool is_selected = false;
if (ImGui::Selectable(std::format("{}##{}", var.get<Hkx::PropName>().text().as_string(), var.m_index).c_str(), is_selected))
{
m_prop_current = var;
ImGui::OpenPopup("Editing Varibale");
}
addTooltip("Click to edit");
if (is_selected)
ImGui::SetItemDefaultFocus();
}
// varEditPopup("Editing Varibale", m_prop_current, current_file);

if (scroll_to_bottom)
ImGui::SetScrollHereY(1.0f);

ImGui::EndTable();
}
ImGui::PopID();
}

} // namespace Ui
} // namespace Haviour
25 changes: 25 additions & 0 deletions src/ui/charedit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "hkx/linkedmanager.h"

namespace Haviour
{
namespace Ui
{
class CharEdit
{
public:
static CharEdit* getSingleton();

void show();

bool m_show = false;

private:
std::string m_prop_filter = {};
Hkx::Variable m_prop_current = {};

void showPropList();
};
} // namespace Ui
} // namespace Haviour
8 changes: 4 additions & 4 deletions src/ui/classinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ UICLASS(hkbBlenderGenerator)
intScalarEdit(obj.getByName("indexOfSyncMasterChild"), file, ImGuiDataType_S16,
"If you want a particular child's duration to be used to sync all of the other children, set this to the index of the child.\n"
"Otherwise, set it to -1.");
flagEdit(obj.getByName("flags"), Hkx::f_hkbBlenderGenerator_BlenderFlags,
"The flags affecting specialized behavior.", "", true);
flagEdit<true>(obj.getByName("flags"), Hkx::f_hkbBlenderGenerator_BlenderFlags,
"The flags affecting specialized behavior.", "");
boolEdit(obj.getByName("subtractLastChild"), file,
"If this is set to true then the last child will be a subtracted from the blend of the rest");

Expand Down Expand Up @@ -802,7 +802,6 @@ UICLASS(hkbBoneIndexArray)
if (ImGui::InputTextMultiline(bone_indices.attribute("name").as_string(), &value))
bone_indices.text() = value.c_str();


ImGui::TableNextColumn();

ImGui::EndTable();
Expand Down Expand Up @@ -840,7 +839,8 @@ UICLASS(hkbBoneIndexArray)
ImGui::TableNextColumn();
ImGui::InputScalar(fmt::format("{}", i).c_str(), ImGuiDataType_S16, &bone_idxs[i]);
ImGui::TableNextColumn();
bonePickerButton(skel_file, bone_idxs[i]);
if (auto res = bonePickerButton("picker", skel_file, bone_idxs[i]); res.has_value())
bone_idxs[i] = res.value();
ImGui::PopID();
}
ImGui::EndTable();
Expand Down
15 changes: 5 additions & 10 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,32 +234,27 @@ void showMenuBar()
}
if (ImGui::BeginMenu("Resources"))
{
if (ImGui::MenuItem("Load Project File")) {}
addTooltip("Load both the character and skeleton");

ImGui::Separator();

if (ImGui::MenuItem("Load Skeleton"))
if (ImGui::MenuItem("Load Character"))
{
nfdchar_t* outPath = nullptr;
nfdresult_t result = NFD_OpenDialog(nullptr, nullptr, &outPath);
if (result == NFD_OKAY)
{
file_manager->m_skel_file.loadFile(outPath);
file_manager->m_char_file.loadFile(outPath);
free(outPath);
}
else if (result == NFD_ERROR)
{
spdlog::error("Error with file dialog:\n\t{}", NFD_GetError());
}
}
if (ImGui::MenuItem("Load Character"))
if (ImGui::MenuItem("Load Skeleton"))
{
nfdchar_t* outPath = nullptr;
nfdresult_t result = NFD_OpenDialog(nullptr, nullptr, &outPath);
if (result == NFD_OKAY)
{
file_manager->m_char_file.loadFile(outPath);
file_manager->m_skel_file.loadFile(outPath);
free(outPath);
}
else if (result == NFD_ERROR)
Expand All @@ -270,8 +265,8 @@ void showMenuBar()

ImGui::Separator();

ImGui::TextDisabled("Skelton: %s", file_manager->m_skel_file.isFileLoaded() ? file_manager->m_skel_file.getPath().data() : "None");
ImGui::TextDisabled("Character: %s", file_manager->m_char_file.isFileLoaded() ? file_manager->m_char_file.getPath().data() : "None");
ImGui::TextDisabled("Skelton: %s", file_manager->m_skel_file.isFileLoaded() ? file_manager->m_skel_file.getPath().data() : "None");

ImGui::EndMenu();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/varedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void VarEdit::showPropList()
addTooltip("Remove unused properties (USE WITH CAUTION!)");
ImGui::SameLine();
if (ImGui::Button(ICON_FA_HASHTAG))
current_file.reindexProperties();
current_file.reindexProps();
addTooltip("Reindex properties\nDiscard all events properties obsolete");

ImGui::InputText("Filter", &m_prop_filter);
Expand Down
Loading

0 comments on commit ed92c6d

Please sign in to comment.