mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
make a open log button (#946)
* make a open log button * move to function * make an icon * do something * small changes
This commit is contained in:
parent
3eddbb5483
commit
47a854d3cc
@ -21,6 +21,32 @@ pub fn writeZon(path: []const u8, zon: ZonElement) !void {
|
||||
try cwd().writeZon(path, zon);
|
||||
}
|
||||
|
||||
pub fn openDirInWindow(path: []const u8) void {
|
||||
const newPath = main.stackAllocator.dupe(u8, path);
|
||||
defer main.stackAllocator.free(newPath);
|
||||
|
||||
if (builtin.os.tag == .windows) {
|
||||
std.mem.replaceScalar(u8, newPath, '/', '\\');
|
||||
}
|
||||
|
||||
const command = if(builtin.os.tag == .windows) .{"explorer", newPath} else .{"open", newPath};
|
||||
|
||||
const result = std.process.Child.run(.{
|
||||
.allocator = main.stackAllocator.allocator,
|
||||
.argv = &command,
|
||||
}) catch |err| {
|
||||
std.log.err("Got error while trying to open file explorer: {s}", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
main.stackAllocator.free(result.stderr);
|
||||
main.stackAllocator.free(result.stdout);
|
||||
}
|
||||
if(result.stderr.len != 0) {
|
||||
std.log.err("Got error while trying to open file explorer: {s}", .{result.stderr});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn openDir(path: []const u8) !Dir {
|
||||
return Dir {
|
||||
.dir = try std.fs.cwd().makeOpenPath(path, .{}),
|
||||
|
@ -4,10 +4,15 @@ const main = @import("root");
|
||||
const files = main.files;
|
||||
const settings = main.settings;
|
||||
const Vec2f = main.vec.Vec2f;
|
||||
const Texture = main.graphics.Texture;
|
||||
|
||||
const gui = @import("../gui.zig");
|
||||
const GuiWindow = gui.GuiWindow;
|
||||
const Label = @import("../components/Label.zig");
|
||||
const VerticalList = @import("../components/VerticalList.zig");
|
||||
const Button = @import("../components/Button.zig");
|
||||
|
||||
var fileExplorerIcon: Texture = undefined;
|
||||
|
||||
pub var window = GuiWindow {
|
||||
.contentSize = Vec2f{128, 64},
|
||||
@ -19,15 +24,31 @@ pub var window = GuiWindow {
|
||||
},
|
||||
};
|
||||
|
||||
pub fn init() void {
|
||||
fileExplorerIcon = Texture.initFromFile("assets/cubyz/ui/file_explorer_icon.png");
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
fileExplorerIcon.deinit();
|
||||
}
|
||||
|
||||
fn openLog(_: usize) void {
|
||||
main.files.openDirInWindow("logs");
|
||||
}
|
||||
|
||||
const padding: f32 = 8;
|
||||
pub fn update() void {
|
||||
if (main.Window.Gamepad.wereControllerMappingsDownloaded()) {
|
||||
gui.closeWindowFromRef(&window);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn onOpen() void {
|
||||
const label = Label.init(.{padding, 16 + padding}, 128, "#ffff00The game encountered errors. Check the logs for details", .center);
|
||||
window.rootComponent = label.toComponent();
|
||||
const list = VerticalList.init(.{padding, 16 + padding}, 300, 16);
|
||||
list.add(Label.init(.{padding, 16 + padding}, 128, "#ffff00The game encountered errors. Check the logs for details", .center));
|
||||
list.add(Button.initIcon(.{0, 0}, .{16, 16}, fileExplorerIcon, false, .{.callback = &openLog}));
|
||||
list.finish(.center);
|
||||
window.rootComponent = list.toComponent();
|
||||
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
|
||||
gui.updateWindowPositions();
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const main = @import("root");
|
||||
const ConnectionManager = main.network.ConnectionManager;
|
||||
@ -86,25 +85,10 @@ fn openFolder(namePtr: usize) void {
|
||||
const nullTerminatedName: [*:0]const u8 = @ptrFromInt(namePtr);
|
||||
const name = std.mem.span(nullTerminatedName);
|
||||
|
||||
const command = if(builtin.os.tag == .windows) .{"explorer"} else .{"open"};
|
||||
|
||||
const path_fmt = if (builtin.os.tag == .windows) "saves\\{s}" else "saves/{s}"; // Use backslashes on windows because it forces you to
|
||||
const path = std.fmt.allocPrint(main.stackAllocator.allocator, path_fmt, .{name}) catch unreachable;
|
||||
const path = std.fmt.allocPrint(main.stackAllocator.allocator, "saves/{s}", .{name}) catch unreachable;
|
||||
defer main.stackAllocator.free(path);
|
||||
const result = std.process.Child.run(.{
|
||||
.allocator = main.stackAllocator.allocator,
|
||||
.argv = &(command ++ .{path}),
|
||||
}) catch |err| {
|
||||
std.log.err("Got error while trying to open file explorer: {s}", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
main.stackAllocator.free(result.stderr);
|
||||
main.stackAllocator.free(result.stdout);
|
||||
}
|
||||
if(result.stderr.len != 0) {
|
||||
std.log.err("Got error while trying to open file explorer: {s}", .{result.stderr});
|
||||
}
|
||||
|
||||
main.files.openDirInWindow(path);
|
||||
}
|
||||
|
||||
fn parseEscapedFolderName(allocator: NeverFailingAllocator, name: []const u8) []const u8 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user