Skip to content

Commit

Permalink
melee: Use animation 0 to render unselected HARs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nopey committed Dec 2, 2024
1 parent 6add65e commit ca16acf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/game/scenes/melee.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ static void render_har_select(melee_local *local, bool player2_is_selectable) {

// render the stupid unselected HAR portraits before anything
// so we can render anything else on top of them
object_render(&local->unselected_har_portraits);
render_highlights(local, player2_is_selectable);
render_disabled_portraits(local->har_portraits);

// currently selected player
object_render(&local->big_portrait_1);
Expand Down Expand Up @@ -654,35 +654,28 @@ static void load_pilot_portraits(scene *scene, melee_local *local) {
}

static void load_har_portraits(scene *scene, melee_local *local) {
sprite *current;
portrait *target;
int row, col;
animation *har_portraits = &bk_get_info(scene->bk_data, 1)->ani;
vga_palette *bk_pal = bk_get_palette(scene->bk_data, 0);

// Use a composite palette to help grayscale rendering
vga_palette pal;
palette_copy(&pal, bk_pal, 0, 255);
palette_load_altpal_player_color(&pal, 0, 16, 0);
palette_load_altpal_player_color(&pal, 0, 16, 1);
palette_load_altpal_player_color(&pal, 0, 16, 2);
sprite *sheet = animation_get_sprite(har_portraits, 0);

for(int i = 0; i < 10; i++) {
row = i / 5;
col = i % 5;
target = &local->har_portraits[i];

// Copy the HAR image in full color (shown when selected)
current = animation_get_sprite(har_portraits, 0);
target->x = current->pos.x + 62 * col;
target->y = current->pos.y + 42 * row;
surface_create_from_surface(&target->enabled, 51, 36, 62 * col, 42 * row, current->data);
target->x = sheet->pos.x + 62 * col;
target->y = sheet->pos.y + 42 * row;
surface_create_from_surface(&target->enabled, 51, 36, 62 * col, 42 * row, sheet->data);
surface_set_transparency(&target->enabled, 0xD0);

// Copy the enabled image, and compress the colors to grayscale
surface_create_from(&target->disabled, &target->enabled);
surface_convert_to_grayscale(&target->disabled, &pal, 0xD0, 0xDF, 0);
}

// convert BK's sheet sprite to grayscale and use it for the unselected_har_portraits
surface_convert_har_to_grayscale(sheet->data, 8);
object_create_static(&local->unselected_har_portraits, scene->gs);
object_set_animation(&local->unselected_har_portraits, har_portraits);
object_select_sprite(&local->unselected_har_portraits, 0);
}

static void load_hars(scene *scene, melee_local *local, bool player2_is_selectable) {
Expand Down
11 changes: 11 additions & 0 deletions src/video/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ void surface_convert_to_grayscale(surface *sur, const vga_palette *pal, int rang
sur->guid = guid++;
}

void surface_convert_har_to_grayscale(surface *sur, uint8_t brightness) {
uint8_t idx;
for(int i = 0; i < sur->w * sur->h; i++) {
idx = sur->data[i];
if(idx != sur->transparent && idx < 0x60) {
sur->data[i] = 0xD0 + brightness * (idx % 0x10) / 0x0F;
}
}
sur->guid = guid++;
}

void surface_compress_index_blocks(surface *sur, int range_start, int range_end, int block_size, int amount) {
uint8_t idx, real_start, old_idx, new_idx;
for(int i = 0; i < sur->w * sur->h; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/video/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ void surface_compress_remap(surface *sur, int range_start, int range_end, int re
void surface_convert_to_grayscale(surface *sur, const vga_palette *pal, int range_start, int range_end,
int ignore_below);

/**
* Convert surface's har colors to grayscale.
* Remaps blocks of 16 colors in the range 0x00..0x5F to 0xD0..=0xDF.
* Leaves other colors, and the transparent color alone.
*
* @param sur Surface to convert
* @param brightness How bright to make the result (range 0x0.=0xF)
*/
void surface_convert_har_to_grayscale(surface *sur, uint8_t brightness);

/**
* Write surface to a PNG file.
*
Expand Down

0 comments on commit ca16acf

Please sign in to comment.