commandBarComponent.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. var versionOptions = Object.keys(Versions).map(key => {
  43. return {
  44. label: key,
  45. storeKey: "version",
  46. isActive: activeVersion === key,
  47. onClick: () => {
  48. Utilities.StoreStringToStore("version", key);
  49. window.location.reload();
  50. }
  51. }
  52. });
  53. var engineOptions = [
  54. {
  55. label: "WebGL2",
  56. storeKey: "engineVersion",
  57. isActive: activeEngineVersion === "WebGL2",
  58. onClick: () => {
  59. Utilities.StoreStringToStore("engineVersion", "WebGL2");
  60. window.location.reload();
  61. }
  62. },
  63. {
  64. label: "WebGL",
  65. storeKey: "engineVersion",
  66. isActive: activeEngineVersion === "WebGL",
  67. onClick: () => {
  68. Utilities.StoreStringToStore("engineVersion", "WebGL");
  69. window.location.reload();
  70. }
  71. }
  72. ];
  73. if (!!navigator.gpu) {
  74. engineOptions.splice(0,0, {
  75. label: "WebGPU",
  76. storeKey: "engineVersion",
  77. isActive: activeEngineVersion === "WebGPU",
  78. onClick: () => {
  79. Utilities.StoreStringToStore("engineVersion", "WebGPU");
  80. window.location.reload();
  81. }
  82. });
  83. }
  84. return (
  85. <div className={"commands " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
  86. <div className="commands-left">
  87. <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" shortcut="Alt+Enter" isActive={true} onClick={()=> this.onPlay()}/>
  88. <CommandButtonComponent globalState={this.props.globalState} tooltip="Save" icon="save" shortcut="Ctrl+S" isActive={false} onClick={()=> this.onSave()}/>
  89. <CommandButtonComponent globalState={this.props.globalState} tooltip="Inspector" icon="inspector" isActive={false} onClick={()=> this.onInspector()}/>
  90. <CommandButtonComponent globalState={this.props.globalState} tooltip="Download" icon="download" shortcut="Shift+Ctrl+S"isActive={false} onClick={()=> this.onDownload()}/>
  91. <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
  92. <CommandButtonComponent globalState={this.props.globalState} tooltip="Clear code" icon="clear" isActive={false} onClick={()=> this.onClear()}/>
  93. <CommandDropdownComponent globalState={this.props.globalState} icon="options" tooltip="Options" items={[
  94. {
  95. label: "Theme",
  96. storeKey: "theme",
  97. defaultValue: "Light",
  98. subItems: [
  99. "Light",
  100. "Dark"
  101. ],
  102. onClick: () => {
  103. this.props.globalState.onThemeChangedObservable.notifyObservers();
  104. }
  105. },
  106. {
  107. label: "Font size",
  108. storeKey: "font-size",
  109. defaultValue: "14",
  110. subItems: [
  111. "12",
  112. "14",
  113. "16",
  114. "18",
  115. "20",
  116. "22",
  117. "24",
  118. "26",
  119. "28",
  120. "30",
  121. ],
  122. onClick: () => {
  123. this.props.globalState.onFontSizeChangedObservable.notifyObservers();
  124. }
  125. },
  126. {
  127. label: "Safe mode",
  128. storeKey: "safe-mode",
  129. defaultValue: false,
  130. onCheck: () => {}
  131. },
  132. {
  133. label: "CTRL+S to save",
  134. storeKey: "ctrl-s-to-save",
  135. defaultValue: true,
  136. onCheck: () => {}
  137. },
  138. {
  139. label: "editor",
  140. storeKey: "editor",
  141. defaultValue: true,
  142. onCheck: (value) => {this.props.globalState.onEditorDisplayChangedObservable.notifyObservers(value)}
  143. }, {
  144. label: "minimap",
  145. storeKey: "minimap",
  146. defaultValue: true,
  147. onCheck: (value) => {this.props.globalState.onMinimapChangedObservable.notifyObservers(value)}
  148. }, {
  149. label: "fullscreen",
  150. onClick: () => {this.props.globalState.onFullcreenRequiredObservable.notifyObservers()}
  151. }, {
  152. label: "fullscreen editor",
  153. onClick: () => {this.props.globalState.onEditorFullcreenRequiredObservable.notifyObservers()}
  154. }, {
  155. label: "format code",
  156. onClick: () => {this.props.globalState.onFormatCodeRequiredObservable.notifyObservers()}
  157. },
  158. {
  159. label: "metadata",
  160. onClick: () => {this.props.globalState.onDisplayMetadataObservable.notifyObservers(true)}
  161. },
  162. {
  163. label: "QR code",
  164. onClick: () => {this.props.globalState.onQRCodeRequiredObservable.notifyObservers(true)}
  165. },
  166. {
  167. label: "Load Unity Toolkit",
  168. storeKey: "unity-toolkit",
  169. defaultValue: false,
  170. onCheck: () => {}
  171. },
  172. ]}/>
  173. </div>
  174. <div className="commands-right">
  175. <CommandDropdownComponent globalState={this.props.globalState} defaultValue={activeEngineVersion} tooltip="Engine" toRight={true} items={engineOptions} />
  176. <CommandDropdownComponent globalState={this.props.globalState} defaultValue={activeVersion} tooltip="Versions" toRight={true} items={versionOptions} />
  177. <CommandButtonComponent globalState={this.props.globalState} tooltip="Examples" icon="examples" onClick={()=> this.onExamples()} isActive={false}/>
  178. </div>
  179. </div>
  180. );
  181. }
  182. }