[Jrisk-cvs] SF.net SVN: domination-code:[2636] Domination/swingUI/src/net/yura/ domination
Brought to you by:
yuranet
|
From: <yu...@us...> - 2025-02-09 17:59:07
|
Revision: 2636
http://sourceforge.net/p/domination/code/2636
Author: yuranet
Date: 2025-02-09 17:59:04 +0000 (Sun, 09 Feb 2025)
Log Message:
-----------
color blind mode support started for desktop UI
Modified Paths:
--------------
Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java
Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
Domination/swingUI/src/net/yura/domination/ui/flashgui/FlashRiskAdapter.java
Domination/swingUI/src/net/yura/domination/ui/flashgui/GameFrame.java
Domination/swingUI/src/net/yura/domination/ui/flashgui/NewGameFrame.java
Domination/swingUI/src/net/yura/domination/ui/swinggui/GameTab.java
Domination/swingUI/src/net/yura/domination/ui/swinggui/SwingGUIPanel.java
Modified: Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -22,10 +22,15 @@
import javax.swing.JPanel;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.logging.Logger;
+import java.util.prefs.Preferences;
import net.yura.domination.engine.ColorUtil;
import net.yura.domination.engine.Risk;
+import net.yura.domination.engine.RiskSettings;
import net.yura.domination.engine.RiskUtil;
import net.yura.domination.engine.core.Card;
import net.yura.domination.engine.core.Country;
@@ -323,8 +328,37 @@
return map[0].length;
}
+ public void setColorBlindMode(Preferences prefs) {
+ if (prefs != null) {
+ setColorBlindMode(prefs.getBoolean(RiskSettings.COLOR_BLIND_KEY, false));
+ }
+ }
+
+ public void setColorBlindMode(boolean cb) {
+ colorBlind = cb;
+ repaint();
+ }
+
public int BALL_SIZE=20;
+ private boolean colorBlind;
+ static Map<Integer,Image> icons = new HashMap();
+ static {
+ icons.put(ColorUtil.RED, RiskUIUtil.getUIImage(PicturePanel.class, "/color_red.png"));
+ icons.put(ColorUtil.BLUE, RiskUIUtil.getUIImage(PicturePanel.class, "/color_blue.png"));
+ icons.put(ColorUtil.YELLOW, RiskUIUtil.getUIImage(PicturePanel.class, "/color_yellow.png"));
+ icons.put(ColorUtil.CYAN, RiskUIUtil.getUIImage(PicturePanel.class, "/color_cyan.png"));
+ icons.put(ColorUtil.GREEN, RiskUIUtil.getUIImage(PicturePanel.class, "/color_green.png"));
+ icons.put(ColorUtil.MAGENTA, RiskUIUtil.getUIImage(PicturePanel.class, "/color_magenta.png"));
+ }
+
+ /**
+ * @see net.yura.domination.android.StatsActivity#getIcon(Player)
+ */
+ public Image getIconForColor(int color) {
+ return colorBlind ? icons.get(color) : null;
+ }
+
/**
* Paints the army components
* @param g2 a 2D Graphics object.
@@ -337,8 +371,6 @@
int state = game.getState();
- int r = BALL_SIZE/2;
-
if (state==RiskGame.STATE_ROLLING || state==RiskGame.STATE_BATTLE_WON || state==RiskGame.STATE_DEFEND_YOURSELF) {
int a=game.getAttacker().getColor();
@@ -380,11 +412,26 @@
}
}
+ Map<Country,Player> capitals = Collections.EMPTY_MAP;
+ if (game.getGameMode() == RiskGame.MODE_CAPITAL && game.getSetupDone() && state != RiskGame.STATE_SELECT_CAPITAL) {
+ capitals = new HashMap(game.getNoPlayers());
+ List<Player> players = game.getPlayers();
+ for (int c=0; c<players.size(); c++) {
+ Player player = players.get(c);
+ Country capital = player.getCapital();
+ if (capital!=null) {
+ capitals.put(capital, player);
+ }
+ }
+ }
+
Country t;
for (int c=0; c< v.length ; c++) {
t = v[c];
+ g2.setFont( getFont() );
+
if ( t.getOwner() != null ) {
int x,y;
@@ -397,71 +444,56 @@
y = (int)ballWorld.balls[c].y;
}
- g2.setColor( new Color( t.getOwner().getColor() ) );
-
- Ellipse2D ellipse = new Ellipse2D.Double();
- ellipse.setFrame( x-r , y-r , BALL_SIZE, BALL_SIZE );
- g2.fill(ellipse);
-
- //g.fillOval( t.getX()-r , t.getY()-r, (r*2), (r*2) );
-
- g2.setColor( new Color( ColorUtil.getTextColorFor( t.getOwner().getColor() ) ) );
-
- g2.setFont( getFont() );
-
- String noa= String.valueOf( t.getArmies() );
-
- int w2 = g2.getFontMetrics().stringWidth(noa) / 2;
- int h2 = g2.getFontMetrics().getAscent()*2/5 ;
-
- g2.drawString( String.valueOf( noa ) , x-w2, y+h2 );
+ drawArmy(this, g2, t.getOwner().getColor(), t.getArmies(), x, y, BALL_SIZE, capitals.get(t));
}
}
+ }
- if (game.getGameMode() == RiskGame.MODE_CAPITAL && game.getSetupDone() && state !=RiskGame.STATE_SELECT_CAPITAL ) {
+ public static void drawArmy(PicturePanel pp, Graphics2D g2, int countryOwnerColor, int armies, int x, int y, int ballSize, Player capital) {
+ int r = ballSize / 2;
+
+ Image icon = pp.getIconForColor(countryOwnerColor);
+ if (icon == null) {
+ g2.setColor( new Color( countryOwnerColor ) );
+ Ellipse2D ellipse = new Ellipse2D.Double();
+ ellipse.setFrame( x-r , y-r , ballSize, ballSize);
+ g2.fill(ellipse);
+ //g.fillOval( t.getX()-r , t.getY()-r, (r*2), (r*2) );
+ }
+ else {
+ int w = (int)(ballSize * 1.1);
+ int h = (int)(icon.getHeight(pp) * (w / (double)icon.getWidth(pp)));
+ g2.drawImage(icon, x-(w/2), y-(w/2), w, h, pp);
+ }
- int stroke = BALL_SIZE / 10;
+ g2.setColor( new Color( ColorUtil.getTextColorFor( countryOwnerColor ) ) );
+ String noa = String.valueOf( armies );
+ int w2 = g2.getFontMetrics().stringWidth(noa) / 2;
+ int h2 = g2.getFontMetrics().getAscent()*2/5 ;
+ g2.drawString( String.valueOf( noa ) , x-w2, y+h2 );
+
+ if (capital != null) {
+ int stroke = ballSize / 10;
+ Stroke old = g2.getStroke();
+ g2.setStroke(new BasicStroke( stroke ));
- Stroke old = g2.getStroke();
- g2.setStroke(new BasicStroke( stroke ));
- List players = game.getPlayers();
+ g2.setColor(new Color(ColorUtil.getTextColorFor(capital.getColor())));
- for (int c=0; c< players.size() ; c++) {
+ Ellipse2D ellipse1 = new Ellipse2D.Double();
+ ellipse1.setFrame( x-r , y-r , ballSize-1, ballSize-1);
+ g2.draw(ellipse1);
- Country capital = ((Player)players.get(c)).getCapital();
+ g2.setColor(new Color(capital.getColor()));
- if ( capital !=null ) {
+ Ellipse2D ellipse2 = new Ellipse2D.Double();
+ int size = ballSize + (stroke*2);
+ ellipse2.setFrame( x-(size/2) , y-(size/2) , size-1, size-1);
+ g2.draw(ellipse2);
- int pos = capital.getColor()-1;
+ g2.setStroke(old);
+ }
+ }
- int x,y;
- if (ballWorld==null) {
- x = v[pos].getX();
- y = v[pos].getY();
- }
- else {
- x = (int)ballWorld.balls[pos].x;
- y = (int)ballWorld.balls[pos].y;
- }
-
- g2.setColor( new Color( ColorUtil.getTextColorFor( capital.getOwner().getColor() ) ) );
-
- Ellipse2D ellipse = new Ellipse2D.Double();
- ellipse.setFrame( x-r , y-r , BALL_SIZE-1, BALL_SIZE-1);
- g2.draw(ellipse);
-
- g2.setColor( new Color( ((Player)players.get(c)).getColor() ) );
-
- Ellipse2D ellipse2 = new Ellipse2D.Double();
- int size = BALL_SIZE + (stroke*2);
- ellipse2.setFrame( x-(size/2) , y-(size/2) , size-1, size-1);
- g2.draw(ellipse2);
- }
- }
- g2.setStroke(old);
- }
- }
-
BallWorld ballWorld;
int oldState;
Modified: Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -245,6 +245,17 @@
// failed to create MultiResolutionImage
}
}
+ if (name.startsWith("/")) {
+ String xhdpi = "/drawable-xhdpi" + name;
+ try {
+ Image img2x = getUIImageCached(cls, xhdpi);
+ Image[] imgList = new Image[] {img, img2x};
+ return GraphicsUtil.newBaseMultiResolutionImage(imgList);
+ }
+ catch (Throwable ex) {
+ // failed to create MultiResolutionImage
+ }
+ }
}
return img;
@@ -1507,6 +1518,7 @@
aiWaitPanel.add(aiwait);
aiWaitPanel.add(new JLabel("milliseconds"));
+ JCheckBox colorBlind = new JCheckBox(resB.getString("game.menu.colorblind"), preferences.getBoolean(RiskSettings.COLOR_BLIND_KEY, false));
JCheckBox soundEnabled = new JCheckBox(resB.getString("game.menu.sound"), GameSound.INSTANCE.isSoundEnabled());
JCheckBox musicEnabled = new JCheckBox(resB.getString("game.menu.music"), GameSound.INSTANCE.isMusicEnabled());
@@ -1522,7 +1534,7 @@
parentComponent, // the parent that the dialog blocks
new Component[] { // the dialog message array
showDice,aiWaitPanel,
- soundEnabled, musicEnabled,
+ colorBlind, soundEnabled, musicEnabled,
autoEndGo, autoDefend
},
"Options", // the title of the dialog window
@@ -1535,6 +1547,7 @@
AIManager.setWait(((Integer)aiwait.getValue()).intValue());
GameSound.INSTANCE.setSoundEnabled(soundEnabled.isSelected());
GameSound.INSTANCE.setMusicEnabled(musicEnabled.isSelected());
+ preferences.putBoolean(RiskSettings.COLOR_BLIND_KEY, colorBlind.isSelected());
RiskSettings.saveSettingsToPrefs(preferences);
if (autoEndGo.isEnabled()) {
Modified: Domination/swingUI/src/net/yura/domination/ui/flashgui/FlashRiskAdapter.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/ui/flashgui/FlashRiskAdapter.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/ui/flashgui/FlashRiskAdapter.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -13,6 +13,7 @@
import javax.swing.SwingUtilities;
import net.yura.domination.engine.Risk;
import net.yura.domination.engine.RiskListener;
+import net.yura.domination.engine.RiskSettings;
import net.yura.domination.guishared.RiskUIUtil;
import net.yura.domination.engine.core.Country;
import net.yura.domination.engine.core.RiskGame;
@@ -37,6 +38,11 @@
private int nogames;
+ /**
+ * constructor for game screen mode ONLY
+ * used when game setup screen is not needed
+ * e.g. Lobby Game Client
+ */
public FlashRiskAdapter(Risk r) {
myrisk = r;
@@ -43,6 +49,7 @@
myrisk.addRiskListener(this);
pp = new PicturePanel(myrisk);
+ pp.setColorBlindMode(RiskSettings.getPreferences(MainMenu.class));
gameFrame = new GameFrame(myrisk, pp);
battledialog = new BattleDialog(gameFrame, false, myrisk);
gameFrame.setBattleDialog(battledialog);
@@ -50,11 +57,13 @@
RiskUIUtil.center(battledialog);
}
-
+ /**
+ * Main constructor
+ */
FlashRiskAdapter(MainMenu m, Risk r) {
this(r);
menu = m;
- newgameframe = new NewGameFrame(myrisk);
+ newgameframe = new NewGameFrame(myrisk, pp);
}
void showMiniLobby(RootPaneContainer root, Frame window) {
@@ -65,7 +74,7 @@
lobby = null;
menu.showMainMenu();
}
-
+
public void updateLookAndFeel() {
if (gameFrame != null) {
SwingUtilities.updateComponentTreeUI(gameFrame);
Modified: Domination/swingUI/src/net/yura/domination/ui/flashgui/GameFrame.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/ui/flashgui/GameFrame.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/ui/flashgui/GameFrame.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.prefs.Preferences;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
@@ -636,9 +637,11 @@
}
}
};
-
+
public void openOptions() {
- RiskUIUtil.openOptions(GameFrame.this, myrisk, gameState > RiskGame.STATE_NEW_GAME, RiskSettings.getPreferences(MainMenu.class));
+ Preferences prefs = RiskSettings.getPreferences(MainMenu.class);
+ RiskUIUtil.openOptions(GameFrame.this, myrisk, gameState > RiskGame.STATE_NEW_GAME, prefs);
+ pp.setColorBlindMode(prefs);
}
public void repaintCountries() {
Modified: Domination/swingUI/src/net/yura/domination/ui/flashgui/NewGameFrame.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/ui/flashgui/NewGameFrame.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/ui/flashgui/NewGameFrame.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -55,6 +55,7 @@
import net.yura.swing.ImageIcon;
import net.yura.domination.guishared.RiskFileFilter;
import net.yura.domination.engine.translation.TranslationBundle;
+import net.yura.domination.guishared.PicturePanel;
/**
* <p> New Game Frame for FlashGUI </p>
@@ -122,12 +123,14 @@
*/
private int nRemoveButtonPos = 8;
+ private PicturePanel pp;
+
/**
* The NewGameFrame Constructor
* @param r The Risk Parser used for playing the game
* @param t States whether this game is local
*/
- public NewGameFrame(Risk r) {
+ public NewGameFrame(Risk r, PicturePanel pp) {
resb = TranslationBundle.getBundle();
myrisk=r;
newgame = RiskUIUtil.getUIImage(this.getClass(),"newgame.jpg");
@@ -136,6 +139,7 @@
setResizable(false);
pack();
chooseCards.requestFocus();
+ this.pp = pp;
}
/**
@@ -706,12 +710,14 @@
public void paintComponent(Graphics g) {
g.setColor( new Color(color.getRed(), color.getGreen(), color.getBlue(), 125) );
-
GraphicsUtil.fillRect(g, 0, 0, 309, 30);
+
+ Image img = pp.getIconForColor(color.getRGB());
+ if (img != null) {
+ GraphicsUtil.drawImageInRect(g, img, 98, 5, 20, 20, this);
+ }
g.setColor( RiskUIUtil.getTextColorFor(color) );
-
-
GraphicsUtil.drawString(g, name, 10, 20);
String typeString;
@@ -766,16 +772,10 @@
GraphicsUtil.drawImage(g, newgame, 0, 0, 700, 600, 0, 0, 700, 600, this);
if (localgame) {
-
GraphicsUtil.drawImage(g, newgame, 432, 262, 557, 305, 700, 482, 825, 525, this);
-
}
- g.setColor( thecolor );
- GraphicsUtil.fillRect(g, 400, 370, 100, 25);
-
g.setColor( Color.black );
-
GraphicsUtil.drawString(g, resb.getString("newgame.label.map"), 55, 40);
GraphicsUtil.drawString(g, resb.getString("newgame.label.players"), 350, 40);
GraphicsUtil.drawString(g, resb.getString("newgame.label.cards"), 55, 250);
@@ -784,9 +784,15 @@
GraphicsUtil.drawString(g, resb.getString("newgame.label.name"), 400, 325);
GraphicsUtil.drawString(g, resb.getString("newgame.label.type"), 520, 325);
+ g.setColor( thecolor );
+ GraphicsUtil.fillRect(g, 400, 370, 100, 25);
+ Image img = pp.getIconForColor(thecolor.getRGB());
+ if (img != null) {
+ GraphicsUtil.drawImageInRect(g, img, 450, 370, 25, 25, this);
+ }
+
g.setColor( RiskUIUtil.getTextColorFor( thecolor ) );
-
- GraphicsUtil.drawString(g, resb.getString("newgame.label.color"), 410, 387);
+ GraphicsUtil.drawString(g, resb.getString("newgame.label.color"), 405, 387);
}
}
@@ -804,6 +810,10 @@
for (int c=0; c< Colors.length ; c++) {
g.setColor( Colors[c].getColor() );
GraphicsUtil.fillRect(g, Colors[c].getX(), Colors[c].getY(), Colors[c].getWidth(), Colors[c].getHeight());
+ Image img = pp.getIconForColor(Colors[c].getColor().getRGB());
+ if (img != null) {
+ GraphicsUtil.drawImageInRect(g2, img, Colors[c].getX(), Colors[c].getY(), Colors[c].getWidth(), Colors[c].getHeight(), this);
+ }
}
}
}//class colorChooserPanel extends JPanel
Modified: Domination/swingUI/src/net/yura/domination/ui/swinggui/GameTab.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/ui/swinggui/GameTab.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/ui/swinggui/GameTab.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -3,6 +3,7 @@
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
@@ -9,6 +10,7 @@
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
+import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
@@ -26,6 +28,7 @@
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
+import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
@@ -559,7 +562,9 @@
}
private void openOptions() {
- RiskUIUtil.openOptions(this, swingGUIPanel.myrisk, swingGUIPanel.gameState > RiskGame.STATE_NEW_GAME, SwingGUIPanel.getUIPreferences());
+ Preferences prefs = SwingGUIPanel.getUIPreferences();
+ RiskUIUtil.openOptions(this, swingGUIPanel.myrisk, swingGUIPanel.gameState > RiskGame.STATE_NEW_GAME, prefs);
+ swingGUIPanel.pp.setColorBlindMode(prefs);
}
public void blockInput() {
@@ -1279,6 +1284,25 @@
setBackground(c);
setForeground( RiskUIUtil.getTextColorFor( c ) );
setText(c.toString());
+
+ final Image img = swingGUIPanel.pp.getIconForColor(c.getRGB());
+ setIcon(img == null ? null : new Icon() {
+ @Override
+ public void paintIcon(Component c, Graphics g, int x, int y) {
+ g.drawImage(img, x, y, getIconWidth(), getIconHeight(), c);
+ }
+
+ @Override
+ public int getIconWidth() {
+ double scale = getIconHeight() / (double)img.getHeight(null);
+ return (int) (scale * img.getWidth(null));
+ }
+
+ @Override
+ public int getIconHeight() {
+ return players.getRowHeight();
+ }
+ });
} else {
super.setValue(value);
}
Modified: Domination/swingUI/src/net/yura/domination/ui/swinggui/SwingGUIPanel.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/ui/swinggui/SwingGUIPanel.java 2025-02-09 16:43:37 UTC (rev 2635)
+++ Domination/swingUI/src/net/yura/domination/ui/swinggui/SwingGUIPanel.java 2025-02-09 17:59:04 UTC (rev 2636)
@@ -106,6 +106,7 @@
gameState=-1; // (-1 means no game)
pp = new PicturePanel(myrisk);
+ pp.setColorBlindMode(getUIPreferences());
setLayout(new java.awt.BorderLayout());
|