#include "script/common.lua" #include "game.lua" #include "ui/ui_extensions.lua" pTool = GetStringParam("tool", "none") pFirst = GetBoolParam("isFirst", false) pAmmo = GetIntParam("ammo", 10) function init() body = FindBody() gunpowderTutorial = 0 if GetBool("game.tool."..pTool..".enabled") then Delete(body) return end transform = GetBodyTransform(body) local boxshapes = FindShapes() boxshape = boxshapes[1] boxtransform = GetShapeWorldTransform(boxshape) local min, max = GetShapeBounds(boxshape) local boundsSize = VecSub(max, min) center = VecLerp(min, max, 0.5) boxtransform.pos[1] = boxtransform.pos[1] - 0.5 boxtransform.pos[3] = boxtransform.pos[3] - 0.5 --SetBodyTransform(body, Transform(Vec(0,-20,0))) SetTag(boxshape, "interact", "loc@PICK_UP") snd = LoadSound("tool_pickup.ogg") spawned = false arrow = LoadSprite("gfx/arrowdown.png") end function tick(dt) if not spawned and not GetBool("game.tool."..pTool..".enabled") then SetBodyTransform(body, transform) spawned = true end if spawned then if body ~= nil then --DebugWatch("spawned", true) if GetPlayerInteractShape() == boxshape then if InputPressed("interact") then PlaySound(snd) SetBool("savegame.mod.tool."..pTool..".enabled", true) SetString("game.player.tool", pTool) SetBool("game.tool."..pTool..".enabled", true) --SetInt("savegame.mod.tool."..pTool..".ammo", pAmmo) --SetInt("game.tool."..pTool..".ammo", pAmmo) --Copy savegame tools properties over to volatile game properties local ammoScale = 1 --if campaign then local s = GetFloat("options.game.campaign.ammo") if s == -1 then ammoScale = 0 else ammoScale = ammoScale + s/100 end for id,tool in pairs(gTools) do if id == pTool then for j=1, #tool.upgrades do local prop = tool.upgrades[j].id local value = tool.upgrades[j].max local saved = GetFloat("savegame.mod.tool."..id.."."..prop) if saved > value then value = saved end if prop == "ammo" then if ammoScale ~= 1 then value = math.floor(value * ammoScale) end pAmmo = value SetInt("game.tool."..id..".ammo.max", value) end SetFloat("game.tool."..id.."."..prop, value) end end end if pTool == "powder" then SetValue("gunpowderTutorial", 1, "cosine", 0.25) end SetInt("savegame.mod.tool."..pTool..".ammo", pAmmo) Delete(body) body = nil end else if not pFirst and not HasTag(body, "invisible") then local t = Transform(center) t.rot = QuatLookAt(t.pos, GetCameraTransform().pos) local offset = 3 + math.sin(4.0*GetTime())*0.5 t.pos[2] = t.pos[2]+offset if not GetBool("game.hub.hidetool") then DrawSprite(arrow, t, 2, 2, 1, 1, 1, 1, false, true) end end end end end end function draw() if gunpowderTutorial > 0 then drawTutorial("loc@UI_TEXT_POWDER", "gunpowderTutorial", { "ui/hud/tutorial/powder_spawn.png", "ui/hud/tutorial/powder_boom.png", "ui/hud/tutorial/powder_ignit.png" }, { "TXT_POWDER_SPAWN", "TXT_POWDER_IGNIT", "TXT_POWDER_BOOM" } ) 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] 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) local iw,ih = UiGetImageSize(img) 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