mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add step selector for int setting gui.
This commit is contained in:
parent
c5dbbeb67c
commit
f0ec2151b3
2 changed files with 75 additions and 4 deletions
|
|
@ -47,7 +47,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
||||||
public void updateGuiValues() {
|
public void updateGuiValues() {
|
||||||
// Update item with value
|
// Update item with value
|
||||||
ItemStack setting1Item = new ItemStack(Material.STONE);
|
ItemStack setting1Item = new ItemStack(Material.STONE);
|
||||||
AbstractSettingGui.SettingGuiFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", ConfigHolder.DEFAULT_CONFIG, 0,42,2,1);
|
AbstractSettingGui.SettingGuiFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", ConfigHolder.DEFAULT_CONFIG, 0,255,2,1, 5, 10, 50, 100);
|
||||||
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
||||||
pane.bindItem('1', setting1);
|
pane.bindItem('1', setting1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class IntSettingsGui extends AbstractSettingGui{
|
public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
@ -30,13 +32,14 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
this.step = holder.steps[0];
|
this.step = holder.steps[0];
|
||||||
|
|
||||||
updateValueDisplay();
|
updateValueDisplay();
|
||||||
|
initStepsValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pattern getGuiPattern() {
|
public Pattern getGuiPattern() {
|
||||||
return new Pattern(
|
return new Pattern(
|
||||||
"000000000",
|
"abcdefghi",
|
||||||
"00-0v0+00",
|
"00-0v0+00",
|
||||||
"B0000000S"
|
"B0000000S"
|
||||||
);
|
);
|
||||||
|
|
@ -58,7 +61,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
minusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
minusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
||||||
}else{
|
}else{
|
||||||
minusItem = GuiGlobalItems.backgroundItem();
|
minusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||||
}
|
}
|
||||||
pane.bindItem('-', minusItem);
|
pane.bindItem('-', minusItem);
|
||||||
|
|
||||||
|
|
@ -75,7 +78,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
plusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
plusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
||||||
}else{
|
}else{
|
||||||
plusItem = GuiGlobalItems.backgroundItem();
|
plusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||||
}
|
}
|
||||||
pane.bindItem('+', plusItem);
|
pane.bindItem('+', plusItem);
|
||||||
|
|
||||||
|
|
@ -99,6 +102,74 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initStepsValue(){
|
||||||
|
// Put background glass on the background of 'a' to 'b'
|
||||||
|
GuiItem background = GuiGlobalItems.backgroundItem();
|
||||||
|
PatternPane pane = getPane();
|
||||||
|
|
||||||
|
for (char i = 'a'; i < 'a'+9; i++) {
|
||||||
|
pane.bindItem(i, background);
|
||||||
|
}
|
||||||
|
// Then update legit step values
|
||||||
|
updateStepValue();
|
||||||
|
}
|
||||||
|
protected void updateStepValue(){
|
||||||
|
if(holder.steps.length <= 1) return;
|
||||||
|
// We assume steps have a length of 2k+1 cause its more pretty
|
||||||
|
char val = 'e'; // e is the middle, maybe rework this part to remove magic number.
|
||||||
|
// Offset
|
||||||
|
val -= (char) ((holder.steps.length-1)/2);
|
||||||
|
|
||||||
|
// Then place items
|
||||||
|
PatternPane pane = getPane();
|
||||||
|
for (int i = 0; i < holder.steps.length; i++) {
|
||||||
|
pane.bindItem(val+i, stepGuiItem(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GuiItem stepGuiItem(int stepIndex){
|
||||||
|
int stepValue = holder.steps[stepIndex];
|
||||||
|
|
||||||
|
// Get material properties
|
||||||
|
Material stepMat;
|
||||||
|
StringBuilder stepName = new StringBuilder("\u00A7");
|
||||||
|
List<String> stepLore;
|
||||||
|
Consumer<InventoryClickEvent> clickEvent;
|
||||||
|
if(stepValue == step){
|
||||||
|
stepMat = Material.GREEN_STAINED_GLASS_PANE;
|
||||||
|
stepName.append('a');
|
||||||
|
stepLore = Collections.singletonList("\u00A77Value is changing by a step of "+stepValue);
|
||||||
|
clickEvent = GuiGlobalActions.stayInPlace;
|
||||||
|
}else{
|
||||||
|
stepMat = Material.RED_STAINED_GLASS_PANE;
|
||||||
|
stepName.append('c');
|
||||||
|
stepLore = Collections.singletonList("\u00A77Click here to change the value of a step by "+stepValue);
|
||||||
|
clickEvent = updateStepValue(stepValue);
|
||||||
|
}
|
||||||
|
stepName.append("Step of: ").append(stepValue);
|
||||||
|
|
||||||
|
// Create item stack then gui item
|
||||||
|
ItemStack item = new ItemStack(stepMat);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
meta.setDisplayName(stepName.toString());
|
||||||
|
meta.setLore(stepLore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
return new GuiItem(item, clickEvent, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Consumer<InventoryClickEvent> updateStepValue(int stepValue){
|
||||||
|
return event -> {
|
||||||
|
event.setCancelled(true);
|
||||||
|
this.step = stepValue;
|
||||||
|
updateStepValue();
|
||||||
|
updateValueDisplay();
|
||||||
|
update();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSave() {
|
public boolean onSave() {
|
||||||
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue