/// <summary> /// called by a child GUI component to launch a game /// </summary> /// <param name="g">game to launch</param> public void ActionLaunchGame(GardenItem g, GameThumbnail thumb) { if (g.IsInstalled) { if (g.IsPlayable) { // if installed, then launch it if possible if ((launcher == null || launcher.IsFinished() == true) && (launchGameThread == null || launchGameThread.IsFinished())) { loadingDisplay.SetLoadingGame(g, thumb); // set state of game to 'game playing state' TreeRoot.SetNextState(new StatePlayingGame()); launcher = new GameLauncherTask(g); launchGameThread = new ThreadedTask(launcher); launchGameThread.TaskSuccessEvent += new TaskEventHandler(taskThread_TaskFinishedEvent); launchGameThread.TaskFailEvent += new TaskEventHandler(taskThread_TaskFinishedEvent); launchGameThread.Start(); } } if (g.IsMusic) { music.Play(g.ExeFilepath, 0.5f, 0f); // TODO vary audio volume per track. } } }
/// <summary> /// set state to loading game and display given game name /// </summary> /// <param name="g">game whose name/info to display while loading</param> public void SetLoadingGame(GardenItem g, GameThumbnail thumb) { SetNextState(new StateLoadingDisplay_Loading(this)); game = g; gameIcon.Texture = thumb.Texture; //gameIcon.Motion.Scale = thumb.Motion.Scale * 1.4f * g.ScaleIcon; gameIcon.Motion.Scale = Screen.Width / gameIcon.DrawInfo.Width; }
public void ActionLaunchWebsite(GardenItem g, GameThumbnail thumb) { ITask t = new ThreadedTask(new SiteLauncherTask(g)); t.Start(); loadingDisplay.SetLoadingGame(g, thumb); TreeRoot.SetNextState(new StatePlayingGame(2f, false)); }
/// <summary> /// called by a child GUI component to install a game /// </summary> /// <param name="g">game to install</param> public void ActionDownloadAndInstallGame(GardenItem g) { // check if download+install task needs to start or not. Can start if not already started before (and game's not installed) // OR if the previous install attempt failed. if ((g.ThreadedDlAndInstallTask == null && !g.IsInstalled) || (g.ThreadedDlAndInstallTask != null && g.ThreadedDlAndInstallTask.IsFinished() && !g.ThreadedDlAndInstallTask.IsSuccess()) ) { g.DlAndInstallTask = new GameDownloadAndInstallTask(g); g.ThreadedDlAndInstallTask = new ThreadedTask(g.DlAndInstallTask); g.ThreadedDlAndInstallTask.Start(); } }
// shorthand method to select the game currently indicated by cursor protected void SelectGameBelowCursor() { if (gl != null) { GardenItem g = gl.FindGameAt(cursor.GridPosition); SelectedGame = g; infoBox.ClearProgressBar(); if (g != null && !g.IsVisible) // reset back to null for invisible items. Not selectable. { SelectedGame = null; } if (g != null) { g.Refresh(); } } }
} // class public GameThumbnail(GardenItem game) : base((Texture2D)null, "GameThumbnail") { ColorB = new ColorChangeBehavior(); Add(ColorB); Motion.Scale = GardenGamesPanel.THUMBNAIL_SCALE_UNSELECTED; Game = game; // effect is still off if no bitmap loaded yet EffectEnabled = false; // first-time texture init if (DefaultTexture == null) { DefaultTexture = GardenGame.Instance.Content.Load <Texture2D>("ball-supernova2"); } // use default texture as long as thumbnail not loaded yet Texture = DefaultTexture; }
/// <summary> /// set cursor to select a given game. It will move there in next Update()s. /// </summary> /// <param name="g"></param> public void SetToGame(GardenItem g) { Motion.TargetPos = g.Position; Motion.TargetPosSpeed = 4f; // TODO constant? GridPosition = g.Position; }
public override void OnChangedSelectedGame(GardenItem newSel, GardenItem oldSel) { // }
protected override void OnUpdate(ref UpdateParams p) { base.OnUpdate(ref p); GardenItem selGame = SelectedGame; // update info box if (selGame == null && infoBox != null) { infoBox.SetGameInfo(selGame); } // handle download/install/launching of a game if (selGame != null && isGameLaunchOngoing && timeLaunching < TIME_BEFORE_GAME_LAUNCH) { timeLaunching += p.Dt; GameThumbnail th = thumbnailsCache[selGame.GameID]; float sc = (1f + timeLaunching / 3f); th.Motion.ScaleTarget = THUMBNAIL_SCALE_SELECTED * sc; // blow up size of thumbnail while user requests launch cursor.Motion.ScaleTarget = sc; cursor.Motion.ScaleSpeed = th.Motion.ScaleSpeed / selGame.ScaleIcon; // TODO correct ScaleIcon? } if (!isGameLaunchOngoing) { cursor.Motion.ScaleTarget = CURSOR_SCALE_REGULAR; } // launch of a game if (isGameLaunchConfirmed && selGame != null) { cursor.Motion.ScaleTarget = CURSOR_SCALE_REGULAR; GameThumbnail thumb = thumbnailsCache[selGame.GameID]; if (selGame.IsIggClient) { if (selGame.IsInstalled) { GardenGame.Instance.music.FadeOut(); GardenGame.Instance.ActionLaunchGame(selGame, thumb); isExiting = true; timeExiting = TIME_BEFORE_EXIT; } else { GardenGame.Instance.ActionDownloadAndInstallGame(selGame); } } else { if (selGame.IsWebGame) { GardenGame.Instance.ActionLaunchWebsitePlayGame(selGame, thumb); } else if (!selGame.IsGrowable) { thumb.Motion.Add(new TemporaryScaleBlowup()); } else if (selGame.IsInstalled) { GardenGame.Instance.music.FadeOut(); GardenGame.Instance.ActionLaunchGame(selGame, thumb); } else // if (not installed) { GardenGame.Instance.ActionDownloadAndInstallGame(selGame); } } isGameLaunchOngoing = false; isGameLaunchConfirmed = false; timeLaunching = 0f; } // handle exit key if (isExiting) { GardenGame.Instance.music.FadeOut(); timeExiting += p.Dt; if (timeExiting > TIME_BEFORE_EXIT) { parentMenu.background.Motion.ScaleModifier = 1f / (1f + (timeExiting - TIME_BEFORE_EXIT) / 11f); if (!isExitingUnstoppable) { GardenGame.Instance.SignalExitGame(); isExitingUnstoppable = true; Motion.ZoomSpeed = PANEL_ZOOM_SPEED_QUITTING; } return; } } else { if (timeExiting > 0f) { if (GardenGame.Instance.music.UserWantsMusic) { GardenGame.Instance.music.FadeIn(); } timeExiting = 0f; } } //-- website launch if (isLaunchWebsite) { if (selGame != null) { GameThumbnail thumb = thumbnailsCache[selGame.GameID]; GardenGame.Instance.ActionLaunchWebsite(selGame, thumb); } isLaunchWebsite = false; } //-- loop all nearby games adapt their display properties where needed if (gl == null) { return; } GardenItem g; // upd cache with possibly new items around cursor List <GardenItem> c = gl.GetItemsAround((int)cursor.GridPosition.X, (int)cursor.GridPosition.Y, (int)CURSOR_DISCOVERY_RANGE); if (selGame != null) { c.Add(selGame); } for (int i = c.Count - 1; i >= 0; i--) { g = c[i]; // if GameThumbnail for current game does not exist yet, create it if (!thumbnailsCache.ContainsKey(g.GameID) && g.IsVisible && g.GameID.Length > 0) { // create now GameThumbnail th = new GameThumbnail(g); Add(0, th); thumbnailsCache.Add(g.GameID, th); //th.Position = new Vector2(RandomMath.RandomBetween(-0.4f,2.0f), RandomMath.RandomBetween(-0.4f,1.4f) ); //th.Scale = RandomMath.RandomBetween(0.01f, 0.09f); // create with new position and scale th.Motion.Position = Screen.Center; th.Motion.Scale = 0.05f; th.Motion.ScaleTarget = 0.05f; th.Motion.ScaleSpeed = 0.01f; // TODO const th.DrawInfo.LayerDepth = LAYER_GRID_ITEMS + ((float)th.ID) * float.Epsilon; th.Visible = false; th.ColorB.Intensity = 0.0f; // special case thumbnails if (g.GameID.Equals("igg_controls")) { th.Motion.Add(new MyFuncyModifier(delegate(float v) { return(v / 22.3f); }, "Rotate")); } } } // visit all cached items and adjust positions, visibility, etc. List <GameThumbnail> toRemoveFromCache = new List <GameThumbnail>(); foreach (GameThumbnail th in thumbnailsCache.Values) { g = th.Game; // check if out of range. If so, remove from cache later if (cursor.DistanceTo(th) > CURSOR_DESTRUCTION_RANGE) { toRemoveFromCache.Add(th); th.Delete = true; } else { // check if thnail invvisible but in range. If so, start loading it if (!th.Visible && cursor.DistanceTo(th) <= CURSOR_DISCOVERY_RANGE) { th.LoadInBackground(); th.ColorB.Intensity = 0f; } // check if thnail is loaded and still in range. If so, start displaying it (fade in) if (th.IsLoaded() && cursor.DistanceTo(th) <= CURSOR_DISCOVERY_RANGE) { if (th.Game.IsGrowable) { th.ColorB.FadeTarget = (0.65f + 0.35f * g.InstallProgress); } else { th.ColorB.FadeTarget = 1f; } } // check if thnail in range to fade out if (th.IsLoaded() && cursor.DistanceTo(th) > CURSOR_FADEOUT_RANGE) { th.ColorB.FadeTarget = 0f; } } th.Motion.ScaleTarget = THUMBNAIL_SCALE_UNSELECTED; th.ColorB.FadeSpeed = THUMBNAIL_FADE_SPEED; // TODO do this only once per th? // coordinate position where to move a game thumbnail to Vector2 targetPos = (g.Position - PanelShiftPos) * new Vector2(PANEL_DELTA_GRID_X, PANEL_DELTA_GRID_Y); th.Motion.TargetPos = targetPos; th.Motion.TargetPosSpeed = PANEL_SPEED_SHIFT; } // end for loop over all games foreach (GameThumbnail th in toRemoveFromCache) { thumbnailsCache.Remove(th.Game.GameID); } // --- for selected game only if (selGame != null) { g = selGame; // update text box with currently selected game info if (g != infoBox.game) { infoBox.SetGameInfo(g); } //-- helpful controls text if (g.GameID.Equals("igg_controls") && !isExiting) { helpTextBitmap.Motion.TargetPos = HELPTEXT_SHOWN_POSITION; if (g.Name.Length == 0) { string msg = GardenConfig.Instance.ServerMsg; string[] msgLines = msg.Split(new char[] { '\n' }, 2); g.Name = msgLines[0]; if (msgLines.Length > 1) { g.Description = msgLines[1]; } } } else { helpTextBitmap.Motion.TargetPos = HELPTEXT_HIDDEN_POSITION; } //-- credits text if (g.GameID.Equals("igg_credits") && !isExiting) { creditsBitmap.Motion.TargetPos = CREDITS_SHOWN_POSITION; Vector2 cpd = cursor.Motion.PositionAbsZoomed; if (cpd.Y <= 0.35f) // TODO const { float dxp = PANEL_SPEED_SHIFT * p.Dt; PanelShiftPos.Y -= dxp; } } else { creditsBitmap.Motion.TargetPos = CREDITS_HIDDEN_POSITION; } if (!isGameLaunchOngoing) { if (thumbnailsCache.ContainsKey(g.GameID)) { GameThumbnail th = thumbnailsCache[g.GameID]; if (g.IsInstalling) { // wobble the size of icon when installing. th.Motion.ScaleTarget = 1.0f + 0.1f * (float)Math.Sin(MathHelper.TwoPi * 0.16f * SimTime); } else { // displaying selected thumbnails larger if (g.IsGrowable) { th.Motion.ScaleTarget = THUMBNAIL_SCALE_SELECTED; } else { th.Motion.ScaleTarget = THUMBNAIL_SCALE_UNSELECTED; } } } } } // cursor where to move to cursor.Motion.TargetPos = (cursor.GridPosition - PanelShiftPos) * new Vector2(PANEL_DELTA_GRID_X, PANEL_DELTA_GRID_Y); cursor.Motion.TargetPosSpeed = PANEL_SPEED_SHIFT; // panel shift effect when cursor hits edges of panel Vector2 cp = cursor.Motion.PositionAbsZoomed; float chw = cursor.DrawInfo.WidthAbs / 2.0f; // cursor-half-width float chh = cursor.DrawInfo.HeightAbs / 2.0f; // cursor-half-height float dx = PANEL_SPEED_SHIFT * p.Dt; const float xMargin = CURSOR_MARGIN_X; // TODO into gui props const float yMargin = CURSOR_MARGIN_Y; if (cp.X <= chw + xMargin) { PanelShiftPos.X -= dx; } else if (cp.X >= PANEL_SIZE_X - chw - xMargin) { PanelShiftPos.X += dx; } if (cp.Y <= chh + yMargin) { PanelShiftPos.Y -= dx; } else if (cp.Y >= PANEL_SIZE_Y - chh - yMargin) { PanelShiftPos.Y += dx; } }
/// <summary> /// construct a new thumbnail downloader for game; downloading from default server /// location. /// </summary> public ThumbnailDownloader(GardenItem g) { this.gi = g; }
/// <summary> /// create new Download and Install task /// </summary> /// <param name="game">info of game to download and install</param> public GameDownloadAndInstallTask(GardenItem game) { this.game = game; status = ITaskStatus.CREATED; }
public GameLibraryDownloader(int version) : base(GardenItem.ConstructGameLibItem(version)) { }
/// <summary> /// specify which game the info box should show status/info of /// </summary> /// <param name="g"></param> public void SetGameInfo(GardenItem g) { game = g; }
public GameDownloader(GardenItem game) : base() { this.game = game; this.segmentsUsedInDownload = 3; }
/// <summary> /// user action triggered a changed selection event /// </summary> /// <param name="newSel">previously selected game</param> /// <param name="oldSel">newly selected game</param> public abstract void OnChangedSelectedGame(GardenItem newSel, GardenItem oldSel);
public void Add(GardenItem item) { listItem.Add(item); canvas.Children.Add(item); SetPos(Window.Current.Bounds.Height, Window.Current.Bounds.Width); }
public InstallTask(GardenItem game) { this.game = game; }