@@ -14,7 +14,8 @@ include( "MapTacks" );
14
14
local COLOR_YELLOW :number = 0xFF2DFFF8 ;
15
15
local COLOR_WHITE :number = 0xFFFFFFFF ;
16
16
17
- local g_editMapPinID :number = nil ;
17
+ local NO_EDIT_PIN_ID :number = - 1 ;
18
+ local g_editPinID :number = NO_EDIT_PIN_ID ;
18
19
local g_uniqueIconsPlayer :number = nil ; -- tailor UAs to the player
19
20
local g_iconOptionEntries = {};
20
21
local g_visibilityTargetEntries = {};
133
134
134
135
-- ===========================================================================
135
136
function PopulateIconOptions ()
137
+ -- unique icons are specific to the current player
138
+ g_uniqueIconsPlayer = Game .GetLocalPlayer ();
136
139
-- build icon table with default pins + extensions
137
140
g_iconPulldownOptions = MapTacksIconOptions (g_stockIcons );
138
141
@@ -191,14 +194,6 @@ function UpdateIconOptionColor(iconEntryIndex :number)
191
194
end
192
195
end
193
196
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
-
202
197
-- ===========================================================================
203
198
function RequestMapPin (hexX :number , hexY :number )
204
199
local activePlayerID = Game .GetLocalPlayer ();
@@ -207,17 +202,14 @@ function RequestMapPin(hexX :number, hexY :number)
207
202
local pPlayerCfg = PlayerConfigurations [activePlayerID ];
208
203
local pMapPin = pPlayerCfg :GetMapPin (hexX , hexY );
209
204
if (pMapPin ~= nil ) then
210
- g_editMapPinID = pMapPin :GetID ()
211
-
205
+ g_editPinID = pMapPin :GetID ();
212
206
g_desiredIconName = pMapPin :GetIconName ();
213
207
if GameConfiguration .IsAnyMultiplayer () then
214
208
MapPinVisibilityToPlayerTarget (pMapPin :GetVisibility (), g_playerTarget );
215
209
UpdatePlayerTargetPulldown (Controls .VisibilityPull , g_playerTarget );
216
210
Controls .VisibilityContainer :SetHide (false );
217
211
else
218
212
Controls .VisibilityContainer :SetHide (true );
219
- -- XXX debug
220
- -- Controls.VisibilityContainer:SetHide(false);
221
213
end
222
214
223
215
Controls .PinName :SetText (pMapPin :GetName ());
@@ -244,6 +236,20 @@ function RequestMapPin(hexX :number, hexY :number)
244
236
end
245
237
end
246
238
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
+
247
253
-- ===========================================================================
248
254
function OnChatPanel_PlayerTargetChanged (playerTargetTable )
249
255
g_cachedChatPanelTarget = playerTargetTable ;
@@ -254,16 +260,19 @@ end
254
260
255
261
-- ===========================================================================
256
262
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 ;
261
270
262
271
Controls .SendToChatButton :SetHide (not showSendButton );
263
272
264
273
-- Send To Chat disables itself if the current chat panel target is not visible to the map pin.
265
274
if (showSendButton ) then
266
- local chatVisible = MapPinIsVisibleToChatTarget (pMapPin :GetVisibility (), g_cachedChatPanelTarget );
275
+ local chatVisible = MapPinIsVisibleToChatTarget (editPin :GetVisibility (), g_cachedChatPanelTarget );
267
276
Controls .SendToChatButton :SetDisabled (not chatVisible );
268
277
if (chatVisible ) then
269
278
Controls .SendToChatButton :SetToolTipString (sendToChatTTStr );
@@ -286,13 +295,13 @@ end
286
295
-- ===========================================================================
287
296
function OnOk ()
288
297
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 );
293
302
294
303
local newMapPinVisibility = PlayerTargetToMapPinVisibility (g_playerTarget );
295
- pMapPin :SetVisibility (newMapPinVisibility );
304
+ editPin :SetVisibility (newMapPinVisibility );
296
305
297
306
Network .BroadcastPlayerInfo ();
298
307
UI .PlaySound (" Map_Pin_Add" );
@@ -305,19 +314,23 @@ end
305
314
306
315
-- ===========================================================================
307
316
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 ());
312
321
end
313
322
end
314
323
315
324
-- ===========================================================================
316
325
function OnDelete ()
317
- if (g_editMapPinID ~= nil ) then
326
+ local editPinCfg = GetEditPinConfig ();
327
+ if (editPinCfg ~= nil ) then
318
328
local activePlayerID = Game .GetLocalPlayer ();
319
329
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 );
321
334
Network .BroadcastPlayerInfo ();
322
335
UI .PlaySound (" Map_Pin_Remove" );
323
336
end
@@ -331,12 +344,12 @@ end
331
344
-- Event Handlers
332
345
---- ------------------------------------------------------------
333
346
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 );
335
348
end
336
349
337
350
function OnLocalPlayerChanged ()
338
351
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 );
340
353
341
354
if ( not ContextPtr :IsHidden () ) then
342
355
UIManager :DequeuePopup ( ContextPtr );
@@ -365,7 +378,7 @@ function Initialize()
365
378
ContextPtr :SetInputHandler ( OnInputHandler , true );
366
379
367
380
PopulateIconOptions ();
368
- PopulateTargetPull (Controls .VisibilityPull , nil , g_visibilityTargetEntries , g_playerTarget , true , OnVisibilityPull );
381
+ PopulateTargetPull (Controls .VisibilityPull , nil , nil , g_visibilityTargetEntries , g_playerTarget , true , OnVisibilityPull );
369
382
Controls .DeleteButton :RegisterCallback (Mouse .eLClick , OnDelete );
370
383
Controls .DeleteButton :RegisterCallback ( Mouse .eMouseEnter , function () UI .PlaySound (" Main_Menu_Mouse_Over" ); end );
371
384
Controls .SendToChatButton :RegisterCallback (Mouse .eLClick , OnSendToChatButton );
@@ -385,6 +398,12 @@ function Initialize()
385
398
-- We have to do this because the map pin's context is loaded after the chat panel's
386
399
-- and the chat panel's show/hide handler is not triggered as expected.
387
400
LuaEvents .MapPinPopup_RequestChatPlayerTarget ();
401
+
402
+ local canChangeName = GameCapabilities .HasCapability (" CAPABILITY_RENAME" );
403
+ if (not canChangeName ) then
404
+ Controls .PinFrame :SetHide (true );
405
+ end
406
+
388
407
end
389
408
Initialize ();
390
409
0 commit comments