Exemple #1
0
 protected override void KeyDownHandler(object sender, KeyboardKeyEventArgs args)
 {
     key_down[args.Key] = true;
     if (!Global.KeyPressed)
     {
         ConsoleKey ck = Global.GetConsoleKey(args.Key);
         if (ck != ConsoleKey.NoName)
         {
             bool alt   = KeyIsDown(Key.LAlt) || KeyIsDown(Key.RAlt);
             bool shift = KeyIsDown(Key.LShift) || KeyIsDown(Key.RShift);
             bool ctrl  = KeyIsDown(Key.LControl) || KeyIsDown(Key.RControl);
             if (ck == ConsoleKey.Enter && alt)
             {
                 if (FullScreen)
                 {
                     FullScreen  = false;
                     WindowState = WindowState.Normal;
                 }
                 else
                 {
                     FullScreen  = true;
                     WindowState = WindowState.Fullscreen;
                 }
             }
             else
             {
                 Global.KeyPressed = true;
                 Global.LastKey    = new ConsoleKeyInfo(Global.GetChar(ck, shift), ck, shift, alt, ctrl);
             }
         }
         MouseUI.RemoveHighlight();
         MouseUI.RemoveMouseover();
     }
 }
Exemple #2
0
        void MouseWheelHandler(object sender, MouseWheelEventArgs args)
        {
            if (!Global.KeyPressed)
            {
                if (args.Delta > 0)
                {
                    switch (MouseUI.Mode)
                    {
                    case MouseMode.ScrollableMenu:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo('8', ConsoleKey.UpArrow, false, false, false);
                        break;

                    case MouseMode.Targeting:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo((char)9, ConsoleKey.Tab, true, false, false);
                        break;

                    case MouseMode.Map:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo((char)9, ConsoleKey.Tab, false, false, false);
                        break;
                    }
                }
                if (args.Delta < 0)
                {
                    switch (MouseUI.Mode)
                    {
                    case MouseMode.ScrollableMenu:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo('2', ConsoleKey.DownArrow, false, false, false);
                        break;

                    case MouseMode.Targeting:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo((char)9, ConsoleKey.Tab, false, false, false);
                        break;

                    case MouseMode.Map:
                        Global.KeyPressed = true;
                        Global.LastKey    = new ConsoleKeyInfo((char)9, ConsoleKey.Tab, false, false, false);
                        break;
                    }
                }
            }
            MouseUI.RemoveHighlight();
            MouseUI.RemoveMouseover();
        }
Exemple #3
0
        void HandleMiddleClick()
        {
            if (!Global.KeyPressed)
            {
                Global.KeyPressed = true;
                switch (MouseUI.Mode)
                {
                case MouseMode.Map:
                    Global.LastKey = new ConsoleKeyInfo('v', ConsoleKey.V, false, false, false);
                    break;

                default:
                    Global.LastKey = new ConsoleKeyInfo((char)27, ConsoleKey.Escape, false, false, false);
                    break;
                }
            }
            MouseUI.RemoveHighlight();
            MouseUI.RemoveMouseover();
        }
Exemple #4
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;
                }
            }
        }
Exemple #5
0
 void MouseLeaveHandler(object sender, EventArgs args)
 {
     MouseUI.RemoveHighlight();
 }
Exemple #6
0
        void MouseClickHandler(object sender, MouseButtonEventArgs args)
        {
            if (MouseUI.IgnoreMouseClicks)
            {
                return;
            }
            if (args.Button == MouseButton.Middle)
            {
                HandleMiddleClick();
                return;
            }
            if (args.Button == MouseButton.Right)
            {
                HandleRightClick();
                return;
            }
            int row;
            int col;

            if (FullScreen)
            {
                row = (int)(args.Y - ClientRectangle.Height * ((1.0f - screen_multiplier_h) * 0.5f)) / cell_h;
                col = (int)(args.X - ClientRectangle.Width * ((1.0f - screen_multiplier_w) * 0.5f)) / cell_w;
            }
            else
            {
                row = args.Y / cell_h;
                col = args.X / cell_w;
            }
            Button b = MouseUI.GetButton(row, col);

            if (!Global.KeyPressed)
            {
                Global.KeyPressed = true;
                if (b != null)
                {
                    bool shifted = (b.mods & ConsoleModifiers.Shift) == ConsoleModifiers.Shift;
                    Global.LastKey = new ConsoleKeyInfo(Global.GetChar(b.key, shifted), b.key, shifted, false, false);
                }
                else
                {
                    switch (MouseUI.Mode)
                    {
                    case MouseMode.Map:
                    {
                        int map_row = row - Global.MAP_OFFSET_ROWS;
                        int map_col = col - Global.MAP_OFFSET_COLS;
                        if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                        {
                            if (map_row == Actor.player.row && map_col == Actor.player.col)
                            {
                                Global.LastKey = new ConsoleKeyInfo('.', ConsoleKey.OemPeriod, false, false, false);
                            }
                            else
                            {
                                if (KeyIsDown(Key.LControl) || KeyIsDown(Key.RControl) || (Math.Abs(map_row - Actor.player.row) <= 1 && Math.Abs(map_col - Actor.player.col) <= 1))
                                {
                                    int rowchange = 0;
                                    int colchange = 0;
                                    if (map_row > Actor.player.row)
                                    {
                                        rowchange = 1;
                                    }
                                    else
                                    {
                                        if (map_row < Actor.player.row)
                                        {
                                            rowchange = -1;
                                        }
                                    }
                                    if (map_col > Actor.player.col)
                                    {
                                        colchange = 1;
                                    }
                                    else
                                    {
                                        if (map_col < Actor.player.col)
                                        {
                                            colchange = -1;
                                        }
                                    }
                                    ConsoleKey dir_key = (ConsoleKey)(ConsoleKey.NumPad0 + Actor.player.DirectionOf(Actor.M.tile[Actor.player.row + rowchange, Actor.player.col + colchange]));
                                    Global.LastKey = new ConsoleKeyInfo(Global.GetChar(dir_key, false), dir_key, false, false, false);
                                }
                                else
                                {
                                    Tile nearest = Actor.M.tile[map_row, map_col];
                                    Actor.player.path = Actor.player.GetPath(nearest.row, nearest.col, -1, true, true, Actor.UnknownTilePathingPreference.UnknownTilesAreOpen);
                                    if (Actor.player.path.Count > 0)
                                    {
                                        Actor.player.path.StopAtBlockingTerrain();
                                        if (Actor.player.path.Count > 0)
                                        {
                                            Actor.interrupted_path = new pos(-1, -1);
                                            ConsoleKey path_key = (ConsoleKey)(ConsoleKey.NumPad0 + Actor.player.DirectionOf(Actor.player.path[0]));
                                            Global.LastKey = new ConsoleKeyInfo(Global.GetChar(path_key, false), path_key, false, false, false);
                                            Actor.player.path.RemoveAt(0);
                                        }
                                        else
                                        {
                                            Global.LastKey = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false);
                                        }
                                    }
                                    else
                                    {
                                        //int distance_of_first_passable = -1;
                                        //List<Tile> passable_tiles = new List<Tile>();
                                        foreach (Tile t in Actor.M.TilesByDistance(map_row, map_col, true, true))
                                        {
                                            //if(distance_of_first_passable != -1 && nearest.DistanceFrom(t) > distance_of_first_passable){
                                            //nearest = passable_tiles.Last();
                                            if (t.passable)
                                            {
                                                nearest           = t;
                                                Actor.player.path = Actor.player.GetPath(nearest.row, nearest.col, -1, true, true, Actor.UnknownTilePathingPreference.UnknownTilesAreOpen);
                                                break;
                                            }

                                            /*}
                                             * if(t.passable){
                                             *      distance_of_first_passable = nearest.DistanceFrom(t);
                                             *      passable_tiles.Add(t);
                                             * }*/
                                        }
                                        if (Actor.player.path.Count > 0)
                                        {
                                            Actor.interrupted_path = new pos(-1, -1);
                                            ConsoleKey path_key = (ConsoleKey)(ConsoleKey.NumPad0 + Actor.player.DirectionOf(Actor.player.path[0]));
                                            Global.LastKey = new ConsoleKeyInfo(Global.GetChar(path_key, false), path_key, false, false, false);
                                            Actor.player.path.RemoveAt(0);
                                        }
                                        else
                                        {
                                            Global.LastKey = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Global.LastKey = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false);
                        }
                        break;
                    }

                    case MouseMode.Directional:
                    {
                        int map_row = row - Global.MAP_OFFSET_ROWS;
                        int map_col = col - Global.MAP_OFFSET_COLS;
                        if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                        {
                            int    dir   = Actor.player.DirectionOf(new pos(map_row, map_col));
                            pos    p     = Actor.player.p.PosInDir(dir);
                            Button dir_b = MouseUI.GetButton(Global.MAP_OFFSET_ROWS + p.row, Global.MAP_OFFSET_COLS + p.col);
                            if (dir_b != null)
                            {
                                bool shifted = (dir_b.mods & ConsoleModifiers.Shift) == ConsoleModifiers.Shift;
                                Global.LastKey = new ConsoleKeyInfo(Global.GetChar(dir_b.key, shifted), dir_b.key, shifted, false, false);
                            }
                        }
                        else
                        {
                            Global.LastKey = new ConsoleKeyInfo((char)27, ConsoleKey.Escape, false, false, false);
                        }
                        break;
                    }

                    case MouseMode.Targeting:
                    {
                        int map_row = row - Global.MAP_OFFSET_ROWS;
                        int map_col = col - Global.MAP_OFFSET_COLS;
                        if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                        {
                            Global.LastKey = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false);
                        }
                        else
                        {
                            Global.LastKey = new ConsoleKeyInfo((char)27, ConsoleKey.Escape, false, false, false);
                        }
                        break;
                    }

                    case MouseMode.YesNoPrompt:
                        Global.LastKey = new ConsoleKeyInfo('y', ConsoleKey.Y, false, false, false);
                        break;

                    case MouseMode.Inventory:
                        Global.LastKey = new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false);
                        break;

                    default:
                        Global.LastKey = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false);
                        break;
                    }
                }
            }
            MouseUI.RemoveHighlight();
            MouseUI.RemoveMouseover();
        }
Exemple #7
0
        void MouseMoveHandler(object sender, MouseMoveEventArgs args)
        {
            if (MouseUI.IgnoreMouseMovement)
            {
                return;
            }
            int row;
            int col;

            if (FullScreen)
            {
                row = (int)(args.Y - ClientRectangle.Height * ((1.0f - screen_multiplier_h) * 0.5f)) / cell_h;               //todo: give this its own var?
                col = (int)(args.X - ClientRectangle.Width * ((1.0f - screen_multiplier_w) * 0.5f)) / cell_w;
            }
            else
            {
                row = args.Y / cell_h;
                col = args.X / cell_w;
            }
            switch (MouseUI.Mode)
            {
            case MouseMode.Targeting:
            {
                int    map_row = row - Global.MAP_OFFSET_ROWS;
                int    map_col = col - Global.MAP_OFFSET_COLS;
                Button b       = MouseUI.GetButton(row, col);
                if (MouseUI.Highlighted != null && MouseUI.Highlighted != b)
                {
                    MouseUI.RemoveHighlight();
                }
                if (args.XDelta == 0 && args.YDelta == 0)
                {
                    return;                     //don't re-highlight immediately after a click
                }
                if (b != null)
                {
                    if (b != MouseUI.Highlighted)
                    {
                        MouseUI.Highlighted = b;
                        colorchar[,] array  = new colorchar[b.height, b.width];
                        for (int i = 0; i < b.height; ++i)
                        {
                            for (int j = 0; j < b.width; ++j)
                            {
                                array[i, j]         = Screen.Char(i + b.row, j + b.col);
                                array[i, j].bgcolor = Color.Blue;
                            }
                        }
                        Screen.UpdateGLBuffer(b.row, b.col, array);
                    }
                }
                else
                {
                    if (!Global.KeyPressed && (row != MouseUI.LastRow || col != MouseUI.LastCol) && !KeyIsDown(Key.LControl) && !KeyIsDown(Key.RControl))
                    {
                        MouseUI.LastRow   = row;
                        MouseUI.LastCol   = col;
                        Global.KeyPressed = true;
                        if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                        {
                            ConsoleKey key = ConsoleKey.F1;
                            Global.LastKey = new ConsoleKeyInfo(Global.GetChar(key, false), key, false, false, false);
                        }
                        else
                        {
                            ConsoleKey key = ConsoleKey.F2;
                            Global.LastKey = new ConsoleKeyInfo(Global.GetChar(key, false), key, false, false, false);
                        }
                    }
                }
                break;
            }

            case MouseMode.Directional:
            {
                int map_row = row - Global.MAP_OFFSET_ROWS;
                int map_col = col - Global.MAP_OFFSET_COLS;
                if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                {
                    int    dir   = Actor.player.DirectionOf(new pos(map_row, map_col));
                    pos    p     = Actor.player.p.PosInDir(dir);
                    Button dir_b = MouseUI.GetButton(Global.MAP_OFFSET_ROWS + p.row, Global.MAP_OFFSET_COLS + p.col);
                    if (MouseUI.Highlighted != null && MouseUI.Highlighted != dir_b)
                    {
                        MouseUI.RemoveHighlight();
                    }
                    if (dir_b != null && dir_b != MouseUI.Highlighted)
                    {
                        MouseUI.Highlighted = dir_b;
                        colorchar[,] array  = new colorchar[1, 1];
                        array[0, 0]         = Screen.Char(Global.MAP_OFFSET_ROWS + p.row, Global.MAP_OFFSET_COLS + p.col);
                        array[0, 0].bgcolor = Color.Blue;
                        Screen.UpdateGLBuffer(dir_b.row, dir_b.col, array);
                    }
                }
                else
                {
                    if (MouseUI.Highlighted != null)
                    {
                        MouseUI.RemoveHighlight();
                    }
                }
                break;
            }

            default:
            {
                Button b = MouseUI.GetButton(row, col);
                if (MouseUI.Highlighted != null && MouseUI.Highlighted != b)
                {
                    MouseUI.RemoveHighlight();
                }
                if (args.XDelta == 0 && args.YDelta == 0)
                {
                    return;                     //don't re-highlight immediately after a click
                }
                if (b != null && b != MouseUI.Highlighted)
                {
                    MouseUI.Highlighted = b;
                    colorchar[,] array  = new colorchar[b.height, b.width];
                    for (int i = 0; i < b.height; ++i)
                    {
                        for (int j = 0; j < b.width; ++j)
                        {
                            array[i, j]         = Screen.Char(i + b.row, j + b.col);
                            array[i, j].bgcolor = Color.Blue;
                        }
                    }
                    Screen.UpdateGLBuffer(b.row, b.col, array);

                    /*for(int i=b.row;i<b.row+b.height;++i){
                     *      for(int j=b.col;j<b.col+b.width;++j){
                     *              colorchar cch = Screen.Char(i,j);
                     *              cch.bgcolor = Color.Blue;
                     *              UpdateVertexArray(i,j,cch.c,ConvertColor(cch.color),ConvertColor(cch.bgcolor));
                     *      }
                     * }*/
                }
                else
                {
                    if (MouseUI.Mode == MouseMode.Map)
                    {
                        int            map_row = row - Global.MAP_OFFSET_ROWS;
                        int            map_col = col - Global.MAP_OFFSET_COLS;
                        PhysicalObject o       = null;
                        if (map_row >= 0 && map_row < Global.ROWS && map_col >= 0 && map_col < Global.COLS)
                        {
                            o = MouseUI.mouselook_objects[map_row, map_col];
                            if (MouseUI.VisiblePath && o == null)
                            {
                                o = Actor.M.tile[map_row, map_col];
                            }
                        }
                        if (MouseUI.mouselook_current_target != null && MouseUI.mouselook_current_target != o)
                        {
                            MouseUI.RemoveMouseover();
                        }
                        if (o != null && o != MouseUI.mouselook_current_target)
                        {
                            MouseUI.mouselook_current_target = o;
                            bool description_on_right = false;

                            /*int max_length = 29;
                             * if(map_col - 6 < max_length){
                             *      max_length = map_col - 6;
                             * }
                             * if(max_length < 20){
                             *      description_on_right = true;
                             *      max_length = 29;
                             * }*/
                            int max_length = MouseUI.MaxDescriptionBoxLength;
                            if (map_col <= 32)
                            {
                                description_on_right = true;
                            }
                            List <colorstring> desc_box = null;
                            Actor a = o as Actor;
                            if (a != null)
                            {
                                desc_box = Actor.MonsterDescriptionBox(a, true, max_length);
                            }
                            else
                            {
                                Item i = o as Item;
                                if (i != null)
                                {
                                    desc_box = Actor.ItemDescriptionBox(i, true, true, max_length);
                                }
                            }
                            if (desc_box != null)
                            {
                                int h        = desc_box.Count;
                                int w        = desc_box[0].Length();
                                int player_r = Actor.player.row;
                                int player_c = Actor.player.col;
                                colorchar[,] array = new colorchar[h, w];
                                if (description_on_right)
                                {
                                    for (int i = 0; i < h; ++i)
                                    {
                                        for (int j = 0; j < w; ++j)
                                        {
                                            array[i, j] = desc_box[i][j];
                                            if (i == player_r && j + Global.COLS - w == player_c)
                                            {
                                                Screen.CursorVisible = false;
                                                player_r             = -1;                                     //to prevent further attempts to set CV to false
                                            }
                                        }
                                    }
                                    Screen.UpdateGLBuffer(Global.MAP_OFFSET_ROWS, Global.MAP_OFFSET_COLS + Global.COLS - w, array);
                                }
                                else
                                {
                                    for (int i = 0; i < h; ++i)
                                    {
                                        for (int j = 0; j < w; ++j)
                                        {
                                            array[i, j] = desc_box[i][j];
                                            if (i == player_r && j == player_c)
                                            {
                                                Screen.CursorVisible = false;
                                                player_r             = -1;
                                            }
                                        }
                                    }
                                    Screen.UpdateGLBuffer(Global.MAP_OFFSET_ROWS, Global.MAP_OFFSET_COLS, array);
                                }
                            }
                            if (MouseUI.VisiblePath)
                            {
                                MouseUI.mouse_path = Actor.player.GetPath(o.row, o.col, -1, true, true, Actor.UnknownTilePathingPreference.UnknownTilesAreOpen);
                                if (MouseUI.mouse_path.Count == 0)
                                {
                                    foreach (Tile t in Actor.M.TilesByDistance(o.row, o.col, true, true))
                                    {
                                        if (t.passable)
                                        {
                                            MouseUI.mouse_path = Actor.player.GetPath(t.row, t.col, -1, true, true, Actor.UnknownTilePathingPreference.UnknownTilesAreOpen);
                                            break;
                                        }
                                    }
                                }
                                pos box_start = new pos(0, 0);
                                int box_h     = -1;
                                int box_w     = -1;
                                if (desc_box != null)
                                {
                                    box_h = desc_box.Count;
                                    box_w = desc_box[0].Length();
                                    if (description_on_right)
                                    {
                                        box_start = new pos(0, Global.COLS - box_w);
                                    }
                                }
                                foreach (pos p in MouseUI.mouse_path)
                                {
                                    if (desc_box != null && p.row < box_start.row + box_h && p.row >= box_start.row && p.col < box_start.col + box_w && p.col >= box_start.col)
                                    {
                                        continue;
                                    }
                                    colorchar cch = Screen.MapChar(p.row, p.col);
                                    cch.bgcolor = Color.DarkGreen;
                                    if (cch.color == Color.DarkGreen)
                                    {
                                        cch.color = Color.Black;
                                    }
                                    //Game.gl.UpdateVertexArray(p.row+Global.MAP_OFFSET_ROWS,p.col+Global.MAP_OFFSET_COLS,text_surface,0,(int)cch.c);
                                    Game.gl.UpdateVertexArray(p.row + Global.MAP_OFFSET_ROWS, p.col + Global.MAP_OFFSET_COLS, text_surface, 0, (int)cch.c, cch.color.GetFloatValues(), cch.bgcolor.GetFloatValues());
                                }
                                if (MouseUI.mouse_path != null && MouseUI.mouse_path.Count == 0)
                                {
                                    MouseUI.mouse_path = null;
                                }
                            }
                        }
                    }
                }
                break;
            }
            }
        }
        public static void ShowKnownItems(Hash <ConsumableType> IDed)
        {
            MouseUI.PushButtonMap();
            UI.draw_bottom_commands = false;
            UI.darken_status_bar    = true;
            const 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[]         names      = new string[2];
                    Color[]          ided_color = new Color[2];
                    for (int i = 0; i < 2; ++i)
                    {
                        ct[i]    = item_list[item_idx + i];
                        names[i] = ct[i].ToString()[0] + ct[i].ToString().Substring(1).ToLower();
                        names[i] = names[i].Replace('_', ' ');
                        if (IDed[ct[i]])
                        {
                            ided_color[i] = Color.Cyan;
                        }
                        else
                        {
                            ided_color[i] = Color.DarkGray;
                        }
                    }
                    int num_spaces = width - (names[0].Length + names[1].Length);
                    string_lists[list_idx].Add(new colorstring(names[0], ided_color[0], "".PadRight(num_spaces), Color.Black, names[1], ided_color[1]));
                    item_idx += 2;
                }
                if (item_list.Count % 2 == 1)
                {
                    ConsumableType ct = item_list.Last();
                    string         n  = (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 - n.Length;
                    string_lists[list_idx].Add(new colorstring(n, ided_color, "".PadRight(num_spaces), Color.Black));
                }
                ++list_idx;
            }
            Screen.WriteMapString(0, 0, "".PadRight(COLS, '-'));
            for (int i = 1; i < ROWS + 2; ++i)
            {
                Screen.WriteMapString(i, 0, "".PadToMapSize());
            }
            Screen.WriteMapString(ROWS + 2, 0, "".PadRight(COLS, '-'));
            const Color label_color          = Color.Yellow;
            const int   first_column_offset  = 2;
            const int   second_column_offset = first_column_offset + 35;
            const int   first_item_row       = 4;

            Screen.WriteMapString(first_item_row - 1, 8 + first_column_offset, "- Potions -", label_color);
            Screen.WriteMapString(first_item_row - 1, 7 + second_column_offset, "- Scrolls -", label_color);
            int line = first_item_row;

            foreach (colorstring s in potions)
            {
                Screen.WriteMapString(line, first_column_offset, s);
                ++line;
            }
            line = first_item_row;
            foreach (colorstring s in scrolls)
            {
                Screen.WriteMapString(line, second_column_offset, s);
                ++line;
            }
            const int second_item_row = first_item_row + 11;

            Screen.WriteMapString(second_item_row - 1, 9 + first_column_offset, "- Orbs -", label_color);
            Screen.WriteMapString(second_item_row - 1, 8 + second_column_offset, "- Wands -", label_color);
            line = second_item_row;
            foreach (colorstring s in orbs)
            {
                Screen.WriteMapString(line, first_column_offset, s);
                ++line;
            }
            line = second_item_row;
            foreach (colorstring s in wands)
            {
                Screen.WriteMapString(line, second_column_offset, s);
                ++line;
            }
            UI.Display("Discovered item types: ");
            Input.ReadKey();
            MouseUI.PopButtonMap();
            UI.draw_bottom_commands = true;
            UI.darken_status_bar    = false;
        }
        public static void ShowPreviousMessages(bool show_footsteps)
        {
            const int     text_height = Global.ROWS + 1;
            List <string> messages    = B.GetMessageLog();

            MouseUI.PushButtonMap(MouseMode.ScrollableMenu);
            UI.draw_bottom_commands = false;
            UI.darken_status_bar    = true;
            MouseUI.CreateMapButton(ConsoleKey.OemMinus, false, 0, 1);
            MouseUI.CreateMapButton(ConsoleKey.OemPlus, false, text_height + 1, 1);
            Screen.WriteMapString(0, 0, "".PadRight(COLS, '-'));
            Screen.WriteMapString(text_height + 1, 0, "".PadRight(COLS, '-'));
            ConsoleKeyInfo command;
            char           ch;
            int            startline = Math.Max(0, messages.Count - text_height);

            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 + text_height < messages.Count)
                {
                    more = true;
                }
                if (more)
                {
                    Screen.WriteMapString(text_height + 1, COLS - 3, new colorstring("[", Color.Yellow, "+", Color.Cyan, "]", Color.Yellow));
                }
                else
                {
                    Screen.WriteMapString(text_height + 1, COLS - 3, "---");
                }
                for (int i = 1; i <= text_height; ++i)
                {
                    if (messages.Count - startline < i)
                    {
                        Screen.WriteMapString(i, 0, "".PadToMapSize());
                    }
                    else
                    {
                        Screen.WriteMapString(i, 0, messages[i + startline - 1].PadToMapSize());
                    }
                }
                UI.Display("Previous messages: ");
                command = Input.ReadKey();
                ConsoleKey ck = command.Key;
                switch (ck)
                {
                case ConsoleKey.Backspace:
                case ConsoleKey.PageUp:
                case ConsoleKey.NumPad9:
                    ch = (char)8;
                    break;

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

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

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

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

                default:
                    ch = command.GetCommandChar();
                    break;
                }
                switch (ch)
                {
                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 -= text_height;
                        if (startline < 0)
                        {
                            startline = 0;
                        }
                    }
                    break;

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

                case '[':
                    startline = 0;
                    break;

                case ']':
                    startline = Math.Max(0, messages.Count - text_height);
                    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();
            UI.draw_bottom_commands = true;
            UI.darken_status_bar    = false;
        }
        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();
        }
Exemple #11
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);
        }
 public static void CreatePlayerStatsButtons()
 {
     if (Mode != MouseMode.Map)
     {
         return;
     }
     ConsoleKey[] keys    = new ConsoleKey[] { ConsoleKey.C, ConsoleKey.E, ConsoleKey.M };
     int[]        rows    = new int[] { 0, UI.equipment_row, UI.depth_row };
     int[]        heights = new int[] { UI.equipment_row, UI.depth_row - UI.equipment_row, UI.status_row_start - UI.depth_row - 1 };
     if (MouseUI.GetButton(0, 0) == null)            // if there's no button here, assume that there are no buttons in this area at all.
     {
         for (int n = 0; n < 3; ++n)
         {
             if (rows[n] + heights[n] > UI.status_row_cutoff)
             {
                 return;
             }
             CreateStatsButton(keys[n], false, rows[n], heights[n]);
         }
     }
     else
     {
         bool all_found = false;
         for (int n = 0; n < 3; ++n)
         {
             if (heights[n] <= 0 || rows[n] + heights[n] > UI.status_row_cutoff)
             {
                 break;
             }
             Button b = MouseUI.GetButton(rows[n], 0);
             if (b != null && b.key == keys[n] && b.row == rows[n] && b.height == heights[n])                     //perfect match, keep it there.
             {
                 if (b.key == ConsoleKey.M)
                 {
                     all_found = true;
                 }
             }
             else
             {
                 for (int i = rows[n]; i < rows[n] + heights[n]; ++i)
                 {
                     Button b2 = MouseUI.GetButton(i, 0);
                     if (b2 != null)
                     {
                         if (b2.key == ConsoleKey.M)
                         {
                             all_found = true;
                         }
                         MouseUI.RemoveButton(b2);
                     }
                 }
                 CreateStatsButton(keys[n], false, rows[n], heights[n]);
             }
         }
         if (!all_found)
         {
             for (int i = rows[2] + heights[2]; i <= UI.status_row_cutoff; ++i) //gotta continue downward until all the previous
             {
                 Button b = MouseUI.GetButton(i, 0);                            // buttons have been accounted for.
                 if (b != null)
                 {
                     MouseUI.RemoveButton(b);
                     if (b.key == ConsoleKey.M)
                     {
                         break;
                     }
                 }
             }
         }
     }
 }
        protected void DisplayLines(List <string> lines, bool morePrompt, bool addToLog)
        {
            for (int i = 0; i < lines.Count; ++i)
            {
                lines[i] = RemoveTrailingSpaces(lines[i]);
            }
            bool repeated   = false;
            bool printCount = true;

            if (lines.Count == 1 && log.Count > 0)
            {
                string last             = GetPreviousMessage(0);
                string lastWithoutCount = last;
                if (repetitionCount > 0)
                {
                    int repIdx = last.LastIndexOf(" (x" + (repetitionCount + 1) + ")");
                    if (repIdx != -1)
                    {
                        lastWithoutCount = last.Substring(0, repIdx);
                    }
                }
                if (lines[0] == lastWithoutCount)                  //if the new line matches the last one, verify that there's room for the (xN)
                {
                    repeated = true;
                    if (HideRepeatCountStrings.Contains(lastWithoutCount))
                    {
                        printCount = false;
                    }
                    else
                    {
                        int max = MaxLength;
                        if (morePrompt)
                        {
                            max -= more.Length;
                        }
                        if ((lastWithoutCount + " (x" + (repetitionCount + 2) + ")").Length > max)
                        {
                            repeated = false;
                        }
                    }
                }
            }
            int numPrev      = NumLines - lines.Count;
            int prevStartIdx = numPrev - 1;

            if (repeated)
            {
                prevStartIdx++;
            }
            for (int i = 0; i < numPrev; ++i)
            {
                Screen.WriteString(i, Global.MAP_OFFSET_COLS, GetPreviousMessage(prevStartIdx - i).PadToMapSize(), Color.DarkGray);
            }
            if (lines.Count == 0)
            {
                return;
            }
            for (int i = 0; i < lines.Count; ++i)
            {
                Screen.WriteString(i + numPrev, Global.MAP_OFFSET_COLS, lines[i].PadToMapSize());
            }
            int extraIdx = lines[lines.Count - 1].Length + Global.MAP_OFFSET_COLS;

            if (repeated)
            {
                if (printCount)
                {
                    string xCount = " (x" + (repetitionCount + 2) + ")";
                    Screen.WriteString(NumLines - 1, extraIdx, xCount, Color.DarkGray);
                    extraIdx += xCount.Length;
                    if (addToLog)
                    {
                        log[log.Count - 1] = lines[lines.Count - 1] + xCount;
                    }
                }
                if (addToLog)
                {
                    ++repetitionCount;
                }
            }
            else
            {
                if (addToLog)
                {
                    repetitionCount = 0;
                    AddToLog(lines);
                }
            }
            if (morePrompt)
            {
                Screen.WriteString(NumLines - 1, extraIdx, more, Color.Yellow);
                MouseUI.PushButtonMap();
                Screen.SetCursorPosition(extraIdx + more.Length - 1, NumLines - 1);
                Input.ReadKey();
                MouseUI.PopButtonMap();
            }
        }