2
0

sample_html.tpl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!-- saved from url=(0013)about:internet -->
  2. <!-- see, http://technet.microsoft.com/en-us/library/bb457150.aspx#EHAA for how, why, this works for local controls -->
  3. <!-- Please note that the saved from line must end in CR LF. Some HTML editors only insert a LF. (Thanks Microsoft) -->
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta name="description" content="Web Game Template" />
  9. <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  10. <link rel="stylesheet" href="styles.css" type="text/css" />
  11. <script type="text/javascript" language="javascript">
  12. // Relative path on web server to installer
  13. var installerPath = "MyGameInstaller"
  14. ua = navigator.userAgent.toLowerCase();
  15. if( ua.indexOf('os x') != -1 || ua.indexOf('osx') != -1)
  16. installerPath += ".pkg";
  17. else
  18. installerPath += ".exe";
  19. // Firefox/Chrome/Safari
  20. var mimeType = "application/__MIMETYPE__";
  21. // Internet Explorer
  22. var projId = "__PROJID__";
  23. var clsId = "__CLSID__";
  24. var pluginInstalled = false;
  25. var minimumPluginVersion = 1.0;
  26. // You can set this to true if you want the page to automatically reload
  27. // once the plugin is installed. However, this can be better handled by
  28. // the installer process in most cases (by opening up web page at end of
  29. // install process, setting up desktop/start menu shortcuts to launch web page
  30. // etc
  31. var autoReload = false;
  32. // Default client screen (overridden below from actual browser window)
  33. var cscreenW = 800;
  34. var cscreenH = 600;
  35. function getClientScreenSize() {
  36. if( typeof( window.innerWidth ) == 'number' ) {
  37. //Non-IE
  38. cscreenW = window.innerWidth;
  39. cscreenH = window.innerHeight;
  40. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  41. //IE 6+ in 'standards compliant mode'
  42. cscreenW = document.documentElement.clientWidth;
  43. cscreenH = document.documentElement.clientHeight;
  44. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  45. //IE 4 compatible
  46. cscreenW = document.body.clientWidth;
  47. cscreenH = document.body.clientHeight;
  48. }
  49. }
  50. function gameObjectResize(){
  51. if (!pluginInstalled)
  52. return;
  53. getClientScreenSize();
  54. var aspectRatio = 800.0/600.0;
  55. var w = cscreenW - 50;
  56. var h = cscreenH - 125;
  57. if( w/h > aspectRatio )
  58. w = h*aspectRatio;
  59. else
  60. h = w/aspectRatio;
  61. var minW = 640;
  62. if( w < minW ){
  63. w = minW;
  64. h = w/aspectRatio;
  65. }
  66. $('#gameobject').width( Math.floor(w) );
  67. $('#gameobject').height( Math.floor(h) );
  68. $('#main').width( Math.floor(w + 2) );
  69. var mygame = document.getElementById("MyGame");
  70. mygame.width = Math.floor(w);
  71. mygame.height = Math.floor(h);
  72. }
  73. $(window).resize( gameObjectResize );
  74. $(document).ready(function(){
  75. if (pluginInstalled)
  76. {
  77. var mygame = document.getElementById("MyGame");
  78. // Let the game object know the page is all loaded
  79. // This is important to register any TorqueScript <-> JavaScript callbacks, etc
  80. mygame.startup();
  81. // Export the TorqueScript -> JavaScript bridge test function
  82. mygame.exportFunction("bridgeCallback",3);
  83. // Enable the bridge test button now that we're all set
  84. var bridgetest = document.getElementById("bridgetest");
  85. bridgetest.disabled = false;
  86. gameObjectResize();
  87. }
  88. });
  89. // Returns the version of Internet Explorer
  90. // or -1 for non-IE browser
  91. // or -2 for 64 bit IE browser
  92. // (indicating the use of another browser).
  93. function getInternetExplorerVersion()
  94. {
  95. var rv = -1; // Return value for non-IE browser
  96. if (navigator.appName == 'Microsoft Internet Explorer')
  97. {
  98. var ua = navigator.userAgent;
  99. if (ua.search("Win64") != -1 || ua.search("x64") != -1)
  100. return -2; // Return value for IE 64 bit
  101. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  102. if (re.exec(ua) != null)
  103. rv = parseFloat( RegExp.$1 );
  104. }
  105. return rv;
  106. }
  107. // Checks whether the NPPlugin is installed (under Firefox/Chrome/Safari)
  108. function nppluginIsInstalled() {
  109. if (!navigator || !navigator.mimeTypes) {
  110. return -1;
  111. }
  112. var mt = navigator.mimeTypes[mimeType];
  113. if (mt && mt.enabledPlugin)
  114. {
  115. var desc = mt.enabledPlugin.description;
  116. var descArray = desc.split(" ");
  117. var version = descArray[descArray.length - 1]
  118. return Number(version);
  119. }
  120. return -1;
  121. }
  122. function nppluginReload () {
  123. navigator.plugins.refresh();
  124. if (nppluginIsInstalled() < 0)
  125. window.location.reload();
  126. setTimeout('nppluginReload()', 500);
  127. }
  128. function activexReload () {
  129. if (activexIsInstalled() < 0)
  130. window.location.reload();
  131. setTimeout('activexReload()', 500);
  132. }
  133. function onTestBridge()
  134. {
  135. var mygame = document.getElementById("MyGame");
  136. // set/get console variables test
  137. // variables are automatically stored Torque 3D side in the Javascript:: namespace
  138. // for security reasons.
  139. mygame.setVariable("$TestBridge", 42);
  140. var everything = mygame.getVariable("$TestBridge");
  141. // this tests bidirectional calling of JavaScript <-> TorqueScript including arguments and return values
  142. // note that testJavaScriptBridge must be specified in webConfig.h as a secure function
  143. var result = mygame.callScript("testJavaScriptBridge('one', 'two', 'three');");
  144. if (parseInt(everything) != 42)
  145. alert("JavaScript <-> TorqueScript: Failed, get/set console variable doesn't match");
  146. else if (result == "0")
  147. alert("JavaScript <-> TorqueScript: All Tests Passed!");
  148. else if (result == "1")
  149. alert("JavaScript -> TorqueScript: Failed, incorrect number of arguments");
  150. else if (result == "2")
  151. alert("JavaScript -> TorqueScript: Failed, incorrect argument");
  152. else if (result == "3")
  153. alert("TorqueScript -> JavaScript: Failed, incorrect return");
  154. else
  155. alert("JavaScript -> TorqueScript: Failed, unknown error");
  156. }
  157. // Called from TorqueScript console -> JavaScript during bridge test
  158. function bridgeCallback(arg1, arg2, arg3)
  159. {
  160. if (arg1 != "one" || arg2 != "two" || arg3 != "three")
  161. {
  162. alert("TorqueScript -> JavaScript: Failed, incorrect argument");
  163. return "0";
  164. }
  165. return "42";
  166. }
  167. </script>
  168. <script language='VBScript'>
  169. function activexIsInstalled()
  170. on error resume next
  171. dim gameControl
  172. dim version
  173. version = -1
  174. set gameControl = CreateObject(projId)
  175. if IsObject(gameControl) then
  176. version = CDbl(gameControl.getVariable("$version"))
  177. end if
  178. activexIsInstalled = version
  179. end function
  180. </script>
  181. </head>
  182. <body>
  183. <img id = "torqueLogo" src = "./torque3D_logo.jpg">
  184. <div id="main">
  185. <div style = "height: 20px;"></div>
  186. <center>Web Game Template</center>
  187. <div id="gameobject">
  188. <script type="text/javascript" language="javascript">
  189. // ActiveX
  190. var ie = getInternetExplorerVersion();
  191. if ( ie == -2) {
  192. document.write('<center><h3>This plugin is not currently supported on Internet Explorer 64 bit<br><br>Please use Internet Explorer 32 bit to access this site.</h3><centre>');
  193. }
  194. else if ( ie != -1) {
  195. if (activexIsInstalled() >= minimumPluginVersion) {
  196. pluginInstalled = true;
  197. document.write('<OBJECT ID="MyGame" CLASSID="CLSID:'+clsId+'" WIDTH="100%" HEIGHT="100%"></OBJECT>');
  198. }
  199. else {
  200. document.write('<center><a href="'+installerPath+'"><img src="getplugin.jpg" /></a></center>');
  201. if (autoReload)
  202. activexReload();
  203. }
  204. }
  205. // Firefox/Chrome/Safari
  206. else {
  207. //we do an initial refresh in case the plugin information has changed (new DLL location, newly installed, etc)
  208. navigator.plugins.refresh();
  209. if (nppluginIsInstalled() >= minimumPluginVersion) {
  210. pluginInstalled = true;
  211. document.write('<object id="MyGame" type="'+mimeType+'" width="100% height="100%" ></object>');
  212. }
  213. else {
  214. document.write('<center><a href="'+installerPath+'"><img src="getplugin.jpg" /></a></center>');
  215. if (autoReload)
  216. nppluginReload();
  217. }
  218. }
  219. </script>
  220. </div>
  221. <center>(Press ESC to show the mouse cursor if hidden)</center>
  222. <center><button id="bridgetest" disabled="true" onclick="onTestBridge();">Test JavaScript <-> TorqueScript Bridge</button></center>
  223. </div>
  224. </body>
  225. </html>