コード例 #1
0
        public static void Import(string filename)
        {
            var path = Path.Combine(Configuration.AutoSaveFolderPath, filename + ".xml");

            if (!File.Exists(path))
            {
                Log.Info($"[{nameof(PresetsUtils)}.{nameof(Import)}] No auto-save file found in path {path}");

                return;
            }

            Log.Info($"[{nameof(PresetsUtils)}.{nameof(Import)}] Loading auto-saved networks from file {path}");

            try
            {
                List <PresetNetItem> presetItems;
                var xmlSerializer = new XmlSerializer(typeof(List <PresetNetItem>));
                using (var streamReader = new StreamReader(path))
                {
                    presetItems = (List <PresetNetItem>)xmlSerializer.Deserialize(streamReader);
                }

                Singleton <ParallelRoadTool> .instance.ClearItems();

                Singleton <ParallelRoadTool> .instance.SelectedRoadTypes.Clear();

                foreach (var preset in presetItems)
                {
                    var netInfo = PrefabCollection <NetInfo> .FindLoaded(preset.NetName);

                    if (netInfo == null)
                    {
                        Log.Info($"[{nameof(PresetsUtils)}.{nameof(Import)}] Couldn't import network with name {preset.NetName} from preset {filename}");

                        continue;
                    }

                    Log.Info($"[{nameof(PresetsUtils)}.{nameof(Import)}] Adding network {netInfo.name} from preset {filename}");

                    var item = new NetTypeItem(netInfo, preset.HorizontalOffset, preset.VerticalOffset,
                                               preset.IsReversed);
                    Singleton <ParallelRoadTool> .instance.SelectedRoadTypes.Add(item);

                    Singleton <ParallelRoadTool> .instance.AddItem(item);

                    NetManagerDetour.NetworksCount = Singleton <ParallelRoadTool> .instance.SelectedRoadTypes.Count;
                }
            }
            catch (Exception e)
            {
                Log.Info($"[{nameof(PresetsUtils)}.{nameof(Import)}] Failed importing {filename} from {path}");
                Log.Exception(e);

                UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel")
                .SetMessage(
                    Locale.Get($"{Configuration.ResourcePrefix}TEXTS", "ImportFailedTitle"),
                    string.Format(Locale.Get($"{Configuration.ResourcePrefix}TEXTS", "ImportFailedMessage"), path),
                    true);
            }
        }
コード例 #2
0
        public void UpdateItem(NetTypeItem item, int index)
        {
            var currentItem = _items[index];

            currentItem.HorizontalOffset = item.HorizontalOffset;
            currentItem.VerticalOffset   = item.VerticalOffset;
            currentItem.IsReversed       = item.IsReversed;

            currentItem.UpdateItem();
        }
コード例 #3
0
        public override void Start()
        {
            name                      = "PRT_NetList";
            padding                   = new RectOffset(4, 4, 4, 0);
            size                      = new Vector2(500 - 8 * 2, 200);
            autoLayoutPadding         = new RectOffset(0, 0, 0, 4);
            autoFitChildrenVertically = true;
            autoLayout                = true;
            autoLayoutDirection       = LayoutDirection.Vertical;
            backgroundSprite          = "GenericPanel";
            color                     = Color.black;

            _items = new List <UINetTypeItem>();

            _currentTool = AddUIComponent <UINetTypeItem>();
            _currentTool.IsCurrentItem = true;
            _currentTool.OnAddCallback = () =>
            {
                DebugUtils.Log("Adding item to list");

                // get offset of previuous item
                float prevOffset = 0;
                if (List.Any())
                {
                    prevOffset = List.Last().HorizontalOffset;
                }

                var netInfo = _currentTool.DropDown.selectedIndex == 0
                    ? PrefabCollection <NetInfo> .FindLoaded(_currentTool.NetInfo.name)
                    : ParallelRoadTool.AvailableRoadTypes[_currentTool.DropDown.selectedIndex];

                DebugUtils.Log($"{_currentTool.NetInfo} halfWidth: {_currentTool.NetInfo.m_halfWidth}");

                var item = new NetTypeItem(netInfo, prevOffset + netInfo.m_halfWidth * 2, 0, false);
                List.Add(item);

                RenderList();

                Changed();
            };

            _space      = AddUIComponent <UIPanel>();
            _space.size = new Vector2(1, 1);
        }
コード例 #4
0
        public void AddItem(NetTypeItem item, bool isCurrentItem = false)
        {
            var component = AddUIComponent <UINetTypeItem>();

            if (!isCurrentItem)
            {
                component.NetInfo          = item.NetInfo;
                component.HorizontalOffset = item.HorizontalOffset;
                component.VerticalOffset   = item.VerticalOffset;
                component.IsReversed       = item.IsReversed;
                component.Index            = _items.Count;
                component.OnChanged       += UiNetTypeItemOnOnChanged;
                component.OnDeleteClicked += UiNetTypeItemOnOnDeleteClicked;
                _items.Add(component);
            }
            else
            {
                component.OnAddClicked += UiNetTypeItemOnOnAddClicked;
                component.IsCurrentItem = true;
            }

            _space.BringToFront();
        }
コード例 #5
0
 public void UpdateItem(NetTypeItem item, int index)
 {
     _netList.UpdateItem(item, index);
 }
コード例 #6
0
 public void AddItem(NetTypeItem item)
 {
     _netList.AddItem(item);
 }