Skip to content

Commit

Permalink
Merge pull request #103 from savaughn/optimize-images
Browse files Browse the repository at this point in the history
optimized text pngs
  • Loading branch information
savaughn authored Nov 21, 2023
2 parents 284c6d2 + bb12f22 commit d6bf1e9
Show file tree
Hide file tree
Showing 31 changed files with 55,760 additions and 81 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
run: |
# Copy assets to the same directory as the executable
mkdir -p build/assets
cp -r assets/images build/assets/images
- name: Publish Build Artifacts
uses: actions/upload-artifact@v2
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ jobs:
# Copy assets
mkdir -p "${MACOS_DESTINATION}/../Resources/assets"
cp -r "${{ github.workspace }}/assets/images" "${MACOS_DESTINATION}/../Resources/assets"
cp "${{ github.workspace }}/assets/icon.icns" "${MACOS_DESTINATION}/../Resources"
# Create Info.plist file
Expand Down Expand Up @@ -188,7 +187,6 @@ jobs:
# Copy assets
mkdir -p "${MACOS_DESTINATION}/../Resources/assets"
cp -r "${{ github.workspace }}/assets/images" "${MACOS_DESTINATION}/../Resources/assets"
cp "${{ github.workspace }}/assets/icon.icns" "${MACOS_DESTINATION}/../Resources"
# Create Info.plist file
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
mkdir -p build/assets
cp assets/icon.ico build/assets/icon.ico
cp assets/pkrom.rc.data build/assets/pkrom.rc.data
cp -r assets/images build/assets
- name: Publish Build Artifacts
uses: actions/upload-artifact@v2
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 0 additions & 5 deletions assets/images/Pixel_Fantasy_Icons_Consoles/EULA - READ ME.txt

This file was deleted.

Binary file removed assets/images/evolve.png
Binary file not shown.
Binary file removed assets/images/logo-text.png
Binary file not shown.
Binary file removed assets/images/pokeballs_MPR/ball_0.png
Binary file not shown.
Binary file removed assets/images/pokeballs_MPR/ball_1.png
Binary file not shown.
Binary file removed assets/images/pokeballs_MPR/ball_2.png
Binary file not shown.
Binary file removed assets/images/pokeballs_MPR/ball_3.png
Binary file not shown.
Binary file removed assets/images/quit.png
Binary file not shown.
Binary file removed assets/images/settings.png
Binary file not shown.
Binary file removed assets/images/trade.png
Binary file not shown.
55,709 changes: 55,709 additions & 0 deletions include/textures.h

Large diffs are not rendered by default.

99 changes: 39 additions & 60 deletions src/raylibhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "filehelper.h"
#include "pksavhelper.h"
#include "pksavfilehelper.h"
#include "textures.h"
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#endif
Expand All @@ -10,7 +11,7 @@ void draw_background_grid(void)
{
int line_count_v = SCREEN_HEIGHT / 10;
int line_count_h = SCREEN_WIDTH / 10;

// draw line grid color_pkmn_red
for (int i = 0; i < line_count_v; i++)
{
Expand Down Expand Up @@ -44,29 +45,6 @@ void create_trainer_id_str(const struct trainer_info *trainer, char *trainer_id)
strcat(trainer_id, id_str);
}

#if defined(__APPLE__)
void get_mac_resource_images_path(void)
{
// Get the path to the bundle's resources directory
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(bundle);
char resources_path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resources_url, true, (UInt8 *)resources_path, PATH_MAX))
{
fprintf(stderr, "Error: could not get resources directory path\n");
exit(EXIT_FAILURE);
}
CFRelease(resources_url);

// Change the current working directory to the resources directory
if (chdir(resources_path) != 0)
{
fprintf(stderr, "Error: could not change working directory to resources directory\n");
exit(EXIT_FAILURE);
}
}
#endif

void handle_list_scroll(int *y_offset, const int num_saves, const int corrupted_count, int *mouses_down_index, bool *is_moving_scroll, int *banner_position_offset)
{
const uint8_t box_height = 93;
Expand Down Expand Up @@ -175,7 +153,7 @@ void update_selected_indexes_with_selection(int *selected_saves_index, int *mous
void draw_no_save_files(char *save_path)
{
ClearBackground(RED);
DrawRectangle(20, 150, SCREEN_WIDTH - 40, SCREEN_HEIGHT - 300, (Color){0,0,0,50});
DrawRectangle(20, 150, SCREEN_WIDTH - 40, SCREEN_HEIGHT - 300, (Color){0, 0, 0, 50});
if (no_dir_err)
{
Vector2 text_center = SCREEN_CENTER("Save folder doesn't exist!", 20);
Expand Down Expand Up @@ -215,15 +193,12 @@ void draw_raylib_screen_loop(
Texture2D textures[19] = {
[0 ... 18] = {
.id = 0}};

char error_message[100] = "Something went wrong";

#if defined(__APPLE__)
if (CI_BUILD)
{
get_mac_resource_images_path();
}
#endif
const struct texture_data *texture_data[5] = {
&evolve_data,
&logo_data,
&quit_data,
&settings_data,
&trade_data};

// while textures are loading
int texture_load_loop_limit = 3;
Expand All @@ -235,48 +210,52 @@ void draw_raylib_screen_loop(
DrawText("Loading Textures...", 20, 20, 20, WHITE);
EndDrawing();

if (textures[T_LOGO].id == 0)
{
textures[T_LOGO] = LoadTextureFromImage(LoadImage("assets/images/logo-text.png"));
}
if (textures[T_TRADE].id == 0)
{
textures[T_TRADE] = LoadTextureFromImage(LoadImage("assets/images/trade.png"));
}
if (textures[T_EVOLVE].id == 0)
{
textures[T_EVOLVE] = LoadTextureFromImage(LoadImage("assets/images/evolve.png"));
}
if (textures[T_SETTINGS].id == 0)
{
textures[T_SETTINGS] = LoadTextureFromImage(LoadImage("assets/images/settings.png"));
}
if (textures[T_QUIT].id == 0)
for (uint8_t i = T_EVOLVE; i < T_CONSOLE_0; i++)
{
textures[T_QUIT] = LoadTextureFromImage(LoadImage("assets/images/quit.png"));
if (textures[i].id == 0)
{
Image img = {0};
img.format = FORMAT;
img.height = texture_data[i]->height;
img.width = texture_data[i]->width;
img.data = texture_data[i]->data;
img.mipmaps = 1;

textures[i] = LoadTextureFromImage(img);
}
}

for (int i = T_CONSOLE_0; i < T_POKEBALL_0; i++)
{
if (textures[i].id == 0)
{
textures[i] = LoadTextureFromImage(LoadImage(TextFormat("assets/images/Pixel_Fantasy_Icons_Consoles/Consoles/console_%d.png", i - T_CONSOLE_0)));
Image console = {0};
console.format = FORMAT;
console.height = CONSOLE_HEIGHT;
console.width = CONSOLE_WIDTH;
console.data = console_data[i - T_CONSOLE_0];
console.mipmaps = 1;

textures[i] = LoadTextureFromImage(console);
}
}

for (int i = T_POKEBALL_0; i < T_POKEBALL_3 + 1; i++)
{
if (textures[i].id == 0)
{
textures[i] = LoadTextureFromImage(LoadImage(TextFormat("assets/images/pokeballs_MPR/ball_%d.png", i - T_POKEBALL_0)));
Image pokeball = {0};
pokeball.format = FORMAT;
pokeball.height = BALL_HEIGHT;
pokeball.width = BALL_WIDTH;
pokeball.data = ball_data[i - T_POKEBALL_0];
pokeball.mipmaps = 1;

textures[i] = LoadTextureFromImage(pokeball);
}
}

texture_loop_count++;
if (texture_loop_count >= texture_load_loop_limit)
{
current_screen = SCREEN_ERROR;
strcpy(error_message, "Failed to load textures. Is asset folder with exe?");
}
}

while (!should_close_window && !WindowShouldClose())
Expand Down Expand Up @@ -319,7 +298,7 @@ void draw_raylib_screen_loop(
default:
BeginDrawing();
ClearBackground(BACKGROUND_COLOR);
DrawText(error_message, SCREEN_CENTER(error_message, 20).x, SCREEN_CENTER(error_message, 20).y, 20, BLACK);
DrawText("Something went wrong", SCREEN_CENTER("Something went wrong", 20).x, SCREEN_CENTER("Something went wrong", 20).y, 20, BLACK);
DrawText("Press ESC key to exit!", SCREEN_CENTER("Press ESC key to exit!", 20).x, SCREEN_CENTER("Press ESC key to exit!", 20).x + 50, 20, BLACK);
EndDrawing();
// Escape key to close window
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ChangeDirScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void draw_change_dir(struct save_file_data *save_file_data, GameScreen *current_
DrawCircle(SCREEN_WIDTH * -0.7, SCREEN_HEIGHT * -1, 1380, BLACK);
DrawCircle(SCREEN_WIDTH * -0.7, SCREEN_HEIGHT * -1, 1350, COLOR_PKMN_RED);

DrawTextureEx(*settings_texture, (Vector2){50, 50}, 0, 0.4, WHITE);
DrawTextureEx(*settings_texture, (Vector2){50, 35}, 0, 1, WHITE);
DrawText("Specify folder name containing saves", 50, SCREEN_HEIGHT / 2 - 50, 25, BLACK);

// Draw the input box
Expand Down
2 changes: 1 addition & 1 deletion src/screens/EvolveScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void draw_evolve(PokemonSave *pkmn_save, char *save_path, struct trainer_info *t
BeginDrawing();
ClearBackground(RED);
draw_background_grid();
DrawTextureEx(*evolve_texture, (Vector2){50, 10}, 0, 0.4, WHITE);
DrawTextureEx(*evolve_texture, (Vector2){50, 10}, 0, 0.8, WHITE);

const int NONE = -1;
static int selected_index = NONE;
Expand Down
12 changes: 6 additions & 6 deletions src/screens/MainMenuScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void draw_main_menu(struct save_file_data *save_file_data, GameScreen *current_s
} rand_console[CONSOLE_COUNT] = {CONSOLE_NONE};

// Draw image pkrom_trader_logo header
DrawTextureEx(textures[T_LOGO], (Vector2){50, 50}, 0, 0.62, WHITE);
DrawTextureEx(textures[T_LOGO], (Vector2){50, 50}, 0, 1, WHITE);

// On Hover/Click Trade button
if (draw_menu_button(text_position_start.x, text_position_start.y, "Trade", text_size))
Expand All @@ -196,7 +196,7 @@ void draw_main_menu(struct save_file_data *save_file_data, GameScreen *current_s
// Move left/right
slide_animate_details_pane(BUTTON_TRADE);
// Trade texture logo
DrawTextureEx(textures[T_TRADE], (Vector2){details_rec.x + anim_from_right[BUTTON_TRADE], details_rec.y + 25}, 0, 0.5, WHITE);
DrawTextureEx(textures[T_TRADE], (Vector2){details_rec.x + anim_from_right[BUTTON_TRADE], details_rec.y + 25}, 0, 1, WHITE);
// Left console texture
DrawTextureEx(textures[rand_console[CONSOLE_LEFT]], (Vector2){details_rec.x + anim_from_right[BUTTON_TRADE] - 40, details_rec.y + 150}, 0, 3, WHITE);
// Arrow animation
Expand Down Expand Up @@ -235,9 +235,9 @@ void draw_main_menu(struct save_file_data *save_file_data, GameScreen *current_s
// Move left/right
slide_animate_details_pane(BUTTON_EVOLVE);
// Evolve texture logo
DrawTextureEx(textures[T_EVOLVE], (Vector2){details_rec.x + anim_from_right[BUTTON_EVOLVE], details_rec.y + 25}, 0, 0.5, WHITE);
DrawTextureEx(textures[T_EVOLVE], (Vector2){details_rec.x + anim_from_right[BUTTON_EVOLVE], details_rec.y + 25}, 0, 1, WHITE);
// Pokeball texture
DrawTextureEx(textures[rand_pokeball_index], (Vector2){details_rec.x + anim_from_right[BUTTON_EVOLVE] + 15, details_rec.y + 80}, 0, 0.25, WHITE);
DrawTextureEx(textures[rand_pokeball_index], (Vector2){details_rec.x + anim_from_right[BUTTON_EVOLVE] + 15, details_rec.y + 80}, 0, 2, WHITE);
// Arrow animation
draw_evolution_arrow_animation();
// Bottom details text
Expand All @@ -263,7 +263,7 @@ void draw_main_menu(struct save_file_data *save_file_data, GameScreen *current_s
// Move left/right
slide_animate_details_pane(BUTTON_SETTINGS);
// Draw settings texture logo
DrawTextureEx(textures[T_SETTINGS], (Vector2){details_rec.x + anim_from_right[BUTTON_SETTINGS] - 25, details_rec.y + 100}, 0, 0.5, WHITE);
DrawTextureEx(textures[T_SETTINGS], (Vector2){details_rec.x + anim_from_right[BUTTON_SETTINGS] - 25, details_rec.y + 100}, 0, 1, WHITE);
// Bottom details text
DrawText("Change trade and evolution settings", details_text.x + anim_from_right[BUTTON_SETTINGS] + 40, details_text.y, 20, BLACK);
}
Expand All @@ -285,7 +285,7 @@ void draw_main_menu(struct save_file_data *save_file_data, GameScreen *current_s
// Move left/right
slide_animate_details_pane(BUTTON_QUIT);
// Draw quit texture logo
DrawTextureEx(textures[T_QUIT], (Vector2){details_rec.x + anim_from_right[BUTTON_QUIT], details_rec.y + 100}, 0, 0.5, WHITE);
DrawTextureEx(textures[T_QUIT], (Vector2){details_rec.x + anim_from_right[BUTTON_QUIT], details_rec.y + 100}, 0, 1, WHITE);
// Bottom details text
DrawText("Quit Pokerom Trader", details_text.x + anim_from_right[BUTTON_QUIT] + 80, details_text.y, 20, BLACK);
}
Expand Down
6 changes: 3 additions & 3 deletions src/screens/SettingsScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ void draw_settings(struct save_file_data *save_file_data, GameScreen *current_sc
BeginDrawing();
ClearBackground(RED);
draw_background_grid();
DrawCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3.5, 1350, BLACK);
DrawCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3.5, 1320, WHITE);
DrawCircleSector((Vector2){SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3.5}, 1350, 0, 360, 500, BLACK);
DrawCircleSector((Vector2){SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3.5}, 1320, 0, 360, 500, WHITE);

DrawTextureEx(*settings_texture, (Vector2){50, 50}, 0, 0.4, WHITE);
DrawTextureEx(*settings_texture, (Vector2){50, 35}, 0, 1, WHITE);
// Toggle for random ivs on trade boolean
DrawText("Disable random DVs on trade", 50, start_y - 25, 20, settings_text_color);
// Checkbox for random ivs on trade
Expand Down
2 changes: 1 addition & 1 deletion src/screens/TradeScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void draw_trade(PokemonSave *save_player1, PokemonSave *save_player2, char *play
ClearBackground(RED);
draw_background_grid();

DrawTextureEx(*trade_texture, (Vector2){50, 10}, 0, 0.4, WHITE);
DrawTextureEx(*trade_texture, (Vector2){50, 10}, 0, 0.8, WHITE);

bool is_valid_trade[2] = {true, true};
draw_trainer_info(trainer1, 25, (SCREEN_HEIGHT - 100) / 2 - 75, trainerSelection, *is_same_generation, is_valid_trade);
Expand Down

0 comments on commit d6bf1e9

Please sign in to comment.