Skip to content

Commit

Permalink
Playing around with using a radial context menu on home screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanceewing committed Jan 31, 2024
1 parent b8ad33a commit 74bc776
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ eclipse.project.name = appName + '-core'

dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.github.payne911:PieMenu:$pieMenuVersion"
}
80 changes: 79 additions & 1 deletion core/src/main/java/com/agifans/agile/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
Expand All @@ -43,6 +44,8 @@
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.payne.games.piemenu.AnimatedPieWidget;
import com.payne.games.piemenu.PieWidget;

/**
* (Placeholder for the AGilE title screen and game selection pages)
Expand All @@ -62,6 +65,9 @@ public class HomeScreen extends InputAdapter implements Screen {
private Map<String, Texture> buttonTextureMap;
private Texture backgroundLandscape;
private Texture backgroundPortrait;
private AnimatedPieWidget portraitMenuWidget;
private AnimatedPieWidget landscapeMenuWidget;
private Texture whitePixelTexture;

/**
* Invoked by AGILE whenever it would like to show a dialog, such as when it needs
Expand Down Expand Up @@ -116,7 +122,11 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) {
viewportManager = ViewportManager.getInstance();
portraitStage = createStage(viewportManager.getPortraitViewport(), appConfig, 3, 5);
landscapeStage = createStage(viewportManager.getLandscapeViewport(), appConfig, 5, 3);


whitePixelTexture = createWhitePixelTexture();
portraitMenuWidget = createMenuWidget(portraitStage);
landscapeMenuWidget = createMenuWidget(landscapeStage);

// The stage handles most of the input, but we need to handle the BACK button
// separately.
portraitInputProcessor = new InputMultiplexer();
Expand All @@ -127,11 +137,65 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) {
landscapeInputProcessor.addProcessor(this);
}

private Texture createWhitePixelTexture() {
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(1,1,1,1);
pixmap.fill();
Texture texture = new Texture(pixmap);
pixmap.dispose();
return texture;
}

private AnimatedPieWidget createMenuWidget(Stage stage) {
AnimatedPieWidget widget = null;

TextureRegion whitePixel = new TextureRegion(whitePixelTexture);

// Setting up and creating the widget.
PieWidget.PieWidgetStyle style = new PieWidget.PieWidgetStyle();
style.sliceColor = new Color(0.9f, 0.9f, 0.9f, 0.9f);
style.separatorWidth = 2;
style.circumferenceWidth = 2;
style.separatorColor = style.circumferenceColor;
widget = new AnimatedPieWidget(whitePixel, style, 160, 40f/160, 315, 270);

// Populating the widget
Label playLabel = new Label("X", skin);
playLabel.setFontScale(2f);
playLabel.setAlignment(Align.center);
widget.addActor(playLabel);

Label deleteLabel = new Label("Delete", skin);
deleteLabel.setFontScale(2f);
deleteLabel.setAlignment(Align.center);
widget.addActor(deleteLabel);

Label editLabel = new Label("Edit", skin);
editLabel.setFontScale(2f);
editLabel.setAlignment(Align.center);
widget.addActor(editLabel);

// Including the Widget in the Stage
stage.addActor(widget);
widget.setVisible(false);

return widget;
}

private Stage createStage(Viewport viewport, AppConfig appConfig, int columns, int rows) {
Stage stage = new Stage(viewport);
addAppButtonsToStage(stage, appConfig, columns, rows);
return stage;
}

private AnimatedPieWidget getCurrentMenuWidget() {
if (viewportManager.isPortrait()) {
return portraitMenuWidget;
}
else {
return landscapeMenuWidget;
}
}

private void addAppButtonsToStage(Stage stage, AppConfig appConfig, int columns, int rows) {
Table container = new Table();
Expand Down Expand Up @@ -266,6 +330,8 @@ public void dispose() {
texture.dispose();
}

whitePixelTexture.dispose();

saveAppConfigMap();
}

Expand Down Expand Up @@ -487,6 +553,16 @@ public boolean longPress(final Actor actor, float x, float y) {
final AppConfigItem appConfigItem = appConfigMap.get(appName);
if (appConfigItem != null) {
longPressActor = actor;

AnimatedPieWidget widget = getCurrentMenuWidget();
widget.toggleVisibility(0.7f);
widget.setPosition(
actor.getX(Align.center),
actor.getY(Align.center) + 15,
Align.center);


/*
dialogHandler.confirm(
"Do you want to remove '" + appConfigItem.getName() + "'?",
new ConfirmResponseHandler() {
Expand All @@ -503,6 +579,8 @@ public void yes() {
public void no() {
}
});
*/

}
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ enableGraalNative=false
gwtFrameworkVersion=2.10.0
gwtPluginVersion=1.1.29
gdxVersion=1.12.1
pieMenuVersion=5.0.0
shapedrawerVersion=2.3.0
2 changes: 2 additions & 0 deletions html/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies {
implementation "com.google.jsinterop:jsinterop-annotations:2.0.2:sources"
implementation "de.knightsoft-net:gwt-webworker:1.0.8"
implementation "org.ainslec:gwt-jszip:1.0.0"
implementation "space.earlygrey:shapedrawer:$shapedrawerVersion:sources"
api "com.github.payne911:PieMenu:$pieMenuVersion:sources"
implementation project(':core')

}
Expand Down
1 change: 1 addition & 0 deletions html/src/main/java/com/agifans/agile/GdxDefinition.gwt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<inherits name="com.agifans.agile.Agile" />
<inherits name='com.google.gwt.webworker.WebWorker' />
<inherits name='com.akjava.gwt.jszip.GWTJSZip'/>
<inherits name="PieMenu"/>
<entry-point class="com.agifans.agile.gwt.GwtLauncher" />
<set-configuration-property name="gdx.assetpath" value="../assets" />
<set-configuration-property name="xsiframe.failIfScriptTag" value="FALSE"/>
Expand Down

0 comments on commit 74bc776

Please sign in to comment.