Skip to content

Commit

Permalink
[editor only] Fix few crash with mini map
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnm committed Jul 5, 2024
1 parent 902663d commit ebb7255
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Texture getMiniMapTexture(int rootEntity) {

minimapCamera.setToOrtho(true, bounds.width, bounds.height);
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);
frameBufferManager.createIfNotExists("minimap", (int) (bounds.width * pixelsPerWU), (int) (bounds.height * pixelsPerWU), false, hasStencilBuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ public void clicked(InputEvent event, float x, float y) {
setBackground(VisUI.getSkin().getDrawable("panel"));
}

public void update() {
public boolean update() {
Sandbox sandbox = Sandbox.getInstance();
HyperLap2dRendererMiniMap rendererMiniMap = sandbox.getEngine().getSystem(HyperLap2dRendererMiniMap.class);

Texture texture = rendererMiniMap.getMiniMapTexture(sandbox.getRootEntity());
if (texture == null) return false;

region.setRegion(texture);
drawable.setRegion(region);
miniMap.setScaling(Scaling.contain);
miniMap.setDrawable(drawable);

miniMapBounds = rendererMiniMap.getMiniMapBounds();
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package games.rednblack.editor.view.ui.dialog;

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.UIStage;
import games.rednblack.h2d.common.MsgAPI;
Expand All @@ -12,13 +13,15 @@ public class MiniMapDialogMediator extends Mediator<MiniMapDialog> {
private static final String TAG = MiniMapDialogMediator.class.getCanonicalName();
private static final String NAME = TAG;

private boolean projectOpened = false;

public MiniMapDialogMediator() {
super(NAME, new MiniMapDialog());
}

@Override
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
Expand All @@ -28,14 +31,20 @@ public void handleNotification(INotification notification) {
UIStage uiStage = sandbox.getUIStage();

switch (notification.getName()) {
case ProjectManager.PROJECT_OPENED:
projectOpened = true;
break;
case MsgAPI.SHOW_MINI_MAP:
if (!projectOpened) break;
viewComponent.setSize(uiStage.getWidth() * 0.6f, uiStage.getHeight() * 0.6f);
viewComponent.setOrigin(Align.center);
viewComponent.update();
uiStage.addActor(viewComponent);
viewComponent.setPosition((uiStage.getWidth() - viewComponent.getWidth()) / 2, (uiStage.getHeight() - viewComponent.getHeight()) / 2);
if (viewComponent.update()) {
uiStage.addActor(viewComponent);
viewComponent.setPosition((uiStage.getWidth() - viewComponent.getWidth()) / 2, (uiStage.getHeight() - viewComponent.getHeight()) / 2);
}
break;
case MsgAPI.HIDE_MINI_MAP:
if (!projectOpened) break;
viewComponent.remove();
break;
}
Expand Down

0 comments on commit ebb7255

Please sign in to comment.