Add version text to landing menus

If the current commit has a tag, the tag name is used as the version.
Otherwise, the short hash of the current commit is used.
This commit is contained in:
Matt Penny 2024-08-20 21:05:29 -04:00
parent da028cd405
commit 429dc0bd91
3 changed files with 39 additions and 13 deletions

View file

@ -19,8 +19,11 @@ $(SKELATOOL64):
@$(MAKE) -C skelatool64 @$(MAKE) -C skelatool64
# Use tag name if a tag exists, otherwise use commit hash
GAME_VERSION := $(shell git describe --tags --exact-match HEAD 2>/dev/null || git rev-parse --short HEAD)
OPTIMIZER := -Os OPTIMIZER := -Os
LCDEFS := -DDEBUG -g -Werror -Wall LCDEFS := -DDEBUG -DGAME_VERSION=\"$(GAME_VERSION)\" -g -Werror -Wall
N64LIB := -lultra_rom N64LIB := -lultra_rom
ifeq ($(PORTAL64_WITH_DEBUGGER),1) ifeq ($(PORTAL64_WITH_DEBUGGER),1)
@ -134,6 +137,14 @@ spanish_audio: vpk/portal_sound_vo_spanish_dir.vpk vpk/portal_sound_vo_spanish_0
buildgame: $(BASE_TARGET_NAME).z64 buildgame: $(BASE_TARGET_NAME).z64
# Allow targets to depend on the GAME_VERSION variable via a file.
# Update the file only when it differs from the variable (triggers rebuild).
.PHONY: gameversion
build/version.txt: gameversion
ifneq ($(shell cat build/version.txt 2>/dev/null), $(GAME_VERSION))
echo -n $(GAME_VERSION) > build/version.txt
endif
include $(COMMONRULES) include $(COMMONRULES)
.s.o: .s.o:
@ -363,7 +374,7 @@ build/src/menu/controls.o: build/assets/materials/ui.h build/src/audio/clips.h b
build/src/menu/game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h build/src/menu/game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h
build/src/menu/gameplay_options.o: build/assets/materials/ui.h build/src/audio/clips.h build/src/menu/gameplay_options.o: build/assets/materials/ui.h build/src/audio/clips.h
build/src/menu/joystick_options.o: build/assets/materials/ui.h build/src/audio/clips.h build/src/menu/joystick_options.o: build/assets/materials/ui.h build/src/audio/clips.h
build/src/menu/landing_menu.o: build/assets/materials/ui.h build/src/audio/clips.h build/src/menu/landing_menu.o: build/assets/materials/ui.h build/src/audio/clips.h build/version.txt
build/src/menu/load_game.o: build/assets/materials/ui.h build/src/audio/clips.h build/src/audio/subtitles.h build/src/menu/load_game.o: build/assets/materials/ui.h build/src/audio/clips.h build/src/audio/subtitles.h
build/src/menu/main_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h build/src/menu/main_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h
build/src/menu/new_game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/src/audio/subtitles.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h build/src/menu/new_game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/src/audio/subtitles.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h

View file

@ -11,19 +11,21 @@
#include "cheat_codes.h" #include "cheat_codes.h"
#include "./translations.h" #include "./translations.h"
#define PORTAL_LOGO_X 30 #define PORTAL_LOGO_X 30
#define PORTAL_LOGO_Y 74 #define PORTAL_LOGO_Y 74
#define PORTAL_LOGO_WIDTH 128 #define PORTAL_LOGO_WIDTH 128
#define PORTAL_LOGO_P_WIDTH 15 #define PORTAL_LOGO_P_WIDTH 15
#define PORTAL_LOGO_O_WIDTH 30 #define PORTAL_LOGO_O_WIDTH 30
#define PORTAL_LOGO_HEIGHT 47 #define PORTAL_LOGO_HEIGHT 47
#define LANDING_MENU_TEXT_START_X 30 #define LANDING_MENU_TEXT_START_X 30
#define LANDING_MENU_TEXT_START_Y 132 #define LANDING_MENU_TEXT_START_Y 132
#define STRIDE_OPTION_1 12 #define STRIDE_OPTION_1 12
#define STRIDE_OPTION_2 16 #define STRIDE_OPTION_2 16
#define PACKED_MENU_THRESHOLD 4 #define PACKED_MENU_THRESHOLD 4
#define LANDING_MENU_VERSION_END_Y 20
Gfx portal_logo_gfx[] = { Gfx portal_logo_gfx[] = {
gsSPTextureRectangle( gsSPTextureRectangle(
@ -72,11 +74,19 @@ void landingMenuInitText(struct LandingMenu* landingMenu) {
SCREEN_WD); SCREEN_WD);
y += stride; y += stride;
} }
landingMenu->versionText = menuBuildPrerenderedText(&gDejaVuSansFont, GAME_VERSION, 0, 0, SCREEN_WD);
prerenderedTextRelocate(
landingMenu->versionText,
SCREEN_WD - LANDING_MENU_TEXT_START_X - landingMenu->versionText->width,
SCREEN_HT - LANDING_MENU_VERSION_END_Y - landingMenu->versionText->height
);
} }
void landingMenuInit(struct LandingMenu* landingMenu, struct LandingMenuOption* options, int optionCount, int darkenBackground) { void landingMenuInit(struct LandingMenu* landingMenu, struct LandingMenuOption* options, int optionCount, int darkenBackground) {
landingMenu->optionText = malloc(sizeof(struct PrerenderedText*) * optionCount); landingMenu->optionText = malloc(sizeof(struct PrerenderedText*) * optionCount);
landingMenu->options = options; landingMenu->options = options;
landingMenu->versionText = NULL;
landingMenu->selectedItem = 0; landingMenu->selectedItem = 0;
landingMenu->optionCount = optionCount; landingMenu->optionCount = optionCount;
landingMenu->darkenBackground = darkenBackground; landingMenu->darkenBackground = darkenBackground;
@ -87,6 +97,8 @@ void landingMenuRebuildText(struct LandingMenu* landingMenu) {
for (int i = 0; i < landingMenu->optionCount; ++i) { for (int i = 0; i < landingMenu->optionCount; ++i) {
prerenderedTextFree(landingMenu->optionText[i]); prerenderedTextFree(landingMenu->optionText[i]);
} }
prerenderedTextFree(landingMenu->versionText);
landingMenuInitText(landingMenu); landingMenuInitText(landingMenu);
} }
@ -169,6 +181,8 @@ void landingMenuRender(struct LandingMenu* landingMenu, struct RenderState* rend
for (int i = 0; i < landingMenu->optionCount; ++i) { for (int i = 0; i < landingMenu->optionCount; ++i) {
prerenderedBatchAdd(batch, landingMenu->optionText[i], &gColorWhite); prerenderedBatchAdd(batch, landingMenu->optionText[i], &gColorWhite);
} }
prerenderedBatchAdd(batch, landingMenu->versionText, &gHalfTransparentWhite);
renderState->dl = prerenderedBatchFinish(batch, gDejaVuSansImages, renderState->dl); renderState->dl = prerenderedBatchFinish(batch, gDejaVuSansImages, renderState->dl);
gSPDisplayList(renderState->dl++, ui_material_revert_list[DEJAVU_SANS_0_INDEX]); gSPDisplayList(renderState->dl++, ui_material_revert_list[DEJAVU_SANS_0_INDEX]);
} }

View file

@ -13,6 +13,7 @@ struct LandingMenuOption {
struct LandingMenu { struct LandingMenu {
struct LandingMenuOption* options; struct LandingMenuOption* options;
struct PrerenderedText** optionText; struct PrerenderedText** optionText;
struct PrerenderedText* versionText;
short selectedItem; short selectedItem;
short optionCount; short optionCount;
short darkenBackground; short darkenBackground;