Exemplo n.º 1
0
        public MyServerAction Travel(MyMwcTravelTypeEnum travelType, MyMwcSectorIdentifier targetSector)
        {
            Debug.Assert(targetSector.SectorType == MyMwcSectorTypeEnum.STORY, "Travel is allowed only in story");

            TryPause();

            var sector = MyLocalCache.LoadSector(targetSector);

            if (sector == null)
            {
                var storySectorId = targetSector;
                storySectorId.UserId = null;
                sector = MyLocalCache.LoadSector(storySectorId);
            }

            if (sector != null)
            {
                TravelSectorLoaded(travelType, targetSector.Position, null, sector);
                return(null);
            }
            else // Not using server...so sector is "from generator"
            {
                TravelSectorLoaded(travelType, targetSector.Position, null, MyMwcObjectBuilder_Sector.UseGenerator());
                return(null);
            }
        }
Exemplo n.º 2
0
        public static MyMwcObjectBuilder_Sector LoadSector(MyMwcSectorIdentifier sectorId)
        {
            MyMwcObjectBuilder_Sector userdataSector = LoadSector(sectorId, GetSectorPath(sectorId));
            MyMwcObjectBuilder_Sector contentSector  = null;

            if (sectorId.UserId == null) // Only non-user sectors loads from Content
            {
                var sectorPath = Path.Combine(ContentSectorPath, GetSectorName(sectorId, false) + ".mws");
                contentSector = LoadSector(sectorId, sectorPath);
            }

            int userVersion    = userdataSector != null ? userdataSector.Version : -1;
            int contentVersion = contentSector != null ? contentSector.Version : -1;

            if (userVersion > contentVersion)
            {
                Log("using USERDATA: ", sectorId, userVersion);
                return(userdataSector);
            }
            else
            {
                if (contentSector != null)
                {
                    Log("using CONTENT: ", sectorId, contentVersion);
                }
                return(contentSector);
            }
        }
Exemplo n.º 3
0
        public MyGuiScreenEditorCopyTool(MyMwcObjectBuilder_Sector sectorBuilder)
            : base(new Vector2(0.5f, 0.5f), new Vector2(0.8f, 0.88f))
        {
            m_size          = new Vector2(0.815f, 0.95f);
            m_sectorBuilder = sectorBuilder;

            //Vector2 controlsDelta = new Vector2(0, 0.0525f);
            //Vector2 controlsColumn1Origin = new Vector2(-m_size.Value.X / 2.0f + 0.03f, -m_size.Value.Y / 2.0f + 0.08f);

            AddCaption(MyTextsWrapperEnum.CopyTool, MyGuiConstants.LABEL_TEXT_COLOR, new Vector2(0, 0.01f));

            m_objectList = new MyGuiControlListbox(this,
                                                   new Vector2(0f, -0.02f),
                                                   MyGuiConstants.LISTBOX_LONGMEDIUM_SIZE,
                                                   MyGuiConstants.DEFAULT_CONTROL_BACKGROUND_COLOR,
                                                   null, .6f, 1, 17, 1, false, true, false,
                                                   null, null, MyGuiManager.GetScrollbarSlider(), MyGuiManager.GetHorizontalScrollbarSlider(), 2, 1, MyGuiConstants.LISTBOX_BACKGROUND_COLOR_BLUE, 0f, 0f, 0f, 0f, 0, 0, -0.01f, -0.01f, -0.02f, 0.02f);

            m_objectList.MultipleSelection = true;

            Controls.Add(m_objectList);

            //AddOkAndCancelButtonControls();
            Vector2 buttonPosition = new Vector2(0, m_size.Value.Y / 2.0f - MyGuiConstants.MESSAGE_BOX_BORDER_AREA_Y - MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.Y - 0.02f);
            Vector2 buttonSize     = new Vector2(0.25f, MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.Y);

            Controls.Add(new MyGuiControlButton(this,
                                                new Vector2(MyGuiConstants.MESSAGE_BOX_BORDER_AREA_X - 0.05f - m_size.Value.X / 2, 0) + buttonPosition + buttonSize / 2,
                                                buttonSize,
                                                MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyTextsWrapperEnum.SelectAllNone, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, OnSelectAllNone, MyGuiControlButtonTextAlignment.CENTERED, true,
                                                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true));

            Controls.Add(new MyGuiControlButton(this,
                                                new Vector2(m_size.Value.X / 2 - MyGuiConstants.MESSAGE_BOX_BORDER_AREA_X - MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.X - buttonSize.X + 0.01f, 0) + buttonPosition + buttonSize / 2,
                                                buttonSize,
                                                MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyTextsWrapperEnum.AddSelectedToSector, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, OnAddSelected, MyGuiControlButtonTextAlignment.CENTERED, true,
                                                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true));

            Controls.Add(new MyGuiControlButton(this,
                                                new Vector2(m_size.Value.X / 2 - MyGuiConstants.MESSAGE_BOX_BORDER_AREA_X - MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.X + 0.05f, 0) + buttonPosition + MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE / 2,
                                                MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE,
                                                MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyTextsWrapperEnum.Cancel, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, OnCancel, MyGuiControlButtonTextAlignment.CENTERED, true,
                                                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true));

            FillControls();
        }
Exemplo n.º 4
0
 private static MyMwcObjectBuilder_Sector LoadSector(MyMwcSectorIdentifier sectorId, string filename)
 {
     if (File.Exists(filename))
     {
         MyMwcObjectBuilder_Sector result = LoadData <MyMwcObjectBuilder_Sector>(filename);
         if (result == null)
         {
             MyMwcLog.WriteLine("Incorrect save data");
             return(null);
         }
         Log("hit", sectorId, result.Version);
         return(result);
     }
     else
     {
         Log("miss", sectorId);
         return(null);
     }
 }
Exemplo n.º 5
0
        public static void Save(MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Sector sector, MyMwcSectorIdentifier sectorIdentifier, bool createChapter = false)
        {
            if (sector == null) // Nothing to save, saving only checkpoint
            {
                return;
            }

            string sectorPath     = GetSectorPath(sectorIdentifier);
            string storeDirectory = Path.GetDirectoryName(sectorPath);

            // Store current sector
            SaveData(sector, sectorPath);


            // Store checkpoint
            if (checkpoint != null)
            {
                string checkpointPath = Path.Combine(storeDirectory, "Checkpoint.mwc");

                var oldValue = checkpoint.SectorObjectBuilder;
                checkpoint.SectorObjectBuilder = null;

                SaveData(checkpoint, checkpointPath);

                checkpoint.SectorObjectBuilder = oldValue;
            }

            if (createChapter)
            {
                var chapterDirectory = GetChapterDirectory(GetChapterName(checkpoint));
                if (Directory.Exists(chapterDirectory))
                {
                    Directory.Delete(chapterDirectory, true);
                }
                DirectoryExtensions.CopyAll(storeDirectory, chapterDirectory);
            }

            Log("update", sectorIdentifier, sector.Version);
        }
        //private void LoadSector()
        //{
        //    // Handles also cache
        //    var travelScreen = new MyGuiScreenEnterSectorProgress(MyMwcTravelTypeEnum.SOLAR, m_checkpoint.CurrentSector.Position, new MinerWarsMath.Vector3(), OnTravelSuccess, m_checkpoint.CurrentSector);
        //    MyGuiManager.AddScreen(travelScreen);
        //}

        private void OnTravelSuccess(MyMwcObjectBuilder_Sector sector, Vector3 newPosition)
        {
            m_checkpoint.SectorObjectBuilder = sector;
            m_loadCheckpointSuccessfulAction(m_checkpoint);
            CloseScreen();
        }
Exemplo n.º 7
0
        private void TravelSectorLoaded(MyMwcTravelTypeEnum travelType, MyMwcVector3Int targetSector, byte[] sectorDataResponse, MyMwcObjectBuilder_Sector cachedSector)
        {
            var checkpoint = GetCheckpointBuilder(false);

            checkpoint.SectorObjectBuilder = cachedSector;

            // Overwrite current sector
            checkpoint.CurrentSector.Position = targetSector;
            UpdatePlayerPosition(travelType, ref checkpoint.PlayerObjectBuilder.ShipObjectBuilder.PositionAndOrientation.Position);

            if (sectorDataResponse != null)
            {
                checkpoint.SectorObjectBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Sector>(sectorDataResponse);
                MyLocalCache.Save(null, checkpoint.SectorObjectBuilder, checkpoint.CurrentSector);
            }

            // Change NEW_STORY to LOAD_CHECKPOINT, because it's necessary, travel is never new story
            MyMwcStartSessionRequestTypeEnum?sessionStart = null;

            if (MyGuiScreenGamePlay.Static != null)
            {
                sessionStart = MyGuiScreenGamePlay.Static.GetSessionType();
                if (sessionStart.HasValue && sessionStart.Value == MyMwcStartSessionRequestTypeEnum.NEW_STORY)
                {
                    sessionStart = MyMwcStartSessionRequestTypeEnum.LOAD_CHECKPOINT;
                }
            }

            MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, sessionStart, null, null, travelType);
        }
Exemplo n.º 8
0
        private void SandboxSectorLoaded(MyMwcVector3Int targetSector, MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Sector cachedSector, MyMwcStartSessionRequestTypeEnum startSessionType, MyMissionID?startMission)
        {
            if (checkpoint.SectorObjectBuilder == null) // Server said, use cache
            {
                checkpoint.SectorObjectBuilder = cachedSector;
            }
            else
            {
                MyLocalCache.SaveCheckpoint(checkpoint);
            }

            MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, startSessionType, MyGuiScreenGamePlayType.GAME_SANDBOX, startMission);
        }