Skip to content

Commit

Permalink
Overlay info panel -- displays auto-updating labels with various info…
Browse files Browse the repository at this point in the history
… + Generalize RefreshableLabels & TextGenerators

* Encumbrance (percentage of occupied inventory space) & its impact on Entity's speed -- 100% encumbrance decreases speed by 35%
* OverlayMouseOverListener now ignores junk InputEvents
* Overlay cleanup
* Explicit gc calls during & after world loading and on screen switch & world.enter()
  • Loading branch information
Hitonoriol committed Aug 7, 2021
1 parent b5f8f16 commit 2a1a6d1
Show file tree
Hide file tree
Showing 38 changed files with 585 additions and 247 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.17a'
version = 'v0.49.17.1a'

ext {
appName = "MadSand"
Expand Down
16 changes: 10 additions & 6 deletions core/src/hitonoriol/madsand/GameSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static void save() {
}

public static boolean load(String filename) {
Utils.dbg("Loading world [%s]...", filename);
Utils.printMemoryInfo();
MadSand.WORLDNAME = filename;
File f = new File(MadSand.MAPDIR + filename);

Expand All @@ -51,7 +53,7 @@ public static boolean load(String filename) {
return false;
}

Gui.overlay.gameLog.clear();
Gui.overlay.getGameLog().clear();
MadSand.world().close();
createDirs();

Expand All @@ -65,6 +67,9 @@ public static boolean load(String filename) {
MadSand.world().updateLight();
loadLog();
MadSand.print("Loaded Game!");
Utils.dbg("Loaded [%s] successfully!", filename);
System.gc();
Utils.printMemoryInfo();
return true;
} else {
loadErrMsg();
Expand Down Expand Up @@ -100,7 +105,7 @@ public static boolean loadLocation(int wx, int wy) {
saver.loadLocationInfo(wx, wy);
saver.bytesToLocation(data, wx, wy);
MadSand.world().setWorldMap(saver.getWorldMap());

System.gc();
return true;
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -141,8 +146,7 @@ private static boolean loadWorld() {
World world = getMapper().readValue(readFile(worldFile), World.class);
world.getPlayer().postLoadInit();
MadSand.instance().setWorld(world);
Utils.dbg("World: %X", world.hashCode());

System.gc();
Utils.out("Done loading world info.");
return true;
} catch (Exception e) {
Expand Down Expand Up @@ -247,7 +251,7 @@ private static boolean saveLog() {
try {
FileWriter fw = new FileWriter(getCurSaveDir() + MadSand.LOGFILE);

for (Label logLabel : Gui.overlay.getLogLabels())
for (Label logLabel : Gui.overlay.getGameLog().getLabels())
fw.write(logLabel.getText().toString() + LINEBREAK);

fw.close();
Expand All @@ -265,7 +269,7 @@ private static boolean loadLog() {
new FileReader(getCurSaveDir() + MadSand.LOGFILE));
String line;
int i = 0;
Label[] labels = Gui.overlay.getLogLabels();
Label[] labels = Gui.overlay.getGameLog().getLabels();

while ((line = br.readLine()) != null)
labels[i++].setText(line);
Expand Down
23 changes: 16 additions & 7 deletions core/src/hitonoriol/madsand/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
Expand Down Expand Up @@ -152,7 +153,6 @@ static private void loadNinePatches() {

static void init() {
initSkin();
overlay = new Overlay();
createTransitionScreens();
}

Expand Down Expand Up @@ -181,12 +181,12 @@ public static OkDialog drawOkDialog(String msg) {
return drawOkDialog(OkDialog.DEFAULT_TITLE, msg);
}

public static void gameUnfocus() {
public static void unfocusGame() {
dialogActive = gameUnfocused = true;
overlay.hideTooltip();
}

public static void gameResumeFocus(GameDialog dialog) {
public static void resumeGameFocus(GameDialog dialog) {
boolean noDialogsLeft = false;
Stage stage = MadSand.getStage();

Expand Down Expand Up @@ -219,8 +219,8 @@ public static boolean hasDialogs(Stage stage) { // If stage has any GameDialog
return hasDialogs(stage, null);
}

public static void gameResumeFocus() {
gameResumeFocus(null);
public static void resumeGameFocus() {
resumeGameFocus(null);
}

public static boolean isGameUnfocused() {
Expand Down Expand Up @@ -329,8 +329,17 @@ public static float getTextHeight(String text, int fontSize) {
return modifyGlyph(text, fontSize).height;
}

public static void skipLine(Table table) {
table.add(new Label("", skin)).row();
public static Cell<Label> skipLine(Table table) {
Cell<Label> cell = table.add(new Label("", skin));
cell.row();
return cell;
}

public static void removeActor(Table table, Actor actor) {
Cell<?> cell = table.getCell(actor);
actor.remove();
table.getCells().removeValue(cell, true);
table.invalidate();
}

public static ProgressBarStyle createProgressBarStyle(float width, float height, Color color, boolean transparent) {
Expand Down
39 changes: 20 additions & 19 deletions core/src/hitonoriol/madsand/MadSand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public class MadSand extends Game {
public static final int TILESIZE = 33;

public static final String SAVE_EXT = ".msf";

public static final String SAVEDIR = "MadSand_Saves/";
public static final String MAPDIR = SAVEDIR + "worlds/";
public static final String PLAYERFILE = "/Player" + SAVE_EXT;
public static final String LOGFILE = "/log" + SAVE_EXT;
public static final String NPCSFILE = "NPCs";
public static final String WORLDFILE = "/World" + SAVE_EXT;
Expand All @@ -44,9 +42,9 @@ public class MadSand extends Game {
private static boolean worldUntouched = true;

private World world;
Storage<AbstractScreen<?>> currentScreen = new Storage<>();
private Storage<AbstractScreen<?>> currentScreen = new Storage<>();
private static MadSand game;
private static WorldRenderer gameWorld;
private static WorldRenderer worldRenderer;

public static GameScreen gameScreen;
public static CraftScreen craftScreen;
Expand All @@ -58,38 +56,39 @@ public class MadSand extends Game {
public void create() {
Utils.out("Starting initialization!");
game = this;
gameWorld = new WorldRenderer();
worldRenderer = new WorldRenderer();
Gdx.graphics.setContinuousRendering(false);

Timer.instance().start();
Resources.loadAll();
Gui.init();
GameTextSubstitutor.init();
initScreens();
Keyboard.initListener();
Mouse.initListener();

GameSaver.createDirs();
initNewGame();
if (!Globals.headless())
game.world.generate();
initScreens();
Keyboard.initDefaultKeyBinds();
switchScreen(mainMenu);
Utils.out("End of initialization!");
Utils.printMemoryInfo();
}

private static void initScreens() {
gameScreen = new GameScreen(gameWorld);
craftScreen = new CraftScreen(gameWorld);
deathScreen = new DeathScreen(gameWorld);
mainMenu = new MainMenu(gameWorld);
switchScreen(mainMenu);
gameScreen = new GameScreen(worldRenderer);
craftScreen = new CraftScreen(worldRenderer);
deathScreen = new DeathScreen(worldRenderer);
mainMenu = new MainMenu(worldRenderer);
}

public static void initNewGame() {
game.createWorld();
MadSand.player().updCoords();
Lua.init();
Gui.overlay.gameLog.clear();
Gui.overlay.getGameLog().clear();
}

private void createWorld() {
Expand All @@ -103,6 +102,7 @@ public static void switchScreen(Screen screen) {
if (Gui.gameUnfocused)
Gui.overlay.getContextMenu().close();
game.setScreen(screen);
System.gc();
}

public static void switchScreen(AbstractScreen<?> screen) {
Expand All @@ -128,7 +128,7 @@ public void resume() {}

@Override
public void resize(int width, int height) {
gameWorld.updateViewport();
worldRenderer.updateViewport();
Gui.overlay.getViewport().update(width, height, true);
Gui.overlay.updateWidgetPositions();
player().setFov();
Expand All @@ -144,15 +144,15 @@ public void dispose() {
}

public static OrthographicCamera getCamera() {
return gameWorld.getCamera();
return worldRenderer.getCamera();
}

public static Stage getStage() {
return game.currentScreen.get().getStage();
}

public static WorldRenderer getRenderer() {
return gameWorld;
return worldRenderer;
}

public World getWorld() {
Expand Down Expand Up @@ -180,7 +180,7 @@ public static void exec(Consumer<World> action) {
}

public static void warn(String msg, boolean duplicateAsDialog) {
Gui.overlay.gameLog.warn(msg);
Gui.overlay.getGameLog().warn(msg);
if (duplicateAsDialog)
Gui.drawOkDialog("Warning", msg);
}
Expand All @@ -190,19 +190,19 @@ public static void warn(String msg) {
}

public static void print(String arg) {
Gui.overlay.gameLog.print(arg);
Gui.overlay.getGameLog().print(arg);
}

public static void print(String arg, Object... args) {
print(String.format(arg, args));
}

public static void print(String msg, String color) {
Gui.overlay.gameLog.print(msg, color);
Gui.overlay.getGameLog().print(msg, color);
}

public static void notice(String msg) {
Gui.overlay.gameLog.notify(msg);
Gui.overlay.getGameLog().notify(msg);
}

public static void notice(String msg, Object... args) {
Expand All @@ -216,6 +216,7 @@ public static void enterWorld() {

Gui.overlay.setPlayer(player());
game.world.enter();
System.gc();
}

public static boolean isWorldUntouched() {
Expand Down
6 changes: 5 additions & 1 deletion core/src/hitonoriol/madsand/containers/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ public Pair toWorld() {
public Pair clear() {
return set(nullPair);
}


public boolean inRectangle(int x, int y, int width, int height) {
return x < this.x && y < this.y && x + width > this.x && y + height > this.y;
}

public boolean isEmpty() {
return equals(nullPair);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/hitonoriol/madsand/dialog/GameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean remove() {
boolean ret = super.remove();
if (!hasNext)
TimeUtils.scheduleTask(() -> {
Gui.gameResumeFocus(this);
Gui.resumeGameFocus(this);
Gui.overlay.refreshActionButton();
}, Gui.DELAY);
return ret;
Expand All @@ -129,7 +129,7 @@ public Dialog show(Stage stage) {
Dialog ret = super.show(stage);
Gui.overlay.hideTooltip();
Gui.overlay.getContextMenu().close();
TimeUtils.scheduleTask(() -> Gui.gameUnfocus(), Gui.DELAY);
TimeUtils.scheduleTask(() -> Gui.unfocusGame(), Gui.DELAY);
return ret;
}

Expand Down
12 changes: 7 additions & 5 deletions core/src/hitonoriol/madsand/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,8 @@ public void playDamageAnimation() {

@JsonIgnore
public float getSpeed() {
float speed = (float) stats.actionPtsMax;
if (speed < 1)
return 1;
return speed;
stats.calcSpeed();
return (float) stats.actionPtsMax;
}

@JsonIgnore
Expand All @@ -734,13 +732,17 @@ else if (percent > 10)
return "at death's door";
}

public String getHealthState() {
return getHealthState(stats.getHealthPercent());
}

public String getName() {
return stats.name;
}

@JsonIgnore
public String getInfoString() {
int hpPercent = (int) (((float) stats.hp / (float) stats.mhp) * 100);
int hpPercent = stats.getHealthPercent();
String ret;
ret = String.format("Health: %s (%d%%)", getHealthState(hpPercent), hpPercent);
return ret;
Expand Down
Loading

0 comments on commit 2a1a6d1

Please sign in to comment.