mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 19:39:04 +07:00
Improved hover block system
This commit is contained in:
parent
efe93d0117
commit
7eaef11a84
@ -497,6 +497,7 @@ text.mech.ability = [LIGHT_GRAY]Ability\: {0}
|
||||
text.liquid.heatcapacity = [LIGHT_GRAY]Heat Capacity\: {0}
|
||||
text.liquid.viscosity = [LIGHT_GRAY]Viscosity\: {0}
|
||||
text.liquid.temperature = [LIGHT_GRAY]Temperature\: {0}
|
||||
block.constructing = {0}\n[LIGHT_GRAY](Constructing)
|
||||
block.spawn.name = Enemy Spawn
|
||||
block.core.name = Core
|
||||
block.metalfloor.name = Metal Floor
|
||||
|
@ -34,7 +34,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
* This class should <i>not</i> call any outside methods to change state of modules, but instead fire events.
|
||||
*/
|
||||
public class Logic extends Module{
|
||||
public boolean doUpdate = true;
|
||||
|
||||
public Logic(){
|
||||
Events.on(TileChangeEvent.class, event -> {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
@ -15,12 +14,12 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class SelectionTable extends Table{
|
||||
Block selected = Blocks.air;
|
||||
Tile lastTile;
|
||||
|
||||
public SelectionTable(){
|
||||
super("clear");
|
||||
|
||||
margin(4f);
|
||||
margin(5f);
|
||||
|
||||
update(() -> {
|
||||
Block result;
|
||||
@ -32,16 +31,20 @@ public class SelectionTable extends Table{
|
||||
result = null;
|
||||
}
|
||||
|
||||
if(result != null) selected = result;
|
||||
if(result != null){
|
||||
lastTile = tile;
|
||||
}
|
||||
|
||||
getTranslation().y = Mathf.lerp(getTranslation().y, result == null ? -getHeight() : 0f, 0.2f);
|
||||
});
|
||||
|
||||
Image image = new Image(new TextureRegionDrawable(new TextureRegion(Draw.region("clear"))));
|
||||
image.update(() -> ((TextureRegionDrawable)image.getDrawable()).setRegion(selected.getEditorIcon()));
|
||||
image.update(() ->
|
||||
((TextureRegionDrawable)image.getDrawable()).setRegion(lastTile == null ? Draw.getBlankRegion() :
|
||||
lastTile.block().getDisplayIcon(lastTile)));
|
||||
|
||||
add(image).size(16*2);
|
||||
label(() -> selected instanceof OreBlock ? selected.drops.item.localizedName() : selected.formalName).pad(4);
|
||||
add(image).size(16*2).padRight(4);
|
||||
label(() -> lastTile == null ? "" : lastTile.block().getDisplayName(lastTile));
|
||||
|
||||
pack();
|
||||
getTranslation().y = - getHeight();
|
||||
|
@ -452,6 +452,14 @@ public class Block extends BaseBlock {
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName(Tile tile){
|
||||
return formalName;
|
||||
}
|
||||
|
||||
public TextureRegion getDisplayIcon(Tile tile){
|
||||
return getEditorIcon();
|
||||
}
|
||||
|
||||
public TextureRegion getEditorIcon(){
|
||||
if(editorIcon == null){
|
||||
editorIcon = Draw.region("block-icon-" + name, Draw.region("clear"));
|
||||
|
@ -16,6 +16,7 @@ import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.input.CursorType;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
@ -26,6 +27,7 @@ import io.anuke.mindustry.world.modules.ItemModule;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInput;
|
||||
@ -68,6 +70,18 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Tile tile){
|
||||
BuildEntity entity = tile.entity();
|
||||
return Bundles.format("block.constructing", entity.recipe == null ? entity.previous.formalName : entity.recipe.result.formalName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion getDisplayIcon(Tile tile){
|
||||
BuildEntity entity = tile.entity();
|
||||
return (entity.recipe == null ? entity.previous : entity.recipe.result).getEditorIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidFor(Tile tile){
|
||||
BuildEntity entity = tile.entity();
|
||||
|
@ -24,6 +24,11 @@ public class OreBlock extends Floor{
|
||||
this.edge = base.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Tile tile){
|
||||
return drops.item.localizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion getEditorIcon(){
|
||||
if(editorIcon == null){
|
||||
|
Loading…
Reference in New Issue
Block a user