Map Pins & Labels

Seileach

Chieftain
Joined
Feb 1, 2002
Messages
79
hi :)

i was tweaking a bit with WHoward's Map Pin mod. i wanted to alter it so it would display map labels.

i did some minor changes to MapPins.lua

first i created a new string array to handle text color (line 25 aprox)
Spoiler :

local g_TextColor = {
{color="[COLOR_XP_BLUE]"}, {color="[COLOR_CITY_BROWN]"}, {color="[COLOR_BROWN_TEXT]"}, {color="[COLOR_CITY_GREEN]"}, {color="[COLOR_FONT_RED]"},
}

and replaced this (line 440 aprox)
Spoiler :

pin.instance.Text:SetText(GetFlag(iType))

with this
Spoiler :

if (iType >= 6) then
labelText = Locale.ConvertTextKey(g_TextColor[iType-5].color) .. sText .. "[ENDCOLOR]"
pin.instance.Text:SetText(labelText)
else
pin.instance.Text:SetText(GetFlag(iType))
end

so that the first 5 icons behave as icons and the last 5 as labels, each with a different color.


i also changed MapPins.xml to change the label text style (line 7)
Spoiler :

<Instance Name="Pin">
<WorldAnchor ID="Anchor">
<Button ID="Text" Size="24,24" Anchor="C,C" String="[ICON_TEAM_3]" Font="TwCenMT24" FontStyle="Stroke" ToolTip=""/>
</WorldAnchor>
</Instance>



i changed FlagIcons.xml too to reflect the changes i had done in the other two files, but it's not relevant to the issue troubling me
Spoiler :

<GameData>
<Language_en_US>
<Row Tag="TXT_KEY_MAPPINS_FLAG_UNKNOWN">
<Text>[ICON_CAPITAL]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_1">
<Text>[ICON_CITY_STATE]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_2">
<Text>[ICON_RAZING]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_3">
<Text>[ICON_WAR]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_4">
<Text>[ICON_CAPITAL]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_5">
<Text>[ICON_GOLDEN_AGE]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_6">
<Text>[COLOR_XP_BLUE]@[ENDCOLOR]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_7">
<Text>[COLOR_CITY_BROWN]@[ENDCOLOR]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_8">
<Text>[COLOR_BROWN_TEXT]@[ENDCOLOR]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_9">
<Text>[COLOR_CITY_GREEN]@[ENDCOLOR]</Text>
</Row>
<Row Tag="TXT_KEY_MAPPINS_FLAG_10">
<Text>[COLOR_FONT_RED]@[ENDCOLOR]</Text>
</Row>
</Language_en_US>
</GameData>



the result was this
Spoiler :



and this
Spoiler :




not bad, right?


thing is, the labels overlap the top bar, the minimaps, the menus, you name it
Spoiler :



it kinda breaks it for me...

any hints on how i could fix this? or if it can be fixed?

my programming skills are limited, i think i've gone as far as i can go on my own.

cheers!
 
You need to change the parent of the layer that the labes/icons are placed on
 
Hazel16 made some work on a similar project before, you might want to take a look at her thread.
 
Hazel16 made some work on a similar project before, you might want to take a look at her thread.

i have, i tried it, it looks gorgeous, but the savegames didn't save the labels consistently, no idea why.

furthermore, Map Labels was much more ambitious, with dynamic labels and all, which makes the code harder to understand.
 
You need to change the parent of the layer that the labes/icons are placed on

i'm having no luck trying to change the parent of the layer...

should i do it in MapPins.lua? maybe using ChangeParent in Controls.PinView or Controls.PinContainer? and what about the syntax?

should i do it in MapPins.xml instead? maybe adding an attribute to <Container ID="PinContainer" Hidden="1"/>? which attribute?

and what about the layer's name? should i make "WorldView" the parent?

i'm really grasping at straws here, searching the web didn't come up with any useful examples this time...

would the tutorial on User Interface Components be helpful? i only browsed it last night, so i couldn't really tell if i would find a solution there for this particular issue.

cheers!
 
ContextPtr:ChangeParent(LookUpControl("/InGame/ResourceIconManager"))

See http://forums.civfanatics.com/showthread.php?p=14171398

still not getting it, sorry :(

where do i insert this line of code? in Init()? and before or after any particular line of code?

and do i insert it as is?

Spoiler :
function Init()
DbmOpen(modDbCreate)

-- Register all the edit popup radio-buttons
local stack = Controls.EditPinFlagsStack1
for i=1, #g_FlagTypes, 1 do
local instance = {}
ContextPtr:BuildInstanceForControl("Flag", instance, stack)
g_FlagTypes.instance = instance

instance.EditPinType:SetVoid1(i)
instance.EditPinType:RegisterCallback(Mouse.eLClick, OnEditPinTypeChanged)

instance.EditPinType:GetTextButton():SetText(GetFlag(i))

if (i == math.ceil(#g_FlagTypes/2)) then
stack = Controls.EditPinFlagsStack2
end
end

-- Adjust the stacks to fit now they have content
Controls.EditPinFlagsStack1:CalculateSize()
Controls.EditPinFlagsStack1:ReprocessAnchoring()
Controls.EditPinFlagsStack2:CalculateSize()
Controls.EditPinFlagsStack2:ReprocessAnchoring()

-- Register the WorldView Lua events
LuaEvents.MapPins_Show.Add(Show)
LuaEvents.MapPins_Toggle.Add(Toggle)
LuaEvents.MapPins_SendVisibility.Add(SendVisibility)

-- Register the API Lua events (some used by InfoCorner MapPinsList)
LuaEvents.MapPins_Get.Add(GetPins)
LuaEvents.MapPins_Add.Add(AddPinViaLuaEvent)
LuaEvents.MapPins_Edit.Add(EditPin)
LuaEvents.MapPins_PopupEdit.Add(ShowEditPinPopup)
LuaEvents.MapPins_Move.Add(MovePin)
LuaEvents.MapPins_Delete.Add(DeletePin)
LuaEvents.MapPins_PopupDelete.Add(ShowConfirmDeletePinPopup)

-- Hide the pinboard and load any saved pins
Hide()
Controls.PinContainer:SetHide(not IsToggle(string.format(g_OptionFlagsVisible, 0)))
ContextPtr:ChangeParent(LookUpControl("/InGame/ResourceIconManager"))
end


or referring to PinContainer? (this syntax appears to be used in other mods)

Spoiler :
function Init()
DbmOpen(modDbCreate)

-- Register all the edit popup radio-buttons
local stack = Controls.EditPinFlagsStack1
for i=1, #g_FlagTypes, 1 do
local instance = {}
ContextPtr:BuildInstanceForControl("Flag", instance, stack)
g_FlagTypes.instance = instance

instance.EditPinType:SetVoid1(i)
instance.EditPinType:RegisterCallback(Mouse.eLClick, OnEditPinTypeChanged)

instance.EditPinType:GetTextButton():SetText(GetFlag(i))

if (i == math.ceil(#g_FlagTypes/2)) then
stack = Controls.EditPinFlagsStack2
end
end

-- Adjust the stacks to fit now they have content
Controls.EditPinFlagsStack1:CalculateSize()
Controls.EditPinFlagsStack1:ReprocessAnchoring()
Controls.EditPinFlagsStack2:CalculateSize()
Controls.EditPinFlagsStack2:ReprocessAnchoring()

-- Register the WorldView Lua events
LuaEvents.MapPins_Show.Add(Show)
LuaEvents.MapPins_Toggle.Add(Toggle)
LuaEvents.MapPins_SendVisibility.Add(SendVisibility)

-- Register the API Lua events (some used by InfoCorner MapPinsList)
LuaEvents.MapPins_Get.Add(GetPins)
LuaEvents.MapPins_Add.Add(AddPinViaLuaEvent)
LuaEvents.MapPins_Edit.Add(EditPin)
LuaEvents.MapPins_PopupEdit.Add(ShowEditPinPopup)
LuaEvents.MapPins_Move.Add(MovePin)
LuaEvents.MapPins_Delete.Add(DeletePin)
LuaEvents.MapPins_PopupDelete.Add(ShowConfirmDeletePinPopup)

-- Hide the pinboard and load any saved pins
Hide()
Controls.PinContainer:SetHide(not IsToggle(string.format(g_OptionFlagsVisible, 0)))
Controls.PinContainer:ChangeParent(ContextPtr:LookUpControl("/InGame/ResourceIconManager"))
end


sorry for the constant and probably dumb questions, and thanks for the all the help so far.
 
If you post the modded mod, I'll see where it needs putting.

I just stuck that line in FireTuner in my own mod and it worked, but there are issues with LookupControl that means it can't be used until the game is fully initialised (which happens after Init() runs) so you need to adopt a just-in-time approach
 
If you post the modded mod, I'll see where it needs putting.

I just stuck that line in FireTuner in my own mod and it worked, but there are issues with LookupControl that means it can't be used until the game is fully initialised (which happens after Init() runs) so you need to adopt a just-in-time approach

i understand

here's the mod, hope this works :) beware, Init() is peppered with my failed attempts at making this change :p

thanks so much for taking the time to help me :)
 
To maintain compatibility with UI - Auto Map Pins

Code:
		if (iType >= 6) then
			labelText = Locale.ConvertTextKey(g_TextColor[iType-5].color) .. sText .. "[ENDCOLOR]"
			pin.instance.Text:[B][COLOR="Red"]LocalizeAndSetText[/COLOR][/B](labelText) -- Jorge
		else
			pin.instance.Text:SetText(GetFlag(iType)) -- WHoward
		end

To pass under the minimap etc
Code:
Init()

[B][COLOR="red"]function ChangeParent()
  local rim = LookUpControl("/InGame/ResourceIconManager")
  if (rim) then
    ContextPtr:ChangeParent(rim)
    GameEvents.PlayerDoTurn.Remove(ChangeParent)
  end
end
GameEvents.PlayerDoTurn.Add(ChangeParent)
[/COLOR][/B]
 
tweaked it a little bit more.

city banners and unit flags were overlapping the EditPin box, so i added this at the beginning of EditPin

Spoiler :
local rim = LookUpControl("/InGame/WorldView/WorldView")
if (rim) then
ContextPtr:ChangeParent(rim)
end


and this in OnEditOk

Spoiler :
local rim = LookUpControl("/InGame/ResourceIconManager")
if (rim) then
ContextPtr:ChangeParent(rim)
end


working so far :)
 
"rim" is shorthand for ResourceIconManager, so the three "rim"s in the first block should be "wv" (for WorldView) to keep it consistent
 
I've come up with a more robust way to do this

a) only change the parent of the PinContainer - that way only the pins pass behind the minimap, city banners, info corner items, etc - so you don't have to mess around with changing back to the WorldView when the popup box is open

b) hook Events.GameplaySetActivePlayer, as that works for reloads as well as initial game start

Code:
function OnChangeParent()
  local rim = LookUpControl("/InGame/ResourceIconManager")
  if (rim) then
    print("Changing PinContainer's parent to ResourceIconManager")
    Controls.PinContainer:ChangeParent(rim)
    Events.GameplaySetActivePlayer.Remove(OnChangeParent);
  end
end
Events.GameplaySetActivePlayer.Add(OnChangeParent);
 
Hey! Is that modified mod still working? And if so can you post a version please?
 
Top Bottom