Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Color for Lenses (from CQUI) #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions Base/Assets/UI/Panels/modallenspanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,37 @@ function AddLensEntry(lensKey:string, lensEntry:table, refreshPanel)
end
end

-- ===========================================================================
function RefreshLensKey(lensKey:string)
ResetKeyStackIM();
ShowModLensKey(lensKey);
end

-- ===========================================================================
function ML_SettingsPanelClosed()
-- Get the active lens and refresh it, updating any color changes made
local activeModLens = {};
LuaEvents.MinimapPanel_GetActiveModLens(activeModLens);
if (activeModLens[1] ~= nil and activeModLens[1] ~= "NONE") then
if (UILens.IsLensActive("Appeal")) then
-- Lens is enabled via the Lenses list
RefreshLensKey(activeModLens[1]);
-- Turn off and Turn on the Appeal Lens to refresh the colors
UILens.SetActive("Default");
LuaEvents.MinimapPanel_SetActiveModLens(activeModLens[1]);
-- Appeal is used for all of the Modded Lenses
UILens.SetActive("Appeal");
elseif (UILens.IsLensActive("Default")) then
-- Lens is enabled because of a selected unit (e.g. Builder, Scout)
local hash = UILens.CreateLensLayerHash("Hex_Coloring_Appeal_Level")
UILens.ToggleLayerOff(hash);
UILens.ToggleLayerOn(hash);
else
print("!! ERROR: ActiveModLens is "..tostring(activeModLens[1]).." but UILens is not Appeal or Default!");
end
end
end

-- ===========================================================================
function LateInitialize()
if (Game.GetLocalPlayer() == -1) then
Expand All @@ -359,6 +390,8 @@ function LateInitialize()

-- Mod Lens Support
LuaEvents.ModalLensPanel_AddLensEntry.Add( AddLensEntry )
-- Support for updating Mod Lens Colors
LuaEvents.ML_SettingsPanelClosed.Add( ML_SettingsPanelClosed );

LuaEvents.MinimapPanel_AddContinentColorPair.Add(OnAddContinentColorPair);
end
Expand Down
37 changes: 28 additions & 9 deletions Lenses/Archaeologist/ModLens_Archaeologist.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
include("LensSupport")
local LENS_NAME = "ML_ARCHAEOLOGIST"
local ML_LENS_LAYER = UILens.CreateLensLayerHash("Hex_Coloring_Appeal_Level")

local m_LensSettings = {
["COLOR_ARCHAEOLOGIST_LENS_ARTIFACT"] = { ConfiguredColor = GetLensColorFromSettings("COLOR_ARCHAEOLOGIST_LENS_ARTIFACT"), KeyLabel = "LOC_HUD_ARCHAEOLOGIST_LENS_ARTIFACT" },
["COLOR_ARCHAEOLOGIST_LENS_SHIPWRECK"] = { ConfiguredColor = GetLensColorFromSettings("COLOR_ARCHAEOLOGIST_LENS_SHIPWRECK"), KeyLabel = "LOC_HUD_ARCHAEOLOGIST_LENS_SHIPWRECK" }
}

-- Should the archaeologist lens auto apply, when a archaeologist is selected.
local AUTO_APPLY_ARCHEOLOGIST_LENS:boolean = false
local AUTO_APPLY_ARCHAEOLOGIST_LENS:boolean = false

local function ML_OnSettingsInitialized()
-- NOTE: Setting to control auto-applying the Archaeologist lens is missing?
UpdateLensConfiguredColors(m_LensSettings, g_ModLensModalPanel, LENS_NAME);
end

local function ML_OnSettingsUpdate()
ML_OnSettingsInitialized();
end

-- ===========================================================================
-- Archaeologist Lens Support
Expand Down Expand Up @@ -34,8 +49,8 @@ local function OnGetColorPlotTable()
local pPlayer:table = Players[localPlayer]
local localPlayerVis:table = PlayersVisibility[localPlayer]

local AntiquityColor = UI.GetColorValue("COLOR_ARTIFACT_ARCH_LENS")
local ShipwreckColor = UI.GetColorValue("COLOR_SHIPWRECK_ARCH_LENS")
local AntiquityColor = m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_ARTIFACT"].ConfiguredColor
local ShipwreckColor = m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_SHIPWRECK"].ConfiguredColor
local IgnoreColor = UI.GetColorValue("COLOR_MORELENSES_GREY")
local colorPlot = {}
colorPlot[AntiquityColor] = {}
Expand Down Expand Up @@ -81,12 +96,12 @@ local function OnUnitSelectionChanged( playerID:number, unitID:number, hexI:numb
local unitType = GetUnitTypeFromIDs(playerID, unitID)
if unitType then
if bSelected then
if unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHEOLOGIST_LENS then
if unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHAEOLOGIST_LENS then
ShowArchaeologistLens()
end
-- Deselection
else
if unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHEOLOGIST_LENS then
if unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHAEOLOGIST_LENS then
ClearArchaeologistLens()
end
end
Expand All @@ -99,7 +114,7 @@ local function OnUnitRemovedFromMap( playerID: number, unitID : number )
local lens = {}
LuaEvents.MinimapPanel_GetActiveModLens(lens)
if playerID == localPlayer then
if lens[1] == LENS_NAME and AUTO_APPLY_ARCHEOLOGIST_LENS then
if lens[1] == LENS_NAME and AUTO_APPLY_ARCHAEOLOGIST_LENS then
ClearArchaeologistLens()
end
end
Expand All @@ -110,7 +125,7 @@ function OnUnitCaptured( currentUnitOwner, unit, owningPlayer, capturingPlayer )
local localPlayer = Game.GetLocalPlayer()
if owningPlayer == localPlayer then
local unitType = GetUnitTypeFromIDs(owningPlayer, unitID)
if unitType and unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHEOLOGIST_LENS then
if unitType and unitType == "UNIT_ARCHAEOLOGIST" and AUTO_APPLY_ARCHAEOLOGIST_LENS then
ClearArchaeologistLens()
end
end
Expand Down Expand Up @@ -139,7 +154,11 @@ if g_ModLensModalPanel ~= nil then
g_ModLensModalPanel[LENS_NAME] = {}
g_ModLensModalPanel[LENS_NAME].LensTextKey = "LOC_HUD_ARCHAEOLOGIST_LENS"
g_ModLensModalPanel[LENS_NAME].Legend = {
{"LOC_TOOLTIP_ARCHAEOLOGIST_LENS_ARTIFACT", UI.GetColorValue("COLOR_ARTIFACT_ARCH_LENS")},
{"LOC_TOOLTIP_ARCHAEOLOGIST_LENS_SHIPWRECK", UI.GetColorValue("COLOR_SHIPWRECK_ARCH_LENS")}
{m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_ARTIFACT"].KeyLabel, m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_ARTIFACT"].ConfiguredColor},
{m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_SHIPWRECK"].KeyLabel, m_LensSettings["COLOR_ARCHAEOLOGIST_LENS_SHIPWRECK"].ConfiguredColor}
}
end

-- Add ML LuaEvent Hooks for minimappanel and modallenspanel contexts
LuaEvents.ML_SettingsUpdate.Add(ML_OnSettingsUpdate);
LuaEvents.ML_SettingsInitialized.Add(ML_OnSettingsInitialized);
24 changes: 22 additions & 2 deletions Lenses/Barbarian/ModLens_Barbarian.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
include("LensSupport")
local LENS_NAME = "ML_BARBARIAN"
local ML_LENS_LAYER = UILens.CreateLensLayerHash("Hex_Coloring_Appeal_Level")

local m_LensSettings = {
["COLOR_BARBARIAN_LENS_ENCAMPMENT"] = { ConfiguredColor = GetLensColorFromSettings("COLOR_BARBARIAN_LENS_ENCAMPMENT"), KeyLabel = "LOC_HUD_BARBARIAN_LENS_ENCAMPMENT" }
}

-- ===========================================================================
-- Barbarian Lens Support
-- ===========================================================================
Expand All @@ -22,7 +27,7 @@ local function OnGetColorPlotTable()
local localPlayer :number = Game.GetLocalPlayer()
local localPlayerVis:table = PlayersVisibility[localPlayer]

local BarbarianColor = UI.GetColorValue("COLOR_BARBARIAN_BARB_LENS")
local BarbarianColor = m_LensSettings["COLOR_BARBARIAN_LENS_ENCAMPMENT"].ConfiguredColor
local IgnoreColor = UI.GetColorValue("COLOR_MORELENSES_GREY")
local colorPlot:table = {}
colorPlot[BarbarianColor] = {}
Expand Down Expand Up @@ -58,6 +63,7 @@ end
local function OnInitialize()
-- Nothing to do
end

]]

local BarbarianLensEntry = {
Expand All @@ -67,6 +73,16 @@ local BarbarianLensEntry = {
GetColorPlotTable = OnGetColorPlotTable
}

-- ===========================================================================
local function ML_OnSettingsInitialized()
UpdateLensConfiguredColors(m_LensSettings, g_ModLensModalPanel, LENS_NAME);
end

-- ===========================================================================
local function ML_OnSettingsUpdate()
ML_OnSettingsInitialized();
end

-- minimappanel.lua
if g_ModLenses ~= nil then
g_ModLenses[LENS_NAME] = BarbarianLensEntry
Expand All @@ -77,6 +93,10 @@ if g_ModLensModalPanel ~= nil then
g_ModLensModalPanel[LENS_NAME] = {}
g_ModLensModalPanel[LENS_NAME].LensTextKey = "LOC_HUD_BARBARIAN_LENS"
g_ModLensModalPanel[LENS_NAME].Legend = {
{"LOC_TOOLTIP_BARBARIAN_LENS_ENCAPMENT", UI.GetColorValue("COLOR_BARBARIAN_BARB_LENS")}
{m_LensSettings["COLOR_BARBARIAN_LENS_ENCAMPMENT"].KeyLabel, m_LensSettings["COLOR_BARBARIAN_LENS_ENCAMPMENT"].ConfiguredColor}
}
end

-- Add ML LuaEvent Hooks for minimappanel and modallenspanel contexts
LuaEvents.ML_SettingsUpdate.Add(ML_OnSettingsUpdate);
LuaEvents.ML_SettingsInitialized.Add(ML_OnSettingsInitialized);
Loading