Skip to content

Commit

Permalink
Merge pull request #2 from Interrupt/texture-picker
Browse files Browse the repository at this point in the history
Preserve textures when creating sectors / lines.
  • Loading branch information
Interrupt authored Jul 15, 2016
2 parents 835c40f + 72b13fb commit dfabcd4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
32 changes: 25 additions & 7 deletions core/src/com/interrupt/doomtest/DoomTestEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public enum EditorModes { SECTOR, POINT, SPLIT };

public static float GRID_SNAP = 2f;

Image texturePickerButton;
TextureRegion currentTexture;

@Override
public void create () {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Expand Down Expand Up @@ -142,7 +145,9 @@ public boolean touchDown(int screenX, int screenY, int pointer, int btn) {
// Texture picker
Array<TextureRegion> textures = loadTexturesFromAtlas("textures/textures.png");
textures.add(new TextureRegion(Art.getTexture("textures/wall1.png")));
setupHud(textures);

currentTexture = textures.get(textures.size - 1);
setupHud(textures, currentTexture);
}

public void refreshRenderer() {
Expand Down Expand Up @@ -406,6 +411,10 @@ else if(button == Input.Buttons.RIGHT) {
hoveredSector.match(pickedSector);
refreshRenderer();
}
else if(pickedLine != null && hoveredLine != null) {
hoveredLine.match(pickedLine);
refreshRenderer();
}
}
}
}
Expand Down Expand Up @@ -457,7 +466,8 @@ public void finishSector() {

if (parent != null) {
parent.addSubSector(current);
current.ceilHeight = parent.ceilHeight;
current.match(parent);
if(editHeight != null) current.floorHeight = editHeight;

// parent's sectors might now be contained by this new sector
editor.refreshSectorParents(current, parent);
Expand All @@ -471,20 +481,25 @@ public void finishSector() {

if (i > 0) {
Vector2 prev = points.get(i - 1);
editor.addLine(current, prev, p);
editor.addLine(current, prev, p, currentTexture);
}
}

// close the loop, if it isn't
Vector2 startPoint = points.first();
Vector2 lastPoint = points.get(points.size - 1);
if (!lastPoint.equals(startPoint)) {
editor.addLine(current, lastPoint, startPoint);
editor.addLine(current, lastPoint, startPoint, currentTexture);
}

if (parent == null)
if (parent == null) {
level.sectors.add(current);

// set texture
current.floorMaterial.set(TextureAttribute.createDiffuse(currentTexture));
current.ceilingMaterial.set(TextureAttribute.createDiffuse(currentTexture));
}


// solid parents mean line solidity might change now
if (parent != null && parent.isSolid) {
Expand Down Expand Up @@ -731,8 +746,8 @@ public void renderGrid() {
lineRenderer.end();
}

private void setupHud(final Array<TextureRegion> textures) {
Image texturePickerButton = new Image(new TextureRegionDrawable(textures.first()));
private void setupHud(final Array<TextureRegion> textures, TextureRegion current) {
texturePickerButton = new Image(new TextureRegionDrawable(current));
texturePickerButton.setScaling(Scaling.stretch);

Table wallPickerLayoutTable = new Table();
Expand All @@ -749,6 +764,7 @@ public void clicked(InputEvent event, float x, float y) {
@Override
public void result(Integer value, TextureRegion region) {
setTexture(region);
texturePickerButton.setDrawable(new TextureRegionDrawable(region));
}
};
hudStage.addActor(picker);
Expand All @@ -761,6 +777,8 @@ public void result(Integer value, TextureRegion region) {
}

public void setTexture(TextureRegion texture) {
currentTexture = texture;

if(pickedLine != null) {
pickedLine.lowerMaterial.set(TextureAttribute.createDiffuse(texture));
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/com/interrupt/doomtest/levels/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ public Plane.PlaneSide getLowerWallSide() {
}
return Plane.PlaneSide.Front;
}

public void match(Line other) {
lowerMaterial.set(other.lowerMaterial.get(TextureAttribute.Diffuse));
}
}
5 changes: 5 additions & 0 deletions core/src/com/interrupt/doomtest/levels/Sector.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.badlogic.gdx.utils.Array;
import com.interrupt.doomtest.gfx.Art;

import javax.xml.soap.Text;

public class Sector {
public Array<Vector2> points = new Array<Vector2>();
public Sector parent = null;
Expand Down Expand Up @@ -225,5 +227,8 @@ public void removePoint(Vector2 vertex) {
public void match(Sector other) {
floorHeight = other.floorHeight;
ceilHeight = other.ceilHeight;

floorMaterial.set((other.floorMaterial.get(TextureAttribute.Diffuse)));
ceilingMaterial.set((other.ceilingMaterial.get(TextureAttribute.Diffuse)));
}
}
7 changes: 6 additions & 1 deletion core/src/com/interrupt/doomtest/levels/editor/Editor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.interrupt.doomtest.levels.editor;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Plane;
import com.badlogic.gdx.math.Vector2;
Expand Down Expand Up @@ -123,6 +125,8 @@ public void addPointToLine(Line l, Vector2 point) {
l.end = point;

Line newLine = new Line(point, oldEnd, l.solid, l.left, l.right);
newLine.match(l);

level.lines.add(newLine);

addNewPointToSector(new Line(l.start, oldEnd, l.solid, l.left, l.right), point, level.sectors);
Expand Down Expand Up @@ -211,7 +215,7 @@ public void addVertex(Vector2 vertex) {
if(existing == null) level.vertices.add(vertex);
}

public void addLine(Sector current, Vector2 start, Vector2 end) {
public void addLine(Sector current, Vector2 start, Vector2 end, TextureRegion texture) {

// don't duplicate verts
Vector2 existingStart = getExistingVertex(start);
Expand All @@ -230,6 +234,7 @@ public void addLine(Sector current, Vector2 start, Vector2 end) {

if(existing == null) {
level.lines.add(line);
line.lowerMaterial.set(TextureAttribute.createDiffuse(texture));
}
else {
if(existing.left == current.parent) {
Expand Down

0 comments on commit dfabcd4

Please sign in to comment.