home *** CD-ROM | disk | FTP | other *** search
/ 3D World 123 / 3DW_123.iso / pc / 3dw.exe / 3dw.dxr / Internal_17_menu_utils.ls < prev    next >
Encoding:
Text File  |  2009-06-30  |  17.6 KB  |  611 lines

  1. global delim, rootPath, contentPath, interfacePath, mainIndex, nextFreeTextCastIndex, nextFreeImageIndex, nextFreeThumbnailIndex, currentSection, currentThumbStart, defaultThumbnailMember, defaultImageMember, nextEnabled, backEnabled, mainMenuEnabled, contentBackEnabled, infoPopup, popupOpen, vlcpath, bannerUrl, showVLCLink
  2.  
  3. on __init__
  4.   rootPath = the moviePath
  5.   delim = the last char in rootPath
  6.   nextFreeTextCastIndex = 1
  7.   nextFreeImageIndex = 1
  8.   nextFreeThumbnailIndex = 1
  9.   contentPath = pathJoin([rootPath, "DiscContents"])
  10.   interfacePath = pathJoin([rootPath, "Interface"])
  11.   menuIndexPath = pathJoin([interfacePath, "menu_items.txt"])
  12.   defaultThumbnailMember = importDefaultThumbnail()
  13.   defaultImageMember = importDefaultImage()
  14.   if baFileExists(menuIndexPath) then
  15.     createMenuObjects(menuIndexPath)
  16.     getIssueNumber()
  17.   else
  18.     alert("No menu_items.txt found at: " & QUOTE & menuIndexPath & QUOTE)
  19.     _player.quit()
  20.   end if
  21.   currentSection = mainIndex[1]
  22.   bannerUrl = "http://www.google.com"
  23.   loadBanner()
  24.   nextEnabled = 0
  25.   backEnabled = 0
  26.   mainMenuEnabled = 0
  27.   contentBackEnabled = 0
  28.   popupOpen = 0
  29.   showVLCLink = 0
  30. end
  31.  
  32. on loadBanner
  33.   banner_id_path = pathJoin([interfacePath, "banner.txt"])
  34.   put banner_id_path
  35.   t = getNetText(banner_id_path)
  36.   if netDone(t) then
  37.     ban = netTextResult(t)
  38.     put ban
  39.     banFile = ban.line[1]
  40.     if (banFile contains "gif") or (banFile contains "GIF") then
  41.       memNum = member("banner_gif_loader").memberNum
  42.       member("banner_gif_loader").fileName = pathJoin([interfacePath, banFile])
  43.       member(memNum).name = "banner_gif_loader"
  44.       sprite(101).member = member(memNum)
  45.       bannerUrl = ban.line[2]
  46.     else
  47.       memNum = member("banner_loader").memberNum
  48.       member("banner_loader").importFileInto(pathJoin([interfacePath, banFile]))
  49.       bannerUrl = ban.line[2]
  50.       member(memNum).name = "banner_loader"
  51.       sprite(101).member = member(memNum)
  52.     end if
  53.   end if
  54. end
  55.  
  56. on getIssueNumber
  57.   issuePath = pathJoin([interfacePath, "issue.txt"])
  58.   if baFileExists(issuePath) then
  59.     t = getNetText(issuePath)
  60.     if netDone(t) then
  61.       member("issue_number").text = netTextResult(t) & " "
  62.     end if
  63.     numchar = 0
  64.     nums = "1234567890"
  65.     repeat with c = 1 to the number of chars in the text of member "issue_number"
  66.       if nums contains member("issue_number").char[c] then
  67.         numchar = c - 1
  68.         exit repeat
  69.       end if
  70.     end repeat
  71.     if numchar > 0 then
  72.       member("issue_number").char[1..numchar].color = rgb(145, 187, 1)
  73.       member("issue_number").char[numchar + 1..member("issue_number").char.count].color = rgb(255, 255, 255)
  74.     end if
  75.   end if
  76. end
  77.  
  78. on importDefaultImage
  79.   iPath = pathJoin([interfacePath, "default_image.jpg"])
  80.   defaultImageMember = member("default_image")
  81.   if baFileExists(iPath) then
  82.     defaultImageMember.importFileInto(iPath)
  83.   end if
  84.   return defaultImageMember
  85. end
  86.  
  87. on importDefaultThumbnail
  88.   tPath = pathJoin([interfacePath, "default_thumbnail.jpg"])
  89.   defaultThumbnailMember = member("default_thumbnail")
  90.   if baFileExists(tPath) then
  91.     defaultThumbnailMember.importFileInto(tPath)
  92.   end if
  93.   return defaultThumbnailMember
  94. end
  95.  
  96. on setMainMenuTitles
  97.   spStart = 35
  98.   repeat with i = spStart to 100
  99.     sprite(i).visible = 0
  100.   end repeat
  101.   curSp = spStart
  102.   repeat with i = 1 to mainIndex.count
  103.     sprite(curSp).member.text = mainIndex[i].itemTitle
  104.     sprite(curSp).visible = 1
  105.     sprite(curSp).menuObject = mainIndex[i]
  106.     if mainIndex[i].itemPath = EMPTY then
  107.       sprite(curSp).Active = 0
  108.       sprite(curSp).member.color = rgb(255, 255, 255)
  109.     else
  110.       sprite(curSp).Active = 1
  111.       sprite(curSp).member.color = rgb(0, 0, 0)
  112.     end if
  113.     curSp = curSp + 1
  114.   end repeat
  115. end
  116.  
  117. on fallBackOpenFolder aPath
  118.   if the last char in aPath = delim then
  119.     Ok = baOpenFile(aPath, "normal")
  120.   else
  121.     lDel = 0
  122.     repeat with i = 1 to aPath.char.count
  123.       if aPath.char[i] = delim then
  124.         lDel = i
  125.       end if
  126.     end repeat
  127.     strippedPath = aPath.char[1..lDel]
  128.     Ok = baOpenFile(strippedPath, "normal")
  129.   end if
  130. end
  131.  
  132. on playVideoVLC videoPath
  133.   put videoPath
  134.   put vlcpath
  135.   sVideoPath = baShortFileName(videoPath)
  136.   sVLCPath = baShortFileName(vlcpath)
  137.   Ok = baShell("open", sVLCPath, sVideoPath, EMPTY, "normal")
  138.   put "ok = " & Ok
  139.   if Ok < 32 then
  140.     fallBackOpenFolder(videoPath)
  141.   end if
  142. end
  143.  
  144. on createMenuObjects menuIndexPath
  145.   mainIndex = []
  146.   lastMenuObject = 0
  147.   menuScriptLoader = getNetText(menuIndexPath)
  148.   if netDone(menuScriptLoader) then
  149.     menuScript = netTextResult(menuScriptLoader)
  150.     repeat with i = 1 to menuScript.line.count
  151.       thisLine = menuScript.line[i]
  152.       if thisLine <> EMPTY then
  153.         if thisLine.char[1..3] = "---" then
  154.           atChar = 0
  155.           repeat with a = 1 to thisLine.char.count
  156.             if thisLine.char[a] = "@" then
  157.               atChar = a
  158.               exit repeat
  159.             end if
  160.           end repeat
  161.           itemTitle = stripWhiteSpace(thisLine.char[4..atChar - 1])
  162.           iPat = stripWhiteSpace(thisLine.char[atChar + 1..thisLine.length])
  163.           if iPat.char.count > 0 then
  164.             if iPat.char[1] <> "[" then
  165.               itemPath = pathJoin([contentPath, stripWhiteSpace(thisLine.char[atChar + 1..thisLine.length])])
  166.             else
  167.               itemPath = iPat
  168.             end if
  169.           else
  170.             itemPath = EMPTY
  171.           end if
  172.           mainIndex.append(createMenuNode(itemTitle, itemPath, i))
  173.           lastMenuObject = mainIndex[mainIndex.count]
  174.           next repeat
  175.         end if
  176.         if lastMenuObject = 0 then
  177.           alert("Problem reading the menu_items.txt:: No main menu defined before" & QUOTE & thisLine & QUOTE & " at line: " & string(i))
  178.           _player.quit()
  179.           next repeat
  180.         end if
  181.         atChar = 0
  182.         repeat with a = 1 to thisLine.char.count
  183.           if thisLine.char[a] = "@" then
  184.             atChar = a
  185.             exit repeat
  186.           end if
  187.         end repeat
  188.         itemTitle = stripWhiteSpace(thisLine.char[1..atChar - 1])
  189.         itemPath = pathJoin([lastMenuObject.itemPath, stripWhiteSpace(thisLine.char[atChar + 1..thisLine.length])])
  190.         lastMenuObject.children.append(createMenuNode(itemTitle, itemPath, i))
  191.       end if
  192.     end repeat
  193.   end if
  194. end
  195.  
  196. on gatherInfo aNode
  197.   if aNode.infoText = 0 then
  198.     if baFolderExists(aNode.itemPath) then
  199.       txtLoader = getNetText(pathJoin([aNode.itemPath, "info.txt"]))
  200.       txt = new(#text, castLib("text"))
  201.       if netDone(txtLoader) then
  202.         txt.text = netTextResult(txtLoader)
  203.       end if
  204.       aNode.infoText = txt
  205.       parseFormattingInfo(aNode.infoText)
  206.       imgPath = pathJoin([aNode.itemPath, "shot.jpg"])
  207.       if baFileExists(imgPath) then
  208.         member(nextFreeImageIndex, "images").importFileInto(imgPath)
  209.         aNode.imageMember = member(nextFreeImageIndex, "images")
  210.         nextFreeImageIndex = nextFreeImageIndex + 1
  211.       end if
  212.       cmsPath = pathJoin([aNode.itemPath, "cms.txt"])
  213.       if baFileExists(cmsPath) then
  214.         t = getNetText(cmsPath)
  215.         if netDone(t) then
  216.           res = netTextResult(t)
  217.           parseContentButtons(res, aNode)
  218.         end if
  219.       end if
  220.     end if
  221.   end if
  222. end
  223.  
  224. on parseContentButtons txt, node
  225.   isVideo = 0
  226.   repeat with i = 1 to txt.line.count
  227.     vt = 0
  228.     extra = EMPTY
  229.     pType = txt.line[i].char[1]
  230.     tail = txt.line[i].char[2..txt.line[i].char.count]
  231.     if tail contains "[" then
  232.       bs = 1
  233.       repeat with j = 1 to tail.char.count
  234.         if tail.char[j] = "[" then
  235.           bs = j
  236.           exit repeat
  237.         end if
  238.       end repeat
  239.       extra = tail.char[bs + 1..tail.char.count]
  240.       pContent = stripWhiteSpace(tail.char[1..bs - 1])
  241.     else
  242.       pContent = stripWhiteSpace(tail)
  243.     end if
  244.     if pType = "l" then
  245.       vt = 1
  246.     else
  247.       if pType = "f" then
  248.         vt = 2
  249.         pContent = pathJoin([node.itemPath, pContent])
  250.       else
  251.         if pType = "v" then
  252.           vt = 3
  253.           isVideo = 1
  254.           isVLC = baFindApp("mov")
  255.           if isVLC <> EMPTY then
  256.             if isVLC contains "vlc" then
  257.               vt = 3
  258.               vlcpath = isVLC
  259.               pContent = validatePathName(pathJoin([node.itemPath, pContent]))
  260.             else
  261.               if the platform contains "mac" then
  262.                 vt = 2
  263.                 pContent = validatePathName(pathJoin([node.itemPath, pContent]))
  264.               else
  265.                 vt = 2
  266.                 pContent = validatePathName(pathJoin([node.itemPath, stripFileName(pContent)]))
  267.               end if
  268.             end if
  269.           else
  270.             vt = 2
  271.             pContent = validatePathName(pathJoin([node.itemPath, stripFileName(pContent)]))
  272.           end if
  273.         else
  274.           if pType = "p" then
  275.             vt = 4
  276.             pContent = validatePathName(pathJoin([node.itemPath, pContent]))
  277.           end if
  278.         end if
  279.       end if
  280.     end if
  281.     node.contentButtons.append(createContentItem(pContent, vt, extra, isVideo))
  282.     isVideo = 0
  283.   end repeat
  284. end
  285.  
  286. on stripFileName aPath
  287.   st = 1
  288.   outPath = EMPTY
  289.   delimChars = ":\/"
  290.   if (aPath contains ":") or (aPath contains "/") or (aPath contains "\") then
  291.     repeat with dd = 1 to the number of chars in aPath
  292.       if delimChars contains aPath.char[dd] then
  293.         st = dd
  294.       end if
  295.     end repeat
  296.     outPath = aPath.char[1..st - 1]
  297.   end if
  298.   return outPath
  299. end
  300.  
  301. on parseFormattingInfo aTxt
  302.   greenStart = 0
  303.   i = 1
  304.   aTxt.fontSize = 14
  305.   aTxt.antialias = 1
  306.   aTxt.antiAliasThreshold = 1
  307.   aTxt.font = "WeddingSans Medium *"
  308.   aTxt.color = rgb(255, 255, 255)
  309.   repeat while i <= aTxt.char.count
  310.     if aTxt.char[i] = "<" then
  311.       greenStart = i
  312.     end if
  313.     if aTxt.char[i] = ">" then
  314.       if greenStart > 0 then
  315.         aTxt.char[greenStart..i].color = rgb(145, 181, 1)
  316.         delete aTxt.char[greenStart]
  317.         delete aTxt.char[i - 1]
  318.         greenStart = 0
  319.       end if
  320.     end if
  321.     i = i + 1
  322.   end repeat
  323. end
  324.  
  325. on gatherThumbnails aNode
  326.   if aNode.children.count > 0 then
  327.     repeat with i = 1 to aNode.children.count
  328.       if aNode.children[i].thumbnailMember = 0 then
  329.         thumbPath = pathJoin([aNode.children[i].itemPath, "thumb.jpg"])
  330.         if baFileExists(thumbPath) then
  331.           member(nextFreeThumbnailIndex, "thumbnails").importFileInto(thumbPath)
  332.           aNode.children[i].thumbnailMember = member(nextFreeThumbnailIndex, "thumbnails")
  333.           nextFreeThumbnailIndex = nextFreeThumbnailIndex + 1
  334.           next repeat
  335.         end if
  336.         aNode.children[i].thumbnailMember = defaultThumbnailMember
  337.       end if
  338.     end repeat
  339.   end if
  340. end
  341.  
  342. on loadSectionPage aNode
  343.   currentThumbStart = 1
  344.   gatherThumbnails(aNode)
  345.   showThumbnails(currentThumbStart, aNode)
  346.   currentSection = aNode
  347. end
  348.  
  349. on showThumbnails thumbstart, node
  350.   if node.children.count > 0 then
  351.     member("section_title").text = EMPTY
  352.     member("section_info").text = EMPTY
  353.     go(marker("main"))
  354.     baseSprite = 14
  355.     contentBackEnabled = 1
  356.     s = thumbstart
  357.     e = min(thumbstart + 5, node.children.count)
  358.     curSp = 1
  359.     repeat while s <= e
  360.       sendSprite(baseSprite, #setContentNode, node.children[s])
  361.       sprite(baseSprite + 2).member = node.children[s].thumbnailMember
  362.       sprite(baseSprite + 1).member.text = node.children[s].itemTitle
  363.       sprite(baseSprite).visible = 1
  364.       sprite(baseSprite + 1).visible = 1
  365.       sprite(baseSprite + 2).visible = 1
  366.       baseSprite = baseSprite + 3
  367.       s = s + 1
  368.     end repeat
  369.     sprite(7).member.text = node.itemTitle
  370.     gatherInfo(node)
  371.     sprite(8).member.text = string(node.infoText.text)
  372.     parseFormattingInfo(sprite(8).member)
  373.     backEnabled = 0
  374.     nextEnabled = 0
  375.     if thumbstart > 1 then
  376.       backEnabled = 1
  377.     end if
  378.     if (thumbstart + 5) < node.children.count then
  379.       nextEnabled = 1
  380.     end if
  381.     if (thumbstart + 5) > node.children.count then
  382.       diff = thumbstart + 5 - node.children.count
  383.       startHidingSp = 14 + (3 * (6 - diff))
  384.       repeat with i = 5 - diff to 5
  385.         sprite(startHidingSp).visible = 0
  386.         sprite(startHidingSp + 1).visible = 0
  387.         sprite(startHidingSp + 2).visible = 0
  388.         startHidingSp = startHidingSp + 3
  389.       end repeat
  390.     end if
  391.     tEnd = min(thumbstart + 5, node.children.count)
  392.     member("showing_txt").text = "Showing " & string(thumbstart) & "-" & string(tEnd) & " of " & string(node.children.count)
  393.     nums = "0123456789"
  394.     lastNum = 0
  395.     repeat with c = 8 to member("showing_txt").char.count
  396.       if member("showing_txt").char[c] = "f" then
  397.         exit repeat
  398.       end if
  399.       if nums contains member("showing_txt").char[c] then
  400.         lastNum = c
  401.       end if
  402.     end repeat
  403.     member("showing_txt").char[8..lastNum].color = rgb(255, 255, 255)
  404.     sprite(11).visible = 1
  405.     sprite(12).visible = 1
  406.     sprite(33).visible = 0
  407.   else
  408.     contentBackEnabled = 0
  409.     showContentPage(node)
  410.   end if
  411. end
  412.  
  413. on showContentPage aNode
  414.   showVLCLink = 0
  415.   if aNode.isWebLink = 0 then
  416.     member("product_title").text = EMPTY
  417.     member("product_info").text = EMPTY
  418.     repeat with k = 1 to 6
  419.       member("cbutton_" & k).text = EMPTY
  420.     end repeat
  421.     go(marker("content"))
  422.     sprite(32).visible = 0
  423.     gatherInfo(aNode)
  424.     member("product_title").text = aNode.itemTitle
  425.     if aNode.infoText <> 0 then
  426.       sprite(9).member = aNode.infoText
  427.     else
  428.       sprite(9).member.text = EMPTY
  429.     end if
  430.     sprite(10).member = aNode.imageMember
  431.     spBut = 19
  432.     repeat with i = spBut to spBut + 5
  433.       sprite(i).visible = 0
  434.     end repeat
  435.     s = spBut
  436.     lastBut = 5
  437.     if aNode.contentButtons.count > 5 then
  438.       lastBut = 5
  439.     else
  440.       lastBut = aNode.contentButtons.count
  441.     end if
  442.     lastBut = min(spBut + 5, lastBut)
  443.     repeat with i = 1 to aNode.contentButtons.count
  444.       sprite(s).visible = 1
  445.       sprite(s).myType = aNode.contentButtons[i].itemType
  446.       sprite(s).myLink = aNode.contentButtons[i].itemPath
  447.       if aNode.contentButtons[i].hasVideo = 1 then
  448.         showVLCLink = 1
  449.       end if
  450.       if aNode.contentButtons[i].extraTitle = EMPTY then
  451.         if aNode.contentButtons[i].itemType = 1 then
  452.           sprite(s).member.text = "+ Visit Website"
  453.         else
  454.           if aNode.contentButtons[i].itemType = 2 then
  455.             sprite(s).member.text = "+ Open Folder"
  456.           else
  457.             if aNode.contentButtons[i].itemType = 3 then
  458.               showVLCLink = 1
  459.               put aNode.contentButtons[i].itemPath
  460.               isVLC = baFindApp("mov")
  461.               if isVLC contains "vlc" then
  462.                 sprite(s).member.text = "+ Play Video in VLC"
  463.                 sprite(32).visible = 1
  464.               else
  465.                 sprite(s).member.text = "+ Open Folder"
  466.                 sprite(32).visible = 1
  467.               end if
  468.             end if
  469.           end if
  470.         end if
  471.       else
  472.         sprite(s).member.text = "+ " & aNode.contentButtons[i].extraTitle
  473.       end if
  474.       s = s - 1
  475.     end repeat
  476.     if aNode.itemTitle = "home" then
  477.       sprite(11).visible = 0
  478.       sprite(12).visible = 0
  479.     else
  480.       sprite(11).visible = 1
  481.       sprite(12).visible = 1
  482.     end if
  483.     if showVLCLink = 1 then
  484.       sprite(32).visible = 1
  485.     else
  486.       sprite(32).visible = 0
  487.     end if
  488.   else
  489.     gotoNetPage(aNode.itemPath)
  490.   end if
  491. end
  492.  
  493. on showInfoPopup txtPath, aTitle
  494.   put txtPath
  495.   if baFileExists(txtPath) then
  496.     infoPopup = window().new(pathJoin([interfacePath, "POPUP.dir"]))
  497.     infoPopup.open()
  498.     tell infoPopup
  499.       loadTextFile(txtPath)
  500.     end tell
  501.   end if
  502. end
  503.  
  504. on gatherContentItems aNode
  505.   content = []
  506. end
  507.  
  508. on createMenuNode itemTitle, itemPath, indexNum
  509.   retObject = [:]
  510.   retObject[#itemTitle] = itemTitle
  511.   retObject[#indexNum] = indexNum
  512.   retObject[#itemPath] = itemPath
  513.   retObject[#children] = []
  514.   retObject[#isWebLink] = 0
  515.   retObject[#imageMember] = 0
  516.   retObject[#thumbnailMember] = 0
  517.   retObject[#infoText] = 0
  518.   retObject[#contentButtons] = []
  519.   put itemPath
  520.   if itemPath.char[1] = "[" then
  521.     put itemPath
  522.     retObject[#isWebLink] = 1
  523.     retObject[#itemPath] = stripWhiteSpace(retObject.itemPath.char[2..retObject.itemPath.length - 1])
  524.   end if
  525.   return retObject
  526. end
  527.  
  528. on createContentItem itemPath, pType, extraTitle, isVideo
  529.   retObject = [:]
  530.   retObject[#itemPath] = itemPath
  531.   retObject[#itemType] = pType
  532.   retObject[#extraTitle] = extraTitle
  533.   retObject[#hasVideo] = isVideo
  534.   return retObject
  535. end
  536.  
  537. on stripWhiteSpace aString
  538.   repeat while aString.char[1] = SPACE
  539.     delete char 1 of aString
  540.   end repeat
  541.   repeat while aString.char[aString.length] = SPACE
  542.     delete char aString.length of aString
  543.   end repeat
  544.   return aString
  545. end
  546.  
  547. on hideGreenHilight
  548.   sprite(33).visible = 0
  549. end
  550.  
  551. on setGreenHilight _loch, _locv
  552.   sprite(33).locH = _loch
  553.   sprite(33).locV = _locv
  554.   sprite(33).visible = 1
  555. end
  556.  
  557. on validatePathName aPath
  558.   if the platform contains "mac" then
  559.     wrongChars = "\/"
  560.     rightChar = ":"
  561.   else
  562.     wrongChars = ":/"
  563.     rightChar = "\"
  564.   end if
  565.   put aPath
  566.   repeat with g = 1 to aPath.char.count
  567.     if (wrongChars contains aPath.char[g]) and (g > 2) then
  568.       outPath = outPath & rightChar
  569.       next repeat
  570.     end if
  571.     outPath = outPath & aPath.char[g]
  572.   end repeat
  573.   put outPath
  574.   return outPath
  575. end
  576.  
  577. on pathJoin itemList
  578.   retString = itemList[1]
  579.   numChars = retString.char.count
  580.   if retString.char[numChars] = delim then
  581.     delete char -30000 of retString
  582.   end if
  583.   repeat with i = 2 to itemList.count
  584.     fud = itemList[i]
  585.     if the last char in fud = delim then
  586.       delete char -30000 of fud
  587.     end if
  588.     retString = retString & delim & fud
  589.   end repeat
  590.   needsFinalDelim = 1
  591.   finalPathElement = itemList[itemList.count]
  592.   numChars = finalPathElement.char.count
  593.   repeat with i = 1 to numChars
  594.     if finalPathElement.char[i] = "." then
  595.       needsFinalDelim = 0
  596.       exit repeat
  597.     end if
  598.   end repeat
  599.   if the last char in finalPathElement = delim then
  600.     needsFinalDelim = 0
  601.   end if
  602.   if needsFinalDelim = 1 then
  603.     retString = retString & delim
  604.   end if
  605.   return retString
  606. end
  607.  
  608. on prepareMovie
  609.   __init__()
  610. end
  611.