public static void FlushInput()
 {
     while (Global.KeyIsAvailable())
     {
         Global.ReadKey();
     }
 }
        public static string EnterString(int max_length)
        {
            string         s = "";
            ConsoleKeyInfo command;

            Screen.CursorVisible = true;
            bool done   = false;
            int  cursor = Screen.CursorLeft;

            Screen.WriteString(Screen.CursorTop, cursor, "".PadRight(max_length));
            while (!done)
            {
                Screen.SetCursorPosition(cursor, Screen.CursorTop);
                command = Global.ReadKey();
                if ((command.KeyChar >= '!' && command.KeyChar <= '~') || command.KeyChar == ' ')
                {
                    if (s.Length < max_length)
                    {
                        s = s + command.KeyChar;
                        Screen.WriteChar(Screen.CursorTop, cursor, command.KeyChar);
                        ++cursor;
                    }
                }
                else
                {
                    if (command.Key == ConsoleKey.Backspace && s.Length > 0)
                    {
                        s = s.Substring(0, s.Length - 1);
                        --cursor;
                        Screen.WriteChar(Screen.CursorTop, cursor, ' ');
                        Screen.SetCursorPosition(cursor, Screen.CursorTop);
                    }
                    else
                    {
                        if (command.Key == ConsoleKey.Escape)
                        {
                            return("");
                        }
                        else
                        {
                            if (command.Key == ConsoleKey.Enter)
                            {
                                if (s.Length == 0)
                                {
                                    return("");
                                }
                                done = true;
                            }
                        }
                    }
                }
            }
            return(s);
        }
        public static void DebugDisplayPositions(IEnumerable <pos> list)
        {
            var temp = Screen.GetCurrentScreen();

            foreach (pos p in list)
            {
                Screen.WriteMapChar(p.row, p.col, '!', Color.Red);
            }
            Global.ReadKey();
            Screen.WriteArray(0, 0, temp);
        }
        public static int EnterInt(int max_length)
        {
            string         s = "";
            ConsoleKeyInfo command;

            Screen.CursorVisible = true;
            bool done = false;
            int  pos  = Screen.CursorLeft;

            Screen.WriteString(Screen.CursorTop, pos, "".PadRight(max_length));
            while (!done)
            {
                Screen.SetCursorPosition(pos, Screen.CursorTop);
                command = Global.ReadKey();
                if (command.KeyChar >= '0' && command.KeyChar <= '9')
                {
                    if (s.Length < max_length)
                    {
                        s = s + command.KeyChar;
                        Screen.WriteChar(Screen.CursorTop, pos, command.KeyChar);
                        ++pos;
                    }
                }
                else
                {
                    if (command.Key == ConsoleKey.Backspace && s.Length > 0)
                    {
                        s = s.Substring(0, s.Length - 1);
                        --pos;
                        Screen.WriteChar(Screen.CursorTop, pos, ' ');
                        Screen.SetCursorPosition(pos, Screen.CursorTop);
                    }
                    else
                    {
                        if (command.Key == ConsoleKey.Escape)
                        {
                            return(0);
                        }
                        else
                        {
                            if (command.Key == ConsoleKey.Enter)
                            {
                                if (s.Length == 0)
                                {
                                    return(-1);
                                }
                                done = true;
                            }
                        }
                    }
                }
            }
            return(Convert.ToInt32(s));
        }
        public static void DebugDisplayDijkstra(PosArray <int> d, int default_cost)
        {
            int h = d.objs.GetLength(0);
            int w = d.objs.GetLength(1);

            for (int i = 0; i < h; ++i)
            {
                for (int j = 0; j < w; ++j)
                {
                    if (d[i, j] == U.DijkstraMax)
                    {
                        Screen.WriteMapChar(i, j, '!', Color.DarkGray);
                    }
                    else
                    {
                        if (d[i, j] == U.DijkstraMin)
                        {
                            Screen.WriteMapChar(i, j, '#', Color.Gray);
                        }
                        else
                        {
                            if (d[i, j] == 0)
                            {
                                Screen.WriteMapChar(i, j, '0', Color.White);
                            }
                            else
                            {
                                int cost = d[i, j] / default_cost;
                                if (cost < 10)
                                {
                                    Screen.WriteMapChar(i, j, cost.ToString()[0], Color.Cyan);
                                }
                                else
                                {
                                    Screen.WriteMapChar(i, j, '+', Color.Blue);
                                }
                            }
                        }
                    }
                }
            }
            Global.ReadKey();
        }
Beispiel #6
0
        public bool YesOrNoPrompt(string s, bool easy_cancel)
        {
            player.Interrupt();
            MouseUI.PushButtonMap(MouseMode.YesNoPrompt);
            MouseUI.CreateButton(ConsoleKey.Y, false, 2, Global.MAP_OFFSET_COLS + s.Length + 1, 1, 2);
            MouseUI.CreateButton(ConsoleKey.N, false, 2, Global.MAP_OFFSET_COLS + s.Length + 4, 1, 2);
            if (MouseUI.descend_hack && Actor.viewing_more_commands)
            {
                MouseUI.CreateStatsButton(ConsoleKey.N, false, 16, 1);
                MouseUI.descend_hack = false;
            }
            DisplayNow(s + " (y/n): ");
            Screen.CursorVisible = true;
            while (true)
            {
                switch (Global.ReadKey().KeyChar)
                {
                case 'y':
                case 'Y':
                    MouseUI.PopButtonMap();
                    return(true);

                case 'n':
                case 'N':
                    MouseUI.PopButtonMap();
                    return(false);

                default:
                    if (easy_cancel)
                    {
                        MouseUI.PopButtonMap();
                        return(false);
                    }
                    break;
                }
            }
        }
        public static void ShowKnownItems(Dict <ConsumableType, bool> IDed)
        {
            MouseUI.PushButtonMap();
            int width = 25;
            List <ConsumableType> potion_order = new List <ConsumableType> {
                ConsumableType.STONEFORM, ConsumableType.CLOAKING, ConsumableType.VAMPIRISM, ConsumableType.HEALING, ConsumableType.MYSTIC_MIND, ConsumableType.SILENCE, ConsumableType.REGENERATION, ConsumableType.ROOTS, ConsumableType.BRUTISH_STRENGTH, ConsumableType.HASTE
            };
            List <ConsumableType> scroll_order = new List <ConsumableType> {
                ConsumableType.SUNLIGHT, ConsumableType.DARKNESS, ConsumableType.BLINKING, ConsumableType.RENEWAL, ConsumableType.FIRE_RING, ConsumableType.CALLING, ConsumableType.KNOWLEDGE, ConsumableType.PASSAGE, ConsumableType.THUNDERCLAP, ConsumableType.RAGE, ConsumableType.ENCHANTMENT, ConsumableType.TIME, ConsumableType.TRAP_CLEARING
            };
            List <ConsumableType> orb_order = new List <ConsumableType> {
                ConsumableType.BREACHING, ConsumableType.FREEZING, ConsumableType.SHIELDING, ConsumableType.BLADES, ConsumableType.CONFUSION, ConsumableType.FLAMES, ConsumableType.DETONATION, ConsumableType.PAIN, ConsumableType.TELEPORTAL, ConsumableType.FOG
            };
            List <ConsumableType> wand_order = new List <ConsumableType> {
                ConsumableType.DUST_STORM, ConsumableType.SLUMBER, ConsumableType.TELEKINESIS, ConsumableType.REACH, ConsumableType.INVISIBILITY, ConsumableType.WEBS, ConsumableType.FLESH_TO_FIRE
            };
            List <colorstring>         potions      = new List <colorstring>();
            List <colorstring>         scrolls      = new List <colorstring>();
            List <colorstring>         orbs         = new List <colorstring>();
            List <colorstring>         wands        = new List <colorstring>();
            List <List <colorstring> > string_lists = new List <List <colorstring> > {
                potions, scrolls, orbs, wands
            };
            int list_idx = 0;

            foreach (List <ConsumableType> item_list in new List <List <ConsumableType> > {
                potion_order, scroll_order, orb_order, wand_order
            })
            {
                int item_idx = 0;
                while (item_idx + 1 < item_list.Count)
                {
                    ConsumableType[] ct         = new ConsumableType[2];
                    string[]         name       = new string[2];
                    Color[]          ided_color = new Color[2];
                    for (int i = 0; i < 2; ++i)
                    {
                        ct[i]   = item_list[item_idx + i];
                        name[i] = ct[i].ToString()[0] + ct[i].ToString().Substring(1).ToLower();
                        name[i] = name[i].Replace('_', ' ');
                        if (IDed[ct[i]])
                        {
                            ided_color[i] = Color.Cyan;
                        }
                        else
                        {
                            ided_color[i] = Color.DarkGray;
                        }
                    }
                    int num_spaces = width - (name[0].Length + name[1].Length);
                    string_lists[list_idx].Add(new colorstring(name[0], ided_color[0], "".PadRight(num_spaces), Color.Black, name[1], ided_color[1]));
                    item_idx += 2;
                }
                if (item_list.Count % 2 == 1)
                {
                    ConsumableType ct   = item_list.Last();
                    string         name = (ct.ToString()[0] + ct.ToString().Substring(1).ToLower()).Replace('_', ' ');
                    //name = name[i].Replace('_',' ');
                    Color ided_color = Color.DarkGray;
                    if (IDed[ct])
                    {
                        ided_color = Color.Cyan;
                    }
                    int num_spaces = width - name.Length;
                    string_lists[list_idx].Add(new colorstring(name, ided_color, "".PadRight(num_spaces), Color.Black));
                }
                ++list_idx;
            }
            Screen.WriteMapString(0, 0, "".PadRight(COLS, '-'));
            for (int i = 1; i < ROWS - 1; ++i)
            {
                Screen.WriteMapString(i, 0, "".PadToMapSize());
            }
            Screen.WriteMapString(ROWS - 1, 0, "".PadRight(COLS, '-'));
            Color label_color          = Color.Yellow;
            int   first_column_offset  = 2;
            int   second_column_offset = first_column_offset + 35;

            Screen.WriteMapString(2, 8 + first_column_offset, "- Potions -", label_color);
            Screen.WriteMapString(2, 4 + second_column_offset, "- Scrolls -", label_color);
            int line = 3;

            foreach (colorstring s in potions)
            {
                Screen.WriteMapString(line, first_column_offset, s);
                ++line;
            }
            line = 3;
            foreach (colorstring s in scrolls)
            {
                Screen.WriteMapString(line, second_column_offset, s);
                ++line;
            }
            Screen.WriteMapString(12, 9 + first_column_offset, "- Orbs -", label_color);
            Screen.WriteMapString(12, 8 + second_column_offset, "- Wands -", label_color);
            line = 13;
            foreach (colorstring s in orbs)
            {
                Screen.WriteMapString(line, first_column_offset, s);
                ++line;
            }
            line = 13;
            foreach (colorstring s in wands)
            {
                Screen.WriteMapString(line, second_column_offset, s);
                ++line;
            }
            B.DisplayNow("Discovered item types: ");
            Screen.CursorVisible = true;
            Global.ReadKey();
            MouseUI.PopButtonMap();
        }
        public static void ShowPreviousMessages(bool show_footsteps)
        {
            List <string> messages = B.GetMessages();

            MouseUI.PushButtonMap(MouseMode.ScrollableMenu);
            MouseUI.CreateMapButton(ConsoleKey.OemMinus, false, 3, 1);
            MouseUI.CreateMapButton(ConsoleKey.OemPlus, false, 24, 1);
            Screen.CursorVisible = false;
            //Screen.Blank();
            Screen.WriteMapString(0, 0, "".PadRight(COLS, '-'));
            Screen.WriteMapString(21, 0, "".PadRight(COLS, '-'));
            ConsoleKeyInfo command2;
            char           ch2;
            int            startline = Math.Max(0, messages.Count - 20);

            for (bool done = false; !done;)
            {
                if (startline > 0)
                {
                    Screen.WriteMapString(0, COLS - 3, new colorstring("[", Color.Yellow, "-", Color.Cyan, "]", Color.Yellow));
                }
                else
                {
                    Screen.WriteMapString(0, COLS - 3, "---");
                }
                bool more = false;
                if (startline + 20 < messages.Count)
                {
                    more = true;
                }
                if (more)
                {
                    Screen.WriteMapString(ROWS - 1, COLS - 3, new colorstring("[", Color.Yellow, "+", Color.Cyan, "]", Color.Yellow));
                }
                else
                {
                    Screen.WriteMapString(ROWS - 1, COLS - 3, "---");
                }
                for (int i = 1; i <= 20; ++i)
                {
                    if (messages.Count - startline < i)
                    {
                        Screen.WriteMapString(i, 0, "".PadToMapSize());
                    }
                    else
                    {
                        Screen.WriteMapString(i, 0, messages[i + startline - 1].PadToMapSize());
                    }
                }
                B.DisplayNow("Previous messages: ");
                Screen.CursorVisible = true;
                command2             = Global.ReadKey();
                ConsoleKey ck = command2.Key;
                switch (ck)
                {
                case ConsoleKey.Backspace:
                case ConsoleKey.PageUp:
                case ConsoleKey.NumPad9:
                    ch2 = (char)8;
                    break;

                case ConsoleKey.Enter:
                    ch2 = ' ';             //hackery ahoy - enter becomes space and pagedown becomes enter.
                    break;

                case ConsoleKey.PageDown:
                case ConsoleKey.NumPad3:
                    ch2 = (char)13;
                    break;

                case ConsoleKey.Home:
                case ConsoleKey.NumPad7:
                    ch2 = '[';
                    break;

                case ConsoleKey.End:
                case ConsoleKey.NumPad1:
                    ch2 = ']';
                    break;

                default:
                    ch2 = Actor.ConvertInput(command2);
                    break;
                }
                switch (ch2)
                {
                case ' ':
                case (char)27:
                    done = true;
                    break;

                case '8':
                case '-':
                case '_':
                    if (startline > 0)
                    {
                        --startline;
                    }
                    break;

                case '2':
                case '+':
                case '=':
                    if (more)
                    {
                        ++startline;
                    }
                    break;

                case (char)8:
                    if (startline > 0)
                    {
                        startline -= 20;
                        if (startline < 0)
                        {
                            startline = 0;
                        }
                    }
                    break;

                case (char)13:
                    if (messages.Count > 20)
                    {
                        startline += 20;
                        if (startline + 20 > messages.Count)
                        {
                            startline = messages.Count - 20;
                        }
                    }
                    break;

                case '[':
                    startline = 0;
                    break;

                case ']':
                    startline = Math.Max(0, messages.Count - 20);
                    break;

                default:
                    break;
                }
            }
            if (show_footsteps && player.HasAttr(AttrType.DETECTING_MOVEMENT) && Actor.previous_footsteps.Count > 0)
            {
                M.Draw();
                Screen.AnimateMapCells(Actor.previous_footsteps, new colorchar('!', Color.Red), 150);
            }
            MouseUI.PopButtonMap();
        }
Beispiel #9
0
        public void Print(bool special_message)
        {
            Screen.CursorVisible = false;
            int idx = str.Count - 1;

            while (special_message && str[idx].Length > max_length - 7)
            {
                for (int i = max_length - 8; i >= 0; --i)
                {
                    if (str[idx].Substring(i, 1) == " ")
                    {
                        overflow = str[idx].Substring(i + 1);
                        str[idx] = str[idx].Substring(0, i + 1);
                        break;
                    }
                }
                if (overflow != "")
                {
                    Screen.ResetColors();
                    Print(false);
                    idx = str.Count - 1;
                }
            }
            foreach (string s in str)
            {
                if (s != "You regenerate. " && s != "You rest... " && s != "You breathe in the overwhelming scent of the poppies. " && s != "")                 //eventually this will become a list of ignored strings
                {
                    if (!player.HasAttr(AttrType.RESTING))
                    {
                        player.Interrupt();
                    }
                }
            }
            bool repeated_message = false;

            foreach (string s in str)
            {
                if (s != "")
                {
                    int last = (position - 1).Modulo(log_length);
                    //if(last == -1){ last = 19; }
                    string prev  = log[last];
                    string count = "1";
                    int    pos   = prev.LastIndexOf(" (x");
                    if (pos != -1)
                    {
                        count = prev.Substring(pos + 3);
                        count = count.Substring(0, count.Length - 1);
                        prev  = prev.Substring(0, pos + 1);
                    }
                    bool too_long_if_repeated = false;
                    if (prev.Length + 3 + (Convert.ToInt32(count) + 1).ToString().Length > max_length)
                    {
                        too_long_if_repeated = true;
                    }
                    if (prev == s && str.Count == 1 && !too_long_if_repeated)                     //trying this - only add the (x2) part if it's a single-line message, for ease of reading
                    {
                        if (s != "You can't move! " && s != "You're rooted to the ground! ")
                        {
                            log[last] = prev + "(x" + (Convert.ToInt32(count) + 1).ToString() + ")";                           //the immobilization messages could be confusing when repeated
                        }
                        repeated_message = true;
                    }
                    else
                    {
                        log[position] = s;
                        position      = (position + 1).Modulo(log_length);
                        if (num_messages < 1000)
                        {
                            ++num_messages;
                        }
                        //++position;
                        //if(position == 20){ position = 0; }
                        repeated_message = false;
                    }
                }
            }
            int lines = str.Count;

            if (str.Last() == "")
            {
                --lines;
            }
            for (int i = 0; i < 3; ++i)
            {
                bool old_message = true;
                if (3 - i <= lines)
                {
                    old_message = false;
                }
                if (old_message)
                {
                    Screen.WriteMapString(i - 3, 0, PreviousMessage(3 - i).PadToMapSize(), Color.DarkGray);
                    //Screen.ForegroundColor = ConsoleColor.Gray;
                }
                else
                {
                    if (repeated_message)
                    {
                        int pos = PreviousMessage(3 - i).LastIndexOf(" (x");
                        if (pos != -1)
                        {
                            Screen.WriteMapString(i - 3, 0, PreviousMessage(3 - i).Substring(0, pos));
                            Screen.WriteMapString(i - 3, pos, PreviousMessage(3 - i).Substring(pos).PadToMapSize(), Color.DarkGray);
                            //Screen.ForegroundColor = ConsoleColor.Gray;
                        }
                        else
                        {
                            Screen.WriteMapString(i - 3, 0, PreviousMessage(3 - i).PadToMapSize());
                        }
                    }
                    else
                    {
                        Screen.WriteMapString(i - 3, 0, PreviousMessage(3 - i).PadToMapSize());
                    }
                }
            }
            if (overflow != "" || special_message == true)
            {
                int cursor_col = str.Last().Length + Global.MAP_OFFSET_COLS;
                int cursor_row = Screen.CursorTop;
                if (cursor_row > 2)
                {
                    cursor_row = 2;                     //hack - attempts a quick fix for the [more] appearing at the player's row
                }
                M.Draw();
                Screen.WriteString(cursor_row, cursor_col, "[more]", Color.Yellow);
                MouseUI.PushButtonMap();
                Screen.SetCursorPosition(cursor_col + 6, cursor_row);
                //Screen.ForegroundColor = ConsoleColor.Gray;
                Screen.CursorVisible = true;
                Global.ReadKey();
                MouseUI.PopButtonMap();
            }
            str.Clear();
            str.Add("");
            string temp = overflow;

            overflow = "";
            AddToStr(temp);
        }