Merge pull request #2910 from bbp9857/master

Added copy and delete deck
This commit is contained in:
Anthony Calosa
2023-04-14 08:31:39 +08:00
committed by GitHub
13 changed files with 144 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Null;
import com.google.common.collect.Lists;
import forge.Forge;
import forge.adventure.data.*;
import forge.adventure.util.*;
import forge.adventure.world.WorldSave;
@@ -78,7 +79,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
}
private void clearDecks() {
for (int i = 0; i < NUMBER_OF_DECKS; i++) decks[i] = new Deck("Empty Deck");
for (int i = 0; i < NUMBER_OF_DECKS; i++) decks[i] = new Deck(Forge.getLocalizer().getMessage("lblEmptyDeck"));
deck = decks[0];
selectedDeckIndex = 0;
}
@@ -347,7 +348,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
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");
else decks[i] = new Deck(Forge.getLocalizer().getMessage("lblEmptyDeck"));
continue;
}
decks[i] = new Deck(data.readString("deck_name_" + i));
@@ -845,4 +846,31 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
public void removeQuest(AdventureQuestData quest) {
quests.remove(quest);
}
/**
* Deletes a deck by replacing the current selected deck with a new deck
*/
public void deleteDeck() {
deck = decks[selectedDeckIndex] = new Deck(Forge.getLocalizer().getMessage("lblEmptyDeck"));
}
/**
* Attempts to copy a deck to an empty slot.
*
* @return int - index of new copy slot, or -1 if no slot was available
*/
public int copyDeck() {
for (int i = 0; i < decks.length; i++ ){
if (isEmptyDeck(i)) {
decks[i] = (Deck)deck.copyTo(deck.getName() + " (" + Forge.getLocalizer().getMessage("lblCopy") + ")");
return i;
}
}
return -1;
}
public boolean isEmptyDeck(int deckIndex) {
return decks[deckIndex].isEmpty() && decks[deckIndex].getName().equals(Forge.getLocalizer().getMessage("lblEmptyDeck"));
}
}

View File

@@ -61,10 +61,48 @@ public class DeckSelectScene extends UIScene {
textInput.setText(Current.player().getSelectedDeck().getName());
showRenameDialog();
});
ui.onButtonPress("copy", DeckSelectScene.this::copy);
ui.onButtonPress("delete", DeckSelectScene.this::maybeDelete);
defColor = ui.findActor("return").getColor();
window.add(root);
}
private void copy() {
if (Current.player().isEmptyDeck(currentSlot)) return;
int index = Current.player().copyDeck();
if (index == -1) {
showDialog(createGenericDialog(Forge.getLocalizer().getMessage("lblCopy"), Forge.getLocalizer().getMessage("lblNoAvailableSlots"),
Forge.getLocalizer().getMessage("lblOk"),
null, this::removeDialog, null));
}
else {
updateDeckButton(index);
select(index);
scrollPane.scrollTo(buttons.get(index).getX(), buttons.get(index).getY(), 0, 0);
}
}
private void maybeDelete() {
if (Current.player().isEmptyDeck(currentSlot)) return;
Dialog deleteDialog = createGenericDialog(Forge.getLocalizer().getMessage("lblDelete"), Forge.getLocalizer().getMessage("lblAreYouSureProceedDelete"),
Forge.getLocalizer().getMessage("lblOk"),
Forge.getLocalizer().getMessage("lblAbort"), this::delete, this::removeDialog);
showDialog(deleteDialog);
}
private void delete() {
Current.player().deleteDeck();
updateDeckButton(currentSlot);
removeDialog();
}
private void updateDeckButton(int index) {
buttons.get(index).setText(Current.player().getDeck(index).getName());
buttons.get(index).getTextraLabel().layout();
buttons.get(index).layout();
}
private void showRenameDialog() {
if (renameDialog == null) {
renameDialog = createGenericDialog(Forge.getLocalizer().getMessage("lblRenameDeck"), null,

View File

@@ -243,8 +243,11 @@ public class UIScene extends Scene {
if (label != null)
dialog.text(label);
TextraButton yes = Controls.newTextButton(stringYes, runnableYes);
TextraButton no = Controls.newTextButton(stringNo, runnableNo);
dialog.button(yes).button(no);
dialog.button(yes);
if (stringNo != null) {
TextraButton no = Controls.newTextButton(stringNo, runnableNo);
dialog.button(no);
}
return dialog;
}

View File

@@ -25,7 +25,7 @@
"width": 100,
"height": 30,
"x": 365,
"y": 60
"y": 10
},
{
"type": "TextButton",
@@ -34,7 +34,7 @@
"width": 100,
"height": 30,
"x": 365,
"y": 120
"y": 60
},
{
"type": "TextButton",
@@ -44,7 +44,25 @@
"width": 100,
"height": 30,
"x": 365,
"y": 180
"y": 110
},
{
"type": "TextButton",
"name": "copy",
"text": "tr(lblCopy)",
"width": 100,
"height": 30,
"x": 365,
"y": 160
},
{
"type": "TextButton",
"name": "delete",
"text": "tr(lblDelete)",
"width": 100,
"height": 30,
"x": 365,
"y": 210
}
]
}

View File

@@ -15,16 +15,25 @@
"x": 4,
"y": 4,
"width": 262,
"height": 442
"height": 414
},
{
"type": "TextButton",
"name": "return",
"text": "tr(lblBack)",
"name": "delete",
"text": "tr(lblDelete)",
"width": 86,
"height": 30,
"x": 4,
"y": 448
"y": 418
},
{
"type": "TextButton",
"name": "copy",
"text": "tr(lblCopy)",
"width": 86,
"height": 30,
"x": 92,
"y": 418
},
{
"type": "TextButton",
@@ -32,16 +41,27 @@
"text": "tr(lblRename)",
"width": 86,
"height": 30,
"x": 92,
"x": 180,
"y": 418
},
{
"type": "TextButton",
"name": "return",
"text": "tr(lblBack)",
"binding": "Back",
"width": 130,
"height": 30,
"x": 4,
"y": 448
},
{
"type": "TextButton",
"name": "edit",
"text": "tr(lblEdit)",
"width": 86,
"binding": "Use",
"width": 130,
"height": 30,
"x": 180,
"x": 136,
"y": 448
}
]

View File

@@ -2961,3 +2961,5 @@ lblExitToWoldMap=Zurück zur Weltkarte?
lblStartArena=Willst du in die Arena gehen?
lblWouldYouLikeDestroy=Möchten Sie {0} zerstören?
lblAdventureDescription=Im Abenteuermodus erkunden Sie die sich ständig ändernde Landschaft von Shandalar und Duell-Kreaturen; um Gold, Scherben, Ausrüstung und neue Karten zu gewinnen, sie alle zu sammeln und der Beste zu werden!
lblEmptyDeck=Leeres Kartendeck
lblNoAvailableSlots=Keine verf<72>gbaren Slots

View File

@@ -2969,4 +2969,6 @@ lblBoon=Boon
lblExitToWoldMap=Exit to the World Map?
lblStartArena=Do you want to go into the Arena?
lblWouldYouLikeDestroy=Would you like to destroy {0}?
lblAdventureDescription=Adventure mode is where you explore the ever-changing landscape of Shandalar, and duel creatures to gain gold, shards, equipment and new cards to become the best and collect them all!
lblAdventureDescription=Adventure mode is where you explore the ever-changing landscape of Shandalar, and duel creatures to gain gold, shards, equipment and new cards to become the best and collect them all!
lblEmptyDeck=Empty Deck
lblNoAvailableSlots=No available slots

View File

@@ -2963,4 +2963,6 @@ lblBoon=Boon
lblExitToWoldMap=Salir al mapa del mundo?
lblStartArena=¿Quieres ir a la arena?
lblWouldYouLikeDestroy=¿Le gustaría destruir {0}?
lblAdventureDescription=¡El modo de aventura es donde exploras el paisaje siempre cambiante de Shandalar, y criaturas de duelo para ganar oro, fragmentos, equipos y nuevas tarjetas para convertirte en el mejor y recogerlas a todos!
lblAdventureDescription=<EFBFBD>El modo de aventura es donde exploras el paisaje siempre cambiante de Shandalar, y criaturas de duelo para ganar oro, fragmentos, equipos y nuevas tarjetas para convertirte en el mejor y recogerlas a todos!
lblEmptyDeck=Baraja de cartas vac<61>a
lblNoAvailableSlots=No hay ranuras disponibles

View File

@@ -2965,4 +2965,6 @@ lblBoon=Aubaine
lblExitToWoldMap=Sortir sur la carte du monde?
lblStartArena=Voulez-vous entrer dans l'arène?
lblWouldYouLikeDestroy=Souhaitez-vous détruire {0}?
lblAdventureDescription=Le mode aventure est l'endroit où vous explorez le paysage en constante évolution de Shandalar, et des créatures duel pour gagner de l'or, des éclats, de l'équipement et de nouvelles cartes pour devenir les meilleurs et les récupérer tous!
lblAdventureDescription=Le mode aventure est l'endroit où vous explorez le paysage en constante évolution de Shandalar, et des créatures duel pour gagner de l'or, des éclats, de l'équipement et de nouvelles cartes pour devenir les meilleurs et les récupérer tous!
lblEmptyDeck=Jeu de cartes vide
lblNoAvailableSlots=Aucune fente disponible

View File

@@ -2967,3 +2967,5 @@ lblExitToWoldMap=Esci alla mappa del mondo?
lblStartArena=Vuoi andare nell'arena?
lblWouldYouLikeDestroy=Vorresti distruggere {0}?
lblAdventureDescription=La modalità Adventure è dove esplori il paesaggio in continua evoluzione di Shandalar e le creature di duello per guadagnare oro, frammenti, attrezzature e nuove carte per diventare i migliori e raccoglierle tutte!
lblEmptyDeck=Mazzo di carte vuoto
lblNoAvailableSlots=Nessuno slot disponibile

View File

@@ -2962,4 +2962,6 @@ lblBoon=ブーン
lblExitToWoldMap=世界地図に終了しますか?
lblStartArena=アリーナに行きたいですか?
lblWouldYouLikeDestroy={0}を破壊しますか?
lblAdventureDescription=アドベンチャーモードは、金、破片、機器、新しいカードを獲得して最高のものになり、すべてを集めるために、Shandalarの絶えず変化する風景と決闘の生き物を探求する場所です
lblAdventureDescription=アドベンチャーモードは、金、破片、機器、新しいカードを獲得して最高のものになり、すべてを集めるために、Shandalarの絶えず変化する風景と決闘の生き物を探求する場所です
lblEmptyDeck=空のトランプデッキ
lblNoAvailableSlots=使用可能なスロットがありませる。

View File

@@ -3052,4 +3052,7 @@ lblBoon=Boon
lblExitToWoldMap=Sair para o mapa do mundo?
lblStartArena=Você quer entrar na arena?
lblWouldYouLikeDestroy=Você gostaria de destruir {0}?
lblAdventureDescription=O modo de aventura é onde você explora a paisagem em constante mudança de Shandalar, e duelo para ganhar ouro, fragmentos, equipamentos e novos cartões para se tornarem os melhores e colecioná-los!
lblAdventureDescription=O modo de aventura é onde você explora a paisagem em constante mudança de Shandalar, e duelo para ganhar ouro, fragmentos, equipamentos e novos cartões para se tornarem os melhores e colecioná-los!
lblEmptyDeck=Baralho de cartas vazio
lblNoAvailableSlots=N<EFBFBD>o h<> slots dispon<6F>veis

View File

@@ -2945,4 +2945,6 @@ lblBoon=恩赐
lblExitToWoldMap=退出世界地图?
lblStartArena=您想进入竞技场吗?
lblWouldYouLikeDestroy=您想销毁{0}吗?
lblAdventureDescription=冒险模式是您探索山达尔Shandalar不断变化的景观以及决斗生物获得黄金碎片设备和新卡片使其成为最好的并收集所有这些
lblAdventureDescription=冒险模式是您探索山达尔Shandalar不断变化的景观以及决斗生物获得黄金碎片设备和新卡片使其成为最好的并收集所有这些
lblEmptyDeck=空牌<EFBFBD> <20> - 空牌<E7A9BA> <20>
lblNoAvailableSlots=没有可用的槽位<EFBFBD>