mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-26 00:29:30 +00:00
Got undo working for map editor (though it is slow because redraw is still slow), also bumped undo to 20 levels.
This commit is contained in:
parent
6854b8d744
commit
47231d366b
|
@ -27,7 +27,7 @@ import org.jvnet.jaxb2_commons.lang.CopyTo2;
|
|||
* @author brobert
|
||||
*/
|
||||
public abstract class Editor<T, D> implements DataObserver<T> {
|
||||
public static final int UNDO_HISTORY_LENGTH = 10;
|
||||
public static final int UNDO_HISTORY_LENGTH = 20;
|
||||
LinkedList<T> undoStates = new LinkedList<>();
|
||||
|
||||
T editEntity;
|
||||
|
@ -35,6 +35,7 @@ public abstract class Editor<T, D> implements DataObserver<T> {
|
|||
public void setEntity(T t) {
|
||||
editEntity = t;
|
||||
DataProducer.addObserver(t, this);
|
||||
onEntityUpdated();
|
||||
}
|
||||
|
||||
public T getEntity() {
|
||||
|
@ -107,7 +108,12 @@ public abstract class Editor<T, D> implements DataObserver<T> {
|
|||
if (!undoStates.isEmpty()) {
|
||||
CopyTo2 undoState = (CopyTo2) undoStates.removeFirst();
|
||||
undoState.copyTo(getEntity());
|
||||
onEntityUpdated();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onEntityUpdated() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,9 +69,8 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
|
|||
double tileHeight = currentPlatform.tileRenderer.getHeight() * zoom;
|
||||
|
||||
@Override
|
||||
public void setEntity(Map t) {
|
||||
super.setEntity(t);
|
||||
currentMap = new TileMap(t);
|
||||
protected void onEntityUpdated() {
|
||||
currentMap = new TileMap(getEntity());
|
||||
}
|
||||
|
||||
public TileMap getCurrentMap() {
|
||||
|
@ -557,6 +556,12 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
|
|||
DrawMode lastDrawMode = null;
|
||||
Tile lastTile = null;
|
||||
|
||||
@Override
|
||||
protected void trackState() {
|
||||
currentMap.updateBackingMap();
|
||||
super.trackState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MouseEvent t) {
|
||||
updateCursorAssistant(t);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
* ANY KIND, either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.badvision.outlaweditor.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -95,7 +94,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||
|
||||
private void registerLocationScript(int x, int y, Script s) {
|
||||
if (!scriptColors.containsKey(s)) {
|
||||
scriptColors.put(s, Color.hsb(HUE, SATURATION, 0.75 + Math.cos(HUE / Math.PI / 2.0)/8.0));
|
||||
scriptColors.put(s, Color.hsb(HUE, SATURATION, 0.75 + Math.cos(HUE / Math.PI / 2.0) / 8.0));
|
||||
HUE = (HUE + 27) % 360;
|
||||
}
|
||||
int loc = getMortonNumber(x, y);
|
||||
|
@ -178,7 +177,8 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||
Set<Tile> unknownTiles = new HashSet<>();
|
||||
Scripts scripts = m.getScripts();
|
||||
if (scripts != null) {
|
||||
scripts.getScript().forEach(
|
||||
List<Script> allScripts = new ArrayList<>(scripts.getScript());
|
||||
allScripts.forEach(
|
||||
s -> s.getLocationTrigger().forEach(
|
||||
l -> registerLocationScript(l.getX(), l.getY(), s)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user