Skip to content

Commit

Permalink
Merge pull request #280 from saltares/issue-274
Browse files Browse the repository at this point in the history
Fix crash in SandboxMediator when currentSelectedTool is null #274
  • Loading branch information
azakhary committed Oct 25, 2015
2 parents c9518f4 + 02bb57a commit e3367b2
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions overlap2d/src/com/uwsoft/editor/view/stage/SandboxMediator.java
Expand Up @@ -95,8 +95,11 @@ private void initTools() {

private void setCurrentTool(String toolName) {
currentSelectedTool = sandboxTools.get(toolName);
facade.sendNotification(SANDBOX_TOOL_CHANGED, currentSelectedTool);
currentSelectedTool.initTool();

if (currentSelectedTool != null) {
facade.sendNotification(SANDBOX_TOOL_CHANGED, currentSelectedTool);
currentSelectedTool.initTool();
}
}

@Override
Expand Down Expand Up @@ -207,7 +210,7 @@ public boolean touchDown(Entity entity, float x, float y, int pointer, int butto
}

Vector2 coords = getStageCoordinates();
return currentSelectedTool.itemMouseDown(entity, coords.x, coords.y);
return currentSelectedTool != null && currentSelectedTool.itemMouseDown(entity, coords.x, coords.y);
}


Expand All @@ -220,11 +223,13 @@ public void touchUp(Entity entity, float x, float y, int pointer, int button) {
toolHotSwapBack();
}

currentSelectedTool.itemMouseUp(entity, x, y);
if (currentSelectedTool != null) {
currentSelectedTool.itemMouseUp(entity, x, y);

if (getTapCount() == 2) {
// this is double click
currentSelectedTool.itemMouseDoubleClick(entity, coords.x, coords.y);
if (getTapCount() == 2) {
// this is double click
currentSelectedTool.itemMouseDoubleClick(entity, coords.x, coords.y);
}
}

if (button == Input.Buttons.RIGHT) {
Expand All @@ -236,7 +241,10 @@ public void touchUp(Entity entity, float x, float y, int pointer, int button) {
@Override
public void touchDragged(Entity entity, float x, float y, int pointer) {
Vector2 coords = getStageCoordinates();
currentSelectedTool.itemMouseDragged(entity, coords.x, coords.y);

if (currentSelectedTool != null) {
currentSelectedTool.itemMouseDragged(entity, coords.x, coords.y);
}
}

}
Expand Down Expand Up @@ -374,7 +382,9 @@ public boolean touchDown(Entity entity, float x, float y, int pointer, int butto
break;
}

currentSelectedTool.stageMouseDown(x, y);
if (currentSelectedTool != null) {
currentSelectedTool.stageMouseDown(x, y);
}

return true;
}
Expand Down Expand Up @@ -409,15 +419,18 @@ public void touchUp(Entity entity, float x, float y, int pointer, int button) {
}

private void doubleClick(Entity entity, float x, float y) {
Sandbox sandbox = Sandbox.getInstance();
currentSelectedTool.stageMouseDoubleClick(x, y);
if (currentSelectedTool != null) {
Sandbox sandbox = Sandbox.getInstance();
currentSelectedTool.stageMouseDoubleClick(x, y);
}
}

@Override
public void touchDragged(Entity entity, float x, float y, int pointer) {
Sandbox sandbox = Sandbox.getInstance();

currentSelectedTool.stageMouseDragged(x, y);
if (currentSelectedTool != null) {
Sandbox sandbox = Sandbox.getInstance();
currentSelectedTool.stageMouseDragged(x, y);
}
}


Expand Down Expand Up @@ -489,9 +502,6 @@ private void toolHotSwapBack() {
}

public String getCurrentSelectedToolName() {
if(currentSelectedTool == null) {
return "";
}
return currentSelectedTool.getName();
return currentSelectedTool != null ? currentSelectedTool.getName() : "";
}
}

0 comments on commit e3367b2

Please sign in to comment.