示例#1
0
        /**
         * Helper method that renames settlement.
         */
        public static void SetSettlementName(Settlement sourceSettlement, string newName, bool updateGlobalMap = true)
        {
            if (updateGlobalMap)
            {
                var globalMapScene            = SandBox.View.Map.MapScreen.Instance.GetMapView <GauntletMapSettlementNameplate>();
                SettlementNameplatesVM plates = (SettlementNameplatesVM)globalMapScene.GetType()
                                                .GetField("_dataSource", BindingFlags.NonPublic | BindingFlags.Instance)
                                                ?.GetValue(globalMapScene);

                foreach (var curPlate in plates.Nameplates.Where(plate => plate.Settlement == sourceSettlement))
                {
                    curPlate.Name = newName;
                    InformationManager.DisplayMessage(new InformationMessage($"Renamed"));
                }
                plates.Update();
            }

            sourceSettlement.Name = new TextObject(newName);
            if (baseBehavior._customDataMap == null)
            {
                baseBehavior._customDataMap = new Dictionary <string, string>();
            }

            var storage = baseBehavior._customDataMap;

            if (storage.ContainsKey(sourceSettlement.Id.ToString()))
            {
                storage.Remove(sourceSettlement.Id.ToString());
            }

            baseBehavior._customDataMap.Add(sourceSettlement.Id.ToString(), newName);
            Campaign.Current.EncyclopediaManager.CreateEncyclopediaPages();
        }
        public static void Postfix(SettlementNameplatesVM __instance)
        {
            MBBindingListInterceptor nameplates = new MBBindingListInterceptor();

            __instance.Nameplates = nameplates;
        }