Skip to content

Commit

Permalink
WaypointDialog -- show all waypoints in current sector, with ability …
Browse files Browse the repository at this point in the history
…to toggle visual navigation to them

* Calculate skill level progress % correctly
* InputDialog -- will be used to rename map waypoints & for other things that may require user input
  • Loading branch information
Hitonoriol committed Aug 4, 2021
1 parent 8f9ef16 commit b9d1564
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.Show
allprojects {
apply plugin: "eclipse"

version = 'v0.49.15a'
version = 'v0.49.16a'

ext {
appName = "MadSand"
Expand Down
Binary file modified core/assets/textures/textures2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions core/src/hitonoriol/madsand/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,20 @@ public static int getFontSize(BitmapFont font) {
.findFirst().orElse(-1);
}

private static GlyphLayout modifyGlyph(String text, int fontSize) {
private static GlyphLayout modifyGlyph(CharSequence text, int fontSize) {
glyphLayout.setText(getFont(fontSize), text);
return glyphLayout;
}

private static GlyphLayout modifyGlyph(String text) {
private static GlyphLayout modifyGlyph(CharSequence text) {
return modifyGlyph(text, FONT_S);
}

public static float getTextWidth(String text, int fontSize) {
public static float getTextWidth(CharSequence text, int fontSize) {
return modifyGlyph(text, fontSize).width;
}

public static float getTextWidth(String text) {
public static float getTextWidth(CharSequence text) {
return getTextWidth(text, FONT_S);
}

Expand Down
22 changes: 14 additions & 8 deletions core/src/hitonoriol/madsand/dialog/GameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.lang3.StringUtils;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
Expand All @@ -23,7 +22,6 @@
import hitonoriol.madsand.util.TimeUtils;

public class GameDialog extends Dialog {
public static final float BTN_WIDTH = Gdx.graphics.getWidth() / 4;
public static final float BTN_HEIGHT = 35;

private static final float TITLE_YPADDING = 18;
Expand All @@ -47,7 +45,7 @@ public GameDialog(String title, String text, Stage stage) {
Label titleLbl = super.getTitleLabel();
titleTbl.getCell(titleLbl);
titleTbl.padTop(TITLE_YPADDING).padLeft(TITLE_XPADDING);

getButtonTable().defaults().size(Gui.BTN_WIDTH, Gui.BTN_HEIGHT);
row();
textLbl = new Label("", Gui.skin);
setText(text);
Expand Down Expand Up @@ -173,14 +171,22 @@ public void changed(ChangeEvent event, Actor actor) {
addButton(button);
}

public Cell<TextButton> addButton(TextButton button) {
public Cell<TextButton> addButton(TextButton button, boolean breakRow) {
if (proceedButton == null)
proceedButton = button;

Cell<TextButton> cell = add(button).width(BTN_WIDTH).height(BTN_HEIGHT).padBottom(PADDING / 2);
cell.row();
Cell<TextButton> cell = add(button)
.width(Math.max(Gui.BTN_WIDTH, Gui.getTextWidth(button.getText())))
.height(BTN_HEIGHT)
.padBottom(PADDING / 2);
if (breakRow)
cell.row();
return cell;
}

public Cell<TextButton> addButton(TextButton button) {
return addButton(button, true);
}

public TextButton getProceedButton() {
return proceedButton;
Expand All @@ -193,7 +199,7 @@ public void show() {
show(stage);
}

public TextButton createCloseButton() {
protected TextButton createCloseButton() {
TextButton closeButton = new TextButton("Close", Gui.skin);
Gui.setAction(closeButton, () -> remove());
return closeButton;
Expand All @@ -204,7 +210,7 @@ public Cell<TextButton> addCloseButton(float width, float height) {
}

public Cell<TextButton> addCloseButton() {
return addCloseButton(Gui.BTN_WIDTH, Gui.BTN_HEIGHT);
return addCloseButton(Gui.BTN_WIDTH, BTN_HEIGHT);
}

public void setPrefSize(float width, float height) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/hitonoriol/madsand/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1291,14 +1291,14 @@ public boolean walk(Direction dir) {

@Override
public void stopMovement() {
if (!hasQueuedMovement())
super.stopMovement();
if (!hasQueuedMovement()) {
Keyboard.resumeInput();

if (afterMovement != null) {
afterMovement.run();
afterMovement = null;
if (afterMovement != null) {
afterMovement.run();
afterMovement = null;
}
}
super.stopMovement();
}

public void doAfterMovement(Runnable action) {
Expand Down
8 changes: 8 additions & 0 deletions core/src/hitonoriol/madsand/entities/StatContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public int getSum() {
sum += get(stat);
return sum;
}

public int getMaxSum() {
return maxStatSum;
}

public int getMinSum() {
return maxStatSum - 1;
}

@JsonIgnore
public int getFreePoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import hitonoriol.madsand.Gui;
import hitonoriol.madsand.MadSand;
import hitonoriol.madsand.gui.dialogs.LevelupDialog;
import hitonoriol.madsand.resources.Resources;
import hitonoriol.madsand.util.Utils;

Expand Down Expand Up @@ -54,7 +55,7 @@ public boolean check(Skill skill, boolean verbose) {

if (skill.equals(Skill.Level)) {
MadSand.player().stats.baseStats.increaseMaxStatSum();
Gui.overlay.levelUpDialog();
new LevelupDialog().show();
} else
Gui.drawOkDialog(skill + " up!", "Your " + skill + " skill is now level " + get(skill).lvl + "!");
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/entities/skill/SkillValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean check() {
}

public float getProgress() {
return (float) (((exp - lvlStartExp) / requiredExp) * 100);
return (float) (((exp - lvlStartExp) / (requiredExp - lvlStartExp)) * 100);
}

public void addExp(double amt) {
Expand Down
42 changes: 42 additions & 0 deletions core/src/hitonoriol/madsand/gui/dialogs/InputDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hitonoriol.madsand.gui.dialogs;

import java.util.function.Consumer;

import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;

import hitonoriol.madsand.Gui;
import hitonoriol.madsand.dialog.GameDialog;

public class InputDialog extends GameDialog {
private static final float PAD = Gui.BTN_HEIGHT * 0.65f;
private static final String DEF_TITLE = "Input";
private TextField textField = new TextField("", Gui.skin);

public InputDialog(String title, String prompt, Consumer<String> inputConsumer) {
makeBordered();
centerTitle();
setTitle(title);
if (prompt != null)
add(prompt).height(Gui.FONT_S).padBottom(PAD).row();
add(textField).size(250, Gui.BTN_HEIGHT).padBottom(PAD).row();
TextButton okBtn = new TextButton("Confirm", Gui.skin);
Gui.setAction(okBtn, () -> {
inputConsumer.accept(textField.getText());
remove();
});
Table btnTable = getButtonTable();
btnTable.add(okBtn).padRight(5);
btnTable.add(createCloseButton());
add(btnTable);
}

public InputDialog(String title, Consumer<String> inputConsumer) {
this(title, null, inputConsumer);
}

public InputDialog(Consumer<String> inputConsumer) {
this(DEF_TITLE, inputConsumer);
}
}
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/gui/dialogs/LevelupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class LevelupDialog extends PlayerStatDialog {
public LevelupDialog() {
super(Gui.overlay, new StatLabels(), "Level Up!", MadSand.player().stats.baseStats.maxStatSum - 1);
super(Gui.overlay, new StatLabels(), "Level Up!", MadSand.player().stats().baseStats.getMinSum());
super.nameField.setDisabled(true);
super.nameField.setText(MadSand.player().stats.name);
TextButton okButton = new TextButton("Done", Gui.skin);
Expand Down
19 changes: 9 additions & 10 deletions core/src/hitonoriol/madsand/gui/dialogs/PlayerStatDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import me.xdrop.jrand.JRand;

public class PlayerStatDialog extends GameDialog {
static int DEFAULT_STAT_SUM = 6;
int maxStatSum = MadSand.player().stats.baseStats.maxStatSum;
int minStatSum;
boolean restoreOnChange = false;
private static int DEFAULT_STAT_SUM = 6;
private int maxStatSum = MadSand.player().stats.baseStats.maxStatSum;
private int minStatSum;
protected boolean restoreOnChange = false;
protected StatLabels statLabels;
String titleString;
TextField nameField;
private String titleString;
protected TextField nameField;

public PlayerStatDialog(Stage stage, StatLabels statLabels, String title, int minStatSum) {
super(stage);
Expand Down Expand Up @@ -62,10 +62,9 @@ private void init() {
super.add(statLabels.freeStatPointsLbl).width(width).row();
}

float BUTTON_WIDTH = 15;
float ENTRY_HEIGHT = 15;
float BUTTON_PADDING = 4;
float LABEL_WIDTH = Gui.defLblWidth - ((BUTTON_WIDTH + BUTTON_PADDING) * 2);
private float BUTTON_WIDTH = 15, BUTTON_PADDING = 4;
private float ENTRY_HEIGHT = 15;
private float LABEL_WIDTH = Gui.defLblWidth - ((BUTTON_WIDTH + BUTTON_PADDING) * 2);

private void addStatEntry(StatLabels.StatLabel label) {
Stat stat = label.stat;
Expand Down
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/gui/dialogs/QuestJournal.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public QuestJournal(QuestWorker quests) {
questScroll.setScrollingDisabled(true, false);

super.add(questScroll).minSize(TABLE_WIDTH, TABLE_HEIGHT).padTop(SCROLL_YPADDING).row();
super.add(closeButton).size(GameDialog.BTN_WIDTH, GameDialog.BTN_HEIGHT).padBottom(CLOSE_BUTTON_YPADDING).row();
super.add(closeButton).size(Gui.BTN_WIDTH, GameDialog.BTN_HEIGHT).padBottom(CLOSE_BUTTON_YPADDING).row();
Gui.setAction(closeButton, () -> remove());
}

Expand Down
72 changes: 72 additions & 0 deletions core/src/hitonoriol/madsand/gui/dialogs/WaypointDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package hitonoriol.madsand.gui.dialogs;

import static hitonoriol.madsand.Gui.*;
import java.util.List;
import java.util.stream.Collectors;

import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Align;

import hitonoriol.madsand.Gui;
import hitonoriol.madsand.MadSand;
import hitonoriol.madsand.dialog.GameDialog;
import hitonoriol.madsand.gui.widgets.AutoFocusScrollPane;
import hitonoriol.madsand.map.object.Waypoint;

public class WaypointDialog extends GameDialog {
private Table container = new Table(Gui.skin);
public WaypointDialog() {
centerTitle();
setTitle("Waypoints in this sector");
makeBordered();
container.align(Align.topLeft);
add(new AutoFocusScrollPane(container)).size(ENTRY_WIDTH * 3.1f, 350).row();
List<Waypoint> waypoints = MadSand.world().getCurLoc()
.getObjects().stream()
.map(object -> object.as(Waypoint.class).orElse(null))
.filter(waypoint -> waypoint != null)
.collect(Collectors.toList());
if (waypoints.isEmpty())
container.add("There are no GPS waypoints in this sector!");
else {
container.add(createWaypointEntry()).padBottom(ENTRY_PAD * 2).row();
waypoints.forEach(waypoint -> container.add(createWaypointEntry(waypoint)).align(Align.left).row());
}
skipLine();
addCloseButton();
}

private final static float ENTRY_WIDTH = 225, ENTRY_PAD = 10;

private Table createWaypointEntry(Waypoint waypoint) {
Table entry = new Table(Gui.skin);
entry.defaults().width(ENTRY_WIDTH).height(FONT_S).padRight(ENTRY_PAD);
/* Create table header */
if (waypoint == null) {
setFontSize(entry.add("Name").getActor(), FONT_M);
setFontSize(entry.add("Position").getActor(), FONT_M);
setFontSize(entry.add("Toggle navigation").getActor(), FONT_M);
return entry;
}
entry.add(waypoint.name);
entry.add(waypoint.getPosition().toString());
TextButton toggleBtn = updateButton(new TextButton("", Gui.skin), waypoint);
entry.add(toggleBtn).size(ENTRY_WIDTH, BTN_HEIGHT);
Gui.setAction(toggleBtn, () -> {
waypoint.toggleArrow();
updateButton(toggleBtn, waypoint);
toFront();
});
return entry;
}

private Table createWaypointEntry() {
return createWaypointEntry(null);
}

private TextButton updateButton(TextButton button, Waypoint waypoint) {
button.setText(waypoint.hasArrow() ? "Deactivate" : "Activate");
return button;
}
}
5 changes: 0 additions & 5 deletions core/src/hitonoriol/madsand/gui/stages/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import hitonoriol.madsand.entities.inventory.item.Item;
import hitonoriol.madsand.entities.quest.QuestWorker;
import hitonoriol.madsand.entities.skill.Skill;
import hitonoriol.madsand.gui.dialogs.LevelupDialog;
import hitonoriol.madsand.gui.widgets.gametooltip.GameTooltip;
import hitonoriol.madsand.gui.widgets.overlay.ActionButton;
import hitonoriol.madsand.gui.widgets.overlay.EquipmentSidebar;
Expand Down Expand Up @@ -172,10 +171,6 @@ public void pollGameConsole() {
}
}

public void levelUpDialog() {
new LevelupDialog().show();
}

public TextField getConsoleField() {
return gameLog.inputField;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import hitonoriol.madsand.gui.dialogs.CharacterInfoWindow;
import hitonoriol.madsand.gui.dialogs.LandDialog;
import hitonoriol.madsand.gui.dialogs.QuestJournal;
import hitonoriol.madsand.gui.dialogs.WaypointDialog;
import hitonoriol.madsand.gui.stages.Overlay;
import hitonoriol.madsand.input.Keyboard;

Expand All @@ -45,6 +46,7 @@ public OverlayBottomMenu(Overlay overlay) {
addButton("Build", Keys.B, () -> new BuildDialog());
addButton("Bestiary", Keys.X, () -> new BestiaryDialog(MadSand.player()));
addButton("Land", Keys.L, () -> new LandDialog(MadSand.world().getLocation()));
addButton("Waypoints", Keys.O, () -> new WaypointDialog());

container.setBackground(new NinePatchDrawable(Gui.darkBackgroundSizeable));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class QuestArrow extends WaypointArrow {
private Quest quest;

public QuestArrow(Quest quest) {
setColor(Color.BLACK);
getArrow().setColor(Color.BLACK);
this.quest = quest;
setDestinationName(quest.name);
update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ public WaypointArrow setDestination(Pair coords) {
}

public WaypointArrow randomizeColor() {
setColor(Utils.randomColor(Utils.dataGen));
arrow.setColor(Utils.randomColor(Utils.dataGen));
return this;
}

protected Image getArrow() {
return arrow;
}

public void update() {
update(player().x, player().y);
Expand Down
Loading

0 comments on commit b9d1564

Please sign in to comment.