mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Start working on Achievements screen for mobile game
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1242,9 +1242,9 @@ forge-gui-mobile/src/forge/screens/quest/QuestSpellShopScreen.java -text
|
||||
forge-gui-mobile/src/forge/screens/quest/QuestStatsScreen.java -text
|
||||
forge-gui-mobile/src/forge/screens/quest/QuestTournamentsScreen.java -text
|
||||
forge-gui-mobile/src/forge/screens/sealed/SealedScreen.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/AchievementsPage.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/FilesPage.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/GuiDownloader.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/HelpPage.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/SettingsPage.java -text
|
||||
forge-gui-mobile/src/forge/screens/settings/SettingsScreen.java -text
|
||||
forge-gui-mobile/src/forge/sound/AudioClip.java -text
|
||||
|
||||
@@ -13,11 +13,9 @@ import java.awt.event.ActionListener;
|
||||
import forge.achievement.Achievement;
|
||||
import forge.achievement.AchievementCollection;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.framework.DragCell;
|
||||
import forge.gui.framework.DragTab;
|
||||
import forge.gui.framework.EDocID;
|
||||
import forge.model.FModel;
|
||||
import forge.screens.home.EMenuGroup;
|
||||
import forge.screens.home.IVSubmenu;
|
||||
import forge.screens.home.VHomeUI;
|
||||
@@ -56,11 +54,8 @@ public enum VSubmenuAchievements implements IVSubmenu<CSubmenuAchievements> {
|
||||
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
|
||||
trophyCase.setMinimumSize(new Dimension(266 * IMAGE_SCALE, 0));
|
||||
|
||||
cbCollections.addItem(FModel.getAchievements(GameType.Constructed));
|
||||
cbCollections.addItem(FModel.getAchievements(GameType.Draft));
|
||||
cbCollections.addItem(FModel.getAchievements(GameType.Sealed));
|
||||
cbCollections.addItem(FModel.getAchievements(GameType.Quest));
|
||||
|
||||
AchievementCollection.buildComboBox(cbCollections);
|
||||
|
||||
cbCollections.setSkinFont(FSkin.getBoldFont(14));
|
||||
cbCollections.setTextAlignment(TextAlignment.CENTER);
|
||||
@@ -186,7 +181,7 @@ public enum VSubmenuAchievements implements IVSubmenu<CSubmenuAchievements> {
|
||||
private static final Color foreColor = new Color(239, 220, 144);
|
||||
|
||||
private AchievementCollection achievements;
|
||||
int shelfCount;
|
||||
private int shelfCount;
|
||||
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
|
||||
@@ -203,7 +203,11 @@ public class FSkin {
|
||||
for (FSkinImage image : FSkinImage.values()) {
|
||||
image.load(textures, preferredIcons);
|
||||
}
|
||||
FSkinTexture.BG_MATCH.load();
|
||||
for (FSkinTexture texture : FSkinTexture.values()) {
|
||||
if (texture != FSkinTexture.BG_TEXTURE) {
|
||||
texture.load();
|
||||
}
|
||||
}
|
||||
|
||||
//assemble avatar textures
|
||||
int counter = 0;
|
||||
|
||||
@@ -109,6 +109,7 @@ public enum FSkinImage implements FImage {
|
||||
BRONZE_TROPHY (FSkinProp.IMG_BRONZE_TROPHY, SourceFile.ICONS),
|
||||
SILVER_TROPHY (FSkinProp.IMG_SILVER_TROPHY, SourceFile.ICONS),
|
||||
GOLD_TROPHY (FSkinProp.IMG_GOLD_TROPHY, SourceFile.ICONS),
|
||||
TROPHY_PLATE (FSkinProp.IMG_TROPHY_PLATE, SourceFile.ICONS),
|
||||
|
||||
//Quest Icons
|
||||
QUEST_ZEP (FSkinProp.ICO_QUEST_ZEP, SourceFile.ICONS),
|
||||
|
||||
@@ -8,7 +8,9 @@ import forge.Graphics;
|
||||
|
||||
public enum FSkinTexture implements FImage {
|
||||
BG_TEXTURE("bg_texture.jpg", true),
|
||||
BG_MATCH("bg_match.jpg", false);
|
||||
BG_MATCH("bg_match.jpg", false),
|
||||
BG_TROPHY_CASE_TOP("bg_trophy_case_top.png", false),
|
||||
BG_TROPHY_CASE_SHELF("bg_trophy_case_shelf.png", false);
|
||||
|
||||
private final String filename;
|
||||
private final boolean repeat;
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package forge.screens.settings;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.Graphics;
|
||||
import forge.achievement.Achievement;
|
||||
import forge.achievement.AchievementCollection;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.assets.FSkinTexture;
|
||||
import forge.screens.TabPageScreen.TabPage;
|
||||
import forge.toolbox.FComboBox;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.util.Utils;
|
||||
|
||||
public class AchievementsPage extends TabPage<SettingsScreen> {
|
||||
private static final float PADDING = Utils.scaleMin(5);
|
||||
private static final int MIN_SHELVES = 3;
|
||||
private static final int TROPHIES_PER_SHELVE = 4;
|
||||
|
||||
private final FComboBox<AchievementCollection> cbCollections = add(new FComboBox<AchievementCollection>());
|
||||
private final TrophyCase trophyCase = add(new TrophyCase());
|
||||
|
||||
protected AchievementsPage() {
|
||||
super("Achievements", FSkinImage.GOLD_TROPHY);
|
||||
|
||||
AchievementCollection.buildComboBox(cbCollections);
|
||||
|
||||
cbCollections.setSelectedIndex(0);
|
||||
cbCollections.setAlignment(HAlignment.CENTER);
|
||||
cbCollections.setChangedHandler(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
setAchievements(cbCollections.getSelectedItem());
|
||||
}
|
||||
});
|
||||
setAchievements(cbCollections.getSelectedItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
float x = PADDING;
|
||||
float y = PADDING;
|
||||
width -= 2 * x;
|
||||
|
||||
cbCollections.setBounds(x, y, width, cbCollections.getHeight());
|
||||
y += cbCollections.getHeight() + PADDING;
|
||||
trophyCase.setBounds(x, y, width, height - PADDING - y);
|
||||
}
|
||||
|
||||
private void setAchievements(AchievementCollection achievements0) {
|
||||
trophyCase.achievements = achievements0;
|
||||
|
||||
trophyCase.shelfCount = achievements0.getCount() % TROPHIES_PER_SHELVE;
|
||||
if (trophyCase.shelfCount < MIN_SHELVES) {
|
||||
trophyCase.shelfCount = MIN_SHELVES;
|
||||
}
|
||||
|
||||
trophyCase.revalidate();
|
||||
}
|
||||
|
||||
private static class TrophyCase extends FScrollPane {
|
||||
private static final FSkinFont FONT = FSkinFont.get(12);
|
||||
private static final FSkinFont SUB_FONT = FSkinFont.get(10);
|
||||
private static final Color FORE_COLOR = new Color(239f / 255f, 220f / 255f, 144f / 255f, 1f);
|
||||
|
||||
private AchievementCollection achievements;
|
||||
private int shelfCount;
|
||||
|
||||
@Override
|
||||
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
|
||||
|
||||
return new ScrollBounds(visibleWidth * 1.6f, visibleHeight * 1.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
float x = -getScrollLeft();
|
||||
float y = -getScrollTop();
|
||||
float w = getScrollWidth();
|
||||
float scale = w / FSkinTexture.BG_TROPHY_CASE_TOP.getWidth();
|
||||
float trophyScale = scale / 3f * 1.8f;
|
||||
float plateScale = scale / 3f;
|
||||
|
||||
float topHeight = FSkinTexture.BG_TROPHY_CASE_TOP.getHeight() * scale;
|
||||
float shelfHeight = FSkinTexture.BG_TROPHY_CASE_SHELF.getHeight() * scale;
|
||||
float trophyWidth = FSkinImage.GOLD_TROPHY.getWidth() * trophyScale;
|
||||
float trophyHeight = FSkinImage.GOLD_TROPHY.getHeight() * trophyScale;
|
||||
float plateWidth = FSkinImage.TROPHY_PLATE.getWidth() * plateScale;
|
||||
float plateHeight = FSkinImage.TROPHY_PLATE.getHeight() * plateScale;
|
||||
|
||||
float plateY = y + topHeight + shelfHeight - plateHeight;
|
||||
float trophyStartY = y + topHeight + (shelfHeight - trophyHeight - 12 * scale) / 2;
|
||||
float plateOffset = (trophyWidth - plateWidth) / 2;
|
||||
|
||||
if (y + topHeight > 0) {
|
||||
g.drawImage(FSkinTexture.BG_TROPHY_CASE_TOP, x, y, w, topHeight);
|
||||
}
|
||||
y += topHeight;
|
||||
|
||||
for (int i = 0; i < shelfCount; i++) {
|
||||
if (y + shelfHeight > 0) {
|
||||
g.drawImage(FSkinTexture.BG_TROPHY_CASE_SHELF, x, y, w, shelfHeight);
|
||||
}
|
||||
y += shelfHeight;
|
||||
if (y >= getHeight()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x += (w - TROPHIES_PER_SHELVE * trophyWidth) / 2;
|
||||
y = trophyStartY;
|
||||
|
||||
int trophyCount = 0;
|
||||
float startX = x;
|
||||
|
||||
for (Achievement achievement : achievements) {
|
||||
if (trophyCount == TROPHIES_PER_SHELVE) {
|
||||
trophyCount = 0;
|
||||
y += shelfHeight;
|
||||
plateY += shelfHeight;
|
||||
x = startX;
|
||||
|
||||
if (y >= getHeight()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (plateY + plateHeight > 0) {
|
||||
if (achievement.earnedGold()) {
|
||||
g.drawImage(FSkinImage.GOLD_TROPHY, x, y, trophyWidth, trophyHeight);
|
||||
}
|
||||
else if (achievement.earnedSilver()) {
|
||||
g.drawImage(FSkinImage.SILVER_TROPHY, x, y, trophyWidth, trophyHeight);
|
||||
}
|
||||
else if (achievement.earnedBronze()) {
|
||||
g.drawImage(FSkinImage.BRONZE_TROPHY, x, y, trophyWidth, trophyHeight);
|
||||
}
|
||||
g.drawImage(FSkinImage.TROPHY_PLATE, x + plateOffset, plateY, plateWidth, plateHeight);
|
||||
|
||||
g.drawText(achievement.getDisplayName(), FONT, FORE_COLOR, x + plateOffset + plateWidth * 0.05f, plateY + plateHeight * 0.05f, plateWidth * 0.9f, plateHeight * 0.55f, false, HAlignment.CENTER, true);
|
||||
|
||||
String subTitle = achievement.getSubTitle();
|
||||
if (subTitle != null) {
|
||||
g.drawText(subTitle, SUB_FONT, FORE_COLOR, x + plateOffset + plateWidth * 0.05f, plateY + plateHeight * 0.6f, plateWidth * 0.9f, plateHeight * 0.35f, false, HAlignment.CENTER, true);
|
||||
}
|
||||
}
|
||||
|
||||
trophyCount++;
|
||||
x += trophyWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package forge.screens.settings;
|
||||
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.screens.TabPageScreen.TabPage;
|
||||
|
||||
public class HelpPage extends TabPage<SettingsScreen> {
|
||||
|
||||
protected HelpPage() {
|
||||
super("Help", FSkinImage.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@ public class SettingsScreen extends TabPageScreen<SettingsScreen> {
|
||||
private SettingsScreen() {
|
||||
super(new TabPage[] {
|
||||
new SettingsPage(),
|
||||
new FilesPage()/*,
|
||||
new HelpPage()*/
|
||||
new AchievementsPage(),
|
||||
new FilesPage()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
@@ -13,7 +14,10 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.Player;
|
||||
import forge.interfaces.IComboBox;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.XmlUtil;
|
||||
@@ -26,6 +30,13 @@ public abstract class AchievementCollection implements Iterable<Achievement> {
|
||||
FileUtil.ensureDirectoryExists(ForgeConstants.ACHIEVEMENTS_DIR);
|
||||
}
|
||||
|
||||
public static void buildComboBox(IComboBox<AchievementCollection> cb) {
|
||||
cb.addItem(FModel.getAchievements(GameType.Constructed));
|
||||
cb.addItem(FModel.getAchievements(GameType.Draft));
|
||||
cb.addItem(FModel.getAchievements(GameType.Sealed));
|
||||
cb.addItem(FModel.getAchievements(GameType.Quest));
|
||||
}
|
||||
|
||||
protected AchievementCollection(String name0, String filename0) {
|
||||
name = name0;
|
||||
filename = filename0;
|
||||
|
||||
Reference in New Issue
Block a user