Added multiple decks in adventure.

Adjusted deck editor to enable usage in adventure mode.
Fixed a crash after a match.
This commit is contained in:
Grimm
2021-11-18 02:27:01 +01:00
parent bcb7bd9a98
commit c47af43006
11 changed files with 354 additions and 70 deletions

View File

@@ -26,8 +26,8 @@ import java.util.Map;
*/
public class DeckEditScene extends ForgeScene {
public class AdventureDeckEditor extends FDeckEditor {
public AdventureDeckEditor(boolean commander) {
super(commander ? EditorType.QuestCommander : EditorType.Quest, "", false, new FEvent.FEventHandler() {
public AdventureDeckEditor( ) {
super( EditorType.Quest, "", false, new FEvent.FEventHandler() {
@Override
public void handleEvent(FEvent e) {
AdventureApplicationAdapter.instance.switchToLast();
@@ -40,24 +40,36 @@ public class DeckEditScene extends ForgeScene {
QuestSpellShop.updateDecksForEachCard();
}
@Override
protected boolean allowDelete() {
return false;
}
@Override
protected boolean allowsSave() {
return false;
}
@Override
protected boolean allowsAddBasic() {
return false;
}
@Override
protected boolean allowRename() {
return false;
}
@Override
protected boolean isLimitedEditor() {
return true;
}
@Override
protected Map<ColumnDef, ItemColumn> getColOverrides(ItemManagerConfig config) {
Map<ColumnDef, ItemColumn> colOverrides = new HashMap<>();
switch (config) {
case QUEST_EDITOR_POOL:
ItemColumn.addColOverride(config, colOverrides, ColumnDef.NEW, FModel.getQuest().getCards().getFnNewCompare(), FModel.getQuest().getCards().getFnNewGet());
break;
case QUEST_DECK_EDITOR:
ItemColumn.addColOverride(config, colOverrides, ColumnDef.NEW, FModel.getQuest().getCards().getFnNewCompare(), FModel.getQuest().getCards().getFnNewGet());
ItemColumn.addColOverride(config, colOverrides, ColumnDef.DECKS, QuestSpellShop.fnDeckCompare, QuestSpellShop.fnDeckGet);
break;
default:
colOverrides = null; //shouldn't happen
break;
}
return colOverrides;
}
public void refresh() {
for(TabPage page:tabPages)
{
@@ -96,7 +108,7 @@ public class DeckEditScene extends ForgeScene {
FModel.getQuest().getCards().addSingleCard(card.getKey(), card.getValue());
Deck deck = AdventurePlayer.current().getDeck();
Deck deck = AdventurePlayer.current().getSelectedDeck();
getScreen();
screen.getEditorType().getController().setDeck(deck);
screen.refresh();
@@ -112,7 +124,7 @@ public class DeckEditScene extends ForgeScene {
@Override
public FScreen getScreen() {
return screen==null?screen = new AdventureDeckEditor(false):screen;
return screen==null?screen = new AdventureDeckEditor():screen;
}
}

View File

@@ -0,0 +1,144 @@
package forge.adventure.scene;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.IntMap;
import forge.adventure.AdventureApplicationAdapter;
import forge.adventure.util.Controls;
import forge.adventure.util.Current;
import forge.adventure.world.AdventurePlayer;
public class DeckSelectScene extends UIScene {
private final IntMap<TextButton> buttons = new IntMap<>();
Color defColor;
Dialog dialog;
TextField textInput;
Table layout;
Label header;
int currentSlot = 0;
public DeckSelectScene() {
super("ui/deck_selector.json");
}
private TextButton addDeckSlot(String name, int i) {
TextButton button = Controls.newTextButton("-");
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
try {
if(!button.isDisabled())
select(i);
} catch (Exception e) {
e.printStackTrace();
}
}
});
layout.add(Controls.newLabel(name)).expandX();
layout.add(button).expandX();
buttons.put(i, button);
layout.row();
return button;
}
public void back() {
AdventureApplicationAdapter.instance.switchToLast();
}
public boolean select(int slot) {
currentSlot = slot;
for (IntMap.Entry<TextButton> butt : new IntMap.Entries<TextButton> (buttons)) {
butt.value.setColor(defColor);
}
if (buttons.containsKey(slot)) {
TextButton button = buttons.get(slot);
button.setColor(Color.RED);
}
Current.player().setSelectedDeckSlot(slot);
return true;
}
@Override
public boolean keyPressed(int keycode)
{
if (keycode == Input.Keys.ESCAPE)
{
back();
}
return true;
}
@Override
public void enter() {
select(Current.player().getSelectedDeckIndex());
for(int i=0;i<AdventurePlayer.NUMBER_OF_DECKS;i++)
{
if(buttons.containsKey(i))
{
buttons.get(i).setText(Current.player().getDeck(i).getName());
}
}
super.enter();
}
@Override
public void resLoaded() {
super.resLoaded();
layout = new Table();
layout.setFillParent(true);
stage.addActor(layout);
header = Controls.newLabel("Select your Deck");
header.setHeight(header.getHeight() * 2);
layout.add(header).colspan(2).align(Align.center);
layout.row();
for (int i = 0; i < AdventurePlayer.NUMBER_OF_DECKS; i++)
addDeckSlot("Deck:" + (i+1), i);
dialog = Controls.newDialog("Save");
textInput = Controls.newTextField("");
dialog.getButtonTable().add(Controls.newLabel("Name your new save file.")).colspan(2);
dialog.getButtonTable().row();
dialog.getButtonTable().add(Controls.newLabel("Name:")).align(Align.left);
dialog.getButtonTable().add(textInput).fillX().expandX();
dialog.getButtonTable().row();
dialog.getButtonTable().add(Controls.newTextButton("Rename", () -> rename())).align(Align.left);
dialog.getButtonTable().add(Controls.newTextButton("Abort", () -> dialog.hide())).align(Align.left);
ui.onButtonPress("return",()-> back());
ui.onButtonPress("edit",()-> edit());
ui.onButtonPress("rename",()-> {
textInput.setText(Current.player().getSelectedDeck().getName());
dialog.show(stage);
stage.setKeyboardFocus(textInput);
});
defColor = ui.findActor("return").getColor();
ScrollPane scrollPane = ui.findActor("deckSlots");
scrollPane.setActor(layout);
}
private void rename() {
dialog.hide();
String text=textInput.getText();
Current.player().renameDeck(text);
buttons.get(currentSlot).setText(Current.player().getDeck(currentSlot).getName());
}
private void edit() {
AdventureApplicationAdapter.instance.switchScene(SceneType.DeckEditScene.instance);
}
}

View File

@@ -47,13 +47,14 @@ public class DuelScene extends ForgeScene {
public void GameEnd() {
boolean winner=humanPlayer == hostedMatch.getGame().getMatch().getWinner();
Gdx.app.postRunnable(() -> {
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS); //start background music
Scene last= AdventureApplicationAdapter.instance.switchToLast();
if(last instanceof HudScene)
{
((HudScene)last).stage.setWinner(humanPlayer == hostedMatch.getGame().getMatch().getWinner());
((HudScene)last).stage.setWinner(winner);
}
});
@@ -66,7 +67,7 @@ public class DuelScene extends ForgeScene {
appliedVariants.add(GameType.Constructed);
List<RegisteredPlayer> players = new ArrayList<>();
Deck playerDeck=(Deck)AdventurePlayer.current().getDeck().copyTo("PlayerDeckCopy");
Deck playerDeck=(Deck)AdventurePlayer.current().getSelectedDeck().copyTo("PlayerDeckCopy");
int missingCards= Config.instance().getConfigData().minDeckSize-playerDeck.getMain().countAll();
if(missingCards>0)
playerDeck.getMain().add("Wastes",missingCards);

View File

@@ -23,7 +23,6 @@ public class ForgeInput extends FGestureAdapter {
private static char lastKeyTyped;
private static boolean keyTyped, shiftKeyDown;
private final ForgeScene forgeScene;
private final Forge.KeyInputAdapter keyInputAdapter = null;
//mouseMoved and scrolled events for desktop version
private int mouseMovedX, mouseMovedY;
@@ -67,7 +66,7 @@ public class ForgeInput extends FGestureAdapter {
back();
}
*/
if (keyInputAdapter == null) {
if (Forge.keyInputAdapter == null) {
if (Forge.KeyInputAdapter.isModifierKey(keyCode)) {
return false; //don't process modifiers keys for unknown adapter
}
@@ -81,7 +80,7 @@ public class ForgeInput extends FGestureAdapter {
}
return container.keyDown(keyCode);
}
return keyInputAdapter.keyDown(keyCode);
return Forge.keyInputAdapter.keyDown(keyCode);
}
@Override
@@ -90,21 +89,21 @@ public class ForgeInput extends FGestureAdapter {
if (keyCode == Input.Keys.SHIFT_LEFT || keyCode == Input.Keys.SHIFT_RIGHT) {
shiftKeyDown = false;
}
if (keyInputAdapter != null) {
return keyInputAdapter.keyUp(keyCode);
if (Forge.keyInputAdapter != null) {
return Forge.keyInputAdapter.keyUp(keyCode);
}
return false;
}
@Override
public boolean keyTyped(char ch) {
if (keyInputAdapter != null) {
if (Forge.keyInputAdapter != null) {
if (ch >= ' ' && ch <= '~') { //only process this event if character is printable
//prevent firing this event more than once for the same character on the same key down, otherwise it fires too often
if (lastKeyTyped != ch || !keyTyped) {
keyTyped = true;
lastKeyTyped = ch;
return keyInputAdapter.keyTyped(ch);
return Forge.keyInputAdapter.keyTyped(ch);
}
}
}
@@ -130,8 +129,8 @@ public class ForgeInput extends FGestureAdapter {
public boolean touchDown(int x, int y, int pointer, int button) {
if (pointer == 0) { //don't change listeners when second finger goes down for zoom
updatePotentialListeners(x, y);
if (keyInputAdapter != null) {
if (!keyInputAdapter.allowTouchInput() || !potentialListeners.contains(keyInputAdapter.getOwner())) {
if (Forge.keyInputAdapter != null) {
if (!Forge.keyInputAdapter.allowTouchInput() || !potentialListeners.contains(Forge.keyInputAdapter.getOwner())) {
//endKeyInput(); //end key input if needed
}
}

View File

@@ -95,7 +95,7 @@ public class SaveLoadScene extends UIScene {
public void loadSave() {
if (save) {
textInput.setText("Save Game " + currentSlot);
textInput.setText(buttons.get(currentSlot).getText().toString());
dialog.show(stage);
stage.setKeyboardFocus(textInput);
} else {

View File

@@ -13,7 +13,8 @@ public enum SceneType {
DeckEditScene(new forge.adventure.scene.DeckEditScene()),
TileMapScene(new forge.adventure.scene.TileMapScene()),
RewardScene(new forge.adventure.scene.RewardScene()),
InnScene(new forge.adventure.scene.InnScene());
InnScene(new forge.adventure.scene.InnScene()),
DeckSelectScene(new forge.adventure.scene.DeckSelectScene());
public final forge.adventure.scene.Scene instance;

View File

@@ -107,7 +107,7 @@ public class GameHUD extends Stage {
private Object openDeck() {
AdventureApplicationAdapter.instance.switchScene(SceneType.DeckEditScene.instance);
AdventureApplicationAdapter.instance.switchScene(SceneType.DeckSelectScene.instance);
return null;
}

View File

@@ -8,6 +8,7 @@ import forge.adventure.data.HeroListData;
import forge.adventure.util.*;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
import java.io.Serializable;
@@ -15,6 +16,7 @@ import java.io.Serializable;
* Class that represents the player (not the player sprite)
*/
public class AdventurePlayer implements Serializable, SaveFileContent {
public static final int NUMBER_OF_DECKS=10;
private Deck deck;
private int avatarIndex;
private int heroRace;
@@ -25,7 +27,17 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
private int gold=0;
private int maxLife=20;
private int life=20;
private int selectedDeckIndex=0;
private Deck[] decks=new Deck[NUMBER_OF_DECKS];
private final DifficultyData difficultyData=new DifficultyData();
public AdventurePlayer()
{
for(int i=0;i<NUMBER_OF_DECKS;i++)
{
decks[i]=new Deck("Empty Deck");
}
}
static public AdventurePlayer current()
{
return WorldSave.currentSave.getPlayer();
@@ -35,6 +47,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
public void create(String n, Deck startingDeck, boolean male, int race, int avatar,DifficultyData difficultyData) {
deck = startingDeck;
decks[0]=deck;
gold =difficultyData.staringMoney;
cards.clear();
cards.addAllFlat(deck.getAllCardsInASinglePool().toFlatList());
@@ -53,9 +66,22 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
onLifeTotalChangeList.emit();
}
public Deck getDeck() {
public void setSelectedDeckSlot(int slot) {
if(slot>=0&&slot<NUMBER_OF_DECKS)
{
selectedDeckIndex=slot;
deck=decks[selectedDeckIndex];
}
}
public int getSelectedDeckIndex() {
return selectedDeckIndex;
}
public Deck getSelectedDeck() {
return deck;
}
public Deck getDeck(int index) {
return decks[index];
}
public CardPool getCards() {
return cards;
}
@@ -106,6 +132,25 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
deck = new Deck(data.readString("deckName"));
deck.getMain().addAll(CardPool.fromCardList(Lists.newArrayList((String[])data.readObject("deckCards"))));
if(data.containsKey("sideBoardCards"))
deck.getOrCreate(DeckSection.Sideboard).addAll(CardPool.fromCardList(Lists.newArrayList((String[])data.readObject("sideBoardCards"))));
for(int i=0;i<NUMBER_OF_DECKS;i++)
{
if(!data.containsKey("deck_name_"+i))
{
if(i==0)
decks[i]=deck;
else
decks[i]=new Deck("Empty Deck");
continue;
}
decks[i] = new Deck(data.readString("deck_name_"+i));
decks[i].getMain().addAll(CardPool.fromCardList(Lists.newArrayList((String[])data.readObject("deck_"+i))));
if(data.containsKey("sideBoardCards_"+i))
decks[i].getOrCreate(DeckSection.Sideboard).addAll(CardPool.fromCardList(Lists.newArrayList((String[])data.readObject("sideBoardCards_"+i))));
}
setSelectedDeckSlot(data.readInt("selectedDeckIndex"));
cards.clear();
cards.addAll(CardPool.fromCardList(Lists.newArrayList((String[])data.readObject("cards"))));
@@ -139,6 +184,17 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
data.storeObject("deckCards",deck.getMain().toCardList("\n").split("\n"));
if(deck.get(DeckSection.Sideboard)!=null)
data.storeObject("sideBoardCards",deck.get(DeckSection.Sideboard).toCardList("\n").split("\n"));
for(int i=0;i<NUMBER_OF_DECKS;i++)
{
data.store("deck_name_"+i,decks[i].getName());
data.storeObject("deck_"+i,decks[i].getMain().toCardList("\n").split("\n"));
if(decks[i].get(DeckSection.Sideboard)!=null)
data.storeObject("sideBoardCards_"+i,decks[i].get(DeckSection.Sideboard).toCardList("\n").split("\n"));
}
data.store("selectedDeckIndex",selectedDeckIndex);
data.storeObject("cards",cards.toCardList("\n").split("\n"));
return data;
@@ -235,4 +291,10 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
public DifficultyData getDifficulty() {
return difficultyData;
}
public void renameDeck( String text) {
deck = (Deck)deck.copyTo(text);
decks[selectedDeckIndex]=deck;
}
}

View File

@@ -48,7 +48,7 @@ public class Forge implements ApplicationListener {
private static FrameRate frameRate;
private static FScreen currentScreen;
protected static SplashScreen splashScreen;
private static KeyInputAdapter keyInputAdapter;
public static KeyInputAdapter keyInputAdapter;
private static boolean exited;
private static int continuousRenderingCount = 1; //initialize to 1 since continuous rendering is the default
private static final Deque<FScreen> Dscreens = new ArrayDeque<>();

View File

@@ -353,12 +353,19 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
editorType.getController().load(editDeckPath, editDeckName);
}
if(allowsSave())
{
btnSave.setCommand(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
save(null);
}
});
}
else
{
btnSave.setVisible(false);
}
btnMoreOptions.setCommand(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
@@ -367,6 +374,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
protected void buildMenu() {
final Localizer localizer = Localizer.getInstance();
if (allowsAddBasic())
addItem(new FMenuItem(localizer.getMessage("lblAddBasicLands"), FSkinImage.LANDLOGO, new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
@@ -655,7 +663,13 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
return null; //never use backdrop for editor
}
private boolean isLimitedEditor() {
protected boolean allowsSave() {
return true;
}
protected boolean allowsAddBasic() {
return true;
}
protected boolean isLimitedEditor() {
switch (editorType) {
case Draft:
case Sealed:
@@ -1819,7 +1833,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
final Localizer localizer = Localizer.getInstance();
name = "[" + localizer.getMessage("lblNewDeck") + "]";
}
if (!saved) {
if (!saved && editor.allowsSave()) {
name = "*" + name;
}
editor.lblName.setText(name);

View File

@@ -0,0 +1,51 @@
{
"width": 480,
"height": 270,
"yDown": true,
"elements":[
{
"type" : "Image",
"image":"ui/title_bg.png",
"width": 480,
"height": 270
} ,
{
"type" : "Scroll",
"name": "deckSlots",
"x": 10,
"y": 10 ,
"width": 344,
"height": 235
} ,
{
"type" : "TextButton",
"name" : "return" ,
"text" : "Back" ,
"width": 48,
"height": 16,
"x": 15,
"y": 250
} ,
{
"type" : "TextButton",
"name" : "rename" ,
"text" : "Rename Deck" ,
"width": 48,
"height": 16,
"x": 115,
"y": 250
} ,
{
"type" : "TextButton",
"name" : "edit" ,
"text" : "Edit Deck" ,
"width": 48,
"height": 16,
"x": 215,
"y": 250
}
]
}