mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-11 13:31:07 -04:00
parent
ac3847db79
commit
337e014d88
@ -160,6 +160,7 @@ pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
|
|||||||
}
|
}
|
||||||
self.scale = @max(self.scale, 0.25);
|
self.scale = @max(self.scale, 0.25);
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
|
gui.save();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Zoom in
|
// Zoom in
|
||||||
@ -169,6 +170,7 @@ pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
|
|||||||
self.scale += 0.25;
|
self.scale += 0.25;
|
||||||
}
|
}
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
|
gui.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,6 +336,7 @@ pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) void {
|
|||||||
self.pos = @max(self.pos, Vec2f{0, 0});
|
self.pos = @max(self.pos, Vec2f{0, 0});
|
||||||
self.pos = @min(self.pos, windowSize - self.size);
|
self.pos = @min(self.pos, windowSize - self.size);
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
|
gui.save();
|
||||||
};
|
};
|
||||||
if(self.rootComponent) |*component| {
|
if(self.rootComponent) |*component| {
|
||||||
component.updateSelected();
|
component.updateSelected();
|
||||||
|
@ -183,7 +183,7 @@ pub fn deinit() void {
|
|||||||
GuiCommandQueue.deinit();
|
GuiCommandQueue.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save() void {
|
pub fn save() void {
|
||||||
const guiJson = JsonElement.initObject(main.stackAllocator);
|
const guiJson = JsonElement.initObject(main.stackAllocator);
|
||||||
defer guiJson.free(main.stackAllocator);
|
defer guiJson.free(main.stackAllocator);
|
||||||
for(windowList.items) |window| {
|
for(windowList.items) |window| {
|
||||||
|
@ -23,6 +23,7 @@ fn apply(_: usize) void {
|
|||||||
const oldName = settings.playerName;
|
const oldName = settings.playerName;
|
||||||
main.globalAllocator.free(settings.playerName);
|
main.globalAllocator.free(settings.playerName);
|
||||||
settings.playerName = main.globalAllocator.dupe(u8, textComponent.currentString.items);
|
settings.playerName = main.globalAllocator.dupe(u8, textComponent.currentString.items);
|
||||||
|
settings.save();
|
||||||
|
|
||||||
gui.closeWindow(&window);
|
gui.closeWindow(&window);
|
||||||
if(oldName.len == 0) {
|
if(oldName.len == 0) {
|
||||||
|
@ -32,10 +32,12 @@ fn keypressListener(key: c_int, mouseButton: c_int, scancode: c_int) void {
|
|||||||
selectedKey.?.scancode = scancode;
|
selectedKey.?.scancode = scancode;
|
||||||
selectedKey = null;
|
selectedKey = null;
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
|
main.settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn updateSensitivity(sensitivity: f32) void {
|
fn updateSensitivity(sensitivity: f32) void {
|
||||||
main.settings.mouseSensitivity = sensitivity;
|
main.settings.mouseSensitivity = sensitivity;
|
||||||
|
main.settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sensitivityFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []const u8 {
|
fn sensitivityFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []const u8 {
|
||||||
|
@ -43,14 +43,17 @@ fn fpsCapFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []co
|
|||||||
|
|
||||||
fn fpsCapCallback(newValue: f32) void {
|
fn fpsCapCallback(newValue: f32) void {
|
||||||
settings.fpsCap = fpsCapRound(newValue);
|
settings.fpsCap = fpsCapRound(newValue);
|
||||||
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renderDistanceCallback(newValue: u16) void {
|
fn renderDistanceCallback(newValue: u16) void {
|
||||||
settings.renderDistance = newValue + renderDistances[0];
|
settings.renderDistance = newValue + renderDistances[0];
|
||||||
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fovCallback(newValue: f32) void {
|
fn fovCallback(newValue: f32) void {
|
||||||
settings.fov = newValue;
|
settings.fov = newValue;
|
||||||
|
settings.save();
|
||||||
main.Window.GLFWCallbacks.framebufferSize(undefined, main.Window.width, main.Window.height);
|
main.Window.GLFWCallbacks.framebufferSize(undefined, main.Window.width, main.Window.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,19 +63,23 @@ fn fovFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []const
|
|||||||
|
|
||||||
fn LODFactorCallback(newValue: u16) void {
|
fn LODFactorCallback(newValue: u16) void {
|
||||||
settings.LODFactor = @as(f32, @floatFromInt(newValue + 1))/2;
|
settings.LODFactor = @as(f32, @floatFromInt(newValue + 1))/2;
|
||||||
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bloomCallback(newValue: bool) void {
|
fn bloomCallback(newValue: bool) void {
|
||||||
settings.bloom = newValue;
|
settings.bloom = newValue;
|
||||||
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vsyncCallback(newValue: bool) void {
|
fn vsyncCallback(newValue: bool) void {
|
||||||
settings.vsync = newValue;
|
settings.vsync = newValue;
|
||||||
|
settings.save();
|
||||||
main.Window.reloadSettings();
|
main.Window.reloadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anisotropicFilteringCallback(newValue: u16) void {
|
fn anisotropicFilteringCallback(newValue: u16) void {
|
||||||
settings.anisotropicFiltering = anisotropy[newValue];
|
settings.anisotropicFiltering = anisotropy[newValue];
|
||||||
|
settings.save();
|
||||||
if(main.game.world != null) {
|
if(main.game.world != null) {
|
||||||
main.blocks.meshes.reloadTextures(undefined);
|
main.blocks.meshes.reloadTextures(undefined);
|
||||||
}
|
}
|
||||||
@ -80,6 +87,7 @@ fn anisotropicFilteringCallback(newValue: u16) void {
|
|||||||
|
|
||||||
fn resolutionScaleCallback(newValue: u16) void {
|
fn resolutionScaleCallback(newValue: u16) void {
|
||||||
settings.resolutionScale = std.math.pow(f32, 2.0, @as(f32, @floatFromInt(newValue)) - 2.0);
|
settings.resolutionScale = std.math.pow(f32, 2.0, @as(f32, @floatFromInt(newValue)) - 2.0);
|
||||||
|
settings.save();
|
||||||
main.Window.GLFWCallbacks.framebufferSize(null, main.Window.width, main.Window.height);
|
main.Window.GLFWCallbacks.framebufferSize(null, main.Window.width, main.Window.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ fn join(_: usize) void {
|
|||||||
_connection.world = &main.game.testWorld;
|
_connection.world = &main.game.testWorld;
|
||||||
main.globalAllocator.free(settings.lastUsedIPAddress);
|
main.globalAllocator.free(settings.lastUsedIPAddress);
|
||||||
settings.lastUsedIPAddress = main.globalAllocator.dupe(u8, ipAddressEntry.currentString.items);
|
settings.lastUsedIPAddress = main.globalAllocator.dupe(u8, ipAddressEntry.currentString.items);
|
||||||
|
settings.save();
|
||||||
main.game.testWorld.init(ipAddressEntry.currentString.items, _connection) catch |err| {
|
main.game.testWorld.init(ipAddressEntry.currentString.items, _connection) catch |err| {
|
||||||
std.log.err("Encountered error while opening world: {s}", .{@errorName(err)});
|
std.log.err("Encountered error while opening world: {s}", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@ pub var window = GuiWindow {
|
|||||||
|
|
||||||
fn musicCallback(newValue: f32) void {
|
fn musicCallback(newValue: f32) void {
|
||||||
settings.musicVolume = deziBelToLinear(newValue);
|
settings.musicVolume = deziBelToLinear(newValue);
|
||||||
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deziBelToLinear(x: f32) f32 {
|
fn deziBelToLinear(x: f32) f32 {
|
||||||
|
@ -96,6 +96,26 @@ pub fn init() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
|
save();
|
||||||
|
inline for(@typeInfo(@This()).Struct.decls) |decl| {
|
||||||
|
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).Pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
|
||||||
|
if(!is_const) {
|
||||||
|
const declType = @TypeOf(@field(@This(), decl.name));
|
||||||
|
if(@typeInfo(declType) == .Struct) {
|
||||||
|
@compileError("Not implemented yet.");
|
||||||
|
}
|
||||||
|
if(@typeInfo(declType) == .Pointer) {
|
||||||
|
if(@typeInfo(declType).Pointer.size == .Slice) {
|
||||||
|
main.globalAllocator.free(@field(@This(), decl.name));
|
||||||
|
} else {
|
||||||
|
@compileError("Not implemented yet.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save() void {
|
||||||
const jsonObject = JsonElement.initObject(main.stackAllocator);
|
const jsonObject = JsonElement.initObject(main.stackAllocator);
|
||||||
defer jsonObject.free(main.stackAllocator);
|
defer jsonObject.free(main.stackAllocator);
|
||||||
|
|
||||||
@ -111,13 +131,6 @@ pub fn deinit() void {
|
|||||||
} else {
|
} else {
|
||||||
jsonObject.put(decl.name, @field(@This(), decl.name));
|
jsonObject.put(decl.name, @field(@This(), decl.name));
|
||||||
}
|
}
|
||||||
if(@typeInfo(declType) == .Pointer) {
|
|
||||||
if(@typeInfo(declType).Pointer.size == .Slice) {
|
|
||||||
main.globalAllocator.free(@field(@This(), decl.name));
|
|
||||||
} else {
|
|
||||||
@compileError("Not implemented yet.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user