Skip to content

Commit

Permalink
XEEN: Refactor FontSurface as ancestors of Window, not Screen
Browse files Browse the repository at this point in the history
This refactoring allowed Screen to now simply derive from
Graphics::Screen, and several duplicated methods could be removed.
  • Loading branch information
dreammaster committed Nov 30, 2017
1 parent 7c74f4f commit 2ca0235
Show file tree
Hide file tree
Showing 30 changed files with 351 additions and 406 deletions.
7 changes: 2 additions & 5 deletions engines/xeen/combat.cpp
Expand Up @@ -133,7 +133,6 @@ void Combat::clear() {

void Combat::giveCharDamage(int damage, DamageType attackType, int charIndex) {
Party &party = *_vm->_party;
Screen &screen = *_vm->_screen;
Scripts &scripts = *_vm->_scripts;
Sound &sound = *_vm->_sound;
Windows &windows = *_vm->_windows;
Expand Down Expand Up @@ -221,8 +220,7 @@ void Combat::giveCharDamage(int damage, DamageType attackType, int charIndex) {

// Draw the attack effect on the character sprite
sound.playFX(fx);
_powSprites.draw(screen, frame,
Common::Point(Res.CHAR_FACES_X[selectedIndex1], 150));
_powSprites.draw(0, frame, Common::Point(Res.CHAR_FACES_X[selectedIndex1], 150));
windows[33].update();

// Reduce damage if power shield active, and set it zero
Expand Down Expand Up @@ -265,7 +263,6 @@ void Combat::doCharDamage(Character &c, int charNum, int monsterDataIndex) {
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Party &party = *_vm->_party;
Screen &screen = *_vm->_screen;
Sound &sound = *_vm->_sound;
Windows &windows = *_vm->_windows;
MonsterStruct &monsterData = map._monsterData[monsterDataIndex];
Expand Down Expand Up @@ -322,7 +319,7 @@ void Combat::doCharDamage(Character &c, int charNum, int monsterDataIndex) {
}

sound.playFX(fx);
intf._charPowSprites.draw(screen, frame, Common::Point(Res.CHAR_FACES_X[charNum], 150));
intf._charPowSprites.draw(0, frame, Common::Point(Res.CHAR_FACES_X[charNum], 150));
windows[33].update();

damage -= party._powerShield;
Expand Down
22 changes: 11 additions & 11 deletions engines/xeen/cutscenes.cpp
Expand Up @@ -60,7 +60,7 @@ void Cutscenes::showSubtitles(uint windowIndex) {
if (!_boxSprites)
// Not already loaded, so load it
_boxSprites = new SpriteResource("box.vga");
_boxSprites->draw(screen, 0, Common::Point(36, 189));
_boxSprites->draw(0, 0, Common::Point(36, 189));

// Write the subtitle line
windows[windowIndex].writeString(_subtitleLine);
Expand Down Expand Up @@ -150,15 +150,15 @@ bool Cutscenes::doScroll(bool rollUp, bool fadeIn) {
screen.restoreBackground();

if (i > 14) {
hand[14]->draw(screen, 0, Common::Point(SCROLL_L[ctr], 0), SPRFLAG_800);
hand[15]->draw(screen, 0, Common::Point(SCROLL_R[ctr], 0), SPRFLAG_800);
hand[14]->draw(0, 0, Common::Point(SCROLL_L[ctr], 0), SPRFLAG_800);
hand[15]->draw(0, 0, Common::Point(SCROLL_R[ctr], 0), SPRFLAG_800);
--ctr;
} else if (i != 0) {
hand[i - 1]->draw(screen, 0);
hand[i - 1]->draw(0, 0);
}

if (i <= 20)
marb[(i - 1) / 5]->draw(screen, (i - 1) % 5);
marb[(i - 1) / 5]->draw(0, (i - 1) % 5);
screen.update();

while (!_vm->shouldQuit() && events.timeElapsed() == 0)
Expand All @@ -174,15 +174,15 @@ bool Cutscenes::doScroll(bool rollUp, bool fadeIn) {
screen.restoreBackground();

if (i < 14) {
hand[i]->draw(screen, 0);
hand[i]->draw(0, 0);
} else {
hand[14]->draw(screen, 0, Common::Point(SCROLL_L[ctr], 0), SPRFLAG_800);
hand[15]->draw(screen, 0, Common::Point(SCROLL_R[ctr], 0), SPRFLAG_800);
hand[14]->draw(0, 0, Common::Point(SCROLL_L[ctr], 0), SPRFLAG_800);
hand[15]->draw(0, 0, Common::Point(SCROLL_R[ctr], 0), SPRFLAG_800);
++ctr;
}

if (i < 20) {
marb[i / 5]->draw(screen, i % 5);
marb[i / 5]->draw(0, i % 5);
}
screen.update();

Expand All @@ -195,8 +195,8 @@ bool Cutscenes::doScroll(bool rollUp, bool fadeIn) {
}

if (rollUp) {
hand[0]->draw(screen, 0);
marb[0]->draw(screen, 0);
hand[0]->draw(0, 0);
marb[0]->draw(0, 0);
} else {
screen.restoreBackground();
}
Expand Down
5 changes: 2 additions & 3 deletions engines/xeen/dialogs.cpp
Expand Up @@ -63,7 +63,6 @@ void ButtonContainer::addPartyButtons(XeenEngine *vm) {

bool ButtonContainer::checkEvents(XeenEngine *vm) {
EventsManager &events = *vm->_events;
Screen &screen = *vm->_screen;
Windows &windows = *_vm->_windows;
_buttonValue = 0;

Expand Down Expand Up @@ -107,7 +106,7 @@ bool ButtonContainer::checkEvents(XeenEngine *vm) {
if (btn._draw && btn._value == _buttonValue) {
// Found the correct button
// Draw button depressed
btn._sprites->draw(screen, btnIndex * 2 + 1,
btn._sprites->draw(0, btnIndex * 2 + 1,
Common::Point(btn._bounds.left, btn._bounds.top));
win.setBounds(btn._bounds);
win.update();
Expand All @@ -117,7 +116,7 @@ bool ButtonContainer::checkEvents(XeenEngine *vm) {
events.wait(2);

// Redraw button in it's original non-depressed form
btn._sprites->draw(screen, btnIndex * 2,
btn._sprites->draw(0, btnIndex * 2,
Common::Point(btn._bounds.left, btn._bounds.top));
win.setBounds(btn._bounds);
win.update();
Expand Down
33 changes: 16 additions & 17 deletions engines/xeen/dialogs_automap.cpp
Expand Up @@ -34,7 +34,6 @@ void AutoMapDialog::show(XeenEngine *vm) {
}

void AutoMapDialog::execute() {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Expand Down Expand Up @@ -91,7 +90,7 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(xDiff, yDiff), 0);

if (map._currentSteppedOn) {
map._tileSprites.draw(screen, map.mazeDataCurrent()._surfaceTypes[v],
map._tileSprites.draw(0, map.mazeDataCurrent()._surfaceTypes[v],
Common::Point(xp, yp));
}
}
Expand All @@ -103,7 +102,7 @@ void AutoMapDialog::execute() {
int wallType = map.mazeDataCurrent()._wallTypes[v];

if (wallType && map._currentSteppedOn)
map._tileSprites.draw(screen, wallType, Common::Point(xp, yp));
map._tileSprites.draw(0, wallType, Common::Point(xp, yp));
}
}

Expand All @@ -112,7 +111,7 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(xDiff, yDiff), 8);

if (v && map._currentSteppedOn)
map._tileSprites.draw(screen, 1, Common::Point(xp, yp));
map._tileSprites.draw(0, 1, Common::Point(xp, yp));
}
}
} else {
Expand All @@ -125,7 +124,7 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(xDiff, yDiff), 0, 0xffff);

if (v != INVALID_CELL && map._currentSteppedOn)
map._tileSprites.draw(screen, 0, Common::Point(xp, yp));
map._tileSprites.draw(0, 0, Common::Point(xp, yp));
}
}

Expand All @@ -134,22 +133,22 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(pt.x - 8, yDiff), 0, 0xffff);

if (v != INVALID_CELL && map._currentSurfaceId != 0 && map._currentSteppedOn)
map._tileSprites.draw(screen, 36 + map.mazeData()._surfaceTypes[
map._tileSprites.draw(0, 36 + map.mazeData()._surfaceTypes[
map._currentSurfaceId], Common::Point(75, yp));
}

// Draw thin tile portion on top-left corner of map
v = map.mazeLookup(Common::Point(pt.x - 8, pt.y + 8), 0, 0xffff);
if (v != INVALID_CELL && map._currentSurfaceId != 0 && map._currentSteppedOn)
map._tileSprites.draw(screen, 36 + map.mazeData()._surfaceTypes[
map._tileSprites.draw(0, 36 + map.mazeData()._surfaceTypes[
map._currentSurfaceId], Common::Point(75, 35));

// Draw any thin tiles at the very top of the map
for (int xp = 85, xDiff = pt.x - 7; xp < 245; xp += 10, ++xDiff) {
v = map.mazeLookup(Common::Point(xDiff, pt.y + 8), 0, 0xffff);

if (v != INVALID_CELL && map._currentSurfaceId != 0 && map._currentSteppedOn)
map._tileSprites.draw(screen, 36 + map.mazeData()._surfaceTypes[
map._tileSprites.draw(0, 36 + map.mazeData()._surfaceTypes[
map._currentSurfaceId], Common::Point(xp, 35));
}

Expand All @@ -159,7 +158,7 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(xDiff, yDiff), 0, 0xffff);

if (v != INVALID_CELL && map._currentSurfaceId && map._currentSteppedOn)
map._tileSprites.draw(screen, map.mazeData()._surfaceTypes[
map._tileSprites.draw(0, map.mazeData()._surfaceTypes[
map._currentSurfaceId], Common::Point(xp, yp));
}
}
Expand Down Expand Up @@ -216,7 +215,7 @@ void AutoMapDialog::execute() {
}

if (frame != -1 && map._currentSteppedOn)
map._tileSprites.draw(screen, frame, Common::Point(70, yp));
map._tileSprites.draw(0, frame, Common::Point(70, yp));

// Draw walls on top edge of map
v = map.mazeLookup(Common::Point(xDiff, pt.y + 8), 0);
Expand Down Expand Up @@ -269,15 +268,15 @@ void AutoMapDialog::execute() {
}

if (frame != -1 && map._currentSteppedOn)
map._tileSprites.draw(screen, frame, Common::Point(xp, 30));
map._tileSprites.draw(0, frame, Common::Point(xp, 30));
}

// Draw any walls on the cells
for (int yCtr = 0, yp = 38, yDiff = pt.y + 7; yCtr < 16; ++yCtr, yp += 8, --yDiff) {
for (int xCtr = 0, xp = 80, xDiff = pt.x - 7; xCtr < 16; ++xCtr, xp += 10, ++xDiff) {
// Draw the arrow if at the correct position
if ((arrowPt.x / 10) == xCtr && (14 - (arrowPt.y / 10)) == yCtr && frameEndFlag) {
globalSprites.draw(screen, party._mazeDirection + 1,
globalSprites.draw(0, party._mazeDirection + 1,
Common::Point(arrowPt.x + 81, arrowPt.y + 29));
}

Expand Down Expand Up @@ -331,7 +330,7 @@ void AutoMapDialog::execute() {
}

if (frame != -1 && map._currentSteppedOn)
map._tileSprites.draw(screen, frame, Common::Point(xp, yp));
map._tileSprites.draw(0, frame, Common::Point(xp, yp));

v = map.mazeLookup(Common::Point(xDiff, yDiff), 0);
switch (v) {
Expand Down Expand Up @@ -382,7 +381,7 @@ void AutoMapDialog::execute() {
}

if (frame != -1 && map._currentSteppedOn)
map._tileSprites.draw(screen, frame, Common::Point(xp, yp));
map._tileSprites.draw(0, frame, Common::Point(xp, yp));
}
}

Expand All @@ -392,16 +391,16 @@ void AutoMapDialog::execute() {
v = map.mazeLookup(Common::Point(xDiff, yDiff), 0, 0xffff);

if (v == INVALID_CELL || !map._currentSteppedOn)
map._tileSprites.draw(screen, 1, Common::Point(xp, yp));
map._tileSprites.draw(0, 1, Common::Point(xp, yp));
}
}
}

windows[5].frame();
if (!map._isOutdoors) {
map._tileSprites.draw(screen, 52, Common::Point(76, 30));
map._tileSprites.draw(0, 52, Common::Point(76, 30));
} else if (frameEndFlag) {
globalSprites.draw(screen, party._mazeDirection + 1,
globalSprites.draw(0, party._mazeDirection + 1,
Common::Point(arrowPt.x + 76, arrowPt.y + 25));
}

Expand Down
4 changes: 1 addition & 3 deletions engines/xeen/dialogs_char_info.cpp
Expand Up @@ -40,7 +40,6 @@ void CharacterInfo::execute(int charIndex) {
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
Screen &screen = *_vm->_screen;
Windows &windows = *_vm->_windows;

bool redrawFlag = true;
Expand Down Expand Up @@ -319,12 +318,11 @@ Common::String CharacterInfo::loadCharacterDetails(const Character &c) {
}

void CharacterInfo::showCursor(bool flag) {
Screen &screen = *_vm->_screen;
const int CURSOR_X[5] = { 9, 60, 111, 176, 0 };
const int CURSOR_Y[5] = { 23, 46, 69, 92, 115 };

if (_cursorCell < 20) {
_iconSprites.draw(screen, flag ? 49 : 48,
_iconSprites.draw(0, flag ? 49 : 48,
Common::Point(CURSOR_X[_cursorCell / 5], CURSOR_Y[_cursorCell % 5]));
}
}
Expand Down
1 change: 0 additions & 1 deletion engines/xeen/dialogs_dismiss.cpp
Expand Up @@ -34,7 +34,6 @@ void Dismiss::show(XeenEngine *vm) {
}

void Dismiss::execute() {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
Expand Down
1 change: 0 additions & 1 deletion engines/xeen/dialogs_error.cpp
Expand Up @@ -34,7 +34,6 @@ void ErrorDialog::show(XeenEngine *vm, const Common::String &msg, ErrorWaitType
}

void ErrorDialog::execute(const Common::String &msg, ErrorWaitType waitType) {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Windows &windows = *_vm->_windows;
Window &w = windows[6];
Expand Down
1 change: 0 additions & 1 deletion engines/xeen/dialogs_exchange.cpp
Expand Up @@ -33,7 +33,6 @@ void ExchangeDialog::show(XeenEngine *vm, Character *&c, int &charIndex) {
}

void ExchangeDialog::execute(Character *&c, int &charIndex) {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
Expand Down
11 changes: 4 additions & 7 deletions engines/xeen/dialogs_input.cpp
Expand Up @@ -118,8 +118,6 @@ Common::KeyCode Input::waitForKey(const Common::String &msg) {
}

void Input::animateCursor() {
Screen &screen = *_vm->_screen;

// Iterate through each frame
_cursorAnimIndex = _cursorAnimIndex ? _cursorAnimIndex - 1 : 5;
static const int CURSOR_ANIMATION_IDS[] = { 32, 124, 126, 127, 126, 124 };
Expand All @@ -128,9 +126,9 @@ void Input::animateCursor() {
Common::String cursorStr = Common::String::format("%c",
CURSOR_ANIMATION_IDS[_cursorAnimIndex]);

Common::Point writePos = screen._writePos;
Common::Point writePos = _window->_writePos;
_window->writeString(cursorStr);
screen._writePos = writePos;
_window->_writePos = writePos;
}

/*------------------------------------------------------------------------*/
Expand Down Expand Up @@ -227,16 +225,15 @@ int Choose123::show(XeenEngine *vm, int numOptions) {
int Choose123::execute(int numOptions) {
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Screen &screen = *_vm->_screen;
Town &town = *_vm->_town;
Windows &windows = *_vm->_windows;

Mode oldMode = _vm->_mode;
_vm->_mode = MODE_DIALOG_123;

loadButtons(numOptions);
_iconSprites.draw(screen, 7, Common::Point(232, 74));
drawButtons(&screen);
_iconSprites.draw(0, 7, Common::Point(232, 74));
drawButtons(&windows[0]);
windows[34].update();

int result = -1;
Expand Down

0 comments on commit 2ca0235

Please sign in to comment.