freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 17 Nov 2009 14:06:21 +0100
changeset 150 cbae8c1b80dc
parent 141 8d5afaa13ee3
child 151 b9e67a17bd10
permissions -rw-r--r--
Supporting iPhone's viewport per Petr Dvorak's suggestion
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     2 <html>
     3   <head>
     4     <title>
     5       <#if user = doc.game.@currentPlayer>
     6          ${bundle.YourTurn}
     7       <#else>
     8          ${bundle("Waiting", doc.game.@currentPlayer?string)}
     9       </#if>
    10     </title>
    11     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    12     <#if user != doc.game.@currentPlayer >
    13         <meta http-equiv="REFRESH" content="60;URL=/games/${doc.game.id.@id}">
    14     </#if>
    15     <#if format?? && format="small">
    16         <meta name="viewport" content="width = 200" />
    17     <#else>
    18         <meta name="viewport" content="width = 460" />
    19     </#if>
    20     <script type="text/javascript">
    21         function paintFence() {
    22             var fifth = fieldSize / 10;
    23             var x = (document.getElementById("column").value.charCodeAt(0) - 64) * fieldSize;
    24             var y = fieldSize * 9 - (document.getElementById("row").value) * fieldSize;
    25             var dx = 0;
    26             var dy = 0;
    27             if (document.getElementById("direction").value.charAt(0) == 'H') {
    28                dx = fieldSize - 2 * fifth;
    29                dy = fifth / 2;
    30             } else {
    31                dx = fifth / 2;
    32                dy = fieldSize - 2 * fifth;
    33             }
    34             var fenceDiv = document.getElementById("fence");
    35             fenceDiv.style.position="absolute";
    36             fenceDiv.style.left = (x - dx) +"px";
    37             fenceDiv.style.top  = (y - dy) +"px";
    38             fenceDiv.style.width = (dx * 2) +"px";
    39             fenceDiv.style.height = (dy * 2) +"px";
    40             fenceDiv.style.backgroundColor = 'black';
    41             fenceDiv.style.visibility = 'visible';
    42          }
    43         function deltas(dir) {
    44             var r = new Object();
    45             r.x = 0;
    46             r.y = 0;
    47             if (dir == 'N') r.y = 1;
    48             if (dir == 'S') r.y = -1;
    49             if (dir == 'E') r.x = 1;
    50             if (dir == 'W') r.x = -1;
    51             return r;
    52         }
    53         function paintPlayer() {
    54             var fifth = fieldSize / 5;
    55             var m1 = deltas(document.getElementById("pdir1").value.charAt(0));
    56             var m2 = deltas(document.getElementById("pdir2").value.charAt(0));
    57 
    58             var pos = {
    59                 x : m1.x + m2.x + playerPos.x,
    60                 y : m1.y + m2.y + playerPos.y
    61             }
    62             var fenceDiv = document.getElementById("player");
    63             fenceDiv.style.position="absolute";
    64             fenceDiv.style.left = (pos.x * fieldSize + fifth) +"px";
    65             fenceDiv.style.top  = ((8 - pos.y) * fieldSize + fifth) +"px";
    66             fenceDiv.style.width = (fieldSize - fifth * 2) +"px";
    67             fenceDiv.style.height = (fieldSize - fifth * 2) +"px";
    68             fenceDiv.style.backgroundColor = 'black';
    69             fenceDiv.style.visibility = 'visible';
    70          }
    71          var fieldSize=<#if format?? && format="small">20<#else>50</#if>;
    72          var playerPos = {
    73              x: ${board.currentPlayer.column}, 
    74              y: ${board.currentPlayer.row}
    75         };
    76     </script>
    77   </head>
    78   <body>
    79       <h3><a href="/">${bundle.TITLE_PLAIN}</a></h3>
    80 
    81       <#macro status who>
    82           ${who?string}
    83           <#if who = doc.game.@currentPlayer>
    84               <#if doc.game.id.@status = "whiteWon" || doc.game.id.@status = "blackWon" >
    85                 - ${bundle.HAS_WON}
    86               <#else>
    87                 - ${bundle.TO_MOVE}
    88               </#if>
    89           </#if>
    90       </#macro>
    91 
    92 
    93       <p>
    94           <b>${bundle.MOVENUMBER}: </b> ${(doc.game.@currentMove?number / 2 + 1)?string("0")}<br>
    95           <b>${bundle.WHITE}:</b> <@status doc.game.id.@white/> ${bundle("FENCES_LEFT", board.players[0].fences)}<br>
    96           <b>${bundle.BLACK}:</b> <@status doc.game.id.@black/> ${bundle("FENCES_LEFT", board.players[1].fences)}<br>
    97       </p>
    98 
    99       <p>
   100       <#if (doc.game.@currentMove?number > 0)>
   101         <a href="/games/${doc.game.id.@id}?move=${doc.game.@currentMove?number - 1}">${bundle.PREVIOUS}</a>
   102       <#else>
   103         ${bundle.PREVIOUS}
   104       </#if>
   105       <a href="/games/${doc.game.id.@id}"">${bundle.LATEST}</a>
   106       <#if (doc.game.@currentMove?number < doc.game.moves.*?size)>
   107         <a href="/games/${doc.game.id.@id}?move=${doc.game.@currentMove?number + 1}">${bundle.NEXT}</a>
   108       <#else>
   109         ${bundle.NEXT}
   110       </#if>
   111       </p>
   112       
   113       <#if message?? >
   114         <p>
   115             <span style="color: red">${message}</span>
   116         </p>
   117       </#if>
   118 
   119       <#assign play = false>
   120 
   121       <#if doc.game.id.@status = "whiteMove" || doc.game.id.@status = "blackMove" >
   122           <#assign play = user = doc.game.@currentPlayer>
   123       </#if>
   124       <#if  play>
   125           <form action="/games/${doc.game.id.@id}/move">
   126               <input type="hidden" name="type" value="fence" readonly="readonly"/>
   127               <select name="column" id="column" onchange="paintFence()">
   128                   <option>A</option>
   129                   <option>B</option>
   130                   <option>C</option>
   131                   <option>D</option>
   132                   <option>E</option>
   133                   <option>F</option>
   134                   <option>G</option>
   135                   <option>H</option>
   136               </select>
   137               <select name="row" id="row" onchange="paintFence()">
   138                   <option>1</option>
   139                   <option>2</option>
   140                   <option>3</option>
   141                   <option>4</option>
   142                   <option>5</option>
   143                   <option>6</option>
   144                   <option>7</option>
   145                   <option>8</option>
   146               </select>
   147               <select name="direction" id="direction" onchange="paintFence()">
   148                   <option value="H">${bundle.H}</option>
   149                   <option value="V">${bundle.V}</option>
   150               </select>
   151               <input type="submit" value="${bundle.PLACE}" />
   152           </form>
   153           <form action="/games/${doc.game.id.@id}/move">
   154               <input type="hidden" name="type" value="move" readonly="readonly"/>
   155               <select id="pdir1" name="direction" onchange="paintPlayer()">
   156                   <option value="E">${bundle.E}</option>
   157                   <option value="W">${bundle.W}</option>
   158                   <option value ="N" <#if doc.game.id.@status = "whiteMove">selected="true"</#if>>${bundle.N}</option>
   159                   <option value ="S" <#if doc.game.id.@status = "blackMove">selected="true"</#if>>${bundle.S}</option>
   160               </select>
   161               <select id="pdir2" name="direction-next" onchange="paintPlayer()">
   162                   <option></option>
   163                   <option value="E">${bundle.E}</option>
   164                   <option value="W">${bundle.W}</option>
   165                   <option value="N">${bundle.N}</option>
   166                   <option value="S">${bundle.S}</option>
   167               </select>
   168               <input type="submit" value="${bundle.MOVE}" />
   169           </form>
   170           <form action="/games/${doc.game.id.@id}/move">
   171               <input type="hidden" name="type" value="resign" readonly="readonly"/>
   172               <input type="submit" value="${bundle.RESIGN}" />
   173           </form>
   174       </#if>
   175       <p>
   176       <#if format?? && format = "text">
   177         <pre>${doc.game.board}</pre>
   178         ${bundle.BOARD_VIEW}
   179         <a href="/games/${doc.game.id.@id}?format=small">${bundle.BOARD_SMALL}</a>
   180         <a href="/games/${doc.game.id.@id}?format=image">${bundle.BOARD_IMAGE}</a>
   181         ${bundle.BOARD_TEXT}
   182       <#elseif format?? && format = "small">
   183         <p/>
   184         <div style="position: relative; height:180px;">
   185             <img style="position: absolute; left: 0; right: 0;"
   186                  width="180" height="180 "
   187                  src="/games/${doc.game.id.@id}.png?fieldSize=20<#if doc.game.@currentMove??>&move=${doc.game.@currentMove}</#if>"
   188                  alt="${bundle.BOARD_TEXT}"
   189              >
   190             <div id="fence" style="position: absolute; left: 0; right: 0;"></div>
   191             <div id="player" style="position: absolute; left: 0; right: 0;"></div>
   192         </div>
   193         ${bundle.BOARD_VIEW}
   194         ${bundle.BOARD_SMALL}
   195         <a href="/games/${doc.game.id.@id}?format=image">${bundle.BOARD_IMAGE}</a>
   196         <a href="/games/${doc.game.id.@id}?format=text">${bundle.BOARD_TEXT}</a>
   197       <#else>
   198         <div style="position: relative; height:450px;">
   199             <img style="position: absolute; left: 0; right: 0;"
   200                  width="450" height="450"
   201                  src="/games/${doc.game.id.@id}.png<#if doc.game.@currentMove??>?move=${doc.game.@currentMove}</#if>"
   202                  alt="${bundle.BOARD_TEXT}"
   203              >
   204             <div id="fence" style="position: absolute; left: 0; right: 0;"></div>
   205             <div id="player" style="position: absolute; left: 0; right: 0;"></div>
   206         </div>
   207         ${bundle.BOARD_VIEW}
   208         <a href="/games/${doc.game.id.@id}?format=small">${bundle.BOARD_SMALL}</a>
   209         ${bundle.BOARD_IMAGE}
   210         <a href="/games/${doc.game.id.@id}?format=text">${bundle.BOARD_TEXT}</a>
   211       </#if>
   212 
   213       <#macro printMove item>
   214         <#if item.@index = doc.game.@currentMove>
   215             <b>${item.@move}</b>
   216         <#else>
   217             <a href="/games/${doc.game.id.@id}?move=${item.@index}">${item.@move}</a>
   218         </#if>
   219       </#macro>
   220 
   221       <h3><a href="/games/${doc.game.id.@id}?move=0">${bundle.MOVES}</a></h3>
   222 
   223       <table border="0">
   224           <thead>
   225               <tr>
   226                   <th>${bundle.MOVENUMBER}</th>
   227                   <th>${doc.game.id.@white}</th>
   228                   <th>${doc.game.id.@black}</th>
   229               </tr>
   230           </thead>
   231           <tbody>
   232               <#assign index = 0>
   233               <#list doc.game.moves.* as item>
   234                 
   235                 <#if item.@index?number % 2 = 1>
   236                     <#assign index = index + 1>
   237                     <tr><td>${index}</td><td><@printMove item/></td>
   238                 <#else>
   239                     <td><@printMove item/></td></tr>
   240                 </#if>
   241               </#list>
   242           </tbody>
   243       </table>
   244 
   245       <h3>${bundle.TALK}</h3>
   246 
   247       <ul>
   248       <#list doc.game.moves.item.comment as item>
   249         <li><b>${item.@who}</b>: ${item}</li>
   250       </#list>
   251       </ul>
   252 
   253       <form action="/games/${doc.game.id.@id}/comment">
   254           <textarea rows="2" cols="80" name="comment"></textarea>
   255           <input type="submit"/>
   256       </form>
   257 
   258       <hr/>
   259       ${bundle("copyright", version)}
   260   </body>
   261 </html>