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; } } }
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(); }
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; } } } } } }