public ScreenReturn Show(GameObject GO)
        {
            GameManager.Instance.PushGameView("QudUX:GameDetails");
            QudUXTextBlock tb = new QudUXTextBlock(0, 1, 78, 23);

            tb.DrawBorder = true;
            tb.Text       = GameDetails;

            while (true)
            {
                Buffer.Clear();
                Buffer.SingleBox();
                Buffer.Title("Game Detail");
                Buffer.EscOr5ToExit();
                Buffer.Goto(2, 24);
                Buffer.Write("[{{W|8}}-Up {{W|2}}-Down {{W|9}}-Pg.Up {{W|3}}-Pg.Down]");

                tb.Display(Buffer);

                Console.DrawBuffer(Buffer);

                Keys keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    GameManager.Instance.PopGameView();
                    return(ScreenReturn.Exit);
                }

                if (keys == Keys.NumPad3 || keys == Keys.Next)
                {
                    tb.ScrollPage(1);
                }

                if (keys == Keys.NumPad9 || keys == Keys.Prior)
                {
                    tb.ScrollPage(-1);
                }

                if (keys == Keys.NumPad2)
                {
                    tb.Scroll(1);
                }

                if (keys == Keys.NumPad8)
                {
                    tb.Scroll(-1);
                }
            }
        }
        public void SW_Choke(Cell C)
        {
            TextConsole  textConsole = Look._TextConsole;
            ScreenBuffer scrapBuffer = TextConsole.ScrapBuffer;

            XRLCore.Core.RenderMapToBuffer(scrapBuffer);
            bool bDraw = C.IsVisible();

            int nBonus = Math.Max(ParentObject.Statistics["Ego"].Modifier, Level);

            if (C != null)
            {
                foreach (GameObject GO in C.GetObjectsInCell())
                {
                    if (GO.HasPart("Brain"))
                    {
                        //if(GO.HasTag("HeroNamePrefixes"))
                        if (GO.HasTag("CanBeChoked"))
                        {
                            ChokedObject = GO;
                            EquipForceGesture();
                            //Apply force choking effect to victim
                            GO.ApplyEffect((Effect) new XRL.World.Parts.Effects.ZD_Choking(Level, GetBaseDamage(Level), GetBonusDamage(Level), ParentObject, GetSaveBonus(Level), GetRange(Level), ForceGestureObject));
                        }
                        else
                        {
                            Popup.Show("The target does not have a throat for you to choke!", true);
                        }
                    }
                }
            }
            scrapBuffer.Goto(C.X, C.Y);
            scrapBuffer.Write("&Y#");
            if (bDraw)
            {
                textConsole.DrawBuffer(scrapBuffer, (IScreenBufferExtra)null, false);
            }
            if (!bDraw)
            {
                return;
            }
            Thread.Sleep(50);
        }
Пример #3
0
        public void CallLightningAnimation()
        {
            TextConsole  _TextConsole = UI.Look._TextConsole;
            ScreenBuffer Buffer       = TextConsole.ScrapBuffer;

            Core.XRLCore.Core.RenderMapToBuffer(Buffer);

            var TargetCell = PickDestinationCell(9, AllowVis.OnlyVisible);
            var zone       = TargetCell.ParentZone;

            var SkyCell = zone.GetCell(TargetCell.X, 0);

            List <Point> SpawningLine  = Zone.Line(9, 0, 16, 0);
            List <Point> Lightningline = Zone.Line(SpawningLine.GetRandomElement().X, SpawningLine.GetRandomElement().Y, TargetCell.X, TargetCell.Y);

            List <string> SparkySparkyChars = new List <string>()
            {
                "\xf8", "*", "."
            };

            for (int index = 0; index < Lightningline.Count; index++)
            {
                Point point = Lightningline[index];
                Cell  cell  = zone.GetCell(point);


                char DisplayBeam;

                if (index % 2 == 0)
                {
                    DisplayBeam = '/';
                }
                else
                {
                    DisplayBeam = '\\';
                }

                Buffer.Goto(cell.X, cell.Y);
                Buffer.Write("&Y^b" + DisplayBeam);

                Cell SparkyBeam = cell.GetRandomLocalAdjacentCell();
                Buffer.Goto(SparkyBeam.X, SparkyBeam.Y);
                Buffer.Write("&Y" + SparkySparkyChars.GetRandomElement());
                _TextConsole.DrawBuffer(Buffer);
                System.Threading.Thread.Sleep(18);
            }



            // foreach (var C in line)
            // {
            //     GameObject Target = C.GetFirstObjectWithPart("Combat");

            //     AddPlayerMessage("Target: " + Target.DisplayName);

            //     Cell TargetCell = Target.CurrentCell;

            //     AddPlayerMessage("Target Cell Found?: " + TargetCell.DebugName);

            //     Zone TargetsZone = Target.CurrentZone;

            //     AddPlayerMessage("Target Zone Found?: " + TargetsZone.DebugName);



            //     AddPlayerMessage("Sky Cell Found?: " + SkyCell.DebugName);


            //     List<string> ElectricChars = new List<string>() { "\xf8", "*", "." };
            //     // List<Point> Lightningline = Zone.Line(line[0].X, line[0].Y, TargetCell.X, SkyCell.Y);

            //     int num = 1;

            //     int dx = Math.Abs(num - num), sx = num < -num ? 1 : -1;
            //     int dy = Math.Abs(num - num), sy = num < -num ? 1 : -1;

            //     XRLCore.ParticleManager.Add(ElectricChars.GetRandomElement(), TargetCell.X, SkyCell.Y, -dx, -dy, 1, 0f, 0f);

            //     AddPlayerMessage("Lightining Code Fired.");

            //     // for (int index = 1; index < line.Count; index++)
            //     // {
            //     //     Cell cell = line[index];
            //     //     char DisplayLightning = Lightningline[index].DisplayChar;
            //     //     Buffer.Goto(cell.X, cell.Y);
            //     //     Buffer.Write("&B^b" + DisplayLightning);

            //     //     Cell LightningStrike = cell.GetRandomLocalAdjacentCell();
            //     //     Buffer.Goto(LightningStrike.X, LightningStrike.Y);
            //     //     Buffer.Write("&W" + ElectricChars.GetRandomElement());
            //     //     _TextConsole.DrawBuffer(Buffer);
            //     //     System.Threading.Thread.Sleep(18);
            //     //     // Find a solid object and combat id on obj in line, to hit in this cell.
            //     //     GameObject obj = cell.FindObject(o => (o.HasPart("Combat")));


            //     //     if (obj != null)
            //     //     {
            //     //         TargetCell = cell;
            //     //         break;
            //     //     }
            //     // }
            //     break;
            // }
        }
        public ScreenReturn Show(GameObject targetBody)
        {
            ScreenMode    screenMode     = ScreenMode.CoreTiles;
            List <string> tileCategories = new List <string>()
            {
                "Animals", "Humanoids", "Robots", "Plants and Fungi", "Cherubim", "Statues", "Furniture", "Other (search)"
            };
            List <List <string> > tileCategoryBlueprintNodes = new List <List <string> >()
            {
                new List <string>()
                {
                    "Animal", "BaseNest"
                },
                new List <string>()
                {
                    "Humanoid"
                },
                new List <string>()
                {
                    "Robot", "Baetyl"
                },
                new List <string>()
                {
                    "Plant", "Fungus", "MutatedPlant", "MutatedFungus"
                },
                null,
                new List <string>()
                {
                    "Statue", "Eater Hologram"
                },
                new List <string>()
                {
                    "Furniture", "FoldingChair", "Vessel", "Catchbasin"
                },
                null
                //TODO: add "Pets" and "Sprites from Installed Mods" ?
            };
            int tileCategoryIndex = 0;

            GameManager.Instance.PushGameView("QudUX:CharacterTile");
            if (PlayerTemplate == null)
            {
                PlayerTemplate            = new CharacterTemplate();
                PlayerTemplate.PlayerBody = targetBody;
            }
            CharacterTileScreenExtender characterTiler = new CharacterTileScreenExtender(PlayerTemplate);
            CharacterTileScreenExtender filterTiler    = null;
            CharacterTileScreenExtender currentTiler   = null;
            var    blueprintTilers      = new Dictionary <string, CharacterTileScreenExtender>();
            string filter               = string.Empty;
            bool   moreOptionSelected   = false;
            bool   shouldAskSearchQuery = false;

            while (true)
            {
                Event.ResetPool();
                Buffer.Clear();
                Buffer.TitledBox("Modify Character Sprite");
                Buffer.Write(2, 24, " {{W|Space}}/{{W|Enter}} Confirm selection ");

                if (screenMode == ScreenMode.CoreTiles)
                {
                    Buffer.EscOr5ToExit();
                    currentTiler = characterTiler;
                    Buffer.Goto(16, 9);
                    currentTiler.DrawTileLine(Buffer);
                    if (moreOptionSelected)
                    {
                        currentTiler.EraseSelectionBox(Buffer);
                        Buffer.Write(35, 14, "{{Y|>}} {{W|More...}}");
                    }
                    else
                    {
                        Buffer.Write(35, 14, "  More...");
                    }
                }

                else if (screenMode == ScreenMode.ExtendedTilesMenu)
                {
                    Buffer.EscOr5GoBack();
                    if (screenMode == ScreenMode.ExtendedTilesMenu)
                    {
                        Buffer.Write(21, 5, "Select a category of tiles to browse:");
                        Buffer.Goto(30, 8);
                        for (int i = 0; i < tileCategories.Count; i++)
                        {
                            string prefix = (i == tileCategoryIndex ? "{{Y|> }}{{W|" : "{{y|  ");
                            Buffer.WriteLine(prefix + tileCategories[i] + "}}");
                        }
                    }
                }

                else if (screenMode == ScreenMode.ExtendedTiles)
                {
                    Buffer.EscOr5GoBack();
                    Buffer.SingleBoxHorizontalDivider(3);
                    Buffer.SingleBoxHorizontalDivider(21);

                    string category = tileCategories[tileCategoryIndex];

                    if (category == "Other (search)")
                    {
                        Buffer.Write(49, 2, "{{W|,}} or {{W|Ctrl+F}} to change query");
                        if (!string.IsNullOrEmpty(filter))
                        {
                            if (filterTiler == null || !filterTiler.CurrentQueryEquals(filter))
                            {
                                Buffer.Write(35, 10, "Loading...");
                                Console.DrawBuffer(Buffer);
                                filterTiler = new CharacterTileScreenExtender(targetBody, filter);
                                Buffer.Write(35, 10, "          ");
                                filterTiler.ResetDrawArea(3, 5, 76, 19);
                            }
                            else
                            {
                                filterTiler.ResetDrawArea(3, 5, 76, 19, preserveSelection: true);
                            }
                            currentTiler = filterTiler;
                            currentTiler.DrawFillTiles(Buffer);
                            Buffer.Write(2, 2, "Filtering on: {{C|" + filter + "}}");
                            Buffer.Write(2, 22, currentTiler.SelectionDisplayName);
                            Buffer.Write(2, 23, "{{K|" + currentTiler.SelectionBlueprintPath + "}}");
                        }
                        else if (shouldAskSearchQuery)
                        {
                            shouldAskSearchQuery = false;
                            Console.DrawBuffer(Buffer);
                            UpdateSearchString(ref filter);
                            continue;
                        }
                    }
                    else //Preset tile category
                    {
                        CharacterTileScreenExtender tiler;
                        if (!blueprintTilers.TryGetValue(category, out tiler))
                        {
                            Buffer.Write(35, 10, "Loading...");
                            Console.DrawBuffer(Buffer);
                            if (tileCategoryBlueprintNodes[tileCategoryIndex] != null)
                            {
                                tiler = new CharacterTileScreenExtender(targetBody, tileCategoryBlueprintNodes[tileCategoryIndex]);
                            }
                            else
                            {
                                tiler = new CharacterTileScreenExtender(targetBody, category);
                            }
                            blueprintTilers.Add(category, tiler);
                            Buffer.Write(35, 10, "          ");
                        }
                        Buffer.Write(2, 2, "{{Y|" + category + "}}");
                        tiler.ResetDrawArea(3, 5, 76, 19, preserveSelection: (tiler == currentTiler));
                        tiler.DrawFillTiles(Buffer);
                        currentTiler = tiler;

                        Buffer.Write(2, 22, currentTiler.SelectionDisplayName);
                        Buffer.Write(2, 23, "{{K|" + currentTiler.SelectionBlueprintPath + "}}");
                    }
                }

                if ((screenMode == ScreenMode.CoreTiles && !moreOptionSelected) || screenMode == ScreenMode.ExtendedTiles)
                {
                    if (!currentTiler.IsPhotosynthetic)
                    {
                        Buffer.Write(39, 24, "<{{W|7}}/{{W|9}} Primary color>");
                    }
                    Buffer.Write(60, 24, "<{{W|+}}/{{W|-}} Detail color>");
                    if (screenMode == ScreenMode.ExtendedTiles)
                    {
                        Buffer.Write(70, 21, "<{{W|f}} Flip>");
                    }
                }

                Console.DrawBuffer(Buffer);

                Keys keys    = Keyboard.getvk(Options.MapDirectionsToKeypad);
                char keyChar = Convert.ToChar(Keyboard.Char);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    if (screenMode == ScreenMode.CoreTiles)
                    {
                        GameManager.Instance.PopGameView();
                        return(ScreenReturn.Exit);
                    }
                    else if (screenMode == ScreenMode.ExtendedTilesMenu)
                    {
                        screenMode         = ScreenMode.CoreTiles;
                        moreOptionSelected = false;
                    }
                    else if (screenMode == ScreenMode.ExtendedTiles)
                    {
                        screenMode = ScreenMode.ExtendedTilesMenu;
                    }
                }
                if (keys == Keys.Enter || keys == Keys.Space)
                {
                    if (screenMode == ScreenMode.CoreTiles)
                    {
                        if (moreOptionSelected)
                        {
                            screenMode = ScreenMode.ExtendedTilesMenu;
                        }
                        else
                        {
                            currentTiler.ApplyToTargetBody();
                            GameManager.Instance.PopGameView();
                            return(ScreenReturn.Exit);
                        }
                    }
                    else if (screenMode == ScreenMode.ExtendedTilesMenu)
                    {
                        screenMode           = ScreenMode.ExtendedTiles;
                        filter               = string.Empty;
                        shouldAskSearchQuery = true;
                    }
                    else if (screenMode == ScreenMode.ExtendedTiles)
                    {
                        if (currentTiler.CurrentTileForegroundColor().ToLower() != "y")
                        {
                            ShowHPOptionColorWarning();
                        }
                        currentTiler.ApplyToTargetBody();
                        GameManager.Instance.PopGameView();
                        return(ScreenReturn.Exit);
                    }
                }
                if (keys == Keys.Add || keys == Keys.Oemplus)
                {
                    if ((screenMode == ScreenMode.CoreTiles && !moreOptionSelected) || screenMode == ScreenMode.ExtendedTiles)
                    {
                        currentTiler.RotateDetailColor(1);
                    }
                }
                if (keys == Keys.Subtract || keys == Keys.OemMinus)
                {
                    if ((screenMode == ScreenMode.CoreTiles && !moreOptionSelected) || screenMode == ScreenMode.ExtendedTiles)
                    {
                        currentTiler.RotateDetailColor(-1);
                    }
                }
                if (keys == Keys.NumPad2 || keys == Keys.NumPad4 || keys == Keys.NumPad6 || keys == Keys.NumPad8)
                {
                    if (screenMode == ScreenMode.ExtendedTiles || screenMode == ScreenMode.CoreTiles)
                    {
                        currentTiler.MoveSelection(keys);
                    }
                    if (keys == Keys.NumPad8)
                    {
                        if (screenMode == ScreenMode.ExtendedTilesMenu)
                        {
                            if (tileCategoryIndex > 0)
                            {
                                tileCategoryIndex--;
                            }
                        }
                        else if (screenMode == ScreenMode.CoreTiles && moreOptionSelected)
                        {
                            moreOptionSelected = false;
                        }
                    }
                    if (keys == Keys.NumPad2)
                    {
                        if (screenMode == ScreenMode.ExtendedTilesMenu)
                        {
                            if (tileCategoryIndex < tileCategories.Count - 1)
                            {
                                tileCategoryIndex++;
                            }
                        }
                        else if (screenMode == ScreenMode.CoreTiles && !moreOptionSelected)
                        {
                            moreOptionSelected = true;
                        }
                    }
                }
                if (keys == Keys.NumPad7 || keys == Keys.D7)
                {
                    if (screenMode == ScreenMode.ExtendedTiles || screenMode == ScreenMode.CoreTiles)
                    {
                        if (!currentTiler.IsPhotosynthetic)
                        {
                            ShowHPOptionColorWarning();
                            currentTiler.RotateForegroundColor(-1);
                        }
                        else
                        {
                            Popup.Show("You can't modify your primary color because you have Photosynthetic Skin.", LogMessage: false);
                        }
                    }
                }
                if (keys == Keys.NumPad9 || keys == Keys.D9)
                {
                    if (screenMode == ScreenMode.ExtendedTiles || screenMode == ScreenMode.CoreTiles)
                    {
                        if (!currentTiler.IsPhotosynthetic)
                        {
                            ShowHPOptionColorWarning();
                            currentTiler.RotateForegroundColor(1);
                        }
                        else
                        {
                            Popup.Show("You can't modify your primary color because you have Photosynthetic Skin.", LogMessage: false);
                        }
                    }
                }
                if (keys == Keys.F)
                {
                    currentTiler.Flip();
                }
                if (keys == Keys.Oemcomma || keyChar == ',' || keys == (Keys.Control | Keys.F))
                {
                    UpdateSearchString(ref filter);
                }
            }
        }
Пример #5
0
        public ScreenReturn Show(GameObject GO)
        {
            GameManager.Instance.PushGameView("QudUX:Inventory");
            QudUX_InventoryScreenState SavedInventoryState = GO.RequirePart <QudUX_InventoryScreenState>();

            InventoryScreenExtender.TabController TabController = new InventoryScreenExtender.TabController(GO);
            Inventory pInventory = GO.GetPart("Inventory") as Inventory;
            Body      pBody      = GO.GetPart("Body") as Body;

            ResetNameCache(GO);
            FilterString = "";
            Keys keys  = 0;
            bool bDone = false;

            StartObject      = 0;
            nSelected        = 0;
            currentMaxWeight = Rules.Stats.GetMaxWeight(GO);
            bool AltDisplayMode            = false;
            Dictionary <char, int> ItemMap = new Dictionary <char, int>();
            bool bShowInventoryTiles       = QudUX.Concepts.Options.UI.ViewInventoryTiles;
            List <GameObject> disabledObjectsWithImposters = null;
            GameObject        fakeTraderForPriceEval       = GameObject.create("DromadTrader1");

            if (bShowInventoryTiles)
            {
                //temporarily disable unity prefab animations in the zone from coordinates 9,3 to 9,22 - this
                //is the area where we'll render tiles and where those animations would potentially animate
                //through the inventory screen.
                disabledObjectsWithImposters = ImposterUtilities.DisableImposters(GO.CurrentZone, 9, 3, 9, 22);
            }

            while (!bDone)
            {
redraw:
                Event.ResetPool(resetMinEventPools: false);
                RebuildLists(GO, TabController);

redrawnorebuild:

                Buffer.Clear();
                Buffer.SingleBox(0, 0, 79, 24, ColorUtility.MakeColor(TextColor.Grey, TextColor.Black));
                Buffer.SingleBox(0, 0, 79, 2, ColorUtility.MakeColor(TextColor.Grey, TextColor.Black));
                //Connect box intersections
                Buffer.Goto(0, 2);
                Buffer.Write(195);
                Buffer.Goto(79, 2);
                Buffer.Write(180);

                Buffer.Goto(35, 0);
                Buffer.Write("[ {{W|Inventory}} ]");

                Buffer.Goto(60, 0);
                Buffer.Write(" {{W|ESC}} or {{W|5}} to exit ");

                Buffer.Goto(50, 24);
                Buffer.Write("< {{W|7}} Character | Equipment {{W|9}} >");

                StringBuilder WeightString = Event.NewStringBuilder();
                WeightString
                .Append("Total weight: {{Y|")
                .Append(pInventory.GetWeight() + pBody.GetWeight())
                .Append(" {{y|/}}  ")
                .Append(Rules.Stats.GetMaxWeight(pInventory.ParentObject))
                .Append(" lbs.}}")
                ;
                Buffer.Goto(79 - ColorUtility.LengthExceptFormatting(WeightString), 23);
                Buffer.Write(WeightString.ToString());

                ItemMap.Clear();

                int nObject = 0;

                QudUX_InventoryCategory CurrentCategory = null;
                GameObject CurrentObject = null;

                int yStart = 3;
                int xStart = 1;
                foreach (char keychar in CategorySelectionList.Keys)
                {
                    if (CategorySelectionList[keychar].Category != null) //category header
                    {
                        Buffer.Goto(xStart, yStart + nObject);
                        string nStart = "";

                        if (nObject == nSelected)
                        {
                            nStart          = "{{Y|>}}";
                            CurrentCategory = CategorySelectionList[keychar].Category;
                        }
                        else
                        {
                            nStart = " ";
                        }

                        StringBuilder sWeight = Event.NewStringBuilder();
                        StringBuilder sCount  = Event.NewStringBuilder();
                        char          color   = (nObject == nSelected) ? 'Y' : 'K';
                        sCount
                        .Append("{{")
                        .Append(color)
                        .Append('|')
                        ;
                        if (Options.ShowNumberOfItems)
                        {
                            sCount
                            .Append(", ")
                            .Append(CategorySelectionList[keychar].Category.Items)
                            .Append(CategorySelectionList[keychar].Category.Items == 1 ? " item" : " items")
                            ;
                        }
                        sCount.Append("}}");

                        sWeight
                        .Append(" {{")
                        .Append(nObject == nSelected ? 'Y' : 'y')
                        .Append("|[")
                        .Append(CategorySelectionList[keychar].Category.Weight)
                        .Append("#]}}")
                        ;

                        string expansionSymbol = CategorySelectionList[keychar].Category.Expanded ? "[-] " : "[+] ";

                        if (nObject == nSelected)
                        {
                            StringBuilder SB = Event.NewStringBuilder();
                            SB
                            .Append(nStart)
                            .Append(expansionSymbol)
                            .Append(keychar)
                            .Append(") {{K|[{{Y|")
                            .Append(CategorySelectionList[keychar].Category.Name)
                            .Append(sCount)
                            .Append("}}]}}")
                            ;
                            Buffer.Write(SB.ToString());
                        }
                        else
                        {
                            StringBuilder SB = Event.NewStringBuilder();
                            SB
                            .Append(nStart)
                            .Append(expansionSymbol)
                            .Append(keychar)
                            .Append(") {{K|[")
                            .Append(CategorySelectionList[keychar].Category.Name)
                            .Append(sCount)
                            .Append("]}}")
                            ;
                            Buffer.Write(SB.ToString());
                        }

                        Buffer.Goto(79 - ColorUtility.LengthExceptFormatting(sWeight), yStart + nObject);
                        Buffer.Write(sWeight);

                        ItemMap.Add(keychar, nObject);
                        nObject++;
                    }
                    else //item (not category header)
                    {
                        string nStart;
                        if (nObject == nSelected)
                        {
                            nStart        = "{{Y|>}}    ";
                            CurrentObject = CategorySelectionList[keychar].Object;
                        }
                        else
                        {
                            nStart = "     ";
                        }

                        Buffer.Goto(xStart, yStart + nObject);
                        StringBuilder SB = Event.NewStringBuilder();
                        SB
                        .Append(nStart)
                        .Append(keychar)
                        .Append(") ")
                        ;
                        Buffer.Write(SB.ToString());

                        if (bShowInventoryTiles)
                        {
                            TileMaker objectTileInfo = new TileMaker(CategorySelectionList[keychar].Object);
                            objectTileInfo.WriteTileToBuffer(Buffer);
                            Buffer.X += 1;
                        }
                        Buffer.Write(CategorySelectionList[keychar].Object.DisplayName);

                        bool          shouldHighlight = (nObject == nSelected);
                        StringBuilder detailString    = Event.NewStringBuilder();
                        if (AltDisplayMode == false || QudUX.Concepts.Options.UI.ViewItemValues == false)
                        {
                            Physics pPhysics = CategorySelectionList[keychar].Object.pPhysics;
                            if (pPhysics != null)
                            {
                                int nWeight = pPhysics.Weight;
                                detailString.Append(" {{")
                                .Append(shouldHighlight ? 'Y' : 'K')
                                .Append("|")
                                .Append(nWeight)
                                .Append("#}}");
                            }
                        }
                        else
                        {
                            string valuePerPound = InventoryScreenExtender.GetItemValueString(CategorySelectionList[keychar].Object, fakeTraderForPriceEval, shouldHighlight);
                            detailString.Append(valuePerPound);
                        }
                        detailString.Append((char)179); //right box border segment in case item name overflowed the screen
                        Buffer.Goto(80 - ColorUtility.LengthExceptFormatting(detailString), yStart + nObject);
                        Buffer.Write(detailString);

                        ItemMap.Add(keychar, nObject);
                        nObject++;
                    }
                }

                if (nObject == 0 && StartObject != 0)
                {
                    StartObject = 0;
                    goto redraw;
                }

                if (nSelected >= nObject)
                {
                    nSelected = nObject - 1;
                    goto redraw;
                }

                if (FilterString != "")
                {
                    Buffer.Goto(3, 23);
                    Buffer.Write("{{y|" + ItemsSkippedByFilter + " items hidden by filter}}");
                    Buffer.Goto(1, 1);
                    Buffer.Write("{{y|Filtering on \"" + FilterString + "\" }}");
                    Buffer.Goto(58, 1);
                    Buffer.Write("{{y| {{W|DEL}} to remove filter}}");

                    if (CategorySelectionList.Count == 0)
                    {
                        Buffer.Goto(4, 5);
                        Buffer.Write("{{y|There are no matching items in your inventory.}}");
                    }
                }
                else
                {
                    Buffer.Goto(1, 1);
                    Buffer.Write(TabController.GetTabUIString());

                    if (CategorySelectionList.Count == 0)
                    {
                        if (TabController.CurrentTab != "Main" && TabController.CurrentTab != "Other")
                        {
                            Buffer.Goto(4, 5);
                            Buffer.Write("{{y|You are not carrying any " + TabController.CurrentTab.ToLower() + ".}}");
                        }
                    }

                    if (TabController.CurrentTab == "Main")
                    {
                        Buffer.Goto(2, 24);
                        Buffer.Write("{{y|{{W|Ctrl}}+{{W|M}} move category to Other}}");
                    }
                    else if (TabController.CurrentTab == "Other")
                    {
                        if (TabController.GetCategoriesForTab("Other").Count > 0)
                        {
                            Buffer.Goto(2, 24);
                            Buffer.Write("{{y|{{W|Ctrl}}+{{W|M}} move category to Main}}");
                        }
                        else
                        {
                            Buffer.Goto(4, 5);
                            Buffer.Write("{{y|There are no item categories here.}}");
                            Buffer.Goto(4, 7);
                            Buffer.Write("{{y|Select a category on the {{Y|Main}} tab and press {{W|Ctrl}}+{{W|M}} to move it here.}}");
                        }
                    }
                }

                Buffer.Goto(34, 24);
                Buffer.Write("{{y|[{{W|?}} view keys]}}");

                TextConsole.DrawBuffer(Buffer, ImposterManager.getImposterUpdateFrame()); //need to update imposters because we've toggled their visibility
                if (!XRL.Core.XRLCore.Core.Game.Running)
                {
                    if (bShowInventoryTiles)
                    {
                        ImposterUtilities.RestoreImposters(disabledObjectsWithImposters);
                    }
                    fakeTraderForPriceEval.Obliterate();
                    GameManager.Instance.PopGameView();
                    return(ScreenReturn.Exit);
                }
                IEvent SentEvent = null;

                keys = ConsoleLib.Console.Keyboard.getvk(Options.MapDirectionsToKeypad, true);
                string ts = "";
                char   ch = (ts + (char)Keyboard.Char + " ").ToLower()[0];
                if (keys == Keys.Enter)
                {
                    keys = Keys.Space;
                }

                if (keys == Keys.MouseEvent && Keyboard.CurrentMouseEvent.Event == "RightClick")
                {
                    bDone = true;
                }
                if (keys == Keys.OemQuestion || ch == '?')
                {
                    InventoryScreenExtender.HelpText.Show();
                }
                else
                if ((int)keys == 131137)  // ctrl+a
                {
                    if (CurrentObject != null)
                    {
                        InventoryActionEvent.Check(out SentEvent, CurrentObject, GO, CurrentObject, "Eat");
                        ResetNameCache(GO);
                        ClearLists();
                    }
                }
                else
                if ((int)keys == 131140) // ctrl+d
                {
                    if (CurrentObject != null)
                    {
                        Event E = Event.New("CommandDropObject", "Object", CurrentObject);
                        SentEvent = E;
                        GO.FireEvent(E);
                        ResetNameCache(GO);
                        ClearLists();
                    }
                }
                else
                if ((int)keys == 131142 || ch == ',') // ctrl+f
                {
                    FilterString = Popup.AskString("Enter text to filter inventory by item name.", FilterString, 80, 0);
                    ClearLists();
                }
                else
                if (keys == Keys.Delete)
                {
                    FilterString = "";
                    ClearLists();
                }
                else
                if ((int)keys == 131154) // ctrl+r
                {
                    if (CurrentObject != null)
                    {
                        InventoryActionEvent.Check(out SentEvent, CurrentObject, GO, CurrentObject, "Drink");
                        ResetNameCache(GO);
                    }
                }
                else
                if ((int)keys == 131152) // ctrl+p
                {
                    if (CurrentObject != null)
                    {
                        InventoryActionEvent.Check(out SentEvent, CurrentObject, GO, CurrentObject, "Apply");
                        ResetNameCache(GO);
                        ClearLists();
                    }
                }
                else
                if (keys == Keys.NumPad7 || (keys == Keys.NumPad9 && Keyboard.RawCode != Keys.PageUp && Keyboard.RawCode != Keys.Next))
                {
                    bDone = true;
                }
                else
                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    bDone = true;
                }
                else
                if (keys == Keys.NumPad8)
                {
                    if (nSelected > 0)
                    {
                        nSelected--;
                        goto redrawnorebuild;
                    }
                    else
                    {
                        if (StartObject > 0)
                        {
                            StartObject--;
                        }
                    }
                }
                else
                if (keys == Keys.NumPad2)
                {
                    if (nSelected < nObject - 1)
                    {
                        nSelected++;
                        goto redrawnorebuild;
                    }
                    else
                    {
                        if (bMore)
                        {
                            StartObject++;
                        }
                    }
                }
                else
                if (keys == Keys.PageDown || keys == Keys.Next || Keyboard.RawCode == Keys.Next || Keyboard.RawCode == Keys.PageDown)
                {
                    if (nSelected < nObject - 1)
                    {
                        nSelected = nObject - 1;
                    }
                    else if (bMore)
                    {
                        StartObject += (InventoryListHeight - 1);
                    }
                }
                else
                if (keys == Keys.PageUp || keys == Keys.Back || Keyboard.RawCode == Keys.PageUp || Keyboard.RawCode == Keys.Back)
                {
                    if (nSelected > 0)
                    {
                        nSelected = 0;
                    }
                    else
                    {
                        StartObject -= (InventoryListHeight - 1);
                        if (StartObject < 0)
                        {
                            StartObject = 0;
                        }
                    }
                }
                else
                if (keys == Keys.Subtract || keys == Keys.OemMinus)
                {
                    foreach (QudUX_InventoryCategory Cat in CategoryList.Values)
                    {
                        Cat.Expanded = false;
                        SavedInventoryState.SetExpandState(Cat.Name, false);
                    }
                }
                else if (keys == Keys.Add || keys == Keys.Oemplus)
                {
                    foreach (QudUX_InventoryCategory Cat in CategoryList.Values)
                    {
                        Cat.Expanded = true;
                        SavedInventoryState.SetExpandState(Cat.Name, true);
                    }
                }
                else if (keys == Keys.Right || keys == Keys.NumPad6)
                {
                    TabController.Forward();
                    ClearLists();
                    StartObject = 0;
                    nSelected   = 0;
                }
                else if (keys == Keys.Left || keys == Keys.NumPad4)
                {
                    TabController.Back();
                    ClearLists();
                    StartObject = 0;
                    nSelected   = 0;
                }
                else if (keys == Keys.NumPad0 || keys == Keys.D0 || keys == Keys.OemPeriod || ch == '.')
                {
                    AltDisplayMode = !AltDisplayMode;
                }
                else if (keys == (Keys.Control | Keys.M))
                {
                    string iCategory = string.Empty;
                    if (CurrentObject != null)
                    {
                        foreach (var pair in CategoryMap)
                        {
                            if (pair.Value.Contains(CurrentObject))
                            {
                                iCategory = pair.Key;
                                break;
                            }
                        }
                    }
                    else if (CurrentCategory != null)
                    {
                        iCategory = CurrentCategory.Name;
                    }
                    if (!string.IsNullOrEmpty(iCategory))
                    {
                        if (TabController.CurrentTab == "Main")
                        {
                            string message = "{{y|Move the {{K|[{{Y|" + iCategory + "}}]}} category to the {{Y|Other}} tab?}}";
                            if (Popup.ShowYesNo(message) == DialogResult.Yes)
                            {
                                TabController.MoveCategoryFromMainToOther(iCategory);
                                ClearLists();
                            }
                        }
                        else if (TabController.CurrentTab == "Other")
                        {
                            string message = "{{y|Move the {{K|[{{Y|" + iCategory + "}}]}} category to the {{Y|Main}} tab?}}";
                            if (Popup.ShowYesNo(message) == DialogResult.Yes)
                            {
                                TabController.MoveCategoryFromOtherToMain(iCategory);
                                ClearLists();
                            }
                        }
                    }
                }
                else
                {
                    if (CurrentObject != null)
                    {
                        if (keys == (Keys.Control | Keys.E))
                        {
                            if (GO.AutoEquip(CurrentObject))
                            {
                                ResetNameCache(GO);
                            }
                        }

                        if (keys == Keys.NumPad1 || keys == Keys.D1 || keys == (Keys.Control | Keys.Left) || keys == (Keys.Control | Keys.NumPad4) || keys == (Keys.Control | Keys.Subtract) || keys == (Keys.Control | Keys.OemMinus))
                        {
                            //collapse the parent category for this item
                            foreach (var pair in CategoryMap)
                            {
                                if (pair.Value.Contains(CurrentObject))
                                {
                                    CategoryList[pair.Key].Expanded = false;
                                    SavedInventoryState.SetExpandState(pair.Key, false);
                                    forceCategorySelect = CategoryList[pair.Key];
                                    break;
                                }
                            }
                        }

                        if (keys == Keys.Space)
                        {
                            Qud.API.EquipmentAPI.TwiddleObject(GO, CurrentObject, ref bDone);
                            ResetNameCache(GO);
                        }

                        if (keys == Keys.Tab)
                        {
                            InventoryActionEvent.Check(CurrentObject, GO, CurrentObject, "Look");
                            ResetNameCache(GO);
                        }
                    }

                    if (CurrentCategory != null)
                    {
                        if (keys == Keys.NumPad1 || keys == Keys.D1 || keys == (Keys.Control | Keys.Left) || keys == (Keys.Control | Keys.NumPad4) || keys == (Keys.Control | Keys.Subtract) || keys == (Keys.Control | Keys.OemMinus))
                        {
                            CurrentCategory.Expanded = false;
                            SavedInventoryState.SetExpandState(CurrentCategory.Name, false);
                        }

                        if (keys == Keys.NumPad3 || keys == Keys.D3 || keys == (Keys.Control | Keys.Right) || keys == (Keys.Control | Keys.NumPad6) || keys == (Keys.Control | Keys.Add) || keys == (Keys.Control | Keys.Oemplus))
                        {
                            CurrentCategory.Expanded = true;
                            SavedInventoryState.SetExpandState(CurrentCategory.Name, true);
                        }

                        if (keys == Keys.Space)
                        {
                            CurrentCategory.Expanded = !CurrentCategory.Expanded;
                            SavedInventoryState.ToggleExpandState(CurrentCategory.Name);
                        }
                    }

                    if (keys >= Keys.A && keys <= Keys.Z && CategorySelectionList.ContainsKey(ch))
                    {
                        if (nSelected == ItemMap[(char)ch] && (!CategorySelectionList.ContainsKey(ch) || CategorySelectionList[ch].Category == null))
                        {
                            EquipmentAPI.TwiddleObject(GO, CurrentObject, ref bDone);
                            ResetNameCache(GO);
                        }
                        else
                        {
                            nSelected = ItemMap[(char)ch];
                            if (CategorySelectionList.ContainsKey(ch) && CategorySelectionList[ch].Category != null)
                            {
                                CategorySelectionList[ch].Category.Expanded = !CategorySelectionList[ch].Category.Expanded;
                                SavedInventoryState.ToggleExpandState(CategorySelectionList[ch].Category.Name);
                            }
                        }
                    }
                }
                if (SentEvent != null && !bDone && SentEvent.InterfaceExitRequested())
                {
                    bDone = true;
                }
            }

            ClearLists();

            if (bShowInventoryTiles)
            {
                ImposterUtilities.RestoreImposters(disabledObjectsWithImposters);
            }
            fakeTraderForPriceEval.Obliterate();

            if (keys == Keys.NumPad7)
            {
                GameManager.Instance.PopGameView();
                return(ScreenReturn.Previous);
            }
            if (keys == Keys.NumPad9)
            {
                GameManager.Instance.PopGameView();
                return(ScreenReturn.Next);
            }
            GameManager.Instance.PopGameView();
            return(ScreenReturn.Exit);
        }
Пример #6
0
        public ScreenReturn Show(GameObject GO)
        {
            GameManager.Instance.PushGameView("QudUX:GameStats");
            currentPage = StatsPage.GamesList;

            //Logger.Log("Loading scoreboard");
            Table scoreTable, levelsTable, deathCauseTable;
            bool  showAbandonned = true;

            FillTables(out scoreTable, out levelsTable, out deathCauseTable, showAbandonned);


            while (true)
            {
                DisplayScreenFrame();
                Buffer.Goto(55, 0);
                Buffer.Write(((int)currentPage).ToString() + "/3");

                Table currentTable = null;
                if (currentPage == StatsPage.GamesList)
                {
                    scoreTable.Display(Buffer, 1, 1);
                    currentTable = scoreTable;
                }
                else if (currentPage == StatsPage.LevelStats)
                {
                    levelsTable.Display(Buffer, 1, 1);
                    currentTable = levelsTable;
                }
                else if (currentPage == StatsPage.DeathStats)
                {
                    deathCauseTable.Display(Buffer, 1, 1);
                    currentTable = deathCauseTable;
                }

                Buffer.Goto(2, 23);
                Buffer.Write(ScoreList.Count.ToString() + " {{O|games}}");

                /*
                 *              // debug table
                 *              Buffer.Goto(1,24);
                 *              Buffer.Write($"si:{scoreTable.SelectedIndex} of:{scoreTable.Offset} mvr:{scoreTable.MaxVisibleRows} cvr:{scoreTable.CurrentVisibleRows} ");
                 */

                Console.DrawBuffer(Buffer);

                Keys keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    GameManager.Instance.PopGameView();
                    return(ScreenReturn.Exit);
                }

                if ((keys == Keys.Enter) && (currentPage == StatsPage.GamesList))
                {
                    EnhancedScoreEntry      esh           = ScoreList[scoreTable.Offset + scoreTable.SelectedIndex];
                    QudUX_GameDetailsScreen detailsScreen = new QudUX_GameDetailsScreen();
                    detailsScreen.GameDetails = esh.Details;
                    detailsScreen.Show(GO);
                }

                if (keys == Keys.OemQuestion)
                {
                    ShowQuickKeys();
                }

                if (currentTable != null)
                {
                    if (keys == Keys.NumPad3 || keys == Keys.Next)
                    {
                        currentTable.ScrollPage(1);
                    }

                    if (keys == Keys.NumPad9 || keys == Keys.Prior)
                    {
                        currentTable.ScrollPage(-1);
                    }

                    if (keys == Keys.NumPad2)
                    {
                        currentTable.MoveSelection(1);
                    }

                    if (keys == Keys.NumPad8)
                    {
                        currentTable.MoveSelection(-1);
                    }

                    if (keys == (Keys.Control | Keys.A))
                    {
                        showAbandonned = !showAbandonned;
                        FillTables(out scoreTable, out levelsTable, out deathCauseTable, showAbandonned);
                    }
                }

                if (keys == Keys.NumPad6)
                {
                    if (currentPage == StatsPage.DeathStats)
                    {
                        currentPage = StatsPage.GamesList;
                    }
                    else
                    {
                        currentPage++;
                    }
                }

                if (keys == Keys.NumPad4)
                {
                    if (currentPage == StatsPage.GamesList)
                    {
                        currentPage = StatsPage.DeathStats;
                    }
                    else
                    {
                        currentPage--;
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Our main menu screen method. Draws the recipe selection screen and handles related functions.
        /// </summary>
        /// <remarks>
        /// This (and several supporting methods) are static just for simplicity's sake, because it
        /// is easier to call from a Harmony patch when it's static. If we were implementing this
        /// directly, we wouldn't make this static.
        /// </remarks>
        public static ScreenReturn Show(List <Tuple <string, CookingRecipe> > recipeList, out int screenResult)
        {
            screenResult = -1;
            if (recipeList == null || recipeList.Count <= 0 || recipeList.Any(r => r.Item2 == null))
            {
                return(ScreenReturn.Exit);
            }

            recipeList.Sort(RecipeComparator);

            GameManager.Instance.PushGameView("QudUX:CookRecipes");
            ScreenBuffer cachedScrapBuffer = ScreenBuffer.GetScrapBuffer2(true);
            Keys         keys                = Keys.None;
            bool         shouldExitMenu      = false;
            int          scrollOffset        = 0;
            int          scrollAreaHeight    = 11;
            int          selectedRecipeIndex = 0;

            while (!shouldExitMenu)
            {
                ScrapBuffer.Clear();
                //Event.ResetPool();  // Can't call this here because there are active event pool lists in use by the enclosing Campfire code
                CookingRecipe selectedRecipe = recipeList[selectedRecipeIndex].Item2;

                //TODO: HANDLE 0 RECIPES (because user deleted them all)

                //Draw main box
                ScrapBuffer.TitledBox("Recipes");
                ScrapBuffer.SingleBoxHorizontalDivider(14);
                ScrapBuffer.EscOr5ToExit();
                //Help text
                ScrapBuffer.Write(2, 0, " {{W|2}} or {{W|8}} to scroll ");
                ScrapBuffer.Write(2, 24, " {{W|Space}}/{{W|Enter}} - Cook ");
                ScrapBuffer.Write(45, 24, " {{W|F}} - Favorite ");
                ScrapBuffer.Write(62, 24, " {{W|D}}/{{W|Del}} - Forget ");

                //Draw scrollable recipe list
                for (int drawIndex = scrollOffset; drawIndex < recipeList.Count && drawIndex - scrollOffset < scrollAreaHeight; drawIndex++)
                {
                    CookingRecipe recipe = recipeList[drawIndex].Item2;
                    string        name   = ColorUtility.StripFormatting(recipe.GetDisplayName());
                    if (name.Length > 74)
                    {
                        name = name.Substring(0, 71) + "...";
                    }
                    name = (recipe.CheckIngredients() ? "{{W|" + name + "}}" : "{{K|" + name + "}}");
                    name = (recipe.Favorite ? "{{R|\u0003" + name + "}}" : name);
                    int xPos = recipe.Favorite ? 4 : 5;
                    int yPos = 2 + (drawIndex - scrollOffset);

                    ScrapBuffer.Write(xPos, yPos, name);

                    if (drawIndex == selectedRecipeIndex)
                    {
                        ScrapBuffer.Write(2, yPos, "{{Y|>}}");
                    }
                }

                //Draw ingredients
                int bottomPaneTextStartPos = 2;
                int maxBottomPaneWidth     = 76;
                int ingredientPaneStartRow = 15;
                int ingredientPaneHeight   = 2;
                ScrapBuffer.Goto(bottomPaneTextStartPos, ingredientPaneStartRow);
                List <string> ingredients = StringFormat.ClipTextToArray(selectedRecipe.GetBriefIngredientList(), maxBottomPaneWidth);
                for (int i = 0; i < ingredients.Count && i < ingredientPaneHeight; i++)
                {
                    ScrapBuffer.WriteLine(ingredients[i]);
                }

                //Draw recipe effect description
                int           recipeDescriptionPaneStartRow = 18;
                int           recipeDescriptionPaneHeight   = 6;
                List <string> description = StringFormat.ClipTextToArray(selectedRecipe.GetDescription(), maxBottomPaneWidth, KeepNewlines: true);
                if (description.Count > 6)
                {
                    //This should be extremely rare - but if some single effects are longer than 2 lines for instance, this removes
                    //line breaks to condense the effect description and ensure it can fit on 6 lines total.
                    description = StringFormat.ClipTextToArray(selectedRecipe.GetDescription(), maxBottomPaneWidth, KeepNewlines: false);
                }
                ScrapBuffer.Goto(bottomPaneTextStartPos, recipeDescriptionPaneStartRow);
                for (int i = 0; i < description.Count && i < recipeDescriptionPaneHeight; i++)
                {
                    ScrapBuffer.WriteLine(description[i]);
                }

                //Draw the screen
                Console.DrawBuffer(ScrapBuffer);

                //Respond to keyboard input
                keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    screenResult   = -1;                   //canceled
                    shouldExitMenu = true;
                }
                if (keys == Keys.NumPad8)
                {
                    if (selectedRecipeIndex == scrollOffset)
                    {
                        if (scrollOffset > 0)
                        {
                            scrollOffset--;
                            selectedRecipeIndex--;
                        }
                    }
                    else if (selectedRecipeIndex > 0)
                    {
                        selectedRecipeIndex--;
                    }
                }
                if (keys == Keys.NumPad2)
                {
                    int maxIndex = recipeList.Count - 1;
                    if (selectedRecipeIndex < maxIndex)
                    {
                        selectedRecipeIndex++;
                    }
                    if (selectedRecipeIndex - scrollOffset >= scrollAreaHeight)
                    {
                        scrollOffset++;
                    }
                }
                if (keys == Keys.Prior)                 //PgUp
                {
                    selectedRecipeIndex = ((selectedRecipeIndex != scrollOffset) ? scrollOffset : (scrollOffset = Math.Max(scrollOffset - (scrollAreaHeight - 1), 0)));
                }
                if (keys == Keys.Next)                 //PgDn
                {
                    if (selectedRecipeIndex != scrollOffset + (scrollAreaHeight - 1))
                    {
                        selectedRecipeIndex = scrollOffset + (scrollAreaHeight - 1);
                    }
                    else
                    {
                        int advancementDistance = scrollAreaHeight - 1;
                        selectedRecipeIndex += advancementDistance;
                        scrollOffset        += advancementDistance;
                    }
                    selectedRecipeIndex = Math.Min(selectedRecipeIndex, recipeList.Count - 1);
                    scrollOffset        = Math.Min(scrollOffset, recipeList.Count - 1);
                }
                if (keys == Keys.F)
                {
                    selectedRecipe.Favorite = !selectedRecipe.Favorite;
                    recipeList.Sort(RecipeComparator);
                    if (selectedRecipe.Favorite)
                    {
                        //if this was just marked as a favorite, update selection index to continue to point to it where it was moved
                        for (int i = 0; i < recipeList.Count; i++)
                        {
                            if (recipeList[i].Item2 == selectedRecipe)
                            {
                                selectedRecipeIndex = i;
                                //scroll the selection back into view if needed
                                if (selectedRecipeIndex < scrollOffset || selectedRecipeIndex >= (scrollOffset + scrollAreaHeight))
                                {
                                    scrollOffset = Math.Max(0, selectedRecipeIndex - (scrollAreaHeight / 2));
                                }
                            }
                        }
                    }
                }
                if (keys == Keys.D || keys == Keys.Delete)
                {
                    if (Popup.ShowYesNo("{{y|Are you sure you want to forget your recipe for }}" + selectedRecipe.GetDisplayName() + "{{y|?}}") == DialogResult.Yes)
                    {
                        selectedRecipe.Hidden = true;
                        for (int i = 0; i < recipeList.Count; i++)
                        {
                            if (recipeList[i].Item2 == selectedRecipe)
                            {
                                recipeList.RemoveAt(i);
                                break;
                            }
                        }
                        selectedRecipeIndex = Math.Min(selectedRecipeIndex, recipeList.Count - 1);
                        scrollOffset        = Math.Min(scrollOffset, recipeList.Count - 1);
                    }
                }
                if (keys == Keys.Space || keys == Keys.Enter)
                {
                    if (!selectedRecipe.CheckIngredients())
                    {
                        List <ICookingRecipeComponent> missingComponents = selectedRecipe.Components.Where(c => !c.doesPlayerHaveEnough()).ToList();
                        string message = "{{y|You don't have enough servings of }}";
                        int    idx     = 0;
                        foreach (ICookingRecipeComponent component in missingComponents)
                        {
                            message += component.GetComponentSimpleName().PrependListElementJoinString(idx++, missingComponents.Count, "or");
                        }
                        message += "{{y| to cook }}" + selectedRecipe.GetDisplayName() + "{{y|.}}";
                        Popup.Show(message, LogMessage: false);
                        continue;
                    }
                    else if (Popup.ShowYesNo("Cook " + selectedRecipe.GetDisplayName() + "&y?") == DialogResult.Yes)
                    {
                        screenResult   = selectedRecipeIndex;
                        shouldExitMenu = true;
                    }
                }
            }

            //Screen exit
            Console.DrawBuffer(cachedScrapBuffer);
            GameManager.Instance.PopGameView(true);
            return(ScreenReturn.Exit);
        }
Пример #8
0
        /// <summary>
        /// Our main menu screen method. Draws the ingredient selection screen and handles related functions.
        /// </summary>
        /// <remarks>
        /// This (and several supporting methods) are static just for simplicity's sake, because it
        /// is easier to call from a Harmony patch when it's static. If we were implementing this
        /// directly, we wouldn't make this static.
        /// </remarks>
        public static ScreenReturn Show(List <GameObject> ingredients, List <bool> isIngredientSelected)
        {
            if (ingredients == null || ingredients.Count <= 0 || isIngredientSelected == null || isIngredientSelected.Count != ingredients.Count)
            {
                return(ScreenReturn.Exit);
            }

            GameManager.Instance.PushGameView("QudUX:CookIngredients");
            ScreenBuffer cachedScrapBuffer = ScreenBuffer.GetScrapBuffer2(true);
            Keys         keys                    = Keys.None;
            bool         shouldExitMenu          = false;
            int          scrollOffset            = 0;
            int          selectedIngredientIndex = 0;
            int          scrollAreaHeight        = 14;
            int          amountColumnPos         = 43;

            //Determine number of ingredients player is allowed to use
            int allowedIngredientCount = 2;

            if (IComponent <GameObject> .ThePlayer.HasSkill("CookingAndGathering_Spicer"))
            {
                allowedIngredientCount++;
            }

            //Gather ingredient display details
            List <IngredientScreenInfo> ingredientOptions = GetIngredientScreenInfo(ingredients, isIngredientSelected);

            while (!shouldExitMenu)
            {
                ScrapBuffer.Clear();
                //Event.ResetPool();  // Can't call this here because there are active event pool lists in use by the enclosing Campfire code
                int selectedIngredientCount = ingredientOptions.Where(io => io.IsSelected == true).Count();

                //Draw main box
                ScrapBuffer.TitledBox("Ingredients");

                //Draw bottom box with selected ingredients
                ScrapBuffer.SingleBoxHorizontalDivider(17);
                int row = 18;
                foreach (IngredientScreenInfo info in ingredientOptions.Where(io => io.IsSelected == true))
                {
                    ScrapBuffer.Write(2, row++, info.OptionName);
                    ScrapBuffer.Write(5, row++, info.CookEffect);
                    if (row > 23)
                    {
                        break;
                    }
                }

                //Draw ingredient list
                if (ingredientOptions.Count == 0)
                {
                    ScrapBuffer.Write(4, 3, "You don't have any ingredients.");
                }
                else
                {
                    for (int drawIndex = scrollOffset; drawIndex < ingredientOptions.Count && drawIndex - scrollOffset < scrollAreaHeight; drawIndex++)
                    {
                        int yPos = 2 + (drawIndex - scrollOffset);
                        ScrapBuffer.Goto(4, yPos);
                        if (string.IsNullOrEmpty(ingredientOptions[drawIndex].OptionName))
                        {
                            ScrapBuffer.Write("&k<Error: unknown ingredient>&y");
                        }
                        else
                        {
                            string option = ingredientOptions[drawIndex].GetCheckboxString();
                            ScrapBuffer.Write(option);
                            if (ConsoleLib.Console.ColorUtility.LengthExceptFormatting(option) > 39)
                            {
                                ScrapBuffer.Write(40, yPos, "{{y|...             }}");
                            }
                        }

                        ScrapBuffer.Goto(amountColumnPos, 2 + (drawIndex - scrollOffset));
                        if (drawIndex == selectedIngredientIndex)
                        {
                            ScrapBuffer.Write("{{^K|" + ingredientOptions[drawIndex].UseCount + "}}");
                        }
                        else
                        {
                            ScrapBuffer.Write(ingredientOptions[drawIndex].UseCount);
                        }

                        //Draw selection caret at current index
                        if (drawIndex == selectedIngredientIndex)
                        {
                            ScrapBuffer.Goto(2, 2 + (drawIndex - scrollOffset));
                            ScrapBuffer.Write("{{Y|>}}");
                        }
                    }
                }

                //Help text on bottom of screen
                ScrapBuffer.Write(2, 24, " {{W|Space{{y|/}}Enter}}{{y| - Select}} ");
                ScrapBuffer.Write(46, 24, " {{W|C{{y|/}}Ctrl+Space{{y|/}}Ctrl+Enter}}{{y| - Cook}} ");

                //Infobox on right-hand side of screen
                ScrapBuffer.SingleBox(56, 0, 79, 17, ConsoleLib.Console.ColorUtility.MakeColor(TextColor.Grey, TextColor.Black));
                ScrapBuffer.Fill(57, 1, 78, 16, ' ', ConsoleLib.Console.ColorUtility.MakeColor(TextColor.Black, TextColor.Black));
                //Fix box intersections
                ScrapBuffer.Goto(56, 17);
                ScrapBuffer.Write(193);
                ScrapBuffer.Goto(56, 0);
                ScrapBuffer.Write(194);
                ScrapBuffer.Goto(79, 17);
                ScrapBuffer.Write(180);

                //Help text at top of screen
                ScrapBuffer.Write(2, 0, "{{y| {{W|2}} or {{W|8}} to scroll }}");
                ScrapBuffer.EscOr5ToExit();

                //Write description to infobox for currently highlighted ingredient
                string   highlightDescription      = ingredientOptions[selectedIngredientIndex].CookEffect;
                string[] linedHighlightDescription = StringFormat.ClipTextToArray(highlightDescription, 20).ToArray();
                ScrapBuffer.Goto(58, 2);
                ScrapBuffer.WriteBlockWithNewlines(linedHighlightDescription, 14);

                //Draw the screen
                Console.DrawBuffer(ScrapBuffer);

                //Respond to keyboard input
                keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    //clear out the boolean list, since our current Harmony setup uses that as a method
                    //to determine whether anything was selected from this menu
                    for (int i = 0; i < isIngredientSelected.Count(); i++)
                    {
                        isIngredientSelected[i] = false;
                    }
                    shouldExitMenu = true;
                }
                if (keys == Keys.NumPad8)
                {
                    if (selectedIngredientIndex == scrollOffset)
                    {
                        if (scrollOffset > 0)
                        {
                            scrollOffset--;
                            selectedIngredientIndex--;
                        }
                    }
                    else if (selectedIngredientIndex > 0)
                    {
                        selectedIngredientIndex--;
                    }
                }
                if (keys == Keys.NumPad2)
                {
                    int maxIndex = ingredientOptions.Count - 1;
                    if (selectedIngredientIndex < maxIndex)
                    {
                        selectedIngredientIndex++;
                    }
                    if (selectedIngredientIndex - scrollOffset >= scrollAreaHeight)
                    {
                        scrollOffset++;
                    }
                }
                if (keys == Keys.Prior)                 //PgUp
                {
                    selectedIngredientIndex = ((selectedIngredientIndex != scrollOffset) ? scrollOffset : (scrollOffset = Math.Max(scrollOffset - (scrollAreaHeight - 1), 0)));
                }
                if (keys == Keys.Next)                 //PgDn
                {
                    if (selectedIngredientIndex != scrollOffset + (scrollAreaHeight - 1))
                    {
                        selectedIngredientIndex = scrollOffset + (scrollAreaHeight - 1);
                    }
                    else
                    {
                        int advancementDistance = scrollAreaHeight - 1;
                        selectedIngredientIndex += advancementDistance;
                        scrollOffset            += advancementDistance;
                    }
                    selectedIngredientIndex = Math.Min(selectedIngredientIndex, ingredientOptions.Count - 1);
                    scrollOffset            = Math.Min(scrollOffset, ingredientOptions.Count - 1);
                }
                if (keys == Keys.C || keys == (Keys.Control | Keys.Enter) || keys == (Keys.Control | Keys.Space))
                {
                    if (selectedIngredientCount > 0)
                    {
                        shouldExitMenu = true;
                    }
                    else
                    {
                        Popup.Show("You haven't selected any ingredients to cook with.", LogMessage: false);
                    }
                }
                if (keys == Keys.Space || keys == Keys.Enter)
                {
                    if (ingredientOptions[selectedIngredientIndex].IsSelected == true)
                    {
                        ingredientOptions[selectedIngredientIndex].IsSelected = false;
                    }
                    else
                    {
                        if (selectedIngredientCount >= allowedIngredientCount)
                        {
                            Popup.Show("You can't select more than " + selectedIngredientCount + " ingredients.", LogMessage: false);
                        }
                        else
                        {
                            ingredientOptions[selectedIngredientIndex].IsSelected = true;
                        }
                    }
                }
                if (keys == Keys.NumPad6)
                {
                    if (ingredientOptions[selectedIngredientIndex].IsSelected == false)
                    {
                        if (selectedIngredientCount >= allowedIngredientCount)
                        {
                            Popup.Show("You can't select more than " + selectedIngredientCount + " ingredients.", LogMessage: false);
                        }
                        else
                        {
                            ingredientOptions[selectedIngredientIndex].IsSelected = true;
                        }
                    }
                }
                if (keys == Keys.NumPad4)
                {
                    if (ingredientOptions[selectedIngredientIndex].IsSelected == true)
                    {
                        ingredientOptions[selectedIngredientIndex].IsSelected = false;
                    }
                }
            }

            //Screen exit
            Console.DrawBuffer(cachedScrapBuffer);
            GameManager.Instance.PopGameView(true);
            return(ScreenReturn.Exit);
        }
        public void ApplyCombustExplosion(Cell C, List <Cell> UsedCells, List <GameObject> Hit, int Force, bool bLocal, bool bShow, GameObject Owner, string BonusDamage, bool?Phase, bool Neutron = false, float DamageModifier = 1f)
        {
            TextConsole  textConsole = Look._TextConsole;
            ScreenBuffer scrapBuffer = TextConsole.ScrapBuffer;

            if (bShow)
            {
                TextConsole.LoadScrapBuffers();
                XRLCore.Core.RenderMapToBuffer(scrapBuffer);
            }
            CleanQueue <Cell>   cleanQueue  = new CleanQueue <Cell>();
            CleanQueue <int>    cleanQueue2 = new CleanQueue <int>();
            CleanQueue <string> cleanQueue3 = new CleanQueue <string>();

            cleanQueue.Enqueue(C);
            cleanQueue2.Enqueue(Force);
            cleanQueue3.Enqueue(".");
            UsedCells.Add(C);
            while (cleanQueue.Count > 0)
            {
                Cell   cell = cleanQueue.Dequeue();
                int    num  = cleanQueue2.Dequeue();
                string text = cleanQueue3.Dequeue();
                for (int i = 0; i < UsedCells.Count; i++)
                {
                    Cell cell2 = UsedCells[i];
                    if (cell2 == null)
                    {
                        return;
                    }
                    if (cell2.ParentZone == XRLCore.Core.Game.ZoneManager.ActiveZone)
                    {
                        scrapBuffer.Goto(cell2.X, cell2.Y);
                        int num2 = Stat.Random(1, 3);
                        if (num2 == 1)
                        {
                            scrapBuffer.Write((Phase != null) ? ((!(Phase == true)) ? "&Y*" : "&K*") : "&M*");
                        }
                        else if (num2 == 2)
                        {
                            scrapBuffer.Write((Phase != null) ? ((!(Phase == true)) ? "&R*" : "&b*") : "&G*");
                        }
                        else
                        {
                            scrapBuffer.Write((Phase != null) ? ((!(Phase == true)) ? "&W*" : "&c*") : "&m*");
                        }
                    }
                }
                if (bShow && C.ParentZone != null && C.ParentZone.IsActive())
                {
                    textConsole.DrawBuffer(scrapBuffer, null, false);
                    if (Force < 100000)
                    {
                        Thread.Sleep(5);
                    }
                }
                List <Cell> list;
                if (bLocal)
                {
                    list = cell.GetLocalAdjacentCells(1, false);
                }
                else
                {
                    list = cell.GetAdjacentCells(true);
                }
                for (int j = 0; j < UsedCells.Count; j++)
                {
                    Cell item = UsedCells[j];
                    if (list.CleanContains(item))
                    {
                        list.Remove(item);
                    }
                }
                int    num3   = 0;
                Damage damage = null;
                Event  @event = null;
                foreach (GameObject gameObject in cell.GetObjectsWithPart("Physics"))
                {
                    if (!Hit.Contains(gameObject))
                    {
                        Hit.Add(gameObject);
                        if (gameObject.PhaseMatches(0))
                        {
                            num3 += gameObject.Weight;
                            if (damage == null || !string.IsNullOrEmpty(BonusDamage))
                            {
                                damage = new Damage((int)(DamageModifier * (float)num / 250f));
                                if (!string.IsNullOrEmpty(BonusDamage))
                                {
                                    damage.Amount += BonusDamage.RollCached();
                                }
                                damage.AddAttribute("Explosion");
                                damage.AddAttribute("Heat");
                                damage.AddAttribute("Fire");
                                damage.AddAttribute("Concussion");
                                if (cell != C)
                                {
                                    damage.AddAttribute("Accidental");
                                }
                            }
                            if (@event == null || !string.IsNullOrEmpty(BonusDamage))
                            {
                                @event = Event.New("TakeDamage", 0, 0, 0);
                                @event.SetParameter("Damage", damage);
                                @event.SetParameter("Owner", Owner);
                                @event.SetParameter("Attacker", Owner);
                                if (Neutron)
                                {
                                    if (gameObject.IsPlayer())
                                    {
                                        gameObject.pPhysics.LastDeathReason = "Crushed under the weight of a thousand suns.";
                                    }
                                    @event.SetParameter("Message", "from being crushed under the weight of a thousand suns.");
                                }
                                else
                                {
                                    @event.SetParameter("Message", "from %t explosion!");
                                }
                            }
                            gameObject.FireEvent(@event);
                        }
                    }
                }
                System.Random random = new System.Random();
                for (int k = 0; k < list.Count; k++)
                {
                    int  index = random.Next(0, list.Count);
                    Cell value = list[k];
                    list[k]     = list[index];
                    list[index] = value;
                }
                Damage damage2 = null;
                Event  event2  = null;
                for (; ;)
                {
IL_44B:
                    int l = 0;
                    while (l < list.Count)
                    {
                        Cell cell3 = list[l];
                        if (!bLocal)
                        {
                            goto IL_4AD;
                        }
                        if (cell3.X != 0)
                        {
                            if (cell3.X != 79)
                            {
                                if (cell3.Y != 0)
                                {
                                    if (cell3.Y != 24)
                                    {
                                        goto IL_4AD;
                                    }
                                }
                            }
                        }
IL_68C:
                        l++;
                        continue;
IL_4AD:
                        foreach (GameObject gameObject2 in cell3.GetObjectsWithPart("Physics"))
                        {
                            if (!Hit.Contains(gameObject2))
                            {
                                Hit.Add(gameObject2);
                                if (gameObject2.PhaseMatches(0))
                                {
                                    if (damage2 == null || !string.IsNullOrEmpty(BonusDamage))
                                    {
                                        damage2 = new Damage(num / 250);
                                        if (!string.IsNullOrEmpty(BonusDamage))
                                        {
                                            damage2.Amount += BonusDamage.RollCached();
                                        }
                                        damage2.AddAttribute("Explosion");
                                        damage2.AddAttribute("Accidental");
                                        damage2.AddAttribute("Heat");
                                        damage2.AddAttribute("Fire");
                                        damage2.AddAttribute("Concussion");
                                    }
                                    if (event2 == null || !string.IsNullOrEmpty(BonusDamage))
                                    {
                                        event2 = Event.New("TakeDamage", 0, 0, 0);
                                        event2.SetParameter("Damage", damage2);
                                        event2.SetParameter("Owner", Owner);
                                        event2.SetParameter("Attacker", Owner);
                                        if (Neutron)
                                        {
                                            if (gameObject2.IsPlayer())
                                            {
                                                gameObject2.pPhysics.LastDeathReason = "Crushed under the weight of a thousand suns.";
                                            }
                                            event2.SetParameter("Message", "from being crushed under the weight of a thousand suns.");
                                        }
                                        else
                                        {
                                            event2.SetParameter("Message", "from %t explosion!");
                                        }
                                    }
                                    gameObject2.FireEvent(event2);
                                }
                            }
                            if (gameObject2.PhaseMatches(0))
                            {
                                int weight = gameObject2.Weight;
                                if (weight > num)
                                {
                                    list.Remove(cell3);
                                    goto IL_44B;
                                }
                                if (weight > 0)
                                {
                                    gameObject2.Move((!(text == ".")) ? text : Directions.GetRandomDirection(), EnergyCost: 1000);
                                }
                            }
                        }
                        if (cell3.IsSolid())
                        {
                            list.Remove(cell3);
                            goto IL_44B;
                        }
                        goto IL_68C;
                    }
                    break;
                }
                if (list.Count > 0)
                {
                    int num4 = (num - num3) / list.Count;
                    if (num4 > 100)
                    {
                        foreach (Cell cell4 in list)
                        {
                            if (cell4 != null && !UsedCells.Contains(cell4))
                            {
                                UsedCells.Add(cell4);
                                cleanQueue.Enqueue(cell4);
                                cleanQueue2.Enqueue(num4);
                                cleanQueue3.Enqueue(cell.GetDirectionFromCell(cell4));
                            }
                        }
                    }
                }
            }
        }
        public void ActuallyFire(int Charges)
        {
            FocusPsi PsiMutation = ParentObject.GetPart <FocusPsi>();

            // Shows the line picker interface for the player.

            TextConsole  _TextConsole = UI.Look._TextConsole;
            ScreenBuffer Buffer       = TextConsole.ScrapBuffer;

            Core.XRLCore.Core.RenderMapToBuffer(Buffer);

            List <GameObject> hit       = new List <GameObject>(1);
            List <Cell>       usedCells = new List <Cell>(1);
            var line = PickLine(20, AllowVis.Any, null, false, ForMissileFrom: ParentObject);

            Body            body        = ParentObject.GetPart <Body>();
            List <BodyPart> ParentsHead = body.GetPart("Head");

            Cell targetCell = line[line.Count - 1];

            if (!PsiMutation.usePsiCharges(Charges))
            {
                AddPlayerMessage("You do not have enough psi-charges!");
                return;
            }
            foreach (var Head in ParentsHead)
            {
                if (Head.Equipped != null)
                {
                    Physics.ApplyExplosion(currentCell, GetForce(Level, Charges), usedCells, hit, true, true, ParentObject, GetDamage(Level, Charges), 1, false, false, 2);
                    AddPlayerMessage("Your helmet obstructs the energy of the beam--it explodes in your face!");
                    return;
                }
            }
            if (ParentObject.HasEffect("Dazed") || ParentObject.HasEffect("Confused"))
            {
                Physics.ApplyExplosion(currentCell, GetForce(Level, Charges), usedCells, hit, true, true, ParentObject, GetDamage(Level, Charges), 1, false, false, 2);
                AddPlayerMessage("You lack the concentration to hold your focus! The collected energy explodes in your face!");
                return;
            }

            ActivatedAbilities activatedAbilities = ParentObject.GetPart("ActivatedAbilities") as ActivatedAbilities;

            activatedAbilities.GetAbility(CombustionBlastActivatedAbilityID).Cooldown = (Charges - 1) * 100;

            // Loop through each cell of the line in order.

            List <string> SparkySparkyChars = new List <string>()
            {
                "\xf8", "*", "."
            };
            List <Point> Beamline = Zone.Line(line[0].X, line[0].Y, targetCell.X, targetCell.Y);

            base.PlayWorldSound("sparkblast", 0.3f, 0.1f, true, null);

            for (int index = 1; index < line.Count; index++)
            {
                Cell cell        = line[index];
                char DisplayBeam = Beamline[index].DisplayChar;
                Buffer.Goto(cell.X, cell.Y);
                Buffer.Write("&Y^r" + DisplayBeam);

                Cell SparkyBeam = cell.GetRandomLocalAdjacentCell();
                Buffer.Goto(SparkyBeam.X, SparkyBeam.Y);
                Buffer.Write("&W" + SparkySparkyChars.GetRandomElement());
                _TextConsole.DrawBuffer(Buffer);
                System.Threading.Thread.Sleep(18);
                // Find a solid object and combat id on obj in line, to hit in this cell.
                GameObject obj = cell.FindObject(o => o.ConsiderSolidFor(ParentObject, ParentObject) || (o.HasPart("Combat") && !o.pPhysics.Solid));


                if (obj != null)
                {
                    targetCell = cell;
                    break;
                }
            }
            if (Stat.Random(1, 100) <= 50)
            {
                base.PlayWorldSound("bang1", 0.3f, 0, true, null);
            }
            else
            {
                base.PlayWorldSound("bang2", 0.3f, 0, true, null);
            }
            ComExplode(GetForce(Level, Charges), targetCell, ParentObject, GetDamage(Level, Charges));
            ParentObject.UseEnergy(10000);
        }
        public ScreenReturn Show(GameObject GO)
        {
            int scrollOffset     = 0;
            int selectedIndex    = 0;
            int scrollAreaHeight = 21;
            Dictionary <string, string> optionList = GetOptionList(QudUX_AutogetHelper.AutogetSettings);

            while (true)
            {
                List <string> optionStrings = optionList.Keys.ToList();

                Buffer.Clear();
                Buffer.SingleBox();
                Buffer.SingleBoxVerticalDivider(49);
                Buffer.Title("Auto-pickup Exclusions");
                Buffer.EscOr5ToExit();

                Buffer.Write(2, 24, " {{W|Space}}/{{W|Enter}}-Remove selected ");
                Buffer.Write(64, 24, " {{W|R}}-Remove all ");

                if (optionStrings.Count <= 0)
                {
                    Buffer.Write(9, 2, "{{K|You haven't disabled auto-pickup}}");
                    Buffer.Write(9, 3, "{{K|         for any items}}");
                }
                else
                {
                    Buffer.Goto(2, 2);
                    for (int i = scrollOffset; i < optionStrings.Count && i < (scrollOffset + scrollAreaHeight); i++)
                    {
                        string entry = (i == selectedIndex) ? "{{Y|> }}" : "  ";
                        entry += optionStrings[i];
                        Buffer.WriteLine(entry);
                    }
                }

                Buffer.Fill(50, 1, 78, 23);
                Buffer.Goto(51, 2);
                Buffer.WriteLine("You've disabled auto-pickup");
                Buffer.WriteLine("for the items listed here.");
                Buffer.WriteLine("These exclusions apply to");
                Buffer.WriteLine("all characters.");
                Buffer.WriteLine("");
                Buffer.WriteLine("Your default game settings");
                Buffer.WriteLine("for auto-pickup will be");
                Buffer.WriteLine("applied first, and then any");
                Buffer.WriteLine("additional exclusions you");
                Buffer.WriteLine("have set here will also be");
                Buffer.WriteLine("applied");
                Buffer.WriteLine("");
                Buffer.WriteLine("You can add or remove ");
                Buffer.WriteLine("auto-pickup exclusions");
                Buffer.WriteLine("outside this menu by");
                Buffer.WriteLine("activating an item and");
                Buffer.WriteLine("selecting the option to");
                Buffer.WriteLine("\"disable auto-pickup\" or");
                Buffer.WriteLine("\"re-enable auto-pickup\"");

                Console.DrawBuffer(Buffer);

                Keys keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    GameManager.Instance.PopGameView();
                    return(ScreenReturn.Exit);
                }
                if (keys == Keys.NumPad2)
                {
                    if (selectedIndex < optionStrings.Count - 1)
                    {
                        selectedIndex++;
                        if (selectedIndex > (scrollOffset + scrollAreaHeight - 1))
                        {
                            scrollOffset++;
                        }
                    }
                }
                if (keys == Keys.NumPad8)
                {
                    if (selectedIndex > 0)
                    {
                        selectedIndex--;
                        if (selectedIndex < scrollOffset)
                        {
                            scrollOffset = selectedIndex;
                        }
                    }
                }
                if ((keys == Keys.Space || keys == Keys.Enter) && optionStrings.Count > 0)
                {
                    if (Popup.ShowYesNo($"Remove auto-pickup exclusion for {optionStrings[selectedIndex]}?") == DialogResult.Yes)
                    {
                        string optionString = optionStrings[selectedIndex];
                        string bagKey       = optionList[optionString];
                        optionList.Remove(optionString);
                        QudUX_AutogetHelper.AutogetSettings.Bag.Remove(bagKey);
                        QudUX_AutogetHelper.AutogetSettings.Flush();
                        if (selectedIndex > optionList.Count - 1)
                        {
                            selectedIndex = Math.Max(0, selectedIndex - 1);
                        }
                    }
                }
                if (keys == Keys.R && optionStrings.Count > 0)
                {
                    if (Popup.ShowYesNo("Remove ALL of your auto-pickup exclusions?") == DialogResult.Yes)
                    {
                        string[] itemsToRemove = QudUX_AutogetHelper.AutogetSettings.Bag.Keys
                                                 .Where(s => s.StartsWith("ShouldAutoget:")).ToArray();

                        foreach (string item in itemsToRemove)
                        {
                            QudUX_AutogetHelper.AutogetSettings.Bag.Remove(item);
                        }
                        QudUX_AutogetHelper.AutogetSettings.Flush();
                        optionList = new Dictionary <string, string>();
                    }
                }
            }
        }
        public static string Show()
        {
            GameManager.Instance.PushGameView("QudUX:BuildLibrary");

            int           currentIndex  = 0;
            int           scrollOffset  = 0;
            int           startX        = 2;
            int           startY        = 2;
            int           scrollHeight  = 21;
            int           infoboxStartX = 47;
            int           infoboxStartY = 2;
            int           infoboxEndY   = 22;
            int           infoboxHeight = infoboxEndY - infoboxStartY + 1;
            List <string> buildInfo     = new List <string>();


            while (true)
            {
                int    infoboxOffset = 0;
                string lastBuiltCode = "";
                buildInfo.Clear();

                BuildLibrary.Init();
                List <BuildEntry> buildEntries = BuildLibrary.BuildEntries;
                if (buildEntries == null)
                {
                    buildEntries = new List <BuildEntry>();
                }

                if (currentIndex >= buildEntries.Count)
                {
                    currentIndex = buildEntries.Count - 1;
                }
                if (scrollOffset < (currentIndex - scrollHeight + 1))
                {
                    scrollOffset = currentIndex - scrollHeight + 1;
                }

                while (true)
                {
                    Event.ResetPool();
                    ScrapBuffer.Clear();
                    ScrapBuffer.SingleBox(0, 0, 79, 24, ColorUtility.MakeColor(TextColor.Grey, TextColor.Black));
                    if (buildEntries.Count > 0)
                    {
                        ScrapBuffer.SingleBox(infoboxStartX - 2, 0, 79, 24, ColorUtility.MakeColor(TextColor.Grey, TextColor.Black));
                    }
                    ScrapBuffer.Goto(32, 0);
                    ScrapBuffer.Write("{{y|[ {{W|Build Library}} ]}}");
                    ScrapBuffer.Goto(60, 0);
                    ScrapBuffer.Write("{{y| {{W|ESC}} or {{W|5}} to exit }}");

                    for (int i = scrollOffset; i < scrollOffset + scrollHeight && i < buildEntries.Count; i++)
                    {
                        int y = (i - scrollOffset) + startY;
                        ScrapBuffer.Goto(startX, y);
                        string prefix       = (currentIndex == i) ? "{{Y|> }}{{W|" : "  {{w|";
                        string postfix      = "}}";
                        int    maxNameWidth = infoboxStartX - startX - 4;
                        string buildName    = buildEntries[i].Name;
                        if (ColorUtility.StripFormatting(buildName).Length > maxNameWidth)
                        {
                            buildName = ColorUtility.StripFormatting(buildName);
                            buildName = buildName.Substring(0, maxNameWidth - 3) + "{{K|...}}";
                        }
                        ScrapBuffer.Write($"{{{{y|{prefix}{buildName}{postfix}}}}}");
                    }
                    string currentBuildCode = null;
                    if (buildEntries.Count <= 0)
                    {
                        string[] array = StringFormat.ClipText("You don't have any character builds in your library. You can save a build after you create a character, or you can find builds online and import their codes.", 70).Split('\n');
                        for (int j = 0; j < array.Length; j++)
                        {
                            ScrapBuffer.Goto(5, 4 + j);
                            ScrapBuffer.Write(array[j]);
                        }
                    }
                    else
                    {
                        currentBuildCode = buildEntries[currentIndex].Code;
                        if (currentBuildCode != lastBuiltCode)
                        {
                            lastBuiltCode = currentBuildCode;
                            MakeBody(currentBuildCode);
                            buildInfo = GetBuildSidebarInfo();
                        }
                    }

                    bool hasScrollableBuildInfo = buildInfo.Count > infoboxHeight;
                    for (int row = infoboxStartY; row <= infoboxEndY; row++)
                    {
                        int index = row - infoboxStartY + infoboxOffset;
                        if (index >= buildInfo.Count)
                        {
                            break;
                        }
                        ScrapBuffer.Goto(infoboxStartX, row);
                        ScrapBuffer.Write(buildInfo[index]);
                    }
                    if (hasScrollableBuildInfo)
                    {
                        if (buildInfo.Count > infoboxOffset + infoboxHeight)
                        {
                            ScrapBuffer.Goto(infoboxStartX, infoboxEndY);
                            ScrapBuffer.Write("{{W|<More... {{y|use}} + {{y|to scroll down}}>}}");
                        }
                        if (infoboxOffset > 0)
                        {
                            ScrapBuffer.Goto(infoboxStartX, infoboxStartY);
                            ScrapBuffer.Write("{{W|<More... {{y|use}} - {{y|to scroll up}}>}}");
                        }
                    }

                    ScrapBuffer.Goto(1, 24);
                    ScrapBuffer.Write(" &WSpace&y-Select &WT&y-Tweet &WR&y-Rename &WC&y-Copy Code &WE&y-Enter Code &WP&y-Paste Code &WD&y-Delete ");

                    Console.DrawBuffer(ScrapBuffer);

                    Keys keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                    if (keys == Keys.Escape || keys == Keys.NumPad5)
                    {
                        GameManager.Instance.PopGameView();
                        return(null);
                    }
                    if (keys == Keys.NumPad8)
                    {
                        if (currentIndex > 0)
                        {
                            currentIndex--;
                            if (currentIndex < scrollOffset)
                            {
                                scrollOffset--;
                            }
                        }
                        //break;
                        continue;
                    }
                    if (keys == Keys.NumPad2)
                    {
                        if (currentIndex < buildEntries.Count - 1)
                        {
                            currentIndex++;
                            if (currentIndex - scrollOffset >= scrollHeight)
                            {
                                scrollOffset++;
                            }
                        }
                    }
                    if (keys == Keys.E)
                    {
                        string code = Popup.AskString("Enter a character build code.", "", 60);
                        if (!CreateCharacter.IsValidCode(code))
                        {
                            Popup.Show("That's an invalid code.");
                            continue;
                        }
                        if (BuildLibrary.HasBuild(code))
                        {
                            Popup.Show("That character build is already in your library.");
                            continue;
                        }
                        string name = Popup.AskString("Give this build a name.", "", 60);
                        BuildLibrary.AddBuild(code, name);
                        currentIndex = buildEntries.Count;
                        break;
                    }
                    if (keys == Keys.Add || keys == Keys.Oemplus)
                    {
                        if (hasScrollableBuildInfo)
                        {
                            if (buildInfo.Count > infoboxOffset + infoboxHeight)
                            {
                                infoboxOffset++;
                            }
                        }
                    }
                    if (keys == Keys.Subtract || keys == Keys.OemMinus)
                    {
                        if (hasScrollableBuildInfo)
                        {
                            if (infoboxOffset > 0)
                            {
                                infoboxOffset--;
                            }
                        }
                    }
                    if (keys == Keys.P || keys == Keys.Insert || keys == Keys.V || keys == (Keys.Control | Keys.V))
                    {
                        string text = CreateCharacter.ClipboardHelper.GetClipboardData();
                        if (!CreateCharacter.IsValidCode(text))
                        {
                            if (text == null)
                            {
                                text = "";
                            }
                            Popup.Show("The code you pasted is invalid.\n\n" + text);
                            continue;
                        }
                        else if (BuildLibrary.HasBuild(text))
                        {
                            Popup.Show("That character build is already in your library.");
                            continue;
                        }
                        else
                        {
                            string name2 = Popup.AskString("Give this build a name.", "", 60);
                            BuildLibrary.AddBuild(text, name2);
                            currentIndex = buildEntries.Count;
                            break;
                        }
                    }
                    if (keys == Keys.MouseEvent && Keyboard.CurrentMouseEvent.Event.StartsWith("Choice:"))
                    {
                        //mouse input not supported in QudUX version of build library
                    }

                    //remaining options require at least one entry
                    if (buildEntries.Count <= 0)
                    {
                        continue;
                    }

                    if (keys == Keys.Enter || keys == Keys.Space)
                    {
                        if (!CreateCharacter.IsValidCode(currentBuildCode))
                        {
                            Popup.Show("This build's build code is no longer valid. It may be from an outdated version of the game.");
                            continue;
                        }
                        MetricsManager.LogEvent("Chargen:Library:" + currentBuildCode);
                        GameManager.Instance.PopGameView();
                        return(currentBuildCode);
                    }
                    if (keys == Keys.C || keys == (Keys.Control | Keys.C))
                    {
                        CreateCharacter.ClipboardHelper.SetClipboardData(currentBuildCode.ToUpper());
                    }
                    if (keys == Keys.R && buildEntries.Count > 0)
                    {
                        string text2 = Popup.AskString("Give this build a new name.", "", 60);
                        if (!string.IsNullOrEmpty(text2))
                        {
                            buildEntries[currentIndex].Name = text2;
                            BuildLibrary.UpdateBuild(buildEntries[currentIndex]);
                            break;
                        }
                    }
                    if (keys == Keys.T && buildEntries.Count > 0)
                    {
                        CreateCharacter.ShareToTwitter("HEY! Try my Caves of Qud character build. I call it, \""
                                                       + buildEntries[currentIndex].Name + "\".\n" + currentBuildCode.ToUpper());
                    }
                    if (keys == Keys.Delete || keys == Keys.D)
                    {
                        if (Popup.ShowYesNoCancel("Are you sure you want to delete this character build?") == DialogResult.Yes)
                        {
                            BuildLibrary.DeleteBuild(currentBuildCode);
                            break;
                        }
                    }
                }
            }
        }