Exemple #1
0
        public void AddItem(StringBuilder text, string tooltip = "", string icon = "", object userData = null)
        {
            var item = new MyGuiControlListbox.Item(text: text, icon: icon, userData: userData);

            m_itemsList.Add(item);
            m_itemsList.VisibleRowsCount = Math.Min(NUM_VISIBLE_ITEMS, m_numItems++) + 1;
        }
 public MyGuiDetailScreenBase(bool isTopMostScreen, MyGuiBlueprintScreenBase parent, string thumbnailTexture, MyGuiControlListbox.Item selectedItem, float textScale)
     : base(new Vector2(0.37f, 0.325f), new Vector2(0.725f, 0.4f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, isTopMostScreen)
 {
     m_thumbnailImage = new MyGuiControlImage()
     {
         BackgroundTexture = MyGuiConstants.TEXTURE_RECTANGLE_DARK,
     };
     m_thumbnailImage.SetPadding(new MyGuiBorderThickness(3f, 2f, 3f, 2f));
     m_thumbnailImage.SetTexture(thumbnailTexture);
     
     m_selectedItem = selectedItem;
     m_blueprintName = selectedItem.Text.ToString();
     m_textScale = textScale;
     m_parent = parent;
 }
 public MyGuiDetailScreenBase(bool isTopMostScreen, MyGuiBlueprintScreenBase parent, MyGuiCompositeTexture thumbnailTexture, MyGuiControlListbox.Item selectedItem, float textScale)
     : base(new Vector2(0.37f, 0.325f), new Vector2(0.725f, 0.4f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, isTopMostScreen)
 {
     m_thumbnailImage = new MyGuiControlImageButton(true);
     if (thumbnailTexture == null)
     {
         m_thumbnailImage.Visible = false;
     }
     else
     {
         m_thumbnailImage.BackgroundTexture = thumbnailTexture;
     }
     m_selectedItem = selectedItem;
     m_blueprintName = selectedItem.Text.ToString();
     m_textScale = textScale;
     m_parent = parent;
 }
 void OpenSharedBlueprint(MyBlueprintItemInfo itemInfo)
 {
     MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
     buttonType: MyMessageBoxButtonsType.YES_NO_CANCEL,
     styleEnum: MyMessageBoxStyleEnum.Info,
     messageCaption: new StringBuilder("Shared Blueprint"),
     messageText: new StringBuilder("Do you want to open this blueprint in steam workshop?"),
     callback: delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
     {
         if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
         {
             MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", itemInfo.PublishedItemId));
             m_recievedBlueprints.Remove(m_selectedItem);
             m_selectedItem = null;
             RefreshBlueprintList();
         }
         else if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.NO)
         {
             m_recievedBlueprints.Remove(m_selectedItem);
             m_selectedItem = null;
             RefreshBlueprintList();
         }
     }));
     
 }
        void ExtractWorkShopItems()
        {
            ProfilerShort.Begin("Blueprint screen - Extracting bluepritns");

            if (!Directory.Exists(m_workshopBlueprintFolder))
            {
                Directory.CreateDirectory(m_workshopBlueprintFolder);
            }
            var downloadedMods = Directory.GetFiles(m_workshopBlueprintFolder);

            foreach (var mod in downloadedMods)
            {
                var fileName = Path.GetFileNameWithoutExtension(mod);
                var id = ulong.Parse(fileName);
                if(!m_subscribedItemsList.Any(item => item.PublishedFileId == id))
                {
                    File.Delete(mod); 
                }
            }

            var tempPath = Path.Combine(m_workshopBlueprintFolder, "temp");
            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            var tempDir = Directory.CreateDirectory(tempPath);

            foreach (var subItem in m_subscribedItemsList)
            {
                if (downloadedMods.Any(item => item.Contains(subItem.PublishedFileId.ToString())))
                {
                    string archive = Array.Find(downloadedMods, item => item.Contains(subItem.PublishedFileId.ToString()));

                    var extractPath = Path.Combine(tempDir.FullName, subItem.PublishedFileId.ToString());

                    if (!File.Exists(extractPath))
                    {
                        Directory.CreateDirectory(extractPath);
                        var extracted = MyZipArchive.OpenOnFile(archive);

                        var modInfo = new MyObjectBuilder_ModInfo();
                        modInfo.SubtypeName = subItem.Title;
                        modInfo.WorkshopId = subItem.PublishedFileId;
                        modInfo.SteamIDOwner = subItem.SteamIDOwner;


                        var infoFile = Path.Combine(m_workshopBlueprintFolder, "temp", subItem.PublishedFileId.ToString(), "info.temp");
                        if (File.Exists(infoFile))
                        {
                            File.Delete(infoFile);
                        }
                        var infoSuccess = MyObjectBuilderSerializer.SerializeXML(infoFile, false, modInfo);
  
                        if (extracted.FileExists("thumb.png"))
                        {
                            var stream = extracted.GetFile("thumb.png").GetStream();
                            if (stream != null)
                            {
                                using (var file = File.Create(Path.Combine(extractPath, "thumb.png")))
                                {
                                    stream.CopyTo(file);
                                }
                            }
                            stream.Close();
                        }
                        
                        extracted.Dispose();

                        var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, subItem.PublishedFileId);
                        var listItem = new MyGuiControlListbox.Item(text: new StringBuilder(subItem.Title), toolTip: subItem.Title, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal, userData: info);

                        var itemIndex = m_blueprintList.Items.FindIndex(item => ((item.UserData as MyBlueprintItemInfo).PublishedItemId == (listItem.UserData as MyBlueprintItemInfo).PublishedItemId) && (item.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM);
                        if (itemIndex == -1)
                        {
                            m_blueprintList.Add(listItem);
                        }
                    }
                }
            }
            ProfilerShort.End();
        }
        void OnSelectItem(MyGuiControlListbox list)
        {
            if (list.SelectedItems.Count == 0)
            {
                return;
            }
            
            m_selectedItem = list.SelectedItems[0];
            m_detailsButton.Enabled = true;
            m_screenshotButton.Enabled = true;
            m_replaceButton.Enabled = m_clipboard.HasCopiedGrids();

            var type = (m_selectedItem.UserData as MyBlueprintItemInfo).Type;
            var id = (m_selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId;
            var path = "";

            if (type == MyBlueprintTypeEnum.LOCAL)
            {
                path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString(), "thumb.png");
                m_deleteButton.Enabled = true;
            }
            else if (type == MyBlueprintTypeEnum.STEAM)
            {
                path = Path.Combine(m_workshopBlueprintFolder, "temp", id.ToString(), "thumb.png");
                m_screenshotButton.Enabled = false;
                m_replaceButton.Enabled = false;
                m_deleteButton.Enabled = false;
            }
            else if (type == MyBlueprintTypeEnum.SHARED)
            {
                m_replaceButton.Enabled = false;
                m_screenshotButton.Enabled = false;
                m_detailsButton.Enabled = false;
                m_deleteButton.Enabled = false;
            }
            else if (type == MyBlueprintTypeEnum.DEFAULT)
            {
                path = Path.Combine(m_defaultBlueprintFolder, m_selectedItem.Text.ToString(), "thumb.png");
                m_replaceButton.Enabled = false;
                m_screenshotButton.Enabled = false;
                m_deleteButton.Enabled = false;
            }

            if (File.Exists(path))
            {
                m_selectedImage.SetTexture(path);
            }

            else
            {
                m_selectedImage.BackgroundTexture = null;
            }
        }
        private MyGuiControlListbox.Item AddBlockToList(MyTerminalBlock block)
        {
            var item = new MyGuiControlListbox.Item(userData: block);
            UpdateItemAppearance(block, item);
            block.CustomNameChanged += block_CustomNameChanged;
            block.PropertiesChanged += block_CustomNameChanged;
            block.ShowInTerminalChanged += block_ShowInTerminalChanged;

            m_blockListbox.Add(item);
            return item;
        }
        void OnSelectItem(MyGuiControlListbox list)
        {
            if (list.SelectedItems.Count == 0)
            {
                return;
            }

            m_selectedItem = list.SelectedItems[0];
            m_detailsButton.Enabled = true;
            m_renameButton.Enabled = false;

            var type = (m_selectedItem.UserData as MyBlueprintItemInfo).Type;
            var id = (m_selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId;

            if (type == MyBlueprintTypeEnum.LOCAL)
            {
                m_deleteButton.Enabled = true;
                m_replaceButton.Enabled = true;
                m_renameButton.Enabled = true;
            }
            else if (type == MyBlueprintTypeEnum.STEAM)
            {
                m_deleteButton.Enabled = false;
                m_replaceButton.Enabled = false;
            }
            else if (type == MyBlueprintTypeEnum.SHARED)
            {
                m_renameButton.Enabled = false;
                m_detailsButton.Enabled = false;
                m_deleteButton.Enabled = false;
            }
        }
 void OnDetails(MyGuiControlButton button)
 {
     if (m_selectedItem == null)
     {
         if (m_activeDetail)
         {
             MyScreenManager.RemoveScreen(m_detailScreen);
         }
         return;
     }
     else if(m_activeDetail)
     {
         MyScreenManager.RemoveScreen(m_detailScreen);
     }
     else if (!m_activeDetail)
     {
         if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.LOCAL)
         {
             var path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen = new MyGuiDetailScreenLocal(
                     callBack: delegate(MyGuiControlListbox.Item item)
                     {
                         if (item == null)
                         {
                             m_screenshotButton.Enabled = false;
                             m_detailsButton.Enabled = false;
                             m_replaceButton.Enabled = false;
                             m_deleteButton.Enabled = false;
                         }
                         m_selectedItem = item;
                         m_activeDetail = false;
                         m_detailScreen = null;
                         if (Task.IsComplete)
                         {
                             RefreshBlueprintList();
                         }
                     },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             buttonType: MyMessageBoxButtonsType.OK,
                             styleEnum: MyMessageBoxStyleEnum.Error,
                             messageCaption: new StringBuilder("Error"),
                             messageText: new StringBuilder("Cannot find the blueprint file.")
                             ));
             }
         }
         else if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.DEFAULT)
         {
             var path = Path.Combine(m_defaultBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen = new MyGuiDetailScreenDefault(
                     callBack: delegate(MyGuiControlListbox.Item item)
                     {
                         if (item == null)
                         {
                             m_screenshotButton.Enabled = false;
                             m_detailsButton.Enabled = false;
                             m_replaceButton.Enabled = false;
                             m_deleteButton.Enabled = false;
                         }
                         m_selectedItem = item;
                         m_activeDetail = false;
                         m_detailScreen = null;
                         if (Task.IsComplete)
                         {
                             RefreshBlueprintList();
                         }
                     },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             buttonType: MyMessageBoxButtonsType.OK,
                             styleEnum: MyMessageBoxStyleEnum.Error,
                             messageCaption: new StringBuilder("Error"),
                             messageText: new StringBuilder("Cannot find the blueprint file.")
                             ));
             }
         }
         else if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM)
         {
             var path2 = Path.Combine(m_workshopBlueprintFolder, (m_selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId.ToString() + m_workshopBlueprintSuffix);
             if (File.Exists(path2))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen = new MyGuiDetailScreenSteam(
                     callBack: delegate(MyGuiControlListbox.Item item)
                     {
                         m_selectedItem = item;
                         m_activeDetail = false;
                         m_detailScreen = null;
                         if (Task.IsComplete)
                         {
                             RefreshBlueprintList();
                         }
                     },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             buttonType: MyMessageBoxButtonsType.OK,
                             styleEnum: MyMessageBoxStyleEnum.Error,
                             messageCaption: new StringBuilder("Error"),
                             messageText: new StringBuilder("Cannot find the blueprint file.")
                             ));
             }
         }
     }
 }
        public void OnDelete(MyGuiControlButton button)
        {
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                buttonType: MyMessageBoxButtonsType.YES_NO,
                styleEnum: MyMessageBoxStyleEnum.Info,
                messageCaption: MyTexts.Get(MySpaceTexts.LoadScreenButtonDelete),
                messageText: MyTexts.Get(MySpaceTexts.ProgrammableBlock_DeleteScriptDialogText),
                callback: delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                {
                    if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        Debug.Assert(m_selectedItem != null, "Selected item shouldnt be null");
                        if (m_selectedItem != null)
                        {
                            if (DeleteScript(m_selectedItem.Text.ToString()))
                            {
                                m_renameButton.Enabled = false;
                                m_deleteButton.Enabled = false;
                                m_detailsButton.Enabled = false;
                                m_selectedItem = null;
                            }

                            RefreshBlueprintList();
                        }
                    }
                }, 
                canHideOthers: false
                ));
        }
 void OnItemDoubleClick(MyGuiControlListbox list)
 {
     m_selectedItem = list.SelectedItems[0];
     Ok();        
 }
        private void RefreshPlayerList()
        {
            //Add the global chat log first
            m_globalItem = new MyGuiControlListbox.Item( MyTexts.Get( MySpaceTexts.TerminalTab_Chat_ChatHistory ) );
            m_playerList.Add( m_globalItem );

            //Comms broadcast history
            m_tempStringBuilder.Clear();
            m_tempStringBuilder.Append(MyTexts.Get(MySpaceTexts.TerminalTab_Chat_GlobalChat));
            
            MyChatHistory chatHistory;
            if (MySession.Static.ChatHistory.TryGetValue(MySession.Static.LocalPlayerId, out chatHistory) && chatHistory.GlobalChatHistory.UnreadMessageCount > 0)
            {
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(chatHistory.GlobalChatHistory.UnreadMessageCount);
                m_tempStringBuilder.Append(")");
            }
            
            m_broadcastItem = new MyGuiControlListbox.Item(m_tempStringBuilder);
            m_playerList.Add(m_broadcastItem);

            //var allPlayers = MySession.Static.Players.GetAllIdentities();
            var allPlayers = MySession.Static.Players.GetAllPlayers();

            m_tempOnlinePlayers.Clear();
            m_tempOfflinePlayers.Clear();

            foreach (var player in allPlayers)
            {
                var playerIdentity = MySession.Static.Players.TryGetIdentity(MySession.Static.Players.TryGetIdentityId(player.SteamId, player.SerialId));

                if (playerIdentity != null && playerIdentity.IdentityId != MySession.Static.LocalPlayerId && player.SerialId == 0)
                {
                    if (playerIdentity.Character == null)
                    {
                        m_tempOfflinePlayers.Add(playerIdentity);
                    }
                    else
                    {
                        m_tempOnlinePlayers.Add(playerIdentity);
                    }
                }
            }

            foreach (var onlinePlayer in m_tempOnlinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(onlinePlayer.DisplayName);

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, onlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: onlinePlayer);
                m_playerList.Add(item);
            }

            foreach (var offlinePlayer in m_tempOfflinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(offlinePlayer.DisplayName);
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(MyTexts.GetString(MySpaceTexts.TerminalTab_Chat_Offline));
                m_tempStringBuilder.Append(")");

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, offlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: offlinePlayer, fontOverride: MyFontEnum.DarkBlue);
                m_playerList.Add(item);
            }
        }
        void GetWorkshopItemsSteam()
        {
            for (int i = 0; i < m_subscribedItemsList.Count; i++)
            {
                MySteamWorkshop.SubscribedItem suscribedItem = m_subscribedItemsList[i];
                MyAnalyticsHelper.ReportActivityStart(null, "show_blueprints", string.Empty, "gui", string.Empty);

                String name = suscribedItem.Title;
                var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, suscribedItem.PublishedFileId) {Item = suscribedItem };
                var item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal);
                m_blueprintList.Add(item);
            }
        }
        void ExtractWorkshopItem(MySteamWorkshop.SubscribedItem subItem)
        {
            string archive = Path.Combine(m_workshopBlueprintFolder, subItem.PublishedFileId.ToString() + m_workshopBlueprintSuffix);
            var extractPath = Path.Combine(TEMP_PATH, subItem.PublishedFileId.ToString());

            if (Directory.Exists(extractPath))
            {
                Directory.Delete(extractPath);
            }

            Directory.CreateDirectory(extractPath);
            var extracted = MyZipArchive.OpenOnFile(archive);

            var modInfo = new MyObjectBuilder_ModInfo();
            modInfo.SubtypeName = subItem.Title;
            modInfo.WorkshopId = subItem.PublishedFileId;
            modInfo.SteamIDOwner = subItem.SteamIDOwner;

            var infoFile = Path.Combine(TEMP_PATH,subItem.PublishedFileId.ToString(), "info.temp");
            if (File.Exists(infoFile))
            {
                File.Delete(infoFile);
            }

            var infoSuccess = MyObjectBuilderSerializer.SerializeXML(infoFile, false, modInfo);

            if (extracted.FileExists("thumb.png"))
            {
                var stream = extracted.GetFile("thumb.png").GetStream();
                if (stream != null)
                {
                    using (var file = File.Create(Path.Combine(extractPath, "thumb.png")))
                    {
                        stream.CopyTo(file);
                    }
                }
                stream.Close();
            }

            extracted.Dispose();

            var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, subItem.PublishedFileId);
            var listItem = new MyGuiControlListbox.Item(text: new StringBuilder(subItem.Title), toolTip: subItem.Title, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal, userData: info);

            var itemIndex = m_blueprintList.Items.FindIndex(item => ((item.UserData as MyBlueprintItemInfo).PublishedItemId == (listItem.UserData as MyBlueprintItemInfo).PublishedItemId) && (item.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM);
            if (itemIndex == -1)
            {
                m_blueprintList.Add(listItem);
            }
        }
        static void ShareBlueprintRequestClient(ulong workshopId, string name, ulong sendToId, string senderName)
        {
            var itemId = workshopId;
            var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.SHARED, id: itemId);
            var item = new MyGuiControlListbox.Item(new StringBuilder(name.ToString()), userData: info, icon: MyGuiConstants.TEXTURE_BLUEPRINTS_ARROW.Normal);
            item.ColorMask = new Vector4(0.7f);
            if (!m_recievedBlueprints.Any(item2 => (item2.UserData as MyBlueprintItemInfo).PublishedItemId == (item.UserData as MyBlueprintItemInfo).PublishedItemId))
            {
                m_recievedBlueprints.Add(item);
                m_blueprintList.Add(item);

                var notification = new MyHudNotificationDebug(senderName + " just shared a blueprint with you.", 2500);
                MyHud.Notifications.Add(notification);
            }
        }
 void OnBlueprintDownloadedDetails(MySteamWorkshop.SubscribedItem workshopDetails)
 {
     var path2 = Path.Combine(m_workshopBlueprintFolder, workshopDetails.PublishedFileId.ToString() + m_workshopBlueprintSuffix);
     if (File.Exists(path2))
     {
         m_thumbnailImage.Visible = false;
         m_detailScreen = new MyGuiDetailScreenSteam(
             callBack: delegate(MyGuiControlListbox.Item item)
             {
                 m_selectedItem = item;
                 m_activeDetail = false;
                 m_detailScreen = null;
                 if (Task.IsComplete)
                 {
                     RefreshBlueprintList();
                 }
             },
             selectedItem: m_selectedItem,
             parent: this,
             thumbnailTexture: m_selectedImage.BackgroundTexture,
             textScale: m_textScale
             );
         m_activeDetail = true;
         MyScreenManager.InputToNonFocusedScreens = true;
         MyScreenManager.AddScreen(m_detailScreen);
     }
     else
     {
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                     buttonType: MyMessageBoxButtonsType.OK,
                     styleEnum: MyMessageBoxStyleEnum.Error,
                     messageCaption: new StringBuilder("Error"),
                     messageText: new StringBuilder("Cannot find the blueprint file.")
                     ));
     }
 }
 public void FillSelectedListContent(ICollection<MyGuiControlListbox.Item> listBoxContent, ICollection<MyGuiControlListbox.Item> listBoxSelectedItems)
 {
     foreach (var texture in m_selectedTexturesToDraw)
     {
         m_helperSB.Clear().Append(texture.Id.SubtypeName);
         var item = new MyGuiControlListbox.Item(text: m_helperSB, userData: texture.TexturePath);
         listBoxContent.Add(item);
     }
 }
        void OnItemDoubleClick(MyGuiControlListbox list)
        {
            m_selectedItem = list.SelectedItems[0];
            var itemInfo = m_selectedItem.UserData as MyBlueprintItemInfo;

            if (itemInfo.Type == MyBlueprintTypeEnum.SHARED)
            {
                OpenSharedBlueprint(itemInfo);
            }
            else
            {
                if (MySession.Static.SurvivalMode && m_clipboard == Sandbox.Game.Entities.MyCubeBuilder.Static.Clipboard)
                {
                    CloseScreen();
                }
                else
                {
                    var close = CopySelectedItemToClipboard();
                    if (close)
                    {
                        CloseScreen();
                    }
                }
            }
        }
        private void FillWaypointList(ICollection<MyGuiControlListbox.Item> waypoints, ICollection<MyGuiControlListbox.Item> selectedWaypoints)
        {
            foreach (var waypoint in m_waypoints)
            {
                m_tempName.Append(waypoint.Name);

                int actionCount = 0;

                m_tempActions.Append("\nActions:");
                if (waypoint.Actions != null)
                {
                    foreach (var action in waypoint.Actions)
                    {
                        if (action != null)
                        {
                            m_tempActions.Append("\n");
                            action.Update(this);
                            m_tempActions.AppendStringBuilder(action.DisplayName);

                            actionCount++;
                        }
                    }
                }

                m_tempTooltip.AppendStringBuilder(m_tempName);
                m_tempTooltip.Append('\n');
                m_tempTooltip.Append(waypoint.Coords.ToString());

                if (actionCount > 0)
                {
                    m_tempName.Append(" [");
                    m_tempName.Append(actionCount.ToString());
                    if (actionCount > 1)
                    {
                        m_tempName.Append(" Actions]");
                    }
                    else
                    {
                        m_tempName.Append(" Action]");
                    }
                    m_tempTooltip.AppendStringBuilder(m_tempActions);
                }

                var item = new MyGuiControlListbox.Item(text: m_tempName, toolTip: m_tempTooltip.ToString(), userData: waypoint);
                waypoints.Add(item);

                if (m_selectedWaypoints.Contains(waypoint))
                {
                    selectedWaypoints.Add(item);
                }

                m_tempName.Clear();
                m_tempTooltip.Clear();
                m_tempActions.Clear();
            }
        }
        void OnReload(MyGuiControlButton button)
        {
            m_selectedItem = null;
            m_detailsButton.Enabled = false;
            m_screenshotButton.Enabled = false;

            RefreshAndReloadBlueprintList();
        }
 void OnItemDoubleClick(MyGuiControlListbox list)
 {
     m_selectedItem = list.SelectedItems[0];
     var itemInfo = m_selectedItem.UserData as MyBlueprintItemInfo;
     OpenSelectedSript();
 }
Exemple #22
0
        public void FillListContent(ICollection<MyGuiControlListbox.Item> listBoxContent, ICollection<MyGuiControlListbox.Item> listBoxSelectedItems)
        {
            string button = MyTexts.GetString(MySpaceTexts.BlockPropertyText_Button);
            for (int i=0; i < m_buttonsUseObjects.Count;++i)
            {
                m_helperSB.Clear().Append(button + " " + (i+1).ToString());
                var item = new MyGuiControlListbox.Item(text: m_helperSB, userData: i);
                listBoxContent.Add(item);

                if (i == m_selectedButton)
                {
                    listBoxSelectedItems.Add(item);
                }
            }
        }
        void OnReload(MyGuiControlButton button)
        {
            m_selectedItem = null;
            m_renameButton.Enabled = false;
            m_detailsButton.Enabled = false;

            RefreshAndReloadScriptsList(true);
        }
        private void RefreshFactionList()
        {
            var localFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);
            if (localFaction != null)
            {
                //Add local player faction first
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(localFaction.Name);

                var chatHistory = MyChatSystem.GetFactionChatHistory(MySession.Static.LocalPlayerId, localFaction.FactionId);
                if (chatHistory != null && chatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(chatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: localFaction);
                m_factionList.Add(item);

                m_factionList.SetToolTip(string.Empty);
                foreach (var faction in MySession.Static.Factions)
                {
                    //Don't add local player faction twice
                    if (faction.Value != localFaction && faction.Value.AcceptHumans)
                    {
                        m_tempStringBuilder.Clear();
                        m_tempStringBuilder.Append(faction.Value.Name);

                        chatHistory = MyChatSystem.GetFactionChatHistory(MySession.Static.LocalPlayerId, faction.Value.FactionId);
                        if (chatHistory != null && chatHistory.UnreadMessageCount > 0)
                        {
                            m_tempStringBuilder.Append(" (");
                            m_tempStringBuilder.Append(chatHistory.UnreadMessageCount);
                            m_tempStringBuilder.Append(")");
                        }

                        item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: faction.Value);
                        m_factionList.Add(item);
                    }
                }
            }
            else
            {
                m_factionList.SelectedItems.Clear();
                m_factionList.Items.Clear();

                m_factionList.SetToolTip(MyTexts.GetString(MySpaceTexts.TerminalTab_Chat_NoFaction));
            }
        }
 static void ShareBlueprintRequest(ref ShareBlueprintMsg msg, MyNetworkClient sender)
 {
     if (Sync.IsServer && msg.SendToId != Sync.MyId)
     {
         Sync.Layer.SendMessage(ref msg, msg.SendToId);
     }
     else
     {
         var itemId = msg.WorkshopId;
         var name = msg.Name;
         var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.SHARED, id: itemId);
         var item = new MyGuiControlListbox.Item(new StringBuilder(name.ToString()), userData: info, icon: MyGuiConstants.TEXTURE_BLUEPRINTS_ARROW.Normal);
         item.ColorMask = new Vector4(0.7f);
         if (!m_recievedBlueprints.Any(item2 => (item2.UserData as MyBlueprintItemInfo).PublishedItemId == (item.UserData as MyBlueprintItemInfo).PublishedItemId))
         {
             m_recievedBlueprints.Add(item);
             m_blueprintList.Add(item);
             if (sender != null)
             {
                 var notification = new MyHudNotificationDebug(sender.DisplayName + " just shared a blueprint with you.", 2500);
                 MyHud.Notifications.Add(notification);
             }
         }
     }
 }
Exemple #26
0
        private void FillListContent(ICollection<MyGuiControlListbox.Item> listBoxContent, ICollection<MyGuiControlListbox.Item> listBoxSelectedItems)
        {
            foreach (var soundCategory in MyDefinitionManager.Static.GetSoundCategoryDefinitions())
            {
                foreach (var sound in soundCategory.Sounds)
                {
                    m_helperSB.Clear().Append(sound.SoundText);
                    var stringId = MySoundPair.GetCueId(sound.SoundId);
                    
                    var item = new MyGuiControlListbox.Item(text: m_helperSB, userData: stringId);

                    listBoxContent.Add(item);
                    if (stringId == CueId)
                        listBoxSelectedItems.Add(item);
                }
            }
        }
        void OnDelete(MyGuiControlButton button)
        {
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                buttonType: MyMessageBoxButtonsType.YES_NO,
                styleEnum: MyMessageBoxStyleEnum.Info,
                messageCaption: new StringBuilder("Delete"),
                messageText: new StringBuilder("Are you sure you want to delete this blueprint?"),
                callback: delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                {
                    if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        Debug.Assert(m_selectedItem != null, "Selected item shouldnt be null");
                        if (m_selectedItem != null)
                        {
                            if (DeleteBlueprint(m_selectedItem.Text.ToString()))
                            {
                                m_deleteButton.Enabled = false;
                                m_detailsButton.Enabled = false;
                                m_screenshotButton.Enabled = false;
                                m_replaceButton.Enabled = false;
                                m_selectedItem = null;
                            }

                            RefreshBlueprintList();
                        }
                    }
                }));
        }
 private void AddGroupToList(MyBlockGroup group, int? position = null)
 {
     foreach (var it in m_blockListbox.Items)
         if (it.UserData == group)
             return;
     var item = new MyGuiControlListbox.Item(userData: group);
     item.Text.Clear().Append("*").AppendStringBuilder(group.Name).Append("*");
     m_blockListbox.Add(item, position);
 }
        void GetBlueprints(string directory, MyBlueprintTypeEnum type)
        {
            if (!Directory.Exists(directory))
                return;
            string[] folders = Directory.GetDirectories(directory);
            List<string> fileNames = new List<string>();
            List<string> blueprintNames = new List<string>();

            foreach (var f in folders)
            {
                fileNames.Add(f + "\\bp.sbc");
                var tokens = f.Split('\\');
                blueprintNames.Add(tokens[tokens.Length - 1]);
            }

            for (int i = 0; i < blueprintNames.Count; i++)
            {
                String name = blueprintNames[i];
                var info = new MyBlueprintItemInfo(type);
                var item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_blueprintList.Add(item);
            }
        }
        private void FillGpsList(ICollection<MyGuiControlListbox.Item> gpsItemList, ICollection<MyGuiControlListbox.Item> selectedGpsItemList)
        {
            List<IMyGps> gpsList = new List<IMyGps>();
            MySession.Static.Gpss.GetGpsList(MySession.Static.LocalPlayerId, gpsList);
            foreach (var gps in gpsList)
            {
                var item = new MyGuiControlListbox.Item(text: new StringBuilder(gps.Name), userData: gps);
                gpsItemList.Add(item);

                if (m_selectedGps == gps)
                {
                    selectedGpsItemList.Add(item);
                }
            }
        }
        void GetWorkshopItemsLocal()
        {
            var filePath = Path.Combine(m_workshopBlueprintFolder, "temp");
            if (Directory.Exists(filePath))
            {
                var folders = Directory.GetDirectories(filePath);
                var blueprintNames = new List<string>();
                var fileNames = new List<string>();

                foreach (var f in folders)
                {
                    var tokens = f.Split('\\');
                    blueprintNames.Add(tokens[tokens.Length - 1]);
                }
                for (int i = 0; i < blueprintNames.Count; i++)
                {
                    var modInfoPath = Path.Combine(filePath, blueprintNames[i], "info.temp");
                    MyObjectBuilder_ModInfo modInfo = null;
                    if (File.Exists(modInfoPath))
                    {
                        MyAnalyticsHelper.ReportActivityStart(null, "show_blueprints", string.Empty, "gui", string.Empty);
                        var success = MyObjectBuilderSerializer.DeserializeXML(modInfoPath, out modInfo);
                        
                        if (!ValidateModInfo(modInfo) || !success)
                            continue;

                        String name = modInfo.SubtypeName;
                        var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, modInfo.WorkshopId);
                        var item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal);
                        m_blueprintList.Add(item);
                    }
                }
            }
        }