Skip to content

Commit 45bd254

Browse files
Add confirmation step to Clear button in channel GUI (#66)
1 parent 050f0b5 commit 45bd254

3 files changed

Lines changed: 219 additions & 3 deletions

File tree

src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class GuiScreenConfigureChannels extends GuiContainer implements IGuiScre
6464
private GuiTextField key, value;
6565
protected int guiTop, guiLeft;
6666
private List<String> info;
67+
private boolean wipePending = false;
68+
private long wipePendingTime = 0;
69+
private static final long WIPE_CONFIRM_TIMEOUT_MS = 3000;
6770

6871
public GuiScreenConfigureChannels(Container container, ItemStack trigger) {
6972
super(container);
@@ -346,9 +349,17 @@ protected void actionPerformed(GuiButton btn) {
346349
ChannelDataAccessor.unsetChannelData(trigger, key.getText());
347350
break;
348351
case WIPE_BTN:
349-
ChannelDataAccessor.wipeChannelData(trigger);
350-
key.setText("");
351-
this.value.setText("");
352+
if (!wipePending) {
353+
wipePending = true;
354+
wipePendingTime = System.currentTimeMillis();
355+
btn.displayString = I18n.format(I18N_PREFIX + "wipe.confirm");
356+
} else {
357+
wipePending = false;
358+
btn.displayString = I18n.format(I18N_PREFIX + "wipe");
359+
ChannelDataAccessor.wipeChannelData(trigger);
360+
key.setText("");
361+
this.value.setText("");
362+
}
352363
break;
353364
}
354365

@@ -369,6 +380,10 @@ public void updateScreen() {
369380
super.updateScreen();
370381
key.updateCursorCounter();
371382
value.updateCursorCounter();
383+
if (wipePending && System.currentTimeMillis() - wipePendingTime > WIPE_CONFIRM_TIMEOUT_MS) {
384+
wipePending = false;
385+
getButtonList().get(WIPE_BTN).displayString = I18n.format(I18N_PREFIX + "wipe");
386+
}
372387
}
373388

374389
@Override

src/main/resources/assets/structurelib/lang/en_US.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ item.structurelib.constructableTrigger.gui.add=Add
3737
item.structurelib.constructableTrigger.gui.set=Update
3838
item.structurelib.constructableTrigger.gui.unset=Remove
3939
item.structurelib.constructableTrigger.gui.wipe=§4Clear
40+
item.structurelib.constructableTrigger.gui.wipe.confirm=§4Sure?
4041
item.structurelib.constructableTrigger.gui.channels.from=§rMod: §9§o%s
4142
item.structurelib.constructableTrigger.gui.info=Many multiblocks support some degree of variation in their structure and a sub channel allows indication of which variant to use.\n All sub channels have a sequence of lowercase characters as key and a positive integer as value. Most known sub channels should be available as typeahead completions.\n You can also drag and drop items from NEI to set the corresponding sub channel value. These items all have a tooltip of "§oIndicates§r §ovalue§r §oX§r §ofor§r §osub§r §ochannel§r §oY§r".
4243

0 commit comments

Comments
 (0)