Ejemplo n.º 1
0
 public static void GameLoop_OneSecondUpdateTicked(object sender, OneSecondUpdateTickedEventArgs e)
 {
     if (ModEntry.callingNPC != null && Game1.activeClickableMenu == null)
     {
         if (ModEntry.currentCallRings < ModEntry.currentCallMaxRings && !ModEntry.inCall)
         {
             if (ModEntry.ringToggle == Config.PhoneRingInterval)
             {
                 Monitor.Log($"Phone ringing, {ModEntry.callingNPC.displayName} calling", LogLevel.Debug);
                 PhoneUtils.PlayRingTone();
                 ModEntry.currentCallRings++;
                 ModEntry.ringToggle = 0;
             }
             else
             {
                 ModEntry.ringToggle++;
             }
         }
         else
         {
             if (!ModEntry.inCall)
             {
                 ModEntry.callingNPC = null;
             }
             ModEntry.currentCallRings = 0;
         }
     }
 }
Ejemplo n.º 2
0
        public static void GameLoop_OneSecondUpdateTicked(object sender, OneSecondUpdateTickedEventArgs e)
        {
            if (ModEntry.callingNPC != null && Game1.activeClickableMenu == null)
            {
                if (ModEntry.currentCallRings < ModEntry.currentCallMaxRings && !ModEntry.inCall)
                {
                    if (ModEntry.currentCallRings == 0 && Config.NotifyOnRing)
                    {
                        Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("phone-ringing"), 2));
                    }

                    if (ModEntry.ringToggle == Config.PhoneRingInterval)
                    {
                        Monitor.Log($"Phone ringing, {ModEntry.callingNPC.displayName} calling", LogLevel.Debug);
                        PhoneUtils.PlayRingTone();
                        ModEntry.currentCallRings++;
                        ModEntry.ringToggle = 0;
                    }
                    else
                    {
                        ModEntry.ringToggle++;
                    }
                }
                else
                {
                    PhoneUtils.StopRingTone();
                    if (!ModEntry.inCall)
                    {
                        ModEntry.callingNPC = null;
                    }
                    ModEntry.currentCallRings = 0;
                }
            }
        }
Ejemplo n.º 3
0
        public static void ReceiveRandomCall()
        {
            CreateCallableList();
            if (callableList.Count == 0)
            {
                Monitor.Log($"You have no friends.", LogLevel.Debug);
                return;
            }
            CallableNPC[] callers = callableList.Where(s => (s.npc.CurrentDialogue.Count >= 1 || s.npc.endOfRouteMessage.Value != null) && !s.npc.isSleeping).ToArray();
            if (callers.Length == 0)
            {
                Monitor.Log($"None of your friends want to talk to you.", LogLevel.Debug);
                return;
            }
            CallableNPC caller = callers[Game1.random.Next(callers.Length)];

            Monitor.Log($"Friend calling: {caller.npc.displayName}", LogLevel.Debug);
            PhoneUtils.PlayRingTone();
            ModEntry.currentCallRings    = 0;
            ModEntry.currentCallMaxRings = Game1.random.Next(Math.Max(0, Config.IncomingCallMinRings), Math.Max(Config.IncomingCallMinRings + 1, Config.IncomingCallMaxRings));
            ModEntry.callingNPC          = caller.npc;
        }
Ejemplo n.º 4
0
        private static void Display_RenderedWorld(object sender, StardewModdingAPI.Events.RenderedWorldEventArgs e)
        {
            if (ModEntry.callingNPC != null)
            {
                return;
            }

            if (!ModEntry.appRunning || !ModEntry.phoneOpen || ModEntry.runningApp != Helper.ModRegistry.ModID)
            {
                ModEntry.appRunning                     = false;
                ModEntry.phoneAppRunning                = false;
                Helper.Events.Display.RenderedWorld    -= Display_RenderedWorld;
                Helper.Events.Input.ButtonPressed      -= Input_ButtonPressed;
                Helper.Events.Input.MouseWheelScrolled -= Input_MouseWheelScrolled;
                return;
            }
            Vector2   screenPos  = PhoneUtils.GetScreenPosition();
            Vector2   screenSize = PhoneUtils.GetScreenSize();
            Rectangle headerRect = new Rectangle((int)screenPos.X, (int)screenPos.Y, (int)screenSize.X, Config.AppHeaderHeight);
            Point     mousePos   = Game1.getMousePosition();

            if (Helper.Input.IsSuppressed(SButton.MouseLeft))
            {
                int dy = mousePos.Y - lastMousePositionY;
                if (Math.Abs(dy) > 0 && ModEntry.screenRect.Contains(mousePos))
                {
                    dragging = true;
                }
                if (dragging)
                {
                    AddYOffset(dy);
                }
            }

            if (clicked && !Helper.Input.IsSuppressed(SButton.MouseLeft))
            {
                clicked = false;
                if (dragging)
                {
                    Monitor.Log($"was dragging");
                    dragging = false;
                }
                else
                {
                    if (headerRect.Contains(mousePos))
                    {
                        if (new Rectangle((int)screenPos.X + (int)screenSize.X - Config.AppHeaderHeight, (int)screenPos.Y, Config.AppHeaderHeight, Config.AppHeaderHeight).Contains(mousePos))
                        {
                            PhoneUtils.ToggleApp(false);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < callableList.Count; i++)
                        {
                            Vector2   pos = GetNPCPos(i);
                            Rectangle r   = new Rectangle((int)pos.X, (int)pos.Y, Config.ContactWidth, Config.ContactHeight);
                            if (r.Contains(mousePos))
                            {
                                Monitor.Log($"calling {callableList[i].npc.Name}");
                                PhoneUtils.PlayRingTone();
                                CallNPC(callableList[i].npc);
                            }
                        }
                    }
                }
            }

            lastMousePositionY = Game1.getMouseY();
            int startListY = (int)screenPos.Y + Config.AppHeaderHeight;

            e.SpriteBatch.Draw(ModEntry.phoneBookTexture, screenPos, Color.White);

            if (yOffset < 0)
            {
                e.SpriteBatch.Draw(ModEntry.upArrowTexture, ModEntry.upArrowPosition, Color.White);
            }
            if (yOffset > PhoneUtils.GetScreenSize().Y - Config.AppHeaderHeight - listHeight)
            {
                e.SpriteBatch.Draw(ModEntry.downArrowTexture, ModEntry.downArrowPosition, Color.White);
            }

            int screenBottom = (int)(screenPos.Y + screenSize.Y);

            for (int i = 0; i < callableList.Count; i++)
            {
                Vector2   npcPos = GetNPCPos(i);
                Rectangle r      = callableList[i].sourceRect;
                if (npcPos.Y < startListY - r.Height * 2 || npcPos.Y >= screenBottom)
                {
                    continue;
                }
                Rectangle sourceRect = r;
                int       cutTop     = 0;
                int       cutBottom  = 0;
                if (npcPos.Y < startListY)
                {
                    cutTop     = (int)Math.Round((startListY - (int)npcPos.Y) / 2f);
                    sourceRect = new Rectangle(r.X, r.Y + cutTop, r.Width, r.Height - cutTop);
                    npcPos     = new Vector2(npcPos.X, startListY);
                }
                else if (npcPos.Y > screenBottom - r.Height * 2)
                {
                    cutBottom  = (int)Math.Round((screenBottom - r.Height * 2 - (int)npcPos.Y) / 2f);
                    sourceRect = new Rectangle(r.X, r.Y, r.Width, r.Height + cutBottom);
                }

                e.SpriteBatch.Draw(callableList[i].portrait, npcPos + new Vector2((Config.ContactWidth - 32) / 2f, 0), sourceRect, Color.White, 0, Vector2.Zero, 2, SpriteEffects.None, 0.86f);
                if (Config.ShowNamesInPhoneBook && npcPos.Y < screenBottom - Config.ContactHeight - callableList[i].nameSize.Y * 0.4f + 6)
                {
                    e.SpriteBatch.DrawString(Game1.dialogueFont, callableList[i].name, GetNPCPos(i) + new Vector2(Config.ContactWidth / 2f - callableList[i].nameSize.X * 0.2f, Config.ContactHeight - 6), Color.Black, 0, Vector2.Zero, 0.4f, SpriteEffects.None, 0.86f);
                }
            }
            e.SpriteBatch.Draw(ModEntry.phoneBookHeaderTexture, headerRect, Color.White);
            string  headerText     = Helper.Translation.Get("phone-book");
            Vector2 headerTextSize = Game1.dialogueFont.MeasureString(headerText) * Config.HeaderTextScale;

            e.SpriteBatch.DrawString(Game1.dialogueFont, headerText, screenPos + new Vector2(screenSize.X / 2f - headerTextSize.X / 2f, Config.AppHeaderHeight / 2f - headerTextSize.Y / 2f), Config.PhoneBookHeaderTextColor, 0, Vector2.Zero, Config.HeaderTextScale, SpriteEffects.None, 0.86f);
            e.SpriteBatch.DrawString(Game1.dialogueFont, "x", screenPos + new Vector2(screenSize.X - Config.AppHeaderHeight / 2f - Game1.dialogueFont.MeasureString("x").X *Config.HeaderTextScale / 2f, Config.AppHeaderHeight / 2f - headerTextSize.Y / 2f), Config.PhoneBookHeaderTextColor, 0, Vector2.Zero, Config.HeaderTextScale, SpriteEffects.None, 0.86f);
        }
Ejemplo n.º 5
0
 public void PlayRingTone()
 {
     PhoneUtils.PlayRingTone();
 }