Skip to content

Commit

Permalink
Fix ModOptionPage
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaGu committed Sep 8, 2024
1 parent 4ddf0fa commit dbaf99b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
18 changes: 16 additions & 2 deletions include/BML/Bui.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,21 @@ namespace Bui {
if (page >= 0 && page < m_PageCount)
m_PageIndex = page;
}
int NextPage() { return m_PageIndex < m_PageCount ? ++m_PageIndex : m_PageCount - 1; }
int PrevPage() { return m_PageIndex > 0 ? --m_PageIndex : 0; }

int NextPage() {
int oldPage = m_PageIndex;
m_PageIndex = m_PageIndex < m_PageCount ? m_PageIndex + 1 : m_PageCount - 1;
if (oldPage != m_PageIndex)
OnPageChanged(m_PageIndex, oldPage);
return m_PageIndex;
}
int PrevPage() {
int oldPage = m_PageIndex;
m_PageIndex = m_PageIndex > 0 ? m_PageIndex - 1 : 0;
if (oldPage != m_PageIndex)
OnPageChanged(m_PageIndex, oldPage);
return m_PageIndex;
}

int GetMaxPage() const { return m_PageCount; }
void SetMaxPage(int num) {
Expand Down Expand Up @@ -241,6 +254,7 @@ namespace Bui {

virtual bool OnOpen() { return true; }
virtual void OnClose() {}
virtual void OnPageChanged(int newPage, int oldPage) {}

static std::size_t DrawEntries(const std::function<bool(std::size_t index)> &onEntry,
const ImVec2 &pos = ImVec2(0.35f, 0.24f), float spacing = 0.14f, std::size_t capability = 4) {
Expand Down
21 changes: 18 additions & 3 deletions src/BMLMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void ModOptionPage::OnDraw() {
m_IntFlags[index] = 2;
}
}
if (ImGui::IsItemDeactivated() && m_IntFlags[index] == 2) {
if (ImGui::IsItemDeactivatedAfterEdit() && m_IntFlags[index] == 2) {
property->SetInteger(m_IntValues[index]);
m_IntFlags[index] = 1;
}
Expand All @@ -331,11 +331,11 @@ void ModOptionPage::OnDraw() {
m_FloatFlags[index] = 1;
}
if (Bui::InputFloatButton(property->GetName(), &m_FloatValues[index])) {
if (fabs(m_FloatValues[index] - property->GetFloat()) < EPSILON) {
if (fabs(m_FloatValues[index] - property->GetFloat()) > EPSILON) {
m_FloatFlags[index] = 2;
}
}
if (ImGui::IsItemDeactivated() && m_FloatFlags[index] == 2) {
if (ImGui::IsItemDeactivatedAfterEdit() && m_FloatFlags[index] == 2) {
property->SetFloat(m_FloatValues[index]);
m_FloatFlags[index] = 1;
}
Expand All @@ -359,6 +359,21 @@ void ModOptionPage::OnClose() {
ModMenuPage::OnClose();
}

void ModOptionPage::OnPageChanged(int newPage, int oldPage) {
FlushBuffers();
}

void ModOptionPage::FlushBuffers() {
memset(m_Buffers, 0, sizeof(m_Buffers));
memset(m_BufferHashes, 0, sizeof(m_BufferHashes));
memset(m_KeyToggled, 0, sizeof(m_KeyToggled));
memset(m_KeyChord, 0, sizeof(m_KeyChord));
memset(m_IntFlags, 0, sizeof(m_IntFlags));
memset(m_FloatFlags, 0, sizeof(m_FloatFlags));
memset(m_IntValues, 0, sizeof(m_IntValues));
memset(m_FloatValues, 0, sizeof(m_FloatValues));
}

void ModOptionPage::ShowCommentBox(Property *property) {
ImGui::PushStyleColor(ImGuiCol_ChildBg, Bui::GetMenuColor());

Expand Down
3 changes: 3 additions & 0 deletions src/BMLMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class ModOptionPage : public ModMenuPage {
void OnAfterBegin() override;
void OnDraw() override;
void OnClose() override;
void OnPageChanged(int newPage, int oldPage) override;

protected:
void FlushBuffers();

static void ShowCommentBox(Property *property);

Category *m_Category = nullptr;
Expand Down

0 comments on commit dbaf99b

Please sign in to comment.