Skip to content

Commit

Permalink
Fix occasional crash on first in-game tooltip update
Browse files Browse the repository at this point in the history
* Update StatProgressBar immediately after setting SkillValue
* Waypoint dialog layout adjustments
* Ignore unequip hotkey (F) when holding a cursed item
* Add padding to GameDialog button text
  • Loading branch information
Hitonoriol committed Aug 4, 2021
1 parent b9d1564 commit 25eed84
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 24 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.16a'
version = 'v0.49.16.1a'

ext {
appName = "MadSand"
Expand Down
19 changes: 7 additions & 12 deletions core/src/hitonoriol/madsand/dialog/GameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@

public class GameDialog extends Dialog {
public static final float BTN_HEIGHT = 35;

private static final float TITLE_YPADDING = 18;
private static final float TITLE_XPADDING = 3;
private static final float TEXT_YPADDING = 15;

public static final float WIDTH = 500;
public static final float HEIGHT = 250;
public static final float PADDING = 10;
private static final float TITLE_YPAD = 18, TITLE_XPAD = 3;
private static final float TEXT_YPAD = 15, BTN_TEXT_XPAD = 30;
public static final float WIDTH = 500, HEIGHT = 250, PADDING = 10;

private AutoFocusScrollPane textScroll;
private Table dialogContainer = new Table(Gui.skin);
Expand All @@ -44,7 +39,7 @@ public GameDialog(String title, String text, Stage stage) {
Table titleTbl = super.getTitleTable();
Label titleLbl = super.getTitleLabel();
titleTbl.getCell(titleLbl);
titleTbl.padTop(TITLE_YPADDING).padLeft(TITLE_XPADDING);
titleTbl.padTop(TITLE_YPAD).padLeft(TITLE_XPAD);
getButtonTable().defaults().size(Gui.BTN_WIDTH, Gui.BTN_HEIGHT);
row();
textLbl = new Label("", Gui.skin);
Expand All @@ -55,7 +50,7 @@ public GameDialog(String title, String text, Stage stage) {
dialogContainer.align(Align.topLeft);
add(textScroll = new AutoFocusScrollPane(dialogContainer)).size(WIDTH, HEIGHT)
.pad(PADDING)
.padTop(TEXT_YPADDING).row();
.padTop(TEXT_YPAD).row();
this.stage = stage;
}

Expand Down Expand Up @@ -176,14 +171,14 @@ public Cell<TextButton> addButton(TextButton button, boolean breakRow) {
proceedButton = button;

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

public Cell<TextButton> addButton(TextButton button) {
return addButton(button, true);
}
Expand Down
5 changes: 4 additions & 1 deletion core/src/hitonoriol/madsand/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,12 @@ public void useItem(Tool item) {

public void freeHands(EquipSlot slot, boolean silent) {
Item item = stats.equipment.getItem(slot);
if (!stats.equipment.unEquip(item))
return;

if (!silent && item.id != Item.NULL_ITEM)
MadSand.print("You put " + item.name + " back to your inventory");
stats.equipment.unEquip(slot);

inventory.getUI().refreshItem(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ private Table createSkillTable() {
.setSkill(player.stats.skills.get(skill))
.setProgressSize(BAR_WIDTH, BAR_HEIGHT))
.size(BAR_WIDTH, BAR_HEIGHT)
.padBottom(LINE_PAD)
.getActor().update();
.padBottom(LINE_PAD);
skillTable.row();
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/hitonoriol/madsand/gui/dialogs/WaypointDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

public class WaypointDialog extends GameDialog {
private Table container = new Table(Gui.skin);

public WaypointDialog() {
centerTitle();
setTitle("Waypoints in this sector");
setTitle("Waypoints in Sector (" + MadSand.world().getCurWPos() + ")");
makeBordered();
container.align(Align.topLeft);
add(new AutoFocusScrollPane(container)).size(ENTRY_WIDTH * 3.1f, 350).row();
Expand All @@ -27,8 +28,10 @@ public WaypointDialog() {
.map(object -> object.as(Waypoint.class).orElse(null))
.filter(waypoint -> waypoint != null)
.collect(Collectors.toList());
if (waypoints.isEmpty())
if (waypoints.isEmpty()) {
container.align(Align.center);
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());
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 = new MapCell();
private final MapCell cell = Map.nullMap.getMapCell(new MapCell());
private Node node;

public static String lineDelimiter = "**********";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public StatProgressBar setSkill(SkillValue skill) {
setValueUpdater(() -> (float) skill.exp);
setMaxValueUpdater(() -> (float) skill.requiredExp);
setProgressUpdater(() -> skill.getProgress());
update();
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/hitonoriol/madsand/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import hitonoriol.madsand.world.worldgen.WorldGenPreset;

public class Map {
public static final Map nullMap = new Map(0, 0);
private int xsz, ysz;

public static int MIN_MAPSIZE = 100;
Expand Down Expand Up @@ -161,6 +162,7 @@ HashMap<Pair, MapObject> getObjectMap() {
return mapObjects;
}

@JsonIgnore
public Collection<MapObject> getObjects() {
return mapObjects.values();
}
Expand Down
10 changes: 7 additions & 3 deletions core/src/hitonoriol/madsand/map/MapCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public MapCell setCoords(int x, int y) {
coords.set(x, y);
return this;
}

public boolean coordsValid() {
return validCoords;
}
Expand All @@ -100,8 +100,12 @@ MapCell get(Map map) {
return this;
}

/* Populates MapCell with cell contents @(x, y) from currently loaded map */
/* Populates MapCell with cell contents from currently loaded map */
public static MapCell get(MapCell cell) {
return MadSand.world().getCurLoc().getMapCell(cell);
}

public static MapCell get(MapCell cell, int x, int y) {
return MadSand.world().getCurLoc().getMapCell(cell.setCoords(x, y));
return get(cell.setCoords(x, y));
}
}
3 changes: 1 addition & 2 deletions core/src/hitonoriol/madsand/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

@JsonAutoDetect(fieldVisibility = Visibility.ANY)
public class World {
private static Map nullLoc = new Map(0, 0);
public static int DEFAULT_MAPSIZE = Map.MIN_MAPSIZE;
private static final float MAX_SIM_DISTANCE_COEF = 2.5f;
private static final float ACT_DELAY_STEP = 0.00125f;
Expand Down Expand Up @@ -182,7 +181,7 @@ Map getLoc(Pair wc, int layer) {
if (locExists(wc, layer)) {
return worldMap.getLocation(wc).getLayer(layer);
} else
return nullLoc;
return Map.nullMap;
}

Map getLoc(int x, int y, int layer) {
Expand Down

0 comments on commit 25eed84

Please sign in to comment.