2 changed files with 140 additions and 140 deletions
@ -1,123 +1,123 @@ |
|||||||
/**
|
/**
|
||||||
* @file monhealthbar.cpp |
* @file monhealthbar.cpp |
||||||
*
|
* |
||||||
* Adds monster health bar QoL feature |
* Adds monster health bar QoL feature |
||||||
*/ |
*/ |
||||||
|
|
||||||
#include "DiabloUI/art_draw.h" |
#include "DiabloUI/art_draw.h" |
||||||
#include "control.h" |
#include "control.h" |
||||||
#include "cursor.h" |
#include "cursor.h" |
||||||
#include "options.h" |
#include "options.h" |
||||||
#include "qol/common.h" |
#include "qol/common.h" |
||||||
#include "utils/language.h" |
#include "utils/language.h" |
||||||
|
|
||||||
namespace devilution { |
namespace devilution { |
||||||
namespace { |
namespace { |
||||||
|
|
||||||
Art healthBox; |
Art healthBox; |
||||||
Art resistance; |
Art resistance; |
||||||
Art health; |
Art health; |
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void InitMonsterHealthBar() |
void InitMonsterHealthBar() |
||||||
{ |
{ |
||||||
if (!sgOptions.Gameplay.bEnemyHealthBar) |
if (!sgOptions.Gameplay.bEnemyHealthBar) |
||||||
return; |
return; |
||||||
|
|
||||||
LoadMaskedArt("data\\healthbox.pcx", &healthBox, 1, 1); |
LoadMaskedArt("data\\healthbox.pcx", &healthBox, 1, 1); |
||||||
LoadArt("data\\health.pcx", &health); |
LoadArt("data\\health.pcx", &health); |
||||||
LoadMaskedArt("data\\resistance.pcx", &resistance, 6, 1); |
LoadMaskedArt("data\\resistance.pcx", &resistance, 6, 1); |
||||||
|
|
||||||
if ((healthBox.surface == nullptr) |
if ((healthBox.surface == nullptr) |
||||||
|| (health.surface == nullptr) |
|| (health.surface == nullptr) |
||||||
|| (resistance.surface == nullptr)) { |
|| (resistance.surface == nullptr)) { |
||||||
app_fatal(_("Failed to load UI resources. Is devilutionx.mpq accessible and up to date?")); |
app_fatal(_("Failed to load UI resources. Is devilutionx.mpq accessible and up to date?")); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
void FreeMonsterHealthBar() |
void FreeMonsterHealthBar() |
||||||
{ |
{ |
||||||
healthBox.Unload(); |
healthBox.Unload(); |
||||||
health.Unload(); |
health.Unload(); |
||||||
resistance.Unload(); |
resistance.Unload(); |
||||||
} |
} |
||||||
|
|
||||||
void DrawMonsterHealthBar(const CelOutputBuffer &out) |
void DrawMonsterHealthBar(const CelOutputBuffer &out) |
||||||
{ |
{ |
||||||
if (!sgOptions.Gameplay.bEnemyHealthBar) |
if (!sgOptions.Gameplay.bEnemyHealthBar) |
||||||
return; |
return; |
||||||
|
|
||||||
assert(healthBox.surface != nullptr); |
assert(healthBox.surface != nullptr); |
||||||
assert(health.surface != nullptr); |
assert(health.surface != nullptr); |
||||||
assert(resistance.surface != nullptr); |
assert(resistance.surface != nullptr); |
||||||
|
|
||||||
if (currlevel == 0) |
if (currlevel == 0) |
||||||
return; |
return; |
||||||
if (pcursmonst == -1) |
if (pcursmonst == -1) |
||||||
return; |
return; |
||||||
|
|
||||||
const MonsterStruct &mon = monster[pcursmonst]; |
const MonsterStruct &mon = monster[pcursmonst]; |
||||||
|
|
||||||
const int width = healthBox.w(); |
const int width = healthBox.w(); |
||||||
const int height = healthBox.h(); |
const int height = healthBox.h(); |
||||||
int xPos = (gnScreenWidth - width) / 2; |
int xPos = (gnScreenWidth - width) / 2; |
||||||
|
|
||||||
if (PANELS_COVER) { |
if (PANELS_COVER) { |
||||||
if (invflag || sbookflag) |
if (invflag || sbookflag) |
||||||
xPos -= SPANEL_WIDTH / 2; |
xPos -= SPANEL_WIDTH / 2; |
||||||
if (chrflag || questlog) |
if (chrflag || questlog) |
||||||
xPos += SPANEL_WIDTH / 2; |
xPos += SPANEL_WIDTH / 2; |
||||||
} |
} |
||||||
|
|
||||||
const int yPos = 18; |
const int yPos = 18; |
||||||
const int border = 3; |
const int border = 3; |
||||||
|
|
||||||
const int maxLife = std::max(mon._mmaxhp, mon._mhitpoints); |
const int maxLife = std::max(mon._mmaxhp, mon._mhitpoints); |
||||||
|
|
||||||
DrawArt(out, xPos, yPos, &healthBox); |
DrawArt(out, xPos, yPos, &healthBox); |
||||||
DrawHalfTransparentRectTo(out, xPos + border, yPos + border, width - (border * 2), height - (border * 2)); |
DrawHalfTransparentRectTo(out, xPos + border, yPos + border, width - (border * 2), height - (border * 2)); |
||||||
int barProgress = (width * mon._mhitpoints) / maxLife; |
int barProgress = (width * mon._mhitpoints) / maxLife; |
||||||
if (barProgress) { |
if (barProgress) { |
||||||
DrawArt(out, xPos + border + 1, yPos + border + 1, &health, 0, barProgress, height - (border * 2) - 2); |
DrawArt(out, xPos + border + 1, yPos + border + 1, &health, 0, barProgress, height - (border * 2) - 2); |
||||||
} |
} |
||||||
|
|
||||||
if (sgOptions.Gameplay.bShowMonsterType) { |
if (sgOptions.Gameplay.bShowMonsterType) { |
||||||
Uint8 borderColors[] = { 248 /*undead*/, 232 /*demon*/, 150 /*beast*/ }; |
Uint8 borderColors[] = { 248 /*undead*/, 232 /*demon*/, 150 /*beast*/ }; |
||||||
Uint8 borderColor = borderColors[mon.MData->mMonstClass]; |
Uint8 borderColor = borderColors[mon.MData->mMonstClass]; |
||||||
int borderWidth = width - (border * 2); |
int borderWidth = width - (border * 2); |
||||||
FastDrawHorizLine(out, xPos + border, yPos + border, borderWidth, borderColor); |
FastDrawHorizLine(out, xPos + border, yPos + border, borderWidth, borderColor); |
||||||
FastDrawHorizLine(out, xPos + border, yPos + height - border - 1, borderWidth, borderColor); |
FastDrawHorizLine(out, xPos + border, yPos + height - border - 1, borderWidth, borderColor); |
||||||
int borderHeight = height - (border * 2) - 2; |
int borderHeight = height - (border * 2) - 2; |
||||||
FastDrawVertLine(out, xPos + border, yPos + border + 1, borderHeight, borderColor); |
FastDrawVertLine(out, xPos + border, yPos + border + 1, borderHeight, borderColor); |
||||||
FastDrawVertLine(out, xPos + width - border - 1, yPos + border + 1, borderHeight, borderColor); |
FastDrawVertLine(out, xPos + width - border - 1, yPos + border + 1, borderHeight, borderColor); |
||||||
} |
} |
||||||
|
|
||||||
int barLableX = xPos + width / 2 - GetTextWidth(mon.mName) / 2; |
int barLableX = xPos + width / 2 - GetTextWidth(mon.mName) / 2; |
||||||
int barLableY = yPos + 10 + (height - 11) / 2; |
int barLableY = yPos + 10 + (height - 11) / 2; |
||||||
PrintGameStr(out, barLableX - 1, barLableY + 1, mon.mName, COL_BLACK); |
PrintGameStr(out, barLableX - 1, barLableY + 1, mon.mName, COL_BLACK); |
||||||
text_color color = COL_WHITE; |
text_color color = COL_WHITE; |
||||||
if (mon._uniqtype != 0) |
if (mon._uniqtype != 0) |
||||||
color = COL_GOLD; |
color = COL_GOLD; |
||||||
else if (mon.leader != 0) |
else if (mon.leader != 0) |
||||||
color = COL_BLUE; |
color = COL_BLUE; |
||||||
PrintGameStr(out, barLableX, barLableY, mon.mName, color); |
PrintGameStr(out, barLableX, barLableY, mon.mName, color); |
||||||
|
|
||||||
if (mon._uniqtype != 0 || monstkills[mon.MType->mtype] >= 15) { |
if (mon._uniqtype != 0 || monstkills[mon.MType->mtype] >= 15) { |
||||||
monster_resistance immunes[] = { IMMUNE_MAGIC, IMMUNE_FIRE, IMMUNE_LIGHTNING }; |
monster_resistance immunes[] = { IMMUNE_MAGIC, IMMUNE_FIRE, IMMUNE_LIGHTNING }; |
||||||
monster_resistance resists[] = { RESIST_MAGIC, RESIST_FIRE, RESIST_LIGHTNING }; |
monster_resistance resists[] = { RESIST_MAGIC, RESIST_FIRE, RESIST_LIGHTNING }; |
||||||
|
|
||||||
int resOffset = 5; |
int resOffset = 5; |
||||||
for (int i = 0; i < 3; i++) { |
for (int i = 0; i < 3; i++) { |
||||||
if (mon.mMagicRes & immunes[i]) { |
if (mon.mMagicRes & immunes[i]) { |
||||||
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2 + 1); |
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2 + 1); |
||||||
resOffset += resistance.w() + 2; |
resOffset += resistance.w() + 2; |
||||||
} else if (mon.mMagicRes & resists[i]) { |
} else if (mon.mMagicRes & resists[i]) { |
||||||
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2); |
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2); |
||||||
resOffset += resistance.w() + 2; |
resOffset += resistance.w() + 2; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
} // namespace devilution
|
} // namespace devilution
|
||||||
|
|||||||
@ -1,17 +1,17 @@ |
|||||||
/**
|
/**
|
||||||
* @file monhealthbar.h |
* @file monhealthbar.h |
||||||
*
|
* |
||||||
* Adds monster health bar QoL feature |
* Adds monster health bar QoL feature |
||||||
*/ |
*/ |
||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
namespace devilution { |
namespace devilution { |
||||||
|
|
||||||
struct CelOutputBuffer; |
struct CelOutputBuffer; |
||||||
|
|
||||||
void InitMonsterHealthBar(); |
void InitMonsterHealthBar(); |
||||||
void FreeMonsterHealthBar(); |
void FreeMonsterHealthBar(); |
||||||
|
|
||||||
void DrawMonsterHealthBar(const CelOutputBuffer &out); |
void DrawMonsterHealthBar(const CelOutputBuffer &out); |
||||||
|
|
||||||
} // namespace devilution
|
} // namespace devilution
|
||||||
|
|||||||
Loading…
Reference in new issue