--CHECK OUT THESE STATIC VARIABLES --Defines how much non-selected elements are faded to GLOBAL_SHARED_FADE_ELEMENT=0.1 GLOBAL_TEXT_SIZE_VERYSMALL=24 GLOBAL_TEXT_SIZE_SMALL=36 GLOBAL_TEXT_SIZE_MED=40 GLOBAL_TEXT_SIZE_LARGE=72 ------------------------------------------------------------------------------- --Sing It 2 general button functions. ------------------------------------------------------------------------------- function AddButton(xpos, ypos, width, height, buttonName, icon) CreateSprite({ texture=icon, name=buttonName, drawOrigin="center", pos={x=xpos, y=ypos}, size={x=width, y=height}, scale={x=1, y=1}, visible=true, color=0XFFFFFF00 }) ConnectChild({parent="root", child=buttonName}) end function AddButton90(xpos, ypos, width, height, buttonName, icon) CreateSprite({ texture=icon, name=buttonName, drawOrigin="center", pos={x=xpos, y=ypos}, rot=90, size={x=width, y=height}, scale={x=1, y=1}, visible=true, color=0XFFFFFF00 }) ConnectChild({parent="root", child=buttonName}) end function AddButton270(xpos, ypos, width, height, buttonName, icon) CreateSprite({ texture=icon, name=buttonName, drawOrigin="center", pos={x=xpos, y=ypos}, rot=270, size={x=width, y=height}, scale={x=1, y=1}, visible=true, color=0XFFFFFF00 }) ConnectChild({parent="root", child=buttonName}) end function AddIconButton(xpos, ypos, width, height, xscale, yscale, buttonName, icon) CreateSprite({ texture=icon, name=buttonName, drawOrigin="center", pos={x=xpos, y=ypos}, size={x=width, y=height}, scale={x=xscale, y=yscale}, visible=true, color=0XFFFFFF00 }) ConnectChild({parent="root", child=buttonName}) end function AddOptionsText(xpos, ypos, text_name, text) --Main title CreateText({name=text_name, text=text, pos={x=xpos,y=ypos}, size={x=512,y=64}, fontSize=30, color=0xFFFFFF00, xAlign="left", yAlign="centre", }) ConnectChild({parent="root", child=text_name}) end ------------------------------------------------------------------------------- --Sing It 2 command button functions. ------------------------------------------------------------------------------- function CreateTextButton(params) Tx=params.x Ty=params.y Tw=params.width Th=params.height Tc=params.color or 0xffffffff Tv=params.visible or true Tn=params.name Tp=params.parent or "root" TxtA=params.txtAlign or "left" Button_Text=params.text or "Text Here" Button_fontSize=params.text_fontSize or 32 Button_Type=params.type or "Normal" Button_Text_Color=params.text_color or 0xffffffff --white text --Set the button textures(depending on the button type). left_texture="textures/common/menubuttons/normal_button_left.tex" middle_texture="textures/common/menubuttons/normal_button_middle.tex" right_texture="textures/common/menubuttons/normal_button_right.tex" if Button_Type =="Highlighted" then Button_Text_Color=params.text_color or 0x000000ff --white text left_texture="textures/common/menubuttons/highlighted_button_left.tex" middle_texture="textures/common/menubuttons/highlighted_button_middle.tex" right_texture="textures/common/menubuttons/highlighted_button_right.tex" elseif Button_Type =="Selected" then Button_Text_Color=params.text_color or 0x000000ff --white text left_texture="textures/common/menubuttons/selected_button_left.tex" middle_texture="textures/common/menubuttons/selected_button_middle.tex" right_texture="textures/common/menubuttons/selected_button_right.tex" end --Scale the end textures relatively. button_texture_height=128 relative_scale=Th / button_texture_height button_height=button_texture_height * relative_scale button_left_end_width=64 * relative_scale button_right_end_width=64 * relative_scale --Set the middle button section width. button_middle_width=0 button_sides_width=button_left_end_width + button_right_end_width if Tw > button_sides_width then button_middle_width=Tw - button_sides_width end --Create a group to hold the button graphics CreateNodeGroup({ name=Tn, pos={ x=Tx, y=Ty }, size={ x=Tw, y=Th }, color=Tc, visible=Tv, }) --Left local left_name=Tn .. "_left" CreateSprite({ texture=left_texture, name=left_name, pos={ x=0, y=0 }, size={ x=button_left_end_width, y=button_height } }) ConnectChild({parent=Tn, child=left_name}) --Middle local middle_name=Tn .. "_middle" CreateSprite({ name=middle_name, texture=middle_texture, pos={ x=button_left_end_width, y=0 }, size={ x=button_middle_width, y=button_height } }) ConnectChild({parent=Tn, child=middle_name}) --Right local right_name=Tn .. "_right" CreateSprite({ name=right_name, texture=right_texture, pos={ x=button_left_end_width + button_middle_width, y=0 }, size={ x=button_right_end_width, y=button_height } }) ConnectChild({parent=Tn, child=right_name}) text_x=45 * relative_scale text_y=button_height / 2 if (TxtA =="center") then text_x=Tw/2 end --Button text local text_name=Tn .. "_text" CreateText({ name=text_name, text=Button_Text, xAlign=TxtA, yAlign="center", fontSize=Button_fontSize, pos={ x=text_x, y=text_y }, size={ x=Tw, y=Th }, color=Button_Text_Color, }) ConnectChild({parent=Tn, child=text_name}) ConnectChild({parent=Tp, child=Tn}) end --Function to create a selected command button animation. function CreateTextButton_SelectAnimation(script_name, button_node, buttonHL_node, buttonSL_node, height, width, valign, halign) StartScript({name=script_name}) verticalAlign=valign or "right" horizontalAlign=valign or "bottom" moveX=0; moveY=0; tw=width or 0 th=height or 0 --change the number below to the difference between newScale and oldScale newScale=1.2 fade_time=0.2 --now to work out how to scale the element with alignment if horizontalAlign =="left" then moveX=0 elseif horizontalAlign =="center" then moveX=-(tw*0.1) else --else we assume it's aligned right moveX=-(tw*0.2) end if verticalAlign =="top" then moveY=0 elseif verticalAlign =="center" then moveY=-(th*0.1) else --else we assume it's aligned bottom moveY=-(th*0.2) end Move({node=button_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonHL_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonSL_node, translation={x=moveX, y=moveY}, duration=fade_time}) --buttons are created from top left perspective, so depending on alignment, we move them differently. ScaleTo({node=button_node, scale={x=newScale, y=newScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonHL_node, scale={x=newScale, y=newScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonSL_node, scale={x=newScale, y=newScale}, duration=fade_time, timeCurve="speed_up_curve"}) FadeIn({node=buttonHL_node, duration=fade_time, timeCurve="speed_up_curve"}) EndScript() end --Function to create a deselected command button animation. function CreateTextButton_DeselectAnimation(script_name, button_node, buttonHL_node, buttonSL_node, height, width, valign, halign) StartScript({name=script_name}) verticalAlign=valign or "right" horizontalAlign=valign or "bottom" tw=width or 0 th=height or 0 --keep oldscale at 1.0, or 100% oldScale=1.0 fade_time=0.2 --now to work out how to scale the element with alignment if horizontalAlign =="left" then moveX=0 elseif horizontalAlign =="center" then moveX=(tw*0.1) else --else we assume it's aligned right moveX=(tw*0.2) end if verticalAlign =="top" then moveY=0 elseif verticalAlign =="center" then moveY=(th*0.1) else --else we assume it's aligned bottom moveY=(th*0.2) end --change the number below to the difference between newScale and oldScale Move({node=button_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonHL_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonSL_node, translation={x=moveX, y=moveY}, duration=fade_time}) ScaleTo({node=button_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonHL_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonSL_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) FadeOut({node=buttonHL_node, duration=fade_time, timeCurve="speed_up_curve"}) EndScript() end --Function to create a deselected command button animation. function CreateTextButton_ClickAnimation(script_name, button_node, buttonHL_node, buttonSL_node, height, width, valign, halign) StartScript({name=script_name}) verticalAlign=valign or "right" horizontalAlign=valign or "bottom" tw=width or 0 th=height or 0 oldScale=1.0 fade_time=0.1 FadeIn({node=buttonSL_node, duration=0.05, timeCurve="speed_up_curve"}) Sleep({duration=0.05}) --now to work out how to scale the element with alignment if horizontalAlign =="left" then moveX=0 elseif horizontalAlign =="center" then moveX=(tw*0.1) else --else we assume it's aligned right moveX=(tw*0.2) end if verticalAlign =="top" then moveY=0 elseif verticalAlign =="center" then moveY=(th*0.1) else --else we assume it's aligned bottom moveY=(th*0.2) end --change the number below to the difference between newScale and oldScale Move({node=button_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonHL_node, translation={x=moveX, y=moveY}, duration=fade_time}) Move({node=buttonSL_node, translation={x=moveX, y=moveY}, duration=fade_time}) ScaleTo({node=button_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonHL_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) ScaleTo({node=buttonSL_node, scale={x=oldScale, y=oldScale}, duration=fade_time, timeCurve="speed_up_curve"}) FadeOut({node=buttonSL_node, duration=fade_time, timeCurve="speed_up_curve"}) EndScript() end --ALL FUNCTIONS ABOVE THIS ARE DEPRECATED --DO NOT USE AND REMOVE ALL REFERENCES TO THEM function CreateButton(button_node_name, texture_name, hasDisabledState, hasActivatedState, overlayTexture) CreateButtonDetailed(button_node_name, texture_name, hasDisabledState, hasActivatedState, overlayTexture, "") end --All buttons should use this --this assumes that all buttons have normal, hover and click state function CreateButtonDetailed(button_node_name, texture_name, hasDisabledState, hasActivatedState, overlayTexture, specialHoverTexture) thePos=0 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER theSize=64 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER theScale=1.0 --start small, prevents upscaling scaleUp=1.1 --states are: Disabled, Normal, Highlighted, Activated, Activated with Highlight and Selected --sprite names [in order of layering] if (hasDisabledState) then disabled_name=button_node_name .. "_Disabled" end normal_name=button_node_name .. "_Normal" highlighted_name=button_node_name .. "_Highlighted" if (hasActivatedState) then activated_name=button_node_name .. "_Activated" activated_highlighted_name=button_node_name .. "_Activated_Highlighted" end selected_name=button_node_name .. "_Selected" overlay_name=button_node_name .. "_Overlay" --textures [in order of layering] if (hasDisabledState) then disabledTexture=texture_name .. "_off.tex" end normalTexture=texture_name .. ".tex" --unique hover texture defined if specialHoverTexture =="" then highlightedTexture=texture_name .. "_over.tex" else highlightedTexture=specialHoverTexture .. ".tex" end --works like radio button, on-off states if (hasActivatedState) then activatedTexture=texture_name .. "_on.tex" activatedHighlightedTexture=texture_name .. "_onover.tex" --unique hover texture defined if specialHoverTexture =="" then activatedHighlightedTexture=texture_name .. "_onover.tex" else activatedHighlightedTexture=specialHoverTexture .. "_on.tex" end end selectedTexture=texture_name .. "_click.tex" if (overlayTexture) then overlayTexture=overlayTexture .. ".tex" end --create the buttons CreateNodeGroup({ name=button_node_name, pos={ x=thePos, y=thePos }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffff00, visible=true }) ConnectChild({parent="root", child=button_node_name}) --Disabled if (hasDisabledState) then CreateSprite({ name=disabled_name, texture=disabledTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffff00, visible=true }) ConnectChild({parent=button_node_name, child=disabled_name}) end --Normal CreateSprite({ name=normal_name, texture=normalTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale-0.02, y=theScale-0.02}, color=0xffffffff, visible=true }) ConnectChild({parent=button_node_name, child=normal_name}) --Highlighted CreateSprite({ name=highlighted_name, texture=highlightedTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffff00, visible=true }) ConnectChild({parent=button_node_name, child=highlighted_name}) --Activated if (hasActivatedState) then CreateSprite({ name=activated_name, texture=activatedTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale+0.02, y=theScale+0.02}, color=0xffffff00, visible=true }) ConnectChild({parent=button_node_name, child=activated_name}) CreateSprite({ name=activated_highlighted_name, texture=activatedHighlightedTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale+0.04, y=theScale+0.04}, color=0xffffff00, visible=true }) ConnectChild({parent=button_node_name, child=activated_highlighted_name}) end --Selected CreateSprite({ name=selected_name, texture=selectedTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale+0.05, y=theScale+0.05}, color=0xffffff00, visible=true }) ConnectChild({parent=button_node_name, child=selected_name}) if (overlayTexture) then CreateSprite({ name=overlay_name, texture=overlayTexture, pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffffcc,--80% alpha visible=true }) ConnectChild({parent=button_node_name, child=overlay_name}) end --scriptnames if (hasDisabledState) then disableScriptName="Disable_" .. button_node_name enableScriptName="Enable_" .. button_node_name end hoverScriptName="Hover_" .. button_node_name unhoverScriptName="Unhover_" .. button_node_name if (hasActivatedState) then activateScriptName="Activate_" .. button_node_name deactivateScriptName="Deactivate_" .. button_node_name hoverActivatedScriptName="Hover_Activated_" ..button_node_name unhoverActivatedScriptName="Unhover_Activated_" ..button_node_name end clickScriptName="Click_" .. button_node_name --scripts if (hasDisabledState) then StartScript({name=disableScriptName}) FadeIn({node=disabled_name, duration=0.01}) FadeOut({node=normal_name, duration=0.1}) if (overlayTexture) then Fade({node=overlay_name, alpha=0.4, duration=0.1}) end EndScript() StartScript({name=enableScriptName}) FadeOut({node=disabled_name, duration=0.01}) FadeIn({node=normal_name, duration=0.1}) if (overlayTexture) then Fade({node=overlay_name, alpha=0.8, duration=0.1}) end EndScript() end --now we do the animations and button calls, this is sweet normal_name=button_node_name .. "_Normal" highlighted_name=button_node_name .. "_Highlighted" if (hasActivatedState) then activated_name=button_node_name .. "_Activated" activated_highlighted_name=button_node_name .. "_Activated_Highlighted" end selected_name=button_node_name .. "_Selected" StartScript({name=hoverScriptName}) UpTime=0.1; DownTime=0.1; FadeIn({node=highlighted_name, duration=0.1}) --bounce up ScaleTo({node=normal_name, scale={x=scaleUp-0.02, y=scaleUp-0.02}, duration=0.1}) ScaleTo({node=highlighted_name, scale={x=scaleUp, y=scaleUp}, duration=0.1}) if (hasActivatedState) then ScaleTo({node=activated_name, scale={x=scaleUp+0.02, y=scaleUp+0.02}, duration=0.1}) ScaleTo({node=activated_highlighted_name, scale={x=scaleUp+0.04, y=scaleUp+0.04}, duration=0.1}) end ScaleTo({node=selected_name, scale={x=scaleUp+0.05, y=scaleUp+0.05}, duration=0.1}) if (overlayTexture) then ScaleTo({node=overlay_name, scale={x=scaleUp, y=scaleUp}, duration=0.1}) --Fade({node=overlay_name, alpha=0.8, duration=0.2}) end --wait for bounce up to end Sleep({duration=0.1}) --bounce back down ScaleTo({node=normal_name, scale={x=theScale-0.02, y=theScale-0.02}, duration=0.1}) ScaleTo({node=highlighted_name, scale={x=theScale, y=theScale}, duration=0.1}) if (hasActivatedState) then ScaleTo({node=activated_name, scale={x=theScale+0.02, y=theScale+0.02}, duration=0.1}) ScaleTo({node=activated_highlighted_name, scale={x=theScale+0.04, y=theScale+0.04}, duration=0.1}) end ScaleTo({node=selected_name, scale={x=theScale+0.05, y=theScale+0.05}, duration=0.1}) if (overlayTexture) then ScaleTo({node=overlay_name, scale={x=theScale, y=theScale}, duration=0.1}) end EndScript() StartScript({name=unhoverScriptName}) FadeOut({node=highlighted_name, duration=0.1}) --if (overlayTexture) then --Fade({node=overlay_name, alpha=0.4, duration=0.1}) --end EndScript() if (hasActivatedState) then StartScript({name=activateScriptName}) FadeIn({node=activated_name, duration=0.1}) --if (overlayTexture) then --Fade({node=overlay_name, alpha=0.8, duration=0.1}) --end EndScript() StartScript({name=deactivateScriptName}) FadeOut({node=activated_name, duration=0.1}) --if (overlayTexture) then --Fade({node=overlay_name, alpha=0.4, duration=0.1}) --end EndScript() StartScript({name=hoverActivatedScriptName}) FadeIn({node=activated_highlighted_name, duration=0.1}) EndScript() StartScript({name=unhoverActivatedScriptName}) FadeOut({node=activated_highlighted_name, duration=0.1}) EndScript() end StartScript({name=clickScriptName}) FadeIn({node=selected_name, duration=0.1}) ScaleTo({node=selected_name, scale={x=scaleUp+0.05, y=scaleUp+0.05}, duration=0.1}) if (overlayTexture) then ScaleTo({node=overlay_name, scale={x=scaleUp, y=scaleUp}, duration=0.1}) --Fade({node=overlay_name, alpha=1.0, duration=0.2}) end Sleep({duration=0.1}) ScaleTo({node=selected_name, scale={x=theScale+0.05, y=theScale+0.05}, duration=0.1}) if (overlayTexture) then ScaleTo({node=overlay_name, scale={x=theScale, y=theScale}, duration=0.1}) --Fade({node=overlay_name, alpha=1.0, duration=0.2}) end FadeOut({node=selected_name, duration=0.2}) EndScript() end function CreateTextElement(text_node_name, theText, hasHoveredState, fontSize, horzAlign, vertAlign, colour) thePos=0 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER theSize=64 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER hAlign=horzAlign or "center" vAlign=vertAlign or "center" theColour=colour or 0xFFFFFF00 --default text element. white. CreateText({name=text_node_name, text=theText, pos={x=thePos,y=thePos}, size={x=theSize,y=theSize}, fontSize=fontSize, color=theColour, xAlign=hAlign, yAlign=vAlign, }) ConnectChild({parent="root", child=text_node_name}) end function CreateBlankButton(button_node_name, hasDisabledState, hasActivatedState) thePos=0 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER theSize=64 --THIS WILL BE ASSIGNED BY AN ANIMESH INFOLAYER theScale=1.0 --start small, prevents upscaling scaleUp=1.1 normal_name=button_node_name .. "_Normal" --create the buttons CreateNodeGroup({ name=button_node_name, pos={ x=thePos, y=thePos }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffffff, visible=true }) ConnectChild({parent="root", child=button_node_name}) --Normal CreateSprite({ name=normal_name, texture="textures/transp.tex", pos={ x=0, y=0 }, size={ x=theSize, y=theSize }, scale={x=theScale, y=theScale}, color=0xffffffff, visible=true }) ConnectChild({parent=button_node_name, child=normal_name}) --scriptnames if (hasDisabledState) then disableScriptName="Disable_" .. button_node_name enableScriptName="Enable_" .. button_node_name end hoverScriptName="Hover_" .. button_node_name unhoverScriptName="Unhover_" .. button_node_name if (hasActivatedState) then activateScriptName="Activate_" .. button_node_name deactivateScriptName="Deactivate_" .. button_node_name end clickScriptName="Click_" .. button_node_name --scripts if (hasDisabledState) then StartScript({name=disableScriptName}) EndScript() StartScript({name=enableScriptName}) EndScript() end StartScript({name=hoverScriptName}) EndScript() StartScript({name=unhoverScriptName}) EndScript() if (hasActivatedState) then StartScript({name=activateScriptName}) EndScript() StartScript({name=deactivateScriptName}) EndScript() end StartScript({name=clickScriptName}) EndScript() end function CreateEasySprite(nodename, textureName) --Normal CreateSprite({ name=nodename, texture=textureName..".tex", pos={ x=0, y=0 }, size={ x=64, y=64 }, scale={x=1.0, y=1.0}, color=0xffffff00, visible=true }) ConnectChild({parent="root", child=nodename}) end