Skip to content

Commit

Permalink
Rename GPS waypoints via Right click -> Rename
Browse files Browse the repository at this point in the history
* MapEntity.populateContextMenu() -- to add additional contextual options to the right click menu for MapEntity subtypes
* CharacterCreationDialog & LevelupDialog now ignore keyboard input (& can't be closed with ESC, breaking the game in some cases)
* Scroll of Teleportation no longer crashes the game
* World size is now actually limited by WorldMap's xsz & ysz
* Input dialog can now also be confirmed with Enter key
* WorldMapSaver cleanup
  • Loading branch information
Hitonoriol committed Aug 5, 2021
1 parent 25eed84 commit 1c1048d
Show file tree
Hide file tree
Showing 28 changed files with 320 additions and 200 deletions.
2 changes: 1 addition & 1 deletion core/assets/globals.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end
",
"Teleportation" : "
world.player:teleport(world:getCurLoc():getRandomPoint());
player:teleport(world:getCurLoc():getRandomPoint());
"
},

Expand Down
6 changes: 3 additions & 3 deletions core/src/hitonoriol/madsand/GameSaver.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hitonoriol.madsand;

import static hitonoriol.madsand.resources.Resources.*;
import static hitonoriol.madsand.resources.Resources.ERR_FILE;
import static hitonoriol.madsand.resources.Resources.LINEBREAK;
import static hitonoriol.madsand.resources.Resources.mapper;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -123,7 +123,7 @@ private static boolean saveWorld() {

player.stats.equipment.setStatBonus(false);
/*Resources.mapper.writeValue(new File(fl), player);*/
mapper.writeValue(worldFile, MadSand.world());
getMapper().writeValue(worldFile, MadSand.world());
player.stats.equipment.setStatBonus(true);

return true;
Expand All @@ -138,7 +138,7 @@ private static boolean loadWorld() {
Utils.out("Loading world info...");
String worldFile = getCurSaveDir() + MadSand.WORLDFILE;

World world = mapper.readValue(readFile(worldFile), World.class);
World world = getMapper().readValue(readFile(worldFile), World.class);
world.getPlayer().postLoadInit();
MadSand.instance().setWorld(world);
Utils.dbg("World: %X", world.hashCode());
Expand Down
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/MadSand.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void createWorld() {

public static void switchScreen(Screen screen) {
if (Gui.gameUnfocused)
Gui.overlay.gameContextMenu.setVisible(false);
Gui.overlay.getContextMenu().close();
game.setScreen(screen);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static LootTable parse(String lootTblString) {

if (!lootTblString.contains("|")) {
try {
return Resources.mapper.readValue(lootTblString, LootTable.class);
return Resources.getMapper().readValue(lootTblString, LootTable.class);
} catch (Exception e) {
e.printStackTrace();
return null;
Expand Down
15 changes: 14 additions & 1 deletion core/src/hitonoriol/madsand/dialog/GameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
Expand Down Expand Up @@ -125,7 +127,7 @@ public boolean remove() {
public Dialog show(Stage stage) {
Dialog ret = super.show(stage);
Gui.overlay.hideTooltip();
Gui.overlay.gameContextMenu.setVisible(false);
Gui.overlay.getContextMenu().close();
TimeUtils.scheduleTask(() -> Gui.gameUnfocus(), Gui.DELAY);
return ret;
}
Expand Down Expand Up @@ -258,6 +260,10 @@ protected final void makeBordered() {
bordered = true;
}

protected void ignoreKeyboard() {
addListener(inputCanceller);
}

public static GameDialog generateDialogChain(String text, Stage stage) {
return new DialogChainGenerator(text).generate(stage);
}
Expand All @@ -277,4 +283,11 @@ public boolean equals(Object obj) {
return getClass().getSimpleName().equals(obj.getClass().getSimpleName());
}

private final static InputListener inputCanceller = new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
event.cancel();
return true;
}
};
}
12 changes: 8 additions & 4 deletions core/src/hitonoriol/madsand/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public void interact(FarmAnimal animal) {

public void interact(AbstractNpc npc) {
npc.interact(this);
Gui.overlay.closeGameContextMenu();
Gui.overlay.getContextMenu().close();
Gui.overlay.hideActionBtn();
}

Expand Down Expand Up @@ -1119,7 +1119,8 @@ public void turn(Direction dir) {
}

public boolean canTravel() {
Map map = MadSand.world().getCurLoc();
World world = MadSand.world();
Map map = world.getCurLoc();
Direction direction = stats.look;
boolean canTravel;

Expand All @@ -1128,7 +1129,10 @@ public boolean canTravel() {
canTravel |= (x < 1 && direction == Direction.LEFT);
canTravel |= (y < 1 && direction == Direction.DOWN);

return canTravel && MadSand.world().curLayer() == Location.LAYER_OVERWORLD;
Pair newWorldPos = world.getCurWPos().copy().addDirection(direction);
canTravel &= world.getWorldMap().validCoords(newWorldPos);

return canTravel && world.curLayer() == Location.LAYER_OVERWORLD;
}

@Override
Expand Down Expand Up @@ -1328,7 +1332,7 @@ protected void pollMovementQueue() {

@Override
public void move(Path path) {
Keyboard.stopInput();
Keyboard.ignoreInput();
super.move(path);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/entities/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void calcStats() {
restore();

calcActionCosts();
check();
hp = Math.min(hp, mhp);
}

public void restore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void launchProjectile(Pair from, Pair to, Consumer<MapEntity> impactActio
to.toWorld();
Map map = MadSand.world().getCurLoc();
Utils.dbg("Projectile " + name + " will land on " + to.toString());
Keyboard.stopInput();
Keyboard.ignoreInput();

projectileImg.addAction(
Actions.sequence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import hitonoriol.madsand.gui.widgets.stats.StatLabels;
import hitonoriol.madsand.lua.Lua;

public class CharacterCreationDialog {
StatLabels statLabels;
public class CharacterCreationDialog extends PlayerStatDialog {
Stats stats;
PlayerStatDialog dialog;
static String titleString = "Character Creation";

public CharacterCreationDialog() {
statLabels = new StatLabels();
super(Gui.overlay, new StatLabels(), titleString);
stats = statLabels.getStats();
createCharDialog();
}
Expand All @@ -30,33 +28,27 @@ void rollStats() {
void createCharDialog() {
float width = Gui.defLblWidth;
rollStats();
dialog = new PlayerStatDialog(Gui.overlay, statLabels, titleString);
dialog.restoreOnChange = true;
restoreOnChange = true;

TextButton statRollBtn = new TextButton("Reroll", Gui.skin);
TextButton createCharBtn = new TextButton("Create", Gui.skin);
dialog.add(statRollBtn).width(width).row();
dialog.row();
dialog.add(createCharBtn).width(width).row();
add(statRollBtn).width(width).row();
add(createCharBtn).width(width).row();

Gui.setAction(createCharBtn, () -> {
if (dialog.hasUnassignedPoints())
if (hasUnassignedPoints())
return;

if (!dialog.nameField.getText().trim().equals("")) {
MadSand.player().setName(dialog.nameField.getText());
String name = nameField.getText().trim();
if (!name.equals("")) {
MadSand.player().setName(name);
MadSand.player().reinit();
dialog.remove();
Gui.gameUnfocused = false;
remove();
Gui.refreshOverlay();
GameTextSubstitutor.add(GameTextSubstitutor.PLAYER_NAME, dialog.nameField.getText());
GameTextSubstitutor.add(GameTextSubstitutor.PLAYER_NAME, name);
Lua.executeScript(Lua.onCreationScript);
}
});
Gui.setAction(statRollBtn, () -> rollStats());
}

public void show() {
dialog.show(Gui.overlay);
}
}
24 changes: 23 additions & 1 deletion core/src/hitonoriol/madsand/gui/dialogs/InputDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.function.Consumer;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
Expand All @@ -20,16 +23,30 @@ public InputDialog(String title, String prompt, Consumer<String> inputConsumer)
setTitle(title);
if (prompt != null)
add(prompt).height(Gui.FONT_S).padBottom(PAD).row();
else
skipLine();
add(textField).size(250, Gui.BTN_HEIGHT).padBottom(PAD).row();
TextButton okBtn = new TextButton("Confirm", Gui.skin);
Gui.setAction(okBtn, () -> {
inputConsumer.accept(textField.getText());
String text = textField.getText().trim();
if (text.length() == 0)
return;
inputConsumer.accept(text);
remove();
});
Table btnTable = getButtonTable();
btnTable.add(okBtn).padRight(5);
btnTable.add(createCloseButton());
add(btnTable);

addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ENTER)
okBtn.toggle();
return super.keyDown(event, keycode);
}
});
}

public InputDialog(String title, Consumer<String> inputConsumer) {
Expand All @@ -39,4 +56,9 @@ public InputDialog(String title, Consumer<String> inputConsumer) {
public InputDialog(Consumer<String> inputConsumer) {
this(DEF_TITLE, inputConsumer);
}

public InputDialog setInitialText(String text) {
textField.setText(text);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class PlayerStatDialog extends GameDialog {

public PlayerStatDialog(Stage stage, StatLabels statLabels, String title, int minStatSum) {
super(stage);
ignoreKeyboard();
this.statLabels = statLabels;
this.minStatSum = minStatSum;
titleString = title;
Expand Down
8 changes: 4 additions & 4 deletions core/src/hitonoriol/madsand/gui/stages/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Overlay extends Stage {

private Table topTable = new Table();
public GameTooltip gameTooltip;
public GameContextMenu gameContextMenu;
private GameContextMenu gameContextMenu;
public ActionButton actionButton;
public GameLog gameLog;
public OverlayBottomMenu bottomMenu;
Expand Down Expand Up @@ -186,9 +186,9 @@ public Label[] getLogLabels() {
public void refreshActionButton() {
actionButton.refresh();
}

public void closeGameContextMenu() {
gameContextMenu.closeGameContextMenu();
public GameContextMenu getContextMenu() {
return gameContextMenu;
}

public void hideActionBtn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CellInfoGenerator extends TooltipTextGenerator {

private Player player;
private Map map;
private final MapCell cell = Map.nullMap.getMapCell(new MapCell());
private final MapCell cell = new MapCell();
private Node node;

public static String lineDelimiter = "**********";
Expand Down
Loading

0 comments on commit 1c1048d

Please sign in to comment.