Esempio n. 1
0
        public static void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (api.IsCallingNPC() || api.GetRunningApp() != Helper.ModRegistry.ModID)
            {
                return;
            }

            if (e.Button == SButton.MouseLeft)
            {
                Point mousePos = Game1.getMousePosition();
                if (!api.GetScreenRectangle().Contains(mousePos))
                {
                    return;
                }

                Helper.Input.Suppress(SButton.MouseLeft);
                Vector2 screenPos  = api.GetScreenPosition();
                Vector2 screenSize = api.GetScreenSize();
                if (!CataloguesApp.opening && new Rectangle((int)(screenPos.X + screenSize.X - Config.AppHeaderHeight), (int)(screenPos.Y), (int)Config.AppHeaderHeight, (int)Config.AppHeaderHeight).Contains(mousePos))
                {
                    Monitor.Log($"Closing app");
                    CataloguesApp.CloseApp();
                    return;
                }
                CataloguesApp.opening     = false;
                Visuals.clicking          = true;
                Visuals.lastMousePosition = mousePos;
            }
        }
Esempio n. 2
0
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            context = this;
            Config  = Helper.ReadConfig <ModConfig>();
            if (!Config.EnableMod)
            {
                return;
            }

            HelperEvents.Initialize(Helper, Monitor, Config);
            Catalogues.Initialize(Helper, Monitor, Config);
            CataloguesApp.Initialize(Helper, Monitor, Config);
            Visuals.Initialize(Helper, Monitor, Config);

            Helper.Events.GameLoop.GameLaunched += HelperEvents.GameLoop_GameLaunched;
        }
Esempio n. 3
0
        public static void Display_RenderedWorld(object sender, RenderedWorldEventArgs e)
        {
            if (api.IsCallingNPC())
            {
                return;
            }

            Vector2 screenPos  = api.GetScreenPosition();
            Vector2 screenSize = api.GetScreenSize();

            if (!api.GetPhoneOpened() || !api.GetAppRunning() || api.GetRunningApp() != Helper.ModRegistry.ModID)
            {
                Monitor.Log($"Closing app: phone opened {api.GetPhoneOpened()} app running {api.GetAppRunning()} running app {api.GetRunningApp()}");
                CataloguesApp.CloseApp();
                return;
            }

            if (!clicking)
            {
                dragging = false;
            }

            Point mousePos = Game1.getMousePosition();

            if (clicking)
            {
                if (mousePos.Y != lastMousePosition.Y && (dragging || api.GetScreenRectangle().Contains(mousePos)))
                {
                    dragging = true;
                    offsetY += mousePos.Y - lastMousePosition.Y;
                    //Monitor.Log($"offsetY {offsetY} max {screenSize.Y - Config.MarginY + (Config.MarginY + Game1.dialogueFont.LineSpacing * 0.9f) * audio.Length}");
                    offsetY           = Math.Min(0, Math.Max(offsetY, (int)(screenSize.Y - (Config.AppHeaderHeight + Config.MarginY + (Config.MarginY + Config.AppRowHeight) * CataloguesApp.catalogueList.Count))));
                    lastMousePosition = mousePos;
                }
            }

            if (clicking && !Helper.Input.IsSuppressed(SButton.MouseLeft))
            {
                Monitor.Log($"unclicking; dragging = {dragging}");
                if (dragging)
                {
                    dragging = false;
                }
                else if (api.GetScreenRectangle().Contains(mousePos) && !new Rectangle((int)screenPos.X, (int)screenPos.Y, (int)screenSize.X, Config.AppHeaderHeight).Contains(mousePos))
                {
                    CataloguesApp.ClickRow(mousePos);
                }
                clicking = false;
            }


            e.SpriteBatch.Draw(backgroundTexture, new Rectangle((int)screenPos.X, (int)screenPos.Y, (int)screenSize.X, (int)screenSize.Y), Color.White);
            for (int i = 0; i < CataloguesApp.catalogueList.Count; i++)
            {
                string    a      = Helper.Translation.Get(CataloguesApp.catalogueList[i]);
                float     posY   = screenPos.Y + Config.AppHeaderHeight + Config.MarginY * (i + 1) + i * Config.AppRowHeight + offsetY;
                Rectangle r      = new Rectangle((int)screenPos.X, (int)posY, (int)screenSize.X, Config.AppRowHeight);
                bool      bought = !Config.RequireCataloguePurchase || Game1.player.mailReceived.Contains($"BoughtCatalogue{a}");
                if (!bought)
                {
                    float backPosY  = posY;
                    int   cutTop    = 0;
                    int   cutBottom = 0;

                    if (posY < screenPos.Y + Config.AppHeaderHeight)
                    {
                        cutTop   = (int)(screenPos.Y - posY);
                        backPosY = screenPos.Y;
                    }
                    if (posY > screenPos.Y + screenSize.Y - Config.AppRowHeight)
                    {
                        cutBottom = (int)(posY - screenPos.Y + screenSize.Y - Config.AppRowHeight);
                    }
                    r = new Rectangle((int)screenPos.X, (int)backPosY, (int)screenSize.X, (int)(Config.AppRowHeight) - cutTop - cutBottom);
                    if (!r.Contains(mousePos))
                    {
                        e.SpriteBatch.Draw(greyedTexture, r, Color.White);
                    }
                }

                if (r.Contains(mousePos))
                {
                    e.SpriteBatch.Draw(hightlightTexture, r, Color.White);
                }

                float textHeight = Game1.dialogueFont.MeasureString(a).Y *Config.TextScale;
                if (posY > screenPos.Y && posY < screenPos.Y + screenSize.Y - Config.AppRowHeight / 2f + textHeight / 2f)
                {
                    e.SpriteBatch.DrawString(Game1.dialogueFont, a, new Vector2(screenPos.X + Config.MarginX, posY + Config.AppRowHeight / 2f - textHeight / 2f), Config.TextColor, 0f, Vector2.Zero, Config.TextScale, SpriteEffects.None, 0.86f);
                    if (!bought)
                    {
                        string  cost    = "" + CataloguesApp.GetCataloguePrice(CataloguesApp.catalogueList[i]);
                        Vector2 buySize = Game1.dialogueFont.MeasureString(cost) * Config.TextScale;
                        e.SpriteBatch.DrawString(Game1.dialogueFont, cost, new Vector2(screenPos.X + screenSize.X - buySize.X - Config.AppRowHeight * 3 / 4, posY + Config.AppRowHeight / 2f - buySize.Y / 2f), Config.TextColor, 0f, Vector2.Zero, Config.TextScale, SpriteEffects.None, 0.86f);
                        e.SpriteBatch.Draw(coinTexture, new Rectangle((int)(screenPos.X + screenSize.X - Config.AppRowHeight * 3 / 4f), (int)(posY + Config.AppRowHeight / 4f), (int)(Config.AppRowHeight / 2f), (int)(Config.AppRowHeight / 2f)), Color.White);
                    }
                }
            }
            e.SpriteBatch.Draw(headerTexture, new Rectangle((int)screenPos.X, (int)screenPos.Y, (int)screenSize.X, Config.AppHeaderHeight), Color.White);
            float   headerTextHeight = Game1.dialogueFont.MeasureString(Helper.Translation.Get("catalogues")).Y *Config.HeaderTextScale;
            Vector2 xSize            = Game1.dialogueFont.MeasureString("x") * Config.HeaderTextScale;

            e.SpriteBatch.DrawString(Game1.dialogueFont, Helper.Translation.Get("catalogues"), new Vector2(screenPos.X + Config.MarginX, screenPos.Y + Config.AppHeaderHeight / 2f - headerTextHeight / 2f), Config.HeaderTextColor, 0f, Vector2.Zero, Config.HeaderTextScale, SpriteEffects.None, 0.86f);
            e.SpriteBatch.DrawString(Game1.dialogueFont, "x", new Vector2(screenPos.X + screenSize.X - Config.AppHeaderHeight / 2f - xSize.X / 2f, screenPos.Y + Config.AppHeaderHeight / 2f - xSize.Y / 2f), Config.HeaderTextColor, 0f, Vector2.Zero, Config.HeaderTextScale, SpriteEffects.None, 0.86f);
        }