Skip to content

Commit

Permalink
KOTOR: Fix crash when setting party portraits without ingame GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jun 5, 2018
1 parent 55256ed commit 6b6954f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
57 changes: 18 additions & 39 deletions src/engines/kotor/gui/ingame/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* The ingame HUD.
*/

#include "src/common/strutil.h"

#include "src/graphics/windowman.h"
#include "src/graphics/graphics.h"

Expand Down Expand Up @@ -149,55 +151,32 @@ void HUD::showContainer() {
sub(*_container, kStartCodeNone, true, false);
}

void HUD::setPartyLeader(Creature *creature) {
if (!creature) {
getLabel("LBL_BACK1")->setInvisible(true);
getLabel("LBL_CHAR1")->setInvisible(true);
getProgressbar("PB_VIT1")->setInvisible(true);
void HUD::setPortrait(uint8 n, bool visible, const Common::UString &portrait) {
WidgetLabel *labelBack = getLabel(Common::UString("LBL_BACK") + Common::composeString(n));
if (labelBack)
labelBack->setInvisible(!visible);

return;
WidgetLabel *labelChar = getLabel(Common::UString("LBL_CHAR") + Common::composeString(n));
if (labelChar) {
labelChar->setInvisible(!visible);
labelChar->setFill(portrait);
}

getLabel("LBL_BACK1")->setInvisible(false);

getLabel("LBL_CHAR1")->setInvisible(false);
getLabel("LBL_CHAR1")->setFill(creature->getPortrait());
WidgetProgressbar *vitals = getProgressbar(Common::UString("PB_VIT") + Common::composeString(n));
if (vitals)
vitals->setInvisible(!visible);
}

getProgressbar("PB_VIT1")->setInvisible(false);
void HUD::setPartyLeader(Creature *creature) {
setPortrait(1, creature != 0, creature ? creature->getPortrait() : "");
}

void HUD::setPartyMember1(Creature *creature) {
if (!creature) {
getLabel("LBL_BACK2")->setInvisible(true);
getLabel("LBL_CHAR2")->setInvisible(true);
getProgressbar("PB_VIT2")->setInvisible(true);

return;
}

getLabel("LBL_BACK2")->setInvisible(false);

getLabel("LBL_CHAR2")->setInvisible(false);
getLabel("LBL_CHAR2")->setFill(creature->getPortrait());

getProgressbar("PB_VIT2")->setInvisible(false);
setPortrait(2, creature != 0, creature ? creature->getPortrait() : "");
}

void HUD::setPartyMember2(Creature *creature) {
if (!creature) {
getLabel("LBL_BACK3")->setInvisible(true);
getLabel("LBL_CHAR3")->setInvisible(true);
getProgressbar("PB_VIT3")->setInvisible(true);

return;
}

getLabel("LBL_BACK3")->setInvisible(false);

getLabel("LBL_CHAR3")->setInvisible(false);
getLabel("LBL_CHAR3")->setFill(creature->getPortrait());

getProgressbar("PB_VIT3")->setInvisible(false);
setPortrait(3, creature != 0, creature ? creature->getPortrait() : "");
}

void HUD::initWidget(Engines::Widget &widget) {
Expand Down
3 changes: 3 additions & 0 deletions src/engines/kotor/gui/ingame/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef ENGINES_KOTOR_GUI_INGAME_HUD_H
#define ENGINES_KOTOR_GUI_INGAME_HUD_H

#include "src/common/ustring.h"

#include "src/engines/aurora/console.h"

#include "src/engines/kotor/module.h"
Expand Down Expand Up @@ -65,6 +67,7 @@ class HUD : public GUI {
Common::ScopedPtr<Minimap> _minimap;

void initWidget(Widget &widget);
void setPortrait(uint8 n, bool visible, const Common::UString &portrait = "");

protected:
virtual void callbackActive(Widget &widget);
Expand Down

0 comments on commit 6b6954f

Please sign in to comment.