protected override void OnUpdate(float dt)
        {
            base.OnUpdate(dt);

            // See if any new mods have been added
            if (Mods.Refresh(Game.Network))
            {
                bool needsLoad = false;
                foreach (var mod in Mods.RemovedLoadedMods)
                {
                    Assets.RemoveSource(mod.Assets);
                    mod.Loaded = false;
                    needsLoad  = true;
                }
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.AutoLoad && !mod.Loaded)
                    {
                        Assets.AddSource(mod.Assets);
                        mod.Loaded = true;
                        needsLoad  = true;
                    }
                }
                if (needsLoad)
                {
                    LoadToState(delegate()
                    {
                        return(new MainOptionsState(Game));
                    });
                }
            }
        }
        private void EditMod(Mod mod)
        {
            Func <State> fnNextState = delegate()
            {
                return(new ModEditorState(Game, mod));
            };

            if (!mod.Loaded)
            {
                Assets.AddSource(mod.Assets);
                mod.Loaded = true;
                LoadToState(fnNextState);
            }
            else
            {
                WipeToState(fnNextState.Invoke());
            }
        }
Beispiel #3
0
        private void EditMod(Mod mod)
        {
            // Animate the robot
            m_robot.StartAnimation(LuaAnimation.Get("animation/menus/startscreen/robot_move_alt.anim.lua"), false);
            m_robot.PlaySoundAfterDelay("sound/new_robot/beam_up.wav", false, 0.3f);

            // Open the mod editor
            Func <State> fnNextState = delegate()
            {
                return(new ModEditorState(Game, mod));
            };

            if (!mod.Loaded)
            {
                Assets.AddSource(mod.Assets);
                mod.Loaded = true;
                LoadToState(fnNextState, 1.75f);
            }
            else
            {
                WipeToState(fnNextState.Invoke(), 1.75f);
            }
        }
        private void OpenCampaign(Campaign campaign, Mod mod)
        {
            // Set the campaign as played
            if (App.Steam && mod != null && mod.Source == ModSource.Workshop && mod.SteamWorkshopID.HasValue)
            {
                Game.Network.Workshop.SetItemPlayed(mod.SteamWorkshopID.Value);
            }

            // Load the campaign
            bool         editor      = m_editor;
            Func <State> fnNextState = delegate()
            {
                // Get the campaign again (it might have only just been loaded)
                campaign = Campaign.Get(campaign.Path);

                // Open the level select screen
                // Choose an appropriate page to open onto
                if (editor)
                {
                    // Open to the last edited level
                    int lastEditedLevelNum = -1;
                    var lastEditedLevel    = Game.User.Progress.LastEditedLevel;
                    if (lastEditedLevel != 0)
                    {
                        for (int i = 0; i < campaign.Levels.Count; ++i)
                        {
                            var levelPath = campaign.Levels[i];
                            var levelData = LevelData.Get(levelPath);
                            if (levelData.ID == lastEditedLevel)
                            {
                                lastEditedLevelNum = i;
                                break;
                            }
                        }
                    }

                    int level = (lastEditedLevelNum >= 0) ? lastEditedLevelNum : campaign.Levels.Count;
                    int page  = level / LevelSelectState.NUM_PER_PAGE;
                    return(new LevelSelectState(Game, mod, campaign, page, -1, true));
                }
                else
                {
                    // Open to the first unplayed level
                    int firstIncompleteLevel = -1;
                    for (int i = 0; i < campaign.Levels.Count; ++i)
                    {
                        var levelPath = campaign.Levels[i];
                        var levelData = LevelData.Get(levelPath);
                        if (!Game.User.Progress.IsLevelCompleted(levelData.ID))
                        {
                            firstIncompleteLevel = i;
                            break;
                        }
                    }
                    if (firstIncompleteLevel == 0 || campaign.Levels.Count == 1)
                    {
                        var introPath = LevelData.Get(campaign.Levels[0]).Intro;
                        if (introPath != null)
                        {
                            return(new CutsceneState(Game, mod, introPath, CutsceneContext.LevelIntro, new Playthrough(campaign, 0)));
                        }
                        else
                        {
                            return(new CampaignState(Game, mod, new Playthrough(campaign, 0)));
                        }
                    }
                    else
                    {
                        int level = (firstIncompleteLevel >= 0) ? firstIncompleteLevel : 0;
                        int page  = level / LevelSelectState.NUM_PER_PAGE;
                        return(new LevelSelectState(Game, mod, campaign, page, -1, false));
                    }
                }
            };

            if (mod != null && !mod.Loaded)
            {
                Assets.AddSource(mod.Assets);
                mod.Loaded = true;
                LoadToState(fnNextState);
            }
            else
            {
                WipeToState(fnNextState.Invoke());
            }
        }
        protected override void OnUpdate(float dt)
        {
            base.OnUpdate(dt);

            // Refresh GUI if mods change
            if (!m_editor && Mods.Refresh(Game.Network))
            {
                bool needsLoad = false;
                foreach (var mod in Mods.RemovedLoadedMods)
                {
                    Assets.RemoveSource(mod.Assets);
                    mod.Loaded = false;
                    needsLoad  = true;
                }
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.AutoLoad && !mod.Loaded)
                    {
                        Assets.AddSource(mod.Assets);
                        mod.Loaded = true;
                        needsLoad  = true;
                    }
                }

                if (needsLoad)
                {
                    LoadToState(delegate()
                    {
                        return(new CampaignSelectState(Game));
                    });
                    return;
                }
                else
                {
                    m_campaigns.Refresh();
                }
            }

            // Update GUI
            ShowSelectPrompt    = m_campaigns.Highlight >= 0 && (Game.Screen.InputMethod != InputMethod.Mouse);
            ShowAltSelectPrompt = m_campaigns.HighlightedAction != CampaignThumbnailAction.None && (Game.Screen.InputMethod != InputMethod.Mouse);
            switch (m_campaigns.HighlightedAction)
            {
            case CampaignThumbnailAction.Delete:
            {
                AltSelectPrompt = "menus.mod_select.delete";
                break;
            }

            case CampaignThumbnailAction.Edit:
            {
                AltSelectPrompt = "menus.mod_select.edit";
                break;
            }

            case CampaignThumbnailAction.ShowInWorkshop:
            {
                AltSelectPrompt = "menus.mod_editor.open_workshop";
                break;
            }
            }
        }
Beispiel #6
0
        protected override void OnUpdate(float dt)
        {
            base.OnUpdate(dt);

            // Update steam controller
            if (Game.ActiveSteamController != null)
            {
                Game.ActiveSteamController.ActionSet = (Game.Screen.ModalDialog != null) ?
                                                       SteamControllerActionSet.Menu.GetID() :
                                                       SteamControllerActionSet.Arcade.GetID();
            }

            // Update
            if (CheckBack())
            {
                GoBack();
            }
            if (CheckDiskSelect())
            {
                ShowDiskSelect();
            }

            var display      = m_devices.Display;
            var displayImage = display.Image;
            var displayVer   = (displayImage != null) ? displayImage.Version : 0;

            // Input
            // Gampad
            var gamepad = m_devices.Gamepad;

            gamepad.UpdateAxis(0, CheckX());
            gamepad.UpdateAxis(1, CheckY());
            gamepad.UpdateButton(0, CheckA());
            gamepad.UpdateButton(1, CheckB());

            // Keyboard
            var keyboard = m_devices.Keyboard;

            if (Game.Screen.ModalDialog == null)
            {
                // Text
                if (Game.Keyboard.Text.Length > 0)
                {
                    Game.Screen.InputMethod = InputMethod.Keyboard;
                    foreach (var c in Game.Keyboard.Text)
                    {
                        if (!char.IsControl(c) && !char.IsSurrogate(c))
                        {
                            keyboard.Char(c);
                        }
                    }
                }

                // Keys
                foreach (Key key in Enum.GetValues(typeof(Key)))
                {
                    int?code = TranslateKey(key);
                    if (code.HasValue)
                    {
                        if (Game.Keyboard.Keys[key].Pressed)
                        {
                            Game.Screen.InputMethod = InputMethod.Keyboard;
                            keyboard.KeyDown(code.Value, false);
                        }
                        else if (Game.Keyboard.Keys[key].Repeated)
                        {
                            Game.Screen.InputMethod = InputMethod.Keyboard;
                            keyboard.KeyDown(code.Value, true);
                        }
                        else if (Game.Keyboard.Keys[key].Released)
                        {
                            Game.Screen.InputMethod = InputMethod.Keyboard;
                            keyboard.KeyUp(code.Value);
                        }
                    }
                }

                // Terminate/Reboot
                if (Game.Keyboard.Keys[Key.LeftCtrl].Held || Game.Keyboard.Keys[Key.RightCtrl].Held)
                {
                    if (Game.Keyboard.Keys[Key.T].Pressed)
                    {
                        Game.Screen.InputMethod = InputMethod.Keyboard;
                        m_computer.Events.Queue("terminate");
                    }
                    if (Game.Keyboard.Keys[Key.R].Pressed)
                    {
                        Game.Screen.InputMethod = InputMethod.Keyboard;
                        m_computer.Reboot();
                    }
                    if (Game.Keyboard.Keys[Key.S].Pressed)
                    {
                        Game.Screen.InputMethod = InputMethod.Keyboard;
                        m_computer.TurnOff();
                    }
                }
            }
            else
            {
                // De-press
                foreach (Key key in Enum.GetValues(typeof(Key)))
                {
                    int?code = TranslateKey(key);
                    if (code.HasValue)
                    {
                        keyboard.KeyUp(code.Value);
                    }
                }
            }

            // Update
            var frameTime = 1.0f / FPS;

            m_frameTimer -= dt;
            while (m_frameTimer <= 0.0f)
            {
                m_computer.Update(TimeSpan.FromSeconds(frameTime));
                m_frameTimer += frameTime;
            }

            // Detect score increase
            if (m_activeDisk != null && m_devices.Score.Score > m_cachedScore)
            {
                var score = m_devices.Score.Score;
                if (m_activeDisk.ID != 0)
                {
                    // Save the score and check achivements
                    Game.User.Progress.SubmitArcadeGameScore(m_activeDisk.ID, score);
                    UnlockHighscoreAchievements(m_activeDiskMod, m_activeDisk, score);

                    // Submit the score to the leaderboards
                    if (Game.Network.SupportsLeaderboards)
                    {
                        string leaderboardName = null;
                        if (m_activeDiskMod == null)
                        {
                            leaderboardName = "arcade.main." + m_activeDisk.ID;
                        }
                        else
                        {
                            leaderboardName = "arcade.mod." + m_activeDisk.ID;
                        }
                        if (leaderboardName != null)
                        {
                            Game.QueuePromiseTask(
                                Game.Network.GetLeaderboardID(leaderboardName, true),
                                delegate(Promise <ulong> promise)
                            {
                                if (promise.Status == Status.Complete)
                                {
                                    Game.Network.LocalUser.SubmitLeaderboardScore(promise.Result, score);
                                }
                            }
                                );
                        }
                    }
                }
                m_cachedScore = score;
            }

            // Detect eject
            if (m_activeDisk != null && m_devices.DiskDrive.Disk == null)
            {
                SelectDisk(null, null);
            }

            // Output
            // Video
            var newDisplayImage = m_devices.Display.Image;
            var newDisplayVer   = (newDisplayImage != null) ? newDisplayImage.Version : 0;

            if (newDisplayImage != displayImage || newDisplayVer != displayVer)
            {
                UpdateDisplay();
            }

            // See if any new mods have been added
            if (Mods.Refresh(Game.Network))
            {
                bool needsLoad = false;
                foreach (var mod in Mods.RemovedLoadedMods)
                {
                    Assets.RemoveSource(mod.Assets);
                    mod.Loaded = false;
                    needsLoad  = true;
                }
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.AutoLoad && !mod.Loaded)
                    {
                        Assets.AddSource(mod.Assets);
                        mod.Loaded = true;
                        needsLoad  = true;
                    }
                }
                if (needsLoad)
                {
                    LoadToState(delegate()
                    {
                        return(new ArcadeState(Game));
                    });
                }
            }
        }
Beispiel #7
0
        private State CreateInitialState()
        {
            // Preload a mod from the command line
            Mod startupMod = null;

            if (App.Arguments.ContainsKey("mod"))
            {
                var modName = App.Arguments.GetString("mod");
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.Source == ModSource.Editor &&
                        Path.GetFileName(modName) == modName)
                    {
                        startupMod = mod;
                        if (!startupMod.Loaded)
                        {
                            Assets.AddSource(startupMod.Assets);
                            startupMod.Loaded = true;
                        }
                        break;
                    }
                }
                if (startupMod == null)
                {
                    App.Log("Error: No editor mod named {0}", modName);
                }
            }

            return(new LoadState(this, delegate()
            {
                if (App.Debug && App.Arguments.ContainsKey("analysis"))
                {
                    // Analysis
                    return new AnalysisState(this);
                }

                /*
                 * if (App.Debug && App.Arguments.ContainsKey("sky"))
                 * {
                 *  // Edit sky
                 *  var levelPath = App.Arguments.GetString("sky");
                 *  return new SkyEditor(this, levelPath);
                 * }
                 */

                if (App.Arguments.ContainsKey("arcade"))
                {
                    // Arcade
                    return new ArcadeState(this);
                }

                if (startupMod != null || App.Debug)
                {
                    if (App.Arguments.ContainsKey("level"))
                    {
                        // Edit level
                        var levelPath = App.Arguments.GetString("level");
                        Campaign campaign;
                        int levelIndex;
                        GuessCampaign(levelPath, startupMod, out campaign, out levelIndex);
                        if (Assets.Exists <LevelData>(levelPath))
                        {
                            return new TestState(this, startupMod, campaign, levelIndex, levelPath, levelPath);
                        }
                        else
                        {
                            return new TestState(this, startupMod, campaign, levelIndex, "levels/template.level", levelPath);
                        }
                    }
                    else if (App.Arguments.ContainsKey("cutscene"))
                    {
                        // Preview cutscene
                        var cutscenePath = App.Arguments.GetString("cutscene");
                        return new CutsceneState(this, startupMod, cutscenePath, CutsceneContext.Test);
                    }
                    else if (startupMod != null)
                    {
                        // Edit mod
                        return new ModEditorState(this, startupMod);
                    }
                }

                // Normal startup
                return new StartScreenState(this);
            }));
        }
Beispiel #8
0
        private void Load()
        {
            // Bind OpenGL
            m_window.MakeCurrent();

            // Set default OpenGL options
            GL.Viewport(0, 0, Window.Width, Window.Height);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthMask(true);

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Greater, 0.0f);

            GL.LineWidth(2.0f);

            // Create render stuff
            var width  = Math.Min(Window.Width, User.Settings.FullscreenWidth);
            var height = Math.Min(Window.Height, User.Settings.FullscreenHeight);
            var aamode = User.Settings.AAMode;

            m_postEffect       = new PostEffectInstance(User.Settings);
            m_postEffect.Gamma = User.Settings.Gamma;

            int scale = (aamode == AntiAliasingMode.SSAA) ? 2 : 1;

            m_worldRenderTexture   = new RenderTexture(scale * width, scale * height, true);
            m_upscaleEffect        = new UpscaleEffectInstance();
            m_backgroundEffect     = new BackgroundEffectInstance();
            m_upscaleRenderTexture = new RenderTexture(width, height, true);
            m_fullScreenQuad       = CreateFullscreenQuad();
            m_cameraAxisMarker     = new AxisMarker();

            // Create camera
            var aspectRatio = (float)Window.Width / (float)Window.Height;

            m_camera = new Camera(Matrix4.Identity, DEFAULT_FOV, aspectRatio);

            // Create screen
            m_screen = new Screen(
                Mouse, Keyboard, Language, m_window, m_audio,
                aspectRatio * SCREEN_HEIGHT, SCREEN_HEIGHT,
                width, height
                );

            m_cursor         = new Cursor();
            m_cursor.Visible = false;
            m_screen.Elements.Add(m_cursor);

            m_debugMenu         = new DebugMenu(this);
            m_debugMenu.Visible = false;
            m_screen.Elements.Add(m_debugMenu);

            // Add the rest of the asset sources:
            // Add the base assets
            var baseAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "base"));
            var baseAssets         = new FileAssetSource("base", baseAssetFileStore);

            Assets.AddSource(baseAssets);

            // Add the main assets
            var mainAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "main"));
            var mainAssets         = new FileAssetSource("main", mainAssetFileStore);

            Assets.AddSource(mainAssets);

            // Add the temp assets (used by the editor)
            var tempAssetFileStore = new LocatedFileStore(
                new FolderFileStore(Path.Combine(App.SavePath, "editor/temp")),
                "temp"
                );
            var tempAssets = new FileAssetSource("temp", tempAssetFileStore);

            Assets.AddSource(tempAssets);

            // Add autoload mod assets
            foreach (Mod mod in Mods.AllMods)
            {
                if (mod.AutoLoad)
                {
                    Assets.AddSource(mod.Assets);
                    mod.Loaded = true;
                }
            }

            // Create initial loading state
            m_currentState = CreateInitialState();
            m_pendingState = null;
            m_currentState.PreInit(null, null);
            m_currentState.Reveal();
            m_currentState.Init();
        }
Beispiel #9
0
        public Game()
        {
            m_promiseTasks = new List <PromiseTask>();

            m_over         = false;
            RenderUI       = true;
            UseDebugCamera = false;

            // Init network
            if (App.Steam)
            {
                m_network = new SteamworksNetwork(
                    AchievementExtensions.GetAllIDs(),
                    StatisticExtensions.GetAllIDs()
                    );
            }
            else
            {
                m_network = new BuiltinNetwork();
            }
            if (m_network.SupportsAchievements)
            {
                m_network.SetAchievementCorner(AchievementCorner.TopRight);
            }

            // Init user
            m_user = LoadUser();

            // Init window
            var title = App.Info.Title + " " + App.Info.Version.ToString();

            if (App.Debug && App.Steam)
            {
                title += " (Steam Debug build)";
            }
            else if (App.Debug)
            {
                title += " (Debug build)";
            }

            bool fullscreen = m_user.Settings.Fullscreen;
            bool vsync      = m_user.Settings.VSync;

            using (var icon = new Bitmap(Path.Combine(App.AssetPath, "icon.png")))
            {
                m_window = new SDL2Window(
                    title,
                    m_user.Settings.WindowWidth,
                    m_user.Settings.WindowHeight,
                    m_user.Settings.Fullscreen,
                    m_user.Settings.WindowMaximised,
                    m_user.Settings.VSync
                    );
                m_window.SetIcon(icon);
            }
            m_window.OnClosed += delegate(object sender, EventArgs e)
            {
                Over = true;
            };
            m_window.OnResized += delegate(object sender, EventArgs e)
            {
                Resize();
                if (!m_window.Fullscreen)
                {
                    if (m_window.Maximised)
                    {
                        m_user.Settings.WindowMaximised = true;
                    }
                    else
                    {
                        m_user.Settings.WindowMaximised = false;
                        m_user.Settings.WindowWidth     = m_window.Width;
                        m_user.Settings.WindowHeight    = m_window.Height;
                    }
                    m_user.Settings.Save();
                }
            };

            // Init audio
            if (App.Arguments.GetBool("nosound"))
            {
                m_audio = new NullAudio();
            }
            else
            {
                m_audio = new OpenALAudio();
            }
            m_audio.EnableSound = m_user.Settings.EnableSound;
            m_audio.SoundVolume = m_user.Settings.SoundVolume / 11.0f;
            m_audio.EnableMusic = m_user.Settings.EnableMusic;
            m_audio.MusicVolume = m_user.Settings.MusicVolume / 11.0f;
            m_gameAudio         = new GameAudio(m_audio);

            // Init input
            m_keyboard      = new SDL2Keyboard(m_window);
            m_mouse         = new SDL2Mouse(m_window);
            m_gamepads      = new SDL2GamepadCollection(m_window);
            m_activeGamepad = null;
            if (App.Steam)
            {
                m_steamControllers = new SteamworksSteamControllerCollection(
                    m_window,
                    SteamControllerActionSetExtensions.GetAllIDs(),
                    SteamControllerButtonExtensions.GetAllIDs(),
                    SteamControllerJoystickExtensions.GetAllIDs(),
                    SteamControllerAxisExtensions.GetAllIDs()
                    );
                m_readOnlySteamControllers = m_steamControllers;
                m_activeSteamController    = null;
            }
            else
            {
                m_steamControllers         = null;
                m_readOnlySteamControllers = new List <ISteamController>(0).ToReadOnly();
                m_activeSteamController    = null;
            }

            // Init tiles
            Tiles.Init();

            // Load early assets
            var earlyAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "early"));
            var earlyAssets         = new FileAssetSource("early", earlyAssetFileStore);

            Assets.AddSource(earlyAssets);
            Assets.LoadAll();

            // Find mods
            Mods.Refresh(Network);
            if (Network.SupportsWorkshop)
            {
                // See if any mods are worthy of the popular mod achievement
                var myModIDs = new List <ulong>();
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.Source == ModSource.Editor &&
                        mod.SteamWorkshopID.HasValue)
                    {
                        myModIDs.Add(mod.SteamWorkshopID.Value);
                    }
                }
                if (myModIDs.Count > 0)
                {
                    QueuePromiseTask(
                        m_network.Workshop.GetItemInfo(myModIDs.ToArray()),
                        delegate(Promise <WorkshopItemInfo[]> result)
                    {
                        if (result.Status == Status.Complete)
                        {
                            var infos = result.Result;
                            int subs  = 0;
                            for (int i = 0; i < infos.Length; ++i)
                            {
                                var info = infos[i];
                                if (info.AuthorID == m_network.LocalUser.ID &&
                                    info.UpVotes >= info.DownVotes)
                                {
                                    subs = Math.Max(info.TotalSubscribers, subs);
                                }
                            }
                            int oldSubs = User.Progress.GetStatistic(Statistic.MostPopularModSubscriptions);
                            if (subs >= 25)
                            {
                                User.Progress.SetStatistic(Statistic.MostPopularModSubscriptions, subs);
                                User.Progress.UnlockAchievement(Achievement.CreatePopularMod);
                                User.Progress.Save();
                            }
                            else if (subs > oldSubs)
                            {
                                User.Progress.SetStatistic(Statistic.MostPopularModSubscriptions, subs);
                                User.Progress.IndicateAchievementProgress(Achievement.CreatePopularMod, subs, 25);
                                User.Progress.Save();
                            }
                        }
                    }
                        );
                }
            }

            // Load language
            SelectLanguage();

            // Load debug stuff
            m_debugCameraController = new DebugCameraController(this);

            // Load game
            Load();
        }