From 077ab356084fa26910200f28a9cd44a954f291eb Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sun, 1 Jun 2008 01:17:36 -0700 Subject: [PATCH] LAYOUT: moved score table and rules to the top removed more of the side layout into the top session bar. removed the list of games in a session and have it now accessable via the score table Signed-off-by: Arun Persaud --- css/{standard005.css => standard006.css} | 61 ++++++++--- include/functions.php | 131 ++++++++++++++++++----- include/game.php | 71 ++++-------- include/output.php | 8 +- 4 files changed, 175 insertions(+), 96 deletions(-) rename css/{standard005.css => standard006.css} (91%) diff --git a/css/standard005.css b/css/standard006.css similarity index 91% rename from css/standard005.css rename to css/standard006.css index 24ffb30..5e9b335 100644 --- a/css/standard005.css +++ b/css/standard006.css @@ -337,10 +337,53 @@ ul.tricks li div div span.comment span{ border-bottom:1px solid black; text-align:center; } +div.session div.sessionrules { + width:19em; + float:left ; + text-align: left; +} +div.session div.sessionscore { + width:19em; + float:right ; + text-align: right; +} +div.session div.sessionrules div{ + display:none; + background-color: white; + border: 1px solid black; + position:absolute; + z-index: 30; + padding:0.5em; +} +div.session div.sessionrules:hover div{ + display:block; +} +div.session div.sessionscore div{ + position:absolute; + width:12em; + right:0em; + display:none; + background-color: white; + border: 1px solid black; + z-index: 30; +} +div.session div.sessionscore:hover div{ + display:block; +} + +.scoretable{ + height:20em; + overflow: auto; +} +table.score { + margin:0.5em; + width:10em; + border-collapse:collapse; +} -.gameinfo, .useroptions { +.gameinfo { position:absolute; - top:10em; + top:27em; right:0em; margin:1em; margin-top:0em; @@ -354,7 +397,7 @@ ul.tricks li div div span.comment span{ padding:0.3em; - background-color: #eee; + background-color: #efefef; } .usermenu { @@ -448,15 +491,6 @@ div span img.button { background-color: #15de26; } -.scoretable{ - height:10em; - overflow: auto; -} -table.score { - width:10em; - border-collapse:collapse; -} - .bigger { font-size:larger; } @@ -484,4 +518,5 @@ table.stats td, table.stats th { } table.stats tr td:last-child, table.stats tr th:last-child { border-right: solid 0 black; } -table.stats th { border-bottom: solid 0.2em black } \ No newline at end of file +table.stats th { border-bottom: solid 0.2em black } + diff --git a/include/functions.php b/include/functions.php index 7b29a28..fafcf36 100644 --- a/include/functions.php +++ b/include/functions.php @@ -863,7 +863,7 @@ function display_user_menu() echo "
\n"; echo "It's your turn in these games:
\n"; } - + $i++; echo "game ".DB_format_gameid($r[1])."
\n"; if($i>4) @@ -880,14 +880,20 @@ function display_user_menu() function generate_score_table($session) { + /* returns an array with N entries + * $score[$i]["gameid"] = gameid + * $score[$i]["players"] = array (id=>total points) + * $score[$i]["points"] = points for this game + * $score[$i]["solo"] = 1 or 0 + */ + $score = array(); + $i=0; + /* get all ids */ $gameids = DB_get_gameids_of_finished_games_by_session($session); if($gameids == NULL) - return ""; - - $output = "
\n\n \n"; - + return $score; /* get player id, names... from the first game */ $player = array(); @@ -895,42 +901,32 @@ function generate_score_table($session) " LEFT JOIN User On Hand.user_id=User.id". " WHERE Hand.game_id=".$gameids[0]); while( $r = DB_fetch_array($result)) - { - $player[] = array( 'id' => $r[0], 'points' => 0 ); - $output.= " \n"; - } - $output.=" \n \n"; + $player[$r[0]] = 0; /* get points and generate table */ foreach($gameids as $gameid) { - $output.=" \n"; - $re_score = DB_get_score_by_gameid($gameid); - foreach($player as $key=>$pl) + foreach($player as $id=>$points) { - $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']); + $party = DB_get_party_by_gameid_and_userid($gameid,$id); if($party == "re") if(DB_get_gametype_by_gameid($gameid)=="solo") - $player[$key]['points'] += 3*$re_score; + $player[$id] += 3*$re_score; else - $player[$key]['points'] += $re_score; + $player[$id] += $re_score; else if ($party == "contra") - $player[$key]['points'] -= $re_score; - - $output.=" \n"; + $player[$id] -= $re_score; } - $output.=" \n \n"; + $i++; } - $output.="
".substr($r[1],0,2)." P
".$player[$key]['points']."".abs($re_score); + $score[$i]['gameid'] = $gameid ; + $score[$i]['players'] = $player; + $score[$i]['points'] = abs($re_score); + $score[$i]['solo'] = (DB_get_gametype_by_gameid($gameid)=="solo"); - /* check for solo */ - if(DB_get_gametype_by_gameid($gameid)=="solo") - $output.= " S"; - $output.="
\n"; - - return $output; + return $score; } function generate_global_score_table() @@ -994,6 +990,87 @@ function generate_global_score_table() return $return; } +function format_score_table_ascii($score) +{ + $output=""; + if(sizeof($score)==0) + return ""; + + // if(sizeof($score)>5) $header.= " ... \n"; + + /* output header */ + foreach($score[0]['players'] as $id=>$points) + { + $name = DB_get_name('userid',$id); /*TODO*/ + $output.= " ".substr($name,0,2)." |"; + } + $output.=" P |\n "; + $output.= "------+------+------+------+------+\n"; + + $max = sizeof($score); + $i=0; + + if($i<$max-6) $output.=" ...\n"; + + foreach($score as $game) + { + $i++; + if($i-1<$max-6) continue; + foreach($game['players'] as $id=>$points) + $output.=str_pad($points,6," ",STR_PAD_LEFT)."|"; + $output.=str_pad($game['points'],4," ",STR_PAD_LEFT); + + /* check for solo */ + if($game['solo']) + $output.= " S|"; + else + $output.= " |"; + + $output.="\n"; + } + return $output; +} + +function format_score_table_html($score,$userid) +{ + global $INDEX; + + if(sizeof($score)==0) + return ""; + + $output = "
\n\n \n"; + + /* output header */ + $output.= " "; + foreach($score[0]['players'] as $id=>$points) + { + $name = DB_get_name('userid',$id); /*TODO*/ + $output.= ""; + } + $output.="\n \n\n\n"; + + $i=0; + foreach($score as $game) + { + $i++; + $output.=" "; + $userhash = DB_get_hash_from_gameid_and_userid($game['gameid'],$userid); + $output.=" "; + foreach($game['players'] as $id=>$points) + $output.=""; + $output.="\n"; + } + + $output.="\n
Nr ".substr($name,0,2)." P
$i".$points."".$game['points']; + + /* check for solo */ + if($game['solo']) + $output.= " S"; + $output.="
\n"; + + return $output; +} + ?> diff --git a/include/game.php b/include/game.php index 3fbc451..4f506f5 100644 --- a/include/game.php +++ b/include/game.php @@ -112,18 +112,28 @@ echo "
\n"; /* output extra division in case this game is part of a session */ if($session) { - echo "
\n". - "This game is part of session $session: \n"; + echo "
\n"; + echo "
Rules (+icons fur rules) \n"; + echo "
\n"; + echo " 10ofhearts : ".$RULES["dullen"] ."
\n"; + echo " schweinchen: ".$RULES["schweinchen"] ."
\n"; + echo " call: ".$RULES["call"] ."
\n"; + echo "
\n
\n"; + echo "
Score \n"; + $score = generate_score_table($session); + echo format_score_table_html($score,$myid); + echo "
\n"; $hashes = DB_get_hashes_by_session($session,$myid); $i = 1; foreach($hashes as $hash) { - if($hash == $me) - echo "$i \n"; - else - echo "$i \n"; - $i++; + if($hash == $me) + $j=$i; + $i++; + $lasthash=$hash; } + $i--; + echo "This is game number $j of $i in session $session."; echo "
\n"; } @@ -1649,35 +1659,9 @@ switch($mystatus) $session = DB_get_session_by_gameid($gameid); $score = generate_score_table($session); - /* convert html to ascii */ - $score = str_replace("
\n\n \n","",$score); - $score = str_replace("
\n","",$score); - $score = str_replace("\n","",$score); - $score = str_replace(array("","","",""),array("","\n","","|"),$score); - $score = explode("\n",$score); - - $header = array_slice($score,0,1); - $header = explode("|",$header[0]); - for($i=0;$i5) $header.= " ... \n"; - - if(sizeof($score)>5) $score = array_slice($score,-5,5); - for($i=0;$i\n"; - echo "Insert note:\n"; + echo "\n"; echo "
\n"; $mycards = DB_get_hand($me); @@ -1869,15 +1853,6 @@ switch($mystatus) /* display rule set for this game */ echo "
\n"; - if($gamestatus != 'pre') - echo " Gametype: $GT
\n"; - - echo "Rules:
\n"; - echo "10ofhearts : ".$RULES["dullen"] ."
\n"; - echo "schweinchen: ".$RULES["schweinchen"] ."
\n"; - echo "call: ".$RULES["call"] ."
\n"; - - echo "
\n"; if($gamestatus == 'play' ) output_form_calls($me); @@ -1888,15 +1863,9 @@ switch($mystatus) if($gamestatus == 'play' || $gameend < 60*60*24*7) { echo "
\nA short comment:\n"; - echo "
"; } - echo "\n
\n"; - - $session = DB_get_session_by_gameid($gameid); - $score = generate_score_table($session); - - echo $score; + echo "\n"; echo "
\n"; diff --git a/include/output.php b/include/output.php index 2fcfaca..86db0a0 100644 --- a/include/output.php +++ b/include/output.php @@ -99,9 +99,9 @@ function output_table($data,$caption="",$class="") $HTML = "\n\n"; else $HTML = "\n
\n"; - + $i=0; - + if($caption!="") $HTML .= " \n"; @@ -270,7 +270,7 @@ function output_header() e-Doko - +
$caption