feat: add attribution and links to About menu
/ build-dist (push) Successful in 1m16s Details

dev
LeRoyce Pearson 2024-05-30 16:27:31 -06:00
parent 6ff5164721
commit 0be0e3db19
1 changed files with 84 additions and 7 deletions

View File

@ -903,6 +903,7 @@ fn menuMain(event: MenuEvent) !void {
try resetGame(); try resetGame();
current_menu_fn = null; current_menu_fn = null;
} else if (std.mem.eql(u8, menu_item, "About")) { } else if (std.mem.eql(u8, menu_item, "About")) {
about_menu_page_selected = 0;
current_menu_fn = menuAbout; current_menu_fn = menuAbout;
} else if (std.mem.eql(u8, menu_item, "Quit")) { } else if (std.mem.eql(u8, menu_item, "Quit")) {
window_global.setShouldClose(true); window_global.setShouldClose(true);
@ -932,19 +933,92 @@ fn menuMain(event: MenuEvent) !void {
} }
} }
var about_menu_page_selected: usize = 0;
fn menuAbout(event: MenuEvent) !void { fn menuAbout(event: MenuEvent) !void {
const Page = struct {
title: []const u8,
description: []const u8,
};
const PAGES = [_]Page{
.{
.title = "Seizer Solitaire",
.description = "version = " ++ build_options.version ++
\\
\\
\\Created by geemili.
\\
\\Based on "Sawayama Solitaire" from
\\"Last Call BBS" by Zachtronics.
\\
\\Cards from CC0 images by Kenney,
\\modified for this game by geemili.
\\
\\Font is "Press Start 2P" by codeman38.
\\
,
},
.{
.title = "geemili",
// TODO: Add QR code
.description =
\\
\\www.geemili.xyz
\\
,
},
.{
.title = "Last Call BBS",
// TODO: Add QR code
.description =
\\
\\www.zachtronics.com/last-call-bbs
\\
,
},
.{
.title = "Kenney",
// TODO: Add QR code
.description =
\\
\\www.kenney.nl
\\
,
},
.{
.title = "Press Start 2P",
// TODO: Add QR code
.description =
\\
\\www.zone38.net/font
\\
,
},
};
switch (event) { switch (event) {
.up => {}, .up => {
.down => {}, if (about_menu_page_selected == 0) about_menu_page_selected = PAGES.len;
about_menu_page_selected -= 1;
},
.down => {
about_menu_page_selected += 1;
about_menu_page_selected %= PAGES.len;
},
.select => {}, .select => {},
.deselect => { .deselect => {
current_menu_fn = menuMain; current_menu_fn = menuMain;
}, },
.draw => |d| { .draw => |d| {
const version_text_size = canvas.font.fmtTextSize("version = {s}", .{build_options.version}, d.scalef); const page = PAGES[about_menu_page_selected];
const title_text_size = canvas.font.textSize(page.title, 2 * d.scalef);
const description_text_size = canvas.font.textSize(page.description, d.scalef);
const margin = [2]f32{ d.scalef * 10, d.scalef * 10 }; const margin = [2]f32{ d.scalef * 10, d.scalef * 10 };
const menu_size = [2]f32{ version_text_size[0] + 2 * margin[0], version_text_size[1] + 2 * margin[1] }; const menu_size = [2]f32{
@max(title_text_size[0], description_text_size[0]) + 2 * margin[0],
title_text_size[1] + description_text_size[1] + 2 * margin[1],
};
const menu_offset = [2]f32{ @floor((canvas.window_size[0] - menu_size[0]) / 2), @floor((canvas.window_size[1] - menu_size[1]) / 2) }; const menu_offset = [2]f32{ @floor((canvas.window_size[0] - menu_size[0]) / 2), @floor((canvas.window_size[1] - menu_size[1]) / 2) };
canvas.rect( canvas.rect(
@ -952,10 +1026,13 @@ fn menuAbout(event: MenuEvent) !void {
menu_size, menu_size,
.{ .color = .{ 0, 0, 0, 0xFF } }, .{ .color = .{ 0, 0, 0, 0xFF } },
); );
const x: f32 = canvas.window_size[0] / 2; var pos = [2]f32{
const y: f32 = menu_offset[1] + margin[1]; canvas.window_size[0] / 2,
menu_offset[1] + margin[1],
};
_ = canvas.printText(.{ x, y }, "version = {s}", .{build_options.version}, .{ .@"align" = .center, .scale = d.scalef }); pos[1] += canvas.writeText(pos, page.title, .{ .@"align" = .center, .scale = 2 * d.scalef })[1];
pos[1] += canvas.writeText(pos, page.description, .{ .@"align" = .center, .scale = d.scalef })[1];
}, },
} }
} }