commandBarComponent.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import * as React from "react";
  2. import { GlobalState } from '../globalState';
  3. import { CommandButtonComponent } from './commandButtonComponent';
  4. import { CommandDropdownComponent } from './commandDropdownComponent';
  5. import { Utilities } from '../tools/utilities';
  6. require("../scss/commandBar.scss");
  7. declare var Versions: any;
  8. interface ICommandBarComponentProps {
  9. globalState: GlobalState;
  10. }
  11. export class CommandBarComponent extends React.Component<ICommandBarComponentProps> {
  12. public constructor(props: ICommandBarComponentProps) {
  13. super(props);
  14. this.props.globalState.onLanguageChangedObservable.add(() => {
  15. this.forceUpdate();
  16. });
  17. }
  18. onPlay() {
  19. this.props.globalState.onRunRequiredObservable.notifyObservers();
  20. }
  21. onNew() {
  22. this.props.globalState.onNewRequiredObservable.notifyObservers();
  23. }
  24. onClear() {
  25. this.props.globalState.onClearRequiredObservable.notifyObservers();
  26. }
  27. onSave() {
  28. this.props.globalState.onSaveRequiredObservable.notifyObservers();
  29. }
  30. onDownload() {
  31. this.props.globalState.onDownloadRequiredObservable.notifyObservers();
  32. }
  33. onInspector() {
  34. this.props.globalState.onInspectorRequiredObservable.notifyObservers(!this.props.globalState.inspectorIsOpened);
  35. }
  36. onExamples() {
  37. this.props.globalState.onExamplesDisplayChangedObservable.notifyObservers();
  38. }
  39. public render() {
  40. let activeVersion = Utilities.ReadStringFromStore("version", "Latest");
  41. let activeEngineVersion = Utilities.ReadStringFromStore("engineVersion", "WebGL2");
  42. if (location.href.indexOf("webgpu") !== -1 && !!navigator.gpu) {
  43. activeEngineVersion = "WebGPU";
  44. }
  45. var versionOptions = Object.keys(Versions).map(key => {
  46. return {
  47. label: key,
  48. storeKey: "version",
  49. isActive: activeVersion === key,
  50. onClick: () => {
  51. Utilities.StoreStringToStore("version", key);
  52. window.location.reload();
  53. }
  54. }
  55. });
  56. var engineOptions = [
  57. {
  58. label: "WebGL2",
  59. storeKey: "engineVersion",
  60. isActive: activeEngineVersion === "WebGL2",
  61. onClick: () => {
  62. Utilities.StoreStringToStore("engineVersion", "WebGL2");
  63. window.location.reload();
  64. }
  65. },
  66. {
  67. label: "WebGL",
  68. storeKey: "engineVersion",
  69. isActive: activeEngineVersion === "WebGL",
  70. onClick: () => {
  71. Utilities.StoreStringToStore("engineVersion", "WebGL");
  72. window.location.reload();
  73. }
  74. }
  75. ];
  76. if (!!navigator.gpu) {
  77. engineOptions.splice(0,0, {
  78. label: "WebGPU",
  79. storeKey: "engineVersion",
  80. isActive: activeEngineVersion === "WebGPU",
  81. onClick: () => {
  82. Utilities.StoreStringToStore("engineVersion", "WebGPU");
  83. window.location.reload();
  84. }
  85. });
  86. }
  87. return (
  88. <div className={"commands " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
  89. <div className="commands-left">
  90. <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" shortcut="Alt+Enter" isActive={true} onClick={()=> this.onPlay()}/>
  91. <CommandButtonComponent globalState={this.props.globalState} tooltip="Save" icon="save" shortcut="Ctrl+S" isActive={false} onClick={()=> this.onSave()}/>
  92. <CommandButtonComponent globalState={this.props.globalState} tooltip="Inspector" icon="inspector" isActive={false} onClick={()=> this.onInspector()}/>
  93. <CommandButtonComponent globalState={this.props.globalState} tooltip="Download" icon="download" shortcut="Shift+Ctrl+S"isActive={false} onClick={()=> this.onDownload()}/>
  94. <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
  95. <CommandButtonComponent globalState={this.props.globalState} tooltip="Clear code" icon="clear" isActive={false} onClick={()=> this.onClear()}/>
  96. <CommandDropdownComponent globalState={this.props.globalState} icon="options" tooltip="Options" items={[
  97. {
  98. label: "Theme",
  99. storeKey: "theme",
  100. defaultValue: "Light",
  101. subItems: [
  102. "Light",
  103. "Dark"
  104. ],
  105. onClick: () => {
  106. this.props.globalState.onThemeChangedObservable.notifyObservers();
  107. }
  108. },
  109. {
  110. label: "Font size",
  111. storeKey: "font-size",
  112. defaultValue: "14",
  113. subItems: [
  114. "12",
  115. "14",
  116. "16",
  117. "18",
  118. "20",
  119. "22",
  120. "24",
  121. "26",
  122. "28",
  123. "30",
  124. ],
  125. onClick: () => {
  126. this.props.globalState.onFontSizeChangedObservable.notifyObservers();
  127. }
  128. },
  129. {
  130. label: "Safe mode",
  131. storeKey: "safe-mode",
  132. defaultValue: false,
  133. onCheck: () => {}
  134. },
  135. {
  136. label: "CTRL+S to save",
  137. storeKey: "ctrl-s-to-save",
  138. defaultValue: true,
  139. onCheck: () => {}
  140. },
  141. {
  142. label: "editor",
  143. storeKey: "editor",
  144. defaultValue: true,
  145. onCheck: (value) => {this.props.globalState.onEditorDisplayChangedObservable.notifyObservers(value)}
  146. }, {
  147. label: "minimap",
  148. storeKey: "minimap",
  149. defaultValue: true,
  150. onCheck: (value) => {this.props.globalState.onMinimapChangedObservable.notifyObservers(value)}
  151. }, {
  152. label: "fullscreen",
  153. onClick: () => {this.props.globalState.onFullcreenRequiredObservable.notifyObservers()}
  154. }, {
  155. label: "fullscreen editor",
  156. onClick: () => {this.props.globalState.onEditorFullcreenRequiredObservable.notifyObservers()}
  157. }, {
  158. label: "format code",
  159. onClick: () => {this.props.globalState.onFormatCodeRequiredObservable.notifyObservers()}
  160. },
  161. {
  162. label: "metadata",
  163. onClick: () => {this.props.globalState.onDisplayMetadataObservable.notifyObservers(true)}
  164. },
  165. {
  166. label: "QR code",
  167. onClick: () => {this.props.globalState.onQRCodeRequiredObservable.notifyObservers(true)}
  168. },
  169. {
  170. label: "Load Unity Toolkit",
  171. storeKey: "unity-toolkit",
  172. defaultValue: false,
  173. onCheck: () => {}
  174. },
  175. ]}/>
  176. </div>
  177. <div className="commands-right">
  178. <CommandDropdownComponent globalState={this.props.globalState} defaultValue={activeEngineVersion} tooltip="Engine" toRight={true} items={engineOptions} />
  179. <CommandDropdownComponent globalState={this.props.globalState} defaultValue={activeVersion} tooltip="Versions" toRight={true} items={versionOptions} />
  180. <CommandButtonComponent globalState={this.props.globalState} tooltip="Examples" icon="examples" onClick={()=> this.onExamples()} isActive={false}/>
  181. </div>
  182. </div>
  183. );
  184. }
  185. }