mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Support laying out top half of bazaar pages
This commit is contained in:
@@ -49,12 +49,27 @@ public class TabPageScreen<T extends TabPageScreen<T>> extends FScreen {
|
||||
selectedPage = tabPage0;
|
||||
if (selectedPage != null) {
|
||||
selectedPage.setVisible(true);
|
||||
if (tabHeader.isScrollable) { //scroll tab into view if needed, leaving half of the previous/next tab visible if possible
|
||||
tabHeader.scroller.scrollIntoView(selectedPage.tab, selectedPage.tab.getWidth() / 2);
|
||||
if (Forge.getCurrentScreen() == this) {
|
||||
scrollSelectedTabIntoView();
|
||||
selectedPage.onActivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
if (selectedPage != null) {
|
||||
scrollSelectedTabIntoView(); //ensure selected tab in view when screen activated
|
||||
selectedPage.onActivate();
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollSelectedTabIntoView() {
|
||||
if (tabHeader.isScrollable) { //scroll tab into view if needed, leaving half of the previous/next tab visible if possible
|
||||
tabHeader.scroller.scrollIntoView(selectedPage.tab, selectedPage.tab.getWidth() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float startY, float width, float height) {
|
||||
height -= startY;
|
||||
@@ -176,6 +191,9 @@ public class TabPageScreen<T extends TabPageScreen<T>> extends FScreen {
|
||||
return icon;
|
||||
}
|
||||
|
||||
protected void onActivate() {
|
||||
}
|
||||
|
||||
protected class Tab extends FDisplayObject {
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ViewWinLose extends FOverlay {
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
if (txtLog.getMaxScrollTop() > 0) {
|
||||
FMagnifyView.show(txtLog, txtLog.getText(), FTextArea.FORE_COLOR, ViewWinLose.this.getBackColor(), txtLog.getFont(), true);
|
||||
FMagnifyView.show(txtLog, txtLog.getText(), txtLog.getTextColor(), ViewWinLose.this.getBackColor(), txtLog.getFont(), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.assets.FImage;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.model.FModel;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.bazaar.IQuestBazaarItem;
|
||||
@@ -19,6 +20,7 @@ import forge.toolbox.FDisplayObject;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FTextArea;
|
||||
import forge.util.Utils;
|
||||
|
||||
public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
public QuestBazaarScreen() {
|
||||
@@ -38,11 +40,15 @@ public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
}
|
||||
|
||||
private static class BazaarPage extends TabPage<QuestBazaarScreen> {
|
||||
private static final float PADDING = Utils.scaleMax(5);
|
||||
|
||||
private final QuestStallDefinition stallDef;
|
||||
private final FLabel lblStallName = add(new FLabel.Builder().text("").align(HAlignment.CENTER).build());
|
||||
private final FLabel lblEmpty = add(new FLabel.Builder().text("The merchant does not have anything useful for sale.")
|
||||
private final FLabel lblEmpty = add(new FLabel.Builder().font(FSkinFont.get(12))
|
||||
.text("The merchant does not have anything useful for sale.")
|
||||
.align(HAlignment.CENTER).build());
|
||||
private final FLabel lblStats = add(new FLabel.Builder().align(HAlignment.CENTER).font(FSkinFont.get(12)).build());
|
||||
private final FLabel lblCredits = add(new FLabel.Builder().font(FSkinFont.get(15)).icon(FSkinImage.QUEST_COINSTACK).iconScaleFactor(1f).build());
|
||||
private final FLabel lblLife = add(new FLabel.Builder().font(lblCredits.getFont()).icon(FSkinImage.QUEST_HEART).iconScaleFactor(1f).align(HAlignment.RIGHT).build());
|
||||
private final FTextArea lblFluff = add(new FTextArea());
|
||||
private final FScrollPane scroller = add(new FScrollPane() {
|
||||
@Override
|
||||
@@ -60,8 +66,14 @@ public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
super(stallDef0.getName(), (FImage)stallDef0.getIcon());
|
||||
stallDef = stallDef0;
|
||||
|
||||
lblFluff.setFont(FSkinFont.get(15));
|
||||
lblFluff.setFont(FSkinFont.get(12));
|
||||
lblFluff.setAlignment(HAlignment.CENTER);
|
||||
lblFluff.setTextColor(FLabel.INLINE_LABEL_COLOR); //make fluff text a little lighter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivate() {
|
||||
update();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
@@ -73,7 +85,8 @@ public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
}
|
||||
|
||||
final QuestAssets qS = qData.getAssets();
|
||||
lblStats.setText("Credits: " + qS.getCredits() + " Life: " + qS.getLife(qData.getMode()));
|
||||
lblCredits.setText("Credits: " + qS.getCredits());
|
||||
lblLife.setText("Life: " + qS.getLife(qData.getMode()));
|
||||
|
||||
final List<IQuestBazaarItem> items = qData.getBazaar().getItems(qData, stallDef.getName());
|
||||
|
||||
@@ -85,6 +98,7 @@ public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
lblEmpty.setVisible(true);
|
||||
}
|
||||
else {
|
||||
lblEmpty.setVisible(false);
|
||||
for (IQuestBazaarItem item : items) {
|
||||
scroller.add(new BazaarItemDisplay(item));
|
||||
}
|
||||
@@ -94,6 +108,23 @@ public class QuestBazaarScreen extends TabPageScreen<QuestBazaarScreen> {
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
float x = PADDING;
|
||||
float y = PADDING;
|
||||
float w = width - 2 * PADDING;
|
||||
|
||||
lblStallName.setBounds(x, y, w, lblStallName.getAutoSizeBounds().height);
|
||||
y += lblStallName.getHeight() + PADDING;
|
||||
lblFluff.setBounds(x, y, w, lblFluff.getPreferredHeight(w));
|
||||
y += lblFluff.getHeight() + PADDING;
|
||||
lblCredits.setBounds(x, y, w / 2, lblCredits.getAutoSizeBounds().height);
|
||||
lblLife.setBounds(x + w / 2, y, w / 2, lblCredits.getHeight());
|
||||
y += lblCredits.getHeight() + PADDING;
|
||||
if (lblEmpty.isVisible()) {
|
||||
lblEmpty.setBounds(x, y, w, lblEmpty.getAutoSizeBounds().height);
|
||||
}
|
||||
else {
|
||||
scroller.setBounds(x, y, w, height - PADDING - y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,14 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.assets.TextRenderer;
|
||||
|
||||
public class FTextArea extends FScrollPane {
|
||||
public static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
|
||||
private String text;
|
||||
private FSkinFont font;
|
||||
private HAlignment alignment;
|
||||
private Vector2 insets;
|
||||
private FSkinColor textColor;
|
||||
private final TextRenderer renderer = new TextRenderer(true);
|
||||
|
||||
public FTextArea() {
|
||||
@@ -26,6 +24,7 @@ public class FTextArea extends FScrollPane {
|
||||
font = FSkinFont.get(14);
|
||||
alignment = HAlignment.LEFT;
|
||||
insets = new Vector2(1, 1); //prevent text getting cut off by clip
|
||||
textColor = FLabel.DEFAULT_TEXT_COLOR;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
@@ -51,6 +50,13 @@ public class FTextArea extends FScrollPane {
|
||||
revalidate();
|
||||
}
|
||||
|
||||
public FSkinColor getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
public void setTextColor(FSkinColor textColor0) {
|
||||
textColor = textColor0;
|
||||
}
|
||||
|
||||
public float getPreferredHeight(float width) {
|
||||
return renderer.getWrappedBounds(text, font, width - 2 * insets.x).height
|
||||
+ font.getLineHeight() - font.getCapHeight() //need to account for difference in line and cap height
|
||||
@@ -64,6 +70,6 @@ public class FTextArea extends FScrollPane {
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
renderer.drawText(g, text, font, FORE_COLOR, insets.x - getScrollLeft(), insets.y - getScrollTop(), getScrollWidth() - 2 * insets.x, getScrollHeight() - 2 * insets.y, 0, getHeight(), true, alignment, false);
|
||||
renderer.drawText(g, text, font, textColor, insets.x - getScrollLeft(), insets.y - getScrollTop(), getScrollWidth() - 2 * insets.x, getScrollHeight() - 2 * insets.y, 0, getHeight(), true, alignment, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user