mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
(svn r20254) -Add: allow NewGRFs to specify their palette
This commit is contained in:
parent
e469a94a2d
commit
4a4f02dc81
@ -5931,6 +5931,27 @@ static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf)
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Callback function for 'INFO'->'PALS' to set the number of valid parameters. */
|
||||
static bool ChangeGRFPalette(size_t len, ByteReader *buf)
|
||||
{
|
||||
if (len != 1) {
|
||||
grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE ", ignoring this field", len);
|
||||
buf->Skip(len);
|
||||
} else {
|
||||
char data = buf->ReadByte();
|
||||
switch (data) {
|
||||
case '*':
|
||||
case 'A': _cur_grfconfig->palette |= GRFP_GRF_ANY; break;
|
||||
case 'W': _cur_grfconfig->palette |= GRFP_GRF_WINDOWS; break;
|
||||
case 'D': _cur_grfconfig->palette |= GRFP_GRF_DOS; break;
|
||||
default:
|
||||
grfmsg(2, "StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef bool (*DataHandler)(size_t, ByteReader *); ///< Type of callback function for binary nodes
|
||||
typedef bool (*TextHandler)(byte, const char *str); ///< Type of callback function for text nodes
|
||||
typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes
|
||||
@ -6018,6 +6039,7 @@ AllowedSubtags _tags_info[] = {
|
||||
AllowedSubtags('NAME', ChangeGRFName),
|
||||
AllowedSubtags('DESC', ChangeGRFDescription),
|
||||
AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
|
||||
AllowedSubtags('PALS', ChangeGRFPalette),
|
||||
AllowedSubtags()
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,12 @@ const char *GRFConfig::GetDescription() const
|
||||
*/
|
||||
void GRFConfig::SetSuitablePalette()
|
||||
{
|
||||
PaletteType pal = _use_palette;
|
||||
PaletteType pal;
|
||||
switch (this->palette & GRFP_GRF_MASK) {
|
||||
case GRFP_GRF_DOS: pal = PAL_DOS; break;
|
||||
case GRFP_GRF_WINDOWS: pal = PAL_WINDOWS; break;
|
||||
default: pal = _use_palette; break;
|
||||
}
|
||||
SB(this->palette, GRFP_USE_BIT, 1, pal == PAL_WINDOWS ? GRFP_USE_WINDOWS : GRFP_USE_DOS);
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,18 @@ enum GRFListCompatibility {
|
||||
/** Information that can/has to be stored about a GRF's palette. */
|
||||
enum GRFPalette {
|
||||
GRFP_USE_BIT = 0, ///< The bit used for storing the palette to use.
|
||||
GRFP_GRF_OFFSET = 2, ///< The offset of the GRFP_GRF data.
|
||||
GRFP_GRF_SIZE = 2, ///< The size of the GRFP_GRF data.
|
||||
|
||||
GRFP_USE_DOS = 0x0, ///< The palette state is set to use the DOS palette.
|
||||
GRFP_USE_WINDOWS = 0x1, ///< The palette state is set to use the Windows palette.
|
||||
GRFP_USE_MASK = 0x1, ///< Bitmask to get only the use palette use states.
|
||||
|
||||
GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET, ///< The NewGRF provided no information.
|
||||
GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET, ///< The NewGRF says the DOS palette can be used.
|
||||
GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET, ///< The NewGRF says the Windows palette can be used.
|
||||
GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS, ///< The NewGRF says any palette can be used.
|
||||
GRFP_GRF_MASK = GRFP_GRF_ANY, ///< Bitmask to get only the NewGRF supplied information.
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user