From 66104476bbe25d53b24a4d9c9d1f3975211e4fed Mon Sep 17 00:00:00 2001 From: Beherith Date: Wed, 25 Nov 2020 12:09:36 +0100 Subject: [PATCH 1/8] Add option to shorten download names --- LuaMenu/widgets/gui_download_window.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LuaMenu/widgets/gui_download_window.lua b/LuaMenu/widgets/gui_download_window.lua index fb75da205..70f76c40f 100644 --- a/LuaMenu/widgets/gui_download_window.lua +++ b/LuaMenu/widgets/gui_download_window.lua @@ -127,6 +127,10 @@ local function CreateDownloadEntry(downloadData) parent = holder, } + local downloadDataname = downloadData.name + if Configuration.gameConfig and Configuration.gameConfig.ShortenNameString then + downloadDataname = Configuration.gameConfig.ShortenNameString(downloadDataname) + end TextBox:New { x = 15 + BUTTON_WIDTH*2, y = 12, @@ -134,7 +138,7 @@ local function CreateDownloadEntry(downloadData) height = 20, valign = 'center', fontsize = Configuration:GetFont(2).size, - text = downloadData.name, + text = downloadDataname, parent = holder, } From cf7036c859b5f112e845f9f6d53f511955ac493b Mon Sep 17 00:00:00 2001 From: Beherith Date: Wed, 9 Dec 2020 10:19:59 +0100 Subject: [PATCH 2/8] Automatically retry downloads up to WG.Chobby.Configuration.downloadRetryCount times Because very often the download itself actually succeeds, but VFS does not pick it up yet. So a retry in these cases usually does not result in a network transfer, just a vfs recheck, one frame later. --- LuaMenu/widgets/api_download_handler.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/LuaMenu/widgets/api_download_handler.lua b/LuaMenu/widgets/api_download_handler.lua index e6e2c9ded..c6d944e80 100644 --- a/LuaMenu/widgets/api_download_handler.lua +++ b/LuaMenu/widgets/api_download_handler.lua @@ -18,7 +18,7 @@ local externalFunctions = {} local listeners = {} local wrapperFunctions = {} -local downloadQueue = {} -- {name, fileType, priority, id} +local downloadQueue = {} -- {name, fileType, priority, id, retryCount} local downloadCount = 0 local topPriority = 0 local removedDownloads = {} @@ -169,6 +169,17 @@ local function RemoveDownload(name, fileType, putInRemoveList, removalType) end downloadQueue[index] = downloadQueue[#downloadQueue] downloadQueue[#downloadQueue] = nil + + if putInRemoveList and removalType == "fail" and WG.Chobby.Configuration.downloadRetryCount then + local lastFailed = removedDownloads[#removedDownloads] + if lastFailed.retryCount < WG.Chobby.Configuration.downloadRetryCount then + Spring.Echo("Downloading of ",name,fileType,"failed, retryCount=", lastFailed.retryCount) + lastFailed.retryCount = lastFailed.retryCount + 1 + externalFunctions.RetryDownload(name,fileType) + end + else + + end requestUpdate = true return true end @@ -203,6 +214,7 @@ function externalFunctions.QueueDownload(name, fileType, priority) fileType = fileType, priority = priority, id = downloadCount, + retryCount = 0, } requestUpdate = true CallListeners("DownloadQueued", downloadCount, name, fileType) From 55ed83daef8ef27c28391d9086d0b787acc168de Mon Sep 17 00:00:00 2001 From: Beherith Date: Wed, 9 Dec 2020 10:42:53 +0100 Subject: [PATCH 3/8] Create an Integer popup window type --- LuaMenu/widgets/gui_integer_popup_window.lua | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 LuaMenu/widgets/gui_integer_popup_window.lua diff --git a/LuaMenu/widgets/gui_integer_popup_window.lua b/LuaMenu/widgets/gui_integer_popup_window.lua new file mode 100644 index 000000000..03e9cecd5 --- /dev/null +++ b/LuaMenu/widgets/gui_integer_popup_window.lua @@ -0,0 +1,107 @@ +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:GetInfo() + return { + name = "Integer Selector Window", + desc = "Displays an integer selector window popup.", + author = "Beherith", + date = "2020.11", + license = "GNU LGPL, v2.1 or later", + layer = 0, + enabled = true -- loaded by default? + } +end + + +local function CreateIntegerSelectorWindow(opts) + opts = opts or {} + + local integerTrackBarValue = opts.defaultValue or 0 + local Configuration = WG.Chobby.Configuration + + local IntegerSelectorWindow = Window:New { + caption = opts.caption or "", + name = "IntegerSelectorWindow", + parent = screen0, + width = 280, + height = 330, + resizable = false, + draggable = false, + classname = "main_window", + } + + local function ChangeAccepted() + if opts.OnAccepted then + opts.OnAccepted(integerTrackBarValue) + end + end + + local function CloseFunction() + IntegerSelectorWindow:Dispose() + IntegerSelectorWindow = nil + end + + local lblTitle = TextBox:New { + x = "5%", + y = "10%", + width = IntegerSelectorWindow.width - IntegerSelectorWindow.padding[1] - IntegerSelectorWindow.padding[3], + height = 35, + align = "center", + font = Configuration:GetFont(2), + text = opts.labelCaption or "", + parent = IntegerSelectorWindow, + } + + local btnOK = Button:New { + x = "10%", + width = "30%", + bottom = 1, + height = 40, + caption = i18n("ok"), + font = Configuration:GetFont(2), + classname = "action_button", + OnClick = { CloseFunction, ChangeAccepted }, + parent = IntegerSelectorWindow, + } + + local btnCancel = Button:New { + right = "10%", + width = "30%", + bottom = 1, + height = 40, + caption = i18n("cancel"), + font = Configuration:GetFont(2), + classname = "action_button", + OnClick = { CloseFunction }, + parent = IntegerSelectorWindow, + } + + + local integerTrackBar = Trackbar:New { + x = 0, + width = IntegerSelectorWindow.width * 0.90, + height = 40, + bottom = 45, + value = opts.defaultValue or 0, + min = opts.minValue or 0, + max = opts.maxValue or 100, + step = opts.step or 1, + parent = IntegerSelectorWindow, + OnChange = { + function(obj, value) + integerTrackBarValue = value + end + } + } + + WG.Chobby.PriorityPopup(IntegerSelectorWindow, CloseFunction, CloseFunction, screen0) +end + +function widget:Initialize() + VFS.Include(LUA_DIRNAME .. "widgets/chobby/headers/exports.lua", nil, VFS.RAW_FIRST) + + WG.IntegerSelectorWindow = { + CreateIntegerSelectorWindow = CreateIntegerSelectorWindow + } +end From 7df1ef42155cd9ba35213f70c214b50a1a0cce4a Mon Sep 17 00:00:00 2001 From: Beherith Date: Wed, 9 Dec 2020 19:40:46 +0100 Subject: [PATCH 4/8] Enable filtering of redundant empty hosts --- .../components/battle/battle_list_window.lua | 89 ++++++++++++++++++- .../widgets/chobby/components/list_window.lua | 9 +- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index e3e448bb4..ba93b5c3b 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -120,11 +120,34 @@ function BattleListWindow:init(parent) }, parent = self.window, } + if Configuration.battleFilterRedundant then + local checkRedundant = Checkbox:New { + x = 590, + width = 21, + bottom = 4, + height = 30, + boxalign = "left", + boxsize = 20, + caption = " Redundant", + checked = Configuration.battleFilterRedundant or false, + font = Configuration:GetFont(2), + OnChange = { + function (obj, newState) + Configuration:SetConfigValue("battleFilterRedundant", newState) + SoftUpdate() + end + }, + parent = self.window, + } + end local function UpdateCheckboxes() checkPassworded:SetToggle(Configuration.battleFilterPassworded2) checkNonFriend:SetToggle(Configuration.battleFilterNonFriend) checkRunning:SetToggle(Configuration.battleFilterRunning) + if Configuration.battleFilterRedundant then + checkRedundant:SetToggle(Configuration.battleFilterRedundant) + end end WG.Delay(UpdateCheckboxes, 0.2) @@ -581,7 +604,7 @@ function BattleListWindow:AddBattle(battleID, battle) self:AddRow({button}, battle.battleID) end -function BattleListWindow:ItemInFilter(id) +function BattleListWindow:ItemInFilter(id, allbattles) local battle = lobby:GetBattle(id) local filterString = Configuration.gameConfig.battleListOnlyShow if filterString ~= nil then @@ -598,9 +621,73 @@ function BattleListWindow:ItemInFilter(id) return false end end + if Configuration.battleFilterRunning and battle.isRunning then return false end + + if Configuration.battleFilterRedundant and allbattles then + local myplayercount = lobby:GetBattlePlayerCount(id) + --Spring.Echo("redundancy filter checking for",battle.isRunning, battle.spectatorCount,myplayercount) + -- for each non-empty battle, only display EU-AUS-USA- hosts first number that is empty + if battle.isRunning then return true end + if myplayercount and myplayercount > 0 then return true end + if battle.spectatorCount and battle.spectatorCount > 1 then return true end + + function parseBattleNumber(btitle) + battlekeys = Configuration.battleFilterRedundantRegions or {} + local hostcountry = nil + for k,battlekey in pairs(battlekeys) do + if string.find( btitle,battlekey ) == 1 then + hostcountry = battlekey + end + end + if hostcountry == nil then + return nil + else + local numbertext = string.sub(btitle,string.len(hostcountry),-1) + if pcall(tonumber, numbertext) == false then return nil end + local hostnumber = tonumber(numbertext) + if hostnumber == nil then + return nil + else + return hostcountry, hostnumber + end + end + end + + local myBattleTitle = battle.title + local mycountry, mynumber = parseBattleNumber(battle.title) + --Spring.Echo("redundancy filter checking for", mycountry,mynumber) + if mycountry == nil then return true end + + local lowestemptybattleindex = 100000000 + local lowestemptybattleID = nil + for k,otherbattleID in pairs(allbattles) do + local otherbattle = lobby:GetBattle(otherbattleID) + local ob_hostcountry, ob_hostnumber = parseBattleNumber(otherbattle.title) + local otherbattleplayercount = lobby:GetBattlePlayerCount(otherbattleID) + + --Spring.Echo("Other battle", ob_hostcountry, ob_hostnumber,otherbattleplayercount ,otherbattle.spectatorCount) + if ob_hostcountry and + ob_hostnumber < lowestemptybattleindex and + otherbattleplayercount == 0 and + otherbattle.spectatorCount == 1 and + mycountry == ob_hostcountry then + + lowestemptybattleID = otherbattleID + lowestemptybattleindex = ob_hostnumber + end + end + if lowestemptybattleID == nil then return true end + + if lowestemptybattleID == id then + return true + else + return false + end + end + return true end diff --git a/LuaMenu/widgets/chobby/components/list_window.lua b/LuaMenu/widgets/chobby/components/list_window.lua index 07934c659..5610d5d0b 100644 --- a/LuaMenu/widgets/chobby/components/list_window.lua +++ b/LuaMenu/widgets/chobby/components/list_window.lua @@ -215,13 +215,18 @@ function ListWindow:CompareItems(id1, id2) return true end -function ListWindow:ItemInFilter(id) +function ListWindow:ItemInFilter(id, allbattleids) return true end function ListWindow:UpdateFilters() + local allbattleids = {} for i = 1, self.scrollChildren do - self.orderPanelMapping[i].inFilter = self:ItemInFilter(self.orderPanelMapping[i].id) + allbattleids[#allbattleids+1] = self.orderPanelMapping[i].id + end + + for i = 1, self.scrollChildren do + self.orderPanelMapping[i].inFilter = self:ItemInFilter(self.orderPanelMapping[i].id, allbattleids) end for id, _ in pairs(self.itemPanelMapping) do self:RecalculateOrder(id) From 68404703aba05c92c6d4d2cf481cbff2e9ce4377 Mon Sep 17 00:00:00 2001 From: Beherith Date: Thu, 10 Dec 2020 14:44:21 +0100 Subject: [PATCH 5/8] Make travis not cry --- LuaMenu/widgets/api_download_handler.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/LuaMenu/widgets/api_download_handler.lua b/LuaMenu/widgets/api_download_handler.lua index c6d944e80..a9eb48f2c 100644 --- a/LuaMenu/widgets/api_download_handler.lua +++ b/LuaMenu/widgets/api_download_handler.lua @@ -177,8 +177,6 @@ local function RemoveDownload(name, fileType, putInRemoveList, removalType) lastFailed.retryCount = lastFailed.retryCount + 1 externalFunctions.RetryDownload(name,fileType) end - else - end requestUpdate = true return true From 4f13c8fb5a086a545afb34c5d271160ebbd7c033 Mon Sep 17 00:00:00 2001 From: Beherith Date: Thu, 10 Dec 2020 14:46:11 +0100 Subject: [PATCH 6/8] white space --- .../chobby/components/battle/battle_list_window.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index ba93b5c3b..d7e11cf87 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -648,14 +648,13 @@ function BattleListWindow:ItemInFilter(id, allbattles) local numbertext = string.sub(btitle,string.len(hostcountry),-1) if pcall(tonumber, numbertext) == false then return nil end local hostnumber = tonumber(numbertext) - if hostnumber == nil then + if hostnumber == nil then return nil else return hostcountry, hostnumber end end end - local myBattleTitle = battle.title local mycountry, mynumber = parseBattleNumber(battle.title) --Spring.Echo("redundancy filter checking for", mycountry,mynumber) @@ -669,8 +668,8 @@ function BattleListWindow:ItemInFilter(id, allbattles) local otherbattleplayercount = lobby:GetBattlePlayerCount(otherbattleID) --Spring.Echo("Other battle", ob_hostcountry, ob_hostnumber,otherbattleplayercount ,otherbattle.spectatorCount) - if ob_hostcountry and - ob_hostnumber < lowestemptybattleindex and + if ob_hostcountry and + ob_hostnumber < lowestemptybattleindex and otherbattleplayercount == 0 and otherbattle.spectatorCount == 1 and mycountry == ob_hostcountry then @@ -681,7 +680,7 @@ function BattleListWindow:ItemInFilter(id, allbattles) end if lowestemptybattleID == nil then return true end - if lowestemptybattleID == id then + if lowestemptybattleID == id then return true else return false From be5c79ce94c2e5d58fe6df95f0cdd59722e9ce8d Mon Sep 17 00:00:00 2001 From: Beherith Date: Thu, 10 Dec 2020 17:59:32 +0100 Subject: [PATCH 7/8] Tooltips to battle filters --- .../widgets/chobby/components/battle/battle_list_window.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index d7e11cf87..60acf1d80 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -83,6 +83,7 @@ function BattleListWindow:init(parent) end }, parent = self.window, + tooltip = "Hides all private battles that require a password to join", } local checkNonFriend = Checkbox:New { x = 280, @@ -101,6 +102,7 @@ function BattleListWindow:init(parent) end }, parent = self.window, + tooltip = "Hides all battles that dont have your friends in them", } local checkRunning = Checkbox:New { x = 435, @@ -119,6 +121,7 @@ function BattleListWindow:init(parent) end }, parent = self.window, + tooltip = "Hides all battles that are in progress", } if Configuration.battleFilterRedundant then local checkRedundant = Checkbox:New { @@ -138,6 +141,7 @@ function BattleListWindow:init(parent) end }, parent = self.window, + tooltip = "Hides empty regional autohosts", } end From d58721f75d397a10254d8e30d9649a7b6a3ffce7 Mon Sep 17 00:00:00 2001 From: Gajo Petrovic Date: Sun, 13 Dec 2020 15:43:59 +0900 Subject: [PATCH 8/8] - remove modifications in list_window.lua - DRY battle_list_window's SoftUpdate - fix spelling & tweak tooltip text - move "hide redundant battlerooms" to a dev-only checkbox --- LuaMenu/widgets/api_download_handler.lua | 4 +- .../components/battle/battle_list_window.lua | 176 ++++++++---------- .../widgets/chobby/components/list_window.lua | 9 +- LuaMenu/widgets/gui_download_window.lua | 8 +- LuaMenu/widgets/gui_settings_window.lua | 4 + 5 files changed, 92 insertions(+), 109 deletions(-) diff --git a/LuaMenu/widgets/api_download_handler.lua b/LuaMenu/widgets/api_download_handler.lua index a9eb48f2c..01c43a958 100644 --- a/LuaMenu/widgets/api_download_handler.lua +++ b/LuaMenu/widgets/api_download_handler.lua @@ -173,8 +173,8 @@ local function RemoveDownload(name, fileType, putInRemoveList, removalType) if putInRemoveList and removalType == "fail" and WG.Chobby.Configuration.downloadRetryCount then local lastFailed = removedDownloads[#removedDownloads] if lastFailed.retryCount < WG.Chobby.Configuration.downloadRetryCount then - Spring.Echo("Downloading of ",name,fileType,"failed, retryCount=", lastFailed.retryCount) - lastFailed.retryCount = lastFailed.retryCount + 1 + Spring.Echo("Downloading of ", name, fileType, "failed, retryCount=", lastFailed.retryCount) + lastFailed.retryCount = lastFailed.retryCount + 1 externalFunctions.RetryDownload(name,fileType) end end diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index 60acf1d80..60bf0a004 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -27,11 +27,6 @@ function BattleListWindow:init(parent) } end - local function SoftUpdate() - self:UpdateFilters() - self:UpdateInfoPanel() - end - local function update() self:Update() end @@ -79,11 +74,11 @@ function BattleListWindow:init(parent) OnChange = { function (obj, newState) Configuration:SetConfigValue("battleFilterPassworded2", newState) - SoftUpdate() + self:SoftUpdate() end }, parent = self.window, - tooltip = "Hides all private battles that require a password to join", + tooltip = "Hides all battles that require a password to join", } local checkNonFriend = Checkbox:New { x = 280, @@ -98,11 +93,11 @@ function BattleListWindow:init(parent) OnChange = { function (obj, newState) Configuration:SetConfigValue("battleFilterNonFriend", newState) - SoftUpdate() + self:SoftUpdate() end }, parent = self.window, - tooltip = "Hides all battles that dont have your friends in them", + tooltip = "Hides all battles that don't have your friends in them", } local checkRunning = Checkbox:New { x = 435, @@ -117,41 +112,17 @@ function BattleListWindow:init(parent) OnChange = { function (obj, newState) Configuration:SetConfigValue("battleFilterRunning", newState) - SoftUpdate() + self:SoftUpdate() end }, parent = self.window, tooltip = "Hides all battles that are in progress", } - if Configuration.battleFilterRedundant then - local checkRedundant = Checkbox:New { - x = 590, - width = 21, - bottom = 4, - height = 30, - boxalign = "left", - boxsize = 20, - caption = " Redundant", - checked = Configuration.battleFilterRedundant or false, - font = Configuration:GetFont(2), - OnChange = { - function (obj, newState) - Configuration:SetConfigValue("battleFilterRedundant", newState) - SoftUpdate() - end - }, - parent = self.window, - tooltip = "Hides empty regional autohosts", - } - end local function UpdateCheckboxes() checkPassworded:SetToggle(Configuration.battleFilterPassworded2) checkNonFriend:SetToggle(Configuration.battleFilterNonFriend) checkRunning:SetToggle(Configuration.battleFilterRunning) - if Configuration.battleFilterRedundant then - checkRedundant:SetToggle(Configuration.battleFilterRedundant) - end end WG.Delay(UpdateCheckboxes, 0.2) @@ -172,7 +143,7 @@ function BattleListWindow:init(parent) return end self:AddBattle(battleID, lobby:GetBattle(battleID)) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnBattleOpened", self.onBattleOpened) @@ -181,7 +152,7 @@ function BattleListWindow:init(parent) return end self:RemoveRow(battleID) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnBattleClosed", self.onBattleClosed) @@ -190,7 +161,7 @@ function BattleListWindow:init(parent) return end self:JoinedBattle(battleID) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnJoinedBattle", self.onJoinedBattle) @@ -199,7 +170,7 @@ function BattleListWindow:init(parent) return end self:LeftBattle(battleID) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnLeftBattle", self.onLeftBattle) @@ -208,7 +179,7 @@ function BattleListWindow:init(parent) return end self:OnUpdateBattleInfo(battleID) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnUpdateBattleInfo", self.onUpdateBattleInfo) @@ -217,13 +188,15 @@ function BattleListWindow:init(parent) return end self:OnBattleIngameUpdate(battleID, isRunning) - SoftUpdate() + self:SoftUpdate() end lobby:AddListener("OnBattleIngameUpdate", self.onBattleIngameUpdate) local function onConfigurationChange(listener, key, value) if key == "displayBadEngines2" then update() + elseif key == "battleFilterRedundant" then + self:SoftUpdate() end end Configuration:AddListener("OnConfigurationChange", onConfigurationChange) @@ -249,6 +222,13 @@ function BattleListWindow:RemoveListeners() lobby:RemoveListener("DownloadFinished", self.downloadFinished) end +function BattleListWindow:UpdateAllBattleIDs() + self.allBattleIDs = {} + for i = 1, self.scrollChildren do + self.allBattleIDs[i] = self.orderPanelMapping[i].id + end +end + function BattleListWindow:Update() self:Clear() @@ -262,6 +242,14 @@ function BattleListWindow:Update() for _, battle in pairs(battles) do self:AddBattle(battle.battleID, battle) end + + self:SoftUpdate() +end + +function BattleListWindow:SoftUpdate() + if Configuration.battleFilterRedundant then + self:UpdateAllBattleIDs() + end self:UpdateFilters() self:UpdateInfoPanel() end @@ -608,7 +596,7 @@ function BattleListWindow:AddBattle(battleID, battle) self:AddRow({button}, battle.battleID) end -function BattleListWindow:ItemInFilter(id, allbattles) +function BattleListWindow:ItemInFilter(id) local battle = lobby:GetBattle(id) local filterString = Configuration.gameConfig.battleListOnlyShow if filterString ~= nil then @@ -630,68 +618,64 @@ function BattleListWindow:ItemInFilter(id, allbattles) return false end - if Configuration.battleFilterRedundant and allbattles then - local myplayercount = lobby:GetBattlePlayerCount(id) - --Spring.Echo("redundancy filter checking for",battle.isRunning, battle.spectatorCount,myplayercount) - -- for each non-empty battle, only display EU-AUS-USA- hosts first number that is empty - if battle.isRunning then return true end - if myplayercount and myplayercount > 0 then return true end - if battle.spectatorCount and battle.spectatorCount > 1 then return true end - - function parseBattleNumber(btitle) - battlekeys = Configuration.battleFilterRedundantRegions or {} - local hostcountry = nil - for k,battlekey in pairs(battlekeys) do - if string.find( btitle,battlekey ) == 1 then - hostcountry = battlekey - end - end - if hostcountry == nil then - return nil - else - local numbertext = string.sub(btitle,string.len(hostcountry),-1) - if pcall(tonumber, numbertext) == false then return nil end - local hostnumber = tonumber(numbertext) - if hostnumber == nil then - return nil - else - return hostcountry, hostnumber - end + if Configuration.battleFilterRedundant then + return self:FilterRedundantBattle(battle, id) + end + + return true +end + +function BattleListWindow:FilterRedundantBattle(battle, id) + -- for each non-empty battle, only display EU-AUS-USA- hosts first number that is empty + if battle.isRunning + or lobby:GetBattlePlayerCount(id) > 0 + or (battle.spectatorCount and battle.spectatorCount > 1) then + return true + end + + function parseBattleNumber(battleTitle) + battleKeys = Configuration.battleFilterRedundantRegions or {} + local hostCountry = nil + for k, battleKey in pairs(battleKeys) do + if string.find(battleTitle, battleKey) == 1 then + hostCountry = battleKey end end - local myBattleTitle = battle.title - local mycountry, mynumber = parseBattleNumber(battle.title) - --Spring.Echo("redundancy filter checking for", mycountry,mynumber) - if mycountry == nil then return true end - - local lowestemptybattleindex = 100000000 - local lowestemptybattleID = nil - for k,otherbattleID in pairs(allbattles) do - local otherbattle = lobby:GetBattle(otherbattleID) - local ob_hostcountry, ob_hostnumber = parseBattleNumber(otherbattle.title) - local otherbattleplayercount = lobby:GetBattlePlayerCount(otherbattleID) - - --Spring.Echo("Other battle", ob_hostcountry, ob_hostnumber,otherbattleplayercount ,otherbattle.spectatorCount) - if ob_hostcountry and - ob_hostnumber < lowestemptybattleindex and - otherbattleplayercount == 0 and - otherbattle.spectatorCount == 1 and - mycountry == ob_hostcountry then - - lowestemptybattleID = otherbattleID - lowestemptybattleindex = ob_hostnumber - end + if hostCountry == nil then + return nil end - if lowestemptybattleID == nil then return true end - if lowestemptybattleID == id then - return true - else - return false + local hostnumber = tonumber(string.sub(battleTitle, string.len(hostCountry), -1)) + if hostnumber == nil then + return nil end + + return hostCountry, hostnumber + end + local myCountry, myNumber = parseBattleNumber(battle.title) + if myCountry == nil then + return true end - return true + local lowestEmptyBattleIndex = math.huge + local lowestEmptyBattleID = nil + for k, otherBattleID in pairs(self.allBattleIDs) do + local otherBattle = lobby:GetBattle(otherBattleID) + local ob_hostCountry, ob_hostnumber = parseBattleNumber(otherBattle.title) + local otherBattlePlayerCount = lobby:GetBattlePlayerCount(otherBattleID) + + if ob_hostCountry and + ob_hostnumber < lowestEmptyBattleIndex and + otherBattlePlayerCount == 0 and + otherBattle.spectatorCount == 1 and + myCountry == ob_hostCountry then + + lowestEmptyBattleID = otherBattleID + lowestEmptyBattleIndex = ob_hostnumber + end + end + + return lowestEmptyBattleID == nil or lowestEmptyBattleID == id end function BattleListWindow:CompareItems(id1, id2) diff --git a/LuaMenu/widgets/chobby/components/list_window.lua b/LuaMenu/widgets/chobby/components/list_window.lua index 5610d5d0b..07934c659 100644 --- a/LuaMenu/widgets/chobby/components/list_window.lua +++ b/LuaMenu/widgets/chobby/components/list_window.lua @@ -215,18 +215,13 @@ function ListWindow:CompareItems(id1, id2) return true end -function ListWindow:ItemInFilter(id, allbattleids) +function ListWindow:ItemInFilter(id) return true end function ListWindow:UpdateFilters() - local allbattleids = {} for i = 1, self.scrollChildren do - allbattleids[#allbattleids+1] = self.orderPanelMapping[i].id - end - - for i = 1, self.scrollChildren do - self.orderPanelMapping[i].inFilter = self:ItemInFilter(self.orderPanelMapping[i].id, allbattleids) + self.orderPanelMapping[i].inFilter = self:ItemInFilter(self.orderPanelMapping[i].id) end for id, _ in pairs(self.itemPanelMapping) do self:RecalculateOrder(id) diff --git a/LuaMenu/widgets/gui_download_window.lua b/LuaMenu/widgets/gui_download_window.lua index 70f76c40f..bff48fdc6 100644 --- a/LuaMenu/widgets/gui_download_window.lua +++ b/LuaMenu/widgets/gui_download_window.lua @@ -127,9 +127,9 @@ local function CreateDownloadEntry(downloadData) parent = holder, } - local downloadDataname = downloadData.name - if Configuration.gameConfig and Configuration.gameConfig.ShortenNameString then - downloadDataname = Configuration.gameConfig.ShortenNameString(downloadDataname) + local downloadDataName = downloadData.name + if Configuration.gameConfig.ShortenNameString then + downloadDataName = Configuration.gameConfig.ShortenNameString(downloadDataName) end TextBox:New { x = 15 + BUTTON_WIDTH*2, @@ -138,7 +138,7 @@ local function CreateDownloadEntry(downloadData) height = 20, valign = 'center', fontsize = Configuration:GetFont(2).size, - text = downloadDataname, + text = downloadDataName, parent = holder, } diff --git a/LuaMenu/widgets/gui_settings_window.lua b/LuaMenu/widgets/gui_settings_window.lua index f9d0f6186..cf329acf5 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -1044,6 +1044,10 @@ local function GetVoidTabControls() children[#children + 1], offset = AddCheckboxSetting(offset, "Agressive Set Borderless", "agressivelySetBorderlessWindowed", false) children[#children + 1], offset = AddCheckboxSetting(offset, "Use wrong engine", "useWrongEngine", false) children[#children + 1], offset = AddCheckboxSetting(offset, "Show old AI versions", "showOldAiVersions", false) + children[#children + 1], offset = AddCheckboxSetting(offset, "Show AIOptions", "showAiOptions", true) + if Configuration.gameConfig.filterEmptyRegionalAutohosts then + children[#children + 1], offset = AddCheckboxSetting(offset, "Filter redundant battles", "battleFilterRedundant", true, nil, "Hides redundant empty regional autohosts.") + end children[#children + 1] = Label:New { x = 20,