Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added LuaMenu/images/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 55 additions & 30 deletions LuaMenu/widgets/chobby/components/ai_list_window.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
AiListWindow = ListWindow:extends{}

function AiListWindow:init(gameName)
local IMG_SETTINGS = LUA_DIRNAME .. "images/settings.png"

function AiListWindow:init(lobby, gameName)

self:super('init', lobbyInterfaceHolder, "Choose AI", false, "main_window", nil, {6, 7, 7, 4})
self.window:SetPos(nil, nil, 500, 700)

self.lobby = lobby or self.lobby
self.validAiNames = {}

-- Disable game-specific AIs for now since it breaks /luaui reload
Expand All @@ -13,11 +16,11 @@ function AiListWindow:init(gameName)
local blackList = Configuration.gameConfig.aiBlacklist
local oldAiVersions = (not Configuration.showOldAiVersions) and Configuration.gameConfig.oldAiVersions
local isRunning64Bit = Configuration:GetIsRunning64Bit()
local isSingleplayer = lobby.name == "singleplayer"

for i, ai in pairs(ais) do
self:AddAiToList(ai, blackList, oldAiVersions, isRunning64Bit)
self:AddAiToList(ai, blackList, oldAiVersions, isRunning64Bit, isSingleplayer)
end

end

function AiListWindow:CompareItems(id1, id2)
Expand All @@ -30,7 +33,7 @@ function AiListWindow:CompareItems(id1, id2)
return true
end

function AiListWindow:AddAiToList(ai, blackList, oldAiVersions, isRunning64Bit)
function AiListWindow:AddAiToList(ai, blackList, oldAiVersions, isRunning64Bit, isSingleplayer)
local shortName = ai.shortName or "Unknown"

if blackList and blackList[shortName] then
Expand Down Expand Up @@ -70,42 +73,65 @@ function AiListWindow:AddAiToList(ai, blackList, oldAiVersions, isRunning64Bit)
if Configuration.gameConfig.aiTooltip then
tooltip = Configuration.gameConfig.aiTooltip[displayName]
end
local addAIButton = Button:New {
x = 0,

local buttonList = {}
local btnWidth = "100%"
if Configuration.showAiOptions and isSingleplayer then
local path = "AI/Skirmish/" .. shortName .. "/" .. ai.version .. "/AIOptions.lua"
if VFS.FileExists(path) then
buttonList[#buttonList + 1] = self:MakeAiOptionsButton(displayName, tooltip, shortName, ai.version, path)
btnWidth = "80%"
end
end
buttonList[#buttonList + 1] = self:MakeAiButton(btnWidth, displayName, tooltip, shortName, ai.version)
self:AddRow(buttonList, displayName)
end

function AiListWindow:MakeAiOptionsButton(displayName, tooltip, shortName, version, path)
local optionsButton = Button:New {
x = "80%",
y = 0,
width = "100%",
width = "20%",
height = "100%",
caption = displayName,
caption = "",
font = Configuration:GetFont(3),
tooltip = tooltip,
OnClick = {
function()
local function defaultAction()
self:AddAi(displayName, shortName, ai.version)
self:HideWindow()
end

local skirmishDefault = WG.Chobby.Configuration.gameConfig.skirmishDefault
if not skirmishDefault or not skirmishDefault.AIOptionsEnabled then
defaultAction()
return
end

local path = "AI/Skirmish/" .. ai.shortName .. "/" .. ai.version .. "/AIOptions.lua"
if not VFS.FileExists(path) then
defaultAction()
return
end

local successFunc = function(aioptions)
self:AddAi(displayName, shortName, ai.version, aioptions)
self:AddAi(displayName, shortName, version, aioptions)
self:HideWindow()
end
WG.Chobby.AiOptionsWindow(displayName, path, successFunc)
end
},
}
self:AddRow({addAIButton}, displayName)
local optionsImage = Image:New {
x = "10%",
y = "10%",
width = "80%",
height = "80%",
file = IMG_SETTINGS,
parent = optionsButton,
}
return optionsButton
end

function AiListWindow:MakeAiButton(btnWidth, displayName, tooltip, shortName, version)
return Button:New {
x = 0,
y = 0,
width = btnWidth,
height = "100%",
caption = displayName,
font = Configuration:GetFont(3),
tooltip = tooltip,
OnClick = {
function()
self:AddAi(displayName, shortName, version)
self:HideWindow()
end
},
}
end

function AiListWindow:AddAi(displayName, shortName, version, options)
Expand Down Expand Up @@ -138,7 +164,6 @@ function AiListWindow:QuickAdd(shortName)
end
end

function AiListWindow:SetLobbyAndAllyTeam(lobby, allyTeam)
self.lobby = lobby or self.lobby
function AiListWindow:SetAllyTeam(allyTeam)
self.allyTeam = allyTeam or self.allyTeam
end
2 changes: 2 additions & 0 deletions LuaMenu/widgets/chobby/components/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function Configuration:init()
self.hideInterface = false
self.enableTextToSpeech = true
self.showOldAiVersions = false
self.showAiOptions = false
self.drawAtFullSpeed = false
self.lobbyIdleSleep = false
self.rememberQueuesOnStart = false
Expand Down Expand Up @@ -546,6 +547,7 @@ function Configuration:GetConfigData()
matchmakerPopupTime = self.matchmakerPopupTime,
enableTextToSpeech = self.enableTextToSpeech,
showOldAiVersions = self.showOldAiVersions,
showAiOptions = self.showAiOptions,
chatFontSize = self.chatFontSize,
myAccountID = self.myAccountID,
lastAddedAiName = self.lastAddedAiName,
Expand Down
22 changes: 15 additions & 7 deletions LuaMenu/widgets/gui_popup_preloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ function widget:GetInfo()
}
end

local oldLobby
local oldGameName
local aiListWindow
local aiPopup

local showOldAiVersions = false
local showAiOptions = false
local simpleAiList = true

--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- AI List window updating

local function UpdateAiListWindow(gameName)
local function UpdateAiListWindow(battleLobby, gameName)
if aiPopup then
aiPopup:ClosePopup()
end
aiListWindow = WG.Chobby.AiListWindow(gameName)
aiListWindow = WG.Chobby.AiListWindow(battleLobby, gameName)
aiListWindow.window:Hide()
end

Expand All @@ -45,8 +47,9 @@ local function InitializeListeners(battleLobby)
return
end

oldLobby = battleLobby
oldGameName = newGameName
UpdateAiListWindow(newGameName)
UpdateAiListWindow(battleLobby, newGameName)
end

local function OnJoinedBattle(listener, joinedBattleId, userName)
Expand All @@ -58,8 +61,9 @@ local function InitializeListeners(battleLobby)
return
end

oldLobby = battleLobby
oldGameName = newGameName
UpdateAiListWindow(newGameName)
UpdateAiListWindow(battleLobby, newGameName)
end

battleLobby:AddListener("OnUpdateBattleInfo", OnUpdateBattleInfo)
Expand All @@ -74,14 +78,18 @@ local PopupPreloader = {}

function PopupPreloader.ShowAiListWindow(battleLobby, newGameName, teamIndex, quickAddAi)
local conf = WG.Chobby.Configuration
if newGameName ~= oldGameName or conf.showOldAiVersions ~= showOldAiVersions or conf.simpleAiList ~= simpleAiList then
if newGameName ~= oldGameName or conf.simpleAiList ~= simpleAiList or oldLobby ~= battleLobby
or conf.showOldAiVersions ~= showOldAiVersions or conf.showAiOptions ~= showAiOptions
then
oldLobby = battleLobby
oldGameName = newGameName
showOldAiVersions = conf.showOldAiVersions
showAiOptions = conf.showAiOptions
simpleAiList = conf.simpleAiList
UpdateAiListWindow(newGameName)
UpdateAiListWindow(battleLobby, newGameName)
end

aiListWindow:SetLobbyAndAllyTeam(battleLobby, teamIndex)
aiListWindow:SetAllyTeam(teamIndex)
if quickAddAi and aiListWindow:QuickAdd(quickAddAi) then
return
end
Expand Down
1 change: 1 addition & 0 deletions LuaMenu/widgets/gui_settings_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ 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", false)

children[#children + 1] = Label:New {
x = 20,
Expand Down