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

Add support for statbar “off state” icons #9462

Merged
merged 9 commits into from
May 11, 2020

Conversation

Wuzzy2
Copy link
Contributor

@Wuzzy2 Wuzzy2 commented Mar 5, 2020

Closes #6030.

This adds support for optional “off state” icons for statbars. “off state icons” can be used to denote the lack of something, like missing hearts or bubbles.

Implementation

This implementation is 100% network-compatible.

The “off state” image is set by using the text field of the HUD definition. To add the “off state” image, append a slash to the original texture name, then the additional texture name to the text field of the HUD definition. Example: heart.png/heart_gone.png. Here, heart.png is the normal icon, and heart_gone.png is the “off state”. If no slash is found, the background image is disabled.

The “maximum value” is set by using the item field.

For the builtin health bar and breath bar, health_gone.png and breath_gone.png are used, respectively. Note the default images are empty, so games need to add these images first.

Implementation rationale and details

The slash was chosen as this is character is forbidden in most OSes.

I would have loved to provide non-empty default _gone images, but decided aginst that because adding visible images would break compability of existing games. Existing games don't have those images yet and add default images would not fit well together with the game-provided heart.png/bubble.png.

Technically, the “off state” does not act as a background of the normal image. Instead, the “off state” icons replace the normal icons. I decided against using overlays because it would have made drawing semitransparent icons (like bubbles) quite annoying.

To do

This PR is ready for review.

How to test

Use this test mod and use the /statbar command to generate a random statbar (random image count and direction):

local bar = nil

minetest.register_chatcommand("statbar", {
	privs = {},
	description = "Render test statbar",
	params = "[<textures>] | clear",
	func = function(name, param)
		local player = minetest.get_player_by_name(name)
		if not player then
			return false, "No player"
		end
		if bar then
			player:hud_remove(bar)
			bar = nil
		end
		if param == "clear" then
			return true
		end
		if param == "" then
			param = "heart.png/heart_gone.png"
		end
		local dir = math.random(0,3)
		local max = math.random(1,15)
		local num = math.random(0,max)
		minetest.chat_send_player(name, "direction="..dir.."; value="..num.."/"..max)
		bar = player:hud_add({
			hud_elem_type = "statbar",
			number = num,
			item = max,
			size = { x = 24, y = 24 },
			position = { x = 0.5, y = 0.5 },
			offset = { x = - 12, y = -12 },
			text = param,
			direction = dir,
		})
		return true
	end,
})

Additionally, you want to test the behavior or the builtin health and breath statbars. You need to replace heart_gone.png and bubble_gone.png for testing purposes because the default ones are empty/transparent.

@MoNTE48
Copy link
Contributor

MoNTE48 commented Mar 5, 2020

Server 5.2, client 5.0. The client will see only "on state", the behavior will not change?

builtin/game/statbars.lua Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Mar 5, 2020

@sfan5: OK, I introduced a new field text2 for the 2nd texture name.

@MoNTE48: The alt. texture will not appear by default. Read the whole 1st post again.

src/network/networkprotocol.h Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Mar 5, 2020

@sfan5: Done.

@sfan5 sfan5 added the Rebase needed The PR needs to be rebased by its author label Apr 21, 2020
src/client/hud.cpp Outdated Show resolved Hide resolved
src/client/hud.cpp Outdated Show resolved Hide resolved
doc/texture_packs.txt Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Apr 21, 2020

Done, rebased and squashed!

@sfan5 sfan5 removed the Rebase needed The PR needs to be rebased by its author label Apr 21, 2020
doc/texture_packs.txt Outdated Show resolved Hide resolved
@sfan5
Copy link
Member

sfan5 commented Apr 21, 2020


textures/base/pack/heart.png: PNG image data, 12 x 12, 4-bit colormap, non-interlaced
textures/base/pack/heart_gone.png: PNG image data, 12 x 12, 4-bit colormap, non-interlaced

grafik

uh? solved, user error

src/client/hud.cpp Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Apr 21, 2020

Weird about the heart thing. Also tested in Minimal with game-provided heart.png removed. Still not reproducible. Note that heart.png and bubble.png are not even touched in this PR.

@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Apr 21, 2020

Note that MTG uses the wrong size for both heart.png and bubble.png (16×16 instead of 12×12).

Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

Works.

@SmallJoker SmallJoker added the Rebase needed The PR needs to be rebased by its author label Apr 29, 2020
@SmallJoker
Copy link
Member

@Wuzzy2 Would you please be so nice and rebase this PR?

@SmallJoker SmallJoker removed the Rebase needed The PR needs to be rebased by its author label May 10, 2020
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented May 10, 2020

This is ready now!

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Code looks better now. PR works.

Two suggestions in the documentation - what do you think about those?

doc/lua_api.txt Outdated Show resolved Hide resolved
doc/lua_api.txt Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented May 10, 2020

Looks good.

@ClobberXD
Copy link
Contributor

The new item field is somewhat non-descriptive, IMHO. If it denotes the maximum value, why not call it max?

@SmallJoker
Copy link
Member

SmallJoker commented May 11, 2020

@sfan5 Outdated review. Does the PR need any change, or does it still look good?

@sfan5
Copy link
Member

sfan5 commented May 11, 2020

Still looks good, you can fix the comment before merge if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add statbar background icons
5 participants