Placement Dialog now places objects in proper isometric space.

This commit is contained in:
Justin Marshall
2020-06-27 14:00:13 -07:00
parent 0189929957
commit 132071e39b
6 changed files with 96 additions and 52 deletions
+55 -3
View File
@@ -999,6 +999,47 @@ bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_d
return false;
}
void CellClass::ConvertCoordsToIsometric(int& x, int& y) {
int tileWidth = CELL_PIXEL_W;
int tileHeight = CELL_PIXEL_H;
int sx = (x / CELL_PIXEL_W) * (tileWidth / 2) - (y / CELL_PIXEL_W) * (tileWidth / 2);
int sy = (x / CELL_PIXEL_W) * (tileHeight / 2) + (y / CELL_PIXEL_W) * (tileHeight / 2);
x = sx + (CELL_PIXEL_W / 2);
y = sy + (CELL_PIXEL_W / 2);
x = x + (ScreenWidth / 2);
}
bool CellClass::ScreenCoordsToIsoTile(int x, int y, int &tileX, int &tileY) {
x = x - (ScreenWidth / 2);
float tempPt_x = (2 * y + x) / 2;
float tempPt_y = (2 * y - x) / 2;
tileX = floor(tempPt_x / (CELL_PIXEL_W * 0.5f));
tileY = floor(tempPt_y / (CELL_PIXEL_H * 0.5f));
if (tileX < 0 || tileY < 0 || tileX > 128 || tileY > 128)
return false;
return true;
}
bool CellClass::ScreenCoordsToIsoCoords(COORDINATE screenCoord, COORDINATE& isoCoord) {
int x, y;
Map.Coord_To_Pixel(screenCoord, x, y);
int tileX, tileY;
if (!CellClass::ScreenCoordsToIsoTile(x, y, tileX, tileY)) {
return false;
}
int worldTileX = tileX * CELL_PIXEL_W;
int worldTileY = tileY * CELL_PIXEL_H;
isoCoord = Map.Pixel_To_Coord(worldTileX, worldTileY);
return true;
}
/***********************************************************************************************
* CellClass::Draw_It -- Draws the cell imagery at the location specified. *
* *
@@ -1022,7 +1063,7 @@ bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_d
* 04/25/1995 JLB : Smudges drawn BELOW overlays. *
* 07/22/1996 JLB : Objects added to draw process. *
*=============================================================================================*/
void CellClass::Draw_It(int x, int y, bool objects) const
void CellClass::Draw_It(int x, int y, bool objects)
{
assert((unsigned)Cell_Number() <= MAP_CELL_TOTAL);
@@ -1093,7 +1134,12 @@ void CellClass::Draw_It(int x, int y, bool objects) const
*/
if (ttype->Get_Image_Data()) {
// jmarshall - hd image should always be valid even if loading legacy assets
LogicPage->Draw_Stamp(ttype->Get_HDImage_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
int xx = x;
int yy = y;
ConvertCoordsToIsometric(xx, yy);
lastRenderX = xx;
lastRenderY = yy;
LogicPage->Draw_Stamp(ttype->Get_HDImage_Data(), icon, xx, yy, NULL, WINDOW_TACTICAL);
// jmarshall end
if (remap) {
LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap);
@@ -1217,7 +1263,12 @@ void CellClass::Draw_It(int x, int y, bool objects) const
(Cell_Y(cell) - Cell_Y(Map.ZoneCell + Map.ZoneOffset)) *
tptr->Width;
// jmarshall - hd image should always be valid even if loading legacy assets
LogicPage->Draw_Stamp(tptr->Get_HDImage_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
int xx = x;
int yy = y;
ConvertCoordsToIsometric(xx, yy);
lastRenderX = xx;
lastRenderY = yy;
LogicPage->Draw_Stamp(tptr->Get_HDImage_Data(), icon, xx, yy, NULL, WINDOW_TACTICAL);
// jmarshall end
}
break;
@@ -1338,6 +1389,7 @@ void CellClass::Draw_It(int x, int y, bool objects) const
renderedFrameObjects.push_back(object);
int xx,yy;
if (object->IsToDisplay && (!object->Is_Techno() || ((TechnoClass *)object)->Visual_Character() == VISUAL_NORMAL) && Map.Coord_To_Pixel(object->Render_Coord(), xx, yy)) {
ConvertCoordsToIsometric(xx, yy);
if (_Calc_Partial_Window(x, y, xx, yy)) {
object->Draw_It(xx, yy, WINDOW_PARTIAL);
if (Debug_Map) {
+12 -1
View File
@@ -276,10 +276,14 @@ class CellClass
void Code_Pointers(void);
void Decode_Pointers(void);
static void ConvertCoordsToIsometric(int& x, int& y);
static bool ScreenCoordsToIsoTile(int x, int y, int& tileX, int& tileY);
static bool ScreenCoordsToIsoCoords(COORDINATE screenCoord, COORDINATE& isoCoord);
/*
** Display and rendering controls.
*/
void Draw_It(int x, int y, bool objects=false) const;
void Draw_It(int x, int y, bool objects=false);
void Redraw_Objects(bool forced=false);
void Shimmer(void);
@@ -319,9 +323,16 @@ class CellClass
*/
void Override_Land_Type(LandType type);
int GetLastRenderX(void) { return lastRenderX; }
int GetLastRenderY(void) { return lastRenderY; }
private:
CellClass (CellClass const &) ;
int lastRenderX;
int lastRenderY;
LandType Land; // The land type of this cell.
LandType OverrideLand; // The overriden land type of this cell.
+12 -20
View File
@@ -1145,11 +1145,19 @@ void DisplayClass::Remove(ObjectClass const * object, LayerType layer)
*=============================================================================================*/
CELL DisplayClass::Click_Cell_Calc(int x, int y) const
{
int tileX, tileY;
if (!CellClass::ScreenCoordsToIsoTile(x, y, tileX, tileY)) {
return -1;
}
x = tileX * CELL_PIXEL_W;
y = tileY * CELL_PIXEL_H;
x -= TacPixelX;
x = Pixel_To_Lepton(x);
y -= TacPixelY;
y = Pixel_To_Lepton(y);
// Possibly ignore the view constraints if we aren't using the internal renderer. ST - 8/5/2019 11:56AM
if (IgnoreViewConstraints || (unsigned)x < TacLeptonWidth && (unsigned)y < TacLeptonHeight) {
COORDINATE tcoord = XY_Coord(Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord))), Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord))));
@@ -2304,28 +2312,16 @@ ObjectClass * DisplayClass::Cell_Object(CELL cell, int x, int y) const
** cell coordinates.
*/
if (Debug_Map && PendingObjectPtr) {
PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(Cell_Coord(ZoneCell + ZoneOffset));
COORDINATE coord = Cell_Coord(ZoneCell + ZoneOffset);
PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(coord);
PendingObjectPtr->Render(true);
}
#endif
BEnd(BENCH_TACTICAL);
}
}
// jmarshall - isometric
void DisplayClass::ConvertCoordsToIsometric(int& x, int& y) {
int tileWidth = CELL_PIXEL_W;
int tileHeight = CELL_PIXEL_H;
int sx = (x / CELL_PIXEL_W) * (tileWidth / 2) - (y / CELL_PIXEL_W) * (tileWidth / 2);
int sy = (x / CELL_PIXEL_W) * (tileHeight / 2) + (y / CELL_PIXEL_W) * (tileHeight / 2);
x = sx + (CELL_PIXEL_W / 2);
y = sy + (CELL_PIXEL_W / 2);
x = x + (ScreenWidth / 2);
}
// jmarshall end
/***********************************************************************************************
* DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
* *
@@ -2362,8 +2358,6 @@ void DisplayClass::Redraw_Icons(void)
int ypixel;
if (Coord_To_Pixel(coord, xpixel, ypixel)) {
ConvertCoordsToIsometric(xpixel, ypixel);
CellClass * cellptr = &(*this)[coord];
/*
@@ -2409,8 +2403,6 @@ void DisplayClass::Redraw_OIcons(void)
if (Coord_To_Pixel(coord, xpixel, ypixel)) {
CellClass * cellptr = &(*this)[coord];
// ConvertCoordsToIsometric(xpixel, ypixel);
/*
** If there is a portion of the underlying icon that could be visible,
** then draw it. Also draw the cell if the shroud is off.
-3
View File
@@ -222,9 +222,6 @@ class DisplayClass: public MapClass
*/
int TacPixelX;
int TacPixelY;
// jmarshall
static void ConvertCoordsToIsometric(int& x, int& y);
// jmarshall end
/*
** This is the coordinate that the tactical map should be in at next available opportunity.
+1 -1
View File
@@ -1318,7 +1318,7 @@ bool ObjectClass::Render(bool forced) const
const_cast<ObjectClass*>(this)->IsToDisplay = false; // added const_cast ST - 5/9/2019
if (Map.Coord_To_Pixel(coord, x, y)) {
CellClass::ConvertCoordsToIsometric(x, y);
/*
** Draw the object itself
*/