mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-21 03:51:41 -08:00
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:
parent
c540f8e5f5
commit
485fc3ea2a
1 changed files with 22 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ public class PlacementFragment extends Fragment{
|
|||
Array<Category> returnCatArray = new Array<>();
|
||||
boolean[] categoryEmpty = new boolean[Category.all.length];
|
||||
Category currentCategory = Category.distribution;
|
||||
ObjectMap<Category,Block> selectedBlocks = new ObjectMap<Category,Block>();
|
||||
Block hovered, lastDisplay;
|
||||
Tile lastHover;
|
||||
Tile hoverTile;
|
||||
|
|
@ -49,6 +50,10 @@ public class PlacementFragment extends Fragment{
|
|||
rebuild();
|
||||
}
|
||||
});
|
||||
|
||||
Events.on(ResetEvent.class, event -> {
|
||||
selectedBlocks.clear();
|
||||
});
|
||||
}
|
||||
|
||||
void rebuild(){
|
||||
|
|
@ -112,6 +117,7 @@ public class PlacementFragment extends Fragment{
|
|||
ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> {
|
||||
if(unlocked(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();
|
||||
|
||||
|
|
@ -266,6 +272,12 @@ public class PlacementFragment extends Fragment{
|
|||
|
||||
categories.addImageButton(Core.atlas.drawable("icon-" + cat.name() + "-smaller"), Styles.clearToggleTransi, () -> {
|
||||
currentCategory = cat;
|
||||
if(control.input.block != null){
|
||||
if(selectedBlocks.get(currentCategory) == null){
|
||||
selectFirstBlock(currentCategory);
|
||||
}
|
||||
control.input.block = selectedBlocks.get(currentCategory);
|
||||
}
|
||||
rebuildCategory.run();
|
||||
}).group(group).update(i -> i.setChecked(currentCategory == cat)).name("category-" + cat.name());
|
||||
}
|
||||
|
|
@ -301,6 +313,16 @@ public class PlacementFragment extends Fragment{
|
|||
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){
|
||||
return !world.isZone() || data.isUnlocked(block);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue