Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public DefaultSettingsWidgetFactory(GuiTheme theme) {

factories.put(BoolSetting.class, (table, setting) -> boolW(table, (BoolSetting) setting));
factories.put(IntSetting.class, (table, setting) -> intW(table, (IntSetting) setting));
factories.put(LongSetting.class, (table, setting) -> longW(table, (LongSetting) setting));
factories.put(DoubleSetting.class, (table, setting) -> doubleW(table, (DoubleSetting) setting));
factories.put(StringSetting.class, (table, setting) -> stringW(table, (StringSetting) setting));
factories.put(EnumSetting.class, (table, setting) -> enumW(table, (EnumSetting<? extends Enum<?>>) setting));
Expand Down Expand Up @@ -178,6 +179,15 @@ private void intW(WTable table, IntSetting setting) {
reset(table, setting, () -> edit.set(setting.get()));
}

private void longW(WTable table, LongSetting setting) {
WTextBox textBox = table.add(theme.textBox(setting.get().toString(), (text, c) -> Character.isDigit(c) || c == '-' && !text.contains("-"))).expandX().widget();
textBox.actionOnUnfocused = () -> {
if (!setting.parse(textBox.get())) textBox.set(setting.get().toString());
};

reset(table, setting, () -> textBox.set(setting.get().toString()));
}

private void doubleW(WTable table, DoubleSetting setting) {
WDoubleEdit edit = theme.doubleEdit(setting.get(), setting.min, setting.max, setting.sliderMin, setting.sliderMax, setting.decimalPlaces, setting.noSlider);
table.add(edit).expandX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ private void createWrappers() {
.build();
}
} else if (value instanceof Long) {
sgInt.add(new IntSetting.Builder()
sgInt.add(new LongSetting.Builder()
.name(setting.getName())
.description(getDescription(setting.getName()))
.defaultValue(((Long) setting.defaultValue).intValue())
.onChanged(integer -> setting.value = integer.longValue())
.onModuleActivated(integerSetting -> integerSetting.set(((Long) setting.value).intValue()))
.defaultValue((Long) setting.defaultValue)
.onChanged(longValue -> setting.value = longValue)
.onModuleActivated(longSetting -> longSetting.set((Long) setting.value))
.build()
);
} else if (value instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.settings;

import net.minecraft.nbt.CompoundTag;

import java.util.function.Consumer;

public class LongSetting extends Setting<Long> {
private LongSetting(String name, String description, long defaultValue, Consumer<Long> onChanged, Consumer<Setting<Long>> onModuleActivated, IVisible visible) {
super(name, description, defaultValue, onChanged, onModuleActivated, visible);
}

@Override
protected Long parseImpl(String str) {
try {
return Long.parseLong(str.trim());
} catch (NumberFormatException _) {
return null;
}
}

@Override
protected boolean isValueValid(Long value) {
return true;
}

@Override
public CompoundTag save(CompoundTag tag) {
tag.putLong("value", get());

return tag;
}

@Override
public Long load(CompoundTag tag) {
set(tag.getLongOr("value", 0));

return get();
}

public static class Builder extends SettingBuilder<Builder, Long, LongSetting> {
public Builder() {
super(0L);
}

@Override
public LongSetting build() {
return new LongSetting(name, description, defaultValue, onChanged, onModuleActivated, visible);
}
}
}
Loading