Ejemplo n.º 1
0
        public void PopulateMods()
        {
            UIGrid gridMods = (UIGrid)typeof(UIElement).GetFieldValue <List <UIElement> >("Elements", sidePanels["Mods"]).First(x => x is UIGrid);

            gridMods.Clear();
            foreach (Mod mod in ModLoader.GetLoadedMods().Select(ModLoader.GetMod).Where(x => !x.Name.StartsWith("ModLoader") && typeof(Mod).GetFieldValue <Dictionary <string, ModNPC> >("npcs", x).Count > 0))
            {
                UIModItem modItem = new UIModItem(mod);
                modItem.Width.Precent = 1;
                modItem.Height.Pixels = 40;
                modItem.OnClick      += (e, element) =>
                {
                    if (currentMods.Contains(modItem.mod.Name))
                    {
                        modItem.SetInactive();
                        currentMods.Remove(modItem.mod.Name);

                        UpdateItems();

                        if (!currentMods.Any())
                        {
                            gridMods.items.ForEach(x => ((UIModItem)x).SetActive());
                        }
                    }
                    else
                    {
                        if (!currentMods.Any())
                        {
                            currentMods.Clear();
                            gridMods.items.ForEach(x => ((UIModItem)x).SetInactive());
                        }

                        modItem.SetActive();
                        currentMods.Add(modItem.mod.Name);

                        UpdateItems();
                    }
                };
                gridMods.Add(modItem);
            }
        }
Ejemplo n.º 2
0
        public MarkerModulePanel(MarkerModule module) : base(module)
        {
            Width.Pixels  = 16 + (SlotSize + SlotMargin) * 9 - SlotMargin;
            Height.Pixels = 44 + SlotSize;

            UITextButton buttonClose = new UITextButton("X")
            {
                Size        = new Vector2(20),
                X           = { Percent = 100 },
                Padding     = Padding.Zero,
                RenderPanel = false
            };

            buttonClose.OnClick += args => PanelUI.Instance.CloseUI(Container);
            Add(buttonClose);

            UIText textLabel = new UIText("Marker Module")
            {
                Width  = { Percent = 100 },
                Height = { Pixels = 20 },
                HorizontalAlignment = HorizontalAlignment.Center
            };

            Add(textLabel);

            switch (Container.Mode)
            {
            case FilteredItemsMode mode:
            {
                UIGrid <UIMarkerSlot> grid = new UIGrid <UIMarkerSlot>(9)
                {
                    Width  = { Percent = 100 },
                    Height = { Pixels = -28, Percent = 100 },
                    Y      = { Pixels = 28 }
                };
                Add(grid);

                for (int i = 0; i < mode.whitelist.Count; i++)
                {
                    UIMarkerSlot slot = new UIMarkerSlot(module, i);
                    grid.Add(slot);
                }

                break;
            }

            case ModBasedMode mode:
            {
                UIGrid <UIModItem> grid = new UIGrid <UIModItem>
                {
                    Width  = { Percent = 100 },
                    Height = { Pixels = -28, Percent = 100 },
                    Y      = { Pixels = 28 }
                };
                Add(grid);

                foreach (Mod mod in ModLoader.Mods)
                {
                    if (mod.GetValue <Dictionary <string, ModItem> >("items").Count <= 0)
                    {
                        continue;
                    }

                    UIModItem item = new UIModItem(mod)
                    {
                        Width     = { Percent = 100 },
                        Height    = { Pixels = 24 },
                        TextColor = mode.mod == mod ? Color.LimeGreen : Color.White
                    };
                    item.OnClick += args =>
                    {
                        mode.mod = mod;

                        grid.Children.ForEach(modItem => ((UIModItem)modItem).TextColor = Color.White);
                        item.TextColor = Color.LimeGreen;
                    };
                    grid.Add(item);
                }

                break;
            }
            }
        }