---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by RJ.
--- DateTime: 11/6/2024 4:48 PM
---

WelcomeMessageB42 = {};

WelcomeMessageUI = ISCollapsableWindow:derive("WelcomeMessageUI");

local FONT_HGT_SMALL = getTextManager():getFontHeight(UIFont.Small)
local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium)
local FONT_HGT_LARGE = getTextManager():getFontHeight(UIFont.Large)
local UI_BORDER_SPACING = 10
local BUTTON_HGT = FONT_HGT_SMALL + 6

WelcomeMessageB42.doMsg = function()
    if getDebug() then
        return;
    end
    local panelWidth = (UI_BORDER_SPACING+1)*2 + getTextManager():MeasureStringX(UIFont.Small, getText("- Farm animals need a Livestock Zone, and will never leave it as long as they are safe - even if it's unfenced."))
    local panel = WelcomeMessageUI:new(60, 60, panelWidth, 650);
    panel:initialise();
    panel:addToUIManager();
    panel:setVisible(false);

    panel:setX((getCore():getScreenWidth() / 2) - (panel.width / 2));
    panel:setY((getCore():getScreenHeight() / 2) - (panel.height / 2));
end

function WelcomeMessageUI:new(x, y, width, height)
    local o = {};
    o = ISCollapsableWindow:new(x, y, width, height);
    setmetatable(o, self);
    self.__index = self;
    o.refreshNeeded = true
    o.screenshot = getTexture("media/ui/DragScreen.png")
    o.borderColor = {r=0.4, g=0.4, b=0.4, a=1};
    o.backgroundColor = {r=0, g=0, b=0, a=0.8};
    return o;
end

function WelcomeMessageUI:create()
    local y = self:titleBarHeight() + UI_BORDER_SPACING

    self.titleLabel = ISLabel:new(0, y, FONT_HGT_LARGE, "Welcome to Build 42 Testing!", 1, 1, 1, 1, UIFont.Large, true)
    self.titleLabel:setX((self:getWidth() - self.titleLabel:getWidth())/2)
    self:addChild(self.titleLabel)

    y = y + self.screenshot:getHeight() + FONT_HGT_LARGE + UI_BORDER_SPACING*2

    self.changeLabel = ISLabel:new(0, y, FONT_HGT_MEDIUM, "Here are some quick tips on what has changed:", 1, 1, 1, 1, UIFont.Medium, true)
    self.changeLabel:setX((self:getWidth() - self.changeLabel:getWidth())/2)
    self:addChild(self.changeLabel)

    y = y + FONT_HGT_MEDIUM + BUTTON_HGT + UI_BORDER_SPACING

    local x = UI_BORDER_SPACING+1
    self.rich = ISRichTextPanel:new(x, y, self.width - x*2, self.height - y - self:resizeWidgetHeight());
    self.rich.anchorLeft = true;
    self.rich.anchorRight = true;
    self.rich.marginLeft = 0
    self.rich.marginRight = 0
    self.rich:initialise();
    self.rich:instantiate();
    self.rich:noBackground();
    self.rich.backgroundColor = {r=0, g=0, b=0, a=0.3};
    self.rich.borderColor = {r=1, g=1, b=1, a=0.1};
    self:addChild(self.rich)

    self:setHeight(y + x + BUTTON_HGT*9)
end

function WelcomeMessageUI:initialise()
    ISCollapsableWindow.initialise(self);

    self:create();
end

function WelcomeMessageUI:render()
    ISCollapsableWindow.render(self);

    self.titleLabel:setX((self:getWidth() - self.titleLabel:getWidth())/2)
    self.changeLabel:setX((self:getWidth() - self.changeLabel:getWidth())/2)

    self:drawTexture(self.screenshot, (self.width-self.screenshot:getWidth())/2, self.titleLabel:getBottom() + UI_BORDER_SPACING, 1, 1, 1, 1)

    self.rich.text =
    "<CENTRE> <SIZE:small> - Farm animals need a Livestock Zone, and will never leave it as long as they are safe - even if it's unfenced. <LINE><LINE> - The firearms aiming system has been upgraded. You are given a pistol to experiment with. <LINE><LINE> - Building and crafting are now done by pressing the new icons at the top left. <LINE><LINE> - Hold E to pick up and drag bodies, and the same to drop them. <LINE><LINE> - Gamepad and Steamdeck functionality has not yet been upgraded.";
    self.rich:paginate()

end

Events.OnGameStart.Add(WelcomeMessageB42.doMsg);