Skip to content

Commit

Permalink
Replace SelectBlocksPanel with SingleBlockSelector class.
Browse files Browse the repository at this point in the history
SingleBlockSelector extends PagedSelector class which contains all iterating through elements.
  • Loading branch information
BONNe committed Feb 3, 2022
1 parent 665789d commit c413f0b
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ protected CommonPanel(CommonPanel parentPanel)
/**
* This method allows to build panel.
*/
public abstract void build();
protected abstract void build();


/**
* Rebuilds this GUI.
*/
public final void reopen()
{
this.build();
}


// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private PanelItem createButton(Action button)
this.mode = Mode.VIEW;
this.build();
} else if (this.parentPanel != null) {
this.parentPanel.build();
this.parentPanel.reopen();
} else {
user.closeInventory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private PanelItem createButton(Action button)
clickHandler = (panel, user, clickType, i) -> {

if (this.parentPanel != null) {
this.parentPanel.build();
this.parentPanel.reopen();
} else {
user.closeInventory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import world.bentobox.magiccobblestonegenerator.panels.CommonPanel;
import world.bentobox.magiccobblestonegenerator.panels.ConversationUtils;
import world.bentobox.magiccobblestonegenerator.panels.utils.SelectBiomePanel;
import world.bentobox.magiccobblestonegenerator.panels.utils.SelectBlocksPanel;
import world.bentobox.magiccobblestonegenerator.panels.utils.SelectGeneratorTypePanel;
import world.bentobox.magiccobblestonegenerator.panels.utils.SingleBlockSelector;
import world.bentobox.magiccobblestonegenerator.utils.Constants;
import world.bentobox.magiccobblestonegenerator.utils.Pair;
import world.bentobox.magiccobblestonegenerator.utils.Utils;
Expand Down Expand Up @@ -889,7 +889,7 @@ private PanelItem createButton(Action button)

clickHandler = (panel, user, clickType, i) -> {
if (this.parentPanel != null) {
this.parentPanel.build();
this.parentPanel.reopen();
} else {
user.closeInventory();
}
Expand Down Expand Up @@ -942,46 +942,54 @@ private PanelItem createButton(Action button)
description.add(this.user.getTranslation(Constants.TIPS + "click-to-add"));

icon = Material.WRITABLE_BOOK;
clickHandler = (panel, user1, clickType, slot) -> {

SelectBlocksPanel.open(user1,
true,
this.activeTab == Tab.BLOCKS,
value -> {
if (value != null) {
Consumer<Number> numberConsumer = number -> {
if (number != null) {
if (this.activeTab == Tab.BLOCKS) {
this.materialChanceList.add(
new Pair<>(value.iterator().next(),
number.doubleValue()));

this.generatorTier.setBlockChanceMap(
Utils.pairList2TreeMap(this.materialChanceList));
this.manager.saveGeneratorTier(this.generatorTier);
} else if (this.activeTab == Tab.TREASURES) {
this.treasureChanceList.add(
new Pair<>(new ItemStack(value.iterator().next()),
number.doubleValue()));

this.generatorTier.setTreasureItemChanceMap(
Utils.pairList2TreeMap(this.treasureChanceList));
this.manager.saveGeneratorTier(this.generatorTier);
}
clickHandler = (panel, user1, clickType, slot) ->
{
SingleBlockSelector.open(this.user,
this.activeTab == Tab.BLOCKS ? SingleBlockSelector.Mode.BLOCKS : SingleBlockSelector.Mode.ANY,
(value, material) ->
{
if (value)
{
Consumer<Number> numberConsumer = number ->
{
if (number != null)
{
if (this.activeTab == Tab.BLOCKS)
{
this.materialChanceList.add(
new Pair<>(material,
number.doubleValue()));

this.generatorTier.setBlockChanceMap(
Utils.pairList2TreeMap(this.materialChanceList));
this.manager.saveGeneratorTier(this.generatorTier);
}
else if (this.activeTab == Tab.TREASURES)
{
this.treasureChanceList.add(
new Pair<>(new ItemStack(material),
number.doubleValue()));

this.generatorTier.setTreasureItemChanceMap(
Utils.pairList2TreeMap(this.treasureChanceList));
this.manager.saveGeneratorTier(this.generatorTier);
}
}

this.build();
};

ConversationUtils.createNumericInput(numberConsumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "input-number"),
0.0,
Long.MAX_VALUE);
} else {
this.build();
}
});
};

ConversationUtils.createNumericInput(numberConsumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "input-number"),
0.0,
Long.MAX_VALUE);
}
else
{
this.build();
}
});

return true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import world.bentobox.magiccobblestonegenerator.config.Settings;
import world.bentobox.magiccobblestonegenerator.panels.CommonPanel;
import world.bentobox.magiccobblestonegenerator.panels.ConversationUtils;
import world.bentobox.magiccobblestonegenerator.panels.utils.SelectBlocksPanel;
import world.bentobox.magiccobblestonegenerator.panels.utils.SingleBlockSelector;
import world.bentobox.magiccobblestonegenerator.utils.Constants;


Expand Down Expand Up @@ -257,13 +257,11 @@ private PanelItem createButton(Action button)
material = this.settings.getBorderBlock();
clickHandler = (panel, user1, clickType, slot) -> {

SelectBlocksPanel.open(user1,
true,
false,
value -> {
if (value != null)
SingleBlockSelector.open(this.user,
(value, newMaterial) -> {
if (value)
{
this.settings.setBorderBlock(value.iterator().next());
this.settings.setBorderBlock(newMaterial);
this.saveSettings();
}

Expand Down Expand Up @@ -394,7 +392,7 @@ private PanelItem createButton(Action button)
clickHandler = (panel, user, clickType, i) -> {
if (this.parentPanel != null)
{
this.parentPanel.build();
this.parentPanel.reopen();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private PanelItem createButton(Action button)

clickHandler = (panel, user, clickType, i) -> {
if (this.parentPanel != null) {
this.parentPanel.build();
this.parentPanel.reopen();
} else {
user.closeInventory();
}
Expand Down

0 comments on commit c413f0b

Please sign in to comment.