-- -- Autor: BenjamÌn de la Fuente Ranea -- Fecha: 28-11-2008 -- -- Script de carga inicial -- ------------------------------------------------------------------------------------------------------------------------------------------------------- --TEXTS ------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------- function GetBestCupStateToString(_cupId, _userLevel) _cupId = GetBestCupState(_cupId, _userLevel) if(_cupId == CUP_BRONZE) then return g_Text.rankBronze elseif(_cupId == CUP_SILVER) then return g_Text.rankSilver elseif(_cupId == CUP_GOLD) then return g_Text.rankGold end end function SelectCupText(_bForeGround) local fontStr = "fontTRN_bg.fnt" local layerFlag = LF_PANELS if _bForeGround then fontStr = "fontTRN_fg.fnt" layerFlag = LF_PANELS + 1 end return { scale = 0.15, font = fontStr, overlap = g_TextOverlap, text = g_Text.selectCup, align = E_ALIGN_LEFT, layer = layerFlag } end -- boton back function backText() return { scale = 0.1, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = g_Text.backButton, align = E_ALIGN_LEFT, layer = LF_PANELS } end function nextText() return { scale = 0.1, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = g_Text.nextButton, align = E_ALIGN_LEFT, layer = LF_PANELS } end -- texto copas bloqueadas... function getTextCup1(_bForeGround) local fontStr = "fontTRN_bg.fnt" local layerFlag = LF_PANELS if _bForeGround then fontStr = "fontTRN_fg.fnt" layerFlag = LF_PANELS + 1 end if(GetBestCupState(1, UserLevel) == CUP_LOCKED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupLockedText[1], align = E_ALIGN_LEFT, layer = layerFlag } elseif (GetBestCupState(1, UserLevel) == CUP_NEVER_TRIED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupJustUnLockedText[1], align = E_ALIGN_LEFT, layer = layerFlag } else return { scale = 0.11, font = fontStr, overlap = g_TextOverlap, text = "\n".. g_Text.rank .. "\n" .. GetBestCupStateToString(1, UserLevel) , align = E_ALIGN_LEFT, layer = layerFlag+1 } end end function getTextCup2(_bForeGround) local fontStr = "fontTRN_bg.fnt" local layerFlag = LF_PANELS if _bForeGround then fontStr = "fontTRN_fg.fnt" layerFlag = LF_PANELS + 1 end if(GetBestCupState(2, UserLevel) == CUP_LOCKED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupLockedText[2], align = E_ALIGN_LEFT, layer = layerFlag } elseif (GetBestCupState(2, UserLevel) == CUP_NEVER_TRIED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupJustUnLockedText[2], align = E_ALIGN_LEFT, layer = layerFlag } else return { scale = 0.11, font = fontStr, overlap = g_TextOverlap, text = "\n".. g_Text.rank .. "\n" .. GetBestCupStateToString(2, UserLevel), align = E_ALIGN_LEFT, layer = layerFlag+1 } end end function getTextCup3(_bForeGround) local fontStr = "fontTRN_bg.fnt" local layerFlag = LF_PANELS if _bForeGround then fontStr = "fontTRN_fg.fnt" layerFlag = LF_PANELS + 1 end if(GetBestCupState(3, UserLevel) == CUP_LOCKED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupLockedText[3], align = E_ALIGN_LEFT, layer = layerFlag } elseif (GetBestCupState(3, UserLevel) == CUP_NEVER_TRIED) then return { scale = 0.08, font = fontStr, overlap = g_TextOverlap, text = g_Text.cupJustUnLockedText[3], align = E_ALIGN_LEFT, layer = layerFlag } else return { scale = 0.11, font = fontStr, overlap = g_TextOverlap, text = "\n".. g_Text.rank .. "\n" .. GetBestCupStateToString(3, UserLevel) , align = E_ALIGN_LEFT, layer = layerFlag+1 } end end function getTextCup4(_bForeGround) return getTextCup1(_bForeGround) end function getTextCup5(_bForeGround) return getTextCup2(_bForeGround) end --Text: St. Marino INDOOR CUP function getTextCup1Name1() local prefix = "" if(GetBestCupState(1, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.13, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. g_cupNamesAlias.cup1, align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup1Name1bis() return getTextCup1Name1() end function getTextCup1Name2() local prefix = "" if(GetBestCupState(1, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.06, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. string.upper(g_cupNames.cup1), align = E_ALIGN_LEFT, layer = LF_PANELS } end function texto() return { scale = 0.06, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = "AAAAAAAAAAHHH", align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup1Name2bis() return getTextCup1Name2() end --Text: Orlando OFFROAD CUP function getTextCup2Name1() local prefix = "" if(GetBestCupState(2, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.13, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. g_cupNamesAlias.cup2, align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup2Name1bis() return getTextCup2Name1() end function getTextCup2Name2() local prefix = "" if(GetBestCupState(2, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.06, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. string.upper(g_cupNames.cup2), align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup2Name2bis() return getTextCup2Name2() end --Text: Olympia SUPER TRAX CUP function getTextCup3Name1() local prefix = "" if(GetBestCupState(3, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.13, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. g_cupNamesAlias.cup3, align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup3Name1bis() return getTextCup3Name1() end function getTextCup3Name2() local prefix = "" if(GetBestCupState(3, UserLevel) == CUP_LOCKED) then prefix = " " end return { scale = 0.06, font = "fontTRN_fg.fnt", overlap = g_TextOverlap, text = prefix .. string.upper(g_cupNames.cup3), align = E_ALIGN_LEFT, layer = LF_PANELS } end function getTextCup3Name2bis() return getTextCup3Name2() end ------------------------------------------------------------------------------------------------------------------------------------------------------- -- Assets list GarageCameras = { { "garage.buggy01", "garage.buggy02", "garage.buggy03", "garage.buggy04" }, { "garage.hummer01", "garage.hummer02", "garage.hummer03", "garage.hummer04" }, { "garage.sport01", "garage.sport02", "garage.sport03", "garage.sport04" }, } -- Actor vars SlideShowAnms = { nil, nil, nil, nil, nil, nil} --actorgeoms function getSlideShow(cup_number2) local modelname = "slideshow" .. cup_number2 cup_number2 = math.mod(cup_number2 - 1,3) + 1 --if(GetBestCupState(cup_number2, UserLevel) == CUP_LOCKED) then return { model = "menu/slideshow" .. cup_number2 .. ".mesh", name = modelname, sleepFrames = -1} --end end function getLock(cup_number) local modelname = "lock" .. cup_number cup_number = math.mod(cup_number - 1,3) + 1 if(GetBestCupState(cup_number, UserLevel) == CUP_LOCKED) then return { model = "lock.mesh", name = modelname, } end end function getLockBase(cup_number) local modelname = "lockbase" .. cup_number cup_number = math.mod(cup_number - 1,3) + 1 if(GetBestCupState(cup_number, UserLevel) == CUP_LOCKED) then return { model = "lockbase.mesh", name = modelname,} end end function getPanelesBorde() return { name = "paneles_borde", model = "menu/cup_scroll_border.mesh", layer = EF_PANELS,} end function getInstancedPrize(_cup) local modelname = "cup" .. _cup g_cup = _cup cup_number = math.mod(_cup - 1,3) + 1 g_cup_number = cup_number local instancedcupstate = GetBestCupState(cup_number, UserLevel) if(instancedcupstate == CUP_BRONZE or instancedcupstate == CUP_SILVER or instancedcupstate == CUP_GOLD) then return { model = "menu/prize_shining_cup" .. cup_number ..".mesh", name = modelname, layer = LF_PANELS+1, sleepFrames = -1} end end --setting anims and materials function prepareSlideShowAnims() if(GetBestCupState(1, UserLevel) == CUP_LOCKED) then log("set anim #1,4") SlideShowAnms[1] = SetActorAnim("slideshow1", { anim = "menu/slideshow.anm", loop = true, }) SlideShowAnms[4] = SetActorAnim("slideshow4", { anim = "menu/slideshow.anm", loop = true, }) else SetEffectParamFloat("slideshow1", "slideshow", "g_channel1OffsetV", 0.875) SetEffectParamFloat("slideshow4", "slideshow", "g_channel1OffsetV", 0.875) end if(GetBestCupState(2, UserLevel) == CUP_LOCKED) then log("set anim #2,5") SlideShowAnms[2] = SetActorAnim("slideshow2", { anim = "menu/slideshow.anm", loop = true, }) SlideShowAnms[5] = SetActorAnim("slideshow5", { anim = "menu/slideshow.anm", loop = true, }) else SetEffectParamFloat("slideshow2", "slideshow", "g_channel1OffsetV", 0.875) SetEffectParamFloat("slideshow5", "slideshow", "g_channel1OffsetV", 0.875) end if(GetBestCupState(3, UserLevel) == CUP_LOCKED) then log("set anim #3,6") SlideShowAnms[3] = SetActorAnim("slideshow3", { anim = "menu/slideshow.anm", loop = true, }) SlideShowAnms[6] = SetActorAnim("slideshow6", { anim = "menu/slideshow.anm", loop = true, }) else SetEffectParamFloat("slideshow3", "slideshow", "g_channel1OffsetV", 0.875) SetEffectParamFloat("slideshow6", "slideshow", "g_channel1OffsetV", 0.875) end --pauseSlideShowAnims() PauseAnim(SlideShowAnms[1]); PauseAnim(SlideShowAnms[2]); PauseAnim(SlideShowAnms[3]); PauseAnim(SlideShowAnms[4]); PauseAnim(SlideShowAnms[5]); PauseAnim(SlideShowAnms[6]); end function resumeCurrentSlideShowAnim() --pauso todas y continuo la que está seleccionada... local i log("resume anims" .. table.getn(SlideShowAnms)) for i = 1, table.getn(SlideShowAnms) do if (math.mod(i -1, 3) + 1 == CupSelected) then --resume log("resume anim #" .. i) ResumeAnim(SlideShowAnms[i]) else PauseAnim(SlideShowAnms[i]) end end end function turnMatsToGreyIfLocked() for i = 1, 3, 1 do if(GetBestCupState(i, UserLevel) == CUP_LOCKED) then SetEffectParamColor("MenuScroll", "cup_" .. i, "g_ambientColor", {0.2,0.2,0.2,1.0}) SetEffectParamColor("MenuScroll", "cup_" .. i, "g_matDiffuse", {1.0,1.0,1.0,1.0}) end end end function setPrizeAnims() SetActorAnim("cup1", { anim = "menu/prize_shining_cup.anm", loop = true, }) SetActorAnim("cup4", { anim = "menu/prize_shining_cup.anm", loop = true, }) SetActorAnim("cup2", { anim = "menu/prize_shining_cup.anm", loop = true, }) SetActorAnim("cup3", { anim = "menu/prize_shining_cup.anm", loop = true, velocity = 1}) --pongo los parametros a los materiales de las copas para for i = 1, 5, 1 do local cupstate = GetBestCupState(math.mod(i-1,3)+1, UserLevel) if(cupstate == CUP_GOLD) then turnToGold("cup" .. i,i) elseif (cupstate == CUP_SILVER) then turnToSilver("cup" .. i,i) elseif (cupstate == CUP_BRONZE) then turnToBronze("cup" .. i,i) else end end end function turnToBronze(_cupActorName,_cup) if(_cup == 1 or _cup == 4) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.5,0.34,0.7,1.0}) elseif (_cup == 2 or _cup == 5) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.4,0.34,0.1,1.0}) elseif (_cup == 3 or _cup == 6) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.5,0.34,0.1,1.0}) end --SetEffectParamColor(_cupActorName, "copa_brilla", "g_matDiffuse", {0.165,0.086,0.0,1.0}) SetEffectParamTexture(_cupActorName,"copa_brilla","g_diffuseTexture","copas_copper.pvr") end function turnToSilver(_cupActorName,_cup) if(_cup == 1 or _cup == 4) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.4,0.5,0.5,1.0}) elseif (_cup == 2 or _cup == 5) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.8,0.8,0.4,1.0}) elseif (_cup == 3 or _cup == 6) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.8,0.8,0.8,1.0}) --SetEffectParamColor(_cupActorName, "copa_brilla", "g_matDiffuse", {0.45,0.45,0.4,1.0}) end --SetEffectParamColor(_cupActorName, "copa_brilla", "g_matDiffuse", {0.6,0.6,0.643,1.0}) SetEffectParamTexture(_cupActorName,"copa_brilla","g_diffuseTexture","copas_silver.pvr") end function turnToGold(_cupActorName,_cup) if(_cup == 1 or _cup == 4) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.4,0.4,0.8,1.0}) elseif (_cup == 2 or _cup == 5) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.4,0.4,0.8,1.0}) elseif (_cup == 3 or _cup == 6) then SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.6,0.55,0.4,1.0}) end --SetEffectParamColor(_cupActorName, "copa_brilla", "g_ambientColor", {0.4,0.4,0.8,1.0}) --SetEffectParamColor(_cupActorName, "copa_brilla", "g_matDiffuse", {0.9,0.7,0.6,1.0}) SetEffectParamTexture(_cupActorName,"copa_brilla","g_diffuseTexture","copas.pvr") end ------------------------------------------------------------------------------------------------------------------------------------------------------- -- Controller ------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------- function difficultyOk() if ExistsActor("DifficultyText") then DestroyActor("DifficultyText") end local oldCupSelected = CupSelected MAX_CUPS = 3 if not g_backMenu then CupSelected = 1 end TrackSelected = 1 DestroyActor("Menu") local background = nil if(not ExistsActor("Background")) then background = CreateActor("ActorGeom", { name = "Background", model = "garage/garage2D.mesh" }) else background = FindActor("Background") end --if(g_backMenu) then --DestroyActor("Background2DNoAlpha") --end DestroyActor("Background2DNoAlpha") --if(not g_backMenu) then DollStates.init() --end CreateActor("ActorGeom", { name = "MenuScroll", model = "menu/cup_scroll.mesh", layer = LF_PANELS }) turnMatsToGreyIfLocked() prepareSlideShowAnims() setPrizeAnims() CreateActor("ActorGeom", { name = "Menu", model = "menu/cup.mesh", layer = LF_PANELS, touchable = true }) if g_backMenu then SetActorAnim("Background", { anim = "garage/cup" .. CupSelected .. "_fade_in.anm", loop = false, velocity = 1.5, }) SetActorAnim("MenuScroll", { anim = "menu/cup_scroll_return" .. CupSelected .. ".anm", loop = false, velocity = 1.5, }) SetActorAnim("Menu", { anim = "menu/cup_return.anm", loop = false, velocity = 1.5, }) g_backMenu = false EnqueueExecuteScript("MenuScroll", [[ SetHScroll("MenuScroll", "menu/cup_scroll.anm", true, 3, 0.2, 0.2, true) SelectScrollItem(true,]] .. CupSelected - 1 .. [[) ScrollHSelectItem(]] .. CupSelected - 1 .. [[)]]) else EnqueueExecuteScript('Fade',[[SetActorAnim('Fade', { anim = 'menu/fade_black_from_1_to_0.anm', loop = false, }) EnqueueExecuteScript('Fade',"DestroyActor('Fade')")]]) SetActorAnim("Background", { anim = "garage/cup" .. CupSelected .. "_fade_in.anm", loop = false, velocity = 1.5, }) SetActorAnim("MenuScroll", { anim = "menu/cup_scroll_start.anm", loop = false, velocity = 1.5, }) SetActorAnim("Menu", { anim = "menu/cup_start.anm", loop = false, velocity = 1.5, }) --falta una primitiva para que el scroll se inicie en un punto determinado EnqueueExecuteScript("MenuScroll", [[ SetHScroll("MenuScroll", "menu/cup_scroll.anm", true, 3, 0.2, 0.2, true) SelectScrollItem(true,0) ScrollHSelectItem(0)]]) end end if(not g_backMenu) then DollStates = { -- ------------------------------------------------------------------------- DollIn = { onBegin = function() -- Pre: No hay ninguna mu√±eca visible.... -- Post: Creo/Muestro mu√±eca seleccionada con animacion de entrada y enqueue setState DollCycle si la copa no esta bloqueada DollStates.currentGirl = CupSelected local curDoll = "Doll" .. DollStates.currentGirl if GetBestCupState(CupSelected, UserLevel) ~= CUP_LOCKED then ActivateActor( curDoll ) ClearActorAnims( curDoll, true, true) SetActorAnim( curDoll , { anim = "menu/dolls_in_cup" .. DollStates.currentGirl .. ".anm", loop = false, }) end EnqueueExecuteScript( curDoll , "DollStates.setState(DollStates.DollCycle)") end, onExit = function() end }, -- ------------------------------------------------------------------------- DollCycle = { onBegin = function() -- Pre: La mu√±eca esta cargada, y acaba de terminar su animacion -- Post: La mu√±eca tiene la animaci√≥n c√≠clica local curDoll = "Doll" .. DollStates.currentGirl if IsActiveActor(curDoll) then ClearActorAnims( curDoll, true, true) SetActorAnim( curDoll , { anim = "menu/dolls_cicle_cup" .. DollStates.currentGirl .. ".anm", loop = true, }) end -- Vemos si se ha cambiado de nuevo la selección mientras se hacían las animaciones DollStates.onChangueCup() end, onChangueCup = function() if DollStates.currentGirl ~= CupSelected then DollStates.setState(DollStates.DollOut) end end, onExit = function () end }, -- ------------------------------------------------------------------------- DollOut = { onBegin = function() -- Pre: La mu√±eca esta cargada, y con su animaci√≥n c√≠clica -- Post: ponemos animacion de salida y enqueue setState DollIn local curDoll = "Doll" .. DollStates.currentGirl if IsActiveActor(curDoll) then ClearActorAnims( curDoll, true, true) local anim = SetActorAnim( curDoll , { anim = "menu/dolls_out_cup" .. DollStates.currentGirl .. ".anm", loop = false , }) --ConfigureAnimBlending(anim, 0.5, 0) end EnqueueExecuteScript(curDoll, "DeactivateActor('" .. curDoll .. "');DollStates.setState(DollStates.DollIn)") end, onExit = function () end }, -- ------------------------------------------------------------------------- currentState = nil, currentGirl = nil, setState = function( _newState ) if DollStates.currentState then DollStates.currentState.onExit() end DollStates.currentState = _newState _newState.onBegin() end, -- ------------------------------------------------------------------------- onChangueCup = function() if DollStates.currentState == nil then DollStates.init() end if DollStates.currentState.onChangueCup ~= nil then DollStates.currentState.onChangueCup() end end, -- ------------------------------------------------------------------------- init = function() if not ExistsActor("Doll1") then CreateActor("ActorGeom", { name = "Doll1", model = "dolls/doll_rock.mesh", layer = LF_PANELS+3, }) CreateActor("ActorGeom", { name = "Doll2", model = "dolls/doll_vaquera.mesh", layer = LF_PANELS+3, }) CreateActor("ActorGeom", { name = "Doll3", model = "dolls/doll_china.mesh", layer = LF_PANELS+3, }) DeactivateActor("Doll1") DeactivateActor("Doll2") DeactivateActor("Doll3") DollStates.currentState = DollStates.DollIn DollStates.currentState.onBegin() end end, -- ------------------------------------------------------------------------- destroy = function() DollStates.currentState = nil --animacion de salida de la mu√±eca actual y me las cargo las tres... ClearActorAnims('Doll' .. CupSelected, true, true) local anim = SetActorAnim("Doll" .. CupSelected, { anim = "menu/dolls_out_cup" .. CupSelected .. ".anm", loop = false, }) --ConfigureAnimBlending(anim, 0.5, 0) --log("waiting 'Doll" .. CupSelected .. "'") EnqueueExecuteScript("Doll" ..CupSelected, "DestroyActor('Doll1');DestroyActor('Doll2');DestroyActor('Doll3')") end, destroySync = function(_actorName) --Estoy usando esto para una salida hacia atras, al menu anterior. Se cubre con un fade, y como no me da tiempo a retirar la muñeca, para que no se quede creada --la estoy destruyendo sin más, sin ponerle ninguna animacion. DollStates.currentState = nil --animacion de salida de la mu√±eca actual y me las cargo las tres... --ClearActorAnims('Doll' .. CupSelected, true, true) --local anim = SetActorAnim("Doll" .. CupSelected, { anim = "menu/dolls_out_cup" .. CupSelected .. ".anm", loop = false, }) --ConfigureAnimBlending(anim, 0.5, 0) --log("waiting 'Doll" .. CupSelected .. "'") EnqueueExecuteScript(_actorName, "DestroyActor('Doll1');DestroyActor('Doll2');DestroyActor('Doll3')") end } end function ScrollHSelectItem(_cup) Sound.PlaySound(g_ScrollSound) local oldCupSelected = CupSelected log("NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO___4") CupSelected = _cup + 1 --pongo gris el boton next si resulta que la copa está bloqueada if GetBestCupState(CupSelected, UserLevel) == CUP_LOCKED then SetEffectParamColor("Menu", "colortextoamarillo", "g_matDiffuse", {0.188, 0.188, 0.188, 1.0} ) else SetEffectParamColor("Menu", "colortextoamarillo", "g_matDiffuse", {0.98, 0.854, 0.0, 1.0} ) end if(oldCupSelected ~= CupSelected) then --fade del fondo.. SetActorAnim("Background", { anim = "garage/cup" .. oldCupSelected .. "_to_cup" .. CupSelected .. ".anm", loop = false, }) --sigue la animacion que toca de diapositivas resumeCurrentSlideShowAnim() DollStates.onChangueCup() end end