Skip to content

Commit 21be1a8

Browse files
authored
Merge pull request #33 from bszonye/feb-2018
Rise & Fall compatibility
2 parents d296f2d + 936b63a commit 21be1a8

5 files changed

+67
-55
lines changed

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Map Tacks 0.9.1 [<img align="right" src="maptacks.png" height="256" width="256">](https://steamcommunity.com/sharedfiles/filedetails/?id=1122081356)
1+
# Map Tacks 0.9.2 [<img align="right" src="maptacks.png" height="256" width="256">](https://steamcommunity.com/sharedfiles/filedetails/?id=1122081356)
22
Enhances map pin list
33
Adds new icon options
44
Fixes base-game bugs
@@ -17,13 +17,12 @@ for all builder and engineer actions, great people, and several common unit
1717
operations, plus a golden hexagon to mark wonder sites.
1818

1919
## Bug fixes and restyling
20-
The mod fixes a few base-game bugs and styling problems: Deleting and re-adding
21-
a pin no longer scrambles the pins. The pin list cannot grow past the top of
22-
the screen. Unnamed pins sort correctly when there are more than ten. Labels
23-
and controls have more consistent alignment and spacing.
20+
The mod fixes a few base-game bugs and styling problems: The pin list cannot
21+
grow past the top of the screen. Unnamed pins sort correctly when there are
22+
more than ten. Labels and controls have more consistent alignment and spacing.
2423

2524
## Compatibility
2625
The Map Tacks mod does not affect saved games. You can add it to a game in
2726
progress or disable it without breaking your game. Enabling or disabling the
2827
mod will not remove any pins that are already on your map, but some may change
29-
color. This mod layers on top of NQ/CQUI, replacing their map pin features.
28+
color. This mod layers on top of CQUI, replacing its map pin features.

mappinpopup.lua

+51-32
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ include( "MapTacks" );
1414
local COLOR_YELLOW :number = 0xFF2DFFF8;
1515
local COLOR_WHITE :number = 0xFFFFFFFF;
1616

17-
local g_editMapPinID :number = nil;
17+
local NO_EDIT_PIN_ID :number = -1;
18+
local g_editPinID :number = NO_EDIT_PIN_ID;
1819
local g_uniqueIconsPlayer :number = nil; -- tailor UAs to the player
1920
local g_iconOptionEntries = {};
2021
local g_visibilityTargetEntries = {};
@@ -133,6 +134,8 @@ end
133134

134135
-- ===========================================================================
135136
function PopulateIconOptions()
137+
-- unique icons are specific to the current player
138+
g_uniqueIconsPlayer = Game.GetLocalPlayer();
136139
-- build icon table with default pins + extensions
137140
g_iconPulldownOptions = MapTacksIconOptions(g_stockIcons);
138141

@@ -191,14 +194,6 @@ function UpdateIconOptionColor(iconEntryIndex :number)
191194
end
192195
end
193196

194-
-- ===========================================================================
195-
function GetMapPinID(id :number)
196-
if id == nil then return nil; end
197-
local activePlayerID = Game.GetLocalPlayer();
198-
local pPlayerCfg = PlayerConfigurations[activePlayerID];
199-
return pPlayerCfg:GetMapPinID(id);
200-
end
201-
202197
-- ===========================================================================
203198
function RequestMapPin(hexX :number, hexY :number)
204199
local activePlayerID = Game.GetLocalPlayer();
@@ -207,17 +202,14 @@ function RequestMapPin(hexX :number, hexY :number)
207202
local pPlayerCfg = PlayerConfigurations[activePlayerID];
208203
local pMapPin = pPlayerCfg:GetMapPin(hexX, hexY);
209204
if(pMapPin ~= nil) then
210-
g_editMapPinID = pMapPin:GetID()
211-
205+
g_editPinID = pMapPin:GetID();
212206
g_desiredIconName = pMapPin:GetIconName();
213207
if GameConfiguration.IsAnyMultiplayer() then
214208
MapPinVisibilityToPlayerTarget(pMapPin:GetVisibility(), g_playerTarget);
215209
UpdatePlayerTargetPulldown(Controls.VisibilityPull, g_playerTarget);
216210
Controls.VisibilityContainer:SetHide(false);
217211
else
218212
Controls.VisibilityContainer:SetHide(true);
219-
-- XXX debug
220-
-- Controls.VisibilityContainer:SetHide(false);
221213
end
222214

223215
Controls.PinName:SetText(pMapPin:GetName());
@@ -244,6 +236,20 @@ function RequestMapPin(hexX :number, hexY :number)
244236
end
245237
end
246238

239+
-- ===========================================================================
240+
-- Returns the map pin configuration for the pin we are currently editing.
241+
-- Do not cache the map pin configuration because it will get destroyed by other processes. Use it and get out!
242+
function GetEditPinConfig()
243+
if(g_editPinID ~= NO_EDIT_PIN_ID) then
244+
local activePlayerID = Game.GetLocalPlayer();
245+
local pPlayerCfg = PlayerConfigurations[activePlayerID];
246+
local pMapPin = pPlayerCfg:GetMapPinID(g_editPinID);
247+
return pMapPin;
248+
end
249+
250+
return nil;
251+
end
252+
247253
-- ===========================================================================
248254
function OnChatPanel_PlayerTargetChanged(playerTargetTable)
249255
g_cachedChatPanelTarget = playerTargetTable;
@@ -254,16 +260,19 @@ end
254260

255261
-- ===========================================================================
256262
function ShowHideSendToChatButton()
257-
local pMapPin = GetMapPinID(g_editMapPinID);
258-
local showSendButton = pMapPin ~= nil and not pMapPin:IsPrivate() and GameConfiguration.IsNetworkMultiplayer();
259-
-- XXX debug
260-
-- showSendButton = true;
263+
local editPin = GetEditPinConfig();
264+
if(editPin == nil) then
265+
return;
266+
end
267+
268+
local privatePin = editPin:IsPrivate();
269+
local showSendButton = GameConfiguration.IsNetworkMultiplayer() and not privatePin;
261270

262271
Controls.SendToChatButton:SetHide(not showSendButton);
263272

264273
-- Send To Chat disables itself if the current chat panel target is not visible to the map pin.
265274
if(showSendButton) then
266-
local chatVisible = MapPinIsVisibleToChatTarget(pMapPin:GetVisibility(), g_cachedChatPanelTarget);
275+
local chatVisible = MapPinIsVisibleToChatTarget(editPin:GetVisibility(), g_cachedChatPanelTarget);
267276
Controls.SendToChatButton:SetDisabled(not chatVisible);
268277
if(chatVisible) then
269278
Controls.SendToChatButton:SetToolTipString(sendToChatTTStr);
@@ -286,13 +295,13 @@ end
286295
-- ===========================================================================
287296
function OnOk()
288297
if( not ContextPtr:IsHidden() ) then
289-
local pMapPin = GetMapPinID(g_editMapPinID);
290-
if(pMapPin ~= nil) then
291-
pMapPin:SetName(Controls.PinName:GetText());
292-
pMapPin:SetIconName(g_desiredIconName);
298+
local editPin = GetEditPinConfig();
299+
if(editPin ~= nil) then
300+
editPin:SetName(Controls.PinName:GetText());
301+
editPin:SetIconName(g_desiredIconName);
293302

294303
local newMapPinVisibility = PlayerTargetToMapPinVisibility(g_playerTarget);
295-
pMapPin:SetVisibility(newMapPinVisibility);
304+
editPin:SetVisibility(newMapPinVisibility);
296305

297306
Network.BroadcastPlayerInfo();
298307
UI.PlaySound("Map_Pin_Add");
@@ -305,19 +314,23 @@ end
305314

306315
-- ===========================================================================
307316
function OnSendToChatButton()
308-
local pMapPin = GetMapPinID(g_editMapPinID);
309-
if(pMapPin ~= nil) then
310-
pMapPin:SetName(Controls.PinName:GetText());
311-
LuaEvents.MapPinPopup_SendPinToChat(pMapPin:GetPlayerID(), pMapPin:GetID());
317+
local editPinCfg = GetEditPinConfig();
318+
if(editPinCfg ~= nil) then
319+
editPinCfg:SetName(Controls.PinName:GetText());
320+
LuaEvents.MapPinPopup_SendPinToChat(editPinCfg:GetPlayerID(), editPinCfg:GetID());
312321
end
313322
end
314323

315324
-- ===========================================================================
316325
function OnDelete()
317-
if(g_editMapPinID ~= nil) then
326+
local editPinCfg = GetEditPinConfig();
327+
if(editPinCfg ~= nil) then
318328
local activePlayerID = Game.GetLocalPlayer();
319329
local pPlayerCfg = PlayerConfigurations[activePlayerID];
320-
pPlayerCfg:DeleteMapPin(g_editMapPinID);
330+
local deletePinID = editPinCfg:GetID();
331+
332+
g_editPinID = NO_EDIT_PIN_ID;
333+
pPlayerCfg:DeleteMapPin(deletePinID);
321334
Network.BroadcastPlayerInfo();
322335
UI.PlaySound("Map_Pin_Remove");
323336
end
@@ -331,12 +344,12 @@ end
331344
-- Event Handlers
332345
----------------------------------------------------------------
333346
function OnMapPinPlayerInfoChanged( playerID :number )
334-
PlayerTarget_OnPlayerInfoChanged( playerID, Controls.VisibilityPull, nil, g_visibilityTargetEntries, g_playerTarget, true);
347+
PlayerTarget_OnPlayerInfoChanged( playerID, Controls.VisibilityPull, nil, nil, g_visibilityTargetEntries, g_playerTarget, true);
335348
end
336349

337350
function OnLocalPlayerChanged()
338351
g_playerTarget.targetID = Game.GetLocalPlayer();
339-
PopulateTargetPull(Controls.VisibilityPull, nil, g_visibilityTargetEntries, g_playerTarget, true, OnVisibilityPull);
352+
PopulateTargetPull(Controls.VisibilityPull, nil, nil, g_visibilityTargetEntries, g_playerTarget, true, OnVisibilityPull);
340353

341354
if( not ContextPtr:IsHidden() ) then
342355
UIManager:DequeuePopup( ContextPtr );
@@ -365,7 +378,7 @@ function Initialize()
365378
ContextPtr:SetInputHandler( OnInputHandler, true );
366379

367380
PopulateIconOptions();
368-
PopulateTargetPull(Controls.VisibilityPull, nil, g_visibilityTargetEntries, g_playerTarget, true, OnVisibilityPull);
381+
PopulateTargetPull(Controls.VisibilityPull, nil, nil, g_visibilityTargetEntries, g_playerTarget, true, OnVisibilityPull);
369382
Controls.DeleteButton:RegisterCallback(Mouse.eLClick, OnDelete);
370383
Controls.DeleteButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
371384
Controls.SendToChatButton:RegisterCallback(Mouse.eLClick, OnSendToChatButton);
@@ -385,6 +398,12 @@ function Initialize()
385398
-- We have to do this because the map pin's context is loaded after the chat panel's
386399
-- and the chat panel's show/hide handler is not triggered as expected.
387400
LuaEvents.MapPinPopup_RequestChatPlayerTarget();
401+
402+
local canChangeName = GameCapabilities.HasCapability("CAPABILITY_RENAME");
403+
if(not canChangeName) then
404+
Controls.PinFrame:SetHide(true);
405+
end
406+
388407
end
389408
Initialize();
390409

mappinpopup.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
<SlideAnim ID="PopupSlideIn" Start="0,-20" End="0,0" Speed="3" Function="Root" Cycle="Once" Size="parent,parent">
99

1010
<Grid ID="WindowContainer" Size="auto,auto" Anchor="C,C" Offset="0,0" Style="DropShadow2" Color="255,255,255,200" AutoSizePadding="25,25" ConsumeMouse="1">
11-
<Grid ID="Window" Size="650,auto" Anchor="C,C" Offset="0,0" Style="WindowFrameTitle" AutoSizePadding="0,12">
11+
<Grid ID="Window" Size="690,auto" Anchor="C,C" Offset="0,0" Style="WindowFrameTitle" AutoSizePadding="0,12">
1212
<Stack ID="WindowStack" StackGrowth="Down" Padding="10" Anchor="C,T">
1313
<Container Size="330,42" Anchor="C,T">
1414
<Label ID="TitleText" Style="WindowHeader" Anchor="C,C" String="{LOC_MAP_PIN_POPUP_TITLE:upper}" />
1515
</Container>
1616
<Container Size="auto,auto" Anchor="C,T">
1717
<Stack ID="WindowContentsStack" Anchor="L,T" StackGrowth="Bottom" Padding="12">
1818
<!-- Name -->
19-
<Grid Style="EditTextButton" Anchor="C,T" Size="310,26">
19+
<Grid ID="PinFrame" Style="EditTextButton" Anchor="C,T" Size="310,26">
2020
<EditBox ID="PinName" Style="EditTextArea" Size="parent-34,22" Anchor="R,C" Offset="4,0" MaxLength="20" EditMode="0" KeepFocus="1"/>
2121
</Grid>
2222
<!-- Icons -->
23-
<Stack ID="IconOptionStack" Anchor="C,T" StackGrowth="Right" Padding="4" WrapWidth="616" WrapGrowth="Down"/>
23+
<Stack ID="IconOptionStack" Anchor="C,T" StackGrowth="Right" Padding="4" WrapWidth="660" WrapGrowth="Down"/>
2424
<!-- Visible to.. -->
2525
<Container ID="VisibilityContainer" Anchor="C,T" Size="1,26" Hidden="1">
2626
<PullDown ID="VisibilityPull" Anchor="C,T" Size="150,26" Style="WBPullDown"/>

maptacks.lua

+7-13
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,19 @@ local g_miscOps = {
6060
GameInfo.UnitOperations.UNITOPERATION_DESIGNATE_PARK,
6161
GameInfo.UnitOperations.UNITOPERATION_EXCAVATE,
6262
GameInfo.UnitOperations.UNITOPERATION_MAKE_TRADE_ROUTE,
63-
GameInfo.Units.UNIT_SPY,
64-
GameInfo.UnitCommands.UNITCOMMAND_ACTIVATE_GREAT_PERSON,
65-
};
66-
local g_attackOps = {
67-
GameInfo.UnitCommands.UNITCOMMAND_FORM_ARMY,
68-
-- GameInfo.UnitOperations.UNITOPERATION_AIR_ATTACK,
6963
GameInfo.UnitOperations.UNITOPERATION_WMD_STRIKE,
7064
GameInfo.UnitOperations.UNITOPERATION_PILLAGE,
7165
GameInfo.UnitCommands.UNITCOMMAND_PLUNDER_TRADE_ROUTE,
66+
GameInfo.UnitCommands.UNITCOMMAND_FORM_ARMY,
67+
GameInfo.Units.UNIT_SPY,
68+
GameInfo.UnitCommands.UNITCOMMAND_ACTIVATE_GREAT_PERSON,
7269
};
7370

7471
-- ===========================================================================
7572
-- Build the grid of map pin icon options
7673
function MapTacksIconOptions(stockIcons : table)
7774
local icons = {};
7875
local activePlayerID = Game.GetLocalPlayer();
79-
g_uniqueIconsPlayer = activePlayerID;
8076
local pPlayerCfg = PlayerConfigurations[activePlayerID];
8177

8278
local leader = GameInfo.Leaders[pPlayerCfg:GetLeaderTypeID()];
@@ -112,14 +108,15 @@ function MapTacksIconOptions(stockIcons : table)
112108
end
113109

114110
-- Districts
111+
table.insert(icons, MapTacksIcon(GameInfo.Districts.DISTRICT_WONDER, "DistrictType"));
115112
for item in GameInfo.Districts() do
116113
local itype = item.DistrictType;
117114
if districts[itype] then
118115
-- unique district replacements for this civ
119116
table.insert(icons, MapTacksIcon(districts[itype], "DistrictType"));
120117
elseif item.TraitType then
121118
-- skip other unique districts
122-
else
119+
elseif itype ~= "DISTRICT_WONDER" then
123120
table.insert(icons, MapTacksIcon(item, "DistrictType"));
124121
end
125122
end
@@ -153,13 +150,13 @@ function MapTacksIconOptions(stockIcons : table)
153150
end
154151
end
155152

156-
for i,v in ipairs(builderIcons) do table.insert(icons, v); end
157-
for i,v in ipairs(g_buildOps) do table.insert(icons, MapTacksIcon(v)); end
158153
if #uniqueIcons==0 then
159154
table.insert(icons, MapTacksIcon(
160155
GameInfo.UnitOperations.UNITOPERATION_BUILD_IMPROVEMENT))
161156
end
162157
for i,v in ipairs(uniqueIcons) do table.insert(icons, v); end
158+
for i,v in ipairs(builderIcons) do table.insert(icons, v); end
159+
for i,v in ipairs(g_buildOps) do table.insert(icons, MapTacksIcon(v)); end
163160
for i,v in ipairs(minorCivIcons) do table.insert(icons, v); end
164161
for i,v in ipairs(g_repairOps) do table.insert(icons, MapTacksIcon(v)); end
165162
for i,v in ipairs(miscIcons) do table.insert(icons, v); end
@@ -170,9 +167,6 @@ function MapTacksIconOptions(stockIcons : table)
170167
table.insert(icons, MapTacksIcon(item));
171168
end
172169

173-
-- Unit actions
174-
for i,v in ipairs(g_attackOps) do table.insert(icons, MapTacksIcon(v)); end
175-
176170
return icons;
177171
end
178172

maptacks.modinfo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Mod id="0a1c826c-0f43-4876-b096-23e1292eee3c" version="0.9.1">
2+
<Mod id="0a1c826c-0f43-4876-b096-23e1292eee3c" version="0.9.2">
33
<Properties>
44
<Name>Map Tacks</Name>
55
<Description>Map pin improvements</Description>

0 commit comments

Comments
 (0)