Get downloaders working from mobile game

This commit is contained in:
drdev
2014-05-29 03:14:39 +00:00
parent 7021873675
commit e3c98c3782
5 changed files with 117 additions and 13 deletions

View File

@@ -75,7 +75,7 @@ public class GuiDownloader extends DefaultBoundedRangeModel {
btnClose.setBorder(new FSkin.LineSkinBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT)));
btnStart.setFont(FSkin.getFont(18));
btnStart.setVisible(false);
btnStart.setEnabled(false);
progressBar.reset();
progressBar.setString("Scanning for existing items...");

View File

@@ -1,16 +1,117 @@
package forge.screens.settings;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.Forge.Graphics;
import forge.assets.FSkinColor;
import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
import forge.download.GuiDownloadPicturesLQ;
import forge.download.GuiDownloadPrices;
import forge.download.GuiDownloadQuestImages;
import forge.download.GuiDownloadService;
import forge.download.GuiDownloadSetPicturesLQ;
import forge.screens.TabPageScreen.TabPage;
import forge.toolbox.FGroupList;
import forge.toolbox.FList;
public class FilesPage extends TabPage {
private final FGroupList<FilesItem> lstItems = add(new FGroupList<FilesItem>());
protected FilesPage() {
super("Files", FSkinImage.OPEN);
lstItems.setListItemRenderer(new FilesItemRenderer());
lstItems.addGroup("Content Downloaders");
//lstItems.addGroup("Data Import");
//content downloaders
lstItems.addItem(new ContentDownloader("Download LQ Card Pictures",
"Download default card picture for each card.") {
@Override
protected GuiDownloadService createService() {
return new GuiDownloadPicturesLQ();
}
}, 0);
lstItems.addItem(new ContentDownloader("Download LQ Set Pictures",
"Download all pictures of each card (one for each set the card appeared in)") {
@Override
protected GuiDownloadService createService() {
return new GuiDownloadSetPicturesLQ();
}
}, 0);
lstItems.addItem(new ContentDownloader("Download Quest Images",
"Download tokens and icons used in Quest mode.") {
@Override
protected GuiDownloadService createService() {
return new GuiDownloadQuestImages();
}
}, 0);
lstItems.addItem(new ContentDownloader("Download Card Prices",
"Download up-to-date price list for in-game card shops.") {
@Override
protected GuiDownloadService createService() {
return new GuiDownloadPrices();
}
}, 0);
}
@Override
protected void doLayout(float width, float height) {
lstItems.setBounds(0, 0, width, height);
}
private abstract class FilesItem {
protected String label;
protected String description;
public FilesItem(String label0, String description0) {
label = label0;
description = description0;
}
public abstract void select();
}
private static class FilesItemRenderer extends FList.ListItemRenderer<FilesItem> {
@Override
public float getItemHeight() {
return SettingsScreen.SETTING_HEIGHT;
}
@Override
public boolean tap(FilesItem value, float x, float y, int count) {
value.select();
return true;
}
@Override
public void drawValue(Graphics g, FilesItem value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items
x += offset;
y += offset;
w -= 2 * offset;
h -= 2 * offset;
float totalHeight = h;
h = font.getMultiLineBounds(value.label).height + SettingsScreen.SETTING_PADDING;
g.drawText(value.label, font, color, x, y, w, h, false, HAlignment.LEFT, false);
h += SettingsScreen.SETTING_PADDING;
g.drawText(value.description, SettingsScreen.DESC_FONT, SettingsScreen.DESC_COLOR, x, y + h, w, totalHeight - h + w * SettingsScreen.INSETS_FACTOR, true, HAlignment.LEFT, false);
}
}
private abstract class ContentDownloader extends FilesItem {
public ContentDownloader(String label0, String description0) {
super(label0, description0);
}
@Override
public void select() {
new GuiDownloader(createService());
}
protected abstract GuiDownloadService createService();
}
}

View File

@@ -55,6 +55,8 @@ public class GuiDownloader extends FDialog {
txtAddress.setGhostText("Proxy Address");
txtPort.setGhostText("Proxy Port");
txtAddress.setEnabled(false);
txtPort.setEnabled(false);
RadioButtonGroup group = new RadioButtonGroup();
radProxyNone.setGroup(group);
@@ -67,7 +69,7 @@ public class GuiDownloader extends FDialog {
radProxyNone.setSelected(true);
btnStart.setFont(FSkinFont.get(18));
btnStart.setVisible(false);
btnStart.setEnabled(false);
btnCancel.setFont(btnStart.getFont());
btnCancel.setCommand(cmdClose);
@@ -102,13 +104,13 @@ public class GuiDownloader extends FDialog {
float x = padding;
float y = padding;
float w = width - 2 * padding;
float radioButtonWidth = (w - 2 * padding) / 3;
float radioButtonHeight = radProxyNone.getHeight();
float radioButtonWidth = w / 3;
float radioButtonHeight = radProxyNone.getAutoSizeBounds().height;
radProxyNone.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x += radioButtonWidth + padding;
x += radioButtonWidth;
radProxyHTTP.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x += radioButtonWidth + padding;
x += radioButtonWidth;
radProxySocks.setBounds(x, y, radioButtonWidth, radioButtonHeight);
x = padding;
@@ -116,8 +118,8 @@ public class GuiDownloader extends FDialog {
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 += txtPort.getHeight() + padding * 2;
progressBar.setBounds(x, y, w, txtPort.getHeight() * 1.5f);
y += progressBar.getHeight() + padding * 2;
float buttonWidth = (w - padding) / 2;
@@ -125,6 +127,6 @@ public class GuiDownloader extends FDialog {
btnStart.setBounds(x, y, buttonWidth, buttonHeight);
x += w - buttonWidth;
btnCancel.setBounds(x, y, buttonWidth, buttonHeight);
return y + buttonWidth + padding;
return y + buttonHeight + padding;
}
}

View File

@@ -9,6 +9,7 @@ import forge.Forge.Graphics;
import forge.assets.FImage;
import forge.assets.FSkinColor;
import forge.assets.FSkinColor.Colors;
import forge.util.Utils;
public class FRadioButton extends FLabel {
private static final FSkinColor INNER_CIRCLE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
@@ -72,9 +73,9 @@ public class FRadioButton extends FLabel {
@Override
public void draw(Graphics g, float x, float y, float w, float h) {
float radius = h / 3;
x += w / 2;
x += w - radius;
y += h / 2;
g.drawCircle(1, OUTER_CIRCLE_COLOR, x, y, radius);
g.drawCircle(Utils.scaleMin(1), OUTER_CIRCLE_COLOR, x, y, radius);
if (isSelected()) {
g.fillCircle(INNER_CIRCLE_COLOR, x, y, radius / 2);
}

View File

@@ -118,7 +118,7 @@ public abstract class GuiDownloadService implements Runnable {
//for(Entry<String, String> kv : cards.entrySet()) System.out.printf("Will get %s from %s%n", kv.getKey(), kv.getValue());
btnStart.setCommand(cmdStartDownload);
}
btnStart.setVisible(true);
btnStart.setEnabled(true);
FThreads.invokeInEdtLater(new Runnable() {
@Override