/// <summary> /// Update the detail view with a puzzle /// </summary> /// <param name="puzzle">Puzzle.</param> public void SetPuzzle(PuzzleData puzzle) { ImagePuzzle.Image = UIImage.FromFile (puzzle.Filename); LabelTitle.Text = System.IO.Path.GetFileNameWithoutExtension (puzzle.Filename); DateTime? bestScore = puzzle.GetBestPlayerScore (GameCenterHelper.LocalPlayer.PlayerID); if (bestScore.HasValue) { LabelTime.Text = bestScore.Value.ToString ("mm:ss"); } else { LabelTime.Text = "Not completed yet"; } }
public static PuzzlesListCellViewController Create(PuzzleData puzzle) { PuzzlesListCellViewController cell = Nib.Instantiate (null, null) [0] as PuzzlesListCellViewController; cell.UpdatePuzzleView (puzzle); // Get components. Check XCode for tags. // 1 = image // 2 = friends icon // 3 = completed icon UIImageView imageView = cell.ViewWithTag (1) as UIImageView; imageView.Image = UIImage.FromFile (puzzle.Filename); UIImageView friendsIcon = cell.ViewWithTag (2) as UIImageView; friendsIcon.Hidden = !(puzzle.IsCustom); UIImageView completedIcon = cell.ViewWithTag (3) as UIImageView; completedIcon.Hidden = (puzzle.GetBestPlayerScore(GameCenterHelper.LocalPlayer.PlayerID).HasValue == false); return cell; }
/// <summary> /// Update versus match status /// </summary> public static void UpdateMatchFromPuzzle(PuzzleData puzzle, Action<NSError> callback) { if (puzzle.Match == null) { Logger.E ("This puzzle contains no match data... Can't do anything!"); return; } // Match data -> Puzzle + Image // -- Image as Base64 string UIImage image = UIImage.FromFile (puzzle.Filename); Byte[] byteArray = null; using (NSData nsImageData = image.AsPNG()) { byteArray = new Byte[nsImageData.Length]; System.Runtime.InteropServices.Marshal.Copy (nsImageData.Bytes, byteArray, 0, Convert.ToInt32 (nsImageData.Length)); } string base64image = Convert.ToBase64String (byteArray); // -- Data TransferablePuzzleData tp = new TransferablePuzzleData (); tp.Puzzle = puzzle; tp.Base64Image = base64image; // Build an XML text string xml = string.Empty; XmlSerializer xmlSerializer = new XmlSerializer (tp.GetType ()); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize (textWriter, tp); xml = textWriter.ToString (); } xmlSerializer = null; // Xml to bytes NSData puzzleData = NSData.FromString (xml); // Next participant GKTurnBasedParticipant nextPlayer = null; foreach (var participant in puzzle.Match.Participants) { if (participant.PlayerID != GKLocalPlayer.LocalPlayer.PlayerID) { nextPlayer = participant; break; } } // Game center match progress // -- Already an opponent score? End if (puzzle.GetBestPlayerScore (nextPlayer.PlayerID).HasValue) { puzzle.Match.EndMatchInTurn ( puzzleData, (err) => { if (callback != null) { callback (err); } } ); } else { // -- Send current score puzzle.Match.EndTurn ( new GKTurnBasedParticipant[] { nextPlayer }, 120, puzzleData, callback ); } }