Refactored scroll dimensions, fixed a crash were you would click on non existent tiles, editor now displays splash initially until you do new scenario or load a existing one.

This commit is contained in:
Justin Marshall
2020-07-17 20:17:49 -07:00
parent c48fc9723a
commit 8353b2c1dd
12 changed files with 103 additions and 21 deletions
+27 -7
View File
@@ -567,16 +567,33 @@ void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height)
if (height == -1) height = SeenBuff.Get_Height();
TacLeptonHeight = Pixel_To_Lepton(height - y) * 4;
// Set our min/max viewport rectangle.
TacViewportRect.Clear();
TacViewportRect.AddPoint(0, 0); // Top Corner
TacViewportRect.AddPoint(TacLeptonWidth, TacLeptonHeight / 4);
TacViewportRect.AddPoint(-TacLeptonWidth, TacLeptonHeight / 4);
TacViewportRect.AddPoint(0, TacLeptonHeight / 2);
{
int iso_x_offset = (ScreenWidth / 2);
int iso_y_offset = (ScreenWidth / 4);
TacViewportRect.X -= Pixel_To_Lepton(iso_x_offset);
TacViewportRect.Y -= Pixel_To_Lepton(iso_y_offset);
TacViewportRect.X2 -= Pixel_To_Lepton(iso_x_offset);
TacViewportRect.Y2 -= Pixel_To_Lepton(iso_y_offset);
}
/*
** Adjust the tactical cell if it is now in an invalid position
** because of the changed dimensions.
*/
// jmarshall - todo, this was a great feature, if the designer clampped the map and the starting point was outside, this essentially fixed that.
int xx = Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W);
int yy = Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H);
Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
//
//Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
//
Set_Tactical_Position(XY_Coord(xx + (MapCellX * CELL_LEPTON_W), yy + (MapCellY * CELL_LEPTON_H)));
// jmarshall end
TacPixelX = x;
TacPixelY = y;
@@ -1224,7 +1241,11 @@ 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)*1.25, Cell_To_Lepton(MapCellHeight)*1.25);
if (!TacViewportRect.ContainsPoint(xx, yy)) {
return false;
}
bool shifted = true; // 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;
@@ -4819,9 +4840,7 @@ void DisplayClass::Read_INI(CCINIClass & ini)
** Set the starting position (do this after Init(), which clears the cells'
** IsWaypoint flags).
*/
if (Scen.Waypoint[WAYPT_HOME] == -1) {
Scen.Waypoint[WAYPT_HOME] = XY_Cell(MapCellX + 5*RESFACTOR, MapCellY + 4*RESFACTOR);
}
Scen.Waypoint[WAYPT_HOME] = ini.Get_Int(name, "HomeCell");
Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = Scen.Waypoint[WAYPT_HOME];
Set_Tactical_Position(Cell_Coord((Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR)) - (5*RESFACTOR)));
@@ -4889,6 +4908,7 @@ void DisplayClass::Write_INI(CCINIClass & ini)
ini.Put_Int(NAME, "Y", MapCellY);
ini.Put_Int(NAME, "Width", MapCellWidth);
ini.Put_Int(NAME, "Height", MapCellHeight);
ini.Put_Int(NAME, "HomeCell", Scen.Waypoint[WAYPT_HOME]);
/*
** Save the Waypoint entries.
+2
View File
@@ -79,6 +79,8 @@ class DisplayClass: public MapClass
LEPTON TacLeptonWidth;
LEPTON TacLeptonHeight;
Rect TacViewportRect;
/*
** These layer control elements are used to group the displayable objects
** so that proper overlap can be obtained.
+1
View File
@@ -72,6 +72,7 @@ extern bool Debug_Flag;
extern bool Debug_Lose;
extern bool Debug_SkipBriefing;
extern bool Debug_Map;
extern bool Debug_RenderEditorSplash;
extern bool Debug_Win;
extern bool Debug_Icon;
extern bool Debug_Passable;
+1
View File
@@ -44,6 +44,7 @@ bool Debug_Icon = false;
bool Debug_Flag = true;
bool Debug_Lose = false;
bool Debug_SkipBriefing = false;
bool Debug_RenderEditorSplash = false;
bool Debug_Win = false;
bool Debug_Map = false; // true = map editor mode
bool Debug_Passable = false; // true = show passable/impassable terrain
+1 -7
View File
@@ -1309,17 +1309,11 @@ bool Select_Game(bool fade)
PlayerPtr = HouseClass::As_Pointer(HOUSE_SPAIN);
PlayerPtr->IsHuman = true;
Base.House = HOUSE_USSR;
//LastHouse = HOUSE_GOOD;
Fill_In_Data();
//Size_Map(-1, -1, 30, 30);
Scen.Waypoint[WAYPT_REINF] = XY_Cell(Map.MapCellX + Map.MapCellWidth / 2, Map.MapCellY + Map.MapCellHeight / 2);
Scen.Waypoint[WAYPT_HOME] = XY_Cell(Map.MapCellX + Map.MapCellWidth / 2, Map.MapCellY + Map.MapCellHeight / 2);
// (*this)[TacticalCoord].IsWaypoint = 1;
Map.Flag_Cell(Coord_Cell(Map.TacticalCoord));
Map.Set_Tactical_Position(Cell_Coord(Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR) - (5 * RESFACTOR)));
Go_Editor(true);
process = false;
Debug_SkipBriefing = true;
Debug_RenderEditorSplash = true;
#else
Theme.Fade_Out();
+9 -4
View File
@@ -1605,7 +1605,8 @@ void MapEditClass::Main_Menu(void)
if (New_Scenario()==0) {
Scen.CarryOverMoney = 0;
Changed = 1;
}
Debug_RenderEditorSplash = false;
}
process = false;
break;
@@ -1629,7 +1630,8 @@ void MapEditClass::Main_Menu(void)
if (Load_Scenario()==0) {
Scen.CarryOverMoney = 0;
Changed = 0;
}
Debug_RenderEditorSplash = false;
}
process = false;
break;
@@ -1637,8 +1639,11 @@ void MapEditClass::Main_Menu(void)
** Save scenario
*/
case 2:
if (Save_Scenario() == 0) {
Changed = 0;
if (!Debug_RenderEditorSplash)
{
if (Save_Scenario() == 0) {
Changed = 0;
}
}
process = false;
break;
+3
View File
@@ -77,6 +77,9 @@ int MapEditClass::Select_Object(void)
** Get cell for x,y
*/
cell = Click_Cell_Calc(x, y);
if(cell == -1) {
return -1;
}
/*
** Convert x,y to offset from cell upper-left
+44 -2
View File
@@ -35,9 +35,9 @@
* Rect::Intersect -- Find the intersection between two rectangles. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
#include "rect.h"
#include <limits.h>
/***********************************************************************************************
* Rect::Rect -- Constructs a rectangle object. *
@@ -168,6 +168,48 @@ Rect const Rect::Intersect(Rect const & rectangle, int * x, int * y) const
return(r);
}
void Rect::Clear(void)
{
X = INT_MAX;
Y = INT_MAX;
X2 = -INT_MAX;
Y2 = -INT_MAX;
Width = INT_MAX;
Height = INT_MAX;
}
void Rect::AddPoint(int xin, int yin)
{
if(xin < X) {
X = xin;
}
if(xin > X2) {
X2 = xin;
}
if (yin < Y) {
Y = yin;
}
if (yin > Y2) {
Y2 = yin;
}
Width = X2 - X;
Height = Y2 - Y;
}
bool Rect::ContainsPoint(int x, int y)
{
if (x < X || y < Y || x > X2 || y > Y2) {
return false;
}
return true;
}
void Rect::AddIsoPoint(int x, int y)
{
CellClass::ConvertCoordsToIsometric(x, y);
AddPoint(x, y);
}
Rect const Union(Rect const & rect1, Rect const & rect2)
{
+8
View File
@@ -61,14 +61,22 @@ class Rect
bool Is_Valid(void) const;
int Size(void) const {return(Width*Height);}
void Clear(void);
void AddPoint(int x, int y);
void AddIsoPoint(int x, int y);
bool ContainsPoint(int x, int y);
// private:
int X;
int Y;
int X2;
int Y2;
int Width;
int Height;
};
#endif
+6
View File
@@ -38,6 +38,12 @@ void SidebarEditor::draw_it(void) {
ImGuiStyle& style = ImGui::GetStyle();
style.FramePadding = ImVec2(0, 0);
if (Debug_RenderEditorSplash)
{
static Image_t* edwinBackground = Image_LoadImage("ui/edwin/eng_edhi.png");
GL_RenderImage(edwinBackground, 0, 0, ScreenWidth, ScreenHeight);
}
Debug_LockScroll = false;
if (ImGui::BeginMainMenuBar())
{