mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r4092) CodeChange : Named sprites instead of magic numbers plus create/use helper macro/enum for recoloring scheme
This commit is contained in:
parent
74853e619a
commit
26a5b62865
|
@ -352,7 +352,7 @@ static void DrawTile_Industry(TileInfo *ti)
|
||||||
|
|
||||||
/* Pointer to industry */
|
/* Pointer to industry */
|
||||||
ind = GetIndustryByTile(ti->tile);
|
ind = GetIndustryByTile(ti->tile);
|
||||||
ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START;
|
ormod = GENERAL_SPRITE_COLOR(ind->color_map);
|
||||||
|
|
||||||
/* Retrieve pointer to the draw industry tile struct */
|
/* Retrieve pointer to the draw industry tile struct */
|
||||||
dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
|
dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
|
||||||
|
|
3
macros.h
3
macros.h
|
@ -67,7 +67,8 @@ static inline int64 BIGMULS(int32 a, int32 b) {
|
||||||
#define SETBITS(x,y) ((x) |= (y))
|
#define SETBITS(x,y) ((x) |= (y))
|
||||||
#define CLRBITS(x,y) ((x) &= ~(y))
|
#define CLRBITS(x,y) ((x) &= ~(y))
|
||||||
|
|
||||||
#define PLAYER_SPRITE_COLOR(owner) ( (_player_colors[owner] + 0x307) << PALETTE_SPRITE_START)
|
#define GENERAL_SPRITE_COLOR(color) ( (color + PALETTE_RECOLOR_START) << PALETTE_SPRITE_START)
|
||||||
|
#define PLAYER_SPRITE_COLOR(owner) ( GENERAL_SPRITE_COLOR(_player_colors[owner]))
|
||||||
#define SPRITE_PALETTE(x) ((x) | PALETTE_MODIFIER_COLOR)
|
#define SPRITE_PALETTE(x) ((x) | PALETTE_MODIFIER_COLOR)
|
||||||
|
|
||||||
extern const byte _ffb_64[128];
|
extern const byte _ffb_64[128];
|
||||||
|
|
|
@ -2404,7 +2404,7 @@ void SetupColorsAndInitialWindow(void)
|
||||||
int width,height;
|
int width,height;
|
||||||
|
|
||||||
for (i = 0; i != 16; i++) {
|
for (i = 0; i != 16; i++) {
|
||||||
const byte* b = GetNonSprite(0x307 + i);
|
const byte* b = GetNonSprite(PALETTE_RECOLOR_START + i);
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
_color_list[i] = *(const ColorList*)(b + 0xC6);
|
_color_list[i] = *(const ColorList*)(b + 0xC6);
|
||||||
|
|
16
player_gui.c
16
player_gui.c
|
@ -271,7 +271,7 @@ static void SelectPlayerColorWndProc(Window *w, WindowEvent *e)
|
||||||
for (i = 0; i != 16; i++) {
|
for (i = 0; i != 16; i++) {
|
||||||
if (!(used_colors & 1) && --pos < 0 && pos >= -8) {
|
if (!(used_colors & 1) && --pos < 0 && pos >= -8) {
|
||||||
DrawString(x + 30, y, STR_00D1_DARK_BLUE + i, 2);
|
DrawString(x + 30, y, STR_00D1_DARK_BLUE + i, 2);
|
||||||
DrawSprite((i << 16) + 0x3078C1A, x + 14, y + 4);
|
DrawSprite(((GENERAL_SPRITE_COLOR(i) | PALETTE_MODIFIER_COLOR) | SPR_VEH_BUS_SIDE_VIEW), x + 14, y + 4);
|
||||||
y += 14;
|
y += 14;
|
||||||
}
|
}
|
||||||
used_colors >>= 1;
|
used_colors >>= 1;
|
||||||
|
@ -541,8 +541,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
|
||||||
DrawPlayerVehiclesAmount(w->window_number);
|
DrawPlayerVehiclesAmount(w->window_number);
|
||||||
|
|
||||||
DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
|
DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
|
||||||
// Draw company-colour bus (0xC19)
|
// Draw company-colour bus
|
||||||
DrawSprite(PLAYER_SPRITE_COLOR(p->index) + (0xC19 | PALETTE_MODIFIER_COLOR), 215, 49);
|
DrawSprite(PLAYER_SPRITE_COLOR(p->index) + SPRITE_PALETTE(SPR_VEH_BUS_SW_VIEW), 215, 49);
|
||||||
|
|
||||||
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
||||||
|
|
||||||
|
@ -726,11 +726,11 @@ static void BuyCompanyWndProc(Window *w, WindowEvent *e)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Widget _buy_company_widgets[] = {
|
static const Widget _buy_company_widgets[] = {
|
||||||
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||||
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 333, 14, 136, 0x0, STR_NULL},
|
{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 333, 14, 136, 0x0, STR_NULL},
|
||||||
{ WWT_TEXTBTN, RESIZE_NONE, 5, 148, 207, 117, 128, STR_00C9_NO, STR_NULL},
|
{ WWT_TEXTBTN, RESIZE_NONE, 5, 148, 207, 117, 128, STR_00C9_NO, STR_NULL},
|
||||||
{ WWT_TEXTBTN, RESIZE_NONE, 5, 218, 277, 117, 128, STR_00C8_YES, STR_NULL},
|
{ WWT_TEXTBTN, RESIZE_NONE, 5, 218, 277, 117, 128, STR_00C8_YES, STR_NULL},
|
||||||
{ WIDGETS_END},
|
{ WIDGETS_END},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
|
||||||
flag |= 2;
|
flag |= 2;
|
||||||
|
|
||||||
/* draw the gradient */
|
/* draw the gradient */
|
||||||
DrawSprite((color + 0x307) << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR | SPR_GRADIENT, x, y);
|
DrawSprite(GENERAL_SPRITE_COLOR(color) | PALETTE_MODIFIER_COLOR | SPR_GRADIENT, x, y);
|
||||||
|
|
||||||
/* draw the cheeks */
|
/* draw the cheeks */
|
||||||
DrawSprite(cheeks_table[flag&3], x, y);
|
DrawSprite(cheeks_table[flag&3], x, y);
|
||||||
|
@ -74,15 +74,15 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
|
||||||
|
|
||||||
if (!(flag & 2)) {
|
if (!(flag & 2)) {
|
||||||
if (!(flag & 1)) {
|
if (!(flag & 1)) {
|
||||||
DrawSprite(high+((val1 * 12 >> 4) + (0x32B | PALETTE_MODIFIER_COLOR)), x, y);
|
DrawSprite(high+((val1 * 12 >> 4) + SPRITE_PALETTE(0x32B)), x, y);
|
||||||
} else {
|
} else {
|
||||||
DrawSprite(high+(val1 + (0x337 | PALETTE_MODIFIER_COLOR)), x, y);
|
DrawSprite(high+(val1 + (0x337 | PALETTE_MODIFIER_COLOR)), x, y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(flag & 1)) {
|
if (!(flag & 1)) {
|
||||||
DrawSprite(high+((val1 * 11 >> 4) + (0x39A | PALETTE_MODIFIER_COLOR)), x, y);
|
DrawSprite(high+(val1 + SPRITE_PALETTE(0x337)), x, y);
|
||||||
} else {
|
} else {
|
||||||
DrawSprite(high+(val1 + (0x3B8 | PALETTE_MODIFIER_COLOR)), x, y);
|
DrawSprite(high+(val1 + SPRITE_PALETTE(0x3B8)), x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,7 +615,7 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
|
||||||
FOR_ALL_PLAYERS(p) {
|
FOR_ALL_PLAYERS(p) {
|
||||||
if (p->is_active) {
|
if (p->is_active) {
|
||||||
_owner_colors[p->index] =
|
_owner_colors[p->index] =
|
||||||
dup_byte32(GetNonSprite(775 + p->player_color)[0xCB]); // XXX - magic pixel
|
dup_byte32(GetNonSprite(PALETTE_RECOLOR_START + p->player_color)[0xCB]); // XXX - magic pixel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -700,6 +700,9 @@ enum Sprites {
|
||||||
SPR_FLAG_VEH_STOPPED = 3090,
|
SPR_FLAG_VEH_STOPPED = 3090,
|
||||||
SPR_FLAG_VEH_RUNNING = 3091,
|
SPR_FLAG_VEH_RUNNING = 3091,
|
||||||
|
|
||||||
|
SPR_VEH_BUS_SW_VIEW = 3097,
|
||||||
|
SPR_VEH_BUS_SIDE_VIEW = 3098,
|
||||||
|
|
||||||
/* Rotor sprite numbers */
|
/* Rotor sprite numbers */
|
||||||
SPR_ROTOR_STOPPED = 3901,
|
SPR_ROTOR_STOPPED = 3901,
|
||||||
SPR_ROTOR_MOVING_1 = 3902,
|
SPR_ROTOR_MOVING_1 = 3902,
|
||||||
|
@ -1133,6 +1136,10 @@ assert_compile( (1 << RECOLOR_BIT & PALETTE_SPRITE_MASK) == 0 );
|
||||||
assert_compile( (PALETTE_SPRITE_MASK & SPRITE_MASK) == 0 );
|
assert_compile( (PALETTE_SPRITE_MASK & SPRITE_MASK) == 0 );
|
||||||
assert_compile( SPRITE_WIDTH + PALETTE_SPRITE_WIDTH <= 30 );
|
assert_compile( SPRITE_WIDTH + PALETTE_SPRITE_WIDTH <= 30 );
|
||||||
|
|
||||||
|
enum Recoloring {
|
||||||
|
PALETTE_RECOLOR_START = 0x307,
|
||||||
|
};
|
||||||
|
|
||||||
#define PALETTE_RECOLOR_SPRITE(a) (a << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR)
|
#define PALETTE_RECOLOR_SPRITE(a) (a << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR)
|
||||||
enum PaletteSprites {
|
enum PaletteSprites {
|
||||||
//note: these numbers are already the modified once the renderer needs.
|
//note: these numbers are already the modified once the renderer needs.
|
||||||
|
@ -1149,8 +1156,8 @@ enum PaletteSprites {
|
||||||
//use this if you add stuff to the value, so that the resulting color
|
//use this if you add stuff to the value, so that the resulting color
|
||||||
//is not a fixed value.
|
//is not a fixed value.
|
||||||
//NOTE THAT THE SWITCH 0x8000 is NOT present in _TO_COLORS yet!
|
//NOTE THAT THE SWITCH 0x8000 is NOT present in _TO_COLORS yet!
|
||||||
PALETTE_TO_COLORS = 0x307 << PALETTE_SPRITE_START,
|
PALETTE_TO_COLORS = PALETTE_RECOLOR_START << PALETTE_SPRITE_START,
|
||||||
PALETTE_TO_DARK_BLUE = PALETTE_RECOLOR_SPRITE(0x307),
|
PALETTE_TO_DARK_BLUE = PALETTE_RECOLOR_SPRITE(PALETTE_RECOLOR_START),
|
||||||
PALETTE_TO_PALE_GREEN = PALETTE_RECOLOR_SPRITE(0x308),
|
PALETTE_TO_PALE_GREEN = PALETTE_RECOLOR_SPRITE(0x308),
|
||||||
PALETTE_TO_PINK = PALETTE_RECOLOR_SPRITE(0x309),
|
PALETTE_TO_PINK = PALETTE_RECOLOR_SPRITE(0x309),
|
||||||
PALETTE_TO_YELLOW = PALETTE_RECOLOR_SPRITE(0x30A),
|
PALETTE_TO_YELLOW = PALETTE_RECOLOR_SPRITE(0x30A),
|
||||||
|
|
|
@ -2052,7 +2052,7 @@ static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player)
|
||||||
|
|
||||||
/* XXX Magic 0x307 is the first company colour remap sprite */
|
/* XXX Magic 0x307 is the first company colour remap sprite */
|
||||||
map = HASBIT(_engine_info[engine_type].misc_flags, EF_USES_2CC) ?
|
map = HASBIT(_engine_info[engine_type].misc_flags, EF_USES_2CC) ?
|
||||||
(SPR_2CCMAP_BASE + colour + colour * 16) : (0x307 + colour);
|
(SPR_2CCMAP_BASE + colour + colour * 16) : (PALETTE_RECOLOR_START + colour);
|
||||||
|
|
||||||
return SPRITE_PALETTE(map << PALETTE_SPRITE_START);
|
return SPRITE_PALETTE(map << PALETTE_SPRITE_START);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue