Added IndexedRenderer rotation, map editor rotation

This commit is contained in:
Anuken 2018-05-21 23:00:40 -04:00
parent 3b5a9c0a10
commit 2d65c9734c
9 changed files with 398 additions and 345 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

View File

@ -151,6 +151,7 @@ text.enemies.single={0} Enemy
text.loadimage=Load Image text.loadimage=Load Image
text.saveimage=Save Image text.saveimage=Save Image
text.oregen=Ore Generation text.oregen=Ore Generation
text.editor.teams=Teams
text.editor.badsize=[orange]Invalid image dimensions![]\nValid map dimensions: {0} text.editor.badsize=[orange]Invalid image dimensions![]\nValid map dimensions: {0}
text.editor.errorimageload=Error loading image file:\n[orange]{0} text.editor.errorimageload=Error loading image file:\n[orange]{0}
text.editor.errorimagesave=Error saving image file:\n[orange]{0} text.editor.errorimagesave=Error saving image file:\n[orange]{0}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -17,6 +17,7 @@ public class MapEditor{
private MapRenderer renderer = new MapRenderer(this); private MapRenderer renderer = new MapRenderer(this);
private int brushSize = 1; private int brushSize = 1;
private int rotation;
private Block drawBlock = Blocks.stone; private Block drawBlock = Blocks.stone;
private Team drawTeam = Team.none; private Team drawTeam = Team.none;
@ -35,6 +36,14 @@ public class MapEditor{
renderer.resize(map.width(), map.height()); renderer.resize(map.width(), map.height());
} }
public int getDrawRotation(){
return rotation;
}
public void setDrawRotation(int rotation){
this.rotation = rotation;
}
public void setDrawTeam(Team team){ public void setDrawTeam(Team team){
this.drawTeam = team; this.drawTeam = team;
} }
@ -75,6 +84,10 @@ public class MapEditor{
writer.team = (byte)drawTeam.ordinal(); writer.team = (byte)drawTeam.ordinal();
} }
if(drawBlock.rotate){
writer.rotation = (byte)rotation;
}
if(drawBlock.isMultiblock()){ if(drawBlock.isMultiblock()){
int offsetx = -(drawBlock.size-1)/2; int offsetx = -(drawBlock.size-1)/2;

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
@ -32,6 +33,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.utils.UIUtils; import io.anuke.ucore.scene.utils.UIUtils;
import io.anuke.ucore.util.Bundles; import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -313,10 +315,12 @@ public class MapEditorDialog extends Dialog{
tools.defaults().size(60f, 64f).padBottom(-5.1f); tools.defaults().size(60f, 64f).padBottom(-5.1f);
tools.addImageButton("icon-back", 16*2, () -> hide()); //tools.addImageButton("icon-back", 16*2, () -> hide());
tools.addImageButton("icon-menu-large", 16*2f, menu::show); tools.addImageButton("icon-menu-large", 16*2f, menu::show);
ImageButton grid = tools.addImageButton("icon-grid", "toggle", 16*2f, () -> view.setGrid(!view.isGrid())).get();
tools.row(); tools.row();
ImageButton undo = tools.addImageButton("icon-undo", 16*2f, () -> view.undo()).get(); ImageButton undo = tools.addImageButton("icon-undo", 16*2f, () -> view.undo()).get();
@ -324,8 +328,6 @@ public class MapEditorDialog extends Dialog{
tools.row(); tools.row();
ImageButton grid = tools.addImageButton("icon-grid", "toggle", 16*2f, () -> view.setGrid(!view.isGrid())).get();
undo.setDisabled(() -> !view.getStack().canUndo()); undo.setDisabled(() -> !view.getStack().canUndo());
redo.setDisabled(() -> !view.getStack().canRedo()); redo.setDisabled(() -> !view.getStack().canRedo());
@ -343,9 +345,23 @@ public class MapEditorDialog extends Dialog{
button.setChecked(true); button.setChecked(true);
tools.add(button).padBottom(-5.1f); tools.add(button).padBottom(-5.1f);
if(i++ % 2 == 1) tools.row(); if(i++ % 2 == 0) tools.row();
} }
ImageButton rotate = tools.addImageButton("icon-arrow-16", 16*2f, () -> editor.setDrawRotation((editor.getDrawRotation() + 1)%4)).get();
rotate.getImage().update(() ->{
rotate.getImage().setRotation(editor.getDrawRotation() * 90);
rotate.getImage().setOrigin(Align.center);
});
tools.row();
tools.table("button", t -> {
t.add("$text.editor.teams");
}).colspan(2).height(40).width(120f);
tools.row();
ButtonGroup<ImageButton> teamgroup = new ButtonGroup<>(); ButtonGroup<ImageButton> teamgroup = new ButtonGroup<>();
for(Team team : Team.values()){ for(Team team : Team.values()){
@ -418,6 +434,14 @@ public class MapEditorDialog extends Dialog{
saveDialog.save(); saveDialog.save();
} }
if(Inputs.keyTap(Input.R)){
editor.setDrawRotation((editor.getDrawRotation() + 1)%4);
}
if(Inputs.keyTap(Input.E)){
editor.setDrawRotation(Mathf.mod((editor.getDrawRotation() + 1), 4));
}
if(Inputs.keyTap(Input.G)){ if(Inputs.keyTap(Input.G)){
view.setGrid(!view.isGrid()); view.setGrid(!view.isGrid());
} }
@ -454,6 +478,7 @@ public class MapEditorDialog extends Dialog{
button.getImageCell().setActor(stack); button.getImageCell().setActor(stack);
button.addChild(stack); button.addChild(stack);
button.getImage().remove(); button.getImage().remove();
button.update(() -> button.setChecked(editor.getDrawBlock() == block));
group.add(button); group.add(button);
content.add(button).pad(4f).size(53f, 58f); content.add(button).pad(4f).size(53f, 58f);

View File

@ -106,9 +106,16 @@ public class MapRenderer {
TextureRegion wregion = (wall == Blocks.air || wall == Blocks.blockpart) ? Draw.region("clear"): wall.getBlockIcon()[wall.getBlockIcon().length-1]; TextureRegion wregion = (wall == Blocks.air || wall == Blocks.blockpart) ? Draw.region("clear"): wall.getBlockIcon()[wall.getBlockIcon().length-1];
region = wregion; region = wregion;
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize, if(wall.rotate){
region.getRegionWidth(), region.getRegionHeight()); mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
region.getRegionWidth(), region.getRegionHeight(), data.rotation*90 - 90);
}else{
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
region.getRegionWidth(), region.getRegionHeight());
}
if(wall.update || wall.destructible) { if(wall.update || wall.destructible) {
mesh.setColor(Team.values()[data.team].color); mesh.setColor(Team.values()[data.team].color);