[editor only] Fix few crash with mini map
This commit is contained in:
@@ -42,6 +42,7 @@ public class HyperLap2dRendererMiniMap extends HyperLap2dRenderer {
|
|||||||
|
|
||||||
minimapCamera.setToOrtho(true, bounds.width, bounds.height);
|
minimapCamera.setToOrtho(true, bounds.width, bounds.height);
|
||||||
minimapCamera.position.set(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2,0);
|
minimapCamera.position.set(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2,0);
|
||||||
|
if (bounds.width == 0 || bounds.height == 0) return null;
|
||||||
|
|
||||||
Gdx.gl.glClearColor(0.318f, 0.318f, 0.318f, 1);
|
Gdx.gl.glClearColor(0.318f, 0.318f, 0.318f, 1);
|
||||||
frameBufferManager.createIfNotExists("minimap", (int) (bounds.width * pixelsPerWU), (int) (bounds.height * pixelsPerWU), false, hasStencilBuffer);
|
frameBufferManager.createIfNotExists("minimap", (int) (bounds.width * pixelsPerWU), (int) (bounds.height * pixelsPerWU), false, hasStencilBuffer);
|
||||||
|
|||||||
@@ -49,16 +49,19 @@ public class MiniMapDialog extends Table {
|
|||||||
setBackground(VisUI.getSkin().getDrawable("panel"));
|
setBackground(VisUI.getSkin().getDrawable("panel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public boolean update() {
|
||||||
Sandbox sandbox = Sandbox.getInstance();
|
Sandbox sandbox = Sandbox.getInstance();
|
||||||
HyperLap2dRendererMiniMap rendererMiniMap = sandbox.getEngine().getSystem(HyperLap2dRendererMiniMap.class);
|
HyperLap2dRendererMiniMap rendererMiniMap = sandbox.getEngine().getSystem(HyperLap2dRendererMiniMap.class);
|
||||||
|
|
||||||
Texture texture = rendererMiniMap.getMiniMapTexture(sandbox.getRootEntity());
|
Texture texture = rendererMiniMap.getMiniMapTexture(sandbox.getRootEntity());
|
||||||
|
if (texture == null) return false;
|
||||||
|
|
||||||
region.setRegion(texture);
|
region.setRegion(texture);
|
||||||
drawable.setRegion(region);
|
drawable.setRegion(region);
|
||||||
miniMap.setScaling(Scaling.contain);
|
miniMap.setScaling(Scaling.contain);
|
||||||
miniMap.setDrawable(drawable);
|
miniMap.setDrawable(drawable);
|
||||||
|
|
||||||
miniMapBounds = rendererMiniMap.getMiniMapBounds();
|
miniMapBounds = rendererMiniMap.getMiniMapBounds();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package games.rednblack.editor.view.ui.dialog;
|
package games.rednblack.editor.view.ui.dialog;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
import games.rednblack.editor.proxy.ProjectManager;
|
||||||
import games.rednblack.editor.view.stage.Sandbox;
|
import games.rednblack.editor.view.stage.Sandbox;
|
||||||
import games.rednblack.editor.view.stage.UIStage;
|
import games.rednblack.editor.view.stage.UIStage;
|
||||||
import games.rednblack.h2d.common.MsgAPI;
|
import games.rednblack.h2d.common.MsgAPI;
|
||||||
@@ -12,13 +13,15 @@ public class MiniMapDialogMediator extends Mediator<MiniMapDialog> {
|
|||||||
private static final String TAG = MiniMapDialogMediator.class.getCanonicalName();
|
private static final String TAG = MiniMapDialogMediator.class.getCanonicalName();
|
||||||
private static final String NAME = TAG;
|
private static final String NAME = TAG;
|
||||||
|
|
||||||
|
private boolean projectOpened = false;
|
||||||
|
|
||||||
public MiniMapDialogMediator() {
|
public MiniMapDialogMediator() {
|
||||||
super(NAME, new MiniMapDialog());
|
super(NAME, new MiniMapDialog());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void listNotificationInterests(Interests interests) {
|
public void listNotificationInterests(Interests interests) {
|
||||||
interests.add(MsgAPI.SHOW_MINI_MAP, MsgAPI.HIDE_MINI_MAP);
|
interests.add(MsgAPI.SHOW_MINI_MAP, MsgAPI.HIDE_MINI_MAP, ProjectManager.PROJECT_OPENED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -28,14 +31,20 @@ public class MiniMapDialogMediator extends Mediator<MiniMapDialog> {
|
|||||||
UIStage uiStage = sandbox.getUIStage();
|
UIStage uiStage = sandbox.getUIStage();
|
||||||
|
|
||||||
switch (notification.getName()) {
|
switch (notification.getName()) {
|
||||||
|
case ProjectManager.PROJECT_OPENED:
|
||||||
|
projectOpened = true;
|
||||||
|
break;
|
||||||
case MsgAPI.SHOW_MINI_MAP:
|
case MsgAPI.SHOW_MINI_MAP:
|
||||||
|
if (!projectOpened) break;
|
||||||
viewComponent.setSize(uiStage.getWidth() * 0.6f, uiStage.getHeight() * 0.6f);
|
viewComponent.setSize(uiStage.getWidth() * 0.6f, uiStage.getHeight() * 0.6f);
|
||||||
viewComponent.setOrigin(Align.center);
|
viewComponent.setOrigin(Align.center);
|
||||||
viewComponent.update();
|
if (viewComponent.update()) {
|
||||||
uiStage.addActor(viewComponent);
|
uiStage.addActor(viewComponent);
|
||||||
viewComponent.setPosition((uiStage.getWidth() - viewComponent.getWidth()) / 2, (uiStage.getHeight() - viewComponent.getHeight()) / 2);
|
viewComponent.setPosition((uiStage.getWidth() - viewComponent.getWidth()) / 2, (uiStage.getHeight() - viewComponent.getHeight()) / 2);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MsgAPI.HIDE_MINI_MAP:
|
case MsgAPI.HIDE_MINI_MAP:
|
||||||
|
if (!projectOpened) break;
|
||||||
viewComponent.remove();
|
viewComponent.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user