Пример #1
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);
                }
                int alpha = callableList[i].npc.CurrentDialogue.Any() && !callableList[i].npc.isSleeping ? 255 : Config.UncallableNPCAlpha;
                e.SpriteBatch.Draw(callableList[i].portrait, npcPos + new Vector2((Config.ContactWidth - 32) / 2f, 0), sourceRect, new Color(255, 255, 255, alpha), 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);
        }
Пример #2
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;
                Helper.Events.Display.RenderedWorld -= Display_RenderedWorld;
                Helper.Events.Input.ButtonPressed   -= Input_ButtonPressed;
                return;
            }
            Vector2   screenPos  = PhoneUtils.GetScreenPosition();
            Vector2   screenSize = PhoneUtils.GetScreenSize();
            Rectangle headerRect = new Rectangle((int)screenPos.X, (int)screenPos.Y, (int)screenSize.X, Config.AppHeaderHeight);
            Rectangle footerRect = new Rectangle((int)screenPos.X, (int)screenPos.Y + (int)screenSize.Y - Config.AppHeaderHeight, (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) && !headerRect.Contains(mousePos) && !footerRect.Contains(mousePos))
                {
                    dragging = true;
                }
                if (dragging)
                {
                    float listHeight;
                    if (whichTab == 0)
                    {
                        listHeight = skinListHeight;
                    }
                    else if (whichTab == 1)
                    {
                        listHeight = backListHeight;
                    }
                    else
                    {
                        listHeight = ringListHeight;
                    }
                    yOffset = (int)Math.Max(Math.Min(0, yOffset + dy), -1 * Math.Max(0, listHeight - screenSize.Y));
                }
            }

            if (clicked && !Helper.Input.IsSuppressed(SButton.MouseLeft))
            {
                clicked = false;
                Monitor.Log($"unclicked");
                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 if (footerRect.Contains(mousePos))
                    {
                        int newTab = (int)((mousePos.X - screenPos.X) / (screenSize.X / 3));
                        if (whichTab != newTab)
                        {
                            whichTab = newTab;
                            yOffset  = 0;
                            int listcount = whichTab == 0 ? skinList.Count : (whichTab == 1 ? backgroundList.Count : ringList.Count);
                            Monitor.Log($"switching to tab {whichTab}: {listcount} items");
                        }
                    }
                    else
                    {
                        if (whichTab == 0)
                        {
                            for (int i = 0; i < skinList.Count; i++)
                            {
                                Vector2   pos = GetItemPos(i);
                                Rectangle r   = new Rectangle((int)pos.X, (int)pos.Y, Config.ThemeItemWidth, Config.ThemeItemHeight);
                                if (r.Contains(mousePos))
                                {
                                    Monitor.Log($"switching to {skinList[i]}");
                                    SetSkin(skinList[i]);
                                }
                            }
                        }
                        else if (whichTab == 1)
                        {
                            for (int i = 0; i < backgroundList.Count; i++)
                            {
                                Vector2   pos = GetItemPos(i);
                                Rectangle r   = new Rectangle((int)pos.X, (int)pos.Y, Config.ThemeItemWidth, Config.ThemeItemHeight);
                                if (r.Contains(mousePos))
                                {
                                    Monitor.Log($"switching to {backgroundList[i]}");
                                    SetBackground(backgroundList[i]);
                                }
                            }
                        }
                        else if (whichTab == 2)
                        {
                            for (int i = 0; i < ringList.Count; i++)
                            {
                                Vector2   pos = GetItemPos(i);
                                Rectangle r   = new Rectangle((int)pos.X, (int)pos.Y, ModEntry.phoneWidth, Config.RingListItemHeight);
                                if (r.Contains(mousePos))
                                {
                                    Monitor.Log($"switching to {ringList[i]}");
                                    SetRing(ringList[i]);
                                }
                            }
                        }
                    }
                }
            }

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

            if (whichTab == 2)
            {
                e.SpriteBatch.Draw(ModEntry.ringListBackgroundTexture, ModEntry.screenRect, Color.White);
            }
            else
            {
                e.SpriteBatch.Draw(ModEntry.backgroundTexture, ModEntry.phoneRect, Color.White);
            }

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

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

            int count = whichTab == 0 ? skinList.Count : (whichTab == 1 ? backgroundList.Count : ringList.Count);


            for (int i = 0; i < count; i++)
            {
                Vector2 itemPos = GetItemPos(i);
                if (whichTab < 2)
                {
                    Rectangle r          = new Rectangle(0, 0, Config.PhoneWidth, Config.PhoneHeight);
                    Rectangle sourceRect = r;
                    Rectangle destRect;
                    destRect = new Rectangle((int)itemPos.X, (int)itemPos.Y, Config.ThemeItemWidth, Config.ThemeItemHeight);
                    float yScale = Config.ThemeItemHeight / (float)Config.PhoneHeight;
                    if (itemPos.Y < startListY - r.Height * yScale || itemPos.Y >= screenBottom)
                    {
                        continue;
                    }
                    int cutTop    = 0;
                    int cutBottom = 0;
                    if (itemPos.Y < startListY)
                    {
                        cutTop           = (int)Math.Ceiling((startListY - itemPos.Y) / yScale);
                        sourceRect       = new Rectangle(r.X, (int)(r.Y + cutTop), r.Width, (int)(r.Height - cutTop));
                        destRect.Y       = startListY;
                        destRect.Height -= (int)(cutTop * yScale);
                        itemPos          = new Vector2(itemPos.X, startListY);
                    }
                    else if (itemPos.Y > screenBottom - r.Height * yScale - Config.AppHeaderHeight)
                    {
                        cutBottom        = (int)Math.Ceiling((screenBottom - Config.AppHeaderHeight - r.Height * yScale - itemPos.Y) / yScale);
                        destRect.Height += (int)(cutBottom * yScale);
                        sourceRect       = new Rectangle(r.X, r.Y, r.Width, r.Height + cutBottom);
                    }
                    Texture2D texture = whichTab == 0 ? skinDict[skinList[i]][0] : backgroundDict[backgroundList[i]][0];
                    //Monitor.Log($"drawing texture {i} {texture.Width}x{texture.Height} {destRect} {ModEntry.screenRect}");
                    e.SpriteBatch.Draw(texture, destRect, sourceRect, Color.White);
                }
                else
                {
                    if (itemPos.Y < screenPos.Y || itemPos.Y >= screenBottom - Config.AppHeaderHeight)
                    {
                        continue;
                    }
                    if (ringList[i] == Config.PhoneRingTone)
                    {
                        e.SpriteBatch.Draw(ModEntry.ringListHighlightTexture, new Rectangle((int)(itemPos.X), (int)itemPos.Y, (int)(screenSize.X), Config.RingListItemHeight), Color.White);
                    }

                    string itemName = ringList[i];
                    if (itemName.Contains(":"))
                    {
                        itemName = itemName.Split(':')[1];
                    }
                    e.SpriteBatch.DrawString(Game1.dialogueFont, itemName, itemPos, Config.RingListItemColor, 0, Vector2.Zero, Config.RingListItemScale, SpriteEffects.None, 0.86f);
                }
            }
            e.SpriteBatch.Draw(ModEntry.themesHeaderTexture, headerRect, Color.White);
            e.SpriteBatch.Draw(ModEntry.themesHeaderTexture, footerRect, Color.White);
            e.SpriteBatch.Draw(ModEntry.themesHighlightTexture, new Rectangle((int)(screenPos.X + (screenSize.X / 3f) * whichTab), screenBottom - Config.AppHeaderHeight, (int)(screenSize.X / 3f), Config.AppHeaderHeight), Color.White);
            string  headerText     = Helper.Translation.Get("themes");
            string  skinsText      = Helper.Translation.Get("skins");
            string  backsText      = Helper.Translation.Get("backs");
            string  ringsText      = Helper.Translation.Get("rings");
            Vector2 headerTextSize = Game1.dialogueFont.MeasureString(headerText) * Config.HeaderTextScale;
            Vector2 skinsTextSize  = Game1.dialogueFont.MeasureString(skinsText) * Config.TabTextScale;
            Vector2 backsTextSize  = Game1.dialogueFont.MeasureString(backsText) * Config.TabTextScale;
            Vector2 ringsTextSize  = Game1.dialogueFont.MeasureString(ringsText) * Config.TabTextScale;

            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);
            e.SpriteBatch.DrawString(Game1.dialogueFont, skinsText, screenPos + new Vector2(screenSize.X / 6f - skinsTextSize.X / 2f, screenSize.Y - Config.AppHeaderHeight / 2f - headerTextSize.Y / 2f), whichTab == 0 ? Config.ThemesHeaderHighlightedTextColor : Config.ThemesHeaderTextColor, 0, Vector2.Zero, Config.TabTextScale, SpriteEffects.None, 0.86f);
            e.SpriteBatch.DrawString(Game1.dialogueFont, backsText, screenPos + new Vector2(screenSize.X / 2f - backsTextSize.X / 2f, screenSize.Y - Config.AppHeaderHeight / 2f - headerTextSize.Y / 2f), whichTab == 1 ? Config.ThemesHeaderHighlightedTextColor : Config.ThemesHeaderTextColor, 0, Vector2.Zero, Config.TabTextScale, SpriteEffects.None, 0.86f);
            e.SpriteBatch.DrawString(Game1.dialogueFont, ringsText, screenPos + new Vector2(screenSize.X * 5f / 6f - ringsTextSize.X / 2f, screenSize.Y - Config.AppHeaderHeight / 2f - headerTextSize.Y / 2f), whichTab == 2 ? Config.ThemesHeaderHighlightedTextColor : Config.ThemesHeaderTextColor, 0, Vector2.Zero, Config.TabTextScale, SpriteEffects.None, 0.86f);
        }