Trying to disable unit icons

DeclanTKatt

Chieftain
Joined
May 29, 2011
Messages
19
Location
Chicago, IL
I am trying to create a simple mod in which a player can toggle the floating icons on/off. I found this interesting bit of code in the InGame.lua:

Spoiler :
function OnEnterCityScreen()

Controls.UnitFlagManager:SetHide( true );
Controls.CityBannerManager:SetHide( true );
.
.
.
end
Events.SerialEventEnterCityScreen.Add( OnEnterCityScreen );


This function hides unit icons (and city banners) upon entering a city. Likewise, there is another function similar to this which re-shows the icons upon exiting the city view:

Spoiler :
function OnExitCityScreen()

Controls.UnitFlagManager:SetHide( false );
Controls.CityBannerManager:SetHide( false );
.
.
.
end
Events.SerialEventExitCityScreen.Add( OnExitCityScreen );


So I created a new checkbox in the MiniMapPanel.xml called ID="HideUnitIcon". In the MiniMapPanel.lua, I then tried to put the UnitFlagManager:SetHide command into the handler for the new checkbox as so:

Spoiler :
function OnHideUnitIconChecked( bIsChecked )

Controls.UnitFlagManager:SetHide( bIsChecked );

end
Controls.HideUnitIcon:RegisterCheckHandler( OnHideUnitIconChecked );


The mod is ineffective. Sure, there is the check-box I created, but checking it has no effect on the visibility of the unit icons. The handler works just fine, though. To test, I copied the code from the 'show resource icons' handler into this handler, and when I loaded the mod, sure enough, the resource icons were toggled as I used this new checkbox.

So the only suspect part of this code is the Controls.UnitFlagManager:SetHide ( bIsChecked ); command. It works for the other functions in the InGame.lua, but not for this function in the MiniMapPanel.lua

Any discussion on why this isn't working, or better yet, how to get it to work would be very beneficial. Thanks.
 
Ingame.xml has <LuaContext FileName="Assets/UI/InGame/UnitFlagManager" ID="UnitFlagManager" />

So when it does Controls.UnitFlagManager:SetHide( true ); it's effectively hiding a different file.
 
Ok, so I put the

<LuaContext FileName="Assets/UI/InGame/UnitFlagManager" ID="UnitFlagManager" />

into my MiniMapPanel.xml file near the top and ran the mod again. Now instead of doing nothing, toggling my new checkbox now hides/shows the unit icon shadow but the icon itself still remains. Very strange.

Any further suggestions? Putting the LuaContext in there seemed to be a step in the right direction.
 
remove your addition to MiniMapPanel.xml and try ContextPtr:LookUpControl("/InGame/UnitFlagManager"):SetHide(bIsChecked ) in your code in MiniMapPanel.lua
 
WOW! Brought in the big guns for this one, eh? A moderator?

Well, that's why you get paid the big bucks, pal! Because your suggestion worked and the mod is now behaving as I intended it to.

Thank you, Gedemon (and Snarko) for your help. I see this bit of code coming in handy for other projects as well.

Much Appreciated :)
 
Back
Top Bottom