#include "script/common.lua" #include "starthub.lua" #include "missions.lua" #include "ui/ui_helpers.lua" #include "ui/ui_extensions.lua" #include "common/ui/sandbox_view.lua" local STAGES = { [1] = "ravine_bridge", [2] = "town_cars", [3] = "ravine_motivational", [4] = "town_grease", [5] = "ravine_tornado", [6] = "town_destruction", [7] = "ravine_heist", [8] = "town_explosive", [9] = "town_heist" } gResetScale = 0 local backgroundImage = "" function GetCurrentStage() local result = "town_heist" for index = 1, #STAGES do local stage = STAGES[index] if GetBool("savegame.mod.mission." .. stage .. ".complete") then result = stage == "ravine_bridge" and stage or STAGES[index - 1] break end end return result end function init() gSandboxScale = 0 backgroundImage = "menu/background_" .. GetCurrentStage() ..".jpg" SandboxView:init() end function tick(dt) SetBool("game.disablepause", true) SetBool("hud.disable", true) if GetInt("options.audio.menumusic") > 0 then PlayMusic("MOD/music/menu-loop.ogg") end if InputPressed("pause") then Menu() end end local ResetDraw = (function() local backgroundHeight = 0 return function() if gResetScale > 0 then UiPush() UiIgnoreNavigation(gResetScale < 1.0) UiTranslate(180, -40) UiScale(gResetScale, 1) UiColorFilter(1,1,1,gResetScale) UiColor(0,0,0) UiAlign("top left") local description = GetTranslatedStringByKey("UI_TEXT_THIS_WILL_TC") local backgroundOffset = 20 local descriptionSize, descriptionSizeY = UiGetTextSize(description); local backgroundWidth = descriptionSize + backgroundOffset local offset = (backgroundWidth - descriptionSize) / 2 + 10 UiImageBox("ui/common/box-solid-10.png", backgroundWidth, backgroundHeight + 20, 10, 10) ---------------------------------------------------------- UiBeginFrame() UiTranslate(offset, 15) UiFont("regular.ttf", 22) UiColor(1,1,1) local completedMissions = 0 for m,_ in pairs(gMissions) do if GetBool("savegame.mod."..m..".complete") then completedMissions = completedMissions + 1 end end if completedMissions > 0 then UiText(description.."\n"..GetTranslatedStringByKey("UI_TEXT_NUMBER_OF_MISSIONS,"..completedMissions)) UiTranslate(0, 24) else UiText(description) end local textReset = GetTranslatedStringByKey("UI_BUTTON_RESET"); local textCancel = GetTranslatedStringByKey("UI_BUTTON_CANCEL"); local sizeReset = UiGetTextSize(textReset) local sizeCancel = UiGetTextSize(textCancel) local biggerString = sizeCancel if sizeReset > sizeCancel then biggerString = sizeReset end local buttonWidth = biggerString + 39 local buttonHeight = 34 local value = 0.25 local buttonOffset = 20 local leftOffset = (backgroundWidth - buttonWidth * 2 - buttonOffset) / 2 UiTranslate(leftOffset - offset, descriptionSizeY) UiFont("regular.ttf", 26) UiPush() UiColorFilter(1, 0.8, 0.8) if UiTextButton(textReset, buttonWidth, buttonHeight) then ClearKey("savegame.mod") SetValue("gResetScale", 0, "cosine", value) end UiPop() UiTranslate(buttonWidth + buttonOffset, 0) if UiTextButton(textCancel, buttonWidth, buttonHeight) then SetValue("gResetScale", 0, "cosine", value) end _, backgroundHeight = UiEndFrame() UiPop() end end end)() function draw() UiMakeInteractive() if LastInputDevice() == UI_DEVICE_GAMEPAD then UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) end UiButtonHoverColor(1,1,0.5,1) UiPush() UiColor(0,0,0) UiRect(UiWidth(), UiHeight()) UiPop() if UiWidth() > 1920 then UiTranslate((UiWidth() - 1920) / 2, 0) UiWindow(1920, 1080) else UiWindow(UiWidth(), UiHeight()) end UiImage(backgroundImage) UiPush() UiColor(0, 0, 0, 0.75) UiRect(UiWidth(), 150) UiColor(1, 1, 1) UiFont("bold.ttf", 40) UiTranslate(UiCenter(), 60) UiAlign("center middle") UiPush() UiScale(2) UiText("loc@UI_TEXT_MENU_TIMECAMPERS") UiPop() UiTranslate(0, 60) UiScale(1.08) UiText(GetTranslatedStringByKey("UI_TEXT_A_TEARDOWN")) UiPop() UiPush() if gResetScale == 1.0 then UiIgnoreNavigation() end local buttonCnt = 5 local buttonHeight = 40 local menuWidth = 326 local menuHeight = (buttonHeight * buttonCnt) + 40 + (8 * (buttonCnt - 1)) local margin = 28 local buttonWidth = menuWidth - 2 * margin UiColor(0, 0, 0, 0.75) UiTranslate(20, 170) UiImageBox("ui/common/box-solid-10.png", menuWidth, menuHeight, 10, 10) UiButtonImageBox("ui/common/box-outline-fill-6.png", 6, 6, 0.96, 0.96, 0.96) UiColor(0.96, 0.96, 0.96) UiAlign("center middle") UiTranslate(menuWidth / 2, 40) UiFont("regular.ttf", 26) if UiTextButton("loc@UI_BUTTON_MENU_CAMPAIGN", buttonWidth, 40) then startHub() end UiTranslate(0, 48) if UiTextButton("loc@UI_BUTTON_SANDBOX", buttonWidth, 40) then openSandboxMenu() end UiTranslate(0, 48) UiPush() if not HasKey("savegame.mod") then UiColorFilter(1,1,1,0.5) UiDisableInput() UiIgnoreNavigation() end if UiTextButton("loc@UI_BUTTON_MENU_RESET", buttonWidth, 40) then if gResetScale == 0 then SetValue("gResetScale", 1, "cosine", 0.25) else SetValue("gResetScale", 0, "cosine", 0.25) end end UiPop() UiTranslate(0, 48) if UiTextButton("loc@UI_BUTTON_CREDITS", buttonWidth, 40) then StartLevel("final", "MOD/time_travel.xml", "outro") end ResetDraw() UiTranslate(0, 48) if UiTextButton("loc@UI_BUTTON_MENU_RETURN", buttonWidth, 40) then Menu() end UiTranslate(0, 48) UiPop() if gSandboxScale > 0 then UiPush() UiBlur(gSandboxScale) UiColor(0.7, 0.7, 0.7, 0.25 * gSandboxScale) UiRect(UiWidth(), UiHeight()) if not drawSandbox(gSandboxScale) then SetValue("gSandboxScale", 0, "cosine", 0.25) end UiPop() end drawLocalUserTag() end function isMissionCompleted(missionId) return missionId and getMissionScore(missionId) > 0 end function getMissionScore(missionId) return GetInt("savegame.mod.mission."..missionId..".score") end function openSandboxMenu() SandboxView:reset() SetValue("gSandboxScale", 1, "cosine", 0.25) end function isLevelUnlocked(level) return level == "hub" and true or isMissionCompleted(level) end