Esempio n. 1
0
 void StartPlay(string classname)
 {
     try
     {
         _playData = new UiData()
         {
             Fonts           = Project.UiData.Fonts,
             Infocards       = Project.UiData.Infocards,
             DataPath        = Project.UiData.DataPath,
             FileSystem      = Project.UiData.FileSystem,
             FlDirectory     = Project.UiData.FlDirectory,
             ResourceManager = Project.UiData.ResourceManager,
             NavbarIcons     = Project.UiData.NavbarIcons,
             NavmapIcons     = Project.UiData.NavmapIcons,
             Resources       = Project.UiData.Resources
         };
         _playData.SetBundle(Compiler.Compile(Project.XmlFolder, Project.XmlLoader));
         _playContext = new UiContext(_playData)
         {
             RenderContext = RenderContext
         };
         _playContext.CommandBuffer = CommandBuffer;
         _playContext.GameApi       = TestApi;
         _playContext.LoadCode();
         _playContext.OpenScene(classname);
         playing = true;
     }
     catch (Exception e)
     {
         var detail = new StringBuilder();
         BuildExceptionString(e, detail);
         CrashWindow.Run("Interface Edit", "Compile Error", detail.ToString());
     }
 }
Esempio n. 2
0
        public LuaMenu(FreelancerGame g) : base(g)
        {
            api        = new MenuAPI(this);
            ui         = Game.Ui;
            ui.GameApi = api;
            ui.Visible = true;
            ui.OpenScene("mainmenu");
            g.GameData.PopulateCursors();
            g.CursorKind = CursorKind.None;
            intro        = g.GameData.GetIntroScene();
            scene        = new Cutscene(new ThnScriptContext(null), Game.GameData, Game.RenderContext.CurrentViewport, Game);
            scene.BeginScene(intro.Scripts);
            FLLog.Info("Thn", "Playing " + intro.ThnName);
            cur = g.ResourceManager.GetCursor("arrow");
            GC.Collect(); //crap
            g.Sound.PlayMusic(intro.Music);
            g.Keyboard.KeyDown   += UiKeyDown;
            g.Keyboard.TextInput += UiTextInput;
#if DEBUG
            g.Keyboard.KeyDown += Keyboard_KeyDown;
#endif
            Game.Saves.Selected = -1;
            if (g.LoadTimer != null)
            {
                g.LoadTimer.Stop();
                FLLog.Info("Game", $"Initial load took {g.LoadTimer.Elapsed.TotalSeconds} seconds");
                g.LoadTimer = null;
            }
            FadeIn(0.1, 0.3);
        }
Esempio n. 3
0
        public RoomGameplay(FreelancerGame g, CGameSession session, string newBase, BaseRoom room = null, string virtualRoom = null) : base(g)
        {
            //Load room data
            this.session = session;
            baseId       = newBase;
            currentBase  = g.GameData.GetBase(newBase);
            currentRoom  = room ?? currentBase.StartRoom;
            currentRoom.InitForDisplay();
            var rm = virtualRoom ?? currentRoom.Nickname;

            this.virtualRoom = virtualRoom;
            //Find infocard
            sys = g.GameData.GetSystem(currentBase.System);
            var obj = sys.Objects.FirstOrDefault((o) =>
            {
                return(o.Base?.Equals(newBase, StringComparison.OrdinalIgnoreCase) ?? false);
            });
            int ids = 0;

            if (obj?.IdsInfo.Length > 0)
            {
                ids = obj.IdsInfo[0];
            }
            roomInfocard = g.GameData.GetInfocard(ids, g.Fonts);
            if (g.GameData.GetRelatedInfocard(ids, g.Fonts, out var ic2))
            {
                roomInfocard.Nodes.Add(new RichTextParagraphNode());
                roomInfocard.Nodes.AddRange(ic2.Nodes);
            }
            //Create user interface
            tophotspots = new List <BaseHotspot>();
            foreach (var hp in currentRoom.Hotspots)
            {
                if (TOP_IDS.Contains(hp.Name))
                {
                    tophotspots.Add(hp);
                }
            }
            SetActiveHotspot(rm);
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += MouseOnMouseDown;
            cursor     = Game.ResourceManager.GetCursor("arrow");
            talk_story = Game.ResourceManager.GetCursor("talk_story");
            ui         = Game.Ui;
            ui.GameApi = new BaseUiApi(this);
            ui.OpenScene("baseside");
            //Set up THN
            SwitchToRoom(room == null);
            FadeIn(0.8, 1.7);
        }
Esempio n. 4
0
        void FinishLoad()
        {
            Game.Saves.Selected = -1;
            ui.OpenScene("hud");
            var shp = Game.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            player       = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager);
            control      = new ShipPhysicsComponent(player);
            control.Ship = shp;
            shipInput    = new ShipInputComponent(player);
            player.Components.Add(shipInput);
            player.Components.Add(control);
            weapons = new WeaponControlComponent(player);
            player.Components.Add(weapons);
            player.Components.Add(new CDamageFuseComponent(player, shp.Fuses));

            player.SetLocalTransform(session.PlayerOrientation * Matrix4x4.CreateTranslation(session.PlayerPosition));
            player.PhysicsComponent.Mass = shp.Mass;
            playerHealth               = new CHealthComponent(player);
            playerHealth.MaxHealth     = shp.Hitpoints;
            playerHealth.CurrentHealth = shp.Hitpoints;
            player.Components.Add(playerHealth);
            if (shp.Mass < 0)
            {
                FLLog.Error("Ship", "Mass < 0");
            }

            player.Tag = GameObject.ClientPlayerTag;
            foreach (var equipment in session.Items.Where(x => !string.IsNullOrEmpty(x.Hardpoint)))
            {
                EquipmentObjectManager.InstantiateEquipment(player, Game.ResourceManager, EquipmentType.LocalPlayer, equipment.Hardpoint, equipment.Equipment);
            }
            powerCore = player.GetComponent <PowerCoreComponent>();
            if (powerCore == null)
            {
                throw new Exception("Player launched without a powercore equipped!");
            }
            camera = new ChaseCamera(Game.RenderContext.CurrentViewport, Game.GameData.Ini.Cameras);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = player.LocalTransform.ClearTranslation();
            var offset = shp.ChaseOffset;

            camera.DesiredPositionOffset = offset;
            if (shp.CameraHorizontalTurnAngle > 0)
            {
                camera.HorizontalTurnAngle = shp.CameraHorizontalTurnAngle;
            }
            if (shp.CameraVerticalTurnUpAngle > 0)
            {
                camera.VerticalTurnUpAngle = shp.CameraVerticalTurnUpAngle;
            }
            if (shp.CameraVerticalTurnDownAngle > 0)
            {
                camera.VerticalTurnDownAngle = shp.CameraVerticalTurnDownAngle;
            }
            camera.Reset();

            sysrender           = new SystemRenderer(camera, Game.GameData, Game.ResourceManager, Game);
            sysrender.ZOverride = true; //Draw all with regular Z
            world = new GameWorld(sysrender);
            world.LoadSystem(sys, Game.ResourceManager, false, session.SpawnTime);
            session.WorldReady();
            player.World = world;
            world.AddObject(player);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            player.Register(world.Physics);
            Game.Sound.PlayMusic(sys.MusicSpace);
            //world.Physics.EnableWireframes(debugphysics);
            cur_arrow                = Game.ResourceManager.GetCursor("arrow");
            cur_cross                = Game.ResourceManager.GetCursor("cross");
            cur_reticle              = Game.ResourceManager.GetCursor("fire_neutral");
            current_cur              = cur_cross;
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += Mouse_MouseDown;
            Game.Mouse.MouseUp      += Mouse_MouseUp;
            input = new InputManager(Game);
            input.ToggleActivated += Input_ToggleActivated;
            input.ToggleUp        += Input_ToggleUp;
            pilotcomponent         = new AutopilotComponent(player);
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
            Game.Sound.ResetListenerVelocity();
            FadeIn(0.5, 0.5);
        }