-
Notifications
You must be signed in to change notification settings - Fork 107
bugfix(gui): implement resolution scaling for unit health and info #1607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2687,22 +2687,17 @@ static Bool computeHealthRegion( const Drawable *draw, IRegion2D& region ) | |
if (!obj->getHealthBoxDimensions(healthBoxHeight, healthBoxWidth)) | ||
return FALSE; | ||
|
||
// scale the health bars according to the zoom | ||
Real zoom = TheTacticalView->getZoom(); | ||
//Real widthScale = 1.3f / zoom; | ||
Real widthScale = 1.0f / zoom; | ||
//Real heightScale = 0.8f / zoom; | ||
Real heightScale = 1.0f; | ||
// scale the health bars according to the zoom and resolution | ||
Real zoomScale = 1.0f / TheTacticalView->getZoom(); | ||
|
||
healthBoxWidth *= widthScale; | ||
healthBoxHeight *= heightScale; | ||
healthBoxWidth *= zoomScale * TheInGameUI->getUnitInfoScaleFactor(); | ||
healthBoxHeight *= TheInGameUI->getUnitHealthbarScaleFactor(); | ||
|
||
// do this so health bar doesn't get too skinny or fat after scaling | ||
//healthBoxHeight = max(3.0f, healthBoxHeight); | ||
healthBoxHeight = 3.0f; | ||
// do this so health bar doesn't get too skinny after scaling | ||
healthBoxHeight = max(defaultHealthBoxHeight, healthBoxHeight); | ||
|
||
// figure out the final region for the health box | ||
region.lo.x = screenCenter.x - healthBoxWidth * 0.45f; | ||
region.lo.x = screenCenter.x - healthBoxWidth * 0.5f; | ||
xezon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
region.lo.y = screenCenter.y - healthBoxHeight * 0.5f; | ||
region.hi.x = region.lo.x + healthBoxWidth; | ||
region.hi.y = region.lo.y + healthBoxHeight; | ||
|
@@ -2839,10 +2834,10 @@ void Drawable::drawEmoticon( const IRegion2D *healthBarRegion ) | |
if( healthBarRegion && getIconInfo()->m_keepTillFrame[ ICON_EMOTICON ] >= now ) | ||
{ | ||
//Draw the emoticon. | ||
Int barWidth = healthBarRegion->hi.x - healthBarRegion->lo.x; | ||
Int barWidth = healthBarRegion->width(); | ||
//Int barHeight = healthBarRegion.hi.y - healthBarRegion.lo.y; | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_EMOTICON ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_EMOTICON ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_EMOTICON ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_EMOTICON ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -2893,9 +2888,9 @@ void Drawable::drawAmmo( const IRegion2D *healthBarRegion ) | |
Real scale = 1.0f; | ||
#endif | ||
|
||
Int boxWidth = REAL_TO_INT(s_emptyAmmo->getImageWidth() * scale); | ||
Int boxHeight = REAL_TO_INT(s_emptyAmmo->getImageHeight() * scale); | ||
const Int SPACING = 1; | ||
Int boxWidth = s_emptyAmmo->getImageWidth() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int boxHeight = s_emptyAmmo->getImageHeight() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
const Real SPACING = 1.0f * TheInGameUI->getUnitInfoScaleFactor(); | ||
//Int totalWidth = (boxWidth+SPACING)*numTotal; | ||
|
||
ICoord2D screenCenter; | ||
|
@@ -2960,9 +2955,9 @@ void Drawable::drawContained( const IRegion2D *healthBarRegion ) | |
#else | ||
Real scale = 1.0f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like EA already tried to do some scaling here with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scale icons with zoom does not have any real relevance once I properly implement the zoom scaling. But the idea was to rescale the info icons as you zoomed into units so their size was kept uniform relative to the health bar. Which is what I reimplemented. We could still make use of the pipscale factor though. |
||
#endif | ||
Int boxWidth = REAL_TO_INT(s_emptyContainer->getImageWidth() * scale); | ||
Int boxHeight = REAL_TO_INT(s_emptyContainer->getImageHeight() * scale); | ||
const Int SPACING = 1; | ||
Int boxWidth = s_emptyContainer->getImageWidth() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int boxHeight = s_emptyContainer->getImageHeight() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
const Real SPACING = 1.0f * TheInGameUI->getUnitInfoScaleFactor(); | ||
//Int totalWidth = (boxWidth+SPACING)*numTotal; | ||
|
||
ICoord2D screenCenter; | ||
|
@@ -3013,8 +3008,8 @@ void Drawable::drawBattlePlans( const IRegion2D *healthBarRegion ) | |
getIconInfo()->m_icon[ ICON_BATTLEPLAN_BOMBARD ] = newInstance(Anim2D)( s_animationTemplates[ ICON_BATTLEPLAN_BOMBARD ], TheAnim2DCollection ); | ||
} | ||
//Int barHeight = healthBarRegion.hi.y - healthBarRegion.lo.y; | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_BOMBARD ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_BOMBARD ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_BOMBARD ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_BOMBARD ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3041,8 +3036,8 @@ void Drawable::drawBattlePlans( const IRegion2D *healthBarRegion ) | |
getIconInfo()->m_icon[ ICON_BATTLEPLAN_HOLDTHELINE ] = newInstance(Anim2D)( s_animationTemplates[ ICON_BATTLEPLAN_HOLDTHELINE ], TheAnim2DCollection ); | ||
} | ||
// draw the icon | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_HOLDTHELINE ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_HOLDTHELINE ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_HOLDTHELINE ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_HOLDTHELINE ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3069,8 +3064,8 @@ void Drawable::drawBattlePlans( const IRegion2D *healthBarRegion ) | |
getIconInfo()->m_icon[ ICON_BATTLEPLAN_SEARCHANDDESTROY ] = newInstance(Anim2D)( s_animationTemplates[ ICON_BATTLEPLAN_SEARCHANDDESTROY ], TheAnim2DCollection ); | ||
} | ||
// draw the icon | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_SEARCHANDDESTROY ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_SEARCHANDDESTROY ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_BATTLEPLAN_SEARCHANDDESTROY ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_BATTLEPLAN_SEARCHANDDESTROY ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3281,10 +3276,10 @@ void Drawable::drawHealing(const IRegion2D* healthBarRegion) | |
// we are going to draw the healing icon relative to the size of the health bar region | ||
// since that region takes into account hit point size and zoom factor of the camera too | ||
// | ||
Int barWidth = healthBarRegion->hi.x - healthBarRegion->lo.x; | ||
Int barWidth = healthBarRegion->width(); | ||
|
||
Int frameWidth = getIconInfo()->m_icon[ typeIndex ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ typeIndex ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ typeIndex ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ typeIndex ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3344,7 +3339,7 @@ void Drawable::drawEnthusiastic(const IRegion2D* healthBarRegion) | |
// we are going to draw the healing icon relative to the size of the health bar region | ||
// since that region takes into account hit point size and zoom factor of the camera too | ||
// | ||
Int barWidth = healthBarRegion->hi.x - healthBarRegion->lo.x;// used for position | ||
Int barWidth = healthBarRegion->width();// used for position | ||
|
||
// based on our own kind of we have certain icons to display at a size scale | ||
Real scale; | ||
|
@@ -3355,8 +3350,8 @@ void Drawable::drawEnthusiastic(const IRegion2D* healthBarRegion) | |
else | ||
scale = 0.5f; | ||
|
||
Int frameWidth = getIconInfo()->m_icon[ iconIndex ]->getCurrentFrameWidth() * scale; | ||
Int frameHeight = getIconInfo()->m_icon[ iconIndex ]->getCurrentFrameHeight() * scale; | ||
Int frameWidth = getIconInfo()->m_icon[ iconIndex ]->getCurrentFrameWidth() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ iconIndex ]->getCurrentFrameHeight() * scale * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3645,10 +3640,10 @@ void Drawable::drawDisabled(const IRegion2D* healthBarRegion) | |
// draw the icon | ||
if( healthBarRegion ) | ||
{ | ||
Int barHeight = healthBarRegion->hi.y - healthBarRegion->lo.y; | ||
Int barHeight = healthBarRegion->height(); | ||
|
||
Int frameWidth = getIconInfo()->m_icon[ ICON_DISABLED ]->getCurrentFrameWidth(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_DISABLED ]->getCurrentFrameHeight(); | ||
Int frameWidth = getIconInfo()->m_icon[ ICON_DISABLED ]->getCurrentFrameWidth() * TheInGameUI->getUnitInfoScaleFactor(); | ||
Int frameHeight = getIconInfo()->m_icon[ ICON_DISABLED ]->getCurrentFrameHeight() * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
// adjust the width to be a % of the health bar region size | ||
|
@@ -3794,19 +3789,19 @@ void Drawable::drawVeterancy( const IRegion2D *healthBarRegion ) | |
if (!image) | ||
return; | ||
|
||
Real scale = 1.3f/CLAMP_ICON_ZOOM_FACTOR( TheTacticalView->getZoom() ); | ||
#ifdef SCALE_ICONS_WITH_ZOOM_ML | ||
Real scale = 1.3f/CLAMP_ICON_ZOOM_FACTOR( TheTacticalView->getZoom() ); | ||
Real objScale = scale * 1.55f; | ||
#else | ||
Real objScale = 1.0f; | ||
#endif | ||
|
||
|
||
Real vetBoxWidth = image->getImageWidth()*objScale; | ||
Real vetBoxHeight = image->getImageHeight()*objScale; | ||
Real vetBoxWidth = image->getImageWidth() * objScale * TheInGameUI->getUnitInfoScaleFactor(); | ||
Real vetBoxHeight = image->getImageHeight() * objScale * TheInGameUI->getUnitInfoScaleFactor(); | ||
|
||
// | ||
// take the center position of the object, go down to it's bottom extent, and project | ||
// take the center position of the health region, go down to it's bottom extent, and project | ||
// that point to the screen, that will be the "center" of our veterancy box | ||
// | ||
|
||
|
@@ -3816,11 +3811,7 @@ void Drawable::drawVeterancy( const IRegion2D *healthBarRegion ) | |
if( !TheTacticalView->worldToScreen( &p, &screenCenter ) ) | ||
return; | ||
|
||
Real healthBoxWidth, healthBoxHeight; | ||
if (!obj->getHealthBoxDimensions(healthBoxHeight, healthBoxWidth)) | ||
return; | ||
|
||
screenCenter.x += healthBoxWidth * scale * 0.5f; | ||
screenCenter.x += healthBarRegion->width() * 0.65f; | ||
|
||
// draw the image | ||
TheDisplay->drawImage(image, screenCenter.x + 1, screenCenter.y + 1, screenCenter.x + 1 + vetBoxWidth, screenCenter.y + 1 + vetBoxHeight); | ||
|
@@ -3925,23 +3916,32 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion) | |
|
||
} | ||
|
||
Real healthBoxWidth = healthBarRegion->width(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IT looks like it comes up to the black viewport to me in both, the thing that makes it look significnatly bigger is the placement of the contained pips. Something i noticed is that the contained pips seem to integer scale and have a fixed seperation.# There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will make sure to do the same for ammo pips There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In 1280x720 the discrepancy still occurs. Maybe is inevitable because of integer rounding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The images themselves are integer rounded within the image draw functions. so you then have that compounding loss over every extra pip while there is only a single rounding on the health bars width. |
||
Real healthBoxHeight = max((Int)defaultHealthBoxHeight, healthBarRegion->height()); | ||
Real healthBoxOutlineSize = floorf(1.0f * TheInGameUI->getUnitHealthbarScaleFactor()); | ||
|
||
// draw a filled bar for the health | ||
// TheSuperHackers @info this takes up the whole size of the health rect area, the border is drawn over the top | ||
// This simplifies the handling of the health bar | ||
TheDisplay->drawFillRect( healthBarRegion->lo.x, healthBarRegion->lo.y, | ||
healthBoxWidth * healthRatio, healthBoxHeight, | ||
color ); | ||
|
||
|
||
/// Real scale = 1.3f / TheTacticalView->getZoom(); | ||
Real healthBoxWidth = healthBarRegion->hi.x - healthBarRegion->lo.x; | ||
|
||
Real healthBoxHeight = max(3, healthBarRegion->hi.y - healthBarRegion->lo.y); | ||
Real healthBoxOutlineSize = 1.0f; | ||
// draw the health blend line but only for intermediate resolutions | ||
// TheSuperHackers @info we adjust the line down by the thickness of the border to keep it with one line of exposed pixels | ||
if (fmod(healthBoxHeight, defaultHealthBoxHeight) > 0.0f) { | ||
Color outlineBlendColor = outlineColor - 0x77000000; | ||
TheDisplay->drawLine( healthBarRegion->lo.x, healthBarRegion->lo.y + healthBoxOutlineSize, | ||
healthBarRegion->lo.x + healthBoxWidth * healthRatio, healthBarRegion->lo.y + healthBoxOutlineSize, | ||
healthBoxOutlineSize + 1.0f, outlineBlendColor); | ||
} | ||
|
||
// draw the health box outline | ||
TheDisplay->drawOpenRect( healthBarRegion->lo.x, healthBarRegion->lo.y, healthBoxWidth, healthBoxHeight, | ||
// TheSuperHackers @info when drawing the outline, the underlying function grows the outline towards the center of the region | ||
TheDisplay->drawOpenRect( healthBarRegion->lo.x, healthBarRegion->lo.y, | ||
healthBoxWidth, healthBoxHeight, | ||
healthBoxOutlineSize, outlineColor ); | ||
|
||
// draw a filled bar for the health | ||
TheDisplay->drawFillRect( healthBarRegion->lo.x + 1, healthBarRegion->lo.y + 1, | ||
(healthBoxWidth - 2) * healthRatio, healthBoxHeight - 2, | ||
color ); | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retrieved health box height from the object is already 3.0f, at higher resoutions this code prevents the health box from scaling relative to the vehicles and looks wrong. Which is why i removed it.
I reinstated the clamp on the max size of the health bar to prevent it shrinking too much when the resolution is scaled. This will also come into play more when zoom scaling is added.