Permalink
Browse files

Cherry picked preview and hide moves features from vDip

  • Loading branch information...
1 parent f5bfd7a commit 60e597a1c52ac7b5d5cd46101c201ec21cc23095 @Sleepcap Sleepcap committed with TimothyJones Nov 13, 2012
@@ -60,6 +60,10 @@ function mapHTML() {
<a href="#" onClick="loadMap('.$this->id.','.$mapTurn.','.$mapTurn.'); return false;">
<img id="End" src="'.l_s('images/historyicons/End_disabled.png').'" alt="'.l_t('End').'" title="'.l_t('View the map from the most recent turn').'" />
</a>
+ <a href="#" onClick="togglePreview('.$this->id.','.$mapTurn.'); return false;">
+ <img id="Preview" src="images/historyicons/Preview.png" alt="PreviewMoves" title="Show server side stored orders on the map" />
+ </a>
+
</p>
<p id="History" class="lightgrey"></p>
</div>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -21,6 +21,44 @@
// Current turn, -2 is undefined, -1 is pre-game
var turn=-2;
+var noMoves='';
+var preview='';
+
+// Toggle the display of the Move arrows.
+function toggleMoves(gameID, currentTurn) {
+ if (noMoves == '') {
+ noMoves = '&hideMoves';
+ $('NoMoves').src = 'images/historyicons/showmoves.png';
+ } else {
+ noMoves = '';
+ $('NoMoves').src = 'images/historyicons/hidemoves.png';
+ }
+ loadMapStep(gameID, currentTurn, 0)
+ loadMap(gameID, currentTurn, turn)
+}
+
+// Toggle the display of the Move arrows.
+function togglePreview(gameID, currentTurn) {
+ turn = currentTurn
+ if (preview == '') {
+ preview = '&preview&noCache=' + Math.floor((Math.random()*10000)+1); ;
+ $('Start').style.visibility = 'hidden';
+ $('Backward').style.visibility = 'hidden';
+ $('NoMoves').style.visibility = 'hidden';
+ $('Forward').style.visibility = 'hidden';
+ $('End').style.visibility = 'hidden';
+ } else {
+ preview = '';
+ $('Start').style.visibility = 'visible';
+ $('Backward').style.visibility = 'visible';
+ $('NoMoves').style.visibility = 'visible';
+ $('Forward').style.visibility = 'visible';
+ $('End').style.visibility = 'visible';
+ }
+ loadMapStep(gameID, currentTurn, 0)
+ loadMap(gameID, currentTurn, turn)
+}
+
// Increment or decrement the turn safely, factoring in the limits, then load the new turn
function loadMapStep(gameID, currentTurn, step)
{
@@ -87,6 +125,12 @@ function loadMap(gameID, currentTurn, newTurn)
$('History').show();
}
+ // Add the Hide parameter if we have HideMoves activated
+ newTurn = newTurn + noMoves
+
+ // Add the Preview parameter if we have Preview activated
+ newTurn = newTurn + preview
+
// Update the link to the large map
$('LargeMapLink').innerHTML =
' <a href="map.php?gameID='+gameID+'&turn='+newTurn+'&mapType=large" target="blank" class="light">'+
@@ -96,4 +140,4 @@ function loadMap(gameID, currentTurn, newTurn)
// Update the source for the map image
$('mapImage').src = 'map.php?gameID='+gameID+'&turn='+newTurn;
-}
+}
@@ -142,6 +142,14 @@ function OrdersHTMLFormClass() {
},this);
this.updateFormButtons();
+
+ // Small addition for the preview-window to update on Save or Ready.
+ if (preview != '')
+ {
+ preview = '';
+ togglePreview(this.context.gameID, this.context.turn);
+ }
+
}
};
View
@@ -36,8 +36,40 @@
define('DELETECACHE',1);
else
define('DELETECACHE',0);
-
+
if( !IGNORECACHE )
+// Check if we should hide the move arrows. (Preview do not need the old move-arrows too...)
+if( isset($_REQUEST['hideMoves']) || isset($_REQUEST['preview']))
+ define('HIDEMOVES',1);
+else
+ define('HIDEMOVES',0);
+
+// Check if we need to color enhance the map
+if( isset($_REQUEST['colorCorrect']))
+{
+ switch($_REQUEST['colorCorrect']) {
+ case 'Protanope': define('COLORCORRECT','Protanope'); break;
+ case 'Deuteranope': define('COLORCORRECT','Deuteranope'); break;
+ case 'Tritanope': define('COLORCORRECT','Tritanope'); break;
+ default: define('COLORCORRECT',0);
+ }
+}
+else
+ define('COLORCORRECT',0);
+
+// Check if we should hide the move arrows.
+if( isset($_REQUEST['preview']))
+ define('PREVIEW',1);
+else
+ define('PREVIEW',0);
+
+// Check if we need to show CountryNames
+if( isset($_REQUEST['countryNames']))
+ define('COUNTRYNAMES',1);
+else
+ define('COUNTRYNAMES',0);
+
+if( !IGNORECACHE && !PREVIEW)
{
// We might be able to fetch the map from the cache
@@ -47,7 +79,11 @@
require_once('lib/cache.php');
$filename = Game::mapFilename((int)$_REQUEST['gameID'], (int)$_REQUEST['turn']);
-
+
+ // Map without arrows
+ if (HIDEMOVES)
+ $filename = str_replace(".map","-hideMoves.map",$filename);
+
if( file_exists($filename) )
{
header("Last-Modified: Mon, 26 Jul 1997 05:00:00 GMT");
@@ -314,11 +350,11 @@
if ( $success ) $drawToTerrID = $toTerrID;
else $drawToTerrID = $terrID;
- $drawMap->drawMove($terrID, $toTerrID, $success);
+ if (!HIDEMOVES) $drawMap->drawMove($terrID, $toTerrID, $success);
}
elseif ( $moveType == 'Retreat' )
{
- $drawMap->drawRetreat($terrID, $toTerrID, $success);
+ if (!HIDEMOVES) $drawMap->drawRetreat($terrID, $toTerrID, $success);
if ( $success ) $drawToTerrID = $toTerrID;
else continue;
@@ -339,20 +375,20 @@
if ( $moveType == 'Support hold' )
{
- $drawMap->drawSupportHold($terrID,
+ if (!HIDEMOVES) $drawMap->drawSupportHold($terrID,
isset($deCoastMap['SupportHoldToTerrID'][$toTerrID]) ? $deCoastMap['SupportHoldToTerrID'][$toTerrID] : $toTerrID,
$success);
}
elseif ( $moveType == 'Support move' )
{
- $drawMap->drawSupportMove($terrID,
+ if (!HIDEMOVES) $drawMap->drawSupportMove($terrID,
isset($deCoastMap['SupportMoveFromTerrID'][$fromTerrID]) ? $deCoastMap['SupportMoveFromTerrID'][$fromTerrID] : $fromTerrID,
isset($deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID]) ? $deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID] : $toTerrID,
$success);
}
elseif ( $moveType == 'Convoy' )
{
- $drawMap->drawConvoy($terrID, $fromTerrID, $toTerrID, $success);
+ if (!HIDEMOVES) $drawMap->drawConvoy($terrID, $fromTerrID, $toTerrID, $success);
}
/*
@@ -376,12 +412,81 @@
}
}
-foreach( $destroyedTerrs as $terrID ) $drawMap->drawDestroyedUnit(isset($deCoastMap['DestroyToTerrID'][$terrID]) ? $deCoastMap['DestroyToTerrID'][$terrID] : $terrID );
-foreach( $dislodgedTerrs as $terrID ) $drawMap->drawDislodgedUnit($terrID);
-foreach( $builtTerrs as $terrID=>$unitType ) $drawMap->drawCreatedUnit($terrID, $unitType);
+foreach( $destroyedTerrs as $terrID )
+ if (!HIDEMOVES) $drawMap->drawDestroyedUnit(isset($deCoastMap['DestroyToTerrID'][$terrID]) ? $deCoastMap['DestroyToTerrID'][$terrID] : $terrID );
+foreach( $dislodgedTerrs as $terrID )
+ if (!HIDEMOVES) $drawMap->drawDislodgedUnit($terrID);
+foreach( $builtTerrs as $terrID=>$unitType )
+ if (!HIDEMOVES) $drawMap->drawCreatedUnit($terrID, $unitType);
// support hold to, support move from, support move to, build/destroy fleet
+// Map is drawn, now add a preview of the server-side orders...
+if (PREVIEW && $Game->Members->isJoined())
+{
+ $sql = "SELECT u.type, u.terrID, o.type, o.toTerrID, o.fromTerrID, o.viaConvoy
+ FROM wD_Orders o
+ LEFT JOIN wD_Units u ON (u.id = o.unitID)
+ WHERE o.gameID = ".$Game->id." AND o.countryID = ".$Game->Members->ByUserID[$User->id]->countryID."
+ ORDER BY FIELD(o.type, 'Move')";
+
+ $tabl = $DB->sql_tabl($sql);
+
+ while(list($unitType, $terrID, $orderType, $toTerrID, $fromTerrID, $viaConvoy) = $DB->tabl_row($tabl))
+ {
+ if ($orderType == 'Move')
+ {
+ $drawMap->drawMove($terrID, $toTerrID, true);
+ }
+ elseif ( $orderType == 'Support hold' )
+ {
+ $drawMap->drawSupportHold($terrID,
+ isset($deCoastMap['SupportHoldToTerrID'][$toTerrID]) ? $deCoastMap['SupportHoldToTerrID'][$toTerrID] : $toTerrID,
+ true);
+ }
+ elseif ( $orderType == 'Support move' )
+ {
+ $drawMap->drawMoveGrey(isset($deCoastMap['SupportMoveFromTerrID'][$fromTerrID]) ? $deCoastMap['SupportMoveFromTerrID'][$fromTerrID] : $fromTerrID,
+ isset($deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID]) ? $deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID] : $toTerrID,
+ true);
+ $drawMap->drawSupportMove($terrID,
+ isset($deCoastMap['SupportMoveFromTerrID'][$fromTerrID]) ? $deCoastMap['SupportMoveFromTerrID'][$fromTerrID] : $fromTerrID,
+ isset($deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID]) ? $deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID] : $toTerrID,
+ true);
+ }
+ elseif ( $orderType == 'Convoy' )
+ {
+ $drawMap->drawMoveGrey(isset($deCoastMap['SupportMoveFromTerrID'][$fromTerrID]) ? $deCoastMap['SupportMoveFromTerrID'][$fromTerrID] : $fromTerrID,
+ isset($deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID]) ? $deCoastMap['SupportMoveToTerrID'][$fromTerrID.'-'.$toTerrID] : $toTerrID,
+ true);
+ $drawMap->drawConvoy($terrID, $fromTerrID, $toTerrID, true);
+ }
+ if ($orderType == 'Build Army')
+ {
+ $drawMap->drawCreatedUnit($toTerrID,'Army');
+ }
+ if ($orderType == 'Build Fleet')
+ {
+ $drawMap->drawCreatedUnit($toTerrID,'Fleet');
+ }
+ if ($orderType == 'Retreat')
+ {
+ $drawMap->countryFlag($terrID, $Game->Members->ByUserID[$User->id]->countryID);
+ $drawMap->addUnit($terrID, $unitType);
+ $drawMap->drawRetreat($terrID, $toTerrID, true);
+ }
+ if ($orderType == 'Destroy')
+ {
+ $drawMap->drawDestroyedUnit(isset($deCoastMap['DestroyToTerrID'][$toTerrID]) ? $deCoastMap['DestroyToTerrID'][$toTerrID] : $toTerrID );
+ }
+
+ $drawMap->caption('Preview');
+ $drawMap->drawRedBox();
+
+ }
+
+}
+
/*
* Territories colored, orders entered, units drawn on.
* Now add territory names, and game-over caption if finished
@@ -411,12 +516,30 @@
$filename = Game::mapFilename($Game->id, $turn);
+if (HIDEMOVES)
+ $filename = str_replace(".map","-hideMoves.map",$filename);
+
if( defined('DATC') && $mapType!='small')
$drawMap->saveThumbnail($filename.'-thumb');
+if (PREVIEW)
+ $filename = libCache::dirID('users',$User->id).'/preview-'. md5($User->password.Config::$secret).'.map';
+
+// colorCorrect Patch
+if (COLORCORRECT)
+{
+ $filename = str_replace(".map","-".COLORCORRECT.".map",$filename);
+ $drawMap->colorEnhance(COLORCORRECT);
+}
+// End colorCorrect Patch
+
+// Add countrynames for colorblind:
+if (COUNTRYNAMES)
+ $filename = str_replace(".map","-names.map",$filename);
+
$drawMap->write($filename);
unset($drawMap); // $drawMap is memory intensive and should be freed as soon as no longer needed
libHTML::serveImage($filename);
-?>
+?>
View
@@ -686,6 +686,40 @@ public function drawMove($fromTerrID, $toTerrID, $success)
}
/**
+ * Draw a move arrow (but only in grey)
+ * Usefull for the Preview-function to draw the corresponding move-arrow for convoy and support commands
+ * @param string $fromTerrID Territory moving unit moved from
+ * @param string $toTerrID Territory moving unit moved to
+ * @param bool $success Move successful or not
+ */
+ public function drawMoveGrey($fromTerrID, $toTerrID, $success)
+ {
+ list($fromX, $fromY) = $this->territoryPositions[$fromTerrID];
+ list($toX, $toY) = $this->territoryPositions[$toTerrID];
+
+ // Rotate the arrow slightly, so that head-to-heads are more clear
+ //list($fromX, $fromY, $toX, $toY) = self::rotate(array($fromX, $fromY, $toX, $toY),
+ // array($fromX-($fromX-$toX)/2, $fromY-($fromY-$toY)/2), M_PI/15);
+
+ $this->drawOrderArrow(array($fromX, $fromY), array($toX, $toY), 'MoveGrey');
+
+ if ( !$success ) $this->drawFailure(array($fromX, $fromY), array($toX, $toY));
+ }
+
+ /**
+ * Draw a red alert boy around the image...
+ * Usefull for the Preview-function
+ */
+ public function drawRedBox()
+ {
+ $red=$this->color(array(240,20,20),$this->map['image']);
+ self::imagelinethick($this->map['image'],0, 0, 0, $this->map['height'], $red, 8);
+ self::imagelinethick($this->map['image'],0, $this->map['height'], $this->map['width'], $this->map['height'], $red, 8);
+ self::imagelinethick($this->map['image'],$this->map['width'], $this->map['height'], $this->map['width'], 0, $red, 8);
+ self::imagelinethick($this->map['image'], $this->map['width'], 0, 0, 0, $red, 8);
+ }
+
+ /**
* Draw a support hold arrow
* @param string $fromTerrID Territory supporting unit supporting from
* @param string $toTerrID Territory supporting unit supported to
@@ -863,6 +897,13 @@ public function write($filename)
'headLength'=>array(12,30),
'border'=>array(0,0)
),
+ 'MoveGrey' => array('color'=>array(100,100,100), // Same as move, but arrowcolor=grey
+ 'thickness'=>array(2,4),
+ 'headAngle'=>7,
+ 'headStart'=>.1,
+ 'headLength'=>array(12,30),
+ 'border'=>array(0,0)
+ ),
'Support hold' => array('color'=>array(67,206,16),
'thickness'=>array(2,4),
'headAngle'=>2,
@@ -1154,7 +1195,7 @@ protected static function imagesquareline($image, $x1, $y1, $x2, $y2, $color, $t
}
/**
- * Write a caption; a large piece of text centered in the map
+ * Write a captioncaptioncaptioncaptioncaptioncaptioncaptioncaptioncaptioncaptioncaptioncaptioncaption; a large piece of text centered in the map
*
* @param string $text
*/

0 comments on commit 60e597a

Please sign in to comment.