示例#1
0
        /// <summary>
        /// Radio station buttons in vanilla game have multiple sprites (one for normal state,
        /// another one for if the button is pressed, ...). Custom stations only have a thumbnail.
        /// This detour method overwrites the vanilla behavior and makes is possible for
        /// music pack creators to only provide a thumbnail.
        /// </summary>
        /// <param name="button">Button.</param>
        /// <param name="station">Station.</param>
        private void CustomAssignStationToButton(UIButton button, RadioChannelInfo station)
        {
            UserRadioCollection collection = LoadingExtension.UserRadioContainer;
            UISprite            iconsprite = button.Find <UISprite>("sprite");

            // Additional sprite on top of the button
            if (iconsprite == null)
            {
                iconsprite      = button.AddUIComponent <UISprite>();
                iconsprite.name = "sprite";
            }

            // Different behavior depending on if the button is displayed in the panel or in the list
            if (button.parent != null && button.parent.name == "StationsList")
            {
                if (ModOptions.Instance.EnableImprovedRadioStationList)
                {
                    AssignStationToButtonInList(button, iconsprite, station, collection);
                }
                else
                {
                    AssignStationToButtonInPanel(button, iconsprite, station, collection);
                }
            }
            else
            {
                AssignStationToButtonInPanel(button, iconsprite, station, collection);

//	            if(ModOptions.Instance.EnableImprovedRadioStationList)
//	                AddComboboxVisualClue(button, iconsprite, station);
            }
        }
示例#2
0
        public override void OnCreated(ILoading loading)
        {
            base.OnCreated(loading);

            if (!Directory.Exists(UserRadioCollection.GameDirUserCollectionDirectory))
            {
                try
                {
                    Directory.CreateDirectory(UserRadioCollection.GameDirUserCollectionDirectory);
                }
                catch (Exception e)
                {
                    Debug.LogError("Could not create CSLMusicMod_Music directory: " + e);
                }
            }

            if (UserRadioContainer == null)
            {
                UserRadioContainer = new GameObject("CSLMusicMod_Definitions").AddComponent <UserRadioCollection>();
            }
            if (StationContainer == null)
            {
                StationContainer = new GameObject("CSLMusicMod_Stations").AddComponent <ChannelInitializer>();
            }
            if (ContentContainer == null)
            {
                ContentContainer = new GameObject("CSLMusicMod_Content").AddComponent <ContentInitializer>();
            }
            if (MethodDetours == null)
            {
                MethodDetours = new GameObject("CSLMusicMod_Detours").AddComponent <Detours>();
            }
        }
        /// <summary>
        /// The game usually translates all radio channel names with a translation table.
        /// If a name is not in this table, an error occurs. This detour looks if the station is custom
        /// and returns the correct title.
        /// </summary>
        /// <returns>Title of a radio station wrt custom stations</returns>
        public string CustomGetLocalizedTitle()
        {
            UserRadioCollection collection = Resources.FindObjectsOfTypeAll <UserRadioCollection>().FirstOrDefault();

            if (collection != null && collection.m_Stations.ContainsKey(name))
            {
                return(name);
            }
            else
            {
                return(ColossalFramework.Globalization.Locale.Get("RADIO_CHANNEL_TITLE", base.gameObject.name));
            }
        }
        /// <summary>
        /// Initializes the custom radio channels
        /// </summary>
        protected void InitializeImpl()
        {
            UserRadioCollection collection = LoadingExtension.UserRadioContainer;

            foreach (UserRadioChannel channel in collection.m_Stations.Values)
            {
                // Creates the actual radio station object that the games uses.
                CreatePrefab(channel.m_Name, "Default", new Action <RadioChannelInfo>((RadioChannelInfo obj) => {
                    obj.m_stateChain = channel.m_StateChain;
                    obj.m_Atlas      = channel.GetThumbnailAtlas(obj.m_Atlas.material);
                    obj.m_Thumbnail  = "thumbnail";
                }));
            }
        }
示例#5
0
        private void AssignStationToButtonInList(UIButton button, UISprite iconsprite, RadioChannelInfo station,
                                                 UserRadioCollection collection)
        {
            if (ModOptions.Instance.DisabledRadioStations.Contains(station.name))
            {
                button.isVisible = false;
            }
            else
            {
                button.isVisible = true;
            }

            ((UIPanel)button.parent).autoLayoutPadding = new RectOffset(0, 0, 0, 0);

            button.atlas            = ListAtlas;
            button.normalFgSprite   = "ListEntryNormal";
            button.hoveredFgSprite  = "ListEntryHover";
            button.pressedFgSprite  = "ListEntryHover";
            button.focusedFgSprite  = "ListEntryNormal";
            button.disabledFgSprite = "ListEntryNormal";
            button.color            = new Color32(200, 200, 200, 255);
            button.hoveredColor     = new Color32(255, 255, 255, 255);
            button.tooltip          = station.GetLocalizedTitle();

            button.text      = station.GetLocalizedTitle();
            button.textColor = new Color32(255, 255, 255, 255);
            button.size      = new Vector2(200, 20);
            button.textHorizontalAlignment = UIHorizontalAlignment.Left;
            button.textPadding             = new RectOffset(25, 2, 2, 2);
            button.textScale = 0.75f;

            button.BringToFront();

            iconsprite.position   = new Vector3(0, 0);
            iconsprite.size       = new Vector2(20, 20);
            iconsprite.atlas      = station.m_Atlas;
            iconsprite.spriteName = station.m_Thumbnail;
            iconsprite.isVisible  = true;
        }
示例#6
0
 public override void OnReleased()
 {
     base.OnReleased();
     if (UI != null)
     {
         UnityEngine.Object.Destroy(UI.gameObject);
         UI = null;
     }
     if (UIShortcutHandler != null)
     {
         UnityEngine.Object.Destroy(UI.gameObject);
         UIShortcutHandler = null;
     }
     if (StationContainer != null)
     {
         UnityEngine.Object.Destroy(StationContainer.gameObject);
         StationContainer = null;
     }
     if (ContentContainer != null)
     {
         UnityEngine.Object.Destroy(ContentContainer.gameObject);
         ContentContainer = null;
     }
     if (MethodDetours != null)
     {
         UnityEngine.Object.Destroy(MethodDetours.gameObject);
         MethodDetours = null;
     }
     if (UserRadioContainer != null)
     {
         UnityEngine.Object.Destroy(UserRadioContainer.gameObject);
         UserRadioContainer = null;
     }
     if (DisabledContentContainer != null)
     {
         UnityEngine.Object.Destroy(DisabledContentContainer.gameObject);
         UserRadioContainer = null;
     }
 }
示例#7
0
        /// <summary>
        /// Initializes the custom songs
        /// </summary>
        protected void InitializeImpl()
        {
            UserRadioCollection collection = LoadingExtension.UserRadioContainer;

            var collectionnames = collection.m_Songs.Values.Select(song => song.m_Collection).Distinct().ToArray();

            CSLMusicMod.Log("Available collections: " + String.Join("\n", collectionnames));

            foreach (UserRadioContent content in collection.m_Songs.Values)
            {
                try
                {
                    // Bases all music on vanilla "Aukio" song.
                    CreatePrefab(content.m_Name, "aukio", new Action <RadioContentInfo>((RadioContentInfo obj) =>
                    {
                        obj.m_fileName    = content.m_FileName;
                        obj.m_displayName = content.m_DisplayName;
                        obj.m_contentType = content.m_ContentType;

                        // Add the channels this song is playing in into the song.
                        List <RadioChannelInfo> channels = new List <RadioChannelInfo>();

                        foreach (UserRadioChannel uchannel in content.m_Channels)
                        {
                            var channel = FindChannelPrefab(uchannel.m_Name);
                            channels.Add(channel);
                        }

                        obj.m_radioChannels = channels.ToArray();
                    }));
                }
                catch (Exception e)
                {
                    Debug.LogError("[CSLMusic] Error while initializing prefab in " + content.m_Name + "! Exception: " + e.ToString());
                }
            }
        }
示例#8
0
        private void AssignStationToButtonInPanel(UIButton button, UISprite iconsprite, RadioChannelInfo station, UserRadioCollection collection)
        {
            button.atlas = station.m_Atlas;

            if (collection != null && collection.m_Stations.ContainsKey(station.name))
            {
                button.normalFgSprite   = station.m_Thumbnail;
                button.hoveredFgSprite  = station.m_Thumbnail;
                button.pressedFgSprite  = station.m_Thumbnail;
                button.focusedFgSprite  = station.m_Thumbnail;
                button.disabledFgSprite = station.m_Thumbnail;
                button.color            = new Color32(225, 225, 225, 255);
                button.hoveredColor     = new Color32(255, 255, 255, 255);
                button.tooltip          = station.GetLocalizedTitle();
                button.BringToFront();
            }
            else
            {
                if (station.m_Thumbnail == null)
                {
                    Debug.LogError("Station " + station.GetLocalizedTitle() + " has no thumbnail assigned.");
                }
                button.normalFgSprite   = station.m_Thumbnail;
                button.hoveredFgSprite  = station.m_Thumbnail + "Hovered";
                button.pressedFgSprite  = station.m_Thumbnail + "Pressed";
                button.focusedFgSprite  = station.m_Thumbnail;
                button.disabledFgSprite = station.m_Thumbnail + "Disabled";
                button.color            = new Color32(255, 255, 255, 255);
                button.hoveredColor     = new Color32(255, 255, 255, 255);
                button.tooltip          = station.GetLocalizedTitle();
                button.BringToFront();
            }

            button.text          = "";
            button.spritePadding = new RectOffset(0, 0, 0, 0);
        }