示例#1
0
 private void InitAtlases()
 {
     if (m_IconAtlas == null)
     {
         CSLMusicMod.Log("Creating icon atlases ...");
         m_IconAtlas = TextureHelper.CreateDefaultIconAtlas();
     }
 }
示例#2
0
        private void Initialize()
        {
            //Create ui
            UIView v = UIView.GetAView();

            m_ListPanel = (UIMusicListPanel)v.AddUIComponent(typeof(UIMusicListPanel));
            m_ListPanel.Hide();

            m_Initialized = true;

            CSLMusicMod.Log("Initialized music UI");
        }
示例#3
0
        /// <summary>
        /// Loads the context definition from JSON formatted data
        /// </summary>
        /// <returns>The RadioContext loaded from JSON</returns>
        /// <param name="json">JSON data</param>
        public static RadioContext LoadFromJson(JsonData json, Dictionary <string, RadioContextCondition> namedConditions)
        {
            RadioContext radiocontext = new RadioContext();

            foreach (JsonData conj in json["conditions"])
            {
                radiocontext.m_Conditions.Add(new List <RadioContextCondition>());

                foreach (JsonData entry in conj)
                {
                    if (entry.IsObject)
                    {
                        RadioContextCondition context = RadioContextCondition.LoadFromJsonUsingType(entry);

                        if (context != null)
                        {
                            radiocontext.m_Conditions.Last().Add(context);
                        }
                    }
                    else if (entry.IsString)
                    {
                        RadioContextCondition context;

                        if (namedConditions.TryGetValue(entry.ToString(), out context))
                        {
                            radiocontext.m_Conditions.Last().Add(context);
                        }
                        else
                        {
                            CSLMusicMod.Log("Could not find named condition " + entry + "!");
                        }
                    }
                }
            }

            foreach (JsonData e in json["collections"])
            {
                radiocontext.m_Collections.Add((String)e);
            }

            if (json.Keys.Contains("songs"))
            {
                foreach (JsonData e in json["songs"])
                {
                    radiocontext.m_Songs.Add((String)e);
                }
            }


            return(radiocontext);
        }
        /// <summary>
        /// Switches to the next track. This abruptly stops the current song.
        /// </summary>
        /// <returns><c>true</c>, if it was possible to switch to the next track, <c>false</c> otherwise.</returns>
        public static bool NextTrack_Hard()
        {
            AudioManager mgr = Singleton <AudioManager> .instance;

            if (ReflectionHelper.GetPrivateField <bool>(mgr, "m_musicFileIsRadio"))
            {
                CSLMusicMod.Log("Radio switches to next track");

                var player = ReflectionHelper.GetPrivateField <AudioManager.AudioPlayer>(mgr, "m_currentRadioPlayer");

                if (player != null)
                {
                    player.m_source.Stop();
                }


                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public void Update()
        {
            // Check if some other UI has the focus
            if (UIView.HasInputFocus())
            {
                m_NextTrackKey_IsDown   = false;
                m_OpenPanelKey_IsDown   = false;
                m_NextStationKey_IsDown = false;
                return;
            }

            m_ModifierCtrl  = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl));
            m_ModifierShift = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
            m_ModiferAlt    = (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt));

            //Next track
            if (ShortcutDown(ModOptions.Instance.ShortcutNextTrack))
            {
                m_NextTrackKey_IsDown = true;
            }
            else if (m_NextTrackKey_IsDown && ShortcutUp(ModOptions.Instance.ShortcutNextTrack))
            {
                m_NextTrackKey_IsDown = false;
                CSLMusicMod.Log("Pressed shortcut for next track");
                AudioManagerHelper.NextTrack();
            }

            //Next station
            if (ShortcutDown(ModOptions.Instance.ShortcutNextStation))
            {
                m_NextStationKey_IsDown = true;
            }
            else if (m_NextStationKey_IsDown && ShortcutUp(ModOptions.Instance.ShortcutNextStation))
            {
                CSLMusicMod.Log("Pressed shortcut for next station");
                m_NextStationKey_IsDown = false;
                AudioManagerHelper.NextStation();
            }

            //Panel
            if (ShortcutDown(ModOptions.Instance.ShortcutOpenRadioPanel))
            {
                m_OpenPanelKey_IsDown = true;
            }
            else if (m_OpenPanelKey_IsDown && ShortcutUp(ModOptions.Instance.ShortcutOpenRadioPanel))
            {
                m_OpenPanelKey_IsDown = false;
                CSLMusicMod.Log("Pressed shortcut for hide/show panel");

                var radiopanel = CurrentRadioPanel;
                if (radiopanel != null)
                {
                    var visible = ReflectionHelper.GetPrivateField <bool>(radiopanel, "m_isVisible");

                    if (visible)
                    {
                        radiopanel.HideRadio();
                    }
                    else
                    {
                        radiopanel.ShowRadio();
                    }
                }
            }
        }
示例#6
0
 public void Start()
 {
     CSLMusicMod.Log(ModOptions.Instance.ShortcutNextTrack);
     CSLMusicMod.Log(ModOptions.Instance.ShortcutNextStation);
     CSLMusicMod.Log(ModOptions.Instance.ShortcutOpenRadioPanel);
 }
        /// <summary>
        /// Switches to a specific radio content (music)
        /// </summary>
        /// <returns><c>true</c>, if the switch was successful, <c>false</c> otherwise.</returns>
        /// <param name="info">Info.</param>
        public static bool SwitchToContent(RadioContentInfo info)
        {
            AudioManager mgr = Singleton <AudioManager> .instance;

            // musicFileIsRadio is false if no radio channel is active. We cannot
            // do anything in this case.
            if (ReflectionHelper.GetPrivateField <bool>(mgr, "m_musicFileIsRadio"))
            {
                ushort contentindex = 0;
                bool   found        = false;

                for (int i = 0; i < mgr.m_radioContentCount; ++i)
                {
                    RadioContentData data = mgr.m_radioContents[i];

                    //Debug.Log("CC: " + data + " + " + data.Info + " == " + info);

                    if (data.Info == info)
                    {
                        contentindex = (ushort)i;
                        //Debug.Log("Found content index for " + info);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    CSLMusicMod.Log("Switching to unloaded music " + info);

                    if (!mgr.CreateRadioContent(out contentindex, info))
                    {
                        CSLMusicMod.Log("... failed to create content " + info);
                        return(false);
                    }
                }

                CSLMusicMod.Log("Radio switches to track " + info);

                //Debug.Log("Content index: " + contentindex);

                // Next content
                ushort activechannel = ReflectionHelper.GetPrivateField <ushort>(mgr, "m_activeRadioChannel");

                if (activechannel >= 0)
                {
                    RadioChannelData data = mgr.m_radioChannels[activechannel];
                    data.m_currentContent = contentindex;
                    //data.m_nextContent = contentindex;
                    mgr.m_radioChannels[activechannel] = data;
                    //mgr.m_radioChannels[activechannel].ChangeContent(activechannel);

                    return(true);
                }

                //var player = ReflectionHelper.GetPrivateField<AudioManager.AudioPlayer>(mgr, "m_currentRadioPlayer");
                //player.m_source.Stop();

                return(false);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        /// <summary>
        /// Creates an texture atlas.
        /// All credits to Craxy, authour of Toggle Traffic Lights
        /// </summary>
        /// <returns>The atlas.</returns>
        /// <param name="file">File.</param>
        /// <param name="name">Name.</param>
        /// <param name="baseMaterial">Base material.</param>
        /// <param name="spriteWidth">Sprite width.</param>
        /// <param name="spriteHeight">Sprite height.</param>
        /// <param name="spriteNames">Sprite names.</param>
        public static UITextureAtlas CreateAtlas(string file, string name, Material baseMaterial, int spriteWidth, int spriteHeight, string[] spriteNames)
        {
            CSLMusicMod.Log("Loading icon atlas from " + file + " as " + name);

            var tex = new Texture2D(spriteWidth * spriteNames.Length, spriteHeight, TextureFormat.ARGB32, false)
            {
                filterMode = FilterMode.Bilinear,
            };

            //load texture
            if (File.Exists(file))
            {
                using (var textureStream = File.Open(file, FileMode.Open))
                {
                    var buf = new byte[textureStream.Length]; //declare arraysize
                    textureStream.Read(buf, 0, buf.Length);   // read from stream to byte array
                    tex.LoadImage(buf);
                    tex.Apply(true, false);
                }
            }
            else
            {
                var assembly = System.Reflection.Assembly.GetExecutingAssembly();

                using (var textureStream = assembly.GetManifestResourceStream("CSLMusicMod." + file))
                {
                    if (textureStream == null)
                    {
                        CSLMusicMod.Log("Texture stream is NULL!");
                    }

                    var buf = new byte[textureStream.Length]; //declare arraysize
                    textureStream.Read(buf, 0, buf.Length);   // read from stream to byte array
                    tex.LoadImage(buf);
                    tex.Apply(true, false);
                }
            }


            var atlas = ScriptableObject.CreateInstance <UITextureAtlas>();
            // Setup atlas
            var material = UnityEngine.Object.Instantiate(baseMaterial);

            material.mainTexture = tex;

            atlas.material = material;
            atlas.name     = name;

            //add sprites
            for (var i = 0; i < spriteNames.Length; ++i)
            {
                var uw = 1.0f / spriteNames.Length;

                var spriteInfo = new UITextureAtlas.SpriteInfo
                {
                    name    = spriteNames[i],
                    texture = tex,
                    region  = new Rect(i * uw, 0, uw, 1),
                };

                atlas.AddSprite(spriteInfo);
            }

            return(atlas);
        }