From 0be0e3db19f05d7af1459991031d64021e8ae43d Mon Sep 17 00:00:00 2001 From: geemili Date: Thu, 30 May 2024 16:27:31 -0600 Subject: [PATCH] feat: add attribution and links to About menu --- src/main.zig | 91 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 7 deletions(-) diff --git a/src/main.zig b/src/main.zig index acd1fcb..9062eb6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -903,6 +903,7 @@ fn menuMain(event: MenuEvent) !void { try resetGame(); current_menu_fn = null; } else if (std.mem.eql(u8, menu_item, "About")) { + about_menu_page_selected = 0; current_menu_fn = menuAbout; } else if (std.mem.eql(u8, menu_item, "Quit")) { 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 { + 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) { - .up => {}, - .down => {}, + .up => { + 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 => {}, .deselect => { current_menu_fn = menuMain; }, .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 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) }; canvas.rect( @@ -952,10 +1026,13 @@ fn menuAbout(event: MenuEvent) !void { menu_size, .{ .color = .{ 0, 0, 0, 0xFF } }, ); - const x: f32 = canvas.window_size[0] / 2; - const y: f32 = menu_offset[1] + margin[1]; + var pos = [2]f32{ + 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]; }, } }