mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Add Tutorial mode
This commit is contained in:
@@ -12,6 +12,7 @@ import forge.screens.home.gauntlet.VSubmenuGauntletQuick;
|
||||
import forge.screens.home.online.VSubmenuOnlineLobby;
|
||||
import forge.screens.home.puzzle.VSubmenuPuzzleCreate;
|
||||
import forge.screens.home.puzzle.VSubmenuPuzzleSolve;
|
||||
import forge.screens.home.puzzle.VSubmenuTutorial;
|
||||
import forge.screens.home.quest.*;
|
||||
import forge.screens.home.sanctioned.VSubmenuConstructed;
|
||||
import forge.screens.home.sanctioned.VSubmenuDraft;
|
||||
@@ -63,6 +64,7 @@ public enum EDocID {
|
||||
HOME_ACHIEVEMENTS (VSubmenuAchievements.SINGLETON_INSTANCE),
|
||||
HOME_AVATARS (VSubmenuAvatars.SINGLETON_INSTANCE),
|
||||
HOME_UTILITIES (VSubmenuDownloaders.SINGLETON_INSTANCE),
|
||||
HOME_TUTORIAL(VSubmenuTutorial.SINGLETON_INSTANCE),
|
||||
HOME_PUZZLE_CREATE(VSubmenuPuzzleCreate.SINGLETON_INSTANCE),
|
||||
HOME_PUZZLE_SOLVE(VSubmenuPuzzleSolve.SINGLETON_INSTANCE),
|
||||
HOME_CONSTRUCTED (VSubmenuConstructed.SINGLETON_INSTANCE),
|
||||
|
||||
@@ -29,6 +29,7 @@ import forge.screens.home.gauntlet.VSubmenuGauntletQuick;
|
||||
import forge.screens.home.online.VSubmenuOnlineLobby;
|
||||
import forge.screens.home.puzzle.VSubmenuPuzzleCreate;
|
||||
import forge.screens.home.puzzle.VSubmenuPuzzleSolve;
|
||||
import forge.screens.home.puzzle.VSubmenuTutorial;
|
||||
import forge.screens.home.quest.*;
|
||||
import forge.screens.home.sanctioned.VSubmenuConstructed;
|
||||
import forge.screens.home.sanctioned.VSubmenuDraft;
|
||||
@@ -44,8 +45,8 @@ import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Top level view class for home UI drag layout.<br>
|
||||
@@ -114,6 +115,7 @@ public enum VHomeUI implements IVTopLevelUI {
|
||||
|
||||
allSubmenus.add(VSubmenuPuzzleSolve.SINGLETON_INSTANCE);
|
||||
allSubmenus.add(VSubmenuPuzzleCreate.SINGLETON_INSTANCE);
|
||||
allSubmenus.add(VSubmenuTutorial.SINGLETON_INSTANCE);
|
||||
|
||||
allSubmenus.add(VSubmenuPreferences.SINGLETON_INSTANCE);
|
||||
allSubmenus.add(VSubmenuAchievements.SINGLETON_INSTANCE);
|
||||
|
||||
@@ -13,10 +13,11 @@ import forge.match.HostedMatch;
|
||||
import forge.menus.IMenuProvider;
|
||||
import forge.menus.MenuUtil;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.puzzle.Puzzle;
|
||||
import forge.puzzle.PuzzleIO;
|
||||
import forge.util.gui.SOptionPane;
|
||||
import forge.util.Localizer;
|
||||
import forge.util.gui.SOptionPane;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -53,7 +54,7 @@ public enum CSubmenuPuzzleSolve implements ICDoc, IMenuProvider {
|
||||
};
|
||||
|
||||
private void updateData() {
|
||||
final ArrayList<Puzzle> puzzles = PuzzleIO.loadPuzzles();
|
||||
final ArrayList<Puzzle> puzzles = PuzzleIO.loadPuzzles(ForgeConstants.PUZZLE_DIR);
|
||||
Collections.sort(puzzles);
|
||||
|
||||
for(Puzzle p : puzzles) {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package forge.screens.home.puzzle;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.UiCommand;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameRules;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.match.HostedMatch;
|
||||
import forge.menus.IMenuProvider;
|
||||
import forge.menus.MenuUtil;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.puzzle.Puzzle;
|
||||
import forge.puzzle.PuzzleIO;
|
||||
import forge.util.Localizer;
|
||||
import forge.util.gui.SOptionPane;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public enum CSubmenuTutorial implements ICDoc, IMenuProvider {
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private VSubmenuTutorial view = VSubmenuTutorial.SINGLETON_INSTANCE;
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
view.getList().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
updateData();
|
||||
view.getBtnStart().addActionListener(
|
||||
new ActionListener() { @Override
|
||||
public void actionPerformed(final ActionEvent e) { startPuzzleSolve(); } });
|
||||
}
|
||||
|
||||
private final UiCommand cmdStart = new UiCommand() {
|
||||
private static final long serialVersionUID = -367368436333443417L;
|
||||
|
||||
@Override public void run() {
|
||||
startPuzzleSolve();
|
||||
}
|
||||
};
|
||||
|
||||
private void updateData() {
|
||||
final ArrayList<Puzzle> tutorials = PuzzleIO.loadPuzzles(ForgeConstants.TUTORIAL_DIR);
|
||||
Collections.sort(tutorials);
|
||||
|
||||
for(Puzzle p : tutorials) {
|
||||
view.getModel().addElement(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
MenuUtil.setMenuProvider(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JMenu> getMenus() {
|
||||
final List<JMenu> menus = new ArrayList<>();
|
||||
menus.add(PuzzleGameMenu.getMenu());
|
||||
return menus;
|
||||
}
|
||||
|
||||
private boolean startPuzzleSolve() {
|
||||
final Puzzle selected = (Puzzle)view.getList().getSelectedValue();
|
||||
if (selected == null) {
|
||||
SOptionPane.showMessageDialog(Localizer.getInstance().getMessage("lblPleaseFirstSelectAPuzzleFromList"), Localizer.getInstance().getMessage("lblNoSelectedPuzzle"), FSkinProp.ICO_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SOverlayUtils.startGameOverlay();
|
||||
SOverlayUtils.showOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
||||
hostedMatch.setStartGameHook(new Runnable() {
|
||||
@Override
|
||||
public final void run() {
|
||||
SOptionPane.showMessageDialog(selected.getGoalDescription(), selected.getName(), SOptionPane.INFORMATION_ICON);
|
||||
selected.applyToGame(hostedMatch.getGame());
|
||||
}
|
||||
});
|
||||
|
||||
hostedMatch.setEndGameHook((new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
selected.savePuzzleSolve(hostedMatch.getGame().getOutcome().isWinner(GamePlayerUtil.getGuiPlayer()));
|
||||
}
|
||||
}));
|
||||
|
||||
final List<RegisteredPlayer> players = new ArrayList<>();
|
||||
final RegisteredPlayer human = new RegisteredPlayer(new Deck()).setPlayer(GamePlayerUtil.getGuiPlayer());
|
||||
human.setStartingHand(0);
|
||||
players.add(human);
|
||||
|
||||
final RegisteredPlayer ai = new RegisteredPlayer(new Deck()).setPlayer(GamePlayerUtil.createAiPlayer());
|
||||
ai.setStartingHand(0);
|
||||
players.add(ai);
|
||||
|
||||
GameRules rules = new GameRules(GameType.Puzzle);
|
||||
rules.setGamesPerMatch(1);
|
||||
hostedMatch.startMatch(rules, null, players, human, GuiBase.getInterface().getNewGuiGame());
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SOverlayUtils.hideOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package forge.screens.home.puzzle;
|
||||
|
||||
import forge.gui.framework.DragCell;
|
||||
import forge.gui.framework.DragTab;
|
||||
import forge.gui.framework.EDocID;
|
||||
import forge.interfaces.IPlayerChangeListener;
|
||||
import forge.match.GameLobby;
|
||||
import forge.match.LocalLobby;
|
||||
import forge.net.event.UpdateLobbyPlayerEvent;
|
||||
import forge.screens.home.*;
|
||||
import forge.toolbox.FList;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.util.Localizer;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public enum VSubmenuTutorial implements IVSubmenu<CSubmenuTutorial> {
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final FList tutorialList;
|
||||
private final FScrollPane tutorialListPane;
|
||||
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
|
||||
private final StartButton btnStart = new StartButton();
|
||||
|
||||
private DragCell parentCell;
|
||||
final Localizer localizer = Localizer.getInstance();
|
||||
private final DragTab tab = new DragTab(localizer.getMessage("lblTutorialMode"));
|
||||
|
||||
private final GameLobby lobby = new LocalLobby();
|
||||
private final VLobby vLobby = new VLobby(lobby);
|
||||
|
||||
VSubmenuTutorial() {
|
||||
tutorialList = new FList<>();
|
||||
tutorialListPane = new FScrollPane(this.tutorialList, true);
|
||||
|
||||
lobby.setListener(vLobby);
|
||||
|
||||
vLobby.setPlayerChangeListener(new IPlayerChangeListener() {
|
||||
@Override public final void update(final int index, final UpdateLobbyPlayerEvent event) {
|
||||
lobby.applyToSlot(index, event);
|
||||
}
|
||||
});
|
||||
|
||||
vLobby.update(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EMenuGroup getGroupEnum() {
|
||||
return EMenuGroup.PUZZLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMenuTitle() {
|
||||
final Localizer localizer = Localizer.getInstance();
|
||||
return localizer.getMessage("lblTutorial");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDocID getItemEnum() {
|
||||
return EDocID.HOME_TUTORIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDocID getDocumentID() {
|
||||
return EDocID.HOME_TUTORIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DragTab getTabLabel() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CSubmenuTutorial getLayoutControl() {
|
||||
return CSubmenuTutorial.SINGLETON_INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParentCell(DragCell cell0) {
|
||||
this.parentCell = cell0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DragCell getParentCell() {
|
||||
return this.parentCell;
|
||||
}
|
||||
|
||||
public JList getList() {
|
||||
return tutorialList;
|
||||
}
|
||||
|
||||
public DefaultListModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public StartButton getBtnStart() {
|
||||
return btnStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate() {
|
||||
final JPanel container = VHomeUI.SINGLETON_INSTANCE.getPnlDisplay();
|
||||
|
||||
container.removeAll();
|
||||
container.setLayout(new MigLayout("insets 0, gap 0, wrap 1, ax right"));
|
||||
final Localizer localizer = Localizer.getInstance();
|
||||
vLobby.getLblTitle().setText(localizer.getMessage("lblTutorialMode"));
|
||||
container.add(vLobby.getLblTitle(), "w 80%, h 40px!, gap 0 0 15px 15px, span 2, al right, pushx");
|
||||
tutorialList.setModel(model);
|
||||
container.add(tutorialListPane, "w 80%, h 80%, gap 0 0 0px 0px, span 2, al center");
|
||||
container.add(btnStart, "w 98%!, ax center, gap 1% 0 20px 20px, span 2");
|
||||
|
||||
|
||||
if (container.isShowing()) {
|
||||
container.validate();
|
||||
container.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user