Example #1
0
        public static void PackWorld(string directoryName, Stream targetStream, Func <string, bool> filter, bool embedExternalContent)
        {
            WorldInfo worldInfo = GetWorldInfo(directoryName);

            if (worldInfo == null)
            {
                throw new InvalidOperationException("Directory does not contain a world.");
            }
            List <string> list = new List <string>();

            RecursiveEnumerateDirectory(directoryName, list, null, filter);
            using (ZipArchive zipArchive = ZipArchive.Create(targetStream, keepStreamOpen: true))
            {
                foreach (string item in list)
                {
                    using (Stream source = Storage.OpenFile(item, OpenFileMode.Read))
                    {
                        string fileName = Storage.GetFileName(item);
                        zipArchive.AddStream(fileName, source);
                    }
                }
                if (embedExternalContent)
                {
                    if (!BlocksTexturesManager.IsBuiltIn(worldInfo.WorldSettings.BlocksTextureName))
                    {
                        try
                        {
                            using (Stream source2 = Storage.OpenFile(BlocksTexturesManager.GetFileName(worldInfo.WorldSettings.BlocksTextureName), OpenFileMode.Read))
                            {
                                string filenameInZip = Storage.CombinePaths("EmbeddedContent", Storage.GetFileNameWithoutExtension(worldInfo.WorldSettings.BlocksTextureName) + ".scbtex");
                                zipArchive.AddStream(filenameInZip, source2);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Warning($"Failed to embed blocks texture \"{worldInfo.WorldSettings.BlocksTextureName}\". Reason: {ex.Message}");
                        }
                    }
                    foreach (PlayerInfo playerInfo in worldInfo.PlayerInfos)
                    {
                        if (!CharacterSkinsManager.IsBuiltIn(playerInfo.CharacterSkinName))
                        {
                            try
                            {
                                using (Stream source3 = Storage.OpenFile(CharacterSkinsManager.GetFileName(playerInfo.CharacterSkinName), OpenFileMode.Read))
                                {
                                    string filenameInZip2 = Storage.CombinePaths("EmbeddedContent", Storage.GetFileNameWithoutExtension(playerInfo.CharacterSkinName) + ".scskin");
                                    zipArchive.AddStream(filenameInZip2, source3);
                                }
                            }
                            catch (Exception ex2)
                            {
                                Log.Warning($"Failed to embed character skin \"{playerInfo.CharacterSkinName}\". Reason: {ex2.Message}");
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public IEnumerable <ActiveExternalContentInfo> GetActiveExternalContent()
        {
            string downloadedContentAddress = CommunityContentManager.GetDownloadedContentAddress(ExternalContentType.World, DirectoryName);

            if (!string.IsNullOrEmpty(downloadedContentAddress))
            {
                yield return(new ActiveExternalContentInfo
                {
                    Address = downloadedContentAddress,
                    DisplayName = WorldSettings.Name,
                    Type = ExternalContentType.World
                });
            }
            if (!BlocksTexturesManager.IsBuiltIn(WorldSettings.BlocksTextureName))
            {
                downloadedContentAddress = CommunityContentManager.GetDownloadedContentAddress(ExternalContentType.BlocksTexture, WorldSettings.BlocksTextureName);
                if (!string.IsNullOrEmpty(downloadedContentAddress))
                {
                    yield return(new ActiveExternalContentInfo
                    {
                        Address = downloadedContentAddress,
                        DisplayName = BlocksTexturesManager.GetDisplayName(WorldSettings.BlocksTextureName),
                        Type = ExternalContentType.BlocksTexture
                    });
                }
            }
            SubsystemPlayers subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true);

            foreach (PlayerData playersDatum in subsystemPlayers.PlayersData)
            {
                if (!CharacterSkinsManager.IsBuiltIn(playersDatum.CharacterSkinName))
                {
                    downloadedContentAddress = CommunityContentManager.GetDownloadedContentAddress(ExternalContentType.CharacterSkin, playersDatum.CharacterSkinName);
                    yield return(new ActiveExternalContentInfo
                    {
                        Address = downloadedContentAddress,
                        DisplayName = CharacterSkinsManager.GetDisplayName(playersDatum.CharacterSkinName),
                        Type = ExternalContentType.CharacterSkin
                    });
                }
            }
            SubsystemFurnitureBlockBehavior subsystemFurnitureBlockBehavior = base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true);

            foreach (FurnitureSet furnitureSet in subsystemFurnitureBlockBehavior.FurnitureSets)
            {
                if (furnitureSet.ImportedFrom != null)
                {
                    downloadedContentAddress = CommunityContentManager.GetDownloadedContentAddress(ExternalContentType.FurniturePack, furnitureSet.ImportedFrom);
                    yield return(new ActiveExternalContentInfo
                    {
                        Address = downloadedContentAddress,
                        DisplayName = FurniturePacksManager.GetDisplayName(furnitureSet.ImportedFrom),
                        Type = ExternalContentType.FurniturePack
                    });
                }
            }
        }
Example #3
0
 public Texture2D GetTexture(string name)
 {
     if (!m_textures.TryGetValue(name, out Texture2D value))
     {
         value = CharacterSkinsManager.LoadTexture(name);
         m_textures.Add(name, value);
     }
     return(value);
 }
Example #4
0
        public void RandomizeCharacterSkin()
        {
            Random random = new Random();

            CharacterSkinsManager.UpdateCharacterSkinsList();
            string[] array  = CharacterSkinsManager.CharacterSkinsNames.Where((string n) => CharacterSkinsManager.IsBuiltIn(n) && CharacterSkinsManager.GetPlayerClass(n) == m_playerClass).ToArray();
            string[] second = SubsystemPlayers.PlayersData.Select((PlayerData pd) => pd.CharacterSkinName).ToArray();
            string[] array2 = array.Except(second).ToArray();
            if (array2.Length != 0)
            {
                CharacterSkinName = array2[random.Int(0, array2.Length - 1)];
            }
            else
            {
                CharacterSkinName = array[random.Int(0, array.Length - 1)];
            }
        }
        public LoadingScreen()
        {
            WidgetsManager.LoadWidgetContents((Widget)this.ScreenWidget, (object)this, ContentManager.Get <XElement>("Screens/LoadingScreen"));

            LabelWidget ExternalAssemblyInfo = new LabelWidget();

            ExternalAssemblyInfo.Text = "Powered By GScience Studio\n";
            //下列两行代码请勿随意删除
            ExternalAssemblyInfo.Text += "Author:" + Info.author + "\n";
            ExternalAssemblyInfo.Text += "Version:" + Info.version;

            ExternalAssemblyInfo.Color     = Color.LightBlue;
            ExternalAssemblyInfo.FontScale = 0.5f;
            this.ScreenWidget.Children.Add(ExternalAssemblyInfo);

            this.AddLoadAction((Action)(() => CommunityContentManager.Initialize()));
            this.AddLoadAction((Action)(() => MotdManager.Initialize()));
            this.AddLoadAction((Action)(() => LightingManager.Initialize()));
            this.AddLoadAction((Action)(() => StringsManager.LoadStrings()));
            this.AddLoadAction((Action)(() => TextureAtlasManager.LoadAtlases()));
            ReadOnlyList <ContentInfo> readOnlyList = ContentManager.List();

            // ISSUE: explicit reference operation
            using (ReadOnlyList <ContentInfo> .Enumerator enumerator = ((ReadOnlyList <ContentInfo>)@readOnlyList).GetEnumerator())
            {
                // ISSUE: explicit reference operation
                while (((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).MoveNext())
                {
                    // ISSUE: explicit reference operation
                    ContentInfo localContentInfo = ((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).Current;
                    this.AddLoadAction((Action)(() => ContentManager.Get((string)localContentInfo.Name)));
                }
            }
            this.AddLoadAction((Action)(() => DatabaseManager.LoadDatabase()));
            this.AddLoadAction((Action)(() => WorldsManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksTexturesManager.Initialize()));
            this.AddLoadAction((Action)(() => CharacterSkinsManager.Initialize()));
            this.AddLoadAction((Action)(() => FurniturePacksManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksManager.Initialize()));
            this.AddLoadAction((Action)(() => CraftingRecipesManager.Initialize()));
            this.AddLoadAction((Action)(() => GScienceStudio.InputManager.Initialize()));
        }
Example #6
0
        public static string ImportExternalContentSync(Stream stream, ExternalContentType type, string name)
        {
            switch (type)
            {
            case ExternalContentType.World:
                return(WorldsManager.ImportWorld(stream));

            case ExternalContentType.BlocksTexture:
                return(BlocksTexturesManager.ImportBlocksTexture(name, stream));

            case ExternalContentType.CharacterSkin:
                return(CharacterSkinsManager.ImportCharacterSkin(name, stream));

            case ExternalContentType.FurniturePack:
                return(FurniturePacksManager.ImportFurniturePack(name, stream));

            default:
                throw new InvalidOperationException(LanguageControl.Get(fName, 4));
            }
        }
Example #7
0
        public static void DeleteExternalContent(ExternalContentType type, string name)
        {
            switch (type)
            {
            case ExternalContentType.World:
                WorldsManager.DeleteWorld(name);
                break;

            case ExternalContentType.BlocksTexture:
                BlocksTexturesManager.DeleteBlocksTexture(name);
                break;

            case ExternalContentType.CharacterSkin:
                CharacterSkinsManager.DeleteCharacterSkin(name);
                break;

            case ExternalContentType.FurniturePack:
                FurniturePacksManager.DeleteFurniturePack(name);
                break;

            default:
                throw new InvalidOperationException(LanguageControl.Get(fName, 4));
            }
        }
Example #8
0
        public override void Initialize()
        {
            if (Initialize1 != null)
            {
                Initialize1();
                return;
            }
            int num = 0;
            Dictionary <int, ClothingData> dictionary = new Dictionary <int, ClothingData>();
            IEnumerator <XElement>         enumerator = ModsManager.CombineXml(ContentManager.Get <XElement>("Clothes"), ModsManager.GetEntries(".clo"), "Index", "Clothes").Elements().GetEnumerator();

            while (enumerator.MoveNext())
            {
                XElement item           = enumerator.Current;
                string   newDescription = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "Description");
                string   newDisplayName = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "DisplayName");
                if (item.Attribute("DisplayName") != null && item.Attribute("Description") != null)
                {
                    newDisplayName = XmlUtils.GetAttributeValue <string>(item, "DisplayName");
                    newDescription = XmlUtils.GetAttributeValue <string>(item, "Description");
                }
                ClothingData clothingData = new ClothingData
                {
                    Index                    = XmlUtils.GetAttributeValue <int>(item, "Index"),
                    DisplayIndex             = num++,
                    DisplayName              = newDisplayName,
                    Slot                     = XmlUtils.GetAttributeValue <ClothingSlot>(item, "Slot"),
                    ArmorProtection          = XmlUtils.GetAttributeValue <float>(item, "ArmorProtection"),
                    Sturdiness               = XmlUtils.GetAttributeValue <float>(item, "Sturdiness"),
                    Insulation               = XmlUtils.GetAttributeValue <float>(item, "Insulation"),
                    MovementSpeedFactor      = XmlUtils.GetAttributeValue <float>(item, "MovementSpeedFactor"),
                    SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(item, "SteedMovementSpeedFactor"),
                    DensityModifier          = XmlUtils.GetAttributeValue <float>(item, "DensityModifier"),
                    IsOuter                  = XmlUtils.GetAttributeValue <bool>(item, "IsOuter"),
                    CanBeDyed                = XmlUtils.GetAttributeValue <bool>(item, "CanBeDyed"),
                    Layer                    = XmlUtils.GetAttributeValue <int>(item, "Layer"),
                    PlayerLevelRequired      = XmlUtils.GetAttributeValue <int>(item, "PlayerLevelRequired"),
                    Texture                  = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(item, "TextureName")),
                    ImpactSoundsFolder       = XmlUtils.GetAttributeValue <string>(item, "ImpactSoundsFolder"),
                    Description              = newDescription
                };
                dictionary.Add(clothingData.Index, clothingData);
            }
            m_clothingData = new ClothingData[dictionary.Count];
            for (int i = 0; i < dictionary.Count; i++)
            {
                m_clothingData[i] = dictionary[i];
            }
            Model playerModel = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male);

            Matrix[] array = new Matrix[playerModel.Bones.Count];
            playerModel.CopyAbsoluteBoneTransformsTo(array);
            int index  = playerModel.FindBone("Hand1").Index;
            int index2 = playerModel.FindBone("Hand2").Index;

            array[index]  = Matrix.CreateRotationY(0.1f) * array[index];
            array[index2] = Matrix.CreateRotationY(-0.1f) * array[index2];
            m_innerMesh   = new BlockMesh();
            foreach (ModelMesh mesh in playerModel.Meshes)
            {
                Matrix matrix = array[mesh.ParentBone.Index];
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    Color color = Color.White * 0.8f;
                    color.A = byte.MaxValue;
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color);
                }
            }
            Model outerClothingModel = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male);

            Matrix[] array2 = new Matrix[outerClothingModel.Bones.Count];
            outerClothingModel.CopyAbsoluteBoneTransformsTo(array2);
            int index3 = outerClothingModel.FindBone("Leg1").Index;
            int index4 = outerClothingModel.FindBone("Leg2").Index;

            array2[index3] = Matrix.CreateTranslation(-0.02f, 0f, 0f) * array2[index3];
            array2[index4] = Matrix.CreateTranslation(0.02f, 0f, 0f) * array2[index4];
            m_outerMesh    = new BlockMesh();
            foreach (ModelMesh mesh2 in outerClothingModel.Meshes)
            {
                Matrix matrix2 = array2[mesh2.ParentBone.Index];
                foreach (ModelMeshPart meshPart2 in mesh2.MeshParts)
                {
                    Color color2 = Color.White * 0.8f;
                    color2.A = byte.MaxValue;
                    m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
                    m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color2);
                }
            }
            base.Initialize();
        }
Example #9
0
        // Replace ClothingBlock.Initialize
        public override void Initialize()
        {
            var num        = 0;
            var dictionary = new Dictionary <int, ClothingData>();

            for (var i = ContentManager.CombineXml(ContentManager.Get <XElement>("Clothes"), ModsManager.GetEntries(".clo"), "Index", "DisplayName", "Clothes").Elements().GetEnumerator(); i.MoveNext();)
            {
                var element      = i.Current;
                var clothingData = new ClothingData
                {
                    Index                    = XmlUtils.GetAttributeValue <int>(element, "Index"),
                    DisplayIndex             = num++,
                    DisplayName              = XmlUtils.GetAttributeValue <string>(element, "DisplayName"),
                    Slot                     = XmlUtils.GetAttributeValue <ClothingSlot>(element, "Slot"),
                    ArmorProtection          = XmlUtils.GetAttributeValue <float>(element, "ArmorProtection"),
                    Sturdiness               = XmlUtils.GetAttributeValue <float>(element, "Sturdiness"),
                    Insulation               = XmlUtils.GetAttributeValue <float>(element, "Insulation"),
                    MovementSpeedFactor      = XmlUtils.GetAttributeValue <float>(element, "MovementSpeedFactor"),
                    SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(element, "SteedMovementSpeedFactor"),
                    DensityModifier          = XmlUtils.GetAttributeValue <float>(element, "DensityModifier"),
                    IsOuter                  = XmlUtils.GetAttributeValue <bool>(element, "IsOuter"),
                    CanBeDyed                = XmlUtils.GetAttributeValue <bool>(element, "CanBeDyed"),
                    Layer                    = XmlUtils.GetAttributeValue <int>(element, "Layer"),
                    PlayerLevelRequired      = XmlUtils.GetAttributeValue <int>(element, "PlayerLevelRequired"),
                    Texture                  = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(element, "TextureName")),
                    ImpactSoundsFolder       = XmlUtils.GetAttributeValue <string>(element, "ImpactSoundsFolder"),
                    Description              = XmlUtils.GetAttributeValue <string>(element, "Description")
                };
                dictionary[clothingData.Index] = clothingData;
            }

            m_clothingData = new ClothingData[dictionary.Count];
            int index;

            for (index = 0; index < dictionary.Count; ++index)
            {
                m_clothingData[index] = dictionary[index];
            }
            var playerModel         = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male);
            var absoluteTransforms1 = new Matrix[playerModel.Bones.Count];

            playerModel.CopyAbsoluteBoneTransformsTo(absoluteTransforms1);
            index = playerModel.FindBone("Hand1", true).Index;
            int index2 = playerModel.FindBone("Hand2", true).Index;

            absoluteTransforms1[index]  = Matrix.CreateRotationY(0.1f) * absoluteTransforms1[index];
            absoluteTransforms1[index2] = Matrix.CreateRotationY(-0.1f) * absoluteTransforms1[index2];
            m_innerMesh = new BlockMesh();
            foreach (var mesh in playerModel.Meshes)
            {
                var matrix = absoluteTransforms1[mesh.ParentBone.Index];
                foreach (var meshPart in mesh.MeshParts)
                {
                    var color = Color.White * 0.8f;
                    color.A = byte.MaxValue;
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, false, false, false, false, Color.White);
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, false, true, false, true, color);
                }
            }

            var outerClothingModel  = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male);
            var absoluteTransforms2 = new Matrix[outerClothingModel.Bones.Count];

            outerClothingModel.CopyAbsoluteBoneTransformsTo(absoluteTransforms2);
            var index3 = outerClothingModel.FindBone("Leg1", true).Index;
            var index4 = outerClothingModel.FindBone("Leg2", true).Index;

            absoluteTransforms2[index3] = Matrix.CreateTranslation(-0.02f, 0.0f, 0.0f) * absoluteTransforms2[index3];
            absoluteTransforms2[index4] = Matrix.CreateTranslation(0.02f, 0.0f, 0.0f) * absoluteTransforms2[index4];
            m_outerMesh = new BlockMesh();
            foreach (var mesh in outerClothingModel.Meshes)
            {
                var matrix = absoluteTransforms2[mesh.ParentBone.Index];
                foreach (var meshPart in mesh.MeshParts)
                {
                    var color = Color.White * 0.8f;
                    color.A = byte.MaxValue;
                    m_outerMesh.AppendModelMeshPart(meshPart, matrix, false, false, false, false, Color.White);
                    m_outerMesh.AppendModelMeshPart(meshPart, matrix, false, true, false, true, color);
                }
            }

            base.Initialize();
        }
Example #10
0
        public override void Update()
        {
            m_characterSkinsCache.GetTexture(m_playerData.CharacterSkinName);
            m_playerModel.PlayerClass       = m_playerData.PlayerClass;
            m_playerModel.CharacterSkinName = m_playerData.CharacterSkinName;
            m_playerClassButton.Text        = m_playerData.PlayerClass.ToString();
            if (!m_nameTextBox.HasFocus)
            {
                m_nameTextBox.Text = m_playerData.Name;
            }
            m_characterSkinLabel.Text = CharacterSkinsManager.GetDisplayName(m_playerData.CharacterSkinName);
            m_controlsLabel.Text      = GetDeviceDisplayName(m_inputDevices.Where((WidgetInputDevice id) => (id & m_playerData.InputDevice) != 0).FirstOrDefault());
            ValuesDictionary valuesDictionary = DatabaseManager.FindValuesDictionaryForComponent(DatabaseManager.FindEntityValuesDictionary(m_playerData.GetEntityTemplateName(), throwIfNotFound: true), typeof(ComponentCreature));
            string           dy = valuesDictionary.GetValue <string>("Description");

            if (dy.StartsWith("[") && dy.EndsWith("]"))
            {
                string[] lp = dy.Substring(1, dy.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                dy = LanguageControl.GetDatabase("Description", lp[1]);
            }
            m_descriptionLabel.Text = dy;
            if (m_playerClassButton.IsClicked)
            {
                m_playerData.PlayerClass = ((m_playerData.PlayerClass == PlayerClass.Male) ? PlayerClass.Female : PlayerClass.Male);
                m_playerData.RandomizeCharacterSkin();
                if (m_playerData.IsDefaultName)
                {
                    m_playerData.ResetName();
                }
            }
            if (m_characterSkinButton.IsClicked)
            {
                CharacterSkinsManager.UpdateCharacterSkinsList();
                IEnumerable <string> items  = CharacterSkinsManager.CharacterSkinsNames.Where((string n) => CharacterSkinsManager.GetPlayerClass(n) == m_playerData.PlayerClass || !CharacterSkinsManager.GetPlayerClass(n).HasValue);
                ListSelectionDialog  dialog = new ListSelectionDialog(LanguageControl.Get(fName, 1), items, 64f, delegate(object item)
                {
                    XElement node       = ContentManager.Get <XElement>("Widgets/CharacterSkinItem");
                    ContainerWidget obj = (ContainerWidget)Widget.LoadWidget(this, node, null);
                    Texture2D texture   = m_characterSkinsCache.GetTexture((string)item);
                    obj.Children.Find <LabelWidget>("CharacterSkinItem.Text").Text    = CharacterSkinsManager.GetDisplayName((string)item);
                    obj.Children.Find <LabelWidget>("CharacterSkinItem.Details").Text = $"{texture.Width}x{texture.Height}";
                    PlayerModelWidget playerModelWidget    = obj.Children.Find <PlayerModelWidget>("CharacterSkinItem.Model");
                    playerModelWidget.PlayerClass          = m_playerData.PlayerClass;
                    playerModelWidget.CharacterSkinTexture = texture;
                    return(obj);
                }, delegate(object item)
                {
                    m_playerData.CharacterSkinName = (string)item;
                    if (m_playerData.IsDefaultName)
                    {
                        m_playerData.ResetName();
                    }
                });
                DialogsManager.ShowDialog(null, dialog);
            }
            if (m_controlsButton.IsClicked)
            {
                DialogsManager.ShowDialog(null, new ListSelectionDialog(LanguageControl.Get(fName, 2), m_inputDevices, 56f, (object d) => GetDeviceDisplayName((WidgetInputDevice)d), delegate(object d)
                {
                    WidgetInputDevice widgetInputDevice = (WidgetInputDevice)d;
                    m_playerData.InputDevice            = widgetInputDevice;
                    foreach (PlayerData playersDatum in m_playerData.SubsystemPlayers.PlayersData)
                    {
                        if (playersDatum != m_playerData && (playersDatum.InputDevice & widgetInputDevice) != 0)
                        {
                            playersDatum.InputDevice &= ~widgetInputDevice;
                        }
                    }
                }));
            }
            if (m_addButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
            }
            if (m_deleteButton.IsClicked)
            {
                DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "warning"), LanguageControl.Get(fName, 3), LanguageControl.Get("Usual", "ok"), LanguageControl.Get("Usual", "cancel"), delegate(MessageDialogButton b)
                {
                    if (b == MessageDialogButton.Button1)
                    {
                        m_playerData.SubsystemPlayers.RemovePlayerData(m_playerData);
                        ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
                    }
                }));
            }
            if (m_playButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Game");
            }
            if (m_addAnotherButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Player", Mode.Initial, m_playerData.SubsystemPlayers.Project);
            }
            if ((base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked) && VerifyName())
            {
                if (m_mode == Mode.Initial)
                {
                    GameManager.SaveProject(waitForCompletion: true, showErrorDialog: true);
                    GameManager.DisposeProject();
                    ScreensManager.SwitchScreen("MainMenu");
                }
                else if (m_mode == Mode.Add || m_mode == Mode.Edit)
                {
                    ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
                }
            }
            m_nameWasInvalid = false;
        }
Example #11
0
 public override void MeasureOverride(Vector2 parentAvailableSize)
 {
     if (OuterClothing)
     {
         m_modelWidget.Model = CharacterSkinsManager.GetOuterClothingModel(PlayerClass);
     }
     else
     {
         m_modelWidget.Model = CharacterSkinsManager.GetPlayerModel(PlayerClass);
     }
     if (CameraShot == Shot.Body)
     {
         m_modelWidget.ViewPosition = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.46f, -3.2f) : new Vector3(0f, 1.39f, -3.04f));
         m_modelWidget.ViewTarget   = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 0.9f, 0f) : new Vector3(0f, 0.86f, 0f));
         m_modelWidget.ViewFov      = 0.57f;
     }
     else
     {
         if (CameraShot != Shot.Bust)
         {
             throw new InvalidOperationException("Unknown shot.");
         }
         m_modelWidget.ViewPosition = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.5f, -1.05f) : new Vector3(0f, 1.43f, -1f));
         m_modelWidget.ViewTarget   = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.5f, 0f) : new Vector3(0f, 1.43f, 0f));
         m_modelWidget.ViewFov      = 0.57f;
     }
     if (OuterClothing)
     {
         m_modelWidget.TextureOverride = OuterClothingTexture;
     }
     else
     {
         m_modelWidget.TextureOverride = ((CharacterSkinName != null) ? CharacterSkinsCache.GetTexture(CharacterSkinName) : CharacterSkinTexture);
     }
     if (AnimateHeadSeed != 0)
     {
         int     num    = (AnimateHeadSeed < 0) ? GetHashCode() : AnimateHeadSeed;
         float   num2   = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * (double)num, 10000.0);
         Vector2 vector = default(Vector2);
         vector.X = MathUtils.Lerp(-0.75f, 0.75f, SimplexNoise.OctavedNoise(num2 + 100f, 0.2f, 1, 2f, 0.5f));
         vector.Y = MathUtils.Lerp(-0.5f, 0.5f, SimplexNoise.OctavedNoise(num2 + 200f, 0.17f, 1, 2f, 0.5f));
         Matrix value = Matrix.CreateRotationX(vector.Y) * Matrix.CreateRotationZ(vector.X);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Head").Index, value);
     }
     if (!OuterClothing && AnimateHandsSeed != 0)
     {
         int     num3    = (AnimateHandsSeed < 0) ? GetHashCode() : AnimateHandsSeed;
         float   num4    = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * (double)num3, 10000.0);
         Vector2 vector2 = default(Vector2);
         vector2.X = MathUtils.Lerp(0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 100f, 0.7f, 1, 2f, 0.5f));
         vector2.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 200f, 0.7f, 1, 2f, 0.5f));
         Vector2 vector3 = default(Vector2);
         vector3.X = MathUtils.Lerp(-0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 300f, 0.7f, 1, 2f, 0.5f));
         vector3.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 400f, 0.7f, 1, 2f, 0.5f));
         Matrix value2 = Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationY(vector2.X);
         Matrix value3 = Matrix.CreateRotationX(vector3.Y) * Matrix.CreateRotationY(vector3.X);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Hand1").Index, value2);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Hand2").Index, value3);
     }
     base.MeasureOverride(parentAvailableSize);
 }
Example #12
0
        public LoadingScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/LoadingScreen");

            LoadContents(this, node);
            AddLoadAction(delegate
            {
                VrManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CommunityContentManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MotdManager.Initialize();
            });
            AddLoadAction(delegate
            {
                LightingManager.Initialize();
            });
            AddLoadAction(delegate
            {
                StringsManager.LoadStrings();
            });
            AddLoadAction(delegate
            {
                TextureAtlasManager.LoadAtlases();
            });
            foreach (ContentInfo item in ContentManager.List())
            {
                ContentInfo localContentInfo = item;
                AddLoadAction(delegate
                {
                    ContentManager.Get(localContentInfo.Name);
                });
            }
            AddLoadAction(delegate
            {
                DatabaseManager.Initialize();
            });
            AddLoadAction(delegate
            {
                WorldsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksTexturesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CharacterSkinsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                FurniturePacksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CraftingRecipesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MusicManager.CurrentMix = MusicManager.Mix.Menu;
            });
        }
Example #13
0
        public void SpawnPlayer(Vector3 position, SpawnMode spawnMode)
        {
            ComponentMount componentMount = null;

            if (spawnMode != SpawnMode.Respawn && CheckIsPointInWater(Terrain.ToCell(position)))
            {
                Entity entity = DatabaseManager.CreateEntity(m_project, "Boat", throwIfNotFound: true);
                entity.FindComponent <ComponentBody>(throwOnError: true).Position = position;
                entity.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathUtils.DegToRad(45f));
                componentMount = entity.FindComponent <ComponentMount>(throwOnError: true);
                m_project.AddEntity(entity);
                position.Y += entity.FindComponent <ComponentBody>(throwOnError: true).BoxSize.Y;
            }
            string value  = "";
            string value2 = "";
            string value3 = "";
            string value4 = "";

            if (spawnMode != SpawnMode.Respawn)
            {
                if (PlayerClass == PlayerClass.Female)
                {
                    if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("2"))
                    {
                        value  = "";
                        value2 = MakeClothingValue(37, 2);
                        value3 = MakeClothingValue(16, 14);
                        value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(27, 0);
                    }
                    else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("3"))
                    {
                        value  = MakeClothingValue(31, 0);
                        value2 = MakeClothingValue(13, 7) + ";" + MakeClothingValue(5, 0);
                        value3 = MakeClothingValue(17, 15);
                        value4 = MakeClothingValue(29, 0);
                    }
                    else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("4"))
                    {
                        value  = MakeClothingValue(30, 7);
                        value2 = MakeClothingValue(14, 6);
                        value3 = MakeClothingValue(25, 7);
                        value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0);
                    }
                    else
                    {
                        value  = MakeClothingValue(30, 12);
                        value2 = MakeClothingValue(37, 3) + ";" + MakeClothingValue(1, 3);
                        value3 = MakeClothingValue(0, 12);
                        value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0);
                    }
                }
                else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("2"))
                {
                    value  = "";
                    value2 = MakeClothingValue(13, 0) + ";" + MakeClothingValue(5, 0);
                    value3 = MakeClothingValue(25, 8);
                    value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0);
                }
                else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("3"))
                {
                    value  = MakeClothingValue(32, 0);
                    value2 = MakeClothingValue(37, 5);
                    value3 = MakeClothingValue(0, 15);
                    value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0);
                }
                else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("4"))
                {
                    value  = MakeClothingValue(31, 0);
                    value2 = MakeClothingValue(15, 14);
                    value3 = MakeClothingValue(0, 0);
                    value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0);
                }
                else
                {
                    value  = MakeClothingValue(32, 0);
                    value2 = MakeClothingValue(37, 0) + ";" + MakeClothingValue(1, 9);
                    value3 = MakeClothingValue(0, 12);
                    value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0);
                }
            }
            ValuesDictionary overrides = new ValuesDictionary
            {
                {
                    "Player",
                    new ValuesDictionary
                    {
                        {
                            "PlayerIndex",
                            PlayerIndex
                        }
                    }
                },
                {
                    "Intro",
                    new ValuesDictionary
                    {
                        {
                            "PlayIntro",
                            spawnMode == SpawnMode.InitialIntro
                        }
                    }
                },
                {
                    "Clothing",
                    new ValuesDictionary
                    {
                        {
                            "Clothes",
                            new ValuesDictionary
                            {
                                {
                                    "Feet",
                                    value4
                                },
                                {
                                    "Legs",
                                    value3
                                },
                                {
                                    "Torso",
                                    value2
                                },
                                {
                                    "Head",
                                    value
                                }
                            }
                        }
                    }
                }
            };
            Vector2 v = ComponentIntro.FindOceanDirection(m_subsystemTerrain.TerrainContentsGenerator, position.XZ);
            string  entityTemplateName = (PlayerClass == PlayerClass.Male) ? "MalePlayer" : "FemalePlayer";
            Entity  entity2            = DatabaseManager.CreateEntity(m_project, entityTemplateName, overrides, throwIfNotFound: true);

            entity2.FindComponent <ComponentBody>(throwOnError: true).Position = position;
            entity2.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, Vector2.Angle(v, -Vector2.UnitY));
            m_project.AddEntity(entity2);
            if (componentMount != null)
            {
                entity2.FindComponent <ComponentRider>(throwOnError: true).StartMounting(componentMount);
            }
            LastSpawnTime = m_subsystemGameInfo.TotalElapsedGameTime;
            int num = ++SpawnsCount;
        }
Example #14
0
 public void ResetName()
 {
     m_name        = CharacterSkinsManager.GetDisplayName(CharacterSkinName);
     IsDefaultName = true;
 }
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     ClothingData clothingData = ClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Example #16
0
 public static void ShowUploadUi(ExternalContentType type, string name)
 {
     DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog(LanguageControl.Get(fName, 9), listingSupportRequired : false, delegate(IExternalContentProvider provider)
     {
         try
         {
             if (provider != null)
             {
                 ShowLoginUiIfNeeded(provider, showWarningDialog: true, delegate
                 {
                     CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 10), autoHideOnCancel: false);
                     DialogsManager.ShowDialog(null, busyDialog);
                     Task.Run(delegate
                     {
                         bool needsDelete  = false;
                         string sourcePath = null;
                         Stream stream     = null;
                         Action cleanup    = delegate
                         {
                             Utilities.Dispose(ref stream);
                             if (needsDelete && sourcePath != null)
                             {
                                 try
                                 {
                                     Storage.DeleteFile(sourcePath);
                                 }
                                 catch
                                 {
                                 }
                             }
                         };
                         try
                         {
                             string path;
                             if (type == ExternalContentType.BlocksTexture)
                             {
                                 sourcePath = BlocksTexturesManager.GetFileName(name);
                                 if (sourcePath == null)
                                 {
                                     throw new InvalidOperationException(LanguageControl.Get(fName, 11));
                                 }
                                 path = Storage.GetFileName(sourcePath);
                             }
                             else if (type == ExternalContentType.CharacterSkin)
                             {
                                 sourcePath = CharacterSkinsManager.GetFileName(name);
                                 if (sourcePath == null)
                                 {
                                     throw new InvalidOperationException(LanguageControl.Get(fName, 11));
                                 }
                                 path = Storage.GetFileName(sourcePath);
                             }
                             else if (type == ExternalContentType.FurniturePack)
                             {
                                 sourcePath = FurniturePacksManager.GetFileName(name);
                                 if (sourcePath == null)
                                 {
                                     throw new InvalidOperationException(LanguageControl.Get(fName, 11));
                                 }
                                 path = Storage.GetFileName(sourcePath);
                             }
                             else
                             {
                                 if (type != ExternalContentType.World)
                                 {
                                     throw new InvalidOperationException(LanguageControl.Get(fName, 12));
                                 }
                                 busyDialog.LargeMessage = LanguageControl.Get(fName, 13);
                                 sourcePath   = "android:SurvivalCraft2.2/WorldUpload.tmp";
                                 needsDelete  = true;
                                 string name2 = WorldsManager.GetWorldInfo(name).WorldSettings.Name;
                                 path         = $"{name2}.scworld";
                                 using (Stream targetStream = Storage.OpenFile(sourcePath, OpenFileMode.Create))
                                 {
                                     WorldsManager.ExportWorld(name, targetStream);
                                 }
                             }
                             busyDialog.LargeMessage = LanguageControl.Get(fName, 14);
                             stream = Storage.OpenFile(sourcePath, OpenFileMode.Read);
                             provider.Upload(path, stream, busyDialog.Progress, delegate(string link)
                             {
                                 long length = stream.Length;
                                 cleanup();
                                 DialogsManager.HideDialog(busyDialog);
                                 if (string.IsNullOrEmpty(link))
                                 {
                                     DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "success"), string.Format(LanguageControl.Get(fName, 15), DataSizeFormatter.Format(length)), LanguageControl.Get("Usual", "ok"), null, null));
                                 }
                                 else
                                 {
                                     DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link));
                                 }
                             }, delegate(Exception error)
                             {
                                 cleanup();
                                 DialogsManager.HideDialog(busyDialog);
                                 DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null));
                             });
                         }
                         catch (Exception ex2)
                         {
                             cleanup();
                             DialogsManager.HideDialog(busyDialog);
                             DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex2.Message, LanguageControl.Get("Usual", "ok"), null, null));
                         }
                     });
                 });
             }
         }
         catch (Exception ex)
         {
             DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex.Message, LanguageControl.Get("Usual", "ok"), null, null));
         }
     }));
 }