Skip to content

Commit 19751ea

Browse files
committed
resizing behaviour infrastructure
dynamically resize the battlescape and geoscape based on scale options. maintains pixel size at all times.
1 parent 650728b commit 19751ea

14 files changed

Lines changed: 216 additions & 24 deletions

‎src/Battlescape/ActionMenuState.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,14 @@ void ActionMenuState::btnActionMenuItemClick(Action *action)
312312
}
313313
}
314314

315+
/**
316+
* Updates the scale.
317+
* @param dX delta of X;
318+
* @param dY delta of Y;
319+
*/
320+
void ActionMenuState::resize(int &dX, int &dY)
321+
{
322+
State::recenter(dX, dY * 2);
323+
}
324+
315325
}

‎src/Battlescape/ActionMenuState.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ActionMenuState : public State
4848
void handle(Action *action);
4949
/// Handler for clicking a action menu item.
5050
void btnActionMenuItemClick(Action *action);
51+
/// Update the resolution settings, we just resized the window.
52+
void resize(int &dX, int &dY);
5153
};
5254

5355
}

‎src/Battlescape/BattlescapeState.cpp‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BattlescapeState::BattlescapeState(Game *game) : State(game), _popups(), _xBefor
9898
int screenWidth = Options::baseXResolution;
9999
int screenHeight = Options::baseYResolution;
100100
int iconsWidth = 320;
101-
int iconsHeight = 56;
101+
int iconsHeight = Map::ICON_HEIGHT;
102102
_mouseOverIcons = false;
103103
// Create buttonbar - this should be on the centerbottom of the screen
104104
_icons = new InteractiveSurface(iconsWidth, iconsHeight, screenWidth/2 - iconsWidth/2, screenHeight - iconsHeight);
@@ -2044,4 +2044,53 @@ void BattlescapeState::txtTooltipOut(Action *action)
20442044
}
20452045
}
20462046

2047+
/**
2048+
* Updates the scale.
2049+
* @param dX delta of X;
2050+
* @param dY delta of Y;
2051+
*/
2052+
void BattlescapeState::resize(int &dX, int &dY)
2053+
{
2054+
dX = Options::baseXResolution;
2055+
dY = Options::baseYResolution;
2056+
int divisor = 1;
2057+
switch (Options::battlescapeScale)
2058+
{
2059+
case SCALE_SCREEN_DIV_3:
2060+
divisor = 3;
2061+
break;
2062+
case SCALE_SCREEN_DIV_2:
2063+
divisor = 2;
2064+
break;
2065+
case SCALE_SCREEN:
2066+
break;
2067+
default:
2068+
return;
2069+
}
2070+
2071+
Options::baseXResolution = std::max(Screen::ORIGINAL_WIDTH, Options::displayWidth / divisor);
2072+
Options::baseYResolution = std::max(Screen::ORIGINAL_HEIGHT, Options::displayHeight / divisor);
2073+
2074+
dX = Options::baseXResolution - dX;
2075+
dY = Options::baseYResolution - dY;
2076+
_map->setWidth(Options::baseXResolution);
2077+
_map->setHeight(Options::baseYResolution);
2078+
_map->getCamera()->resize();
2079+
_map->getCamera()->jumpXY(dX/2, dY/2);
2080+
2081+
for (std::vector<Surface*>::const_iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
2082+
{
2083+
if (*i != _map && (*i) != _btnPsi && *i != _btnLaunch && *i != _txtDebug)
2084+
{
2085+
(*i)->setX((*i)->getX() + dX / 2);
2086+
(*i)->setY((*i)->getY() + dY);
2087+
}
2088+
else if (*i != _map && *i != _txtDebug)
2089+
{
2090+
(*i)->setX((*i)->getX() + dX);
2091+
}
2092+
}
2093+
2094+
}
2095+
20472096
}

‎src/Battlescape/BattlescapeState.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class BattlescapeState : public State
208208
void txtTooltipIn(Action *action);
209209
/// Handler for hiding tooltip.
210210
void txtTooltipOut(Action *action);
211+
/// Update the resolution settings, we just resized the window.
212+
void resize(int &dX, int &dY);
211213
};
212214

213215
}

‎src/Battlescape/Camera.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,13 @@ bool Camera::isOnScreen(const Position &mapPos) const
581581
&& screenPos.y <= _screenHeight - 48;
582582
}
583583

584+
/**
585+
* Resizes the viewable window of the camera.
586+
*/
587+
void Camera::resize()
588+
{
589+
_screenWidth = _map->getWidth();
590+
_screenHeight = _map->getHeight();
591+
_visibleMapHeight = _map->getHeight() - Map::ICON_HEIGHT;
592+
}
584593
}

‎src/Battlescape/Camera.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class Camera
106106
bool getShowAllLayers() const;
107107
/// Checks if map coordinates X,Y,Z are on screen.
108108
bool isOnScreen(const Position &mapPos) const;
109+
/// Resize the viewable area.
110+
void resize();
109111
};
110112
}
111113
#endif

‎src/Battlescape/Map.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,5 +1294,13 @@ void Map::refreshSelectorPosition()
12941294
setSelectorPosition(_mouseX, _mouseY);
12951295
}
12961296

1297-
1297+
/*
1298+
* Special handling for setting the height of the map viewport.
1299+
* @param height the new base screen height.
1300+
*/
1301+
void Map::setHeight(int height)
1302+
{
1303+
Surface::setHeight(height);
1304+
_visibleMapHeight = height - ICON_HEIGHT;
1305+
}
12981306
}

‎src/Battlescape/Map.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Timer;
4040
class Text;
4141

4242
enum CursorType { CT_NONE, CT_NORMAL, CT_AIM, CT_PSI, CT_WAYPOINT, CT_THROW };
43-
4443
/**
4544
* Interactive map of the battlescape.
4645
*/
@@ -75,6 +74,7 @@ class Map : public InteractiveSurface
7574
void drawTerrain(Surface *surface);
7675
int getTerrainLevel(Position pos, int size);
7776
public:
77+
static const int ICON_HEIGHT = 56;
7878
/// Creates a new map at the specified position and size.
7979
Map(Game *game, int width, int height, int x, int y, int visibleMapHeight);
8080
/// Cleans up the map.
@@ -133,6 +133,8 @@ class Map : public InteractiveSurface
133133
void setUnitDying(bool flag);
134134
/// Refreshes the battlescape selector after scrolling.
135135
void refreshSelectorPosition();
136+
/// Special handling for updating map height.
137+
void setHeight(int height);
136138
};
137139

138140
}

‎src/Geoscape/GeoscapeState.cpp‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace OpenXcom
114114
*/
115115
GeoscapeState::GeoscapeState(Game *game) : State(game), _pause(false), _zoomInEffectDone(false), _zoomOutEffectDone(false), _popups(), _dogfights(), _dogfightsToBeStarted(), _minimizedDogfights(0)
116116
{
117-
int screenWidth = Options::baseXGeoscape - Options::baseXGeoscape%4;
117+
int screenWidth = Options::baseXGeoscape;
118118
int screenHeight = Options::baseYGeoscape;
119119

120120
// Create objects
@@ -2133,6 +2133,10 @@ void GeoscapeState::determineAlienMissions(bool atGameStart)
21332133
}
21342134
}
21352135

2136+
/**
2137+
* Handler for clicking on a timer button.
2138+
* @param action pointer to the mouse action.
2139+
*/
21362140
void GeoscapeState::btnTimerClick(Action *action)
21372141
{
21382142
SDL_Event ev;
@@ -2142,4 +2146,48 @@ void GeoscapeState::btnTimerClick(Action *action)
21422146
action->getSender()->mousePress(&a, this);
21432147
}
21442148

2149+
/**
2150+
* Updates the scale.
2151+
* @param dX delta of X;
2152+
* @param dY delta of Y;
2153+
*/
2154+
void GeoscapeState::resize(int &dX, int &dY)
2155+
{
2156+
if (_game->getSavedGame()->getSavedBattle())
2157+
return;
2158+
dX = Options::baseXResolution;
2159+
dY = Options::baseYResolution;
2160+
int divisor = 1;
2161+
switch (Options::geoscapeScale)
2162+
{
2163+
case SCALE_SCREEN_DIV_3:
2164+
divisor = 3;
2165+
break;
2166+
case SCALE_SCREEN_DIV_2:
2167+
divisor = 2;
2168+
break;
2169+
case SCALE_SCREEN:
2170+
break;
2171+
default:
2172+
return;
2173+
}
2174+
2175+
Options::baseXResolution = std::max(Screen::ORIGINAL_WIDTH, Options::displayWidth / divisor);
2176+
Options::baseYResolution = std::max(Screen::ORIGINAL_HEIGHT, Options::displayHeight / divisor);
2177+
2178+
dX = Options::baseXResolution - dX;
2179+
dY = Options::baseYResolution - dY;
2180+
2181+
_globe->resize();
2182+
2183+
for (std::vector<Surface*>::const_iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
2184+
{
2185+
if (*i != _globe)
2186+
{
2187+
(*i)->setX((*i)->getX() + dX);
2188+
(*i)->setY((*i)->getY() + dY/2);
2189+
}
2190+
}
2191+
2192+
}
21452193
}

‎src/Geoscape/GeoscapeState.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class GeoscapeState : public State
149149
bool processTerrorSite(TerrorSite *ts) const;
150150
/// Handles base defense
151151
void handleBaseDefense(Base *base, Ufo *ufo);
152+
/// Update the resolution settings, we just resized the window.
153+
void resize(int &dX, int &dY);
152154
private:
153155
/// Handle alien mission generation.
154156
void determineAlienMissions(bool atGameStart = false);

0 commit comments

Comments
 (0)