Skip to content

Commit

Permalink
XEEN: Refactored drawing the party icons into a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Feb 11, 2015
1 parent 8256f7c commit e596178
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 137 deletions.
1 change: 0 additions & 1 deletion engines/xeen/dialogs_dismiss.cpp
Expand Up @@ -73,7 +73,6 @@ void Dismiss::execute() {
Character tempChar = party._activeParty[_buttonValue];
int charIndex = party._partyMembers[_buttonValue];

intf.sortFaces();
// party.sortParty();

// TODO
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/dialogs_exchange.cpp
Expand Up @@ -65,7 +65,7 @@ void ExchangeDialog::execute(Character *&c, int &charIndex) {
}

w.close();
intf.charIconsPrint(true);
intf.drawParty(true);
intf.highlightChar(charIndex);
}

Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/dialogs_items.cpp
Expand Up @@ -505,7 +505,7 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) {
}
}

intf.charIconsPrint(true);
intf.drawParty(true);
if (updateStock)
charData2BlackData();

Expand Down
9 changes: 4 additions & 5 deletions engines/xeen/dialogs_party.cpp
Expand Up @@ -220,7 +220,6 @@ void PartyDialog::setupBackground() {
*/
void PartyDialog::setupFaces(int firstDisplayChar, Common::Array<int> xeenSideChars, bool updateFlag) {
Party &party = *_vm->_party;
Resources &res = *_vm->_resources;
Common::String charNames[4];
Common::String charRaces[4];
Common::String charSex[4];
Expand All @@ -229,7 +228,7 @@ void PartyDialog::setupFaces(int firstDisplayChar, Common::Array<int> xeenSideCh
int charId;

for (posIndex = 0; posIndex < 4; ++posIndex) {
charId = (firstDisplayChar + posIndex) >= xeenSideChars.size() ? -1 :
charId = (firstDisplayChar + posIndex) >= (int)xeenSideChars.size() ? -1 :
xeenSideChars[firstDisplayChar + posIndex];
bool isInParty = party.isInParty(charId);

Expand All @@ -248,11 +247,11 @@ void PartyDialog::setupFaces(int firstDisplayChar, Common::Array<int> xeenSideCh
charClasses[posIndex] = CLASS_NAMES[ps._class];
}

charIconsPrint(updateFlag);
drawParty(updateFlag);

// Set up the sprite set to use for each face
for (int posIndex = 0; posIndex < 4; ++posIndex) {
if ((firstDisplayChar + posIndex) >= xeenSideChars.size())
if ((firstDisplayChar + posIndex) >= (int)xeenSideChars.size())
_faceDrawStructs[posIndex]._sprites = nullptr;
else
_faceDrawStructs[posIndex]._sprites = party._roster[posIndex]._faceSprites;
Expand All @@ -268,7 +267,7 @@ void PartyDialog::setupFaces(int firstDisplayChar, Common::Array<int> xeenSideCh

void PartyDialog::startingCharChanged(Common::Array<int> &charList, int firstDisplayChar) {
Party &party = *_vm->_party;

// TODO
}

} // End of namespace Xeen
2 changes: 1 addition & 1 deletion engines/xeen/dialogs_party.h
Expand Up @@ -47,7 +47,7 @@ class PartyDialog : public ButtonContainer {

void setupBackground();

void charIconsPrint(bool updateFlag);
void drawParty(bool updateFlag);

void setupFaces(int firstDisplayChar, Common::Array<int> xeenSideChars, bool updateFlag);

Expand Down
5 changes: 3 additions & 2 deletions engines/xeen/dialogs_query.cpp
Expand Up @@ -97,11 +97,12 @@ bool YesNo::show(XeenEngine *vm, bool type, bool townFlag) {
}

bool YesNo::execute(bool type, bool townFlag) {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Party &party = *_vm->_party;
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;
Town &town = *_vm->_town;
SpriteResource confirmSprites;
int numFrames;
Expand All @@ -112,7 +113,7 @@ bool YesNo::execute(bool type, bool townFlag) {

if (!type) {
confirmSprites.load("confirm.icn");
intf._globalSprites.draw(screen, 7, Common::Point(232, 74));
res._globalSprites.draw(screen, 7, Common::Point(232, 74));
confirmSprites.draw(screen, 0, Common::Point(235, 75));
confirmSprites.draw(screen, 2, Common::Point(260, 75));
screen._windows[34].update();
Expand Down
193 changes: 96 additions & 97 deletions engines/xeen/interface.cpp
Expand Up @@ -33,9 +33,96 @@

namespace Xeen {

Interface::Interface(XeenEngine *vm) : ButtonContainer(), InterfaceMap(vm), _vm(vm) {
_buttonsLoaded = false;
PartyDrawer::PartyDrawer(XeenEngine *vm): _vm(vm) {
_restoreSprites.load("restorex.icn");
_hpSprites.load("hpbars.icn");
_dseFace.load("dse.fac");
_hiliteChar = -1;
}

void PartyDrawer::drawParty(bool updateFlag) {
Party &party = *_vm->_party;
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;
bool inCombat = _vm->_mode == MODE_COMBAT;
_restoreSprites.draw(screen, 0, Common::Point(8, 149));

// Handle drawing the party faces
uint partyCount = inCombat ? party._combatParty.size() : party._activeParty.size();
for (uint idx = 0; idx < partyCount; ++idx) {
Character &ps = inCombat ? *party._combatParty[idx] : party._activeParty[idx];
Condition charCondition = ps.worstCondition();
int charFrame = FACE_CONDITION_FRAMES[charCondition];

SpriteResource *sprites = (charFrame > 4) ? &_dseFace : ps._faceSprites;
if (charFrame > 4)
charFrame -= 5;

sprites->draw(screen, charFrame, Common::Point(CHAR_FACES_X[idx], 150));
}

for (uint idx = 0; idx < partyCount; ++idx) {
Character &ps = inCombat ? *party._combatParty[idx] : party._activeParty[idx];

// Draw the Hp bar
int maxHp = ps.getMaxHP();
int frame;
if (ps._currentHp < 1)
frame = 4;
else if (ps._currentHp > maxHp)
frame = 3;
else if (ps._currentHp == maxHp)
frame = 0;
else if (ps._currentHp < (maxHp / 4))
frame = 2;
else
frame = 1;

_hpSprites.draw(screen, frame, Common::Point(HP_BARS_X[idx], 182));
}

if (_hiliteChar != -1)
res._globalSprites.draw(screen, 8, Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));

if (updateFlag)
screen._windows[33].update();
}

void PartyDrawer::highlightChar(int charId) {
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;

if (charId != _hiliteChar && _hiliteChar != HILIGHT_CHAR_DISABLED) {
// Handle deselecting any previusly selected char
if (_hiliteChar != -1) {
res._globalSprites.draw(screen, 9 + _hiliteChar,
Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));
}

// Highlight new character
res._globalSprites.draw(screen, 8, Common::Point(CHAR_FACES_X[charId] - 1, 149));
_hiliteChar = charId;
screen._windows[33].update();
}
}

void PartyDrawer::unhighlightChar() {
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;

if (_hiliteChar != -1) {
res._globalSprites.draw(screen, _hiliteChar + 9,
Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));
_hiliteChar = -1;
screen._windows[33].update();
}
}

/*------------------------------------------------------------------------*/

Interface::Interface(XeenEngine *vm) : ButtonContainer(), InterfaceMap(vm),
PartyDrawer(vm), _vm(vm) {
_buttonsLoaded = false;
_intrIndex1 = 0;
_steppingFX = 0;

Expand Down Expand Up @@ -65,75 +152,15 @@ void Interface::initDrawStructs() {

void Interface::setup() {
InterfaceMap::setup();
_restoreSprites.load("restorex.icn");
_hpSprites.load("hpbars.icn");
_uiSprites.load("inn.icn");
_dseFace.load("dse.fac");

Party &party = *_vm->_party;
party.loadActiveParty();
party._newDay = party._minutes >= 300;
}

void Interface::charIconsPrint(bool updateFlag) {
Screen &screen = *_vm->_screen;
bool stateFlag = _vm->_mode == MODE_COMBAT;
_restoreSprites.draw(screen, 0, Common::Point(8, 149));

// Handle drawing the party faces
for (int idx = 0; idx < (stateFlag ? _vm->_party->_combatPartyCount :
_vm->_party->_partyCount); ++idx) {
int charIndex = stateFlag ? _combatCharIds[idx] : idx;
Character &ps = _vm->_party->_activeParty[charIndex];
Condition charCondition = ps.worstCondition();
int charFrame = FACE_CONDITION_FRAMES[charCondition];

SpriteResource *sprites = (charFrame > 4) ? &_dseFace : ps._faceSprites;
if (charFrame > 4)
charFrame -= 5;

sprites->draw(screen, charFrame, Common::Point(CHAR_FACES_X[idx], 150));
}

if (!_hpSprites.empty()) {
for (int idx = 0; idx < (stateFlag ? _vm->_party->_combatPartyCount :
_vm->_party->_partyCount); ++idx) {
int charIndex = stateFlag ? _combatCharIds[idx] : idx;
Character &ps = _vm->_party->_activeParty[charIndex];

// Draw the Hp bar
int maxHp = ps.getMaxHP();
int frame;
if (ps._currentHp < 1)
frame = 4;
else if (ps._currentHp > maxHp)
frame = 3;
else if (ps._currentHp == maxHp)
frame = 0;
else if (ps._currentHp < (maxHp / 4))
frame = 2;
else
frame = 1;

_hpSprites.draw(screen, frame, Common::Point(HP_BARS_X[idx], 182));
}
}

if (_hiliteChar != -1)
_globalSprites.draw(screen, 8, Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));

if (updateFlag)
screen._windows[33].update();
}

/**
* Removes any empty character entries from the faces list
*/
void Interface::sortFaces() {
// No implementation needed
}

void Interface::startup() {
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;
_iconSprites.load("main.icn");

Expand All @@ -147,10 +174,10 @@ void Interface::startup() {
}
draw3d(false);

_globalSprites.draw(screen._windows[1], 5, Common::Point(232, 9));
charIconsPrint(false);
res._globalSprites.draw(screen._windows[1], 5, Common::Point(232, 9));
drawParty(false);

_mainList[0]._sprites = &_globalSprites;
_mainList[0]._sprites = &res._globalSprites;
for (int i = 1; i < 16; ++i)
_mainList[i]._sprites = &_iconSprites;

Expand Down Expand Up @@ -582,34 +609,6 @@ void Interface::doFalling() {
// TODO
}

void Interface::highlightChar(int charId) {
Screen &screen = *_vm->_screen;

if (charId != _hiliteChar && _hiliteChar != HILIGHT_CHAR_DISABLED) {
// Handle deselecting any previusly selected char
if (_hiliteChar != -1) {
_globalSprites.draw(screen, 9 + _hiliteChar,
Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));
}

// Highlight new character
_globalSprites.draw(screen, 8, Common::Point(CHAR_FACES_X[charId] - 1, 149));
_hiliteChar = charId;
screen._windows[33].update();
}
}

void Interface::unhighlightChar() {
Screen &screen = *_vm->_screen;

if (_hiliteChar != -1) {
_globalSprites.draw(screen, _hiliteChar + 9,
Common::Point(CHAR_FACES_X[_hiliteChar] - 1, 149));
_hiliteChar = -1;
screen._windows[33].update();
}
}

bool Interface::checkMoveDirection(int key) {
Map &map = *_vm->_map;
Party &party = *_vm->_party;
Expand Down Expand Up @@ -738,7 +737,7 @@ void Interface::rest() {
for (uint charIdx = 0; charIdx < party._activeParty.size(); ++charIdx) {
party._activeParty[charIdx]._conditions[ASLEEP] = 1;
}
charIconsPrint(true);
drawParty(true);

Mode oldMode = _vm->_mode;
_vm->_mode = MODE_SLEEPING;
Expand Down Expand Up @@ -826,7 +825,7 @@ void Interface::rest() {
}
}

charIconsPrint(true);
drawParty(true);
_vm->_mode = oldMode;
doStepCode();
draw3d(true);
Expand Down Expand Up @@ -924,7 +923,7 @@ void Interface::bash(const Common::Point &pt, Direction direction) {

party.checkPartyDead();
events.ipause(2);
charIconsPrint(true);
drawParty(true);
}


Expand Down

0 comments on commit e596178

Please sign in to comment.