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

UI polish #181

Merged
merged 1 commit into from
Jan 1, 2024
Merged

UI polish #181

merged 1 commit into from
Jan 1, 2024

Conversation

Hop311
Copy link
Contributor

@Hop311 Hop311 commented Dec 26, 2023

  • Added GFXButtonStateTexture which modifies the base/normal image in the same way as Vic2 does:
    • hover - +0.1f to each colour component (clamped)
    • pressed - -0.1f to each colour component (clamped)
    • disabled - make greyscale using standard luminance coefficients
  • Added support for block colour font/back segments for progress bars, used when the corresponding texture isn't defined/fails to load (all vanilla ProgressBars have both colours defined, but not all of them have the textures defined).

@Spartan322 Spartan322 added the enhancement New feature or request label Dec 26, 2023
@Spartan322
Copy link
Member

Tested on Linux, personally I prefer how the UI states are handled here, it feels more consistent and obvious imo compared to how Victoria 2 does it, but keeping this could be considered to be distinct from Victoria 2.

@Hop311
Copy link
Contributor Author

Hop311 commented Dec 28, 2023

Tested on Linux, personally I prefer how the UI states are handled here, it feels more consistent and obvious imo compared to how Victoria 2 does it, but keeping this could be considered to be distinct from Victoria 2.

Hover and pressed look fine, fairly similar to Vic2 anyway, but disabled look much worse IMO. I'm going to implement a custom class extending ImageTexture which generates a monochrome and 10% whiter version of the normal texture (always either GFXIconTexture or GFXMaskedFlagTexture) and is connect by a signal so it updates itself whenever the base texture changes.

@Spartan322
Copy link
Member

Spartan322 commented Dec 28, 2023

Why can't you just make such a modification a disabled style? Why would you need to update it like that?

@Hop311
Copy link
Contributor Author

Hop311 commented Dec 28, 2023

Why can't you just make such a modification a disabled style? Why would you need to update it like that?

It would be using a separate disabled stylebox, when I said update on the normal texture changing I meant stuff like a flag changing to a different country, so regenerate the modified image when the normal image changes completely.

@Spartan322
Copy link
Member

Spartan322 commented Dec 28, 2023

That's fine, you can modify the look of textures with a stylebox, like you can just make a new derived stylebox that modify the draw however you want, there is no need to manually manage it. (and its automatically handled by Godot anyway)

@Hop311
Copy link
Contributor Author

Hop311 commented Dec 29, 2023

That's fine, you can modify the look of textures with a stylebox, like you can just make a new derived stylebox that modify the draw however you want, there is no need to manually manage it. (and its automatically handled by Godot anyway)

Oh yeah that sounds better, same texture referenced everywhere just changed by the stylebox. My only concern is will the stylebox have to calculate the modified version pixel by pixel every frame, as opposed to only when the base texture changes and caching after that? Unless there's a way to grey-ify and lerp images with a colour other than pixel by pixel calculations.

@Spartan322
Copy link
Member

Spartan322 commented Dec 29, 2023

My only concern is will the stylebox have to calculate the modified version pixel by pixel every frame,

What you could do is have a texture exist in a control, have a stylebox for that control that can get the texture and draws it modified, then what you do is whenever you change that control's texture, you call queue_redraw, and now whenever that texture changes or the stylebox is swapped out or changed, it'll draw it as you want. (you can't store any values of the control in the stylebox, you can retrieve them from control in the stylebox though)

@Hop311
Copy link
Contributor Author

Hop311 commented Dec 30, 2023

My only concern is will the stylebox have to calculate the modified version pixel by pixel every frame,

What you could do is have a texture exist in a control, have a stylebox for that control that can get the texture and draws it modified, then what you do is whenever you change that control's texture, you call queue_redraw, and now whenever that texture changes or the stylebox is swapped out or changed, it'll draw it as you want. (you can't store any values of the control in the stylebox, you can retrieve them from control in the stylebox though)

Looking through RenderingServer, I can't see any way to achieve what I need for disabled with draw methods - that is, convert RGB to greyscale by calculating each pixel's luminance. I think I'm going to have to generate a modifier Image, and it'll be faster to only generate when the normal image changes rather than on every redraw.

@Hop311 Hop311 marked this pull request as ready for review December 30, 2023 15:01
@Spartan322
Copy link
Member

Spartan322 commented Dec 30, 2023

Might need to consider RenderingDevice as well, also draw functions in Godot don't generally run every frame, CanvasItem.queue_redraw() is necessary when you modify the values of a node that changes the node's draw behavior, Resource.emit_change() is necessary for resources whose value changes (specifically styleboxes) if you don't run either of these functions on change, the common draw functions never update the draw behavior. I was thinking maybe you could use something like Texture2DRD but I'm not actually sure how to deal with that.

@Hop311
Copy link
Contributor Author

Hop311 commented Jan 1, 2024

godot-cpp doesn't provide access to RenderingDevice, and I can't see a way to use it to draw an image as luma greyscale (so each pixel is 0.2126f * r + 0.7152f * g + 0.0722f * b), except maybe generating a byte array containing the modified image and using it to create a texture, which is basically what I'm already doing.

@Spartan322
Copy link
Member

Spartan322 commented Jan 1, 2024

Just to point out godot-cpp does provide access to the RenderingDevice: RenderingServer.get_rendering_device(). To get the RenderingServer you do RenderingServer::get_singleton() so in total you do RenderingServer::get_singleton()->get_rendering_device() which returns a pointer of the RenderingDevice.

Copy link
Member

@Spartan322 Spartan322 left a comment

Choose a reason for hiding this comment

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

Works on Linux

@Hop311
Copy link
Contributor Author

Hop311 commented Jan 1, 2024

Just to point out godot-cpp does provide access to the RenderingDevice: RenderingServer.get_rendering_device(). To get the RenderingServer you do RenderingServer::get_singleton() so in total you do RenderingServer::get_singleton()->get_rendering_device() which returns a pointer of the RenderingDevice.

Oh so it does, thanks for pointing that out, my VSCode search was bugged, fixed now with a restart.

@Hop311 Hop311 merged commit cf34ce1 into master Jan 1, 2024
16 checks passed
@Hop311 Hop311 deleted the ui-state-style branch January 1, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants