From 9aeaa8fd1c097587cc6efb7769a115a9c1196fc3 Mon Sep 17 00:00:00 2001 From: SlightPersimmon1 <65872044+SlightPersimmon1@users.noreply.github.com> Date: Mon, 25 May 2020 18:34:01 +0100 Subject: [PATCH 1/3] Race background colors implementation --- src/rotp/model/empires/Empire.java | 10 +++++ src/rotp/ui/races/RacesUI.java | 69 ++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/rotp/model/empires/Empire.java b/src/rotp/model/empires/Empire.java index dbed49a64..686eae12a 100644 --- a/src/rotp/model/empires/Empire.java +++ b/src/rotp/model/empires/Empire.java @@ -118,6 +118,7 @@ public final class Empire implements Base, NamedObject, Serializable { private transient BufferedImage shipImageHuge; private transient BufferedImage scoutImage; private transient BufferedImage transportImage; + private transient BufferedImage raceBackImage; private transient Color ownershipColor; private transient Color selectionColor; private transient Color reachColor; @@ -234,6 +235,15 @@ public BufferedImage transportImage() { transportImage = ShipLibrary.current().transportImage(shipColorId()); return transportImage; } + + public BufferedImage raceBackImage() { + return raceBackImage; + } + + public void setRaceBackImage(BufferedImage image) { + raceBackImage = image; + } + public Color ownershipColor() { if (ownershipColor == null) { Color c = color(); diff --git a/src/rotp/ui/races/RacesUI.java b/src/rotp/ui/races/RacesUI.java index 0a60832ad..9af70d1d6 100644 --- a/src/rotp/ui/races/RacesUI.java +++ b/src/rotp/ui/races/RacesUI.java @@ -50,10 +50,9 @@ public class RacesUI extends BasePanel { public static final Color darkBrown = new Color(112,85,68); public static final Color darkerBrown = new Color(75,55,39); public static final Color gradientBottom = new Color(110,79,56); - private static final Color raceEdgeColor = new Color(114,75,49); - private static final Color raceCenterColor = new Color(179,117,77); + private static final Color raceEdgeColor = new Color(8, 8, 8); + private static final Color raceCenterColor = new Color(255, 255, 255); static Color[] relationsC = new Color[40]; - public static BufferedImage raceBackImg; public static BufferedImage raceIconBackImg; private final List empires = new ArrayList<>(); @@ -555,7 +554,7 @@ private void drawContact(Graphics2D g, Empire emp, int x, int y, int w, int h) { boxFor(emp).setBounds(x0,y0,w0,h0); g.setColor(darkBrown); g.fillRect(x0, y0, w0, h0); - BufferedImage back = raceBackImg(); + BufferedImage back = raceBackImg(emp); int w1 = back.getWidth(); int h1 = back.getHeight(); int mgn = (h-h1)/2; @@ -660,26 +659,70 @@ else if (otherDipGone) } } } - public BufferedImage raceBackImg() { - if (raceBackImg == null) - initRaceBackImg(); - return raceBackImg; + public BufferedImage raceBackImg(Empire emp) { + + if (emp.raceBackImage() == null ) + initRaceBackImg(emp); + return emp.raceBackImage(); + } - private void initRaceBackImg() { + private void initRaceBackImg(Empire emp) { int w = s76; int h = s82; - raceBackImg = gc().createCompatibleImage(w, h); - + emp.setRaceBackImage(gc().createCompatibleImage(w, h)); + Point2D center = new Point2D.Float(w/2, h/2); float radius = s78; float[] dist = {0.0f, 0.1f, 0.5f, 1.0f}; - Color[] colors = {raceCenterColor, raceCenterColor, raceEdgeColor, raceEdgeColor}; + // gradient - method 1 (less flexible) +// Color[] colors = { +// emp.color().brighter().brighter(), +// emp.color().brighter().brighter(), +// emp.color().darker().darker(), +// emp.color().darker().darker() +// }; + // gradient - method 2 - blending colors (more flexible) + Color[] colors = { + blendColor(raceCenterColor,emp.color(), 0.6f), + blendColor(raceCenterColor,emp.color(), 0.6f), + blendColor(raceEdgeColor,emp.color(), 0.6f), + blendColor(raceEdgeColor,emp.color(), 0.6f) + }; + + RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors); - Graphics2D g = (Graphics2D) raceBackImg.getGraphics(); + Graphics2D g = (Graphics2D) emp.raceBackImage().getGraphics(); g.setPaint(p); g.fillRect(0, 0, w, h); g.dispose(); } + + private Color blendColor( Color c1, Color c2, float ratio ) { + if ( ratio > 1f ) ratio = 1f; + else if ( ratio < 0f ) ratio = 0f; + float iRatio = 1.0f - ratio; + + int i1 = c1.getRGB(); + int i2 = c2.getRGB(); + + int a1 = (i1 >> 24 & 0xff); + int r1 = ((i1 & 0xff0000) >> 16); + int g1 = ((i1 & 0xff00) >> 8); + int b1 = (i1 & 0xff); + + int a2 = (i2 >> 24 & 0xff); + int r2 = ((i2 & 0xff0000) >> 16); + int g2 = ((i2 & 0xff00) >> 8); + int b2 = (i2 & 0xff); + + int a = (int)((a1 * iRatio) + (a2 * ratio)); + int r = (int)((r1 * iRatio) + (r2 * ratio)); + int g = (int)((g1 * iRatio) + (g2 * ratio)); + int b = (int)((b1 * iRatio) + (b2 * ratio)); + + return new Color( a << 24 | r << 16 | g << 8 | b ); + } + private Rectangle boxFor(Empire emp) { if (!contactBoxes.containsKey(emp)) contactBoxes.put(emp, new Rectangle()); From 12b98bb8276758ec89e188286e49bb098e96db68 Mon Sep 17 00:00:00 2001 From: SlightPersimmon1 <65872044+SlightPersimmon1@users.noreply.github.com> Date: Tue, 26 May 2020 18:47:51 +0100 Subject: [PATCH 2/3] Initial Full Screen Support --- src/rotp/Rotp.java | 11 ++++++++++ src/rotp/ui/UserPreferences.java | 35 ++++++++++++++++++++++++++++++++ src/rotp/ui/game/GameUI.java | 19 +++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/rotp/Rotp.java b/src/rotp/Rotp.java index 9bfe34142..36da10ad2 100644 --- a/src/rotp/Rotp.java +++ b/src/rotp/Rotp.java @@ -33,6 +33,8 @@ import rotp.ui.SwingExceptionHandler; import rotp.ui.UserPreferences; import rotp.util.FontManager; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; public class Rotp { private static final int MB = 1048576; @@ -49,9 +51,18 @@ public class Rotp { private static float resizeAmt = -1.0f; public static int actualAlloc = -1; public static boolean reloadRecentSave = false; + private static GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0]; public static void main(String[] args) { frame = new JFrame("Remnants of the Precursors"); + + if (UserPreferences.getPreferenceValueFromFile("FULL_SCREEN").equalsIgnoreCase("YES")) + { + frame.setUndecorated(true); + device.setFullScreenWindow(frame); + } + + if (args.length == 0) { if (restartWithMoreMemory(frame, false)) return; diff --git a/src/rotp/ui/UserPreferences.java b/src/rotp/ui/UserPreferences.java index bbd45852f..f945a8e5e 100644 --- a/src/rotp/ui/UserPreferences.java +++ b/src/rotp/ui/UserPreferences.java @@ -41,6 +41,7 @@ public enum GraphicsSetting { NORMAL, MEDIUM, LOW; } private static boolean textures = true; private static float uiTexturePct = 0.20f; private static int screenSizePct = 93; + private static boolean fullScreenMode = false; private static final HashMap raceNames = new HashMap<>(); private static GraphicsSetting graphicsLevel = GraphicsSetting.NORMAL; @@ -63,6 +64,7 @@ public enum GraphicsSetting { NORMAL, MEDIUM, LOW; } public static void uiTexturePct(int i) { uiTexturePct = i / 100.0f; } public static float uiTexturePct() { return uiTexturePct; } public static GraphicsSetting graphicsLevel() { return graphicsLevel; } + public static boolean fullScreenMode() { return fullScreenMode; } public static void loadAndSave() { load(); @@ -102,6 +104,7 @@ public static void save() { out.println(keyFormat("UI_TEXTURES")+ yesOrNo(textures)); out.println(keyFormat("UI_TEXTURE_LEVEL")+(int) (uiTexturePct()*100)); out.println(keyFormat("LANGUAGE")+ languageDir()); + out.println(keyFormat("FULL_SCREEN")+ yesOrNo(fullScreenMode)); for (String raceKey: raceKeys) out.println(keyFormat(raceKey)+raceNames.get(raceKey)); } @@ -137,10 +140,42 @@ private static void loadPreferenceLine(String line) { case "UI_TEXTURES": textures = yesOrNo(val); return; case "UI_TEXTURE_LEVEL": uiTexturePct(Integer.valueOf(val)); return; case "LANGUAGE": selectLanguage(val); return; + case "FULL_SCREEN": fullScreenMode = yesOrNo(val); return; default: raceNames.put(key, val); break; } } + + public static String getPreferenceValueFromFile(String key){ + + String path = Rotp.jarPath(); + try (FileReader fileReader = new FileReader(new File(path, PREFERENCES_FILE)); + BufferedReader in = new BufferedReader(fileReader); ) { + String input; + if (in != null) { + while ((input = in.readLine()) != null) + if (input.contains(key) && input.contains(":") ) + return input.split(":")[1].trim(); + } + } + catch (FileNotFoundException e) { + System.err.println(path + PREFERENCES_FILE + " not found."); + } + catch (IOException e) { + System.err.println("UserPreferences.load -- IOException: " + e.toString()); + } + + return ""; + + } + + public static void toggleFullScreenMode() { + if (!fullScreenMode) setScreenSizePct(100); + fullScreenMode = !fullScreenMode; + save(); + } + + private static String yesOrNo(boolean b) { return b ? "YES" : "NO"; } diff --git a/src/rotp/ui/game/GameUI.java b/src/rotp/ui/game/GameUI.java index 5825e1765..cd27c8fd2 100644 --- a/src/rotp/ui/game/GameUI.java +++ b/src/rotp/ui/game/GameUI.java @@ -106,6 +106,7 @@ public class GameUI extends BasePanel implements MouseListener, MouseMotionList BaseText soundsText, musicText, graphicsText, texturesText, versionText, memoryText; BaseText developerText, artistText, graphicDsnrText, writerText, soundText, translatorText; BaseText shrinkText, enlargeText; + BaseText fullScreenText; BaseText hoverBox; Rectangle languageBox = new Rectangle(); boolean mouseDepressed = false; @@ -315,6 +316,7 @@ public GameUI() { writerText = new BaseText(this, false,16, -220,-44, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); soundText = new BaseText(this, false,16, -220,-27, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); translatorText = new BaseText(this, false,16, -220,-10, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); + fullScreenText = new BaseText(this, false,16, 20,-95, enabledC, disabledC, hoverC, depressedC, shadedC, 0, 0, 0); developerText.disabled(true); artistText.disabled(true); @@ -359,6 +361,7 @@ private void setTextValues() { soundText.displayText(text("CREDITS_SOUND")); translatorText.displayText(text("CREDITS_TRANSLATOR")); versionText.displayText(text("GAME_VERSION", str(Rotp.releaseId))); + fullScreenText.displayText(fullScreenStr()); } @Override public boolean drawMemory() { return true; } @@ -466,6 +469,7 @@ public void paintComponent(Graphics g0) { graphicsText.draw(g); musicText.draw(g); soundsText.draw(g); + fullScreenText.draw(g); } private boolean canContinue() { return session().status().inProgress() || session().hasRecentSession(); } private boolean canNewGame() { return true; } @@ -571,6 +575,16 @@ public void exitGame() { public void restartGame() { Rotp.restart(); } + + private void toggleFullScreen(){ + UserPreferences.toggleFullScreenMode(); + restartGame(); + } + + private String fullScreenStr() { + return "Full Screen: " + (UserPreferences.fullScreenMode()? "ON" : "OFF"); + } + private String texturesStr() { if (UserPreferences.textures()) return text("GAME_TEXTURES_ON")+" "; @@ -723,6 +737,9 @@ else if (enlargeText.contains(x,y)) expandFrame(); else if (memoryText.contains(x,y)) toggleMemory(); + else if (fullScreenText.contains(x,y)) + toggleFullScreen(); + } @Override public void mouseDragged(MouseEvent e) { @@ -767,6 +784,8 @@ else if (enlargeText.contains(x,y)) newHover = enlargeText; else if (memoryText.contains(x,y)) newHover = memoryText; + else if (fullScreenText.contains(x,y)) + newHover = fullScreenText; if (hoverBox != newHover) { if (hoverBox != null) From 6d7c4ecb7f9d2d12cbb50d35ffd0b564838105b2 Mon Sep 17 00:00:00 2001 From: SlightPersimmon1 <65872044+SlightPersimmon1@users.noreply.github.com> Date: Tue, 26 May 2020 18:55:37 +0100 Subject: [PATCH 3/3] Revert "Initial Full Screen Support" This reverts commit 12b98bb8276758ec89e188286e49bb098e96db68. --- src/rotp/Rotp.java | 11 ---------- src/rotp/ui/UserPreferences.java | 35 -------------------------------- src/rotp/ui/game/GameUI.java | 19 ----------------- 3 files changed, 65 deletions(-) diff --git a/src/rotp/Rotp.java b/src/rotp/Rotp.java index 36da10ad2..9bfe34142 100644 --- a/src/rotp/Rotp.java +++ b/src/rotp/Rotp.java @@ -33,8 +33,6 @@ import rotp.ui.SwingExceptionHandler; import rotp.ui.UserPreferences; import rotp.util.FontManager; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; public class Rotp { private static final int MB = 1048576; @@ -51,18 +49,9 @@ public class Rotp { private static float resizeAmt = -1.0f; public static int actualAlloc = -1; public static boolean reloadRecentSave = false; - private static GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0]; public static void main(String[] args) { frame = new JFrame("Remnants of the Precursors"); - - if (UserPreferences.getPreferenceValueFromFile("FULL_SCREEN").equalsIgnoreCase("YES")) - { - frame.setUndecorated(true); - device.setFullScreenWindow(frame); - } - - if (args.length == 0) { if (restartWithMoreMemory(frame, false)) return; diff --git a/src/rotp/ui/UserPreferences.java b/src/rotp/ui/UserPreferences.java index f945a8e5e..bbd45852f 100644 --- a/src/rotp/ui/UserPreferences.java +++ b/src/rotp/ui/UserPreferences.java @@ -41,7 +41,6 @@ public enum GraphicsSetting { NORMAL, MEDIUM, LOW; } private static boolean textures = true; private static float uiTexturePct = 0.20f; private static int screenSizePct = 93; - private static boolean fullScreenMode = false; private static final HashMap raceNames = new HashMap<>(); private static GraphicsSetting graphicsLevel = GraphicsSetting.NORMAL; @@ -64,7 +63,6 @@ public enum GraphicsSetting { NORMAL, MEDIUM, LOW; } public static void uiTexturePct(int i) { uiTexturePct = i / 100.0f; } public static float uiTexturePct() { return uiTexturePct; } public static GraphicsSetting graphicsLevel() { return graphicsLevel; } - public static boolean fullScreenMode() { return fullScreenMode; } public static void loadAndSave() { load(); @@ -104,7 +102,6 @@ public static void save() { out.println(keyFormat("UI_TEXTURES")+ yesOrNo(textures)); out.println(keyFormat("UI_TEXTURE_LEVEL")+(int) (uiTexturePct()*100)); out.println(keyFormat("LANGUAGE")+ languageDir()); - out.println(keyFormat("FULL_SCREEN")+ yesOrNo(fullScreenMode)); for (String raceKey: raceKeys) out.println(keyFormat(raceKey)+raceNames.get(raceKey)); } @@ -140,42 +137,10 @@ private static void loadPreferenceLine(String line) { case "UI_TEXTURES": textures = yesOrNo(val); return; case "UI_TEXTURE_LEVEL": uiTexturePct(Integer.valueOf(val)); return; case "LANGUAGE": selectLanguage(val); return; - case "FULL_SCREEN": fullScreenMode = yesOrNo(val); return; default: raceNames.put(key, val); break; } } - - public static String getPreferenceValueFromFile(String key){ - - String path = Rotp.jarPath(); - try (FileReader fileReader = new FileReader(new File(path, PREFERENCES_FILE)); - BufferedReader in = new BufferedReader(fileReader); ) { - String input; - if (in != null) { - while ((input = in.readLine()) != null) - if (input.contains(key) && input.contains(":") ) - return input.split(":")[1].trim(); - } - } - catch (FileNotFoundException e) { - System.err.println(path + PREFERENCES_FILE + " not found."); - } - catch (IOException e) { - System.err.println("UserPreferences.load -- IOException: " + e.toString()); - } - - return ""; - - } - - public static void toggleFullScreenMode() { - if (!fullScreenMode) setScreenSizePct(100); - fullScreenMode = !fullScreenMode; - save(); - } - - private static String yesOrNo(boolean b) { return b ? "YES" : "NO"; } diff --git a/src/rotp/ui/game/GameUI.java b/src/rotp/ui/game/GameUI.java index cd27c8fd2..5825e1765 100644 --- a/src/rotp/ui/game/GameUI.java +++ b/src/rotp/ui/game/GameUI.java @@ -106,7 +106,6 @@ public class GameUI extends BasePanel implements MouseListener, MouseMotionList BaseText soundsText, musicText, graphicsText, texturesText, versionText, memoryText; BaseText developerText, artistText, graphicDsnrText, writerText, soundText, translatorText; BaseText shrinkText, enlargeText; - BaseText fullScreenText; BaseText hoverBox; Rectangle languageBox = new Rectangle(); boolean mouseDepressed = false; @@ -316,7 +315,6 @@ public GameUI() { writerText = new BaseText(this, false,16, -220,-44, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); soundText = new BaseText(this, false,16, -220,-27, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); translatorText = new BaseText(this, false,16, -220,-10, enabledC, enabledC, hoverC, depressedC, shadedC, 0, 0, 0); - fullScreenText = new BaseText(this, false,16, 20,-95, enabledC, disabledC, hoverC, depressedC, shadedC, 0, 0, 0); developerText.disabled(true); artistText.disabled(true); @@ -361,7 +359,6 @@ private void setTextValues() { soundText.displayText(text("CREDITS_SOUND")); translatorText.displayText(text("CREDITS_TRANSLATOR")); versionText.displayText(text("GAME_VERSION", str(Rotp.releaseId))); - fullScreenText.displayText(fullScreenStr()); } @Override public boolean drawMemory() { return true; } @@ -469,7 +466,6 @@ public void paintComponent(Graphics g0) { graphicsText.draw(g); musicText.draw(g); soundsText.draw(g); - fullScreenText.draw(g); } private boolean canContinue() { return session().status().inProgress() || session().hasRecentSession(); } private boolean canNewGame() { return true; } @@ -575,16 +571,6 @@ public void exitGame() { public void restartGame() { Rotp.restart(); } - - private void toggleFullScreen(){ - UserPreferences.toggleFullScreenMode(); - restartGame(); - } - - private String fullScreenStr() { - return "Full Screen: " + (UserPreferences.fullScreenMode()? "ON" : "OFF"); - } - private String texturesStr() { if (UserPreferences.textures()) return text("GAME_TEXTURES_ON")+" "; @@ -737,9 +723,6 @@ else if (enlargeText.contains(x,y)) expandFrame(); else if (memoryText.contains(x,y)) toggleMemory(); - else if (fullScreenText.contains(x,y)) - toggleFullScreen(); - } @Override public void mouseDragged(MouseEvent e) { @@ -784,8 +767,6 @@ else if (enlargeText.contains(x,y)) newHover = enlargeText; else if (memoryText.contains(x,y)) newHover = memoryText; - else if (fullScreenText.contains(x,y)) - newHover = fullScreenText; if (hoverBox != newHover) { if (hoverBox != null)