Skip to content

Commit

Permalink
Merge pull request #6042 from kevlahnota/master2
Browse files Browse the repository at this point in the history
fix autosell refresh, update SaveLoadScene
  • Loading branch information
kevlahnota authored Sep 3, 2024
2 parents 1a1833c + df04f1b commit a634ffe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
54 changes: 26 additions & 28 deletions forge-gui-mobile/src/forge/adventure/scene/SaveLoadScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static SaveLoadScene instance() {
}

public class SaveSlot extends Selectable<TextraButton> {
private int slotNumber;
private final int slotNumber;

public SaveSlot(int slotNumber) {
super(Controls.newTextButton("..."));
Expand Down Expand Up @@ -163,27 +163,19 @@ private boolean updateSlot(int slot) {
if (slot > 0)
lastSelectedSlot = slot;
if (previews.containsKey(slot)) {
WorldSaveHeader header = previews.get(slot);
if (header.preview != null) {
previewImage.setDrawable(new TextureRegionDrawable(new Texture(header.preview)));
WorldSaveHeader worldSaveHeader = previews.get(slot);
if (worldSaveHeader.preview != null) {
previewImage.setDrawable(new TextureRegionDrawable(new Texture(worldSaveHeader.preview)));
previewImage.setScaling(Scaling.fit);
previewImage.layout();
previewImage.setVisible(true);
previewDate.setVisible(true);
if (header.saveDate != null)
previewDate.setText("[%98]" + DateFormat.getDateInstance().format(header.saveDate) + " " + DateFormat.getTimeInstance(DateFormat.SHORT).format(header.saveDate));
if (worldSaveHeader.saveDate != null)
previewDate.setText("[%98]" + DateFormat.getDateInstance().format(worldSaveHeader.saveDate) + " " + DateFormat.getTimeInstance(DateFormat.SHORT).format(worldSaveHeader.saveDate));
else
previewDate.setText("");
if (header.name.contains(Character.toString(ASCII_179))) {
String[] split = TextUtil.split(header.name, ASCII_179);
try {
playerLocation.setText(split[1]);
} catch (Exception e) {
playerLocation.setText("");
}
} else {
playerLocation.setText("");
}
//getLocation
playerLocation.setText(getSplitHeaderName(worldSaveHeader, true));
}
} else {
if (previewImage != null)
Expand All @@ -206,7 +198,7 @@ public void loadSave() {
//Access to screen should be disabled, but stop the process just in case.
//Saving needs to be disabled inside maps until we can capture and load exact map state
//Otherwise location based events for quests can be skipped by saving and then loading outside the map
Dialog noSave = createGenericDialog("", Forge.getLocalizer().getMessage("lblGameNotSaved"), Forge.getLocalizer().getMessage("lblOK"),null, null, null);
Dialog noSave = createGenericDialog("", Forge.getLocalizer().getMessage("lblGameNotSaved"), Forge.getLocalizer().getMessage("lblOK"), null, null, null);
showDialog(noSave);
return;
}
Expand Down Expand Up @@ -311,26 +303,32 @@ private void updateFiles() {
try (FileInputStream fos = new FileInputStream(name.getAbsolutePath());
InflaterInputStream inf = new InflaterInputStream(fos);
ObjectInputStream oos = new ObjectInputStream(inf)) {


int slot = WorldSave.filenameToSlot(name.getName());
WorldSaveHeader header = (WorldSaveHeader) oos.readObject();
if (header.name.contains(Character.toString(ASCII_179))) {
String[] split = TextUtil.split(header.name, ASCII_179);
buttons.get(slot).actor.setText(split[0]);
//playerLocation.setText(split[1]);
} else {
buttons.get(slot).actor.setText(header.name);
}
previews.put(slot, header);
WorldSaveHeader worldSaveHeader = (WorldSaveHeader) oos.readObject();
//get header name
buttons.get(slot).actor.setText(getSplitHeaderName(worldSaveHeader, false));
previews.put(slot, worldSaveHeader);
}
} catch (ClassNotFoundException | IOException | GdxRuntimeException e) {
//e.printStackTrace();
}
}
}

}

private String getSplitHeaderName(WorldSaveHeader worldSaveHeader, boolean getLocation) {
String noMapData = "[RED]No Map Data!";
if (worldSaveHeader.name.contains(Character.toString(ASCII_179))) {
String[] split = TextUtil.split(worldSaveHeader.name, ASCII_179);
if (getLocation)
return split.length > 1 ? split[1] : noMapData;
else
return split[0];
}
return getLocation ? noMapData : worldSaveHeader.name;
}

public enum Modes {
Save,
Load,
Expand Down
2 changes: 2 additions & 0 deletions forge-gui-mobile/src/forge/adventure/scene/ShopScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public void doAutosell() {
}
}
AdventurePlayer.current().doAutosell();
if (screen != null)
screen.refresh();
}

private boolean confirmAutosell(int profit, int cards, float townPriceModifier) {
Expand Down
7 changes: 5 additions & 2 deletions forge-gui-mobile/src/forge/adventure/stage/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.Align;
import forge.Forge;
import forge.adventure.util.Controls;

public class Console extends Window {
Expand All @@ -17,8 +18,10 @@ public void toggle() {
setVisible(false);
getStage().unfocus(input);
} else {
setVisible(true);
getStage().setKeyboardFocus(input);
if (!Forge.advFreezePlayerControls) {
setVisible(true);
getStage().setKeyboardFocus(input);
}
}
}

Expand Down
19 changes: 18 additions & 1 deletion forge-gui-mobile/src/forge/adventure/stage/GameStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.Input;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
Expand All @@ -24,6 +25,7 @@
import com.github.tommyettinger.textra.TypingAdapter;
import com.github.tommyettinger.textra.TypingLabel;
import forge.Forge;
import forge.Graphics;
import forge.adventure.character.CharacterSprite;
import forge.adventure.character.MapActor;
import forge.adventure.character.PlayerSprite;
Expand All @@ -34,6 +36,7 @@
import forge.adventure.scene.Scene;
import forge.adventure.scene.StartScene;
import forge.adventure.scene.TileMapScene;
import forge.adventure.util.Config;
import forge.adventure.util.Controls;
import forge.adventure.util.Current;
import forge.adventure.util.KeyBinding;
Expand Down Expand Up @@ -658,7 +661,7 @@ public void resetPlayerLocation()
Timer.schedule(new Timer.Task() {
@Override
public void run() {
showImageDialog(Current.generateDefeatMessage(), null,
showImageDialog(Current.generateDefeatMessage(), getDefeatBadge(),
() -> FThreads.invokeInEdtNowOrLater(() -> Forge.setTransitionScreen(new TransitionScreen(() -> {
Forge.advFreezePlayerControls = false;
WorldStage.getInstance().setPosition(new Vector2(poi.getPosition().x - 16f, poi.getPosition().y + 16f));
Expand All @@ -670,5 +673,19 @@ public void run() {
}, 1f);
}//Spawn shouldn't be null
}
private FBufferedImage getDefeatBadge() {
FileHandle defeat = Config.instance().getFile("ui/defeat.png");
if (defeat.exists()) {
TextureRegion tr = new TextureRegion(Forge.getAssets().getTexture(defeat, true, false));
tr.flip(true, false);
return new FBufferedImage(88, 100) {
@Override
protected void draw(Graphics g, float w, float h) {
g.drawImage(tr, 0, 0, 88, 100);
}
};
}
return null;
}

}
Binary file added forge-gui/res/adventure/common/ui/defeat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a634ffe

Please sign in to comment.