- Removing quite a lot of redundant code from DefaultResolutionProfile now that LHS of GamePanel uses a layout manager instead of absolute positioning.

master
Lodici 2013-10-30 19:04:49 +00:00
parent c017f09d26
commit 8234e77854
3 changed files with 80 additions and 141 deletions

View File

@ -17,7 +17,6 @@ import magic.ui.viewer.HandGraveyardExileViewer;
import magic.ui.viewer.ImageBattlefieldViewer;
import magic.ui.viewer.ImageCombatViewer;
import magic.ui.viewer.ImageHandGraveyardExileViewer;
import magic.ui.viewer.ImageViewer;
import magic.ui.viewer.LogBookViewer;
import magic.ui.viewer.PlayerViewer;
import magic.ui.viewer.StackCombatViewer;
@ -28,13 +27,11 @@ import magic.ui.widget.ZoneBackgroundLabel;
import net.miginfocom.swing.MigLayout;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.KeyStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
@ -78,8 +75,6 @@ public final class GamePanel extends JPanel {
private final ImageBattlefieldViewer imagePlayerPermanentViewer;
private final ImageBattlefieldViewer imageOpponentPermanentViewer;
private final ImageCombatViewer imageCombatViewer;
private final ImageViewer imageViewer;
private final JPanel lhsPanel, rhsPanel;
public GamePanel(
@ -111,7 +106,6 @@ public final class GamePanel extends JPanel {
lhsPanel.setOpaque(false);
rhsPanel = new JPanel(null);
rhsPanel.setOpaque(false);
rhsPanel.setBorder(BorderFactory.createLineBorder(Color.CYAN, 1));
logBookViewer=new LogBookViewer(game.getLogBook());
logBookViewer.setVisible(false);
@ -180,7 +174,6 @@ public final class GamePanel extends JPanel {
imagePlayerPermanentViewer=new ImageBattlefieldViewer(viewerInfo,controller,false);
imageOpponentPermanentViewer=new ImageBattlefieldViewer(viewerInfo,controller,true);
imageCombatViewer=new ImageCombatViewer(viewerInfo,controller);
imageViewer=new ImageViewer();
final TitleBar stackTitleBar = new TitleBar("Stack");
stackTitleBar.setIcon(theme.getIcon(Theme.ICON_SMALL_STACK));
@ -360,7 +353,6 @@ public final class GamePanel extends JPanel {
rhsPanel.remove(imagePlayerPermanentViewer);
rhsPanel.remove(imageOpponentPermanentViewer);
rhsPanel.remove(imageCombatViewer);
rhsPanel.remove(imageViewer);
rhsPanel.add(cardViewer);
rhsPanel.add(handGraveyardViewer);
rhsPanel.add(stackCombatViewer);
@ -379,10 +371,8 @@ public final class GamePanel extends JPanel {
rhsPanel.add(imagePlayerPermanentViewer);
rhsPanel.add(imageOpponentPermanentViewer);
rhsPanel.add(imageCombatViewer);
rhsPanel.add(imageViewer);
}
resizeComponents();
//update();
revalidate();
repaint();
}
@ -407,7 +397,6 @@ public final class GamePanel extends JPanel {
logBookViewer.setBounds(result.getBoundary(ResolutionProfileType.GameLogBookViewer));
if (isTextView()) {
cardViewer.setBounds(result.getBoundary(ResolutionProfileType.GameCardViewer));
stackCombatViewer.setBounds(result.getBoundary(ResolutionProfileType.GameStackCombatViewer));
handGraveyardViewer.setBounds(result.getBoundary(ResolutionProfileType.GameHandGraveyardViewer));
playerPermanentViewer.setBounds(result.getBoundary(ResolutionProfileType.GamePlayerPermanentViewer));
@ -418,7 +407,6 @@ public final class GamePanel extends JPanel {
imagePlayerPermanentViewer.setBounds(result.getBoundary(ResolutionProfileType.GameImagePlayerPermanentViewer));
imageOpponentPermanentViewer.setBounds(result.getBoundary(ResolutionProfileType.GameImageOpponentPermanentViewer));
imageCombatViewer.setBounds(result.getBoundary(ResolutionProfileType.GameImageCombatViewer));
imageViewer.setBounds(result.getBoundary(ResolutionProfileType.GameImageViewer));
}
setThisLayout(result);
@ -458,7 +446,6 @@ public final class GamePanel extends JPanel {
buttonPanel.add(textViewButton, "w " + r.width + "px!, h " + r.height + "px!");
lhsPanel.add(buttonPanel, "w 100%");
r = result.getBoundary(ResolutionProfileType.GameImageStackViewer);
lhsPanel.add(imageStackViewer, "w 100%, pushy, bottom");
r = result.getBoundary(ResolutionProfileType.GameDuelViewer);
@ -472,9 +459,6 @@ public final class GamePanel extends JPanel {
// RHS
add(rhsPanel, "w 100%, h 100%");
// lhsPanel.validate();
// lhsPanel.repaint();
}
}

View File

@ -9,13 +9,6 @@ import java.awt.Rectangle;
public class DefaultResolutionProfile implements ResolutionProfile {
private static final int PLAYERS_VIEWER_WIDTH=134;
private static final int DECK_VIEWER_WIDTH=350;
private static final int DUEL_VIEWER_WIDTH=270;
private static final int DUEL_VIEWER_HEIGHT=130;
private static final int DECK_STATISTICS_VIEWER_HEIGHT=200;
private static final int DECK_STRENGTH_VIEWER_HEIGHT=160;
private static final int PLAY_BUTTON_HEIGHT=50;
public static final int CARD_VIEWER_WIDTH=CardImagesProvider.CARD_WIDTH;
public static final int CARD_VIEWER_HEIGHT=CardImagesProvider.CARD_HEIGHT+20;
private static final int PLAYER_VIEWER_WIDTH=300;
@ -25,20 +18,20 @@ public class DefaultResolutionProfile implements ResolutionProfile {
private static final int MIN_HAND_VIEWER_WIDTH=250;
private static final int IMAGE_HAND_VIEWER_HEIGHT=145;
private static final int MAX_LOGBOOK_VIEWER_WIDTH=1000;
private static final int IMAGE_VIEWER_WIDTH=PLAYER_VIEWER_WIDTH;
private static final int IMAGE_VIEWER_HEIGHT=PLAYER_VIEWER_WIDTH;
private static final int BUTTON_SIZE=30;
private static final int BUTTON_Y_SPACING=10;
private static final Theme theme = ThemeFactory.getInstance().getCurrentTheme();
private static Dimension containerSize;
private static final int LHS_CONTENT_WIDTH = 300;
private static final int OUTER_MARGIN = theme.getValue(Theme.VALUE_SPACING);
@Override
public ResolutionProfileResult calculate(final Dimension size) {
containerSize = size;
final int offset=theme.getValue(Theme.VALUE_GAME_OFFSET);
final ResolutionProfileResult result=new ResolutionProfileResult();
int spacing=theme.getValue(Theme.VALUE_SPACING);
@ -50,118 +43,87 @@ public class DefaultResolutionProfile implements ResolutionProfile {
}
}
//
// GamePanel Layout
//
int x = spacing;
int y = spacing;
int playerHeight = PLAYER_VIEWER_HEIGHT;
int cardHeight = size.height - GAME_VIEWER_HEIGHT - (spacing * 4) - BUTTON_Y_SPACING;
final boolean small = (cardHeight - playerHeight * 2) < CARD_VIEWER_HEIGHT;
if (small) {
playerHeight = PLAYER_VIEWER_HEIGHT_SMALL;
}
cardHeight -= playerHeight * 2;
result.setFlag(ResolutionProfileType.GamePlayerViewerSmall, small);
//
// LHS - Uses MigLayout so do not need to track position.
//
setLhsBounds(result);
// Duel
final int maxHeight=size.height-spacing*2;
int x=spacing;
result.setBoundary(ResolutionProfileType.DuelPlayersViewer,
new Rectangle(x,spacing,PLAYERS_VIEWER_WIDTH,maxHeight - PLAY_BUTTON_HEIGHT - spacing));
int y = size.height;
y -= spacing + PLAY_BUTTON_HEIGHT;
result.setBoundary(ResolutionProfileType.DuelNewButton,
new Rectangle(x,y,PLAYERS_VIEWER_WIDTH,PLAY_BUTTON_HEIGHT));
result.setBoundary(
ResolutionProfileType.GameOpponentViewer,
new Rectangle(-1, -1, PLAYER_VIEWER_WIDTH, playerHeight));
x+=PLAYERS_VIEWER_WIDTH+spacing;
final int deckWidth=Math.min(
DECK_VIEWER_WIDTH,
size.width-spacing*5-PLAYERS_VIEWER_WIDTH-CARD_VIEWER_WIDTH-DUEL_VIEWER_WIDTH);
result.setBoundary(ResolutionProfileType.DuelDeckViewers,
new Rectangle(x,spacing,deckWidth,maxHeight - PLAY_BUTTON_HEIGHT - spacing));
y = size.height;
y -= spacing + PLAY_BUTTON_HEIGHT;
result.setBoundary(ResolutionProfileType.DuelPlayButton,
new Rectangle(x,y,deckWidth,PLAY_BUTTON_HEIGHT));
result.setBoundary(
ResolutionProfileType.GameLogBookButton,
new Rectangle(-1, -1, BUTTON_SIZE, BUTTON_SIZE));
result.setBoundary(
ResolutionProfileType.TextViewButton,
new Rectangle(-1, -1, BUTTON_SIZE, BUTTON_SIZE));
x+=deckWidth+spacing;
result.setBoundary(ResolutionProfileType.DuelCardViewer,
new Rectangle(x,spacing,CARD_VIEWER_WIDTH,CARD_VIEWER_HEIGHT));
final int logWidth = Math.min(MAX_LOGBOOK_VIEWER_WIDTH, size.width - (spacing * 3) - BUTTON_SIZE);
result.setBoundary(
ResolutionProfileType.GameLogBookViewer,
new Rectangle(x + BUTTON_SIZE + 6, spacing, logWidth, size.height - spacing * 2));
x=size.width-spacing-DUEL_VIEWER_WIDTH;
y=spacing;
result.setBoundary(ResolutionProfileType.DuelDeckStatisticsViewer,
new Rectangle(x,y,DUEL_VIEWER_WIDTH,DECK_STATISTICS_VIEWER_HEIGHT));
y+=DECK_STATISTICS_VIEWER_HEIGHT+spacing;
result.setBoundary(ResolutionProfileType.DuelDeckStrengthViewer,
new Rectangle(x,y,DUEL_VIEWER_WIDTH,DECK_STRENGTH_VIEWER_HEIGHT));
y+=DECK_STRENGTH_VIEWER_HEIGHT+spacing;
result.setBoundary(ResolutionProfileType.DuelDifficultyViewer,
new Rectangle(x,y,DUEL_VIEWER_WIDTH,DUEL_VIEWER_HEIGHT));
result.setBoundary(
ResolutionProfileType.GameImageStackViewer,
new Rectangle(-1, -1, PLAYER_VIEWER_WIDTH, cardHeight - BUTTON_Y_SPACING - BUTTON_SIZE));
// Game
x=spacing;
y=spacing;
int playerHeight=PLAYER_VIEWER_HEIGHT;
int cardHeight=size.height-GAME_VIEWER_HEIGHT-spacing*4-BUTTON_Y_SPACING;
final boolean small=cardHeight-playerHeight*2<CARD_VIEWER_HEIGHT;
if (small) {
playerHeight=PLAYER_VIEWER_HEIGHT_SMALL;
}
cardHeight-=playerHeight*2;
result.setBoundary(
ResolutionProfileType.GameDuelViewer,
new Rectangle(-1, -1, PLAYER_VIEWER_WIDTH, GAME_VIEWER_HEIGHT));
result.setFlag(ResolutionProfileType.GamePlayerViewerSmall,small);
result.setBoundary(
ResolutionProfileType.GamePlayerViewer,
new Rectangle(-1 ,-1, PLAYER_VIEWER_WIDTH, playerHeight));
//opponent viewer
result.setBoundary(ResolutionProfileType.GameOpponentViewer,
new Rectangle(x,y,PLAYER_VIEWER_WIDTH,playerHeight));
y+=playerHeight+spacing;
//log book, text view button and log book viewer
//y-=BUTTON_SIZE+BUTTON_Y_SPACING;
result.setBoundary(ResolutionProfileType.GameLogBookButton,
new Rectangle(x,y,BUTTON_SIZE,BUTTON_SIZE));
result.setBoundary(ResolutionProfileType.TextViewButton,
new Rectangle(x+PLAYER_VIEWER_WIDTH-BUTTON_SIZE,y,BUTTON_SIZE,BUTTON_SIZE));
final int logWidth=Math.min(MAX_LOGBOOK_VIEWER_WIDTH,size.width-spacing*3-BUTTON_SIZE);
result.setBoundary(ResolutionProfileType.GameLogBookViewer,
new Rectangle(x+BUTTON_SIZE+6,spacing,logWidth,size.height-spacing*2));
y += BUTTON_SIZE+BUTTON_Y_SPACING;
//
// RHS - this still uses absolute positioning (null layout).
//
//image viewer, image stack viewer
result.setBoundary(ResolutionProfileType.GameImageViewer,
new Rectangle(x,y,IMAGE_VIEWER_WIDTH,IMAGE_VIEWER_HEIGHT));
result.setBoundary(ResolutionProfileType.GameImageStackViewer,
new Rectangle(x,y,PLAYER_VIEWER_WIDTH,cardHeight-BUTTON_Y_SPACING-BUTTON_SIZE));
//y+=(cardHeight-CARD_VIEWER_HEIGHT)/2;
// this is the gap between the edge of the RHS panel and its content.
final int offset = theme.getValue(Theme.VALUE_GAME_OFFSET);
x = offset;
//card viewer
result.setBoundary(ResolutionProfileType.GameCardViewer,
new Rectangle(x+(PLAYER_VIEWER_WIDTH-CARD_VIEWER_WIDTH)/2,y,CARD_VIEWER_WIDTH,CARD_VIEWER_HEIGHT));
y+=CARD_VIEWER_HEIGHT+spacing;
//game player viewer
y=size.height-spacing-playerHeight;
result.setBoundary(ResolutionProfileType.GamePlayerViewer,
new Rectangle(x,y,PLAYER_VIEWER_WIDTH,playerHeight));
// duel viewer
y-=GAME_VIEWER_HEIGHT+spacing;
result.setBoundary(ResolutionProfileType.GameDuelViewer,
new Rectangle(x,y,PLAYER_VIEWER_WIDTH,GAME_VIEWER_HEIGHT));
x+=PLAYER_VIEWER_WIDTH+spacing+offset;
int rhsX = x - PLAYER_VIEWER_WIDTH - spacing - offset + 2;
// TextMode adjustments
int width2=(size.width-PLAYER_VIEWER_WIDTH-spacing*5-offset)/3;
if (width2<MIN_HAND_VIEWER_WIDTH) {
width2=(size.width-PLAYER_VIEWER_WIDTH-spacing*4-offset)/2;
final int height2=(size.height-spacing*3)/2;
final int x2=rhsX+width2+spacing;
final int x2=x+width2+spacing;
y=spacing;
result.setBoundary(ResolutionProfileType.GameOpponentPermanentViewer,
new Rectangle(x2,y,width2,height2));
result.setBoundary(
ResolutionProfileType.GameOpponentPermanentViewer,
new Rectangle(x2, y, width2, height2));
y+=height2+spacing;
result.setBoundary(ResolutionProfileType.GamePlayerPermanentViewer,
new Rectangle(x2,y,width2,height2));
result.setBoundary(
ResolutionProfileType.GamePlayerPermanentViewer,
new Rectangle(x2, y, width2, height2));
} else {
final int height3=size.height-spacing*2;
int x2=rhsX+width2+spacing;
y=spacing;
result.setBoundary(ResolutionProfileType.GamePlayerPermanentViewer,
int x2=x+width2+spacing;
y = spacing;
result.setBoundary(
ResolutionProfileType.GamePlayerPermanentViewer,
new Rectangle(x2,y,width2,height3));
x2+=width2+spacing;
result.setBoundary(ResolutionProfileType.GameOpponentPermanentViewer,
x2 += width2 + spacing;
result.setBoundary(
ResolutionProfileType.GameOpponentPermanentViewer,
new Rectangle(x2,y,width2,height3));
}
@ -169,21 +131,23 @@ public class DefaultResolutionProfile implements ResolutionProfile {
y=spacing;
result.setBoundary(
ResolutionProfileType.GameStackCombatViewer,
new Rectangle(rhsX, y, width2, 2*height2));
new Rectangle(x, y, width2, 2*height2));
y+=2*height2+spacing;
result.setBoundary(
ResolutionProfileType.GameHandGraveyardViewer,
new Rectangle(rhsX, y, width2, height2));
new Rectangle(x, y, width2, height2));
y=size.height-spacing-IMAGE_HAND_VIEWER_HEIGHT;
result.setBoundary(ResolutionProfileType.GameZones,new Rectangle(0, 0, x-offset, y-offset));
y = size.height - spacing - IMAGE_HAND_VIEWER_HEIGHT;
result.setBoundary(
ResolutionProfileType.GameZones,
new Rectangle(-1, -1, getPanelWidthLHS(), y - offset));
final int width3=size.width-PLAYER_VIEWER_WIDTH-spacing*3-offset;
result.setBoundary(
ResolutionProfileType.GameImageHandGraveyardViewer,
new Rectangle(rhsX, y, width3, IMAGE_HAND_VIEWER_HEIGHT));
new Rectangle(x, y, width3, IMAGE_HAND_VIEWER_HEIGHT));
final int height3=size.height-spacing*5-IMAGE_HAND_VIEWER_HEIGHT-offset;
@ -193,27 +157,30 @@ public class DefaultResolutionProfile implements ResolutionProfile {
y=spacing;
result.setBoundary(
ResolutionProfileType.GameImageOpponentPermanentViewer,
new Rectangle(rhsX, y, width3, height4));
new Rectangle(x, y, width3, height4));
y+=height4+spacing;
result.setBoundary(
ResolutionProfileType.GameImageCombatViewer,
new Rectangle(rhsX, y, width3, height5));
new Rectangle(x, y, width3, height5));
y+=height5+spacing;
result.setBoundary(
ResolutionProfileType.GameImagePlayerPermanentViewer,
new Rectangle(rhsX, y, width3, height4));
new Rectangle(x, y, width3, height4));
return result;
}
private void setLhsBounds(final ResolutionProfileResult result) {
int spacing = theme.getValue(Theme.VALUE_SPACING);
Rectangle r = new Rectangle(
0, 0,
300 + (spacing * 2),
getPanelWidthLHS(),
containerSize.height);
result.setBoundary(ResolutionProfileType.GameLHS, r);
}
private int getPanelWidthLHS() {
return LHS_CONTENT_WIDTH + (OUTER_MARGIN * 2);
}
}

View File

@ -2,21 +2,10 @@ package magic.ui.resolution;
public enum ResolutionProfileType {
GameLHS,
DuelPlayersViewer,
DuelDeckViewers,
DuelDeckStatisticsViewer,
DuelDeckStrengthViewer,
DuelCardViewer,
DuelDifficultyViewer,
DuelPlayButton,
DuelNewButton,
GameZones,
GamePlayerViewerSmall,
GamePlayerViewer,
GameOpponentViewer,
GameCardViewer,
GameDuelViewer,
GameLogBookViewer,
GameLogBookButton,
@ -29,6 +18,5 @@ public enum ResolutionProfileType {
GameImageHandGraveyardViewer,
GameImagePlayerPermanentViewer,
GameImageOpponentPermanentViewer,
GameImageCombatViewer,
GameImageViewer;
GameImageCombatViewer;
}