OSDN Git Service

キャスト表Wiki出力の見栄えを改善 topic/ribbonwiki
authorOlyutorskii <olyutorskii@users.osdn.me>
Sun, 8 Jul 2018 03:08:38 +0000 (12:08 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Sun, 8 Jul 2018 03:08:38 +0000 (12:08 +0900)
CHANGELOG.txt
src/main/java/jp/sfjp/jindolf/dxchg/WolfBBS.java
src/main/java/jp/sfjp/jindolf/summary/GameSummary.java
src/test/java/jp/sfjp/jindolf/dxchg/WolfBBSTest.java

index e50cae2..30beefe 100644 (file)
@@ -5,8 +5,9 @@ Jindolf 変更履歴
 
 
 X.XXX.X (XXXX-XX-XX)
-    ・JinParser 2.101.4 に対応。
     ・JDK9以降のWindows HiDPI環境に対応。
+    ・キャスト表Wiki出力の見栄えを改善。
+    ・JinParser 2.101.4 に対応。
     ・-nosplashオプションの廃止。
 
 3.302.4 (2017-04-09)
index 2bb857b..2dfed6b 100644 (file)
@@ -7,6 +7,7 @@
 
 package jp.sfjp.jindolf.dxchg;
 
+import java.awt.Color;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -58,6 +59,12 @@ public final class WolfBBS{
 
     private static final String WOLFBBS_URL = "http://wolfbbs.jp/";
 
+    private static final Color COLOR_INNOCENT = new Color(0xb7bad3);
+    private static final Color COLOR_WOLF     = new Color(0xe0b8b8);
+    private static final Color COLOR_HAMSTER  = new Color(0xb9d0be);
+    private static final Color COLOR_DEAD     = new Color(0xaaaaaa);
+    private static final Color COLOR_ALIVE    = new Color(0xffffff);
+
     private static final Logger LOGGER = Logger.getAnonymousLogger();
 
     static{
@@ -374,13 +381,60 @@ public final class WolfBBS{
     }
 
     /**
-     * 陣営の色Wiki表記を返す。
+     * ColorのRGB各成分をWikiカラー表記に変換する。
+     *
+     * α成分は無視される。
+     *
+     * @param color 色
+     * @return Wikiカラー表記
+     */
+    public static String cnvWikiColor(Color color){
+        int packRGB = color.getRGB();
+
+        String txtRGB = Integer.toHexString(packRGB);
+        String leadRGB = "00000000" + txtRGB;
+        int chopLen = leadRGB.length() - 6;
+        String fixed = leadRGB.substring(chopLen);
+        String result = "#" + fixed;
+
+        return result;
+    }
+
+    /**
+     * 表の偶数行に色の変化を付ける。
+     *
+     * @param color 色
+     * @return 変化した色
+     */
+    public static Color evenColor(Color color){
+        int red   = color.getRed();
+        int green = color.getGreen();
+        int blue  = color.getBlue();
+
+        float[] hsb = Color.RGBtoHSB(red, green, blue, null);
+        float h = hsb[0];
+        float s = hsb[1];
+        float b = hsb[2];
+
+        if(b < 0.5){
+            b += 0.03;
+        }else{
+            b -= 0.03;
+        }
+
+        Color result = Color.getHSBColor(h, s, b);
+
+        return result;
+    }
+
+    /**
+     * 陣営の色を返す。
      *
      * @param role 役職
-     * @return 色Wiki表記
+     * @return 色
      */
-    public static String getTeamWikiColor(GameRole role){
-        String result;
+    public static Color getTeamColor(GameRole role){
+        Color result;
 
         switch(role){
         case INNOCENT:
@@ -388,14 +442,14 @@ public final class WolfBBS{
         case SHAMAN:
         case HUNTER:
         case FRATER:
-            result = "#b7bad3";
+            result = COLOR_INNOCENT;
             break;
         case WOLF:
         case MADMAN:
-            result = "#e0b8b8";
+            result = COLOR_WOLF;
             break;
         case HAMSTER:
-            result = "#b9d0be";
+            result = COLOR_HAMSTER;
             break;
         default:
             assert false;
@@ -449,15 +503,15 @@ public final class WolfBBS{
     }
 
     /**
-     * 運命に対応する色Wiki表記を返す。
+     * 運命に対応する色を返す。
      *
      * @param destiny 運命
-     * @return 色Wiki表記
+     * @return 色
      */
-    public static String getDestinyColorWiki(Destiny destiny){
-        String result;
-        if(destiny == Destiny.ALIVE) result = "#ffffff";
-        else                         result = "#aaaaaa";
+    public static Color getDestinyColor(Destiny destiny){
+        Color result;
+        if(destiny == Destiny.ALIVE) result = COLOR_ALIVE;
+        else                         result = COLOR_DEAD;
         return result;
     }
 
index 299afdc..1d66056 100644 (file)
@@ -7,6 +7,7 @@
 
 package jp.sfjp.jindolf.summary;
 
+import java.awt.Color;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -46,6 +47,8 @@ public class GameSummary{
     public static final Comparator<Player> COMPARATOR_CASTING =
             new CastingComparator();
 
+    private static final Color COLOR_PLAINTABLE = new Color(0xedf5fe);
+
     private static final String GENERATOR =
             VerInfo.TITLE + "\u0020Ver." + VerInfo.VERSION;
 
@@ -694,6 +697,8 @@ public class GameSummary{
                 .append('\n');
         wikiText.append(WolfBBS.COMMENTLINE);
 
+        boolean even = true;
+
         for(Player player : getCastingPlayerList()){
             Avatar avatar   = player.getAvatar();
             GameRole role   = player.getRole();
@@ -720,34 +725,48 @@ public class GameSummary{
                     .append("]");
             wikiText.append(" ==========\n");
 
-            String teamColor =  "BGCOLOR("
-                              + WolfBBS.getTeamWikiColor(role)
+            Color teamColor    = WolfBBS.getTeamColor(role);
+            Color destinyColor = WolfBBS.getDestinyColor(destiny);
+            Color plainColor   = COLOR_PLAINTABLE;
+            if(even){
+                teamColor    = WolfBBS.evenColor(teamColor);
+                destinyColor = WolfBBS.evenColor(destinyColor);
+                plainColor   = WolfBBS.evenColor(plainColor);
+            }
+            even = ! even;
+
+            String teamWikiColor =  "BGCOLOR("
+                              + WolfBBS.cnvWikiColor(teamColor)
+                              + "):";
+            String destinyWikiColor = "BGCOLOR("
+                              + WolfBBS.cnvWikiColor(destinyColor)
+                              + "):";
+            String plainWikiColor = "BGCOLOR("
+                              + WolfBBS.cnvWikiColor(plainColor)
                               + "):";
 
             String avatarIcon = iconSet.getAvatarIconWiki(avatar);
 
-            wikiText.append('|').append(teamColor);
+            wikiText.append('|').append(teamWikiColor);
             wikiText.append(avatarIcon).append("&br;");
 
             wikiText.append("[[").append(avatar.getName()).append("]]");
 
-            wikiText.append('|').append(teamColor);
+            wikiText.append('|').append(teamWikiColor);
             wikiText.append("[[").append(WolfBBS.escapeWikiBracket(name));
             if(urlText != null && urlText.length() > 0){
                 wikiText.append('>').append(urlText);
             }
             wikiText.append("]]");
 
-            wikiText.append('|').append(teamColor);
+            wikiText.append('|').append(teamWikiColor);
             wikiText.append(WolfBBS.getRoleIconWiki(role));
             wikiText.append("&br;");
             wikiText.append("[[");
             wikiText.append(role.getRoleName());
             wikiText.append("]]");
 
-            String destinyColor = WolfBBS.getDestinyColorWiki(destiny);
-            wikiText.append('|');
-            wikiText.append("BGCOLOR(").append(destinyColor).append("):");
+            wikiText.append('|').append(destinyWikiColor);
             if(destiny == Destiny.ALIVE){
                 wikiText.append("最後まで&br;生存");
             }else{
@@ -755,7 +774,7 @@ public class GameSummary{
                 wikiText.append(destiny.getMessage());
             }
 
-            wikiText.append('|');
+            wikiText.append('|').append(plainWikiColor);
             wikiText.append(avatar.getJobTitle()).append('。');
 
             if(avatar == Avatar.AVATAR_GERD){
index 63a5de4..90b57e7 100644 (file)
@@ -6,8 +6,7 @@
 
 package jp.sfjp.jindolf.dxchg;
 
-import jp.sourceforge.jindolf.corelib.Destiny;
-import jp.sourceforge.jindolf.corelib.GameRole;
+import java.awt.Color;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -68,64 +67,31 @@ public class WolfBBSTest {
     }
 
     /**
-     * Test of getTeamWikiColor method, of class WolfBBS.
+     * Test of cnvWikiColor method, of class WolfBBS.
      */
     @Test
-    public void testGetTeamWikiColor() {
-        System.out.println("getTeamWikiColor");
+    public void testCnvWikiColor() {
+        System.out.println("cnvWikiColor");
 
         String result;
 
-        result = WolfBBS.getTeamWikiColor(GameRole.INNOCENT);
-        assertEquals("#b7bad3", result);
+        result = WolfBBS.cnvWikiColor(new Color(0x00, 0x00, 0x00));
+        assertEquals("#000000", result);
 
-        result = WolfBBS.getTeamWikiColor(GameRole.FRATER);
-        assertEquals("#b7bad3", result);
+        result = WolfBBS.cnvWikiColor(new Color(0x12, 0x34, 0x56));
+        assertEquals("#123456", result);
 
-        result = WolfBBS.getTeamWikiColor(GameRole.HUNTER);
-        assertEquals("#b7bad3", result);
+        result = WolfBBS.cnvWikiColor(new Color(0x01, 0x00, 0x00));
+        assertEquals("#010000", result);
 
-        result = WolfBBS.getTeamWikiColor(GameRole.SEER);
-        assertEquals("#b7bad3", result);
+        result = WolfBBS.cnvWikiColor(new Color(0x00, 0x00, 0x01));
+        assertEquals("#000001", result);
 
-        result = WolfBBS.getTeamWikiColor(GameRole.SHAMAN);
-        assertEquals("#b7bad3", result);
-
-        result = WolfBBS.getTeamWikiColor(GameRole.WOLF);
-        assertEquals("#e0b8b8", result);
-
-        result = WolfBBS.getTeamWikiColor(GameRole.MADMAN);
-        assertEquals("#e0b8b8", result);
-
-        result = WolfBBS.getTeamWikiColor(GameRole.HAMSTER);
-        assertEquals("#b9d0be", result);
-
-        return;
-    }
-
-    /**
-     * Test of getDestinyColorWiki method, of class WolfBBS.
-     */
-    @Test
-    public void testGetDestinyColorWiki() {
-        System.out.println("getDestinyColorWiki");
-
-        String result;
-
-        result = WolfBBS.getDestinyColorWiki(Destiny.ALIVE);
+        result = WolfBBS.cnvWikiColor(new Color(0xff, 0xff, 0xff));
         assertEquals("#ffffff", result);
 
-        result = WolfBBS.getDestinyColorWiki(Destiny.DISSOLVE);
-        assertEquals("#aaaaaa", result);
-
-        result = WolfBBS.getDestinyColorWiki(Destiny.EATEN);
-        assertEquals("#aaaaaa", result);
-
-        result = WolfBBS.getDestinyColorWiki(Destiny.EXECUTED);
-        assertEquals("#aaaaaa", result);
-
-        result = WolfBBS.getDestinyColorWiki(Destiny.SUDDENDEATH);
-        assertEquals("#aaaaaa", result);
+        result = WolfBBS.cnvWikiColor(new Color(0x12, 0x34, 0x56, 0x78));
+        assertEquals("#123456", result);
 
         return;
     }