/*****************
        * Public methods
        *****************/

        /// <summary>
        /// Entry for this mod.
        /// </summary>
        /// <param name="helper">Helper.</param>
        public override void Entry(IModHelper helper)
        {
            Util.Init(Helper, Monitor);

            Config = Helper.ReadConfig <QualityProductsConfig>();

            if (Config.IsAnythingEnabled())
            {
                if (Config.IsCookingEnabled())
                {
                    Helper.Events.Display.MenuChanged += OnCrafting;
                }

                Helper.Events.GameLoop.Saved            += OnSaved;
                Helper.Events.GameLoop.Saving           += OnSaving;
                Helper.Events.GameLoop.SaveLoaded       += OnSaveLoaded;
                Helper.Events.World.LocationListChanged += OnLoadLocation;
                Helper.Events.World.ObjectListChanged   += OnPlacingProcessor;

                if (Config.EnableMeadTextures && SpriteLoader.Init(Helper, Monitor, Config))
                {
                    PatchManager.ApplyAll(
                        typeof(SObjectDrawPatch),
                        typeof(SObjectDraw2Patch),
                        typeof(SObjectDrawInMenuPatch),
                        typeof(SObjectDrawWhenHeld),
                        typeof(FurnitureDrawPatch)
                        );
                }
            }
        }
Exemple #2
0
        protected void InitAll()
        {
            // Order matters
            Logger.Init();
            SettingsManager.Init();
            StringsManager.Init();
            Screens.Init();
            SysInfo.Init();
            SysPath.Init();

            // Order doesn't matter
            Inputs.Init();
            Rand.Init();
            Score.Init();
            Vibrator.Init();
            Tracker.Init();
            SpriteLoader.Init();
            AudioLoader.Init();
        }
Exemple #3
0
        public void Update()
        {
            if (!_noGlowMaterial)
            {
                Shader shader = Shader.Find("Custom/SpriteNoGlow");
                if (shader)
                {
                    _noGlowMaterial           = new Material(shader);
                    _background.material      = new Material(shader);
                    _lockButtonImage.material = new Material(shader);
                }
            }

            if (!_noGlowMaterialUI)
            {
                Shader shader = Shader.Find("Custom/UINoGlow");
                if (shader)
                {
                    _noGlowMaterialUI = new Material(shader);
                    var mat = new Material(shader);
                    mat.color = Color.clear;
                    _chatMoverPrimitive.GetComponent <Renderer>().material  = mat;
                    _lockButtonPrimitive.GetComponent <Renderer>().material = mat;
                }
            }

            if (_noGlowMaterial && _noGlowMaterialUI)
            {
                // Set our lock button image sprite
                _lockButtonImage.sprite = Plugin.Instance.Config.LockChatPosition ? _lockedSprite : _unlockedSprite;

                // Wait a few seconds after we've connect to the chat, then send our welcome message
                if (displayStatusMessage && (TwitchIRCClient.JoinedChannel || (DateTime.Now - TwitchIRCClient.ConnectionTime).TotalSeconds >= 5))
                {
                    if (TwitchIRCClient.JoinedChannel)
                    {
                        Plugin.Log("Reinitializing sprites!");
                        _spriteLoader.Init();
                    }

                    MessageInfo messageInfo = new MessageInfo();
                    messageInfo.nameColor = "#00000000";
                    messageInfo.sender    = String.Empty;
                    if (TwitchIRCClient.JoinedChannel)
                    {
                        TwitchIRCClient.RenderQueue.Push(new ChatMessage($"Success joining chat room \"{Plugin.Instance.Config.TwitchChannel}\"", messageInfo));
                    }
                    else
                    {
                        TwitchIRCClient.RenderQueue.Push(new ChatMessage($"Failed to connect to the chat room!", messageInfo));
                    }
                    displayStatusMessage = false;
                }

                // Save images to file when we're at the main menu
                if (Plugin.Instance.IsAtMainMenu)
                {
                    if (SpriteLoader.SpriteSaveQueue.Count > 0)
                    {
                        if (SpriteLoader.SpriteSaveQueue.TryPop(out var saveInfo))
                        {
                            File.WriteAllBytes(saveInfo.path, saveInfo.data);
                            //Plugin.Log("Saved local file!");
                        }
                    }
                }

                // Removed any timed out messages from view
                if (_timeoutQueue.Count > 0)
                {
                    if (_timeoutQueue.TryPop(out var userID))
                    {
                        PurgeChatMessages(userID);
                    }
                }

                // Overlay any animated emotes that have just finished processing
                if (SpriteLoader.AnimationDisplayQueue.Count > 0)
                {
                    if (SpriteLoader.AnimationDisplayQueue.TryPop(out var animationDisplayInfo))
                    {
                        if (SpriteLoader.CachedSprites.ContainsKey(animationDisplayInfo.emoteIndex))
                        {
                            var animationInfo = SpriteLoader.CachedSprites[animationDisplayInfo.emoteIndex]?.animationInfo;
                            if (animationInfo != null && animationInfo.Count == 1)
                            {
                                foreach (CustomText currentMessage in _chatMessages)
                                {
                                    for (int i = currentMessage.emoteRenderers.Count - 1; i >= 0; i--)
                                    {
                                        Image img = currentMessage.emoteRenderers[i];
                                        if (img.sprite == animationInfo[0].sprite)
                                        {
                                            Destroy(img.gameObject);
                                            currentMessage.emoteRenderers.RemoveAt(i);
                                        }
                                    }
                                }
                            }
                        }

                        SpriteLoader.CachedSprites[animationDisplayInfo.emoteIndex] = new CachedSpriteData(animationDisplayInfo.sprites);
                        if (animationDisplayInfo.sprites.Count > 1)
                        {
                            _animationController.Register(animationDisplayInfo.sprites);
                        }
                        foreach (CustomText currentMessage in _chatMessages)
                        {
                            if (animationDisplayInfo.emoteIndex.StartsWith("AB"))
                            {
                                foreach (EmoteInfo e in currentMessage.messageInfo.parsedEmotes)
                                {
                                    if (e.emoteIndex == animationDisplayInfo.emoteIndex)
                                    {
                                        e.cachedSpriteInfo = SpriteLoader.CachedSprites[animationDisplayInfo.emoteIndex];
                                        Drawing.OverlayEmote(currentMessage, e.swapChar, _noGlowMaterialUI, _animationController, e.cachedSpriteInfo);
                                    }
                                }
                            }
                        }
                    }
                }

                // Display any messages that we've cached all the resources for and prepared for rendering
                if (TwitchIRCClient.RenderQueue.Count > 0 && !_messageRendering)
                {
                    if (_waitForFrames == 0)
                    {
                        if (TwitchIRCClient.RenderQueue.TryPop(out var messageToSend))
                        {
                            StartCoroutine(AddNewChatMessage(messageToSend.msg, messageToSend.messageInfo));
                        }
                    }
                    else
                    {
                        _waitForFrames--;
                    }
                }
            }
        }