Phobos icon indicating copy to clipboard operation
Phobos copied to clipboard

Customizable Bars (Health, Shield and much more)

Open Fryone opened this issue 1 year ago • 32 comments

Added customizable bars in form of BarTypes.

Example

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

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

[AudioVisual]
Buildings.DefaultBarTypes= ;list of bar types
Infantry.DefaultBarTypes= ;list of bar types
Vehicles.DefaultBarTypes= ;list of bar types
Aircraft.DefaultBarTypes= ;list of bar types

[SOMETECHNO]
BarTypes= ;list of bar types

No docs for now, needs testing. image

Fryone avatar Sep 25 '24 17:09 Fryone

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.

github-actions[bot] avatar Sep 25 '24 17:09 github-actions[bot]

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?

tyuah8 avatar Sep 26 '24 03:09 tyuah8

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

Fryone avatar Sep 26 '24 03:09 Fryone

nice feature for epic vehicle/airship/battleship :)

NetsuNegi avatar Sep 26 '24 12:09 NetsuNegi

image Custom Health Bar

Metadorius avatar Sep 26 '24 17:09 Metadorius

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 avatar Sep 26 '24 17:09 Metadorius

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.

Metadorius avatar Sep 26 '24 17:09 Metadorius

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 avatar Sep 26 '24 18:09 Fryone

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.

Metadorius avatar Sep 26 '24 18:09 Metadorius

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

Fryone avatar Sep 26 '24 18:09 Fryone

#1287 #1309 #1395 https://github.com/Phobos-developers/Phobos/pull/1287#issuecomment-2198477945 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.

chaserli avatar Sep 27 '24 15:09 chaserli

#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.

Fryone avatar Sep 27 '24 15:09 Fryone

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.

chaserli avatar Sep 27 '24 15:09 chaserli

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.

ZivDero avatar Sep 28 '24 20:09 ZivDero

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

Metadorius avatar Nov 11 '24 07:11 Metadorius

@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 avatar Nov 11 '24 07:11 Fryone

A practical feature, let me share my ideas. Can we consider a similar approach to DigitalDisplayType, no longer confined to individual HealthBar.BarType or ShieldBar.BarType, but using InfoType in BarType to define what values to display? In addition, can we encapsulate the drawing functions that mimic the vanilla style to reserve some space for future additions of different drawing methods (such as custom grid spacing, sharing the same grid, or even a single shp)?

CrimRecya avatar Mar 11 '25 04:03 CrimRecya

@Fryone any response on the comments?

Metadorius avatar Apr 19 '25 09:04 Metadorius

I'm thinking if I should just finish whats done without any new logic changes (which is yrpp constants and docs)

Fryone avatar Apr 19 '25 09:04 Fryone

I'm thinking if I should just finish whats done without any new logic changes (which is yrpp constants and docs)

On the InfoType: while I am not sure which approach is better, I do agree that it would be better to have this part common between digital displays and bars. Essentially, bars and digital displays do the same thing but in a bit different way, so they should be similar in use.

From what I understood, @CrimRecya (and previously @chaserli too) suggest a unified way to draw all such indicators and a "framework" of sorts, which is pretty logical.

Metadorius avatar Apr 19 '25 09:04 Metadorius

If possible, I also believe that #1422 is the best solution. But it requires a lot of effort, so I would like to ask for your opinion. Can you help complete this framework? if you don't have that much time either, perhaps we can also consider merging this pr first and modifying it in the future and using the migration document.

CrimRecya avatar Apr 19 '25 09:04 CrimRecya

the idea:

[InfoDisplayTypes] DisplayFormatType= ; BarType / DigitalDisplayType InfoType= ; Displayed value enumeration (health|shield|ammo|mindcontrol|spawns|passengers|tiberium|experience|occupants|gattlingstage) //all positioning and visibility related stuff//

Fryone avatar Apr 19 '25 09:04 Fryone

I prefer to use separated BarType and DigitalDisplayType. BarType may require some other drawing method, while DigitalDisplayType does not; DigitalDisplayType may need to display like a timer, while BarType does not. It's just that their data sources are all from InfoType. For example, in this pr, simply change the data source to InfoType. When no custom bars are defined, just use the default health and shield bar. Then this PR can be included as a part of the framework.

CrimRecya avatar Apr 19 '25 09:04 CrimRecya

Considering that the vanillia filename is called "pips.shp", "pipbrd.shp", maybe it's better to use PipBrd and Pips instead of BoardBG and Section

NetsuNegi avatar Apr 21 '25 00:04 NetsuNegi

from design perspective https://github.com/Phobos-developers/Phobos/pull/1635 is clearer and more universal, but since that one is closed, I think we should tweak this PR a bit to make it use generic Pip tags, instead of BoardBG/FG which is kinda hard to be understood and can't be extended to other type of bars in the future

Coronia avatar Jun 23 '25 09:06 Coronia

from design perspective #1635 is clearer and more universal

Can you list what specifically needs improvement with examples? I think @Fryone could incorporate @NetsuNegi's improvements over this PR, or @NetsuNegi could submit some changes as he has edit rights as a maintainer.

Metadorius avatar Jun 23 '25 10:06 Metadorius

I already changed tag names, just not uploaded it here. Plus, there is something that using any shield bar type would crash game.

Fryone avatar Jun 23 '25 10:06 Fryone

latest look

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

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

[AudioVisual] Buildings.DefaultBarTypes= ;list of bar types Infantry.DefaultBarTypes= ;list of bar types Vehicles.DefaultBarTypes= ;list of bar types Aircraft.DefaultBarTypes= ;list of bar types

[SOMETECHNO] BarTypes= ;list of bar types

Fryone avatar Jun 23 '25 19:06 Fryone

Planned:

  1. Proper calculations;
  2. Adding "DrawEmptyBar" for some infotypes;
  3. Adding support for new infotypes;
  4. Fixing bars for shields.

Fryone avatar Jun 23 '25 19:06 Fryone

Here are some ideas for the custom health bar:

1.Multi-layer health bar.Like this. image image

2.Add light-colored pips that temporary appear for a few frames when taking damage, indicating the amount of damage taken per hit. image

A1026K78B avatar Aug 17 '25 03:08 A1026K78B