Skip to content

Commit

Permalink
Allow disabling icon colors in inventory menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Parapets committed Feb 22, 2023
1 parent 09468d1 commit 610abdd
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Data/CustomDataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace Data
rule.SetInfo(a_entryObject, needsIconUpdate);
}

if (needsIconUpdate) {
if (needsIconUpdate && a_processIconCallback) {
a_processIconCallback(a_entryObject);
}

Expand Down
65 changes: 39 additions & 26 deletions src/Hooks/FavoritesListEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,7 @@ namespace Hooks
return;
}

// Favorites menu icons are offset by (64, 64) compared to icon swf
// Icon sprite also has a transform, which might vary depending on mods
if (!a_params.thisPtr->HasMember("_iconPosFixed")) {
RE::GFxValue transform;
itemIcon.GetMember("transform", &transform);

if (transform.IsObject()) {
RE::GFxValue matrix;
transform.GetMember("matrix", &matrix);

if (matrix.IsObject()) {
RE::GFxValue sx, sy;
matrix.GetMember("a", &sx);
matrix.GetMember("d", &sy);

if (sx.IsNumber() && sy.IsNumber()) {
std::array<RE::GFxValue, 2>
args{ -64.0 * sx.GetNumber(), -64.0 * sy.GetNumber() };
matrix.Invoke("translate", args);

transform.SetMember("matrix", matrix);
a_params.thisPtr->SetMember("_iconPosFixed", true);
}
}
}
}
FixIconPos(a_params.thisPtr, itemIcon);

// We are overriding the embedded icons in the movie
const char* source = "skyui/icons_item_psychosteve.swf";
Expand Down Expand Up @@ -171,6 +146,44 @@ namespace Hooks
ChangeIconColor(a_icon, iconColor);
}

void FavoritesListEntry::FixIconPos(RE::GFxValue* a_thisPtr, RE::GFxValue& a_icon)
{
assert(a_thisPtr);
assert(a_icon.IsDisplayObject());

// Favorites menu icons are offset by (64, 64) compared to icon swf
// Icon sprite also has a transform, which might vary depending on mods
if (a_thisPtr->HasMember("_iconPosFixed")) {
return;
}

RE::GFxValue transform;
a_icon.GetMember("transform", &transform);

if (!transform.IsObject()) {
return;
}

RE::GFxValue matrix;
transform.GetMember("matrix", &matrix);

if (!matrix.IsObject()) {
return;
}

RE::GFxValue sx, sy;
matrix.GetMember("a", &sx);
matrix.GetMember("d", &sy);

if (sx.IsNumber() && sy.IsNumber()) {
std::array<RE::GFxValue, 2> args{ -64.0 * sx.GetNumber(), -64.0 * sy.GetNumber() };
matrix.Invoke("translate", args);

transform.SetMember("matrix", matrix);
a_thisPtr->SetMember("_iconPosFixed", true);
}
}

void FavoritesListEntry::ChangeIconColor(const RE::GFxValue& a_icon, const RE::GFxValue& a_rgb)
{
if (!a_icon.IsDisplayObject()) {
Expand Down
2 changes: 2 additions & 0 deletions src/Hooks/FavoritesListEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Hooks
void Call(Params& a_params) override;
};

static void FixIconPos(RE::GFxValue* a_thisPtr, RE::GFxValue& a_icon);

static void ChangeIconColor(const RE::GFxValue& a_icon, const RE::GFxValue& a_rgb);

static RE::GRenderer::Cxform GetColorTransform(std::uint32_t a_rgb);
Expand Down
54 changes: 40 additions & 14 deletions src/Hooks/IconSetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ namespace Hooks
a_list.GetMember("_entryList", &entryList);
}

if (entryList.IsArray()) {
for (std::uint32_t i = 0, size = entryList.GetArraySize(); i < size; i++) {
RE::GFxValue entryObject;
entryList.GetElement(i, &entryObject);
ModifyObject(a_params.movie, entryObject);
}
if (!entryList.IsArray()) {
return;
}

for (std::uint32_t i = 0, size = entryList.GetArraySize(); i < size; i++) {
RE::GFxValue entryObject;
entryList.GetElement(i, &entryObject);
ModifyObject(a_params.movie, entryObject);
}

if (_oldFunc.IsObject()) {
Expand All @@ -59,23 +61,47 @@ namespace Hooks
static_cast<std::size_t>(a_params.argCount) + 1);
}

if (entryList.IsArray()) {
for (std::uint32_t i = 0, size = entryList.GetArraySize(); i < size; i++) {
RE::GFxValue entryObject;
entryList.GetElement(i, &entryObject);
if (entryObject.IsObject()) {
ProcessEntry(a_params.thisPtr, &entryObject);
RE::GFxValue _noIconColors;
a_params.thisPtr->GetMember("_noIconColors", &_noIconColors);
bool noIconColors = _noIconColors.IsBool() && _noIconColors.GetBool();
RE::GFxValue defaultColor;

if (noIconColors) {
RE::GFxValue dummy;
a_params.movie->CreateObject(&dummy);

auto dataManager = Data::CustomDataManager::GetSingleton();
dataManager->ProcessEntry(&dummy, {});

dummy.GetMember("iconColor", &defaultColor);
}

for (std::uint32_t i = 0, size = entryList.GetArraySize(); i < size; i++) {
RE::GFxValue entryObject;
entryList.GetElement(i, &entryObject);
if (!entryObject.IsObject()) {
continue;
}

ProcessEntry(a_params.thisPtr, &entryObject);

if (noIconColors && entryObject.HasMember("iconColor")) {
if (defaultColor.IsUndefined()) {
entryObject.DeleteMember("iconColor");
}
else {
entryObject.SetMember("iconColor", defaultColor);
}
}
}
}

void IconSetter::ProcessEntry(RE::GFxValue* a_thisPtr, RE::GFxValue* a_entryObject)
{
const auto inventoryManager = Data::CustomDataManager::GetSingleton();
const auto dataManager = Data::CustomDataManager::GetSingleton();

auto processIconCallback = std::bind_front(&ProcessIconInternal, a_thisPtr);
inventoryManager->ProcessEntry(a_entryObject, processIconCallback);
dataManager->ProcessEntry(a_entryObject, processIconCallback);
}

void IconSetter::ProcessIconInternal(RE::GFxValue* a_thisPtr, RE::GFxValue* a_entryObject)
Expand Down

0 comments on commit 610abdd

Please sign in to comment.