diff --git a/Source/UI/UIChangeMaterialWnd.cpp b/Source/UI/UIChangeMaterialWnd.cpp index f0f0313d..6ae81474 100644 --- a/Source/UI/UIChangeMaterialWnd.cpp +++ b/Source/UI/UIChangeMaterialWnd.cpp @@ -1,5 +1,33 @@ #include "UI/UIChangeMaterialWnd.h" +// OFFSET: 0x005E1080 +// FUNCTION: fn_03871 +void UIChangeMaterialWnd_List::sub_5E1080(int delta) { + int64_t newIndex = this->m_selectedIndex + delta; + const int count = static_cast(this->m_items.size()); + const int maxIndex = count - 1; + + if (newIndex >= static_cast(maxIndex)) { + newIndex = maxIndex; + } + + int targetIndex = static_cast(newIndex); + if (targetIndex < this->m_scrollOffset || targetIndex >= this->m_scrollOffset + this->m_pageSize) { + int newOffset = this->m_previousScrollOffset; + if (targetIndex < newOffset || targetIndex >= newOffset + this->m_pageSize) { + const int candidate = targetIndex - this->m_pageSize + 1; + const int limit = count - this->m_pageSize; + newOffset = static_cast(candidate) < static_cast(limit) ? candidate : limit; + } + + this->m_scrollOffset = newOffset; + this->sub_5E2A70(); + this->m_previousScrollOffset = this->m_scrollOffset; + } + + this->sub_5E3B80(targetIndex); +} + // OFFSET: 0x005E1120 // FUNCTION: fn_03872 ITEM_INFO* UIChangeMaterialWnd::GetItemAt(int x, int y) { diff --git a/Source/UI/UIChangeMaterialWnd.h b/Source/UI/UIChangeMaterialWnd.h index 4850ac98..51f47599 100644 --- a/Source/UI/UIChangeMaterialWnd.h +++ b/Source/UI/UIChangeMaterialWnd.h @@ -29,6 +29,20 @@ public: class UIChangeMaterialWnd_List : public UIFrameWnd { public: void Move(int x, int y) override; + + void sub_5E2A70(); + void sub_5E3B80(int index); + void sub_5E1080(int delta); + + /* 00BC */ int m_pageSize; + /* 00C0 */ int64_t m_selectedIndex; + /* 00C8 */ int unknown_00C8; + /* 00CC */ int unknown_00CC; + /* 00D0 */ int m_scrollOffset; + /* 00D4 */ int m_previousScrollOffset; + /* 00D8 */ int unknown_00D8; + /* 00DC */ std::vector m_items; + /* 00E8 */ unsigned char unknown_00E8[0x10]; }; #if defined(_WIN32) && !defined(_WIN64) @@ -36,6 +50,12 @@ static_assert(offsetof(UIChangeMaterialWnd, m_resultX) == 0xC4); static_assert(offsetof(UIChangeMaterialWnd, m_resultItem) == 0xD0); static_assert(offsetof(UIChangeMaterialWnd, m_materialPos) == 0x1C8); static_assert(offsetof(UIChangeMaterialWnd, m_materials) == 0x1F8); +static_assert(sizeof(UIChangeMaterialWnd_List) == 0xF8); +static_assert(offsetof(UIChangeMaterialWnd_List, m_pageSize) == 0xBC); +static_assert(offsetof(UIChangeMaterialWnd_List, m_selectedIndex) == 0xC0); +static_assert(offsetof(UIChangeMaterialWnd_List, m_scrollOffset) == 0xD0); +static_assert(offsetof(UIChangeMaterialWnd_List, m_previousScrollOffset) == 0xD4); +static_assert(offsetof(UIChangeMaterialWnd_List, m_items) == 0xDC); #endif #endif