]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Center worldmap on screen.
authorOskar Wiksten <oskar.wiksten@gmail.com>
Sun, 14 Oct 2012 11:41:59 +0000 (13:41 +0200)
committerOskar Wiksten <oskar.wiksten@gmail.com>
Sun, 14 Oct 2012 11:41:59 +0000 (13:41 +0200)
AndorsTrail/res/values/worldmap_template.xml
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/WorldMapController.java

index 4ea5c1fa926da5ea7825ebc6f349f80f9c9281d0..fbf0c339457ba0f23b86fd7bb31fdf82a614a874 100644 (file)
@@ -6,22 +6,28 @@
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
        <title></title>
        <style type=\"text/css\">
-#playerPosition { position: absolute; z-index: 3; font-size: 19pt; color: red; text-shadow: rgba(0, 0, 0, 1) 2px 2px 2px; }
-img { z-index: 1; position: absolute; }
-.namedarea { position: absolute; z-index: 2; font-size: 16pt; text-shadow: black 0.1em 0.1em 0.2em; text-align: center; }
-.namedarea span { display: inline-block; vertical-align: middle; line-height: 1em; }
-.settlement { color: white; }
-.other { color: #cccccc; }
+html, body { height:100%%; padding:0; margin:0; }
+div#table { height:100%%; width:100%%; display:table; }
+div#cell { display:table-cell; vertical-align:middle; text-align:center;}
+div#maps { width:{{sizex}}px; height:{{sizey}}px; position:relative; display:inline-block; }
+div#playerPosition { position:absolute; z-index:3; font-size:19pt; color:red; text-shadow:rgba(0, 0, 0, 1) 2px 2px 2px; }
+img { z-index:1; position:absolute; }
+.namedarea { position: absolute; z-index:2; font-size:16pt; text-shadow:black 0.1em 0.1em 0.2em; text-align:center; }
+.namedarea span { display:inline-block; vertical-align:middle; line-height:1em; }
+.settlement { color:white; }
+.other { color:#cccccc; }
        </style>
 </head>
 <body>
 
+<div id=\"table\">
+<div id=\"cell\">
 <div id=\"maps\">
-       
 {{maps}}
 {{areas}}
-       
-       <div id=\"playerPosition\">x</div>
+<div id=\"playerPosition\">x</div>
+</div>
+</div>
 </div>
 
 <script type=\"text/javascript\">
index c3ab96ee917f1cf1f68f282dd8559c8f2b851cf1..ced405918fd61063a77cadb47df0b3cb1ef7cd8a 100644 (file)
@@ -176,6 +176,8 @@ public final class WorldMapController {
                        offsetWorldmapTo.y = Math.min(offsetWorldmapTo.y, map.worldPosition.y);
                }
                
+               Coord bottomRight = new Coord(0, 0);
+               
                StringBuffer mapsAsHtml = new StringBuffer();
                for (WorldMapSegmentMap segmentMap : segment.maps.values()) {
                        File f = WorldMapController.getFileForMap(segmentMap.mapName);
@@ -197,7 +199,14 @@ public final class WorldMapController {
                                .append((segmentMap.worldPosition.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
                                .append("px;\" />");
                        if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) mapsAsHtml.append("\n");
+                       
+                       bottomRight.x = Math.max(bottomRight.x, segmentMap.worldPosition.x + size.width);
+                       bottomRight.y = Math.max(bottomRight.y, segmentMap.worldPosition.y + size.height);
                }
+               Size worldmapSegmentSize = new Size(
+                               (bottomRight.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
+                               ,(bottomRight.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
+                       );
                
                StringBuffer namedAreasAsHtml = new StringBuffer();
                for (NamedWorldMapArea area : segment.namedAreas.values()) {
@@ -223,6 +232,8 @@ public final class WorldMapController {
                return res.getString(R.string.worldmap_template)
                                .replace("{{maps}}", mapsAsHtml.toString())
                                .replace("{{areas}}", namedAreasAsHtml.toString())
+                               .replace("{{sizex}}", Integer.toString(worldmapSegmentSize.width))
+                               .replace("{{sizey}}", Integer.toString(worldmapSegmentSize.height))
                                .replace("{{offsetx}}", Integer.toString(offsetWorldmapTo.x * WorldMapController.WORLDMAP_DISPLAY_TILESIZE))
                                .replace("{{offsety}}", Integer.toString(offsetWorldmapTo.y * WorldMapController.WORLDMAP_DISPLAY_TILESIZE));
        }