Refactor how header for screens handled

Add GuiDownloader for mobile app
This commit is contained in:
drdev
2014-05-28 02:13:16 +00:00
parent 226145ca22
commit d5d3fd3bb5
14 changed files with 223 additions and 68 deletions

1
.gitattributes vendored
View File

@@ -1101,6 +1101,7 @@ forge-gui-mobile/src/forge/card/CardRenderer.java -text
forge-gui-mobile/src/forge/card/CardZoom.java -text
forge-gui-mobile/src/forge/deck/FDeckChooser.java -text
forge-gui-mobile/src/forge/deck/FDeckViewer.java -text
forge-gui-mobile/src/forge/download/GuiDownloader.java -text
forge-gui-mobile/src/forge/error/BugReportDialog.java -text
forge-gui-mobile/src/forge/itemmanager/CardManager.java -text
forge-gui-mobile/src/forge/itemmanager/DeckManager.java -text

View File

@@ -44,7 +44,7 @@ public class FDeckChooser extends FScreen {
private FPref stateSetting = null;
public FDeckChooser(boolean isAi0) {
super(true, "");
super("");
isAi = isAi0;
lstDecks.setItemActivateHandler(new FEventHandler() {

View File

@@ -37,7 +37,7 @@ public class FDeckViewer extends FScreen {
}
private FDeckViewer(Deck deck0) {
super(true, deck0.getName());
super(deck0.getName());
deck = deck0;
cardManager = new CardManager(false);
cardManager.setPool(deck.getMain());

View File

@@ -0,0 +1,129 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.download;
import java.net.Proxy;
import forge.UiCommand;
import forge.assets.FSkinFont;
import forge.toolbox.*;
import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FRadioButton.RadioButtonGroup;
public class GuiDownloader extends FDialog {
public static final Proxy.Type[] TYPES = Proxy.Type.values();
private final FProgressBar progressBar = add(new FProgressBar());
private final FButton btnStart = add(new FButton("Start"));
private final FButton btnCancel = add(new FButton("Cancel"));
private final FTextField txtAddress = add(new FTextField());
private final FTextField txtPort = add(new FTextField());
private final FRadioButton radProxyNone = add(new FRadioButton("No Proxy"));
private final FRadioButton radProxySocks = add(new FRadioButton("SOCKS Proxy"));
private final FRadioButton radProxyHTTP = add(new FRadioButton("HTTP Proxy"));
@SuppressWarnings("serial")
private final UiCommand cmdClose = new UiCommand() {
@Override
public void run() {
service.setCancel(true);
hide();
}
};
private final GuiDownloadService service;
public GuiDownloader(GuiDownloadService service0) {
super(service0.getTitle());
service = service0;
txtAddress.setGhostText("Proxy Address");
txtPort.setGhostText("Proxy Port");
RadioButtonGroup group = new RadioButtonGroup();
radProxyNone.setGroup(group);
radProxyHTTP.setGroup(group);
radProxySocks.setGroup(group);
radProxyNone.setCommand(new ProxyHandler(0));
radProxyHTTP.setCommand(new ProxyHandler(1));
radProxySocks.setCommand(new ProxyHandler(2));
radProxyNone.setSelected(true);
btnStart.setFont(FSkinFont.get(18));
btnStart.setVisible(false);
btnCancel.setFont(btnStart.getFont());
btnCancel.setCommand(cmdClose);
progressBar.reset();
progressBar.setDescription("Scanning for existing items...");
show();
service.initialize(txtAddress, txtPort, progressBar, btnStart, cmdClose, null);
}
private class ProxyHandler implements FEventHandler {
private final int type;
public ProxyHandler(final int type) {
this.type = type;
}
@Override
public void handleEvent(FEvent e) {
if (((FRadioButton) e.getSource()).isSelected()) {
service.setType(this.type);
txtAddress.setEnabled(this.type != 0);
txtPort.setEnabled(this.type != 0);
}
}
}
@Override
protected float layoutAndGetHeight(float width, float maxHeight) {
float padding = FDialog.INSETS;
float x = padding;
float y = padding;
float w = width - 2 * padding;
float radioButtonWidth = (w - 2 * padding) / 3;
float radioButtonHeight = radProxyNone.getHeight();
radProxyNone.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x += radioButtonWidth + padding;
radProxyHTTP.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x += radioButtonWidth + padding;
radProxySocks.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x = padding;
y += radioButtonHeight + padding;
txtAddress.setBounds(x, y, w, txtAddress.getHeight());
y += txtAddress.getHeight() + padding;
txtPort.setBounds(x, y, w, txtPort.getHeight());
y += (txtPort.getHeight() + padding) * 2;
progressBar.setBounds(x, y, w, txtPort.getHeight() * 2);
y += progressBar.getHeight() + padding * 2;
float buttonWidth = (w - padding) / 2;
float buttonHeight = txtPort.getHeight() * 1.5f;
btnStart.setBounds(x, y, buttonWidth, buttonHeight);
x += w - buttonWidth;
btnCancel.setBounds(x, y, buttonWidth, buttonHeight);
return y + buttonWidth + padding;
}
}

View File

@@ -4,10 +4,9 @@ import java.util.ArrayList;
import java.util.List;
import forge.Forge.Graphics;
import forge.screens.FScreen;
import forge.toolbox.FContainer;
import forge.screens.FScreen.Header;
public class FMenuBar extends FContainer {
public class FMenuBar extends Header {
private final List<FMenuTab> tabs = new ArrayList<FMenuTab>();
public void addTab(String text0, FDropDown dropDown0) {
@@ -53,6 +52,6 @@ public class FMenuBar extends FContainer {
protected void drawBackground(Graphics g) {
float w = getWidth();
float h = getHeight();
g.fillRect(FScreen.HEADER_BACK_COLOR, 0, 0, w, h);
g.fillRect(BACK_COLOR, 0, 0, w, h);
}
}

View File

@@ -18,42 +18,27 @@ import forge.util.Utils;
public abstract class FScreen extends FContainer {
public static final FSkinColor TEXTURE_OVERLAY_COLOR = FSkinColor.get(Colors.CLR_THEME);
public static final FSkinColor HEADER_BTN_PRESSED_COLOR = TEXTURE_OVERLAY_COLOR.alphaColor(1f);
public static final FSkinColor HEADER_LINE_COLOR = HEADER_BTN_PRESSED_COLOR.stepColor(-40);
public static final FSkinColor HEADER_BACK_COLOR = HEADER_BTN_PRESSED_COLOR.stepColor(-80);
public static final float HEADER_HEIGHT = Math.round(Utils.AVG_FINGER_HEIGHT * 0.8f);
private static final FSkinFont HEADER_FONT = FSkinFont.get(16);
private final Header header;
private final FLabel btnBack, lblHeader;
protected FScreen(boolean showBackButton, String headerCaption) {
if (showBackButton) {
btnBack = add(new FLabel.Builder().icon(new BackIcon()).pressedColor(HEADER_BTN_PRESSED_COLOR).align(HAlignment.CENTER).command(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
Forge.back();
}
}).build());
}
else {
btnBack = null;
}
if (headerCaption != null) {
lblHeader = add(new FLabel.Builder().text(headerCaption).font(HEADER_FONT).align(HAlignment.CENTER).build());
}
else {
lblHeader = null;
protected FScreen(String headerCaption) {
this(headerCaption == null ? null : new DefaultHeader(headerCaption));
}
protected FScreen(Header header0) {
header = header0;
if (header != null) {
add(header);
}
}
public String getHeaderCaption() {
if (lblHeader == null) { return ""; }
return lblHeader.getText();
public Header getHeader() {
return header;
}
public void setHeaderCaption(String headerCaption) {
if (lblHeader == null) { return; }
lblHeader.setText(headerCaption);
if (header instanceof DefaultHeader) {
((DefaultHeader)header).lblCaption.setText(headerCaption);
}
}
public void onActivate() {
@@ -78,16 +63,9 @@ public abstract class FScreen extends FContainer {
@Override
protected final void doLayout(float width, float height) {
float headerX = HEADER_HEIGHT;
float headerWidth = width - 2 * headerX;
if (btnBack != null) {
btnBack.setBounds(0, 0, HEADER_HEIGHT, HEADER_HEIGHT);
}
if (lblHeader != null) {
lblHeader.setBounds(headerX, 0, headerWidth, HEADER_HEIGHT);
doLayout(HEADER_HEIGHT, width, height);
if (header != null) {
header.setBounds(0, 0, width, header.getPreferredHeight());
doLayout(header.getHeight(), width, height);
}
else {
doLayout(0, width, height);
@@ -102,10 +80,52 @@ public abstract class FScreen extends FContainer {
float h = getHeight();
g.drawImage(FSkinTexture.BG_TEXTURE, 0, 0, w, h);
g.fillRect(TEXTURE_OVERLAY_COLOR, 0, 0, w, h);
}
if (lblHeader != null) { //draw custom background behind header label
g.fillRect(HEADER_BACK_COLOR, 0, 0, w, HEADER_HEIGHT);
g.drawLine(1, HEADER_LINE_COLOR, 0, HEADER_HEIGHT, w, HEADER_HEIGHT);
public static abstract class Header extends FContainer {
protected static final FSkinColor BTN_PRESSED_COLOR = TEXTURE_OVERLAY_COLOR.alphaColor(1f);
protected static final FSkinColor LINE_COLOR = BTN_PRESSED_COLOR.stepColor(-40);
protected static final FSkinColor BACK_COLOR = BTN_PRESSED_COLOR.stepColor(-80);
protected static final float LINE_THICKNESS = Utils.scaleY(1);
public abstract float getPreferredHeight();
}
private static class DefaultHeader extends Header {
protected static final float HEIGHT = Math.round(Utils.AVG_FINGER_HEIGHT * 0.8f);
private static final FSkinFont FONT = FSkinFont.get(16);
private final FLabel lblCaption, btnBack;
public DefaultHeader(String headerCaption) {
lblCaption = add(new FLabel.Builder().text(headerCaption).font(FONT).align(HAlignment.CENTER).build());
btnBack = add(new FLabel.Builder().icon(new BackIcon(HEIGHT, HEIGHT)).pressedColor(BTN_PRESSED_COLOR).align(HAlignment.CENTER).command(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
Forge.back();
}
}).build());
btnBack.setSize(HEIGHT, HEIGHT);
}
@Override
public float getPreferredHeight() {
return HEIGHT;
}
@Override
public void drawBackground(Graphics g) {
g.fillRect(BACK_COLOR, 0, 0, getWidth(), HEIGHT);
}
@Override
public void drawOverlay(Graphics g) {
float y = HEIGHT - LINE_THICKNESS / 2;
g.drawLine(LINE_THICKNESS, LINE_COLOR, 0, y, getWidth(), y);
}
@Override
protected void doLayout(float width, float height) {
lblCaption.setBounds(0, 0, width, height);
}
}
@@ -113,14 +133,20 @@ public abstract class FScreen extends FContainer {
private static final float THICKNESS = Utils.scaleMax(3);
private static final FSkinColor COLOR = FSkinColor.get(Colors.CLR_TEXT);
private final float width, height;
private BackIcon(float width0, float height0) {
width = width0;
height = height0;
}
@Override
public float getWidth() {
return HEADER_HEIGHT;
return width;
}
@Override
public float getHeight() {
return HEADER_HEIGHT;
return height;
}
@Override

View File

@@ -28,7 +28,7 @@ public abstract class LaunchScreen extends FScreen {
private boolean creatingMatch;
public LaunchScreen(String headerCaption) {
super(true, headerCaption);
super(headerCaption);
btnStart = add(new StartButton());
}

View File

@@ -63,7 +63,7 @@ public class AvatarSelector extends FScreen {
};
private AvatarSelector(final String playerName, final int currentIndex0, final List<Integer> usedAvatars0, final Callback<Integer> callback0) {
super(true, "Select Avatar for " + playerName);
super("Select Avatar for " + playerName);
currentIndex = currentIndex0;
usedAvatars = usedAvatars0;

View File

@@ -837,7 +837,7 @@ public class ConstructedScreen extends LaunchScreen {
private int selectedIndex;
private DeckList() {
super(true, "");
super("");
list = new FList<Object>();
}
@@ -987,7 +987,7 @@ public class ConstructedScreen extends LaunchScreen {
private final FList<Variant> lstVariants = add(new FList<Variant>());
private MultiVariantSelect() {
super(true, "Select Variants");
super("Select Variants");
lstVariants.setListItemRenderer(new VariantRenderer());
lstVariants.addItem(new Variant(GameType.Vanguard, "Each player has a special \"Avatar\" card that affects the game."));

View File

@@ -21,9 +21,9 @@ public class HomeScreen extends FScreen {
public static final float INSETS_FACTOR = 0.025f;
private static final float GAP_Y_FACTOR = 0.01f;
private final ArrayList<FButton> buttons = new ArrayList<FButton>();
public HomeScreen() {
super(false, null);
super((Header)null);
addButton("Constructed", new FEventHandler() {
@Override

View File

@@ -39,7 +39,6 @@ public class MatchScreen extends FScreen {
public static FSkinColor BORDER_COLOR = FSkinColor.get(Colors.CLR_BORDERS);
private final Map<Player, VPlayerPanel> playerPanels = new HashMap<Player, VPlayerPanel>();
private final FMenuBar menuBar;
private final VPrompt prompt;
private final VLog log;
private final VStack stack;
@@ -48,7 +47,7 @@ public class MatchScreen extends FScreen {
private VPlayerPanel bottomPlayerPanel, topPlayerPanel;
public MatchScreen(Game game, LobbyPlayer localPlayer, List<VPlayerPanel> playerPanels0) {
super(false, null); //match screen has custom header
super(new FMenuBar());
scroller = add(new FieldScroller());
for (VPlayerPanel playerPanel : playerPanels0) {
@@ -77,7 +76,7 @@ public class MatchScreen extends FScreen {
stack = new VStack(game.getStack(), localPlayer);
devMenu = new VDevMenu();
menuBar = add(new FMenuBar());
FMenuBar menuBar = (FMenuBar)getHeader();
menuBar.addTab("Game", new VGameMenu());
menuBar.addTab("Players (" + playerPanels.size() + ")", new VPlayers());
menuBar.addTab("Log", log);
@@ -123,8 +122,6 @@ public class MatchScreen extends FScreen {
@Override
protected void doLayout(float startY, float width, float height) {
menuBar.setBounds(0, 0, width, menuBar.getPreferredHeight());
startY = menuBar.getHeight();
scroller.setBounds(0, startY, width, height - VPrompt.HEIGHT - startY);
prompt.setBounds(0, height - VPrompt.HEIGHT, width, VPrompt.HEIGHT);
}

View File

@@ -75,11 +75,11 @@ public class ViewWinLose extends FOverlay {
}
btnContinue.setText("Next Game");
btnContinue.setFontSize(22);
btnContinue.setFont(FSkinFont.get(22));
btnRestart.setText("Start New Match");
btnRestart.setFontSize(22);
btnRestart.setFont(btnContinue.getFont());
btnQuit.setText("Quit Match");
btnQuit.setFontSize(22);
btnQuit.setFont(btnContinue.getFont());
btnContinue.setEnabled(!game0.getMatch().isMatchOver());
lblLog = add(new FLabel.Builder().text("Game Log").align(HAlignment.CENTER).font(FSkinFont.get(18)).build());

View File

@@ -32,7 +32,7 @@ public class SettingsScreen extends FScreen {
private final FGroupList<Setting> lstSettings = add(new FGroupList<Setting>());
public SettingsScreen() {
super(true, "Settings");
super("Settings");
lstSettings.setListItemRenderer(new SettingRenderer());
lstSettings.addGroup("General Settings");
@@ -235,7 +235,7 @@ public class SettingsScreen extends FScreen {
private final String currentValue = FModel.getPreferences().getPref(pref);
private CustomSelectScreen() {
super(true, "Select " + label.substring(0, label.length() - 1));
super("Select " + label.substring(0, label.length() - 1));
lstOptions = add(new FList<String>(options));
lstOptions.setListItemRenderer(new FList.DefaultListItemRenderer<String>() {
@Override

View File

@@ -65,8 +65,11 @@ public class FButton extends FDisplayObject implements IButton {
text = text0;
}
public void setFontSize(int fontSize0) {
font = FSkinFont.get(fontSize0);
public FSkinFont getFont() {
return font;
}
public void setFont(FSkinFont font0) {
font = font0;
}
@Override