From 344feb997558e7b563653931201795abfee24a2e Mon Sep 17 00:00:00 2001 From: Vanawy Date: Sun, 19 Nov 2023 14:20:13 +0300 Subject: [PATCH 1/2] Draft: Add pagination option --- src/Interface/Controls/Pagination.as | 53 ++++++++++++++++++++++++++++ src/Interface/Tabs/PluginList.as | 43 +++++++++++++++++----- src/Settings.as | 5 ++- 3 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 src/Interface/Controls/Pagination.as diff --git a/src/Interface/Controls/Pagination.as b/src/Interface/Controls/Pagination.as new file mode 100644 index 0000000..a5a3c6b --- /dev/null +++ b/src/Interface/Controls/Pagination.as @@ -0,0 +1,53 @@ +namespace Controls +{ + class Pagination { + + int page = 0; + int total = 0; + int pageCount = 0; + + int m_limit = 3; + + bool isPageRequested = false; + int requestedPageIndex = 0; + + void Render() { + isPageRequested = false; + requestedPageIndex = 0; + + if (page > 0) { + PageButton(page - 1, "Prev Page"); + } + + UI::BeginGroup(); + for (uint i = Math::Max(0, page - m_limit); i < page; i++) { + PageButton(i); + } + + UI::BeginDisabled(); + PageButton(page); + + UI::EndDisabled(); + + for (uint i = page + 1; i < Math::Min(pageCount, page + m_limit + 1); i++) { + PageButton(i); + } + + if (pageCount > page + 1) { + PageButton(page + 1, "Next Page"); + } + UI::EndGroup(); + } + + void PageButton(int pageIndex, string label = "") { + if (label == "") { + label = "" + (pageIndex + 1); + } + if (UI::Button(label)) { + isPageRequested = true; + requestedPageIndex = pageIndex; + } + UI::SameLine(); + } + } +} \ No newline at end of file diff --git a/src/Interface/Tabs/PluginList.as b/src/Interface/Tabs/PluginList.as index 40a1440..44c8a16 100644 --- a/src/Interface/Tabs/PluginList.as +++ b/src/Interface/Tabs/PluginList.as @@ -10,6 +10,8 @@ class PluginListTab : Tab int m_pageCount; uint m_lastPageRequestFinished = 0; + Controls::Pagination m_pagination; + array m_plugins; string GetLabel() override { return "Plugins"; } @@ -59,7 +61,11 @@ class PluginListTab : Tab void StartRequest() { Clear(); - StartRequestForPage(0); + int defaultPage = 0; + if (Setting_TabsPagination) { + defaultPage = m_pagination.page; + } + StartRequestForPage(defaultPage); } void StartRequestForPage(int page) @@ -121,7 +127,17 @@ class PluginListTab : Tab m_page = js["page"]; m_pageCount = js["pages"]; + m_pagination.total = m_total; + m_pagination.page = m_page; + m_pagination.pageCount = m_pageCount; + auto jsItems = js["items"]; + + if (Setting_TabsPagination) { + UI::SetScrollY(0); + m_plugins.Resize(0); + } + for (uint i = 0; i < jsItems.Length; i++) { PluginInfo pi(jsItems[i]); if (Setting_ChangelogTooltips && pi.GetInstalledVersion() < pi.m_version) { @@ -188,17 +204,26 @@ class PluginListTab : Tab if (haveMorePages) { UI::TableNextRow(UI::TableRowFlags::None, rowHeight); UI::TableNextColumn(); - string infiniteScrollMsg = (m_request is null ? "Scroll to load" : "Loading") + " page " + (m_page + 2); - UI::Dummy(vec2(0, rowHeight / 3.0)); - UI::Text(infiniteScrollMsg); + if (!Setting_TabsPagination) { + string infiniteScrollMsg = (m_request is null ? "Scroll to load" : "Loading") + " page " + (m_page + 2); + UI::Dummy(vec2(0, rowHeight / 3.0)); + UI::Text(infiniteScrollMsg); + } } UI::EndTable(); - // after >500ms since the last request, get the next page if there is excess vertical space or when we scroll to just a bit before the final row is in view - bool waitedLongEnough = m_lastPageRequestFinished + 500 < Time::Now; - bool scrolledNearEnd = UI::GetScrollMaxY() == 0 || UI::GetScrollY() > (UI::GetScrollMaxY() - rowHeight); - if (waitedLongEnough && scrolledNearEnd && haveMorePages && m_request is null) { - StartRequestForPage(m_page + 1); + if (Setting_TabsPagination) { + m_pagination.Render(); + if (m_pagination.isPageRequested) { + StartRequestForPage(m_pagination.requestedPageIndex); + } + } else { + // after >500ms since the last request, get the next page if there is excess vertical space or when we scroll to just a bit before the final row is in view + bool waitedLongEnough = m_lastPageRequestFinished + 500 < Time::Now; + bool scrolledNearEnd = UI::GetScrollMaxY() == 0 || UI::GetScrollY() > (UI::GetScrollMaxY() - rowHeight); + if (waitedLongEnough && scrolledNearEnd && haveMorePages && m_request is null) { + StartRequestForPage(m_page + 1); + } } } } diff --git a/src/Settings.as b/src/Settings.as index 9b596e9..cb886f4 100644 --- a/src/Settings.as +++ b/src/Settings.as @@ -10,11 +10,14 @@ int Setting_PluginsPerRow = 3; [Setting category="Interface" name="Display changelog when hovering over updatable plugins."] bool Setting_ChangelogTooltips = true; +[Setting category="Interface" name="Enable tabs pagination"] +bool Setting_TabsPagination = true; + [Setting category="Advanced" name="Base URL" description="Only change if you know what you're doing!"] string Setting_BaseURL = "https://openplanet.dev/"; [Setting category="Advanced" name="Verbose logging (useful for development)"] -bool Setting_VerboseLog = false; +bool Setting_VerboseLog = true; [Setting category="Advanced" name="Auto-update plugins on game startup"] bool Setting_PerformAutoUpdates = false; From 3de9a91c6ce49509df47bba756c484c21ead3ffa Mon Sep 17 00:00:00 2001 From: Ilya Sakharchuk Date: Sun, 19 Nov 2023 14:26:45 +0300 Subject: [PATCH 2/2] revert default settings --- src/Settings.as | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Settings.as b/src/Settings.as index cb886f4..686225d 100644 --- a/src/Settings.as +++ b/src/Settings.as @@ -11,13 +11,13 @@ int Setting_PluginsPerRow = 3; bool Setting_ChangelogTooltips = true; [Setting category="Interface" name="Enable tabs pagination"] -bool Setting_TabsPagination = true; +bool Setting_TabsPagination = false; [Setting category="Advanced" name="Base URL" description="Only change if you know what you're doing!"] string Setting_BaseURL = "https://openplanet.dev/"; [Setting category="Advanced" name="Verbose logging (useful for development)"] -bool Setting_VerboseLog = true; +bool Setting_VerboseLog = false; [Setting category="Advanced" name="Auto-update plugins on game startup"] bool Setting_PerformAutoUpdates = false;