use of net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType in project RPG-Hud by KurodaAkira.
the class GuiSettingsMod method tick.
@Override
public void tick() {
super.tick();
for (String settingID : textFields.keySet()) {
for (TextFieldWidget t : textFields.get(settingID)) {
if (t instanceof TextFieldWidgetMod) {
ValueType type = ((TextFieldWidgetMod) t).getValueType();
switch(type) {
case DOUBLE:
double value;
try {
value = Double.valueOf(textFields.get(settingID).get(0).getText());
this.settings.getSetting(settingID).setValue(value);
} catch (NumberFormatException e) {
}
break;
case POSITION:
this.settings.getSetting(settingID).setValue(textFields.get(settingID).get(0).getText() + "_" + textFields.get(settingID).get(1).getText());
break;
}
}
t.tick();
}
}
}
use of net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType in project RPG-Hud by KurodaAkira.
the class GuiSettingsMod method init.
@Override
public void init() {
TextRenderer fontRenderer = client.textRenderer;
if (this.subSetting.equals("")) {
GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + 0 % 2 * 160, this.height / 6 - 14 + 20 * (0 >> 1), "general", new TranslatableText("gui.rpg.general"), button -> {
GuiButtonTooltip b = (GuiButtonTooltip) button;
if (b.enumOptions != null)
client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
}).setTooltip(I18n.translate("tooltip.general", new Object[0]));
this.addDrawableChild(guismallbutton);
int count = 1;
for (HudElementType type : HudElementType.values()) {
List<String> settings = this.settings.getSettingsOf(type);
if (!settings.isEmpty()) {
guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + count % 2 * 160, this.height / 6 - 14 + 20 * (count >> 1), type.name(), new TranslatableText(type.getDisplayName()), button -> {
GuiButtonTooltip b = (GuiButtonTooltip) button;
if (b.enumOptions != null) {
this.client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
}
}).setTooltip(I18n.translate("tooltip.element", new Object[0]));
this.addDrawableChild(guismallbutton);
count++;
}
}
} else {
List<String> settingList = this.settings.getSettingsOf(this.subSetting);
for (int i = 0; i < settingList.size(); i++) {
if (this.settings.getSetting(settingList.get(i)) instanceof SettingPosition) {
String[] values = ((String) this.settings.getSetting(settingList.get(i)).getValue()).split("_");
List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
GuiTextLabel settingLabel = new GuiTextLabel(this.width / 2 - 152 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
labelList.add(settingLabel);
TextFieldWidget xPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[0]));
xPos.setText(values[0]);
xPos.setMaxLength(6);
this.addDrawableChild(xPos);
fields.add(xPos);
TextFieldWidget yPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160 + 48, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[1]));
yPos.setText(values[1]);
yPos.setMaxLength(6);
this.addDrawableChild(yPos);
fields.add(yPos);
textFields.put(settingList.get(i), fields);
} else if (this.settings.getSetting(settingList.get(i)) instanceof SettingDouble) {
List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
GuiTextLabel scaleLabel = new GuiTextLabel(this.width / 2 - 151 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
TextFieldWidget scale = new TextFieldWidgetMod(fontRenderer, ValueType.DOUBLE, this.width / 2 - 100 + i % 2 * 160 + 3, this.height / 6 - 12 + 20 * (i >> 1), 90, 15, new TranslatableText(String.valueOf(this.settings.getDoubleValue(settingList.get(i)))));
scale.setText(String.valueOf(this.settings.getDoubleValue(settingList.get(i))));
labelList.add(scaleLabel);
this.addDrawableChild(scale);
fields.add(scale);
textFields.put(settingList.get(i), fields);
} else {
GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 14 + 20 * (i >> 1), settingList.get(i), new TranslatableText(this.settings.getButtonString(settingList.get(i))), button -> {
GuiButtonTooltip b = (GuiButtonTooltip) button;
if (b.enumOptions != null) {
if (settings.getSetting(b.enumOptions) instanceof SettingColor) {
client.setScreen(new GuiSettingsModColor(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
} else {
settings.increment(b.enumOptions);
button.setMessage(new TranslatableText(settings.getButtonString(b.enumOptions)));
}
}
}).setTooltip(this.settings.getSetting(settingList.get(i)).getTooltip());
this.addDrawableChild(guismallbutton);
}
}
}
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, new TranslatableText("gui.done"), button -> {
Settings settings = ModRPGHud.instance.settings;
for (String settingID : textFields.keySet()) {
for (TextFieldWidget t : textFields.get(settingID)) {
if (t instanceof TextFieldWidgetMod) {
ValueType type = ((TextFieldWidgetMod) t).getValueType();
switch(type) {
case DOUBLE:
double value;
try {
value = Double.valueOf(textFields.get(settingID).get(0).getText());
this.settings.getSetting(settingID).setValue(value);
} catch (NumberFormatException e) {
}
break;
case POSITION:
this.settings.getSetting(settingID).setValue(textFields.get(settingID).get(0).getText() + "_" + textFields.get(settingID).get(1).getText());
break;
}
}
}
}
settings.saveSettings();
client.setScreen(parent);
}));
}
Aggregations