In-game editing (broken)
This commit is contained in:
@@ -40,6 +40,10 @@ public class GameState{
|
||||
state = astate;
|
||||
}
|
||||
|
||||
public boolean isEditor(){
|
||||
return rules.editor;
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
return (is(State.paused) && !Net.active()) || (gameOver && !Net.active());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DrawOperation{
|
||||
public void undo(MapEditor editor){
|
||||
for(int i = array.size - 1; i >= 0; i--){
|
||||
long l = array.get(i);
|
||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
||||
set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,12 @@ public class DrawOperation{
|
||||
public void redo(MapEditor editor){
|
||||
for(int i = 0; i < array.size; i++){
|
||||
long l = array.get(i);
|
||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
||||
set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
||||
}
|
||||
}
|
||||
|
||||
short get(MapEditor editor, Tile tile, byte type){
|
||||
short get(Tile tile, byte type){
|
||||
if(type == OpType.floor.ordinal()){
|
||||
return tile.floorID();
|
||||
}else if(type == OpType.block.ordinal()){
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.editor;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.editor.DrawOperation.OpType;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.TileOp;
|
||||
@@ -9,6 +10,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.modules.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
//TODO somehow remove or replace this class with a more flexible solution
|
||||
@@ -18,13 +20,13 @@ public class EditorTile extends Tile{
|
||||
super(x, y, floor, overlay, wall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Team getTeam(){
|
||||
return Team.all[getTeamID()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloor(Floor type){
|
||||
if(state.is(State.playing)){
|
||||
super.setFloor(type);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type instanceof OverlayFloor){
|
||||
//don't place on liquids
|
||||
if(!floor.isLiquid){
|
||||
@@ -41,18 +43,37 @@ public class EditorTile extends Tile{
|
||||
|
||||
@Override
|
||||
public void setBlock(Block type){
|
||||
if(state.is(State.playing)){
|
||||
super.setBlock(type);
|
||||
return;
|
||||
}
|
||||
|
||||
if(block == type) return;
|
||||
op(OpType.block, block.id);
|
||||
if(rotation != 0) op(OpType.rotation, rotation);
|
||||
if(team != 0) op(OpType.team, team);
|
||||
super.setBlock(type);
|
||||
}
|
||||
|
||||
//TODO check if this line is necessary
|
||||
//if(pteam != getTeamID()){
|
||||
// op((byte)OpType.team.ordinal(), pteam, getTeamID());
|
||||
//}
|
||||
@Override
|
||||
public void setBlock(Block type, Team team, int rotation){
|
||||
if(state.is(State.playing)){
|
||||
super.setBlock(type, team, rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
setBlock(type);
|
||||
setTeam(team);
|
||||
rotation(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeam(Team team){
|
||||
if(state.is(State.playing)){
|
||||
super.setTeam(team);
|
||||
return;
|
||||
}
|
||||
|
||||
if(getTeamID() == team.ordinal()) return;
|
||||
op(OpType.team, getTeamID());
|
||||
super.setTeam(team);
|
||||
@@ -60,6 +81,11 @@ public class EditorTile extends Tile{
|
||||
|
||||
@Override
|
||||
public void rotation(int rotation){
|
||||
if(state.is(State.playing)){
|
||||
super.rotation(rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
if(rotation == rotation()) return;
|
||||
op(OpType.rotation, rotation());
|
||||
super.rotation(rotation);
|
||||
@@ -67,6 +93,11 @@ public class EditorTile extends Tile{
|
||||
|
||||
@Override
|
||||
public void setOverlayID(short overlay){
|
||||
if(state.is(State.playing)){
|
||||
super.setOverlayID(overlay);
|
||||
return;
|
||||
}
|
||||
|
||||
if(overlayID() == overlay) return;
|
||||
op(OpType.overlay, overlay);
|
||||
super.setOverlayID(overlay);
|
||||
@@ -74,11 +105,21 @@ public class EditorTile extends Tile{
|
||||
|
||||
@Override
|
||||
protected void preChanged(){
|
||||
if(state.is(State.playing)){
|
||||
super.preChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
super.setTeam(Team.none);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void changed(){
|
||||
if(state.is(State.playing)){
|
||||
super.changed();
|
||||
return;
|
||||
}
|
||||
|
||||
entity = null;
|
||||
|
||||
if(block == null){
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.editor;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.StringMap;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.function.Consumer;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
@@ -18,6 +19,7 @@ import io.anuke.arc.scene.ui.layout.Unit;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.game.Gamemode;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.MapIO;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
@@ -131,6 +133,10 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
|
||||
menu.cont.row();
|
||||
|
||||
menu.cont.addImageTextButton("$play", "icon-play", isize, this::playtest).padTop(-5).size(swidth * 2f + 10, 60f);
|
||||
|
||||
menu.cont.row();
|
||||
|
||||
menu.cont.addImageTextButton("$quit", "icon-back", isize, () -> {
|
||||
tryExit();
|
||||
menu.hide();
|
||||
@@ -203,6 +209,28 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
drawDefaultBackground(x, y);
|
||||
}
|
||||
|
||||
public void resumeEditing(){
|
||||
shownWithMap = true;
|
||||
show();
|
||||
editor.renderer().updateAll();
|
||||
}
|
||||
|
||||
private void playtest(){
|
||||
menu.hide();
|
||||
ui.loadAnd(() -> {
|
||||
hide();
|
||||
//logic.reset();
|
||||
state.rules = Gamemode.editor.get();
|
||||
world.setMap(new Map(StringMap.of(
|
||||
"name", "Editor Playtesting",
|
||||
"width", editor.width(),
|
||||
"height", editor.height()
|
||||
)));
|
||||
world.endMapLoad();
|
||||
logic.play();
|
||||
});
|
||||
}
|
||||
|
||||
private void save(){
|
||||
String name = editor.getTags().get("name", "").trim();
|
||||
|
||||
|
||||
@@ -34,12 +34,25 @@ public enum Gamemode{
|
||||
unitBuildSpeedMultiplier = 3f;
|
||||
unitHealthMultiplier = 2f;
|
||||
attackMode = true;
|
||||
}});
|
||||
}}),
|
||||
editor(true, () -> new Rules(){{
|
||||
infiniteResources = true;
|
||||
editor = true;
|
||||
waves = true;
|
||||
waveTimer = false;
|
||||
respawnTime = 0f;
|
||||
}}),;
|
||||
|
||||
private final Supplier<Rules> rules;
|
||||
public final boolean hidden;
|
||||
|
||||
Gamemode(Supplier<Rules> rules){
|
||||
this(false, rules);
|
||||
}
|
||||
|
||||
Gamemode(boolean hidden, Supplier<Rules> rules){
|
||||
this.rules = rules;
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public Rules get(){
|
||||
|
||||
@@ -60,4 +60,6 @@ public class Rules{
|
||||
public boolean waitForWaveToEnd = false;
|
||||
/** Determinates if gamemode is attack mode */
|
||||
public boolean attackMode = false;
|
||||
/** Whether this is the editor gamemode. */
|
||||
public boolean editor = false;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class CustomGameDialog extends FloatingDialog{
|
||||
Table modes = new Table();
|
||||
|
||||
for(Gamemode mode : Gamemode.values()){
|
||||
if(mode.hidden) continue;
|
||||
modes.addButton(mode.toString(), "toggle", () -> {
|
||||
selectedGamemode = mode;
|
||||
rules = mode.get();
|
||||
@@ -147,6 +148,7 @@ public class CustomGameDialog extends FloatingDialog{
|
||||
pane.setFadeScrollBars(false);
|
||||
table.row();
|
||||
for(Gamemode mode : Gamemode.values()){
|
||||
if(mode.hidden) continue;
|
||||
table.labelWrap("[accent]" + mode.toString() + ":[] [lightgray]" + mode.description()).width(400f);
|
||||
table.row();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PausedDialog extends FloatingDialog{
|
||||
}
|
||||
cont.addButton("$settings", ui.settings::show);
|
||||
|
||||
if(!world.isZone()){
|
||||
if(!world.isZone() && !state.isEditor()){
|
||||
cont.row();
|
||||
cont.addButton("$savegame", save::show);
|
||||
cont.addButton("$loadgame", load::show).disabled(b -> Net.active());
|
||||
@@ -55,9 +55,10 @@ public class PausedDialog extends FloatingDialog{
|
||||
|
||||
cont.row();
|
||||
|
||||
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
||||
|
||||
cont.row();
|
||||
if(!state.isEditor()){
|
||||
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
||||
cont.row();
|
||||
}
|
||||
|
||||
cont.addButton("$quit", () -> {
|
||||
ui.showConfirm("$confirm", "$quit.confirm", () -> {
|
||||
@@ -74,7 +75,7 @@ public class PausedDialog extends FloatingDialog{
|
||||
cont.addRowImageTextButton("$back", "icon-play-2", isize, this::hide);
|
||||
cont.addRowImageTextButton("$settings", "icon-tools", isize, ui.settings::show);
|
||||
|
||||
if(!world.isZone()){
|
||||
if(!world.isZone() && !state.isEditor()){
|
||||
cont.addRowImageTextButton("$save", "icon-save", isize, save::show);
|
||||
|
||||
cont.row();
|
||||
@@ -84,7 +85,9 @@ public class PausedDialog extends FloatingDialog{
|
||||
cont.row();
|
||||
}
|
||||
|
||||
cont.addRowImageTextButton("$hostserver.mobile", "icon-host", isize, ui.host::show).disabled(b -> Net.active());
|
||||
if(!state.isEditor()){
|
||||
cont.addRowImageTextButton("$hostserver.mobile", "icon-host", isize, ui.host::show).disabled(b -> Net.active());
|
||||
}
|
||||
cont.addRowImageTextButton("$quit", "icon-quit", isize, () -> {
|
||||
ui.showConfirm("$confirm", "$quit.confirm", () -> {
|
||||
if(Net.client()) netClient.disconnectQuietly();
|
||||
@@ -96,8 +99,12 @@ public class PausedDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
public void runExitSave(){
|
||||
if(control.saves.getCurrent() == null ||
|
||||
!control.saves.getCurrent().isAutosave()){
|
||||
if(state.isEditor()){
|
||||
ui.editor.resumeEditing();
|
||||
return;
|
||||
}
|
||||
|
||||
if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave()){
|
||||
state.set(State.menu);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ public class Tile implements Position, TargetTrait{
|
||||
protected Block block;
|
||||
protected Floor floor;
|
||||
/** Rotation, 0-3. Also used to store offload location, in which case it can be any number.*/
|
||||
private byte rotation;
|
||||
protected byte rotation;
|
||||
/** Team ordinal. */
|
||||
private byte team;
|
||||
protected byte team;
|
||||
/** Ore that is on top of this (floor) block. */
|
||||
private short overlay = 0;
|
||||
protected short overlay = 0;
|
||||
|
||||
public Tile(int x, int y){
|
||||
this.x = (short)x;
|
||||
@@ -140,25 +140,12 @@ public class Tile implements Position, TargetTrait{
|
||||
preChanged();
|
||||
this.block = type;
|
||||
this.team = (byte)team.ordinal();
|
||||
this.rotation = 0;
|
||||
this.rotation = (byte)Mathf.mod(rotation, 4);
|
||||
changed();
|
||||
}
|
||||
|
||||
public void setBlock(Block type, int rotation){
|
||||
preChanged();
|
||||
this.block = type;
|
||||
this.rotation = 0;
|
||||
this.rotation = (byte)Mathf.mod(rotation, 4);
|
||||
changed();
|
||||
}
|
||||
|
||||
public void setBlock(Block type, Team team){
|
||||
preChanged();
|
||||
this.block = type;
|
||||
this.team = (byte)team.ordinal();
|
||||
this.rotation = 0;
|
||||
changed();
|
||||
setBlock(type, team, 0);
|
||||
}
|
||||
|
||||
public void setBlock(Block type){
|
||||
|
||||
Reference in New Issue
Block a user