#include "common.lua" #include "game.lua" #include "ui/ui_extensions.lua" pTool = GetStringParam("tool", "none") function init() body = FindBody("tool") transform = GetBodyTransform(body) SetBodyTransform(body, Transform(Vec(0,-20,0))) SetTag(body, "interact", "loc@PICK_UP") snd = LoadSound("tool_pickup.ogg") spawned = false arrow = LoadSprite("gfx/arrowdown.png") upgradeTimer = 0 plankTutorial = 0 rifleTutorial = 0 end function tick(dt) if not spawned and not GetBool("game.tool."..pTool..".enabled") then local score = GetInt("savegame.hub.score") for i=1,#gRanks do if score >= gRanks[i].score and gRanks[i].tool == pTool then SetBodyTransform(body, transform) spawned = true SetBool("level.toolspawn", true) end end end if spawned then if body ~= nil then if GetPlayerInteractBody() == body then if InputPressed("interact") then PlaySound(snd) SetBool("savegame.tool."..pTool..".enabled", true) SetString("game.player.tool", pTool) SetBool("game.tool."..pTool..".enabled", true) Delete(body) body = nil upgradeTimer = 3 --Copy over default configuration for tool for j=1, #gTools[pTool].upgrades do local id = gTools[pTool].upgrades[j].id local value = gTools[pTool].upgrades[j].default local saved = GetInt("savegame.tool."..pTool.."."..id) if saved > value then value = saved end if id == "ammo" then SetInt("game.tool."..id..".ammo.max", value) end SetInt("game.tool."..pTool.."."..id, value) end if pTool == "plank" then SetValue("plankTutorial", 1, "cosine", 0.25) end if pTool == "rifle" then SetValue("rifleTutorial", 1, "cosine", 0.25) end SetBool("level.toolspawn", false) end elseif not GetBool("game.map.enabled") then local t = TransformCopy(transform) t.rot = QuatLookAt(t.pos, GetCameraTransform().pos) local offset = 3 + math.sin(4.0*GetTime())*0.5 t.pos[2] = t.pos[2] + offset DrawSprite(arrow, t, 2, 2, 1, 1, 1, 1, false, true) end end end if upgradeTimer > 0 then upgradeTimer = upgradeTimer - GetTimeStep() if upgradeTimer <= 0 then SetString("hud.notification", GetTranslatedStringByKey("UI_HUD_NOTE_YOU_CAN")) end end end tutorialStep = 1 tutorialStepsCount = 1 function endTutorial(tutorialName) SetValue(tutorialName, 0, "cosine", 0.25) tutorialStep = tutorialStepsCount end function drawTutorial(tutorialTitle, tutorialName, images, texts) local tutorialActive = _G[tutorialName] if tutorialActive > 0 then UiMakeInteractive() if LastInputDevice() == UI_DEVICE_GAMEPAD then UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) end local width = 792 local height = 720 if tutorialStep < 1 then tutorialStep = 1 end local img = images[tutorialStep] local tutorialText = texts[tutorialStep] tutorialStepsCount = #images UiBlur(tutorialActive) UiColor(0.7,0.7,0.7, 0.25*tutorialActive) UiRect(UiWidth(), UiHeight()) UiColorFilter(1,1,1,tutorialActive) UiTranslate(UiCenter(), UiMiddle()) UiAlign("center middle") UiColor(.0, .0, .0, 0.7*tutorialActive) UiScale(1, tutorialActive) UiImageBox("ui/common/box-solid-shadow-50.png", width, height, -50, -50) UiWindow(width, height) UiAlign("center") UiTranslate(UiCenter(), 60) UiPush() Ui:BoldFont(30) UiColor(1,1,1) UiText(tutorialTitle) UiPop() UiFont("regular.ttf", 26) UiColor(1, 1, 1) UiTranslate(0, 40) UiImage(img) UiTranslate(0, 480) UiPush() Ui:MediumFont(22) UiWordWrap(600) UiTextAlignment(Ui.TextAlignment.Center) UiText(GetTranslatedStringByKey(tutorialText)) UiPop() UiTranslate(0, 100) UiPush() local txt = (tutorialStep < tutorialStepsCount) and "loc@UI_BUTTON_NEXT" or "loc@UI_BUTTON_CLOSE" UiTranslate(0, 12) if LastInputDevice() == UI_DEVICE_GAMEPAD then if InputPressed("menu_accept") then if tutorialStep < tutorialStepsCount then tutorialStep = tutorialStep + 1 else endTutorial(tutorialName) end end UiDrawHintsCentered({ { ico = "[[menu:menu_accept;iconsize=42,42]]", txt = txt } }) else UiColor(0.96, 0.96, 0.96) UiButtonImageBox("ui/common/box-outline-fill-6.png", 6, 6, 0.96, 0.96, 0.96, 0.8) UiButtonHoverColor(1.0,1.0,0.5,1) if UiTextButton(txt) then if tutorialStep < tutorialStepsCount then tutorialStep = tutorialStep + 1 else endTutorial(tutorialName) end end end UiPop() end end function draw() if plankTutorial > 0 then drawTutorial("loc@UI_TEXT_PLANK_TOOL", "plankTutorial", { "ui/hud/tutorial/plank-ramp.jpg", "ui/hud/tutorial/plank-lift.jpg", "ui/hud/tutorial/plank-complex.jpg" }, { "TXT_PLANKS_CAN", "TXT_YOU_CAN", "TXT_USE_MULTIPLE" } ) end if rifleTutorial > 0 then local key = "[[menu:gamepad_button_l3;iconsize=42\\,42]]" if LastInputDevice() ~= UI_DEVICE_GAMEPAD then key = GetTranslatedStringByKey("RMB") end drawTutorial("loc@UI_TEXT_HUNTING_RIFLE", "rifleTutorial", {"ui/hud/tutorial/rifle.jpg"}, {"TXT_PRESS_GRAB,"..key} ) end end