Skip to content

Commit

Permalink
Eresar
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Nov 6, 2014
1 parent 54b04ba commit af5fc26
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ public boolean touchDown(InputEvent event, float screenX, float screenY, int poi
if (button == Input.Buttons.RIGHT) {
dragMouseButtonPressed = true;
//HashBot.ui.grabCursor();
mouseDrag.set(screenX, screenY);
mouseDrag.set(Gdx.input.getX(), Gdx.input.getY());
return true;
} else if (button == Input.Buttons.MIDDLE) {
rotateMouseButtonPressed = true;
//HashBot.ui.grabCursor();
mouseRotationDrag.set(screenX, screenY);
mouseRotationDrag.set(Gdx.input.getX(), Gdx.input.getY());
return true;
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion core/src/macbury/forge/utils/VoxelPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean getVoxelPositionForPickRay(Ray pickRay, float far, VoxelCursor ou
pickRay.getEndPoint(rayEndPoint, j);
map.worldPositionToLocalVoxelPosition(rayEndPoint, localVoxelPosition);

if (map.isSolid(localVoxelPosition)) {
if (map.isSolid(localVoxelPosition) || localVoxelPosition.y == 0) {
map.localVoxelPositionToWorldPosition(localVoxelPosition, worldVoxelPosition);
outVoxelIntersectPoint.replace.set(worldVoxelPosition);
worldVoxelPositionWithSize.set(worldVoxelPosition).add(map.voxelSize);
Expand Down
4 changes: 4 additions & 0 deletions core/src/macbury/forge/voxel/VoxelMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,8 @@ public void setEmptyForPosition(Vector3i voxelPosition) {
public boolean isEmptyNotOutOfBounds(Vector3i voxelPosition) {
return isEmptyNotOutOfBounds(voxelPosition.x, voxelPosition.y, voxelPosition.z);
}

public boolean isOutOfBounds(Vector3i voxelPosition) {
return isOutOfBounds(voxelPosition.x, voxelPosition.y, voxelPosition.z);
}
}
3 changes: 3 additions & 0 deletions editor/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: macbury.forge.editor.DesktopLauncher

20 changes: 12 additions & 8 deletions editor/src/macbury/forge/editor/controllers/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public void setMainWindow(MainWindow mainWindow) {

private void updateUI() {
boolean editorScreenEnabled = editorScreen != null;

mainWindow.mainSplitPane.setVisible(editorScreenEnabled);
//mainWindow.openGlContainer.setVisible(editorScreenEnabled);
}

Expand Down Expand Up @@ -110,9 +112,9 @@ public void onJobStart(Job job) {
progressTaskDialog.setLocationRelativeTo(mainWindow);
progressTaskDialog.setVisible(true);
mainWindow.setEnabled(false);
} else {
jobProgressBar.setVisible(true);
}

jobProgressBar.setVisible(true);
}

@Override
Expand All @@ -125,12 +127,14 @@ public void onJobError(Job job, Exception e) {

@Override
public void onJobFinish(Job job) {
if (job.isBlockingUI()) {
progressTaskDialog.setVisible(false);
} else {
jobProgressBar.setVisible(false);
}
mainWindow.setEnabled(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jobProgressBar.setVisible(false);
progressTaskDialog.setVisible(false);
mainWindow.setEnabled(true);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import macbury.forge.editor.controllers.listeners.OnMapChangeListener;
import macbury.forge.editor.parell.JobManager;
import macbury.forge.editor.screens.EditorScreen;
import macbury.forge.editor.selection.AbstractSelection;
import macbury.forge.editor.selection.BoxSelection;
import macbury.forge.editor.selection.SelectionInterface;
import macbury.forge.editor.selection.SingleBlockSelection;
import macbury.forge.editor.selection.*;
import macbury.forge.editor.systems.SelectionSystem;
import macbury.forge.editor.undo_redo.ChangeManager;
import macbury.forge.editor.undo_redo.Changeable;
import macbury.forge.editor.undo_redo.actions.ApplyBlock;
import macbury.forge.editor.undo_redo.actions.ApplyRangeBlock;
import macbury.forge.editor.undo_redo.actions.EraserBlock;
import macbury.forge.voxel.ChunkMap;

import javax.swing.*;
Expand All @@ -26,40 +24,58 @@ public class TerrainToolsController implements OnMapChangeListener, ActionListen
private final ButtonGroup toolsGroup;
private final JToggleButton drawPencilButton;
private final SingleBlockSelection singleBlockSelection;
private final BoxSelection boxSelection;
private final BoxSelection rectSelection;
private final ButtonGroup modifyGroup;
private final JToggleButton appendBlocksButton;
private final JToggleButton replaceBlocksButton;
private final EreaseSelection ereaseSelection;
private final JToggleButton ereaserButton;
private AbstractSelection currentSelection;
private final JToggleButton drawRectButton;
private SelectionSystem selectionSystem;
private ChangeManager changeManager;
private ChunkMap map;
private EditorScreen screen;
private JobManager jobs;
private SelectType currentSelectType;

public TerrainToolsController(JToolBar terrainToolsToolbar) {
toolbar = terrainToolsToolbar;
this.toolsGroup = new ButtonGroup();
this.modifyGroup = new ButtonGroup();

this.singleBlockSelection = new SingleBlockSelection();
this.boxSelection = new BoxSelection();
this.rectSelection = new BoxSelection();
this.ereaseSelection = new EreaseSelection();

drawPencilButton = buildToogleButton("draw_pencil", toolsGroup);
drawRectButton = buildToogleButton("draw_rect", toolsGroup);
buildToogleButton("draw_bucket", toolsGroup);

buildToogleButton("draw_airbrush", toolsGroup);
buildToogleButton("draw_elipsis", toolsGroup);
buildToogleButton("draw_eraser", toolsGroup);
ereaserButton = buildToogleButton("draw_eraser", toolsGroup);

toolbar.addSeparator();

appendBlocksButton = buildToogleButton("append_blocks", modifyGroup);
replaceBlocksButton = buildToogleButton("replace_blocks", modifyGroup);
updateUI();
}

private void updateUI() {
boolean interfaceEnabled = screen != null;
boolean showAppend = !ereaserButton.isSelected();

appendBlocksButton.setVisible(showAppend);
replaceBlocksButton.setVisible(showAppend);

toolbar.setEnabled(interfaceEnabled);
drawPencilButton.setEnabled(interfaceEnabled);
drawRectButton.setEnabled(interfaceEnabled);

appendBlocksButton.setEnabled(interfaceEnabled);
replaceBlocksButton.setEnabled(interfaceEnabled);
}

private JToggleButton buildToogleButton(String iconName, ButtonGroup buttonGroup) {
Expand Down Expand Up @@ -92,6 +108,8 @@ public void onCloseMap(ProjectController controller, EditorScreen screen) {
@Override
public void onNewMap(ProjectController controller, EditorScreen screen) {
drawPencilButton.setSelected(true);
appendBlocksButton.setSelected(true);
currentSelectType = SelectType.Append;
this.screen = screen;
selectionSystem = screen.selectionSystem;
changeManager = screen.changeManager;
Expand All @@ -100,7 +118,7 @@ public void onNewMap(ProjectController controller, EditorScreen screen) {
jobs = controller.jobs;

singleBlockSelection.setVoxelSize(map.voxelSize);
boxSelection.setVoxelSize(map.voxelSize);
rectSelection.setVoxelSize(map.voxelSize);

selectionSystem.addListener(this);

Expand All @@ -113,7 +131,17 @@ public void actionPerformed(ActionEvent e) {
if (e.getSource() == drawPencilButton) {
setCurrentSelection(singleBlockSelection);
} else if (e.getSource() == drawRectButton) {
setCurrentSelection(boxSelection);
setCurrentSelection(rectSelection);
} else if (e.getSource() == ereaserButton) {
setCurrentSelection(ereaseSelection);
}

if (e.getSource() == replaceBlocksButton) {
currentSelectType = SelectType.Replace;
setCurrentSelection(currentSelection);
} else if (e.getSource() == appendBlocksButton) {
currentSelectType = SelectType.Append;
setCurrentSelection(currentSelection);
}
}

Expand All @@ -136,14 +164,18 @@ private void createTaskForSelection(AbstractSelection selection) {
Changeable task = null;
if (selection == singleBlockSelection) {
task = new ApplyBlock(selection, map);
} else if (selection == boxSelection) {
} else if (selection == rectSelection) {
task = new ApplyRangeBlock(selection, map);
} else if (selection == ereaseSelection) {
task = new EraserBlock(selection, map);
}
changeManager.addChangeable(task).apply();
}

private void setCurrentSelection(AbstractSelection currentSelection) {
this.currentSelection = currentSelection;
currentSelection.setSelectType(currentSelectType);
this.selectionSystem.setSelection(currentSelection);
updateUI();
}
}
2 changes: 1 addition & 1 deletion editor/src/macbury/forge/editor/screens/EditorScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void resize(int width, int height) {

level.resize(width, height);
stage.getViewport().update(width,height);
overlay.invalidateHierarchy();
overlay.invalidate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void setSelectType(SelectType selectType) {
}

public boolean isAppendSelectType() {
return this.selectType == SelectType.Append;
return getSelectType() == SelectType.Append;
}

public boolean isReplaceSelectType() {
return this.selectType == SelectType.Replace;
return getSelectType() == SelectType.Replace;
}

public BoundingBox getBoundingBox() {
Expand Down
11 changes: 11 additions & 0 deletions editor/src/macbury/forge/editor/selection/EreaseSelection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package macbury.forge.editor.selection;

/**
* Created by macbury on 06.11.14.
*/
public class EreaseSelection extends BoxSelection {
@Override
public SelectType getSelectType() {
return SelectType.Replace;
}
}
5 changes: 3 additions & 2 deletions editor/src/macbury/forge/editor/systems/SelectionSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
Expand Down Expand Up @@ -71,8 +72,7 @@ public void update(float deltaTime) {
}

private boolean getCurrentVoxelCursor(float screenX, float screenY) {
mousePosition.set(screenX, screenY);
Ray pickRay = camera.getPickRay(mousePosition.x, mousePosition.y);
Ray pickRay = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY());
return voxelPicker.getVoxelPositionForPickRay(pickRay, camera.far, voxelCursor);
}

Expand All @@ -82,6 +82,7 @@ public void setOverlay(Overlay overlay) {

@Override
public boolean mouseMoved(InputEvent event, float x, float y) {

if (getCurrentVoxelCursor(x,y)) {
selection.reset(voxelCursor);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package macbury.forge.editor.undo_redo.actions;

import macbury.forge.editor.selection.AbstractSelection;
import macbury.forge.editor.selection.SelectType;
import macbury.forge.voxel.VoxelMap;
import macbury.forge.voxel.VoxelMaterial;

Expand Down Expand Up @@ -39,10 +40,16 @@ public void apply() {
for (int x = (int)applyBox.min.x; x < applyBox.max.x; x++) {
for (int y = (int)applyBox.min.y; y < applyBox.max.y; y++) {
for (int z = (int)applyBox.min.z; z < applyBox.max.z; z++) {
if (!map.isEmpty(x,y,z)) {
oldMaterials[x - (int)applyBox.min.x][y - (int)applyBox.min.y][z - (int)applyBox.min.z] = map.getMaterialForPosition(x,y,z);

if (selectType == SelectType.Append) {
if (!map.isEmpty(x,y,z)) {
oldMaterials[x - (int)applyBox.min.x][y - (int)applyBox.min.y][z - (int)applyBox.min.z] = map.getMaterialForPosition(x,y,z);
}
map.setMaterialForPosition(map.materials.get(4), x,y,z);
} else if (!map.isEmpty(x,y,z)) {
map.setMaterialForPosition(map.materials.get(4), x,y,z);
}
map.setMaterialForPosition(map.materials.get(4), x,y,z);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import com.badlogic.gdx.math.collision.BoundingBox;
import macbury.forge.editor.selection.AbstractSelection;
import macbury.forge.editor.selection.SelectType;
import macbury.forge.editor.undo_redo.Changeable;
import macbury.forge.utils.Vector3i;

/**
* Created by macbury on 03.11.14.
*/
public abstract class CursorChangeable extends Changeable {
protected SelectType selectType;
protected Vector3i from;
protected Vector3i to;
protected BoundingBox applyBox;

public CursorChangeable(AbstractSelection selection) {
this.from = new Vector3i();
this.to = new Vector3i();
applyBox = new BoundingBox();

this.selectType = selection.getSelectType();

this.from.set(selection.getStartPosition());
this.to.set(selection.getEndPostion());
applyBox = new BoundingBox();

applyBox.set(selection.getBoundingBox());
}
}
50 changes: 50 additions & 0 deletions editor/src/macbury/forge/editor/undo_redo/actions/EraserBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package macbury.forge.editor.undo_redo.actions;

import macbury.forge.editor.selection.AbstractSelection;
import macbury.forge.voxel.VoxelMap;
import macbury.forge.voxel.VoxelMaterial;

/**
* Created by macbury on 06.11.14.
*/
public class EraserBlock extends TerrainCursorChangeable {
private VoxelMaterial oldMaterials[][][];

public EraserBlock(AbstractSelection selection, VoxelMap map) {
super(selection, map);
}

@Override
public void revert() {
for (int x = (int)applyBox.min.x; x < applyBox.max.x; x++) {
for (int y = (int)applyBox.min.y; y < applyBox.max.y; y++) {
for (int z = (int)applyBox.min.z; z < applyBox.max.z; z++) {
VoxelMaterial mat = oldMaterials[x - (int)applyBox.min.x][y - (int)applyBox.min.y][z - (int)applyBox.min.z];
if (mat == null) {
map.setEmptyForPosition(x,y,z);
} else {
map.setMaterialForPosition(mat, x,y,z);
}

}
}
}

oldMaterials = null;
}

@Override
public void apply() {
this.oldMaterials = new VoxelMaterial[(int)applyBox.getWidth()][(int)applyBox.getHeight()][(int)applyBox.getDepth()];
for (int x = (int)applyBox.min.x; x < applyBox.max.x; x++) {
for (int y = (int)applyBox.min.y; y < applyBox.max.y; y++) {
for (int z = (int)applyBox.min.z; z < applyBox.max.z; z++) {
if (!map.isEmpty(x,y,z)) {
oldMaterials[x - (int)applyBox.min.x][y - (int)applyBox.min.y][z - (int)applyBox.min.z] = map.getMaterialForPosition(x,y,z);
}
map.setEmptyForPosition(x,y,z);
}
}
}
}
}
Loading

0 comments on commit af5fc26

Please sign in to comment.