예제 #1
0
        void start_Click(object sender, EventArgs e)
        {
            var p = profiles.SelectedItem as SelectedProfile;

            if (p == null)
            {
                Dialog.Show(Locale.Resource.MenuNoProfileSelectedTitle, Locale.Resource.MenuNoProfileSelected);
                return;
            }
            Program.Settings.LastProfile = p.Filename;
            Program.Instance.Profile     = Profile.Load(p.Filename);
            if (Program.Instance.Profile == null)
            {
                Dialog.Show(Locale.Resource.MenuUnableToLoadProfile, Locale.Resource.MenuUnableToLoadProfileDetails);
            }
            else
            {
                if (Program.Instance.Profile.AutostartFirstCinematic && !Program.Settings.ProfileClickOnceWin)
                {
                    Program.Instance.Profile.AutostartFirstCinematic = false;
                    Program.Instance.Profile.Save();
                    Program.Instance.ProgramState = new Game.Game("Maps/" + Campaign.Campaign1().Tiers[0].Maps[0].MapName + ".map");
                }
                else
                {
                    Program.Instance.LoadNewState(new ProfileMenuState());
                }
            }
        }
        void mainMenuButton_Click(object sender, EventArgs e)
        {
            var c   = Campaign.Campaign1();
            var map = c.GetMapByFilename(Game.Instance.LoadMapFilename);

            if (map != null)
            {
                var nextTier = map.Tier.NextTier;
                if (FirstTimeCompletedMap && nextTier.Cutscene)
                {
                    Program.Instance.ProgramState = new Game("Maps/" + nextTier.Maps[0].MapName + ".map");
                    return;
                }
            }
            Program.Instance.EnterProfileMenuState();
        }
예제 #3
0
            public override void Enter()
            {
                base.Enter();
                Game.Instance.GameState = GameState.Playing;
                Game.Instance.CameraController.Init();
                Game.Instance.SilverYield            = 0;
                Game.Instance.PreviousMaxSilverYield = Program.Instance.Profile.GetMaxSilverYield(Game.Instance.LoadMapFilename);
                var m = Campaign.Campaign1().GetMapByFilename(Game.Instance.LoadMapFilename);

                if (m != null)
                {
                    Game.Instance.HasPreviouslyCompletedMap = Program.Instance.Profile.IsCompleted(m.MapName);
                }

                Game.Instance.CurrentStageInfos     = new Client.Game.Interface.StageInfo[Game.Instance.Map.Settings.Stages];
                Game.Instance.BestStagesInfos       = new Client.Game.Interface.StageInfo[Game.Instance.Map.Settings.Stages];
                Game.Instance.stagesControl.NStages = Game.Instance.Map.Settings.Stages;
                for (int i = 0; i < Game.Instance.BestStagesInfos.Length; i++)
                {
                    Game.Instance.BestStagesInfos[i] = Program.Instance.Profile.GetBestStage(Game.Instance.LoadMapFilename, i + 1);
                    Game.Instance.stagesControl.SetBestStage(i + 1, Game.Instance.BestStagesInfos[i]);
                }
                if (Game.Instance.Map.Settings.Stages > 0)
                {
                    Game.Instance.stagesControl.SetActive(1, true);
                }

                Game.Instance.FeedbackInfo = new FeedbackCommon.GameInstance
                {
                    Profile   = Program.Instance.Profile.FeedbackInfo,
                    StartTime = DateTime.Now,
                };

                if (Game.Instance.Map.Settings.MapType != Client.Game.Map.MapType.Cinematic)
                {
                    Program.Instance.Interface.AddFader();
                    ssc = new Interface.StartScreenControl
                    {
                        AvailableMeleeWeapons  = Program.Instance.Profile.AvailableMeleeWeapons,
                        SelectedMeleeWeapon    = Program.Instance.Profile.LastMeleeWeapon,
                        AvailableRangedWeapons = Program.Instance.Profile.AvailableRangedWeapons,
                        SelectedRangedWeapon   = Program.Instance.Profile.LastBulletType,
                        MapSettings            = Game.Instance.Map.Settings,
                        Localization           = Game.Instance.Map.StringLocalizationStorage
                    };
                    Program.Instance.Interface.AddChild(ssc);
                    ssc.Closed += new EventHandler(ssc_Closed);
                }
                else
                {
                    Game.Instance.ChangeState(new RunningState());
                }

                if (Game.Instance.Map.Settings.MapType != Client.Game.Map.MapType.Cinematic)
                {
                    var sm = Program.Instance.SoundManager;

                    if (Game.Instance.musicChannel1 == null)
                    {
                        if (Game.Instance.Map.Settings.MusicTrack1 != Client.Sound.Stream.EmptyTrack)
                        {
                            if (Game.Instance.Map.Settings.MusicTrack2 != Client.Sound.Stream.EmptyTrack && Game.Instance.Map.Settings.MusicTrack1 != Game.Instance.Map.Settings.MusicTrack2)
                            {
                                Game.Instance.musicChannel1 = sm.GetSoundResourceGroup(sm.GetStream(Game.Instance.Map.Settings.MusicTrack1), sm.GetStream(Game.Instance.Map.Settings.MusicTrack2)).PlayLoopedWithIntervals(0.5f, 1.5f, 0.5f, new Sound.PlayArgs());
                            }
                            else
                            {
                                Game.Instance.musicChannel1 = sm.GetStream(Game.Instance.Map.Settings.MusicTrack1).Play(new Client.Sound.PlayArgs {
                                    Looping = true
                                });
                            }
                        }
                        else if (Game.Instance.Map.Settings.MusicTrack2 != Client.Sound.Stream.EmptyTrack)
                        {
                            Game.Instance.musicChannel1 = sm.GetStream(Game.Instance.Map.Settings.MusicTrack2).Play(new Client.Sound.PlayArgs {
                                Looping = true
                            });
                        }
                    }

                    if (Game.Instance.ambienceChannel1 == null && Game.Instance.Map.Settings.AmbienceTrack1 != Client.Sound.Stream.EmptyTrack)
                    {
                        Game.Instance.ambienceChannel1 = sm.GetStream(Game.Instance.Map.Settings.AmbienceTrack1).Play(new Sound.PlayArgs {
                            Looping = true
                        });
                    }

                    if (Game.Instance.ambienceChannel2 == null && Game.Instance.Map.Settings.AmbienceTrack2 != Client.Sound.Stream.EmptyTrack && Game.Instance.Map.Settings.AmbienceTrack1 != Game.Instance.Map.Settings.AmbienceTrack2)
                    {
                        Game.Instance.ambienceChannel2 = sm.GetStream(Game.Instance.Map.Settings.AmbienceTrack2).Play(new Sound.PlayArgs {
                            Looping = true
                        });
                    }
                }
                else
                {
                    //run some ambience for the cut scenes
                }

                if (Game.Instance.LoadingScreen != null)
                {
                    Game.Instance.LoadingScreen.Remove();
                    Game.Instance.LoadingScreen = null;
                }
            }
예제 #4
0
            public override void Enter()
            {
                if (ProgramStates.MainMenuState.MainMenuMusic != null)
                {
                    float fadeOut = 0.3f;
                    ProgramStates.MainMenuState.MainMenuMusic.Stop(fadeOut);
                    ProgramStates.MainMenuState.MainMenuMusic = null;
                    DateTime lastUpdate = DateTime.Now;
                    float    dtime      = 0;
                    do
                    {
                        Program.Instance.SoundManager.Update(dtime);
                        float sleep = 100 / 6f - 1000f * dtime;
                        if (sleep > 0)
                        {
                            System.Threading.Thread.Sleep((int)sleep);
                        }

                        DateTime now = DateTime.Now;
                        dtime      = (float)(now - lastUpdate).TotalSeconds;
                        lastUpdate = now;
                        fadeOut   -= dtime;
                    } while (fadeOut > 0);
                }
                base.Enter();
                Application.Log("Entering loading state...");
                Application.Log(Program.Settings.DumpVideoSettings());


                Random = new Random();
                Instance.SpawnRandomizer = new Random();
                Instance.SceneControl.InnerSceneController =
                    Instance.SceneController = new SceneManager {
                    Scene = Instance.Scene, Activated = false
                };
                if (Program.Settings.ReplayState == ReplayState.Replaying)
                {
                    Instance.Replay = Replay.Load(Program.Settings.ReplayFile);
                    Instance.Replay.StartReplaying(Game.Instance);
                }
                else
                {
                    Instance.Input = new HardwareInput(Instance.SceneController);
                    if (Program.Settings.ReplayState == ReplayState.Recording)
                    {
                        Instance.Replay = Replay.New(Program.Settings.ReplayFile);
                        Instance.Replay.StartRecording(Instance);
                    }
                }
                Instance.SceneControl.Focus();

                LogLoading("Scene controller initialized");

                Instance.Statistics = new Statistics();

#if DEBUG
                RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("StartLoadMap start");
#endif
                LogLoading("StartLoadMap()");

                Tier t = null;
                if (Instance.LoadMapFilename != null)
                {
                    CampaignMap map = Campaign.Campaign1().GetMapByFilename(Instance.LoadMapFilename);
                    if (map != null)
                    {
                        t = map.Tier;
                    }
                }
                if (t != null)
                {
                    Instance.LoadingScreen = new Interface.LoadingScreen(t.LoadingScreenPicture, t.LoadingScreenPictureSize);
                }
                else
                {
                    Instance.LoadingScreen = new Interface.LoadingScreen();
                }

                Program.Instance.Interface.AddChild(Game.Instance.LoadingScreen);
                LogLoading("LoadingScreen added");
                UpdateProgress(0f);

                float mapLoadInc = 0.54f;
                if (Instance.mapLoader != null)
                {
                    Instance.Map = Instance.mapLoader();
                    UpdateProgress(mapLoadInc);
                }
                else if (!string.IsNullOrEmpty(Instance.LoadMapFilename))
                {
                    Map.Map map;

                    var   steps   = Client.Game.Map.MapPersistence.Instance.GetLoadSteps(Instance.LoadMapFilename, Instance.Scene.Device, out map);
                    float incStep = mapLoadInc / steps.Count;
                    foreach (var v in steps)
                    {
                        v.Second.Invoke();
                        UpdateProgress(incStep);
                    }
                    Instance.Map = map;
                }
                else
                {
                    Instance.Map = Instance.preLoadedMap;
                    UpdateProgress(mapLoadInc);
                }

                LogLoading("Map loaded");

                Instance.sceneQuadtree = new Common.Quadtree <Entity>(10);
                //sceneQuadtree = new Common.BruteForceBoundingVolumeHierarchy<Entity>();

                Instance.sceneQuadtreeAutoSyncer = new SceneBVHAutoSyncer(Instance.Scene, Instance.sceneQuadtree)
                {
                    MinMovedDistanceForUpdate = -1
                };
                //sceneQuadtree = new Common.BruteForceBoundingVolumeHierarchy<Entity>();

                LogLoading("QuadTree initialized");

                ((LookatSphericalCamera)Instance.Scene.Camera).Lookat = Instance.Map.MainCharacter.Translation;

                Instance.Mechanics = new Mechanics.Manager(Instance.Map);

                LogLoading("Mechanics loaded");
                UpdateProgress(0.004f);


                //Game.Instance.Map.Settings.cut
                //if (!Game.Instance.Map.Settings.Cinematic)
                //{
                //    var sm = Program.Instance.SoundManager;
                //    Game.Instance.musicChannel1 = sm.GetSoundResourceGroup(sm.GetStream(Client.Sound.Stream.InGameMusic2)).PlayLoopedWithIntervals(0.5f, 1.5f, 0.5f);
                //    Game.Instance.musicChannel2 = sm.GetStream(Client.Sound.Stream.BirdsAmbient1).Play();
                //    Game.Instance.musicChannel2.Looping = true;

                //}
                //else
                //{
                //    //run some ambience for the cut scenes
                //}

                //LogLoading("Music playing");

#if DEBUG
                RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("StartLoadMap return to app start");
#endif

                for (int i = 0; i < Instance.Map.Ground.Pieces.GetLength(0); i++)
                {
                    for (int j = 0; j < Instance.Map.Ground.Pieces.GetLength(1); j++)
                    {
                        Instance.Map.Ground.Pieces[i, j].EnsureConstructed();
                    }
                }

                Instance.Scene.Root.AddChild(Instance.Map.Ground);
                UpdateProgress(0.106f);
                LogLoading("Ground added");
                Instance.Scene.Root.AddChild(Instance.Map.DynamicsRoot);
                LogLoading("DynamicsRoot added");
                UpdateProgress(0.145f);
                Instance.Scene.Root.AddChild(Instance.Map.StaticsRoot);
                LogLoading("StaticsRoot added");
                UpdateProgress(0.145f);
                Instance.Scene.Root.AddChild(new Water(Instance.Map));
                LogLoading("Water added");
                UpdateProgress(0.008f);

                PreLoading.Initialize();

                foreach (MetaModel m in PreLoading.MetaModels)
                {
                    if (m.SkinnedMesh != null)
                    {
                        Program.Instance.Content.Acquire <SkinnedMesh>(m.SkinnedMesh);
                    }
                    if (m.XMesh != null)
                    {
                        Program.Instance.Content.Acquire <SlimDX.Direct3D9.Mesh>(m.XMesh);
                    }
                    if (m.Texture != null)
                    {
                        Program.Instance.Content.Acquire <Texture>(m.Texture);
                    }
                    for (int i = 0; i < 2; i++)
                    {
                        if (m.SplatTexutre != null)
                        {
                            if (m.SplatTexutre[i] != null)
                            {
                                Program.Instance.Content.Acquire <Texture>(m.SplatTexutre[i]);
                            }
                        }
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        if (m.MaterialTexture != null)
                        {
                            if (m.MaterialTexture[i] != null)
                            {
                                Program.Instance.Content.Acquire <Texture>(m.MaterialTexture[i]);
                            }
                        }
                    }
                }

                foreach (Graphics.Renderer.Renderer.MetaEntityAnimation m in PreLoading.MetaEntityAnimations)
                {
                    Program.Instance.Content.Acquire <Graphics.Renderer.Renderer.EntityAnimation>(m);
                }

                foreach (Graphics.Content.Font font in PreLoading.MetaFonts)
                {
                    Program.Instance.Content.Acquire <FontImplementation>(font);
                }

                Instance.Renderer.Settings.CullMode = Instance.Map.Settings.MapType == Client.Game.Map.MapType.Cinematic ? Cull.None : Cull.Counterclockwise;

                LogLoading("Loading screen removed");

                Instance.GroundProbe = new WorldViewProbe
                {
                    Camera     = Instance.Scene.Camera,
                    View       = Program.Instance,
                    WorldProbe = new GroundProbe(Instance.Map)
                };
                Instance.MainCharPlaneProbe = new WorldViewProbe
                {
                    Camera     = Instance.Scene.Camera,
                    View       = Program.Instance,
                    WorldProbe = new MainCharPlaneProbe(Instance.Map.MainCharacter)
                };

                LogLoading("Probes initialized");
                UpdateProgress(0.052f);

                ((SceneManager)Instance.SceneController).Activated = true;

                LogLoading("Changing to StartRunningState");
#if DEBUG
                RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("StartLoadMap done");
#endif

#if DEBUG_LOADING
                OutputLog();

                if (System.Math.Abs(loadingScreen.Percentage - 1f) > 0.001f)
                {
                    throw new Exception(String.Format("Progress did not equal 100%, got {0:0.000}%", loadingScreen.Percentage * 100f));
                }
#endif

                Program.Instance.Interface.AddChild(Instance.stagesControl);
                Instance.Interface.Visible = true;

                Instance.ChangeState(new StartGameState());
            }