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

AGS 4: Support proper 32-bit color values #2501

Merged

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Aug 17, 2024

Resolves #1980

What is done:

  • Color numbers encode 32-bit R8G8B8,
  • Color properties correctly map R-G-B input to a 32-bit color number,
  • Color Finder updated to display correct 32-bit values and matching colors, ignoring special 0-31 entries,
  • 8-bit games should still interpret color numbers as palette indexes,
  • Game.GetColorFromRGB script function updated to return a 32-bit R8G8B8,
  • Old projects are updated on import, all color properties converted from 16-bit R5G6B5 to 32-bit R8G8B8 (except when it's a 8-bit game).
  • Reimplemented use of hardcoded colors in some parts of the game, like built-in dialogs, etc.
  • Cursor's hotspot crosshair colors are saved as int32 in game data (was saved as int16).
  • Default color values in the Editor (Character speech color, GUI colors etc), - these are currently set as 0-31 palette indexes. We cannot have "default values" for more than 1 mode simultaneously; so I left these for now, and made them converted to the current mode when adding an item in the editor.
  • Editor now converts all color properties when Color Depth setting is switched (between palette index and RGB number).
  • Engine updates color values when loading older games. I also increased save versions, but did not do any upgrade there (it may be added later if really needed).

Additionally:

  • Merged pairs of Color/ColorNumber properties into a single one (keeping data format unchanged), which displays a color value differently depending on the Game's ColorDepth setting. The color picker only works in 32-bit mode for now, but some kind of "palette picker" may be implemented in the future if desired.

What is left:

  • Alpha value is not settable yet, and is always assumed as 255 when color is used to draw anything in the engine. But alpha should rather be addressed as a separate task. Also color properties should maybe changed from int to uint for this; alternatively they should use a custom editor attribute that displays unsigned numbers (or maybe in hex).

@ivan-mogilko ivan-mogilko added this to the 4.0.0 (preliminary) milestone Aug 17, 2024
@ivan-mogilko ivan-mogilko force-pushed the ags4--32bitcolorindex branch 3 times, most recently from b04f82a to 9c3adae Compare August 18, 2024 06:02
@ivan-mogilko ivan-mogilko force-pushed the ags4--32bitcolorindex branch from 373b64a to 0097445 Compare August 27, 2024 17:04
@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Aug 27, 2024

I've been wondering, would that make sense to handle existing duality of Color / ColorNumber properties by hiding one of this pair depending on the current game's color depth? That is - display ColorNumber if game is 8-bit and Color (rgb) if game is 32-bit.

But then, it would also be nice to have color displayed on ColorNumber field. Maybe even add a [...] ColorNumber property which opens a palette for selecting a color.

Alternatively, how feasible that would be to merge Color and ColorNumber properties together?
Only ColorNumber is serialized, and Color (rgb) field is there only for editing at design time. This makes it possible to remove one, rename ColorNumber's "display name" to just Color. But the biggest question is whether it would be possible to change the looks and functionality of the field depending on game settings. Supposedly the field may have a custom editor attribute, that draws the field and provides [...] button depending on some condition.

@ivan-mogilko ivan-mogilko force-pushed the ags4--32bitcolorindex branch from 46a98fc to e886ca4 Compare August 27, 2024 21:02
@ivan-mogilko ivan-mogilko marked this pull request as ready for review August 27, 2024 21:02
@ivan-mogilko
Copy link
Contributor Author

The "Github Actions" are failing because of the test games. I suspect the DrawingSurface tests will have to be adjusted after this is merged.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Aug 28, 2024

I managed to figure out how to make a property that may have two meanings and textual representation in a PropertyGrid, depending on game settings (see two commits above).

This lets merge a pair of properties ColorNumber and Color (rgb) into a single one. I used "ColorNumber", since it's the one that was serialized, so to keep data format unmodified.

The idea is that this property will now look like a "color number" if the game is 8-bit, and like a RGB string when the game is 32-bit. Internally it is always integer (either palette index, or encoded RGB). In 32-bit mode it opens color picker on pressing a button. In 8-bit mode button is removed, but in theory it might be possible to implement a "palette selector" in the future.

Merged all existing color property pairs into a single property (in character, gui, etc), and even made "cursor hotspot colors" properties to work the same way, so you can have a colored rectangle and color picker there too, without adding more properties.

Same property depending on a game setting:
doublecolorproperty

@ivan-mogilko
Copy link
Contributor Author

If I understood right, @AlanDrake have tested this PR (he mentioned this on Discord).

@AlanDrake
Copy link
Contributor

Yes. I've tested upgrading a 32bit project, a 8bit one, and some simple DynamicSprite drawings.

Avoid any special numbers, etc.
Alpha component  is not applied yet (and there's no way to set it in the color picker).
This is necessary because we have default values of color properties set in palette indexes. But also because it's not possible to set two default values for 8-bit and 32-bit modes.
So if we leave these defaults in 8-bit, we have to convert to 32-bit after an item is created and added in game.
This lets to have a single property which is displayed on a PropertyGrid in one of two ways: as a RGB color or as a palette index number.
The mode is switched by the Editor on game load and on Game's ColorDepth setting change.
Have a single *Color property which meaning and textual representation changes with the Game's ColorDepth.
@ivan-mogilko ivan-mogilko force-pushed the ags4--32bitcolorindex branch from 14b9520 to 57c328f Compare August 30, 2024 18:25
@ivan-mogilko
Copy link
Contributor Author

Alright, fingers crossed...

@ivan-mogilko ivan-mogilko merged commit a34c748 into adventuregamestudio:ags4 Sep 1, 2024
17 of 21 checks passed
@ivan-mogilko ivan-mogilko deleted the ags4--32bitcolorindex branch September 1, 2024 14:01
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.

2 participants