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 = GO.GetMaxCarriedWeight();
            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(pInventory.ParentObject.GetMaxCarriedWeight())
                .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);
        }
Пример #2
0
 public void ClearBuffer() => _buffer.Clear();
        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;
                        }
                    }
                }
            }
        }
        public ScreenReturn Show(GameObject targetBody)
        {
            ScreenMode    screenMode     = ScreenMode.CoreTiles;
            List <string> tileCategories = new List <string>()
            {
                "Animals", "Humanoids", "Robots", "Plants and Fungi", "Cherubim", "Statues", "Furniture", "Character Presets", "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,
                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;
            //}
            if (PlayerTemplate == null)
            {
                PlayerTemplate = 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 //"Character Presets" or "Cherubim"
                            {
                                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);
                }
            }
        }