diff --git a/build.zig b/build.zig index a7c1867936..99e7803c2a 100644 --- a/build.zig +++ b/build.zig @@ -71,8 +71,10 @@ fn linkLibraries(b: *std.Build, exe: *std.Build.Step.Compile, useLocalDeps: bool if (t.os.tag == .windows) { exe.root_module.linkSystemLibrary("bcrypt", .{}); + exe.root_module.linkSystemLibrary("comdlg32", .{}); exe.root_module.linkSystemLibrary("crypt32", .{}); exe.root_module.linkSystemLibrary("gdi32", .{}); + exe.root_module.linkSystemLibrary("ole32", .{}); exe.root_module.linkSystemLibrary("opengl32", .{}); exe.root_module.linkSystemLibrary("ws2_32", .{}); } else if (t.os.tag == .macos) { diff --git a/build.zig.zon b/build.zig.zon index 265eacb138..31e551f62e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,37 +9,37 @@ .lazy = true, }, .cubyz_deps_headers = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_headers.tar.gz", - .hash = "N-V-__8AAAQ8dwBKANzWIqLXH227TZFN-Cs3SEUz1BlvOIdk", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_headers.tar.gz", + .hash = "N-V-__8AAB6xcQAzOlBtWsr0BKq1iJr81QNqsMJiRqbFdLQu", }, .cubyz_deps_aarch64_macos = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_aarch64-macos-none.tar.gz", - .hash = "N-V-__8AAFDsiwWqygpcW19zQ5qWleEjoqaiuzT1NiLJkwgV", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_aarch64-macos-none.tar.gz", + .hash = "N-V-__8AABoInwXLwZD4LGu6NHUWDHqZhtFV7M_75BLg8S2c", .lazy = true, }, .cubyz_deps_aarch64_linux = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_aarch64-linux-musl.tar.gz", - .hash = "N-V-__8AANpf5AKBmNccW_gzB8L0ROUX23R9SvwakkIaC8dI", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_aarch64-linux-musl.tar.gz", + .hash = "N-V-__8AAIJB3QJEfQMtQipbSUYSoSwVtixb8VNey8r84yxq", .lazy = true, }, .cubyz_deps_aarch64_windows = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_aarch64-windows-gnu.tar.gz", - .hash = "N-V-__8AAEpU-wLzojxVacuzuCWzgxX832c35NhDPdlpzzNV", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_aarch64-windows-gnu.tar.gz", + .hash = "N-V-__8AAJzA9ALZU9f_NM0T71V-wj3sJDU1uILlmAV19hSO", .lazy = true, }, .cubyz_deps_x86_64_macos = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_x86_64-macos-none.tar.gz", - .hash = "N-V-__8AAFEIfwXPoQ_whMaJiUEiYTYbz7i3GLbtGJ5yyuYn", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_x86_64-macos-none.tar.gz", + .hash = "N-V-__8AADBWkAWFax-EOLwiNC4EQpU4u6suCzlW3FemTrXT", .lazy = true, }, .cubyz_deps_x86_64_linux = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_x86_64-linux-musl.tar.gz", - .hash = "N-V-__8AAIg94AIPPluGDS6T9ZsEmWU6NjyhrCVNhzb93w-V", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_x86_64-linux-musl.tar.gz", + .hash = "N-V-__8AAFAX2AJMXYC4zzXanosSctAE1E2xiJLuY92qa17Z", .lazy = true, }, .cubyz_deps_x86_64_windows = .{ - .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/11/cubyz_deps_x86_64-windows-gnu.tar.gz", - .hash = "N-V-__8AALI8HwOYeQDK3pbIUi7_ugLq5oXLbwdoVp6JNnYW", + .url = "https://github.com/PixelGuys/Cubyz-Libs/releases/download/12/cubyz_deps_x86_64-windows-gnu.tar.gz", + .hash = "N-V-__8AAHITFwPGSkpkm-6reDqNtW9R1xRx_hzZnZdILhCu", .lazy = true, }, .cubyz_large_assets = .{ diff --git a/src/c.h b/src/c.h index db3cd8af8a..f2736d673b 100644 --- a/src/c.h +++ b/src/c.h @@ -61,3 +61,6 @@ // used to compile shaders to SPIR-V #include #include + +// file save/open dialog +#include diff --git a/src/gui/windows/authentication/create_account_account_code.zig b/src/gui/windows/authentication/create_account_account_code.zig index c9ead80366..04c8301c0e 100644 --- a/src/gui/windows/authentication/create_account_account_code.zig +++ b/src/gui/windows/authentication/create_account_account_code.zig @@ -15,6 +15,8 @@ const Label = GuiComponent.Label; const TextInput = GuiComponent.TextInput; const VerticalList = GuiComponent.VerticalList; +const c = @import("c"); + pub var window = GuiWindow{ .contentSize = Vec2f{128, 256}, .closeIfMouseIsGrabbed = true, @@ -25,7 +27,8 @@ const padding: f32 = 8; var accountCodeLabel: *Label = undefined; var accountCode: ?main.network.authentication.AccountCode = null; -var fileNameEntry: *TextInput = undefined; +var fileNameEntry: *Label = undefined; +var fileName: []const u8 = undefined; pub const StorageMethod = enum(usize) { file = 0, @@ -44,13 +47,6 @@ pub fn setStorageMethod(method: StorageMethod) void { fn next() void { switch (storageMethod) { .file => { - var fileName = fileNameEntry.currentString.items; - if (builtin.os.tag == .windows and !std.mem.endsWith(u8, fileName, ".txt")) { // Windows has very poor ergonomics for files without extensions - fileName = std.fmt.allocPrint(main.stackAllocator.allocator, "{s}.txt", .{fileNameEntry.currentString.items}) catch unreachable; - } - defer if (builtin.os.tag == .windows and !std.mem.endsWith(u8, fileNameEntry.currentString.items, ".txt")) { - main.stackAllocator.free(fileName); - }; main.files.cwd().write(fileName, accountCode.?.text) catch |err| { std.log.err("Failed to write Account Code to file: {s}", .{@errorName(err)}); return; @@ -74,6 +70,12 @@ fn copy() void { main.Window.setClipboardString(accountCode.?.text); } +fn selectFile() void { + const result: [*:0]const u8 = c.tinyfd_saveFileDialog("Select File to save Account Code", "Cubyz Account.txt", 1, @as([*]const [*:0]const u8, &.{"*.txt"}), "Text Files") orelse return; + fileName = std.mem.span(result); + fileNameEntry.updateText(fileName); +} + pub fn onOpen() void { if (accountCode == null) accountCode = .initRandomly(); @@ -88,15 +90,16 @@ pub fn onOpen() void { switch (storageMethod) { .file => { list.add(Label.init(.{0, 0}, width, "Please enter a file name, we will store it there.", .left)); - fileNameEntry = TextInput.init(.{0, 0}, width, 22, "", .{.onNewline = .{}}); + list.add(Button.initText(.{0, 0}, 250, "Select File", .{.onAction = .init(selectFile)})); + fileNameEntry = Label.init(.{0, 0}, width, "", .center); list.add(fileNameEntry); - button = Button.initText(.{10, 0}, 250, "Save and return to login", .{.onAction = .init(next), .disabled = true}); + button = Button.initText(.{0, 0}, 250, "Save and return to login", .{.onAction = .init(next), .disabled = true}); }, .paper, .passwordManager => { if (storageMethod == .paper) list.add(Label.init(.{0, 0}, width, "We will give you some time to write it down.", .left)); if (storageMethod == .passwordManager) list.add(Label.init(.{0, 0}, width, "We will give you some time to copy it to your password manager.", .left)); list.add(Label.init(.{0, 0}, width, "Note: Do not give your Account Code to anyone else, only enter it in the login screen inside the game.", .left)); - button = Button.initText(.{10, 0}, 250, "Return to login (15)", .{.onAction = .init(next), .disabled = true}); + button = Button.initText(.{0, 0}, 250, "Return to login (15)", .{.onAction = .init(next), .disabled = true}); }, } const buttonRow = HorizontalList.init(); @@ -114,7 +117,7 @@ pub fn onOpen() void { pub fn update() void { switch (storageMethod) { .file => { - button.disabled = fileNameEntry.currentString.items.len == 0; + button.disabled = fileName.len == 0; }, .paper, .passwordManager => { if (button.disabled) {