use of org.blockartistry.Presets.data.PresetInfo in project DynamicSurroundings by OreCruncher.
the class PresetsConfigGui method setPresetButtonText.
public void setPresetButtonText() {
final int start = this.currentPage * MAX_PRESETS_PAGE;
for (int i = 0; i < MAX_PRESETS_PAGE; i++) {
final GuiButtonExt button = this.presetButtons.get(i);
final int idx = start + i;
if (idx >= this.presets.size()) {
button.visible = false;
} else {
final PresetInfo info = this.presets.get(idx);
button.displayString = info.getTitle();
button.enabled = this.selectedPreset != idx;
button.visible = true;
final StringBuilder builder = new StringBuilder();
builder.append(TextFormatting.GOLD + info.getTitle()).append('\n');
builder.append(TextFormatting.AQUA + info.getFilename());
if (info.isRestartRequired())
builder.append('\n').append(this.TOOLTIP_RESTART_REQUIRED);
if (!StringUtils.isEmpty(info.getDescription().trim()))
builder.append("\n\n").append(TextFormatting.RESET).append(info.getDescription());
this.tooltips.set(i, new GuiTooltip(this, button, builder.toString(), PRESET_TOOLTIP_WIDTH));
}
}
updateButtonState();
}
use of org.blockartistry.Presets.data.PresetInfo in project DynamicSurroundings by OreCruncher.
the class PresetsConfigGui method confirmClicked.
@Override
public void confirmClicked(final boolean answer, final int buttonId) {
final PresetInfo pi = this.presets.get(this.selectedPreset);
switch(buttonId) {
case ID_SAVE:
if (answer) {
this.config.collectPreset(pi);
this.config.save(pi);
}
break;
case ID_DELETE:
if (answer) {
this.config.delete(pi);
reload();
}
break;
case ID_APPLY:
if (answer) {
this.config.applyPreset(pi);
}
break;
}
this.mc.displayGuiScreen(this);
}
use of org.blockartistry.Presets.data.PresetInfo in project DynamicSurroundings by OreCruncher.
the class PresetsConfigGui method actionPerformed.
@Override
protected void actionPerformed(@Nonnull final GuiButton button) throws IOException {
PresetInfo pi = this.selectedPreset != -1 ? this.presets.get(this.selectedPreset) : null;
switch(button.id) {
case ID_DONE:
this.mc.displayGuiScreen(this.parentScreen);
break;
case ID_APPLY:
{
final StringBuilder builder = new StringBuilder();
builder.append(pi.getTitle());
if (pi.isRestartRequired())
builder.append("\n\n").append(this.RESTART_REQUIRED_TEXT);
final GuiYesNo yn = new GuiYesNo(this, this.APPLY_WARNING_TEXT, builder.toString(), ID_APPLY);
this.mc.displayGuiScreen(yn);
}
break;
case ID_CREATE:
{
pi = new PresetInfo();
final PresetInfoModifyGui gui = new PresetInfoModifyGui(this, pi, false, ID_CREATE);
this.mc.displayGuiScreen(gui);
}
break;
case ID_EDIT:
{
final PresetInfoModifyGui gui = new PresetInfoModifyGui(this, pi, true, ID_EDIT);
this.mc.displayGuiScreen(gui);
}
break;
case ID_SAVE:
{
final GuiYesNo yn = new GuiYesNo(this, this.SAVE_WARNING_TEXT, pi.getTitle(), ID_SAVE);
this.mc.displayGuiScreen(yn);
}
break;
case ID_DELETE:
{
final GuiYesNo yn = new GuiYesNo(this, this.DELETE_WARNING_TEXT, pi.getTitle(), ID_DELETE);
this.mc.displayGuiScreen(yn);
}
break;
case ID_REFRESH:
reload();
break;
case ID_PREV_PAGE:
if (this.currentPage > 0) {
this.currentPage--;
setPresetButtonText();
}
break;
case ID_NEXT_PAGE:
if (this.currentPage < this.maxPage) {
this.currentPage++;
setPresetButtonText();
}
break;
default:
// Handle selection of a preset button
final int buttonMashed = button.id - ID_PRESET_BASE;
if (buttonMashed < 0 || buttonMashed >= MAX_PRESETS_PAGE) {
super.actionPerformed(button);
} else {
// A preset was hit!
if (this.selectedPreset != -1) {
// We have a preset to clear. If it's in the current range
// we need to toggle.
final int low = this.currentPage * MAX_PRESETS_PAGE;
final int high = low + MAX_PRESETS_PAGE;
if (this.selectedPreset >= low && this.selectedPreset < high) {
// It's in range
final int idx = this.selectedPreset % MAX_PRESETS_PAGE;
this.presetButtons.get(idx).enabled = true;
}
}
this.selectedPreset = this.currentPage * MAX_PRESETS_PAGE + buttonMashed;
this.presetButtons.get(buttonMashed).enabled = false;
updateButtonState();
}
}
}
Aggregations