level_editor.vala 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. /*
  2. * Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
  4. */
  5. using Gdk; // Pixbuf
  6. using Gee;
  7. using Gtk;
  8. namespace Crown
  9. {
  10. public enum ToolType
  11. {
  12. PLACE,
  13. MOVE,
  14. ROTATE,
  15. SCALE
  16. }
  17. public enum SnapMode
  18. {
  19. RELATIVE,
  20. ABSOLUTE
  21. }
  22. public enum ReferenceSystem
  23. {
  24. LOCAL,
  25. WORLD
  26. }
  27. public class LevelEditor : Gtk.Window
  28. {
  29. private Project _project;
  30. // Editor state
  31. private double _grid_size;
  32. private double _rotation_snap;
  33. private bool _show_grid;
  34. private bool _snap_to_grid;
  35. private bool _debug_render_world;
  36. private bool _debug_physics_world;
  37. private ToolType _tool_type;
  38. private SnapMode _snap_mode;
  39. private ReferenceSystem _reference_system;
  40. // Engine connections
  41. private GLib.Subprocess _compiler_process;
  42. private GLib.Subprocess _engine_process;
  43. private GLib.Subprocess _game_process;
  44. private ConsoleClient _compiler;
  45. private ConsoleClient _engine;
  46. // Level data
  47. private Database _db;
  48. private Level _level;
  49. private string _level_filename;
  50. private ResourceCompiler _resource_compiler;
  51. // Widgets
  52. private StartingCompiler _starting_compiler;
  53. private ConsoleView _console_view;
  54. private EngineView _engine_view;
  55. private LevelTreeView _level_treeview;
  56. private LevelLayersTreeView _level_layers_treeview;
  57. private PropertiesView _properties_view;
  58. /*
  59. private GraphStore _graph_store;
  60. private GraphView _graph_view;
  61. */
  62. private PreferencesDialog _preferences_dialog;
  63. private Gtk.Alignment _alignment_engine;
  64. private Gtk.Alignment _alignment_level_tree_view;
  65. private Gtk.Alignment _alignment_properties_view;
  66. private Gtk.ActionGroup _action_group;
  67. private Gtk.UIManager _ui_manager;
  68. private Gtk.Toolbar _toolbar;
  69. private Gtk.Paned _pane_left;
  70. private Gtk.Paned _pane_right;
  71. private Gtk.Notebook _notebook_left;
  72. private Gtk.Notebook _notebook_right;
  73. private Gtk.Box _vbox;
  74. private Gtk.FileFilter _file_filter;
  75. private ResourceBrowser _resource_browser;
  76. const Gtk.ActionEntry[] action_entries =
  77. {
  78. { "menu-file", null, "_File", null, null, null },
  79. { "new", null, "New", "<ctrl>N", null, on_new },
  80. { "open", null, "Open...", "<ctrl>O", null, on_open },
  81. { "save", null, "Save", "<ctrl>S", null, on_save },
  82. { "save-as", null, "Save As...", "<shift><ctrl>S", null, on_save_as },
  83. { "import", null, "Import", null, null, null },
  84. { "import-sprites", null, "Sprites...", null, null, on_import_sprites },
  85. { "import-meshes", null, "Meshes...", null, null, on_import_meshes },
  86. { "import-sounds", null, "Sounds...", null, null, on_import_sounds },
  87. { "import-textures", null, "Textures...", null, null, on_import_textures },
  88. { "preferences", null, "Preferences", null, null, on_preferences },
  89. { "quit", null, "Quit", "<ctrl>Q", null, on_quit },
  90. { "menu-edit", null, "_Edit", null, null, null },
  91. { "undo", null, "Undo", "<ctrl>Z", null, on_undo },
  92. { "redo", null, "Redo", "<shift><ctrl>Z", null, on_redo },
  93. { "duplicate", null, "Duplicate", "<ctrl>D", null, on_duplicate },
  94. { "delete", null, "Delete", "<ctrl>K", null, on_delete },
  95. { "menu-grid", null, "Grid", null, null, null },
  96. { "grid-custom", null, "Custom", "G", null, on_custom_grid },
  97. { "menu-rotation-snap", null, "Rotation Snap", null, null, null },
  98. { "rotation-snap-custom", null, "Custom", "H", null, on_rotation_snap },
  99. { "menu-create", null, "Create", null, null, null },
  100. { "menu-primitives", null, "Primitives", null, null, null },
  101. { "primitive-cube", null, "Cube", null, null, on_create_cube },
  102. { "primitive-sphere", null, "Sphere", null, null, on_create_sphere },
  103. { "primitive-cone", null, "Cone", null, null, on_create_cone },
  104. { "primitive-cylinder", null, "Cylinder", null, null, on_create_cylinder },
  105. { "primitive-plane", null, "Plane", null, null, on_create_plane },
  106. { "camera", null, "Camera", null, null, on_create_camera },
  107. { "light", null, "Light", null, null, on_create_light },
  108. { "sound-source", null, "Sound Source", null, null, on_create_sound_source },
  109. { "menu-engine", null, "En_gine", null, null, null },
  110. { "menu-view", null, "View", null, null, null },
  111. { "resource-browser", null, "Resource Browser", "<ctrl>P", null, on_resource_browser },
  112. { "restart", null, "_Restart", null, null, on_engine_restart },
  113. { "reload-lua", null, "Reload Lua", "F7", null, on_reload_lua },
  114. { "menu-run", null, "_Run", null, null, null },
  115. { "game-run", "run", "Run Game", "F5", null, on_run_game },
  116. { "menu-help", null, "Help", null, null, null },
  117. { "manual", null, "Manual", "F1", null, on_manual },
  118. { "report-issue", null, "Report an Issue", null, null, on_report_issue },
  119. { "open-last-log", null, "Open last.log", null, null, on_open_last_log },
  120. { "about", null, "About", null, null, on_about }
  121. };
  122. const Gtk.RadioActionEntry[] grid_entries =
  123. {
  124. { "grid-0.1", null, "0.1m", null, null, 10 },
  125. { "grid-0.2", null, "0.2m", null, null, 20 },
  126. { "grid-0.5", null, "0.5m", null, null, 50 },
  127. { "grid-1", null, "1m", null, null, 100 },
  128. { "grid-2", null, "2m", null, null, 200 },
  129. { "grid-5", null, "5m", null, null, 500 }
  130. };
  131. const RadioActionEntry[] rotation_snap_entries =
  132. {
  133. { "rotation-snap-1", null, "1°", null, null, 1 },
  134. { "rotation-snap-15", null, "15°", null, null, 15 },
  135. { "rotation-snap-30", null, "30°", null, null, 30 },
  136. { "rotation-snap-45", null, "45°", null, null, 45 },
  137. { "rotation-snap-90", null, "90°", null, null, 90 },
  138. { "rotation-snap-180", null, "180°", null, null, 180 }
  139. };
  140. const RadioActionEntry[] tool_entries =
  141. {
  142. { "place", "tool-place", "Place", "Q", "Place", (int)ToolType.PLACE },
  143. { "move", "tool-move", "Move", "W", "Move", (int)ToolType.MOVE },
  144. { "rotate", "tool-rotate", "Rotate", "E", "Rotate", (int)ToolType.ROTATE },
  145. { "scale", "tool-scale", "Scale", "R", "Scale", (int)ToolType.SCALE }
  146. };
  147. const RadioActionEntry[] snap_mode_entries =
  148. {
  149. { "snap-relative", "reference-local", "Relative Snap", null, "Relative Snap", (int)SnapMode.RELATIVE },
  150. { "snap-absolute", "reference-world", "Absolute Snap", null, "Absolute Snap", (int)SnapMode.ABSOLUTE }
  151. };
  152. const RadioActionEntry[] reference_system_entries =
  153. {
  154. { "reference-system-local", "axis-local", "Local Axis", null, "Local Axis", (int)ReferenceSystem.LOCAL },
  155. { "reference-system-world", "axis-world", "World Axis", null, "World Axis", (int)ReferenceSystem.WORLD }
  156. };
  157. const ToggleActionEntry[] snap_to_entries =
  158. {
  159. { "snap-to-grid", "snap-to-grid", "Snap To Grid", "<ctrl>U", "Snap To Grid", on_snap_to_grid, true },
  160. { "grid-show", null, "Show Grid", null, "Show Grid", on_show_grid, true }
  161. };
  162. const ToggleActionEntry[] view_entries =
  163. {
  164. { "debug-render-world", null, "Debug Render World", null, null, on_debug_render_world, false },
  165. { "debug-physics-world", null, "Debug Physics World", null, null, on_debug_physics_world, false }
  166. };
  167. public LevelEditor(Project project)
  168. {
  169. this.title = "Level Editor";
  170. _project = project;
  171. // Editor state
  172. _grid_size = 1.0;
  173. _rotation_snap = 45.0;
  174. _show_grid = true;
  175. _snap_to_grid = true;
  176. _debug_render_world = false;
  177. _debug_physics_world = false;
  178. _tool_type = ToolType.MOVE;
  179. _snap_mode = SnapMode.RELATIVE;
  180. _reference_system = ReferenceSystem.LOCAL;
  181. // Engine connections
  182. _compiler_process = null;
  183. _engine_process = null;
  184. _game_process = null;
  185. _compiler = new ConsoleClient();
  186. _compiler.connected.connect(on_compiler_connected);
  187. _compiler.disconnected.connect(on_compiler_disconnected);
  188. _compiler.message_received.connect(on_message_received);
  189. _engine = new ConsoleClient();
  190. _engine.connected.connect(on_engine_connected);
  191. _engine.disconnected.connect(on_engine_disconnected);
  192. _engine.message_received.connect(on_message_received);
  193. // Level data
  194. _db = new Database();
  195. _level = new Level(_db, _engine, _project.source_dir(), _project.toolchain_dir());
  196. _level_filename = null;
  197. _resource_compiler = new ResourceCompiler(_compiler);
  198. // Widgets
  199. _console_view = new ConsoleView(_engine);
  200. _level_treeview = new LevelTreeView(_db, _level);
  201. _level_layers_treeview = new LevelLayersTreeView(_db, _level);
  202. _properties_view = new PropertiesView(_level);
  203. /*
  204. _graph_store = new GraphStore();
  205. _graph_view = new GraphView(_graph_store);
  206. */
  207. _starting_compiler = new StartingCompiler();
  208. _alignment_engine = new Gtk.Alignment(0, 0, 1, 1);
  209. _alignment_level_tree_view = new Gtk.Alignment(0, 0, 1, 1);
  210. _alignment_properties_view = new Gtk.Alignment(0, 0, 1, 1);
  211. _alignment_engine.add(_starting_compiler);
  212. _alignment_level_tree_view.add(_starting_compiler);
  213. _alignment_properties_view.add(_starting_compiler);
  214. start_compiler();
  215. try
  216. {
  217. Gtk.IconTheme.add_builtin_icon("tool-place", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/tool-place.png"));
  218. Gtk.IconTheme.add_builtin_icon("tool-move", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/tool-move.png"));
  219. Gtk.IconTheme.add_builtin_icon("tool-rotate", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/tool-rotate.png"));
  220. Gtk.IconTheme.add_builtin_icon("tool-scale", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/tool-scale.png"));
  221. Gtk.IconTheme.add_builtin_icon("axis-local", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/axis-local.png"));
  222. Gtk.IconTheme.add_builtin_icon("axis-world", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/axis-world.png"));
  223. Gtk.IconTheme.add_builtin_icon("snap-to-grid", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/snap-to-grid.png"));
  224. Gtk.IconTheme.add_builtin_icon("reference-local", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/reference-local.png"));
  225. Gtk.IconTheme.add_builtin_icon("reference-world", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/reference-world.png"));
  226. Gtk.IconTheme.add_builtin_icon("run", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/run.png"));
  227. Gtk.IconTheme.add_builtin_icon("level-tree", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/level-tree.png"));
  228. Gtk.IconTheme.add_builtin_icon("level-layers", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/level-layers.png"));
  229. Gtk.IconTheme.add_builtin_icon("layer-visible", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/layer-visible.png"));
  230. Gtk.IconTheme.add_builtin_icon("layer-locked", 16, new Pixbuf.from_resource("/org/pepper/icons/theme/layer-locked.png"));
  231. }
  232. catch (Error e)
  233. {
  234. stderr.printf(e.message);
  235. }
  236. _action_group = new Gtk.ActionGroup("group");
  237. _action_group.add_actions(action_entries, this);
  238. _action_group.add_radio_actions(grid_entries, (int)(_grid_size*100.0), this.on_grid_changed);
  239. _action_group.add_radio_actions(rotation_snap_entries, (int)_rotation_snap, this.on_rotation_snap_changed);
  240. _action_group.add_radio_actions(tool_entries, (int)_tool_type, on_tool_changed);
  241. _action_group.add_radio_actions(snap_mode_entries, (int)_snap_mode, on_snap_mode_changed);
  242. _action_group.add_radio_actions(reference_system_entries, (int)_reference_system, on_reference_system_changed);
  243. _action_group.add_toggle_actions(snap_to_entries, this);
  244. _action_group.add_toggle_actions(view_entries, this);
  245. _ui_manager = new UIManager();
  246. try
  247. {
  248. _ui_manager.add_ui_from_resource("/org/pepper/level_editor_menu.xml");
  249. _ui_manager.insert_action_group(_action_group, 0);
  250. add_accel_group(_ui_manager.get_accel_group());
  251. }
  252. catch (Error e)
  253. {
  254. error(e.message);
  255. }
  256. _toolbar = _ui_manager.get_widget("/toolbar") as Toolbar;
  257. _toolbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR);
  258. _toolbar.set_style(Gtk.ToolbarStyle.ICONS);
  259. _pane_left = new Gtk.Paned(Gtk.Orientation.VERTICAL);
  260. _pane_left.pack1(_alignment_engine, true, true);
  261. _pane_left.pack2(_console_view, true, true);
  262. Gtk.Box vb = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
  263. vb.pack_start(_toolbar, false, false, 0);
  264. vb.pack_start(_pane_left, true, true, 0);
  265. _notebook_right = new Notebook();
  266. _notebook_right.show_border = false;
  267. _notebook_right.append_page(_level_treeview, new Gtk.Image.from_icon_name("level-tree", IconSize.SMALL_TOOLBAR));
  268. _notebook_right.append_page(_level_layers_treeview, new Gtk.Image.from_icon_name("level-layers", IconSize.SMALL_TOOLBAR));
  269. Gtk.Paned rb = new Gtk.Paned(Gtk.Orientation.VERTICAL);
  270. rb.pack1(_notebook_right, true, true);
  271. rb.pack2(_alignment_properties_view, true, true);
  272. _pane_right = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
  273. _pane_right.pack1(vb, true, false);
  274. _pane_right.pack2(rb, true, false);
  275. _notebook_left = new Notebook();
  276. _notebook_left.show_border = false;
  277. _notebook_left.append_page(_pane_right, new Gtk.Label("Level"));
  278. /*
  279. _notebook_left.append_page(_graph_view, new Gtk.Label("Nodes"));
  280. */
  281. MenuBar menu = (MenuBar)_ui_manager.get_widget("/menubar");
  282. _vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
  283. _vbox.pack_start(menu, false, false, 0);
  284. _vbox.pack_start(_notebook_left, true, true, 0);
  285. _file_filter = new FileFilter();
  286. _file_filter.set_filter_name("Level (*.level)");
  287. _file_filter.add_pattern("*.level");
  288. _resource_browser = new ResourceBrowser(_project);
  289. _resource_browser.relative_to = _toolbar;
  290. _resource_browser.resource_selected.connect(on_resource_browser_resource_selected);
  291. _resource_browser.delete_event.connect(() => { _resource_browser.hide(); return true; });
  292. _resource_browser.modal = true;
  293. // Save level once every 5 minutes.
  294. GLib.Timeout.add_seconds(5*3600, save_timeout);
  295. this.destroy.connect(this.on_destroy);
  296. this.delete_event.connect(this.on_delete_event);
  297. this.key_press_event.connect(this.on_key_press);
  298. this.key_release_event.connect(this.on_key_release);
  299. this.add(_vbox);
  300. this.maximize();
  301. this.show_all();
  302. }
  303. private bool on_key_press(Gdk.EventKey ev)
  304. {
  305. if (ev.keyval == Gdk.Key.Control_L)
  306. _engine.send_script(LevelEditorApi.key_down("left_ctrl"));
  307. else if (ev.keyval == Gdk.Key.Shift_L)
  308. _engine.send_script(LevelEditorApi.key_down("left_shift"));
  309. return false;
  310. }
  311. private bool on_key_release(Gdk.EventKey ev)
  312. {
  313. if (ev.keyval == Gdk.Key.Control_L)
  314. _engine.send_script(LevelEditorApi.key_up("left_ctrl"));
  315. else if (ev.keyval == Gdk.Key.Shift_L)
  316. _engine.send_script(LevelEditorApi.key_up("left_shift"));
  317. return false;
  318. }
  319. private void on_resource_browser_resource_selected(string type, string name)
  320. {
  321. _engine.send_script(LevelEditorApi.set_placeable(type, name));
  322. }
  323. private void on_compiler_connected()
  324. {
  325. _console_view.log("Compiler connected.", "info");
  326. _compiler.receive_async();
  327. }
  328. private void on_compiler_disconnected()
  329. {
  330. _console_view.log("Compiler disconnected.", "info");
  331. }
  332. private void on_engine_connected()
  333. {
  334. _console_view.log("Engine connected.", "info");
  335. _engine.receive_async();
  336. }
  337. private void on_engine_disconnected()
  338. {
  339. _console_view.log("Engine disconnected.", "info");
  340. }
  341. private static int stringcmp(ref string a, ref string b)
  342. {
  343. return Posix.strcmp(a, b);
  344. }
  345. private void on_message_received(ConsoleClient client, uint8[] json)
  346. {
  347. try
  348. {
  349. Hashtable msg = JSON.decode(json) as Hashtable;
  350. string msg_type = msg["type"] as string;
  351. if (msg_type == "message")
  352. {
  353. _console_view.log((string)msg["message"], (string)msg["severity"]);
  354. }
  355. else if (msg_type == "compile")
  356. {
  357. Guid id = Guid.parse((string)msg["id"]);
  358. if (msg.has_key("start"))
  359. {
  360. // FIXME
  361. }
  362. else if (msg.has_key("success"))
  363. {
  364. _resource_compiler.finished((bool)msg["success"]);
  365. }
  366. }
  367. else if (msg_type == "unit_spawned")
  368. {
  369. string id = (string) msg["id"];
  370. string name = (string) msg["name"];
  371. ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
  372. ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
  373. ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
  374. _level.on_unit_spawned(Guid.parse(id)
  375. , name
  376. , Vector3.from_array(pos)
  377. , Quaternion.from_array(rot)
  378. , Vector3.from_array(scl)
  379. );
  380. }
  381. else if (msg_type == "sound_spawned")
  382. {
  383. string id = (string) msg["id"];
  384. string name = (string) msg["name"];
  385. ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
  386. ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
  387. ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
  388. double range = (double) msg["range"];
  389. double volume = (double) msg["volume"];
  390. bool loop = (bool) msg["loop"];
  391. _level.on_sound_spawned(Guid.parse(id)
  392. , name
  393. , Vector3.from_array(pos)
  394. , Quaternion.from_array(rot)
  395. , Vector3.from_array(scl)
  396. , range
  397. , volume
  398. , loop
  399. );
  400. }
  401. else if (msg_type == "move_objects")
  402. {
  403. Hashtable ids = (Hashtable)msg["ids"];
  404. Hashtable new_positions = (Hashtable)msg["new_positions"];
  405. Hashtable new_rotations = (Hashtable)msg["new_rotations"];
  406. Hashtable new_scales = (Hashtable)msg["new_scales"];
  407. string[] keys = ids.keys.to_array();
  408. Posix.qsort(keys, keys.length, sizeof(string), (Posix.compar_fn_t)stringcmp);
  409. Guid[] n_ids = new Guid[keys.length];
  410. Vector3[] n_positions = new Vector3[keys.length];
  411. Quaternion[] n_rotations = new Quaternion[keys.length];
  412. Vector3[] n_scales = new Vector3[keys.length];
  413. for (int i = 0; i < keys.length; ++i)
  414. {
  415. string k = keys[i];
  416. n_ids[i] = Guid.parse((string)ids[k]);
  417. n_positions[i] = Vector3.from_array((ArrayList<Value?>)(new_positions[k]));
  418. n_rotations[i] = Quaternion.from_array((ArrayList<Value?>)new_rotations[k]);
  419. n_scales[i] = Vector3.from_array((ArrayList<Value?>)new_scales[k]);
  420. }
  421. _level.on_move_objects(n_ids, n_positions, n_rotations, n_scales);
  422. }
  423. else if (msg_type == "selection")
  424. {
  425. Hashtable objects = (Hashtable)msg["objects"];
  426. string[] keys = objects.keys.to_array();
  427. Posix.qsort(keys, keys.length, sizeof(string), (Posix.compar_fn_t)stringcmp);
  428. Guid[] ids = new Guid[keys.length];
  429. for (int i = 0; i < keys.length; ++i)
  430. {
  431. string k = keys[i];
  432. ids[i] = Guid.parse((string)objects[k]);
  433. }
  434. _level.on_selection(ids);
  435. }
  436. }
  437. catch (Error e)
  438. {
  439. _console_view.log(e.message, "error");
  440. }
  441. // Receive next message
  442. client.receive_async();
  443. }
  444. private void send_state()
  445. {
  446. StringBuilder sb = new StringBuilder();
  447. sb.append(LevelEditorApi.set_grid_size(_grid_size));
  448. sb.append(LevelEditorApi.set_rotation_snap(_rotation_snap));
  449. sb.append(LevelEditorApi.enable_show_grid(_show_grid));
  450. sb.append(LevelEditorApi.enable_snap_to_grid(_snap_to_grid));
  451. sb.append(LevelEditorApi.enable_debug_render_world(_debug_render_world));
  452. sb.append(LevelEditorApi.enable_debug_physics_world(_debug_physics_world));
  453. sb.append(LevelEditorApi.set_tool_type(_tool_type));
  454. sb.append(LevelEditorApi.set_snap_mode(_snap_mode));
  455. sb.append(LevelEditorApi.set_reference_system(_reference_system));
  456. _engine.send_script(sb.str);
  457. }
  458. private bool on_button_press(EventButton ev)
  459. {
  460. // Prevent accelerators to step on camera's toes
  461. remove_accel_group(_ui_manager.get_accel_group());
  462. return true;
  463. }
  464. private bool on_button_release(EventButton ev)
  465. {
  466. add_accel_group(_ui_manager.get_accel_group());
  467. return true;
  468. }
  469. private void start_compiler()
  470. {
  471. string args[] =
  472. {
  473. ENGINE_EXE,
  474. "--source-dir", _project.source_dir(),
  475. "--map-source-dir", "core", _project.toolchain_dir(),
  476. "--server",
  477. null
  478. };
  479. GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE);
  480. sl.set_cwd(ENGINE_DIR);
  481. try
  482. {
  483. _compiler_process = sl.spawnv(args);
  484. }
  485. catch (Error e)
  486. {
  487. _console_view.log(e.message, "error");
  488. }
  489. for (int tries = 0; !_compiler.is_connected() && tries < 5; ++tries)
  490. {
  491. _compiler.connect("127.0.0.1", CROWN_DEFAULT_SERVER_PORT);
  492. GLib.Thread.usleep(100*1000);
  493. }
  494. _resource_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
  495. if (_resource_compiler.compile.end(res))
  496. {
  497. if (_engine_view != null)
  498. return;
  499. _engine_view = new EngineView(_engine);
  500. _engine_view.realized.connect(on_engine_view_realized);
  501. _engine_view.button_press_event.connect(on_button_press);
  502. _engine_view.button_release_event.connect(on_button_release);
  503. _alignment_engine.remove(_alignment_engine.get_child());
  504. _alignment_level_tree_view.remove(_alignment_level_tree_view.get_child());
  505. _alignment_properties_view.remove(_alignment_properties_view.get_child());
  506. _alignment_engine.add(_engine_view);
  507. _alignment_level_tree_view.add(_level_treeview);
  508. _alignment_properties_view.add(_properties_view);
  509. _alignment_engine.show_all();
  510. _alignment_level_tree_view.show_all();
  511. _alignment_properties_view.show_all();
  512. }
  513. });
  514. }
  515. private void stop_compiler()
  516. {
  517. _compiler.close();
  518. if (_compiler_process != null)
  519. _compiler_process.force_exit();
  520. }
  521. private void start_engine(uint window_xid)
  522. {
  523. string args[] =
  524. {
  525. ENGINE_EXE,
  526. "--data-dir", _project.data_dir(),
  527. "--boot-dir", LEVEL_EDITOR_BOOT_DIR,
  528. "--parent-window", window_xid.to_string(),
  529. "--wait-console",
  530. null
  531. };
  532. GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE);
  533. sl.set_cwd(ENGINE_DIR);
  534. try
  535. {
  536. _engine_process = sl.spawnv(args);
  537. }
  538. catch (Error e)
  539. {
  540. _console_view.log(e.message, "error");
  541. }
  542. for (int tries = 0; !_engine.is_connected() && tries < 5; ++tries)
  543. {
  544. _engine.connect("127.0.0.1", 10001);
  545. GLib.Thread.usleep(100*1000);
  546. }
  547. new_level();
  548. send_state();
  549. }
  550. private void stop_engine()
  551. {
  552. _engine.close();
  553. if (_engine_process != null)
  554. _engine_process.force_exit();
  555. }
  556. private void restart_engine()
  557. {
  558. stop_engine();
  559. start_engine(_engine_view.window_id);
  560. }
  561. private void start_game()
  562. {
  563. if (!save())
  564. return;
  565. _resource_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
  566. if (_resource_compiler.compile.end(res))
  567. {
  568. string args[] =
  569. {
  570. ENGINE_EXE,
  571. "--data-dir", _project.data_dir(),
  572. "--console-port", "12345",
  573. null
  574. };
  575. GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(SubprocessFlags.NONE);
  576. sl.set_cwd(ENGINE_DIR);
  577. try
  578. {
  579. _game_process = sl.spawnv(args);
  580. }
  581. catch (Error e)
  582. {
  583. _console_view.log(e.message, "error");
  584. }
  585. }
  586. });
  587. }
  588. private void stop_game()
  589. {
  590. if (_game_process != null)
  591. _game_process.force_exit();
  592. }
  593. private void on_engine_view_realized()
  594. {
  595. start_engine(_engine_view.window_id);
  596. }
  597. private void on_tool_changed(Gtk.Action action)
  598. {
  599. RadioAction ra = (RadioAction)action;
  600. _tool_type = (ToolType)ra.current_value;
  601. send_state();
  602. }
  603. private void on_snap_mode_changed(Gtk.Action action)
  604. {
  605. RadioAction ra = (RadioAction)action;
  606. _snap_mode = (SnapMode)ra.current_value;
  607. send_state();
  608. }
  609. private void on_reference_system_changed(Gtk.Action action)
  610. {
  611. RadioAction ra = (RadioAction)action;
  612. _reference_system = (ReferenceSystem)ra.current_value;
  613. send_state();
  614. }
  615. private void on_grid_changed(Gtk.Action action)
  616. {
  617. RadioAction ra = (RadioAction)action;
  618. _grid_size = (float)ra.current_value/100.0;
  619. send_state();
  620. }
  621. private void on_rotation_snap_changed(Gtk.Action action)
  622. {
  623. RadioAction ra = (RadioAction)action;
  624. _rotation_snap = (float)ra.current_value;
  625. send_state();
  626. }
  627. private void new_level()
  628. {
  629. _level_filename = null;
  630. _level.load_empty_level();
  631. }
  632. private void load()
  633. {
  634. FileChooserDialog fcd = new FileChooserDialog("Open..."
  635. , this
  636. , FileChooserAction.OPEN
  637. , "Cancel"
  638. , ResponseType.CANCEL
  639. , "Open"
  640. , ResponseType.ACCEPT
  641. );
  642. fcd.add_filter(_file_filter);
  643. fcd.set_current_folder(_project.source_dir());
  644. if (fcd.run() == (int)ResponseType.ACCEPT)
  645. {
  646. string filename = fcd.get_filename();
  647. if (filename.has_suffix(".level"))
  648. {
  649. _level_filename = filename;
  650. _level.load(_level_filename);
  651. send_state();
  652. }
  653. }
  654. fcd.destroy();
  655. }
  656. private bool save_as()
  657. {
  658. bool saved = false;
  659. FileChooserDialog fcd = new FileChooserDialog("Save As..."
  660. , this
  661. , FileChooserAction.SAVE
  662. , "Cancel"
  663. , ResponseType.CANCEL
  664. , "Save"
  665. , ResponseType.ACCEPT
  666. );
  667. fcd.add_filter(_file_filter);
  668. fcd.set_current_folder(_project.source_dir());
  669. if (fcd.run() == (int)ResponseType.ACCEPT)
  670. {
  671. _level_filename = fcd.get_filename();
  672. if (!_level_filename.has_suffix(".level"))
  673. _level_filename += ".level";
  674. _level.save(_level_filename);
  675. saved = true;
  676. }
  677. fcd.destroy();
  678. return saved;
  679. }
  680. private bool save()
  681. {
  682. bool saved = false;
  683. if (_level_filename == null)
  684. {
  685. saved = save_as();
  686. }
  687. else
  688. {
  689. _level.save(_level_filename);
  690. saved = true;
  691. }
  692. return saved;
  693. }
  694. private bool save_timeout()
  695. {
  696. if (_level_filename != null)
  697. save();
  698. return true;
  699. }
  700. private void shutdown()
  701. {
  702. if (_resource_browser != null)
  703. _resource_browser.destroy();
  704. if (_preferences_dialog != null)
  705. _preferences_dialog.destroy();
  706. stop_game();
  707. stop_engine();
  708. stop_compiler();
  709. Gtk.main_quit();
  710. }
  711. private void quit()
  712. {
  713. if (!_db.changed())
  714. {
  715. shutdown();
  716. return;
  717. }
  718. Gtk.MessageDialog md = new Gtk.MessageDialog(this
  719. , Gtk.DialogFlags.MODAL
  720. , Gtk.MessageType.WARNING
  721. , Gtk.ButtonsType.NONE
  722. , "File changed, save?"
  723. );
  724. md.add_button("Quit without Saving", ResponseType.NO);
  725. md.add_button("Cancel", ResponseType.CANCEL);
  726. md.add_button("Save", ResponseType.YES);
  727. md.set_default_response(ResponseType.YES);
  728. int rt = md.run();
  729. md.destroy();
  730. if (rt == (int)ResponseType.YES && save() || rt == (int)ResponseType.NO)
  731. shutdown();
  732. }
  733. private void on_new()
  734. {
  735. if (!_db.changed())
  736. {
  737. new_level();
  738. send_state();
  739. return;
  740. }
  741. Gtk.MessageDialog md = new Gtk.MessageDialog(this
  742. , Gtk.DialogFlags.MODAL
  743. , Gtk.MessageType.WARNING
  744. , Gtk.ButtonsType.NONE
  745. , "File changed, save?"
  746. );
  747. md.add_button("New without Saving", ResponseType.NO);
  748. md.add_button("Cancel", ResponseType.CANCEL);
  749. md.add_button("Save", ResponseType.YES);
  750. md.set_default_response(ResponseType.YES);
  751. int rt = md.run();
  752. md.destroy();
  753. if (rt == (int)ResponseType.YES && save() || rt == (int)ResponseType.NO)
  754. {
  755. new_level();
  756. send_state();
  757. }
  758. }
  759. private void on_open(Gtk.Action action)
  760. {
  761. if (!_db.changed())
  762. {
  763. load();
  764. return;
  765. }
  766. Gtk.MessageDialog md = new Gtk.MessageDialog(this
  767. , Gtk.DialogFlags.MODAL
  768. , Gtk.MessageType.WARNING
  769. , Gtk.ButtonsType.NONE
  770. , "File changed, save?"
  771. );
  772. md.add_button("Open without Saving", ResponseType.NO);
  773. md.add_button("Cancel", ResponseType.CANCEL);
  774. md.add_button("Save", ResponseType.YES);
  775. md.set_default_response(ResponseType.YES);
  776. int rt = md.run();
  777. md.destroy();
  778. if (rt == (int)ResponseType.YES && save() || rt == (int)ResponseType.NO)
  779. load();
  780. }
  781. private void on_save(Gtk.Action action)
  782. {
  783. save();
  784. }
  785. private void on_save_as(Gtk.Action action)
  786. {
  787. save_as();
  788. }
  789. private void on_import_begin(Gtk.FileFilter ff, out SList<string> filenames, out string filename)
  790. {
  791. FileChooserDialog fcd = new FileChooserDialog("Import..."
  792. , this
  793. , FileChooserAction.OPEN
  794. , "Cancel"
  795. , ResponseType.CANCEL
  796. , "Open"
  797. , ResponseType.ACCEPT
  798. );
  799. fcd.select_multiple = true;
  800. fcd.add_filter(ff);
  801. if (fcd.run() != (int)ResponseType.ACCEPT)
  802. {
  803. fcd.destroy();
  804. return;
  805. }
  806. filenames = fcd.get_filenames();
  807. fcd.destroy();
  808. FileChooserDialog dst = new FileChooserDialog("Select destination folder..."
  809. , this
  810. , FileChooserAction.SELECT_FOLDER
  811. , "Cancel"
  812. , ResponseType.CANCEL
  813. , "Select"
  814. , ResponseType.ACCEPT
  815. );
  816. dst.set_current_folder(_project.source_dir());
  817. if (dst.run() != (int)ResponseType.ACCEPT)
  818. {
  819. dst.destroy();
  820. return;
  821. }
  822. filename = dst.get_filename();
  823. dst.destroy();
  824. }
  825. private void on_import_end()
  826. {
  827. _resource_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
  828. if (_resource_compiler.compile.end(res))
  829. {
  830. _project.scan_source_dir();
  831. }
  832. });
  833. }
  834. private void on_import_sprites(Gtk.Action action)
  835. {
  836. Gtk.FileFilter ff = new FileFilter();
  837. ff.set_filter_name("Sprite (*.png)");
  838. ff.add_pattern("*.png");
  839. SList<string> filenames;
  840. string filename;
  841. on_import_begin(ff, out filenames, out filename);
  842. _project.import_sprites(filenames, filename);
  843. on_import_end();
  844. }
  845. private void on_import_meshes(Gtk.Action action)
  846. {
  847. Gtk.FileFilter ff = new FileFilter();
  848. ff.set_filter_name("Mesh (*.mesh)");
  849. ff.add_pattern("*.mesh");
  850. SList<string> filenames;
  851. string filename;
  852. on_import_begin(ff, out filenames, out filename);
  853. _project.import_meshes(filenames, filename);
  854. on_import_end();
  855. }
  856. private void on_import_sounds(Gtk.Action action)
  857. {
  858. Gtk.FileFilter ff = new FileFilter();
  859. ff.set_filter_name("Sound (*.wav)");
  860. ff.add_pattern("*.wav");
  861. SList<string> filenames;
  862. string filename;
  863. on_import_begin(ff, out filenames, out filename);
  864. _project.import_sounds(filenames, filename);
  865. on_import_end();
  866. }
  867. private void on_import_textures(Gtk.Action action)
  868. {
  869. Gtk.FileFilter ff = new FileFilter();
  870. ff.set_filter_name("Texture (*.png, *.tga, *.dds, *.ktx, *.pvr)");
  871. ff.add_pattern("*.png");
  872. ff.add_pattern("*.tga");
  873. ff.add_pattern("*.dds");
  874. ff.add_pattern("*.ktx");
  875. ff.add_pattern("*.pvr");
  876. SList<string> filenames;
  877. string filename;
  878. on_import_begin(ff, out filenames, out filename);
  879. _project.import_textures(filenames, filename);
  880. on_import_end();
  881. }
  882. private void on_preferences(Gtk.Action action)
  883. {
  884. if (_preferences_dialog == null)
  885. {
  886. _preferences_dialog = new PreferencesDialog(_engine);
  887. _preferences_dialog.set_transient_for(this);
  888. _preferences_dialog.delete_event.connect(() => { _preferences_dialog.hide(); return true; });
  889. }
  890. _preferences_dialog.show_all();
  891. }
  892. private void on_quit(Gtk.Action action)
  893. {
  894. quit();
  895. }
  896. private void on_show_grid(Gtk.Action action)
  897. {
  898. ToggleAction ta = (ToggleAction)action;
  899. _show_grid = ta.active;
  900. send_state();
  901. }
  902. private void on_custom_grid()
  903. {
  904. MessageDialog dg = new MessageDialog(this
  905. , DialogFlags.MODAL
  906. , MessageType.OTHER
  907. , ButtonsType.OK_CANCEL
  908. , "Grid size in meters:"
  909. );
  910. SpinButtonDouble sb = new SpinButtonDouble(_grid_size, 0.1, 1000);
  911. (dg.message_area as Gtk.Box).add(sb);
  912. dg.show_all();
  913. if (dg.run() == (int)ResponseType.OK)
  914. {
  915. _grid_size = sb.value;
  916. send_state();
  917. }
  918. dg.destroy();
  919. }
  920. private void on_rotation_snap(Gtk.Action action)
  921. {
  922. MessageDialog dg = new MessageDialog(this
  923. , DialogFlags.MODAL
  924. , MessageType.OTHER
  925. , ButtonsType.OK_CANCEL
  926. , "Rotation snap in degrees:"
  927. );
  928. SpinButtonDouble sb = new SpinButtonDouble(_rotation_snap, 1.0, 180.0);
  929. (dg.message_area as Gtk.Box).add(sb);
  930. dg.show_all();
  931. if (dg.run() == (int)ResponseType.OK)
  932. {
  933. _rotation_snap = sb.value;
  934. send_state();
  935. }
  936. dg.destroy();
  937. }
  938. private void on_create_cube(Gtk.Action action)
  939. {
  940. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cube"));
  941. }
  942. private void on_create_sphere(Gtk.Action action)
  943. {
  944. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/sphere"));
  945. }
  946. private void on_create_cone(Gtk.Action action)
  947. {
  948. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cone"));
  949. }
  950. private void on_create_cylinder(Gtk.Action action)
  951. {
  952. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cylinder"));
  953. }
  954. private void on_create_plane(Gtk.Action action)
  955. {
  956. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/plane"));
  957. }
  958. private void on_create_camera(Gtk.Action action)
  959. {
  960. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/camera"));
  961. }
  962. private void on_create_light(Gtk.Action action)
  963. {
  964. _engine.send_script(LevelEditorApi.set_placeable("unit", "core/units/light"));
  965. }
  966. private void on_create_sound_source(Gtk.Action action)
  967. {
  968. _engine.send_script(LevelEditorApi.set_placeable("sound", ""));
  969. }
  970. private void on_resource_browser(Gtk.Action action)
  971. {
  972. _resource_browser.show_all();
  973. }
  974. private void on_engine_restart(Gtk.Action action)
  975. {
  976. restart_engine();
  977. }
  978. private void on_reload_lua(Gtk.Action action)
  979. {
  980. _resource_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
  981. if (_resource_compiler.compile.end(res))
  982. {
  983. _engine.send(EngineApi.pause());
  984. _engine.send(EngineApi.reload("lua", "core/editors/level_editor/level_editor"));
  985. _engine.send(EngineApi.unpause());
  986. }
  987. });
  988. }
  989. public void on_snap_to_grid(Gtk.Action action)
  990. {
  991. ToggleAction ta = (ToggleAction)action;
  992. _snap_to_grid = ta.active;
  993. send_state();
  994. }
  995. private void on_debug_render_world(Gtk.Action action)
  996. {
  997. ToggleAction ta = (ToggleAction)action;
  998. _debug_render_world = ta.active;
  999. send_state();
  1000. }
  1001. private void on_debug_physics_world(Gtk.Action action)
  1002. {
  1003. ToggleAction ta = (ToggleAction)action;
  1004. _debug_physics_world = ta.active;
  1005. send_state();
  1006. }
  1007. private void on_run_game(Gtk.Action action)
  1008. {
  1009. start_game();
  1010. }
  1011. private void on_undo(Gtk.Action action)
  1012. {
  1013. _db.undo();
  1014. }
  1015. private void on_redo(Gtk.Action action)
  1016. {
  1017. _db.redo();
  1018. }
  1019. private void on_duplicate(Gtk.Action action)
  1020. {
  1021. _level.duplicate_selected_objects();
  1022. }
  1023. private void on_delete(Gtk.Action action)
  1024. {
  1025. _level.destroy_selected_objects();
  1026. }
  1027. private void on_manual(Gtk.Action action)
  1028. {
  1029. try
  1030. {
  1031. AppInfo.launch_default_for_uri("https://taylor001.github.io/crown/html", null);
  1032. }
  1033. catch (Error e)
  1034. {
  1035. _console_view.log(e.message, "error");
  1036. }
  1037. }
  1038. private void on_report_issue(Gtk.Action action)
  1039. {
  1040. try
  1041. {
  1042. AppInfo.launch_default_for_uri("https://github.com/taylor001/crown/issues", null);
  1043. }
  1044. catch (Error e)
  1045. {
  1046. _console_view.log(e.message, "error");
  1047. }
  1048. }
  1049. private void on_open_last_log(Gtk.Action action)
  1050. {
  1051. File file = File.new_for_path(_project.data_dir() + "/last.log");
  1052. try
  1053. {
  1054. AppInfo.launch_default_for_uri(file.get_uri(), null);
  1055. }
  1056. catch (Error e)
  1057. {
  1058. _console_view.log(e.message, "error");
  1059. }
  1060. }
  1061. private void on_about(Gtk.Action action)
  1062. {
  1063. Gtk.AboutDialog dlg = new Gtk.AboutDialog();
  1064. dlg.set_destroy_with_parent(true);
  1065. dlg.set_transient_for(this);
  1066. dlg.set_modal(true);
  1067. try
  1068. {
  1069. dlg.set_logo(new Pixbuf.from_resource("/org/pepper/icons/128x128/pepper.png"));
  1070. }
  1071. catch (Error e)
  1072. {
  1073. stderr.printf("%s\n", e.message);
  1074. }
  1075. dlg.program_name = "Crown Game Engine";
  1076. dlg.version = CROWN_VERSION;
  1077. dlg.website = "https://github.com/taylor001/crown";
  1078. dlg.copyright = "Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.";
  1079. dlg.license = "Crown Game Engine.\n"
  1080. + "Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.\n"
  1081. + "\n"
  1082. + "This program is free software; you can redistribute it and/or\n"
  1083. + "modify it under the terms of the GNU General Public License\n"
  1084. + "as published by the Free Software Foundation; either version 2\n"
  1085. + "of the License, or (at your option) any later version.\n"
  1086. + "\n"
  1087. + "This program is distributed in the hope that it will be useful,\n"
  1088. + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  1089. + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  1090. + "GNU General Public License for more details.\n"
  1091. + "\n"
  1092. + "You should have received a copy of the GNU General Public License\n"
  1093. + "along with this program; if not, write to the Free Software\n"
  1094. + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
  1095. ;
  1096. dlg.run();
  1097. dlg.destroy();
  1098. }
  1099. private void on_destroy()
  1100. {
  1101. Gtk.main_quit();
  1102. }
  1103. private bool on_delete_event()
  1104. {
  1105. quit();
  1106. return true;
  1107. }
  1108. }
  1109. public static int main (string[] args)
  1110. {
  1111. Gtk.init(ref args);
  1112. Intl.setlocale(LocaleCategory.ALL, "C");
  1113. Gtk.Settings.get_default().gtk_application_prefer_dark_theme = true;
  1114. Gtk.CssProvider provider = new Gtk.CssProvider();
  1115. Gdk.Screen screen = Gdk.Display.get_default().get_default_screen();
  1116. Gtk.StyleContext.add_provider_for_screen(screen, provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
  1117. provider.load_from_resource("/org/pepper/theme/style.css");
  1118. Project project = new Project();
  1119. project.load(args[1], args[2], args[3]);
  1120. var editor = new LevelEditor(project);
  1121. editor.show_all();
  1122. Gtk.main();
  1123. return 0;
  1124. }
  1125. }