Skip to content

Conversation

Mushymato
Copy link
Contributor

@Mushymato Mushymato commented Sep 1, 2025

Adds some background theme options, and refactor code for potential mod added themes down the road (i.e. not in this PR)

image

@Mushymato Mushymato changed the title Lookup anything.theme options [Lookup Anything] Background theme options Sep 1, 2025
@Pathoschild
Copy link
Owner

Thanks for the pull request!

Splitting the logic between LetterBackground + MenuBoxBackground + PlainBackground will make things harder to extend later though. Could you combine them into one implementation which reads a unified data model?

For example, something like...

/// <summary>Get the default themes.</summary>
private static Dictionary<string, ThemeData> GetDefaultThemes()
{
    return new()
    {
        // formerly LetterBackground
        ["TornLetter"] = new ThemeData
        {
            Background = new()
            {
                Texture = "LooseSprites/letterBG",
                SourceRect = new Rectangle(0, 0, 320, 180)
            }
        },

        // formerly PlainBackground
        ["PlainWheat"] = new ThemeData
        {
            Background = new()
            {
                Color = "Wheat"
            },
            Border = new()
            {
                Color = "BurlyWood",
                Width = 4
            }
        },

        // formerly MenuBoxBackground
        ["MenuBox_Inset"] = new ThemeData
        {
            Background = new()
            {
                Texture = "Maps/MenuTiles",
                SourceRect = new Rectangle(0, 316, 60, 60),
                ScaleMode = BackgroundScaleMode.TextureBox
            }
        }
    };
}

Then the unified implementation would do something like...

public void DrawBackground(SpriteBatch b, int x, int y, int width, int height)
{
    if (this.Theme.Background is { } background)
    {
        if (background.Color != null)
            Utility.DrawSquare(b, new(x, y, width, height), 0, backgroundColor: background.Color);

        if (background.Texture != null)
        {
            Rectangle sourceRect = background.SourceRect;

            switch (background.ScaleMode)
            {
                case BackgroundScaleMode.TextureBox:
                    // copy logic from MenuBoxBackground
                    break;
                    
                default:
                    // copy logic from LetterBackground
                    break;
            }
        }
    }

   if (this.Theme.Border is { } border)
       Utility.DrawSquare(b, new(x, y, width, height), border.Width, border.Color);
}

Once we have that, it'll be much easier to allow custom mod themes (which I could add after merging the PR).

@Mushymato Mushymato force-pushed the LookupAnything.theme_options branch 3 times, most recently from a14ba1e to 52c555c Compare September 5, 2025 05:07
@Mushymato Mushymato force-pushed the LookupAnything.theme_options branch from 52c555c to f2ffe11 Compare September 5, 2025 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants