From cd6446d58a535bc06e30d342d9cb4b2e4566fd70 Mon Sep 17 00:00:00 2001 From: nev6502 Date: Wed, 8 Jul 2020 00:58:13 -0600 Subject: [PATCH] Improved Scrolling, Large Map Handling - Bugfix in MapClass::Overpass when placing objects while scrolled all the way up / left on a larger map - Disabled a check in DisplayClass::Set_Cursor_Pos preventing mouse cell coordinates from being updated while scrolled all the way up / left on a larger map - Added (disabled) function to display mouse/cell position - Improved mouse scroll region (but still work to be done) --- code/redalert/display.cpp | 18 +++++++++++------- code/redalert/map.cpp | 3 ++- code/redalert/mapedit.cpp | 7 +++++++ code/redalert/scroll.cpp | 38 +++++++++++++++++++++----------------- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/code/redalert/display.cpp b/code/redalert/display.cpp index 61af377..079d256 100644 --- a/code/redalert/display.cpp +++ b/code/redalert/display.cpp @@ -863,8 +863,10 @@ CELL DisplayClass::Set_Cursor_Pos(CELL pos) int x = Cell_X(pos + ZoneOffset); int y = Cell_Y(pos + ZoneOffset); - if (x < Coord_XCell(TacticalCoord)) x = Coord_XCell(TacticalCoord); - if (y < Coord_YCell(TacticalCoord)) y = Coord_YCell(TacticalCoord); + + // JJ TODO: This code appears to prevent object placement in the scenario editor when scrolled to the top of a large map + //if (x < Coord_XCell(TacticalCoord)) x = Coord_XCell(TacticalCoord); + //if (y < Coord_YCell(TacticalCoord)) y = Coord_YCell(TacticalCoord); if (x+w >= Coord_XCell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)) x = Coord_XCell(TacticalCoord)+Lepton_To_Cell(TacLeptonWidth)-w; if (y+h >= Coord_YCell(TacticalCoord) + Lepton_To_Cell(TacLeptonHeight)) y = Coord_YCell(TacticalCoord)+Lepton_To_Cell(TacLeptonHeight)-h; pos = XY_Cell(x, y) - ZoneOffset; @@ -1190,6 +1192,8 @@ bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really) ** If the distance is invalid then no further checking is required. Bail ** with a no-can-do flag. */ + + if (distance == 0) return(false); FacingType crude = Dir_Facing(facing); @@ -1201,11 +1205,11 @@ bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really) if (crude == FACING_NW) facing = DIR_W; if (crude == FACING_NE) facing = DIR_E; } - if (Coord_X(TacticalCoord) + TacLeptonWidth == Cell_To_Lepton(MapCellX+MapCellWidth) && crude != FACING_E) { + if (Coord_X(TacticalCoord) + TacLeptonWidth == Cell_To_Lepton(MapCellX+(MapCellWidth*1.25)) && crude != FACING_E) { if (crude == FACING_NE) facing = DIR_N; if (crude == FACING_SE) facing = DIR_S; } - if (Coord_Y(TacticalCoord) + TacLeptonHeight == Cell_To_Lepton(MapCellY+MapCellHeight) && crude != FACING_S) { + if (Coord_Y(TacticalCoord) + TacLeptonHeight == Cell_To_Lepton(MapCellY+(MapCellHeight*1.25)) && crude != FACING_S) { if (crude == FACING_SE) facing = DIR_E; if (crude == FACING_SW) facing = DIR_W; } @@ -1220,7 +1224,7 @@ bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really) */ int xx = (int)(short)Coord_X(coord) - (short)Cell_To_Lepton(MapCellX); int yy = (int)(short)Coord_Y(coord) - (short)Cell_To_Lepton(MapCellY); - bool shifted = Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth), Cell_To_Lepton(MapCellHeight)); + bool shifted = Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth)*1.25, Cell_To_Lepton(MapCellHeight)*1.25); if (xx < 0) { xx = 0; shifted = true; @@ -3500,7 +3504,7 @@ void DisplayClass::Mouse_Right_Press(void) PendingObjectPtr = 0; PendingObject = 0; PendingHouse = HOUSE_NONE; - Set_Cursor_Shape(0); + //Set_Cursor_Shape(0); } else { if (IsRepairMode) { IsRepairMode = false; @@ -4255,7 +4259,7 @@ void DisplayClass::Set_Tactical_Position(COORDINATE coord) int yy = (int)Coord_Y(coord) - (int)Cell_To_Lepton(MapCellY); // Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth) + GlyphXClientSidebarWidthInLeptons, Cell_To_Lepton(MapCellHeight)); // Needed to accomodate Glyphx client sidebar. ST - 4/12/2019 5:29PM - Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth), Cell_To_Lepton(MapCellHeight)); + //Confine_Rect(&xx, &yy, 0, 0, Cell_To_Lepton(MapCellWidth*2), Cell_To_Lepton(MapCellHeight*2)); coord = XY_Coord(xx + Cell_To_Lepton(MapCellX), yy + Cell_To_Lepton(MapCellY)); if (ScenarioInit) { diff --git a/code/redalert/map.cpp b/code/redalert/map.cpp index 7197c9d..9b4e50b 100644 --- a/code/redalert/map.cpp +++ b/code/redalert/map.cpp @@ -880,7 +880,8 @@ long MapClass::Overpass(void) */ for (int y = 0; y < MapCellHeight; y++) { for (int x = 0; x < MapCellWidth; x++) { - CELL cell = (MapCellY+y) * MAP_CELL_W + (MapCellX+x); + //CELL cell = (MapCellY+y) * MAP_CELL_W + (MapCellX+x); + CELL cell = XY_Cell(x,y); // Replaced because a crash was being caused value += (*this)[cell].Tiberium_Adjust(true); (*this)[cell].Recalc_Attributes(); } diff --git a/code/redalert/mapedit.cpp b/code/redalert/mapedit.cpp index f4a5974..c74fb02 100644 --- a/code/redalert/mapedit.cpp +++ b/code/redalert/mapedit.cpp @@ -534,6 +534,13 @@ void MapEditClass::AI(KeyNumType & input, int x, int y) /* ** Check for mouse motion while left button is down. */ + + //Draw mouse cell position (CellX/CellY) + //CELL template_cell = (ZoneCell + ZoneOffset); + //char tmp[12]; + //sprintf(tmp, "%d , %d", Cell_X(template_cell), Cell_Y(template_cell)); + //GL_DrawText(6, 64, 64, tmp); + rc = Mouse_Moved(); if (Keyboard->Down(KN_LMOUSE) && rc) { diff --git a/code/redalert/scroll.cpp b/code/redalert/scroll.cpp index 0ad225f..05db10f 100644 --- a/code/redalert/scroll.cpp +++ b/code/redalert/scroll.cpp @@ -105,7 +105,11 @@ void ScrollClass::AI(KeyNumType &input, int x, int y) bool noscroll = false; if (!noscroll) { - bool at_screen_edge = (y == 0 || x == 0 || x >= SeenBuff.Get_Width()-1 || y >= SeenBuff.Get_Height()-1); + + int screen_width = SeenBuff.Get_Width(); + int screen_height = SeenBuff.Get_Height(); + + bool at_screen_edge = (y == 0 || x == 0 || x >= screen_width - 1 || y >= screen_height - 1); /* ** Verify that the mouse is over a scroll region. @@ -113,28 +117,28 @@ void ScrollClass::AI(KeyNumType &input, int x, int y) if (Inertia || at_screen_edge) { if (at_screen_edge) { - player_scrolled=true; + player_scrolled = true; + + int half_screen_width = screen_width / 2; + int half_screen_height = screen_height / 2; /* ** Adjust the mouse coordinates to emphasize the ** cardinal directions over the diagonals. */ - int altx = x; - if (altx < 50 * RESFACTOR) altx -= ((50 * RESFACTOR)-altx); + int altx = y; + if (altx < (50)) altx -= (50) - altx; altx = max(altx, 0); - if (altx > ((320-50) * RESFACTOR)) altx += altx-((320-50) * RESFACTOR); - altx = min(altx, (320 * RESFACTOR)); - if (altx > (50 * RESFACTOR) && altx < ((320-50) * RESFACTOR)) { - altx += (((320/2) * RESFACTOR)-altx)/2; - } + if (altx > ((half_screen_width - 50))) altx += altx - ((half_screen_width - 50)); + altx = min(altx, screen_width); int alty = y; - if (alty < (50 * RESFACTOR)) alty -= (50 * RESFACTOR)-alty; + if (alty < (50)) alty -= (50) - alty; alty = max(alty, 0); - if (alty > (150 * RESFACTOR)) alty += alty-(150 * RESFACTOR); - alty = min(alty, 200 * RESFACTOR); + if (alty > ((half_screen_height - 50))) alty += alty - ((half_screen_height - 50)); + alty = min(alty, screen_height); - direction = (DirType)Desired_Facing256((320/2) * RESFACTOR, (200/2) * RESFACTOR, altx, alty); + direction = (DirType)Desired_Facing256((half_screen_width), (half_screen_height), x, y); } int control = Dir_Facing(direction); @@ -168,9 +172,9 @@ void ScrollClass::AI(KeyNumType &input, int x, int y) /* ** Increase the scroll rate if the mouse button is held down. */ - // if (Keyboard->Down(KN_LMOUSE)) { - // rate = Bound(rate-3, 0, 4); - // } + // if (Keyboard->Down(KN_LMOUSE)) { + // rate = Bound(rate-3, 0, 4); + // } if (Keyboard->Down(KN_RMOUSE)) { rate = Bound(rate+1, 4, (int)(sizeof(_rate)/sizeof(_rate[0]))-1); } @@ -180,7 +184,7 @@ void ScrollClass::AI(KeyNumType &input, int x, int y) ** one of the 8 facings, then adjust the direction value ** accordingly. */ - direction = Facing_Dir(Dir_Facing(direction)); + direction = Facing_Dir(Dir_Facing(direction)) - (1<<5); int distance = _rate[rate]/2;