// ----------------------------------------------------------------------------- // // showPopupMessage( %textToShow, %appearMethod, %showMethod) // // // // Notes: The first parameter is the text that is to be displayed. Tabs are used (\t) // to indicate multiple lines. Second parameter is the appearance method - first // word is the method (see below) and second word is how long it takes to appear // in miliseconds (ie 1,000 means on second). Third parameter is the show method - first // word is the method (see below), second word is how long it appears on screen, and // the third word is how long each animation cycle is. // // showPopupMessage( "text line 1/ttext line 2", // "appearanceMethod appearanceLength", // "showMethod showLength showCycle"); // // // Appearance Methods (appearanceMethod) // ================== // -1 - Random Method (any but 'None' method) // 0 - None // 1 - Rise Up // 2 - Zoom from the left // 3 - Drop Down // 4 - Zoom from the right // 5 - Diagonal to straight // 6 - Four Corners // 7 - Circle in from right // // // Show Methods (showMethod) (bits set - more than one method can be selected) // ============ // 0 - Steady // 1 - Sin bounce // 2 - Cos side-to-side // 4 - Whole word sin bounce // 8 - Whole word cos side-to-side // // // // Some sample calls // ----------------- // // showPopupMessage($PlayerName[%playerNum] @ "\tYour Putt", "2 700", "2 1800 800"); // // This will show player name on 1st line and "Your Putt" on the second line. It // will zoom in from the left and take 0.7 seconds to appear. It will then animate // for 1.8 seconds using the Cos side-to-side method cycling every 0.8 seconds. // //------------------- // // showPopupMessage( "Got it!", "0 0", "1 1200 800"); // // This will show "Got it!" on the screen. It will appear immediately with no // appearance animation. It will animate for 1.2 seconds using the Sin bound // method with a cycle of 0.8 seconds. // //------------------- // // showPopupMessage("Hole-In-One!!/tBirdie", "7 1200", "3 3200 900"); // // This will show "Hole-In-One!!" on the 1st line and "Birdie" on the second // line. It will circle in from the right and take 1.2 seconds to appear. It // will then animation for 3.2 seconds using both the Sin bounce and Cos side-to-side // methods with a cycle of 0.9 seconds. function showPopupMessage( %textToShow, %appearMethod, %showMethod) { // No pop up message when a hint is up if ($ShowingHint) return; // First, clear out the previous message (if there is one) removePopupMessage(); // Get the extent of our play window %ext = PlayGui.getExtent(); $PuPlayGuiW = getWord(%ext,0); $PuPlayGuiH = getWord(%ext,1); // Save the appearace method and time $PuAppearanceMethod = getWord(%appearMethod,0); if ($PuAppearanceMethod $= "-1") $PuAppearanceMethod = getRandom(6) + 1; $PuAppearanceTime = getWord(%appearMethod,1); if ($PuAppearanceTime == 0) $PuAppearanceTime = 1; // Save the show method %howLong = $PuAppearanceTime + getWord(%showMethod,1); $PuShowCycle = getWord(%showMethod,2); %showMethod = getWord(%showMethod,0); $PuShowMethod = %showMethod & 15; $PuAlwaysShow = %showMethod & 16; // Find where each line is in our text to show $PuNumLines = getFieldCount(%textToShow); %fixedTextToShow = ""; for (%i = 0; %i < $PuNumLines; %i++) { %fieldText = getField(%textToShow,%i); %fixedTextToShow = %fixedTextToShow @ %fieldText; %nextLineChar[%i] = strlen(%fixedTextToShow)-1; } // Some initial setup $PuNumChars = strlen(%fixedTextToShow); %curLine = 0; $PuTotalWidth[0] = 0; // Create a BitmapCtrl for each non-space character for (%i=0;%i<$PuNumChars;%i++) { %curChar = getSubStr(%fixedTextToShow,%i,1); // Skip all the spaces if (%curChar !$= " ") { // Check for special characters if (%curChar $= "!") %curChar = "ep"; else if (%curChar $= ".") %curChar = "period"; else if (%curChar $= "?") %curChar = "question"; else if (%curChar $= ":") %curChar = "colon"; else if (%curChar $= "-") %curChar = "minus"; else if (%curChar $= ",") %curChar = "comma"; else if (%curChar $= "\"") %curChar = "doublequote"; else if (%curChar $= "=") %curChar = "equal"; else if (%curChar $= "+") %curChar = "plus"; else if (%curChar $= "\'") %curChar = "quote"; else if (%curChar $= ";") %curChar = "semicolon"; // All our alphanumeric bitmaps are in the folder %bitmap = "~/client/ui/alpha/" @ %curChar; // Create a BitmapCtrl and add it to the play gui $PuCtrlId[%i] = new GuiBitmapCtrl() { profile = "GuiDefaultProfile"; horizSizing = "width"; vertSizing = "height"; position = "-100 0"; extent = "80 48"; minExtent = "8 8"; visible = "1"; helpTag = "0"; bitmap = %bitmap; wrap = "0"; }; PlayGui.add($PuCtrlId[%i]); // This will force the extent of this ctrl to match the size of the bitmap $PuCtrlId[%i].setBitmap($PuCtrlId[%i].bitmap,true); %width = getWord($PuCtrlId[%i].extent,0); } else { // Give spaces a width of 40 pixels %width = 40; $PuCtrlId[%i] = 0; } // Update our total width $PuTotalWidth[%curLine] += %width; if (%i == %nextLineChar[%curLine]) { %curLine++; $PuTotalWidth[%curLine] = 0; } } // Set our beginning x location so our text is centered on the screen %x = ($PuPlayGuiW / 2) - ($PuTotalWidth[0] / 2); %y = ($PuPlayGuiH / 2) - 80 - ($PuNumLines-1) * 60; %curLine = 0; // Now that we know the total width we can set each chars final position for (%i=0;%i<$PuNumChars;%i++) { if ($PuCtrlId[%i]) { // PuPt2 is the final ending position $PuPt2x[%i] = %x; $PuPt2y[%i] = %y; // The starting position will depend upon our appearance method setPuStartPos(%i); // Width of this bitmap %width = getWord($PuCtrlId[%i].extent,0); } else { // Spaces have a width of 40 %width = 40; } // Set where our next character will be positioned %x += %width; if (%i == %nextLineChar[%curLine]) { %curLine++; %x = ($PuPlayGuiW / 2) - ($PuTotalWidth[%curLine] / 2); %y += 120; } } $PuStartTime = $PuLastTime = GetRealTime(); echodebug("\nfunction showPopupMessage()"); echodebug(" realTime: " @ $PuStartTime); // Set all the chars of the message to their starting positions updatePopupMessage(); // Schedule the removal of this message $PuRemoveSchedule = schedule( %howLong, 0, "removePopupMessage"); } function setPuStartPos( %i ) { // Set our starting position based upon our appearance method if ($PuAppearanceMethod == 0) { $PuPt1x[%i] = $PuPt2x[%i]; $PuPt1y[%i] = $PuPt2y[%i]; } else if ($PuAppearanceMethod == 1) { $PuPt1x[%i] = $PuPt2x[%i]; $PuPt1y[%i] = $PuPlayGuiH + (%i * 80); } else if ($PuAppearanceMethod == 2) { %pos = $PuPt2x[%i] - ($PuPlayGuiW/2) - ($PuTotalWidth/2) - 40; $PuPt1x[%i] = %pos * 3; $PuPt1y[%i] = $PuPt2y[%i]; } else if ($PuAppearanceMethod == 3) { $PuPt1x[%i] = $PuPt2x[%i]; $PuPt1y[%i] = 0 - (%i * 80) - 80; } else if ($PuAppearanceMethod == 4) { %pos = $PuPt2x[%i] - (($PuPlayGuiW / 2) - ($PuTotalWidth / 2)); $PuPt1x[%i] = $PuPlayGuiW + %pos * 3; $PuPt1y[%i] = $PuPt2y[%i]; } else if ($PuAppearanceMethod == 5) { $PuPt1x[%i] = ($PuPlayGuiW/2) - (($PuPlayGuiW / 2) - $PuPt2x[%i]) * 2; $PuPt1y[%i] = $PuPlayGuiH - (%i * 80) - 80; } else if ($PuAppearanceMethod == 6) { switch (%i % 8) { case 0: $PuPt1x[%i] = $PuPlayGuiW; $PuPt1y[%i] = $PuPlayGuiH - getWord($PuCtrlId[%i].extent,1); case 1: $PuPt1x[%i] = $PuPlayGuiW - getWord($PuCtrlId[%i].extent,0); $PuPt1y[%i] = $PuPlayGuiH; case 2: $PuPt1x[%i] = $PuPlayGuiW; $PuPt1y[%i] = 0; case 3: $PuPt1x[%i] = $PuPlayGuiW - getWord($PuCtrlId[%i].extent,0); $PuPt1y[%i] = 0 - getWord($PuCtrlId[%i].extent,1); case 4: $PuPt1x[%i] = 0; $PuPt1y[%i] = $PuPlayGuiH; case 5: $PuPt1x[%i] = 0 - getWord($PuCtrlId[%i].extent,0); $PuPt1y[%i] = $PuPlayGuiH - getWord($PuCtrlId[%i].extent,1); case 6: $PuPt1x[%i] = 0; $PuPt1y[%i] = 0 - getWord($PuCtrlId[%i].extent,1); case 7: $PuPt1x[%i] = 0 - getWord($PuCtrlId[%i].extent,0); $PuPt1y[%i] = 0; } } else if ($PuAppearanceMethod == 7) { $PuPt1x[%i] = $PuPlayGuiW; $PuPt1y[%i] = $PuPlayGuiH/4; $PuPtMidx[%i] = $PuPlayGuiW/2; $PuPtMidy[%i] = $PuPt1y[%i]; } } function interpolatePopup( %percentage, %pt1, %pt2) { %result = %pt1 + (%pt2 - %pt1) * %percentage; return %result; } // Close enough for our purposes $PI = 3.14159265; function computePopupShowAdjust( %i, %percent, %percentToUse ) { // Default to adjusting neither 'x' nor 'y' %adjustX = 0; %adjustY = 0; if ($PuShowMethod & 3) { // Modify percent by char position %percent1 = %percent + (%i/10); if ($PuShowMethod & 1) { %offset = 12 * mSin($PI * 2 * %percent1); %adjustY = %offset * %percentToUse; } if ($PuShowMethod & 2) { %offset = 12 * mCos($PI * 2 * %percent1); %adjustX = %offset * %percentToUse; } } if ($PuShowMethod & 4) { %offset = 12 * mSin($PI * 2 * %percent); %adjustY += %offset * %percentToUse; } if ($PuShowMethod & 8) { %offset = 12 * mCos($PI * 2 * %percent); %adjustX += %offset * %percentToUse; } return (%adjustX SPC %adjustY); } function computePopupPosition( %i, %percent, %percentShow ) { // Special case for the Circle in method if ($PuAppearanceMethod == 7) { %percent -= %i * 0.04; if (%percent < 0) %percent = 0; } // Get our show adjust - %percent will always be set to 1.0 or // below after doing this code fragment if ($PuAlwaysShow & 16) { %adjust = computePopupShowAdjust( %i, %percentShow, 1); if (%percent > 1) %percent = 1; } else { if (%percent > 1) { if (%percent > 1.2) %percentToUse = 1; else %percentToUse = (%percent - 1) / 0.2; %adjust = computePopupShowAdjust( %i, %percentShow, %percentToUse); %percent = 1; } else { %adjust = 0; } } // Break out the x and y components of the adjust value %adjustX = getWord(%adjust,0); %adjustY = getWord(%adjust,1); // Special case for Circle in method if ($PuAppearanceMethod == 7) { if (%percent <= 0.25) { // Adjust percent so it covers the range of 0.0 to 0.25 %percent /= 0.25; // Get the interpolated position between pt1 and ptMid %workPtX = interpolatePopup(%percent,$PuPt1x[%i],$PuPtMidx[%i]); %workPtY = interpolatePopup(%percent,$PuPt1y[%i],$PuPtMidy[%i]); } else if (%percent <= 0.9) { // Adjust percent so it covers the range of 0.25 to 0.9 %percent = (%percent - 0.25) / 0.65; %piVal = %percent * $PI * 2; %sinVal = mSin(%piVal); %cosVal = mCos(%piVal); // Get our position around the circle %workPtX = $PuPlayGuiW/2 - %sinVal * $PuPtMidy[%i]; %workPtY = $PuPlayGuiH/2 - %cosVal * $PuPtMidy[%i]; } else { // Adjust percent so it covers the range of 0.9 to 1.0 %percent = (%percent - 0.9) / 0.1; // Get the interpolated position between ptMid and pt2 %workPtX = interpolatePopup(%percent,$PuPtMidx[%i],$PuPt2x[%i]); %workPtY = interpolatePopup(%percent,$PuPtMidy[%i],$PuPt2y[%i]); } } else { // Get the interpolated position between pt1 and pt2 %workPtX = interpolatePopup(%percent,$PuPt1x[%i],$PuPt2x[%i]); %workPtY = interpolatePopup(%percent,$PuPt1y[%i],$PuPt2y[%i]); } %workPtX = mFloor(%workPtX+%adjustX); %workPtY = mFloor(%workPtY+%adjustY); return (%workPtX SPC %workPtY); } $upmFunctionAvail = true; function updatePopupMessage() { if ($PuRemoveSchedule) { %curTime = GetRealTime(); %diffTime = %curTime - $PuStartTime; %appearancePercent = %diffTime / $PuAppearanceTime; %showPercent = %diffTime / $PuShowCycle; for (%i=0;%i<$PuNumChars;%i++) { if ($PuCtrlId[%i]) { %pos = computePopupPosition(%i,%appearancePercent,%showPercent); $PuCtrlId[%i].position = %pos; } } } } function removePopupMessage() { if ($PuRemoveSchedule) { cancel($PuRemoveSchedule); $PuRemoveSchedule = 0; for (%i=0;%i<$PuNumChars;%i++) { if ($PuCtrlId[%i]) { PlayGui.remove($PuCtrlId[%i]); $PuCtrlId[%i].delete(); $PuCtrlId[%i] = 0; } } } if ($UnlockedBallHintToShow) { $UnlockedBallHintToShow = false; // %hintText = getField($cbSkinPower[$UnlockedBallPowerNum],1); $Hints51 = "You have earned a golf ball that has a new Super Power!\n\nYou can choose this new ball from the choose ball screen."; showHint(12); } }