update new game, save load and settings

This commit is contained in:
Anthony Calosa
2022-02-23 16:09:55 +08:00
parent dc4eed4b08
commit aa0fca7b68
6 changed files with 145 additions and 46 deletions

View File

@@ -41,7 +41,7 @@ public class NewGameScene extends UIScene {
} }
public boolean start() { public boolean start() {
if(selectedName.getText().isEmpty()) { if (selectedName.getText().isEmpty()) {
selectedName.setText(NameGenerator.getRandomName("Any", "Any", "")); selectedName.setText(NameGenerator.getRandomName("Any", "Any", ""));
} }
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@@ -53,7 +53,7 @@ public class NewGameScene extends UIScene {
race.getCurrentIndex(), race.getCurrentIndex(),
avatarIndex, avatarIndex,
deck.getCurrentIndex(), deck.getCurrentIndex(),
Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()],0); Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()], 0);
GamePlayerUtil.getGuiPlayer().setName(selectedName.getText()); GamePlayerUtil.getGuiPlayer().setName(selectedName.getText());
Forge.clearTransitionScreen(); Forge.clearTransitionScreen();
Forge.switchScene(SceneType.GameScene.instance); Forge.switchScene(SceneType.GameScene.instance);
@@ -82,7 +82,7 @@ public class NewGameScene extends UIScene {
return NewGameScene.this.updateAvatar(); return NewGameScene.this.updateAvatar();
} }
}); });
Random rand=new Random(); Random rand = new Random();
deck = ui.findActor("deck"); deck = ui.findActor("deck");
@@ -104,18 +104,17 @@ public class NewGameScene extends UIScene {
difficulty = ui.findActor("difficulty"); difficulty = ui.findActor("difficulty");
Array<String> diffList = new Array<>(starterDeck.length); Array<String> diffList = new Array<>(starterDeck.length);
int i=0; int i = 0;
int startingDifficulty=0; int startingDifficulty = 0;
for (DifficultyData diff : Config.instance().getConfigData().difficulties) for (DifficultyData diff : Config.instance().getConfigData().difficulties) {
{ if (diff.startingDifficulty)
if(diff.startingDifficulty) startingDifficulty = i;
startingDifficulty=i;
diffList.add(diff.name); diffList.add(diff.name);
i++; i++;
} }
difficulty.setTextList(diffList); difficulty.setTextList(diffList);
difficulty.setCurrentIndex(startingDifficulty); difficulty.setCurrentIndex(startingDifficulty);
avatarIndex=rand.nextInt(); avatarIndex = rand.nextInt();
gender.setCurrentIndex(rand.nextInt()); gender.setCurrentIndex(rand.nextInt());
deck.setCurrentIndex(rand.nextInt()); deck.setCurrentIndex(rand.nextInt());
race.setCurrentIndex(rand.nextInt()); race.setCurrentIndex(rand.nextInt());

View File

@@ -20,6 +20,7 @@ import forge.Forge;
import forge.adventure.util.Controls; import forge.adventure.util.Controls;
import forge.adventure.world.WorldSave; import forge.adventure.world.WorldSave;
import forge.adventure.world.WorldSaveHeader; import forge.adventure.world.WorldSaveHeader;
import forge.gui.GuiBase;
import forge.screens.TransitionScreen; import forge.screens.TransitionScreen;
import java.io.File; import java.io.File;
@@ -30,7 +31,6 @@ import java.util.zip.InflaterInputStream;
/** /**
* Scene to load and save the game. * Scene to load and save the game.
*
*/ */
public class SaveLoadScene extends UIScene { public class SaveLoadScene extends UIScene {
private final IntMap<TextButton> buttons = new IntMap<>(); private final IntMap<TextButton> buttons = new IntMap<>();
@@ -43,17 +43,16 @@ public class SaveLoadScene extends UIScene {
Label header; Label header;
int currentSlot = -3; int currentSlot = -3;
Image previewImage; Image previewImage;
Image previewBorder;
TextButton saveLoadButton; TextButton saveLoadButton;
TextButton quickSave; TextButton quickSave;
TextButton autoSave; TextButton autoSave;
public SaveLoadScene() { public SaveLoadScene() {
super("ui/save_load.json"); super(GuiBase.isAndroid() ? "ui/save_load_mobile.json" : "ui/save_load.json");
} }
private TextButton addSaveSlot(String name, int i) { private TextButton addSaveSlot(String name, int i) {
layout.add(Controls.newLabel(name)).colspan(1).align(Align.right).expandX(); layout.add(Controls.newLabel(name)).colspan(1).align(Align.right).expandX();
layout.add(Controls.newLabel(" ")); layout.add(Controls.newLabel(" "));
@@ -88,9 +87,16 @@ public class SaveLoadScene extends UIScene {
if (header.preview != null) { if (header.preview != null) {
previewImage.setDrawable(new TextureRegionDrawable(new Texture(header.preview))); previewImage.setDrawable(new TextureRegionDrawable(new Texture(header.preview)));
previewImage.layout(); previewImage.layout();
previewImage.setVisible(true);
previewBorder.setVisible(true);
} }
} else {
if (previewImage != null)
previewImage.setVisible(false);
if (previewBorder != null)
previewBorder.setVisible(false);
} }
for (IntMap.Entry<TextButton> butt : new IntMap.Entries<TextButton> (buttons)) { for (IntMap.Entry<TextButton> butt : new IntMap.Entries<TextButton>(buttons)) {
butt.value.setColor(defColor); butt.value.setColor(defColor);
} }
if (buttons.containsKey(slot)) { if (buttons.containsKey(slot)) {
@@ -123,18 +129,16 @@ public class SaveLoadScene extends UIScene {
} }
@Override @Override
public boolean keyPressed(int keycode) public boolean keyPressed(int keycode) {
{ if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE)
{
back(); back();
} }
return true; return true;
} }
public void save() { public void save() {
dialog.hide(); dialog.hide();
if( WorldSave.getCurrentSave().save(textInput.getText(), currentSlot)) if (WorldSave.getCurrentSave().save(textInput.getText(), currentSlot)) {
{
updateFiles(); updateFiles();
Forge.switchScene(SceneType.GameScene.instance); Forge.switchScene(SceneType.GameScene.instance);
} }
@@ -147,7 +151,7 @@ public class SaveLoadScene extends UIScene {
File f = new File(WorldSave.getSaveDir()); File f = new File(WorldSave.getSaveDir());
f.mkdirs(); f.mkdirs();
File[] names = f.listFiles(); File[] names = f.listFiles();
if(names==null) if (names == null)
throw new RuntimeException("Can not find save directory"); throw new RuntimeException("Can not find save directory");
previews.clear(); previews.clear();
for (File name : names) { for (File name : names) {
@@ -159,7 +163,7 @@ public class SaveLoadScene extends UIScene {
ObjectInputStream oos = new ObjectInputStream(inf)) { ObjectInputStream oos = new ObjectInputStream(inf)) {
int slot=WorldSave.filenameToSlot(name.getName()); int slot = WorldSave.filenameToSlot(name.getName());
WorldSaveHeader header = (WorldSaveHeader) oos.readObject(); WorldSaveHeader header = (WorldSaveHeader) oos.readObject();
buttons.get(slot).setText(header.name); buttons.get(slot).setText(header.name);
previews.put(slot, header); previews.put(slot, header);
@@ -222,12 +226,13 @@ public class SaveLoadScene extends UIScene {
})).align(Align.left); })).align(Align.left);
previewImage = ui.findActor("preview"); previewImage = ui.findActor("preview");
previewBorder = ui.findActor("preview_border");
header = Controls.newLabel("Save"); header = Controls.newLabel("Save");
header.setHeight(header.getHeight() * 2); header.setHeight(header.getHeight() * 2);
layout.add(header).colspan(3).align(Align.center).expand(); layout.add(header).colspan(3).align(Align.center).expand();
layout.row(); layout.row();
autoSave=addSaveSlot("Auto save", WorldSave.AUTO_SAVE_SLOT); autoSave = addSaveSlot("Auto save", WorldSave.AUTO_SAVE_SLOT);
quickSave=addSaveSlot("Quick save", WorldSave.QUICK_SAVE_SLOT); quickSave = addSaveSlot("Quick save", WorldSave.QUICK_SAVE_SLOT);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
addSaveSlot("Slot:" + i, i); addSaveSlot("Slot:" + i, i);

View File

@@ -37,7 +37,7 @@ public class SettingsScene extends UIScene {
private Table settingGroup; private Table settingGroup;
public SettingsScene() { public SettingsScene() {
super("ui/settings.json"); super(GuiBase.isAndroid() ? "ui/settings_mobile.json" : "ui/settings.json");
} }
@@ -63,18 +63,18 @@ public class SettingsScene extends UIScene {
} }
@Override @Override
public boolean keyPressed(int keycode) public boolean keyPressed(int keycode) {
{ if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE)
{
back(); back();
} }
return true; return true;
} }
public boolean back() { public boolean back() {
Forge.switchToLast(); Forge.switchToLast();
return true; return true;
} }
private void addInputField(String name, ForgePreferences.FPref pref) { private void addInputField(String name, ForgePreferences.FPref pref) {
@@ -91,6 +91,7 @@ public class SettingsScene extends UIScene {
addLabel(name); addLabel(name);
settingGroup.add(box).align(Align.right); settingGroup.add(box).align(Align.right);
} }
private void addCheckBox(String name, ForgePreferences.FPref pref) { private void addCheckBox(String name, ForgePreferences.FPref pref) {
@@ -107,9 +108,10 @@ public class SettingsScene extends UIScene {
addLabel(name); addLabel(name);
settingGroup.add(box).align(Align.right); settingGroup.add(box).align(Align.right);
} }
private void addSettingSlider(String name, ForgePreferences.FPref pref, int min,int max) {
Slider slide = Controls.newSlider(min,max, 1, false); private void addSettingSlider(String name, ForgePreferences.FPref pref, int min, int max) {
Slider slide = Controls.newSlider(min, max, 1, false);
slide.setValue(Preference.getPrefInt(pref)); slide.setValue(Preference.getPrefInt(pref));
slide.addListener(new ChangeListener() { slide.addListener(new ChangeListener() {
@Override @Override
@@ -121,6 +123,7 @@ public class SettingsScene extends UIScene {
addLabel(name); addLabel(name);
settingGroup.add(slide).align(Align.right); settingGroup.add(slide).align(Align.right);
} }
private void addSettingField(String name, boolean value, ChangeListener change) { private void addSettingField(String name, boolean value, ChangeListener change) {
CheckBox box = Controls.newCheckBox(""); CheckBox box = Controls.newCheckBox("");
@@ -129,6 +132,7 @@ public class SettingsScene extends UIScene {
addLabel(name); addLabel(name);
settingGroup.add(box).align(Align.right); settingGroup.add(box).align(Align.right);
} }
private void addSettingField(String name, int value, ChangeListener change) { private void addSettingField(String name, int value, ChangeListener change) {
@@ -145,14 +149,15 @@ public class SettingsScene extends UIScene {
addLabel(name); addLabel(name);
settingGroup.add(text).align(Align.right); settingGroup.add(text).align(Align.right);
} }
void addLabel( String name)
{
Label label = new Label(name, Controls.GetSkin().get("white",Label.LabelStyle.class)); void addLabel(String name) {
Label label = new Label(name, Controls.GetSkin().get("white", Label.LabelStyle.class));
settingGroup.row().space(5); settingGroup.row().space(5);
settingGroup.add(label).align(Align.left).fillX(); settingGroup.add(label).align(Align.left).fillX();
} }
@Override @Override
public void resLoaded() { public void resLoaded() {
super.resLoaded(); super.resLoaded();
@@ -165,7 +170,7 @@ public class SettingsScene extends UIScene {
SelectBox plane = Controls.newComboBox(Config.instance().getAllAdventures(), Config.instance().getSettingData().plane, new Function<Object, Void>() { SelectBox plane = Controls.newComboBox(Config.instance().getAllAdventures(), Config.instance().getSettingData().plane, new Function<Object, Void>() {
@Override @Override
public Void apply(Object o) { public Void apply(Object o) {
Config.instance().getSettingData().plane= (String) o; Config.instance().getSettingData().plane = (String) o;
Config.instance().saveSettings(); Config.instance().saveSettings();
return null; return null;
} }
@@ -177,7 +182,7 @@ public class SettingsScene extends UIScene {
SelectBox videomode = Controls.newComboBox(new String[]{"720p", "768p", "900p", "1080p"}, Config.instance().getSettingData().videomode, new Function<Object, Void>() { SelectBox videomode = Controls.newComboBox(new String[]{"720p", "768p", "900p", "1080p"}, Config.instance().getSettingData().videomode, new Function<Object, Void>() {
@Override @Override
public Void apply(Object o) { public Void apply(Object o) {
String mode = (String)o; String mode = (String) o;
if (mode == null) if (mode == null)
mode = "720p"; mode = "720p";
Config.instance().getSettingData().videomode = mode; Config.instance().getSettingData().videomode = mode;
@@ -209,7 +214,7 @@ public class SettingsScene extends UIScene {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
boolean value = ((CheckBox) actor).isChecked(); boolean value = ((CheckBox) actor).isChecked();
Config.instance().getSettingData().fullScreen=value; Config.instance().getSettingData().fullScreen = value;
Config.instance().saveSettings(); Config.instance().saveSettings();
//update //update
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_FULLSCREEN_MODE) != value) { if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_FULLSCREEN_MODE) != value) {
@@ -220,8 +225,8 @@ public class SettingsScene extends UIScene {
}); });
} }
addCheckBox(localizer.getMessage("lblCardName"), ForgePreferences.FPref.UI_OVERLAY_CARD_NAME); addCheckBox(localizer.getMessage("lblCardName"), ForgePreferences.FPref.UI_OVERLAY_CARD_NAME);
addSettingSlider(localizer.getMessage("cbAdjustMusicVolume"), ForgePreferences.FPref.UI_VOL_MUSIC,0,100); addSettingSlider(localizer.getMessage("cbAdjustMusicVolume"), ForgePreferences.FPref.UI_VOL_MUSIC, 0, 100);
addSettingSlider(localizer.getMessage("cbAdjustSoundsVolume"), ForgePreferences.FPref.UI_VOL_SOUNDS, 0,100); addSettingSlider(localizer.getMessage("cbAdjustSoundsVolume"), ForgePreferences.FPref.UI_VOL_SOUNDS, 0, 100);
addCheckBox(localizer.getMessage("lblManaCost"), ForgePreferences.FPref.UI_OVERLAY_CARD_MANA_COST); addCheckBox(localizer.getMessage("lblManaCost"), ForgePreferences.FPref.UI_OVERLAY_CARD_MANA_COST);
addCheckBox(localizer.getMessage("lblPowerOrToughness"), ForgePreferences.FPref.UI_OVERLAY_CARD_POWER); addCheckBox(localizer.getMessage("lblPowerOrToughness"), ForgePreferences.FPref.UI_OVERLAY_CARD_POWER);
addCheckBox(localizer.getMessage("lblCardID"), ForgePreferences.FPref.UI_OVERLAY_CARD_ID); addCheckBox(localizer.getMessage("lblCardID"), ForgePreferences.FPref.UI_OVERLAY_CARD_ID);

View File

@@ -145,18 +145,18 @@
"type": "TextButton", "type": "TextButton",
"name": "back", "name": "back",
"text": "Back", "text": "Back",
"width": 44, "width": 48,
"height": 30, "height": 30,
"x": 38, "x": 36,
"y": 212 "y": 212
}, },
{ {
"type": "TextButton", "type": "TextButton",
"name": "start", "name": "start",
"text": "Start", "text": "Start",
"width": 44, "width": 48,
"height": 30, "height": 30,
"x": 400, "x": 398,
"y": 212 "y": 212
} }
] ]

View File

@@ -0,0 +1,60 @@
{
"width": 480,
"height": 270,
"yDown": true,
"elements": [
{
"type": "Image",
"image": "ui/title_bg.png",
"width": 480,
"height": 270
},
{
"type": "Scroll",
"name": "saveSlots",
"x": 25,
"y": 18,
"width": 430,
"height": 235
},
{
"type": "Image",
"name" : "preview_border",
"image": "ui/avatarhud.png",
"width": 96,
"height": 54,
"x": 350,
"y": 26
},
{
"type": "Image",
"name": "preview",
"width": 86,
"height": 48,
"x": 356,
"y": 29
},
{
"type": "TextButton",
"name": "return",
"text": "Back",
"width": 48,
"height": 30,
"x": 36,
"y": 212
},
{
"type": "TextButton",
"name": "save",
"text": "saveLoad",
"width": 48,
"height": 30,
"x": 398,
"y": 212
},
{
"type": "Table",
"font": "default"
}
]
}

View File

@@ -0,0 +1,30 @@
{
"width": 480,
"height": 270,
"yDown": true,
"elements": [
{
"type": "Image",
"image": "ui/title_bg.png",
"width": 480,
"height": 270
},
{
"type": "Scroll",
"name": "settings",
"x": 25,
"y": 18,
"width": 430,
"height": 235
},
{
"type": "ImageButton",
"name": "return",
"style": "leftarrow",
"width": 32,
"height": 32,
"x": 25,
"y": 220
}
]
}