Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TD: Handle save games made with different resolutions #939

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tiberiandawn/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ CreditClass::CreditClass(void)
* HISTORY: *
* 03/13/1995 JLB : Created. *
*=============================================================================================*/
#define XX (320 - 120)
#define WW 50
void CreditClass::Graphic_Logic(bool forced)
{
Expand Down
38 changes: 22 additions & 16 deletions tiberiandawn/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ void PowerClass::Init_Clear(void)
PowerDir = 0;
}

void PowerClass::Recalculate_Offsets(void)
{
int factor = Get_Resolution_Factor();
PowX = SeenBuff.Get_Width() - Map.RadWidth;
if (factor) {
PowY = Map.RadY + Map.RadHeight + (13 << factor) - 4;
} else {
PowY = Map.RadY + Map.RadHeight + (13 << factor);
}
PowWidth = 8 << factor;
PowHeight = SeenBuff.Get_Height() - PowY;
PowLineSpace = 5 << factor;
PowLineWidth = PowWidth - 4;

PowerButton.X = PowX;
PowerButton.Y = PowY;
PowerButton.Width = PowWidth - 1;
PowerButton.Height = PowHeight;
}

/***********************************************************************************************
* PowerClass::One_Time -- One time processing for the power bar. *
* *
Expand All @@ -127,24 +147,9 @@ void PowerClass::Init_Clear(void)
void PowerClass::One_Time(void)
{
RadarClass::One_Time();
Recalculate_Offsets();

int factor = Get_Resolution_Factor();
PowX = SeenBuff.Get_Width() - Map.RadWidth;
if (factor) {
PowY = Map.RadY + Map.RadHeight + (13 << factor) - 4;
} else {
PowY = Map.RadY + Map.RadHeight + (13 << factor);
}
PowWidth = 8 << factor;
PowHeight = SeenBuff.Get_Height() - PowY;
PowLineSpace = 5 << factor;
PowLineWidth = PowWidth - 4;

PowerButton.X = PowX;
PowerButton.Y = PowY;
PowerButton.Width = PowWidth - 1;
PowerButton.Height = PowHeight;

PowerShape = MFCD::Retrieve((factor) ? "HPOWER.SHP" : "POWER.SHP");
PowerBarShape = Hires_Retrieve("PWRBAR.SHP");
}
Expand Down Expand Up @@ -172,6 +177,7 @@ void PowerClass::Draw_It(bool complete)
int factor = Get_Resolution_Factor();

if (complete || IsToRedraw) {
Recalculate_Offsets();
// PowX = TacPixelX + TacWidth*ICON_PIXEL_W; // X position of upper left corner of power bar.

if (LogicPage->Lock()) {
Expand Down
1 change: 1 addition & 0 deletions tiberiandawn/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class PowerClass : public RadarClass
};

private:
void Recalculate_Offsets(void);
int Power_Height(int value);

unsigned IsActive : 1;
Expand Down
45 changes: 26 additions & 19 deletions tiberiandawn/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,7 @@ RadarClass::RadarClass(void)
IsPlayerNames = false;
}

/***********************************************************************************************
* RadarClass::One_Time -- Handles one time processing for the radar map. *
* *
* This routine handles any one time processing required in order for the radar map to *
* function. This actually only requires an allocation of the radar staging buffer. This *
* buffer is needed for those cases where the radar area of the page is being destroyed *
* and it needs to be destroyed. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Be sure to call this routine only ONCE. *
* *
* HISTORY: *
* 12/22/1994 JLB : Created. *
*=============================================================================================*/
void RadarClass::One_Time(void)
void RadarClass::Recalculate_Offsets(void)
{
int factor = Get_Resolution_Factor();
RadWidth = 80 << factor;
Expand All @@ -144,13 +127,35 @@ void RadarClass::One_Time(void)
RadIHeight = 69 << factor;
}

DisplayClass::One_Time();
RadarButton.X = RadX + RadOffX;
RadarButton.Y = RadY + RadOffY;
RadarButton.Width = RadIWidth;
RadarButton.Height = RadIHeight;
}

/***********************************************************************************************
* RadarClass::One_Time -- Handles one time processing for the radar map. *
* *
* This routine handles any one time processing required in order for the radar map to *
* function. This actually only requires an allocation of the radar staging buffer. This *
* buffer is needed for those cases where the radar area of the page is being destroyed *
* and it needs to be destroyed. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Be sure to call this routine only ONCE. *
* *
* HISTORY: *
* 12/22/1994 JLB : Created. *
*=============================================================================================*/
void RadarClass::One_Time(void)
{
Recalculate_Offsets();
DisplayClass::One_Time();
}

/***********************************************************************************************
* RadarClass::Init_Clear -- Sets the radar map to a known state. *
* *
Expand Down Expand Up @@ -338,6 +343,8 @@ void RadarClass::Draw_It(bool forced)
if (!forced && !IsToRedraw && !FullRedraw)
return;

Recalculate_Offsets();

static HousesType _house = HOUSE_NONE;
if (PlayerPtr->ActLike != _house) {
char name[_MAX_NAME + _MAX_EXT];
Expand Down
2 changes: 2 additions & 0 deletions tiberiandawn/radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class RadarClass : public DisplayClass
static TacticalClass RadarButton;

private:
void Recalculate_Offsets(void);

/*
** The current radar position as the upper left corner cell for the
** radar map display. The width and height is controlled by the
Expand Down
79 changes: 56 additions & 23 deletions tiberiandawn/sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,8 @@ SidebarClass::SidebarClass(void)
new (&Column[1]) StripClass(InitClass());
}

/***********************************************************************************************
* SidebarClass::One_Time -- Handles the one time game initializations. *
* *
* This routine is used to load the graphic data that is needed by the sidebar display. It *
* should only be called ONCE. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Only call this routine once when the game first starts. *
* *
* HISTORY: *
* 10/28/94 JLB : Created. *
*=============================================================================================*/
void SidebarClass::One_Time(void)
void SidebarClass::Recalculate_Offsets(void)
{
PowerClass::One_Time();
/*
** Set up the pixel offsets and widths and heights used to render the
** sidebar. They are now variables because we need to change them for
Expand Down Expand Up @@ -216,6 +200,50 @@ void SidebarClass::One_Time(void)
Column[1].X = Column[0].X + (StripClass::STRIP_WIDTH * factor) + spacing - 1;
Column[1].Y = SideY + TopHeight + 1;

if (Get_Resolution_Factor()) {
if (!Repair)
Repair = new ShapeButtonClass();
if (!Upgrade)
Upgrade = new ShapeButtonClass();
if (!Zoom)
Zoom = new ShapeButtonClass();
Repair->X = SideX + 4;
Upgrade->X = SideX + 57;
Zoom->X = SideX + 110;
} else {
if (!Repair)
Repair = new TextButtonClass();
if (!Upgrade)
Upgrade = new TextButtonClass();
if (!Zoom)
Zoom = new TextButtonClass();
Repair->X = SideX + 2;
Upgrade->X = Repair->X + Repair->Width + 2;
Zoom->X = Upgrade->X + Upgrade->Width + 2;
}
}

/***********************************************************************************************
* SidebarClass::One_Time -- Handles the one time game initializations. *
* *
* This routine is used to load the graphic data that is needed by the sidebar display. It *
* should only be called ONCE. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Only call this routine once when the game first starts. *
* *
* HISTORY: *
* 10/28/94 JLB : Created. *
*=============================================================================================*/
void SidebarClass::One_Time(void)
{
PowerClass::One_Time();

Recalculate_Offsets();

Column[0].One_Time(0);
Column[1].One_Time(1);

Expand Down Expand Up @@ -341,17 +369,14 @@ void SidebarClass::Init_IO(void)
ShapeButtonClass* SBCUpgrade = (ShapeButtonClass*)Upgrade;
ShapeButtonClass* SBCZoom = (ShapeButtonClass*)Zoom;

Repair->X = 484;
Repair->Y = 160;
SBCRepair->ReflectButtonState = true;
SBCRepair->Set_Shape(Hires_Retrieve(repair_shp));

Upgrade->X = 480 + 57;
Upgrade->Y = 160;
SBCUpgrade->ReflectButtonState = true;
SBCUpgrade->Set_Shape(Hires_Retrieve(sell_shp));

Zoom->X = 480 + 110;
Zoom->Y = 160;
SBCZoom->Set_Shape(Hires_Retrieve(map_shp));
} else {
Expand All @@ -368,17 +393,14 @@ void SidebarClass::Init_IO(void)
TBCZoom->Set_Text("Map");
TBCZoom->Set_Style(TPF_6POINT | TPF_NOSHADOW | TPF_CENTER);

Repair->X = 242;
Repair->Y = 80;
Repair->Width = 32;
Repair->Height = 9;

Upgrade->X = Repair->X + Repair->Width + 2;
Upgrade->Y = Repair->Y;
Upgrade->Width = 20;
Upgrade->Height = Repair->Height;

Zoom->X = Upgrade->X + Upgrade->Width + 2;
Zoom->Y = Upgrade->Y;
Zoom->Width = 20;
Zoom->Height = Upgrade->Height;
Expand Down Expand Up @@ -766,6 +788,8 @@ void SidebarClass::Draw_It(bool complete)
if (IsSidebarActive && (IsToRedraw || complete) && !Debug_Map) {
IsToRedraw = false;

Recalculate_Offsets();

if (LogicPage->Lock()) {
/*
** Draw the outline box around the sidebar buttons.
Expand Down Expand Up @@ -1225,6 +1249,14 @@ void SidebarClass::StripClass::Init_Clear(void)
}
}

void SidebarClass::StripClass::Recalculate_Offsets(void)
{
for (int i = 0; i < COLUMNS; i++) {
UpButton[i].X = X + ButtonSpacingOffset + 1;
DownButton[i].X = UpButton[i].X + UpButton[i].Width + ButtonSpacingOffset - 2;
}
}

/***********************************************************************************************
* SidebarClass::StripClass::Init_IO -- Initializes the strip's buttons *
* *
Expand Down Expand Up @@ -1757,6 +1789,7 @@ bool SidebarClass::StripClass::AI(KeyNumType& input, int, int)
void SidebarClass::StripClass::Draw_It(bool complete)
{
if (IsToRedraw || complete) {
Recalculate_Offsets();
IsToRedraw = false;
int factor = Get_Resolution_Factor();

Expand Down
4 changes: 4 additions & 0 deletions tiberiandawn/sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ class SidebarClass : public PowerClass
*/
static char ClockTranslucentTable[(1 + 1) * 256];

private:
void Recalculate_Offsets(void);

} Column[COLUMNS];

/*
Expand Down Expand Up @@ -408,6 +411,7 @@ class SidebarClass : public PowerClass
static void const* SidebarShape2;

private:
void Recalculate_Offsets(void);
bool Activate_Repair(int control);
bool Activate_Upgrade(int control);
bool Activate_Demolish(int control);
Expand Down
2 changes: 1 addition & 1 deletion tiberiandawn/tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void TabClass::Draw_It(bool complete)

void TabClass::Draw_Credits_Tab(void)
{
unsigned x = Get_Resolution_Factor() ? 320 : 160;
unsigned x = SeenBuff.Get_Width() - (Get_Resolution_Factor() ? 320 : 160);
CC_Draw_Shape(TabShape, 0, x, 0, WINDOW_MAIN, SHAPE_NORMAL);
}

Expand Down
Loading