mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Allow the player to change block break/place speeds.
This will make building large structures in creative much easier.
This commit is contained in:
parent
412d5b93b8
commit
fa73ca7c22
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
pub const advanced_controls = @import("advanced_controls.zig");
|
||||||
pub const change_name = @import("change_name.zig");
|
pub const change_name = @import("change_name.zig");
|
||||||
pub const chat = @import("chat.zig");
|
pub const chat = @import("chat.zig");
|
||||||
pub const controls = @import("controls.zig");
|
pub const controls = @import("controls.zig");
|
||||||
|
54
src/gui/windows/advanced_controls.zig
Normal file
54
src/gui/windows/advanced_controls.zig
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const main = @import("root");
|
||||||
|
const settings = main.settings;
|
||||||
|
const Vec2f = main.vec.Vec2f;
|
||||||
|
|
||||||
|
const gui = @import("../gui.zig");
|
||||||
|
const GuiComponent = gui.GuiComponent;
|
||||||
|
const GuiWindow = gui.GuiWindow;
|
||||||
|
const Button = @import("../components/Button.zig");
|
||||||
|
const CheckBox = @import("../components/CheckBox.zig");
|
||||||
|
const ContinuousSlider = @import("../components/ContinuousSlider.zig");
|
||||||
|
const DiscreteSlider = @import("../components/DiscreteSlider.zig");
|
||||||
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
|
pub var window = GuiWindow {
|
||||||
|
.contentSize = Vec2f{128, 256},
|
||||||
|
};
|
||||||
|
|
||||||
|
const padding: f32 = 8;
|
||||||
|
|
||||||
|
fn delayCallback(newValue: f32) void {
|
||||||
|
settings.updateRepeatDelay = @intFromFloat(newValue);
|
||||||
|
settings.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delayFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []const u8 {
|
||||||
|
return std.fmt.allocPrint(allocator.allocator, "#ffffffPlace/Break Delay: {d:.0} ms", .{value}) catch unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn speedCallback(newValue: f32) void {
|
||||||
|
settings.updateRepeatSpeed = @intFromFloat(newValue);
|
||||||
|
settings.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn speedFormatter(allocator: main.utils.NeverFailingAllocator, value: f32) []const u8 {
|
||||||
|
return std.fmt.allocPrint(allocator.allocator, "#ffffffPlace/Break Speed: {d:.0} ms", .{value}) catch unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn onOpen() void {
|
||||||
|
const list = VerticalList.init(.{padding, 16 + padding}, 300, 16);
|
||||||
|
list.add(ContinuousSlider.init(.{0, 0}, 128, 1.0, 1000.0, @floatFromInt(settings.updateRepeatDelay), &delayCallback, &delayFormatter));
|
||||||
|
list.add(ContinuousSlider.init(.{0, 0}, 128, 1.0, 500.0, @floatFromInt(settings.updateRepeatSpeed), &speedCallback, &speedFormatter));
|
||||||
|
list.finish(.center);
|
||||||
|
window.rootComponent = list.toComponent();
|
||||||
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
|
||||||
|
gui.updateWindowPositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn onClose() void {
|
||||||
|
if(window.rootComponent) |*comp| {
|
||||||
|
comp.deinit();
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ pub fn onOpen() void {
|
|||||||
list.add(Button.initText(.{0, 0}, 128, "Graphics", gui.openWindowCallback("graphics")));
|
list.add(Button.initText(.{0, 0}, 128, "Graphics", gui.openWindowCallback("graphics")));
|
||||||
list.add(Button.initText(.{0, 0}, 128, "Sound", gui.openWindowCallback("sound")));
|
list.add(Button.initText(.{0, 0}, 128, "Sound", gui.openWindowCallback("sound")));
|
||||||
list.add(Button.initText(.{0, 0}, 128, "Controls", gui.openWindowCallback("controls")));
|
list.add(Button.initText(.{0, 0}, 128, "Controls", gui.openWindowCallback("controls")));
|
||||||
|
list.add(Button.initText(.{0, 0}, 128, "Advanced Controls", gui.openWindowCallback("advanced_controls")));
|
||||||
list.add(Button.initText(.{0, 0}, 128, "Change Name", gui.openWindowCallback("change_name")));
|
list.add(Button.initText(.{0, 0}, 128, "Change Name", gui.openWindowCallback("change_name")));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
window.rootComponent = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
|
@ -46,10 +46,9 @@ pub var musicVolume: f32 = 1;
|
|||||||
pub var storageTime: i64 = 5000;
|
pub var storageTime: i64 = 5000;
|
||||||
|
|
||||||
|
|
||||||
pub const updateRepeatSpeed: u31 = 200;
|
pub var updateRepeatSpeed: u31 = 200;
|
||||||
|
|
||||||
pub const updateRepeatDelay: u31 = 500;
|
|
||||||
|
|
||||||
|
pub var updateRepeatDelay: u31 = 500;
|
||||||
|
|
||||||
pub var developerAutoEnterWorld: []const u8 = "";
|
pub var developerAutoEnterWorld: []const u8 = "";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user