コード例 #1
0
        private void Main_Aborted(object sender, EventArgs e)
        {
            // Unsub NativeUI events
            if (BenchMain != null)
            {
                BenchMain.OnItemSelect -= BenchMain_OnItemSelect;
            }

            if (BenchList != null)
            {
                BenchList.OnItemSelect -= BenchList_OnItemSelect;
            }

            if (AmountItem != null)
            {
                AmountItem.Activated -= AmountItem_Activated;
            }

            if (ConfirmItem != null)
            {
                ConfirmItem.Activated -= ConfirmItem_Activated;
            }

            // Clear managers
            AmmoTypeManager.Clear();
            MaterialManager.Clear();
            ConversionManager.Clear();

            // Unsub area events before nuking benches
            foreach (Bench bench in BenchManager.Benches)
            {
                if (bench.Area != null)
                {
                    bench.Area.PlayerEnter -= PlayerEnterBenchArea;
                    bench.Area.PlayerLeave -= PlayerLeaveBenchArea;
                }
            }

            BenchManager.Clear();

            // Other clean-up
            CurCraftingAmounts.Clear();
            MaterialMenuItems.Clear();

            CurCraftingAmounts = null;
            MaterialMenuItems  = null;
        }
コード例 #2
0
        public Main()
        {
            // Initialize managers
            AmmoTypeManager.Init();
            MaterialManager.Init();
            ConversionManager.Init();
            BenchManager.Init();

            // NativeUI
            Point          noBannerOffset = new Point(0, -107);
            UIResRectangle emptyBanner    = new UIResRectangle(Point.Empty, Size.Empty, Color.Empty);

            // Main menu
            BenchMain = new UIMenu(string.Empty, "SELECT AN OPTION", noBannerOffset);
            BenchMain.SetBannerType(emptyBanner);

            // Generic list menu for displaying ammo types/bench materials, subtitle changes with BenchMain item selection
            BenchList = new UIMenu(string.Empty, "LIST MENU TITLE", noBannerOffset);
            BenchList.SetBannerType(emptyBanner);

            // Action menu, subtitle changes with BenchList item selection
            BenchAction = new UIMenu(string.Empty, "ACTION MENU TITLE", noBannerOffset);
            BenchAction.SetBannerType(emptyBanner);

            MaterialHeader = new UIMenuColoredItem("~b~MATERIAL", Color.Transparent, Color.Transparent);
            MaterialHeader.SetRightLabel("~b~BENCH");
            MaterialHeader.Enabled = false;

            // Amount button
            AmountItem = new UIMenuItem("Amount");
            AmountItem.SetRightLabel("Select...");

            // Confirm button
            ConfirmItem = new UIMenuItem("Confirm");
            ConfirmItem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);

            // Separators
            MaterialSeparator         = new UIMenuColoredItem("TITLE", Color.Black, Color.Black);
            MaterialSeparator.Enabled = false;

            ActionSeparator         = new UIMenuColoredItem("~b~ACTION", Color.Black, Color.Black);
            ActionSeparator.Enabled = false;

            // Menu relations
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Craft Ammo"));
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Dismantle Ammo"));
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Bench Materials"));

            // Add menus to the menupool
            MenuPool.Add(BenchMain);
            MenuPool.Add(BenchList);
            MenuPool.Add(BenchAction);

            // Menu events
            BenchMain.OnItemSelect += BenchMain_OnItemSelect;
            BenchList.OnItemSelect += BenchList_OnItemSelect;
            AmountItem.Activated   += AmountItem_Activated;
            ConfirmItem.Activated  += ConfirmItem_Activated;

            // Events
            Tick    += Main_Tick;
            Aborted += Main_Aborted;
        }
コード例 #3
0
        private void BenchList_OnItemSelect(UIMenu sender, UIMenuItem selectedItem, int index)
        {
            if (CurBench == null || !CanUseBench || CurListMode == ListMode.None || CurListMode == ListMode.Inventory)
            {
                return;
            }

            CurAmmoType = AmmoTypeManager.GetHashes()[index];
            CurAmount   = 0;

            BenchAction.RefreshIndex();
            BenchAction.Clear();

            CurCraftingAmounts.Clear();
            MaterialMenuItems.Clear();

            switch (CurListMode)
            {
            case ListMode.Crafting:
                BenchAction.Subtitle.Caption = $"~b~CRAFTING: ~s~{selectedItem.Text.ToUpperInvariant()}";
                MaterialSeparator.Text       = "~b~REQUIRES";

                bool isMaxCapacity = Util.CalcAmmoCapacity(CurAmmoType) == 0;
                AmountItem.SetRightLabel(isMaxCapacity ? "Full" : "Select...");
                BenchAction.AddItem(AmountItem);
                BenchAction.AddItem(MaterialSeparator);
                BenchAction.AddItem(MaterialHeader);

                // Crafting material display
                foreach (var material in ConversionManager.Conversions[CurAmmoType].CraftingMaterials)
                {
                    UIMenuColoredItem item = new UIMenuColoredItem($"→ {material.Value} {MaterialManager.GetName(material.Key)}", Color.Transparent, Color.Transparent);
                    item.SetRightLabel(CurBench.GetMaterialAmount(material.Key).ToString());
                    item.HighlightedTextColor = Color.WhiteSmoke;
                    item.Enabled = false;

                    MaterialMenuItems[material.Key] = item;
                    BenchAction.AddItem(item);
                }

                BenchAction.AddItem(ActionSeparator);
                BenchAction.AddItem(ConfirmItem);

                AmountItem.Enabled  = !isMaxCapacity;
                ConfirmItem.Enabled = false;
                break;

            case ListMode.Dismantling:
                BenchAction.Subtitle.Caption = $"~b~DISMANTLING: ~s~{selectedItem.Text.ToUpperInvariant()}";
                MaterialSeparator.Text       = "~b~GIVES";

                bool canDismantle = Game.Player.Character.GetAmmoByType(CurAmmoType) > 0;
                AmountItem.SetRightLabel(canDismantle ? "Select..." : "No Ammo");
                BenchAction.AddItem(AmountItem);
                BenchAction.AddItem(MaterialSeparator);
                BenchAction.AddItem(MaterialHeader);

                // Dismantling material display
                foreach (var material in ConversionManager.Conversions[CurAmmoType].BreakdownMaterials)
                {
                    int min = material.Value.Item1;
                    int max = material.Value.Item2;

                    UIMenuColoredItem item = new UIMenuColoredItem($"→ {(min == max ? max.ToString() : $"{min}-{max}")} {MaterialManager.GetName(material.Key)}", Color.Transparent, Color.Transparent);
                    item.SetRightLabel(CurBench.GetMaterialAmount(material.Key).ToString());
                    item.HighlightedTextColor = Color.WhiteSmoke;

                    MaterialMenuItems[material.Key] = item;
                    BenchAction.AddItem(item);
                }

                BenchAction.AddItem(ActionSeparator);
                BenchAction.AddItem(ConfirmItem);

                AmountItem.Enabled  = canDismantle;
                ConfirmItem.Enabled = false;
                break;
            }