Latest UI layout reshuffling.

This commit is contained in:
Doublestrike
2011-12-02 13:38:00 +00:00
parent d83571a6bd
commit f1285945e7
2 changed files with 124 additions and 78 deletions

View File

@@ -54,8 +54,7 @@ import forge.properties.ForgePreferences;
import forge.view.toolbox.FPanel; import forge.view.toolbox.FPanel;
/** /**
* - Lays out battle, sidebar, user areas in locked % vals and repaints as * - Lays out containers and borders for resizeable layout.<br>
* necessary.<br>
* - Instantiates top-level controller for match UI.<br> * - Instantiates top-level controller for match UI.<br>
* - Has access methods for all child controllers<br> * - Has access methods for all child controllers<br>
* - Implements Display interface used in singleton pattern * - Implements Display interface used in singleton pattern
@@ -77,13 +76,14 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
private double delta; private double delta;
// Default layout parameters (all in percent!) // Default layout parameters (all in percent!)
private static final int BOUNDARY_THICKNESS_PX = 6; private double dockWpct = 0.15;
private double rightbarWpct = 0.16; private double dockHpct = 0.2;
private double pictureHpct = 0.5; private double tabberHpct = 0.55;
private double battleWpct = 0.68; private double battleWpct = 0.68;
private double battleHpct = 0.73; private double battleHpct = 0.73;
private double dockHpct = 0.2; private double pictureHpct = 0.5;
private double inputHpct = 0.2;
private static final int BOUNDARY_THICKNESS_PX = 6;
// Boundary rectangles for all components, and boundary panel objects. // Boundary rectangles for all components, and boundary panel objects.
private Rectangle pictureBounds, detailBounds, battleBounds, private Rectangle pictureBounds, detailBounds, battleBounds,
@@ -112,6 +112,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
this.setLayout(null); this.setLayout(null);
b = (int) Math.ceil(BOUNDARY_THICKNESS_PX / 2); b = (int) Math.ceil(BOUNDARY_THICKNESS_PX / 2);
// Declare and add containers and resizers for various regions in layout
pnlPicture = new RegionPanel(); pnlPicture = new RegionPanel();
pnlDetail = new RegionPanel(); pnlDetail = new RegionPanel();
pnlBattlefield = new RegionPanel(); pnlBattlefield = new RegionPanel();
@@ -121,10 +122,10 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
pnlTabber = new RegionPanel(); pnlTabber = new RegionPanel();
pnlB1 = new BoundaryPanel(true); pnlB1 = new BoundaryPanel(true);
pnlB2 = new BoundaryPanel(); pnlB2 = new BoundaryPanel(true);
pnlB3 = new BoundaryPanel(true); pnlB3 = new BoundaryPanel();
pnlB4 = new BoundaryPanel(); pnlB4 = new BoundaryPanel(true);
pnlB5 = new BoundaryPanel(true); pnlB5 = new BoundaryPanel();
pnlB6 = new BoundaryPanel(true); pnlB6 = new BoundaryPanel(true);
add(pnlPicture); add(pnlPicture);
@@ -142,6 +143,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
add(pnlB5); add(pnlB5);
add(pnlB6); add(pnlB6);
// Declare and add various view components
input = new ViewInput(); input = new ViewInput();
hand = new ViewHand(); hand = new ViewHand();
dock = new ViewDock(); dock = new ViewDock();
@@ -168,13 +170,19 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
* Panel resizing algorithms. Basically, find the change in % per * Panel resizing algorithms. Basically, find the change in % per
* drag event, then add that to an appropriate parameter. In some * drag event, then add that to an appropriate parameter. In some
* cases, also remove the delta from an appropriate parameter. * cases, also remove the delta from an appropriate parameter.
*
*/ */
// Formulas here SHOULD NOT BE VERY COMPLICATED at all. If they're
// complicated, you're doing it wrong. The complicated part should
// be in calculateBounds().
private void addDragListeners() { private void addDragListeners() {
pnlB1.addMouseMotionListener(new MouseMotionAdapter() { pnlB1.addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(final MouseEvent e) { public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h; delta = e.getY() / (double) h;
pictureHpct += delta; dockHpct += delta;
tabberHpct -= delta;
repaint(); repaint();
} }
}); });
@@ -182,14 +190,23 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
pnlB2.addMouseMotionListener(new MouseMotionAdapter() { pnlB2.addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(final MouseEvent e) { public void mouseDragged(final MouseEvent e) {
delta = e.getX() / (double) w; delta = e.getY() / (double) h;
rightbarWpct += delta; tabberHpct += delta;
battleWpct -= delta;
repaint(); repaint();
} }
}); });
pnlB3.addMouseMotionListener(new MouseMotionAdapter() { pnlB3.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getX() / (double) w;
battleWpct -= delta;
dockWpct += delta;
repaint();
}
});
pnlB4.addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(final MouseEvent e) { public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h; delta = e.getY() / (double) h;
@@ -198,7 +215,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
} }
}); });
pnlB4.addMouseMotionListener(new MouseMotionAdapter() { pnlB5.addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(final MouseEvent e) { public void mouseDragged(final MouseEvent e) {
delta = e.getX() / (double) w; delta = e.getX() / (double) w;
@@ -207,21 +224,11 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
} }
}); });
pnlB5.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h;
dockHpct += delta;
inputHpct -= delta;
repaint();
}
});
pnlB6.addMouseMotionListener(new MouseMotionAdapter() { pnlB6.addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(final MouseEvent e) { public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h; delta = e.getY() / (double) h;
inputHpct += delta; pictureHpct += delta;
repaint(); repaint();
} }
}); });
@@ -230,46 +237,37 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
/** /**
* Put together default layout; most values are dependent * Put together default layout; most values are dependent
* on sibling component dimensions. The whole layout can be * on sibling component dimensions. The whole layout can be
* defined from six parameters: * defined from six parameters.
*
* rightbarWpct = % width of the right sidebar<br>
* pictureHpct = % height of card art<br>
*
* battleWpct = % width of the battlefield<br>
* battleHpct = % height of the battlefield<br>
*
* dockHpct = % height of the dock<br>
* inputHpct = % height of the input<br>
* *
*/ */
private void calculateBounds() { private void calculateBounds() {
pictureBounds = new Rectangle( dockBounds = new Rectangle(
b, b, b, b,
(int) (w * rightbarWpct), (int) (h * pictureHpct - 2 * b)); (int) (dockWpct * w), (int) (dockHpct * h));
detailBounds = new Rectangle( tabberBounds = new Rectangle(
b, pictureBounds.height + 3 * b, dockBounds.x, dockBounds.height + 3 * b,
pictureBounds.width, h - pictureBounds.height - 4 * b); dockBounds.width, (int) (tabberHpct * h));
inputBounds = new Rectangle(
dockBounds.x, tabberBounds.y + tabberBounds.height + 2 * b,
dockBounds.width, h - tabberBounds.y - tabberBounds.height - 3 * b);
battleBounds = new Rectangle( battleBounds = new Rectangle(
pictureBounds.width + 3 * b, b, dockBounds.width + 3 * b, b,
(int) (w * battleWpct), (int) (h * battleHpct)); (int) (w * battleWpct), (int) (h * battleHpct));
handBounds = new Rectangle( handBounds = new Rectangle(
battleBounds.x, battleBounds.height + 3 * b, battleBounds.x, battleBounds.height + 3 * b,
battleBounds.width, h - battleBounds.height - 4 * b); battleBounds.width, h - battleBounds.height - 4 * b);
dockBounds = new Rectangle( pictureBounds = new Rectangle(
pictureBounds.width + battleBounds.width + 5 * b, b, battleBounds.x + battleBounds.width + 2 * b, b,
w - pictureBounds.width - battleBounds.width - 6 * b, (int) (h * dockHpct - 2 * b)); w - battleBounds.x - battleBounds.width - 3 * b, (int) (h * pictureHpct));
inputBounds = new Rectangle( detailBounds = new Rectangle(
dockBounds.x, dockBounds.height + 2 * b, pictureBounds.x, pictureBounds.height + 3 * b,
dockBounds.width, (int) (h * inputHpct - b)); pictureBounds.width, h - pictureBounds.height - 4 * b);
tabberBounds = new Rectangle(
dockBounds.x, inputBounds.y + inputBounds.height + 2 * b,
dockBounds.width, h - inputBounds.y - inputBounds.height - 3 * b);
// Apply bounds to regions. // Apply bounds to regions.
pnlPicture.setBounds(pictureBounds); pnlPicture.setBounds(pictureBounds);
@@ -282,28 +280,28 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
// Apply bounds to boundaries. // Apply bounds to boundaries.
pnlB1.setBounds(new Rectangle( pnlB1.setBounds(new Rectangle(
0, pictureBounds.height + b, b, dockBounds.height + b,
pictureBounds.width + b, 2 * b)); dockBounds.width, 2 * b));
pnlB2.setBounds(new Rectangle( pnlB2.setBounds(new Rectangle(
pictureBounds.width + b, 0, b, dockBounds.height + tabberBounds.height + 3 * b,
2 * b, h)); dockBounds.width, 2 * b));
pnlB3.setBounds(new Rectangle( pnlB3.setBounds(new Rectangle(
pictureBounds.width + 3 * b, battleBounds.height + b, dockBounds.width + b, b,
battleBounds.width, 2 * b)); 2 * b, h - 2 * b));
pnlB4.setBounds(new Rectangle( pnlB4.setBounds(new Rectangle(
dockBounds.x - 2 * b, 0, dockBounds.width + 3 * b, battleBounds.height + b,
2 * b, h)); battleBounds.width, 2 * b));
pnlB5.setBounds(new Rectangle( pnlB5.setBounds(new Rectangle(
dockBounds.x, dockBounds.height, battleBounds.width + dockBounds.width + 3 * b, b,
dockBounds.width, 2 * b)); 2 * b, h - 2 * b));
pnlB6.setBounds(new Rectangle( pnlB6.setBounds(new Rectangle(
dockBounds.x, tabberBounds.y - 2 * b, pictureBounds.x, pictureBounds.height + b,
dockBounds.width, 2 * b)); pictureBounds.width, 2 * b));
this.revalidate(); this.revalidate();
} // End calculateBounds() } // End calculateBounds()
@@ -334,7 +332,8 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
private class RegionPanel extends JPanel { private class RegionPanel extends JPanel {
public RegionPanel() { public RegionPanel() {
super(); super();
// For testing, comment this opaque setter. A border helps too. // For testing, comment this opaque setter, uncomment the border.
//setBorder(new LineBorder(Color.green, 1));
setOpaque(false); setOpaque(false);
setLayout(new MigLayout("insets 0, gap 0")); setLayout(new MigLayout("insets 0, gap 0"));
} }
@@ -754,7 +753,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
if (damage <= 0) { if (damage <= 0) {
return; return;
} }
new GuiMultipleBlockers(attacker, blockers, damage, this); new GuiMultipleBlockers(attacker, blockers, damage, this);
} }

View File

@@ -44,12 +44,23 @@ public class FVerticalTabPanel extends FPanel {
private final CardLayout cards; private final CardLayout cards;
private final JPanel pnlContent; private final JPanel pnlContent;
private final List<VTab> allVTabs; private final List<VTab> allVTabs;
private int w, h;
private final FSkin skin; private final FSkin skin;
private int active; private int active;
private final Color activeColor, inactiveColor, hoverColor; private final Color activeColor, inactiveColor, hoverColor;
private final Border inactiveBorder, hoverBorder; private final Border inactiveBorder, hoverBorder;
private boolean tabsOnRightSide;
/** Constructor, will automatically place tabs on left side.
*
* @param childPanels &emsp; JPanels to be placed in tabber
*/
public FVerticalTabPanel(final List<JPanel> childPanels) {
this(childPanels, false);
}
/** /**
* Assembles vertical tab panel from list of child panels. Tooltip on tab is * Assembles vertical tab panel from list of child panels. Tooltip on tab is
* same as tooltip on child panel. Title of tab is same as name of child * same as tooltip on child panel. Title of tab is same as name of child
@@ -57,10 +68,12 @@ public class FVerticalTabPanel extends FPanel {
* *
* @param childPanels * @param childPanels
* &emsp; JPanels to be placed in tabber * &emsp; JPanels to be placed in tabber
* @param b &emsp; boolean, true if tabs are on right side, false for left side.
*/ */
public FVerticalTabPanel(final List<JPanel> childPanels) { public FVerticalTabPanel(final List<JPanel> childPanels, boolean b) {
// General inits and skin settings // General inits and skin settings
super(); super();
tabsOnRightSide = b;
this.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); this.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
this.setOpaque(false); this.setOpaque(false);
final int size = childPanels.size(); final int size = childPanels.size();
@@ -81,14 +94,26 @@ public class FVerticalTabPanel extends FPanel {
this.pnlContent = new JPanel(); this.pnlContent = new JPanel();
this.pnlContent.setOpaque(false); this.pnlContent.setOpaque(false);
this.pnlContent.setLayout(this.cards); this.pnlContent.setLayout(this.cards);
this.pnlContent.setBorder(new MatteBorder(0, 0, 0, 1, this.skin.getClrBorders()));
this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!"); // If tabs are on the left side, content panel is added
// immediately to define grid.
if (tabsOnRightSide) {
this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!");
this.pnlContent.setBorder(new MatteBorder(0, 0, 0, 1, this.skin.getClrBorders()));
}
// Add top spacer in any case.
final JPanel topSpacer = new JPanel(); final JPanel topSpacer = new JPanel();
topSpacer.setOpaque(false); topSpacer.setOpaque(false);
this.add(topSpacer, "w " + pctTabW + "%!, h " + pctInsetH + "%!"); this.add(topSpacer, "w " + pctTabW + "%!, h " + pctInsetH + "%!");
// If tabs are on right side, content panel
// must be added after spacer, which then defines the grid.
if (!tabsOnRightSide) {
this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!");
this.pnlContent.setBorder(new MatteBorder(0, 1, 0, 0, this.skin.getClrBorders()));
}
// Add all tabs // Add all tabs
VTab tab; VTab tab;
this.allVTabs = new ArrayList<VTab>(); this.allVTabs = new ArrayList<VTab>();
@@ -151,9 +176,14 @@ public class FVerticalTabPanel extends FPanel {
public class VTab extends JPanel { public class VTab extends JPanel {
private String msg; private String msg;
private int id; private int id;
private int w;
// ID is used to retrieve this tab from the list of allVTabs. // ID is used to retrieve this tab from the list of allVTabs.
/**
* Creates the actual clickable tab.
*
* @param txt &emsp; String text in tab
* @param i &emsp; int index
*/
VTab(final String txt, final int i) { VTab(final String txt, final int i) {
super(); super();
this.setLayout(new MigLayout("insets 0, gap 0")); this.setLayout(new MigLayout("insets 0, gap 0"));
@@ -192,23 +222,39 @@ public class FVerticalTabPanel extends FPanel {
@Override @Override
protected void paintComponent(final Graphics g) { protected void paintComponent(final Graphics g) {
super.paintComponent(g); super.paintComponent(g);
this.w = this.getWidth(); w = this.getWidth();
h = this.getHeight();
// Careful with this font scale factor; the vertical tabs will be // Careful with this font scale factor; the vertical tabs will be
// unreadable // unreadable
// if small window, too big if large window. // if small window, too big if large window.
g.setFont(FVerticalTabPanel.this.skin.getFont1().deriveFont(Font.PLAIN, (int) (this.w * 0.68))); g.setFont(FVerticalTabPanel.this.skin.getFont1().deriveFont(Font.PLAIN, (int) (h * 0.2)));
// Rotate, draw string, rotate back (to allow hover border to be // Rotate, draw string, rotate back (to allow hover border to be
// painted properly) // painted properly)
final Graphics2D g2d = (Graphics2D) g; final Graphics2D g2d = (Graphics2D) g;
final AffineTransform at = g2d.getTransform(); final AffineTransform at = g2d.getTransform();
at.rotate(Math.toRadians(90), 0, 0);
g2d.setTransform(at);
g2d.setColor(AllZone.getSkin().getClrText());
g2d.drawString(this.msg, 5, -4);
at.rotate(Math.toRadians(-90), 0, 0); if (tabsOnRightSide) {
at.rotate(Math.toRadians(90), 0, 0);
g2d.setTransform(at);
g2d.setColor(AllZone.getSkin().getClrText());
g2d.drawString(this.msg, 5, -4);
}
else {
at.rotate(Math.toRadians(-90), 0, 0);
g2d.setTransform(at);
g2d.setColor(AllZone.getSkin().getClrText());
g2d.drawString(this.msg, 5 - h, w - 4);
}
if (tabsOnRightSide) {
at.rotate(Math.toRadians(-90), 0, 0);
}
else {
at.rotate(Math.toRadians(90), 0, 0);
}
g2d.setTransform(at); g2d.setTransform(at);
} }
@@ -218,6 +264,7 @@ public class FVerticalTabPanel extends FPanel {
} }
} }
/** @return List<VTab> */
public List<VTab> getAllVTabs() { public List<VTab> getAllVTabs() {
return allVTabs; return allVTabs;
} }