Change selected block when changing category (#837)
* Change selected block when changing category * Use an ObjectMap in the HUD fragment instead of attribute in category
This commit is contained in:
@@ -30,6 +30,7 @@ public class PlacementFragment extends Fragment{
|
|||||||
Array<Category> returnCatArray = new Array<>();
|
Array<Category> returnCatArray = new Array<>();
|
||||||
boolean[] categoryEmpty = new boolean[Category.all.length];
|
boolean[] categoryEmpty = new boolean[Category.all.length];
|
||||||
Category currentCategory = Category.distribution;
|
Category currentCategory = Category.distribution;
|
||||||
|
ObjectMap<Category,Block> selectedBlocks = new ObjectMap<Category,Block>();
|
||||||
Block hovered, lastDisplay;
|
Block hovered, lastDisplay;
|
||||||
Tile lastHover;
|
Tile lastHover;
|
||||||
Tile hoverTile;
|
Tile hoverTile;
|
||||||
@@ -49,6 +50,10 @@ public class PlacementFragment extends Fragment{
|
|||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Events.on(ResetEvent.class, event -> {
|
||||||
|
selectedBlocks.clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void rebuild(){
|
void rebuild(){
|
||||||
@@ -112,6 +117,7 @@ public class PlacementFragment extends Fragment{
|
|||||||
ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> {
|
ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> {
|
||||||
if(unlocked(block)){
|
if(unlocked(block)){
|
||||||
control.input.block = control.input.block == block ? null : block;
|
control.input.block = control.input.block == block ? null : block;
|
||||||
|
selectedBlocks.put(currentCategory, control.input.block);
|
||||||
}
|
}
|
||||||
}).size(46f).group(group).name("block-" + block.name).get();
|
}).size(46f).group(group).name("block-" + block.name).get();
|
||||||
|
|
||||||
@@ -266,6 +272,12 @@ public class PlacementFragment extends Fragment{
|
|||||||
|
|
||||||
categories.addImageButton(Core.atlas.drawable("icon-" + cat.name() + "-smaller"), Styles.clearToggleTransi, () -> {
|
categories.addImageButton(Core.atlas.drawable("icon-" + cat.name() + "-smaller"), Styles.clearToggleTransi, () -> {
|
||||||
currentCategory = cat;
|
currentCategory = cat;
|
||||||
|
if(control.input.block != null){
|
||||||
|
if(selectedBlocks.get(currentCategory) == null){
|
||||||
|
selectFirstBlock(currentCategory);
|
||||||
|
}
|
||||||
|
control.input.block = selectedBlocks.get(currentCategory);
|
||||||
|
}
|
||||||
rebuildCategory.run();
|
rebuildCategory.run();
|
||||||
}).group(group).update(i -> i.setChecked(currentCategory == cat)).name("category-" + cat.name());
|
}).group(group).update(i -> i.setChecked(currentCategory == cat)).name("category-" + cat.name());
|
||||||
}
|
}
|
||||||
@@ -301,6 +313,16 @@ public class PlacementFragment extends Fragment{
|
|||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Block selectFirstBlock(Category cat) {
|
||||||
|
for(Block block : getByCategory(currentCategory)){
|
||||||
|
if(unlocked(block)){
|
||||||
|
selectedBlocks.put(currentCategory, block);
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
boolean unlocked(Block block){
|
boolean unlocked(Block block){
|
||||||
return !world.isZone() || data.isUnlocked(block);
|
return !world.isZone() || data.isUnlocked(block);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user