Skip to content
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

Customizable Bars of Health Points #1395

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

Fryone
Copy link
Contributor

@Fryone Fryone commented Sep 25, 2024

Added customizable health bars in form of BarTypes. By default, technos use their own vanilla healthbars.
Adding HealthBar.BarType changing health bar to this type. Can be applied to buildings.

Example

[BarTypes]                           ; section in rulesmd.ini
0=HEALTHBAR1

[HEALTHBAR1]
BoardBG.File=                        ; filename - without the .shp extension, image for use as background, first frame
BoardBG.ShowWhenNotSelected=false    ; boolean, should background be drawn, when ponting on techno
BoardBG.Translucency=                ; translucency level (0/25/50/75), background image translucency level
BoardFG.File=                        ; filename - without the .shp extension, image for use as foreground (drawn after health sections), first frame
BoardFG.ShowWhenNotSelected=false    ; boolean, should foreground be drawn, when ponting on techno
BoardFG.Translucency=                ; translucency level (0/25/50/75), foreground image translucency level
Board.Offset=0,0                     ; X,Y, offset of background and foreground boards images
Bar.Offset=0,0                       ; X,Y, offset of whole bar
Sections.DrawBackwards=false         ; boolean, changes order of drawing from last to first
Sections.EmptyPip=-1                 ; integer, frame in pips.shp to use for empty section
Sections.Pips=16,17,18               ; list of 3 integers, frames of pips.shp to use (green, yellow, red states)
Sections.Amount=17                   ; integer, amount of sections, when bar is full
Sections.PositionDelta=2,0           ; X,Y, increment in pixels to next section

[SOMETECHNO]
HealthBar.BarType=HEALTHBAR1

No docs for now, needs testing.
image

Initial commit
Copy link

github-actions bot commented Sep 25, 2024

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

@tyuah8
Copy link

tyuah8 commented Sep 26, 2024

Added customizable vertical health bars in form of HealthBarTypes. By default, technos use their own vanilla healthbars. Adding CustomHealthBarType changing health bar to this type. Can be applied to buildings.

Example

[HealthBarTypes]                                                       ; section in rulesmd.ini
0=HEALTHBAR1

[HEALTHBAR1]
Frame.Background=PIPBRD                                      ; shp file for use as background, first frame
Frame.Background.Translucency=0                           ; background translucency level
Frame.Background.ShowWhenNotSelected=false    ; should background be drawn, when ponting on techno
Frame.Foreground=                                                   ; shp file for use as foreground (drawn after health sections), first frame
Frame.Foreground.ShowWhenNotSelected=false     ; should foreground be drawn, when ponting on techno
HealthBar.OffsetX=0                                                  ; horizontal offset, similar to PixelSelectionBracketDelta
Sections.Pips=16,17,18                                              ; frames of pips.shp to use (green, yellow, red states)
Sections.Amount=17                                                 ; amount of sections, when bar is full
Sections.Size=2                                                          ; size in px of individual section

[SOMETECHNO]
CustomHealthBarType=HEALTHBAR1

No docs for now, needs testing. image

Those voxels are quite nice and seem to resemble the look and feel of the original game voxels. Did you make those voxels yourself?

@Fryone
Copy link
Contributor Author

Fryone commented Sep 26, 2024

Those voxels are quite nice and seem to resemble the look and feel of the original game voxels. Did you make those voxels yourself?

yep

@NetsuNegi
Copy link
Contributor

nice feature for epic vehicle/airship/battleship :)

@Metadorius
Copy link
Member

image
Custom Health Bar

@Metadorius
Copy link
Member

Couple of suggestions on the general API stuff:
[HealthBarTypes] => [BarTypes]
In general I propose to treat this as a "custom anything bar" which can be used for HP bars.

For technos the tag should be CustomHealthBarType => HealthBar, less redundancy and more in-line with other things.

I think shields should use that too.

@Metadorius
Copy link
Member

P.S. Can you do any shape/direction bars this way? I think it's a matter of making the section offset customizable in two dimensions, this way you could specify the 2,2 offset and have the bar go diagonal for example.

@Fryone
Copy link
Contributor Author

Fryone commented Sep 26, 2024

P.S. Can you do any shape/direction bars this way? I think it's a matter of making the section offset customizable in two dimensions, this way you could specify the 2,2 offset and have the bar go diagonal for example.

The horizontal (vanilla like) bars were first in mind. I understand vertical ones, but diagonal...

@Fryone Fryone changed the title Custom Health Bars Customizable Bars of Health Points Sep 26, 2024
@Metadorius
Copy link
Member

The horizontal (vanilla like) bars were first in mind. I understand vertical ones, but diagonal...

It's only an example. The point is that if one can specify offset between sections in 2 dimensions then they can come up with whatever weird graphics they want, including diagonal bars, sectioned graphics etc.

@Fryone
Copy link
Contributor Author

Fryone commented Sep 26, 2024

I think, I probably should make some "BarMaker" then, like procedure to draw by position and type.

@chaserli
Copy link
Contributor

#1287 #1309 #1395
#1287 (comment)
If you are making a bar, generalize it to cover all fractionable quantities. HP/SP are just a small part of them. Some should display regardless of mouse hovering/selected.

@Fryone
Copy link
Contributor Author

Fryone commented Sep 27, 2024

#1287 #1309 #1395 #1287 (comment) If you are making a bar, generalize it to cover all fractionable quantities. HP/SP are just a small part of them. Some should display regardless of mouse hovering/selected.

yeah, so the bars can be used to draw without hovering/selecting. i'm just using bar-drawer in the vanilla health part code. So it behaves like vanilla health bar.

@chaserli
Copy link
Contributor

yeah, so the bars can be used to draw without hovering/selecting. i'm just using bar-drawer in the vanilla health part code. So it behaves like vanilla health bar.

I mean you can go more aggressive than that, just replace all 4 DrawHealthBar vtbl calls and handle it as well as other things in drawextras.

- added emptypip
- added draw direction
- added border offset
- changed overall logic
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/New/Type/BarTypeClass.h Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/New/Type/BarTypeClass.h Outdated Show resolved Hide resolved
src/Ext/Techno/Hooks.Pips.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.h Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
src/Ext/Techno/Body.Visuals.cpp Outdated Show resolved Hide resolved
Comment on lines 13 to 17
Nullable<TranslucencyLevel> BoardBG_Translucency;
Nullable<SHPStruct*> BoardFG_File;
Valueable<bool> BoardFG_ShowWhenNotSelected;
Nullable<TranslucencyLevel> BoardFG_Translucency;
Valueable<Vector2D<int>> Board_Offset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why translucency flags are nullable here when they can just be valueables with default 0?

@ZivDero
Copy link
Contributor

ZivDero commented Sep 28, 2024

Also, you're hooking into the function. But the vanilla function is just one big if-else, and you hook both of the branches. You should replace the entire function.

Additionally, your hooks disable other Phobos hooks (shield bars, HeathBar.Height, digital displays). As such, you should move those patches into your replaced function, too.

@Metadorius
Copy link
Member

@Fryone is there anything blocking you from fulfilling the requested changes?

@Fryone
Copy link
Contributor Author

Fryone commented Nov 11, 2024

@Fryone is there anything blocking you from fulfilling the requested changes?

Nothing, I just need to get it. I just need to do it.

Fryone and others added 6 commits November 16, 2024 18:15
- hook refactor
- Healthbar.Hide moved to healthbar hook
- applied some suggested changes
- added ability to choose file for bar pips
- added ShieldBar.BarType

TO DO:
- for now, ShieldBar.BarType dont work without HealthBar.BarType
Comment on lines 300 to 310
int length = pThisIsInf ? 8 : 17;

if (pThisIsBld)
{
position.Y -= (static_cast<BuildingClass*>(pThis)->Type->Height + 1) * Unsorted::CellHeightInPixels / 2;
const int pThisBldTypeWidth = static_cast<BuildingClass*>(pThis)->Type->GetFoundationWidth();
length = pThisBldTypeWidth * 7 + (pThisBldTypeWidth / 2);
}
else
{
position.Y -= pThisIsInf ? 25 : 26;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add constants from here to YRpp (I think) to improve readability

- changed blitterflags
- updated logic with latest hook movements
- shield and health bars can be used separately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants