|
|
@@ -9,1969 +9,1970 @@ using Gtk;
|
|
|
|
|
|
namespace Crown
|
|
|
{
|
|
|
- const int WINDOW_DEFAULT_WIDTH = 1280;
|
|
|
- const int WINDOW_DEFAULT_HEIGHT = 720;
|
|
|
+const int WINDOW_DEFAULT_WIDTH = 1280;
|
|
|
+const int WINDOW_DEFAULT_HEIGHT = 720;
|
|
|
|
|
|
- public class LevelEditorWindow : Gtk.ApplicationWindow
|
|
|
+public class LevelEditorWindow : Gtk.ApplicationWindow
|
|
|
+{
|
|
|
+ private const GLib.ActionEntry[] action_entries =
|
|
|
{
|
|
|
- private const GLib.ActionEntry[] action_entries =
|
|
|
- {
|
|
|
- { "fullscreen", on_fullscreen, null, null }
|
|
|
- };
|
|
|
-
|
|
|
- public bool _fullscreen;
|
|
|
-
|
|
|
- public LevelEditorWindow(Gtk.Application app)
|
|
|
- {
|
|
|
- Object(application: app);
|
|
|
-
|
|
|
- this.add_action_entries(action_entries, this);
|
|
|
-
|
|
|
- this.title = "Level Editor";
|
|
|
- this.key_press_event.connect(this.on_key_press);
|
|
|
- this.key_release_event.connect(this.on_key_release);
|
|
|
- this.window_state_event.connect(this.on_window_state_event);
|
|
|
- this.delete_event.connect(this.on_delete_event);
|
|
|
- this.focus_out_event.connect(this.on_focus_out);
|
|
|
+ { "fullscreen", on_fullscreen, null, null }
|
|
|
+ };
|
|
|
|
|
|
- _fullscreen = false;
|
|
|
- }
|
|
|
-
|
|
|
- private void on_fullscreen(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- if (_fullscreen)
|
|
|
- unfullscreen();
|
|
|
- else
|
|
|
- fullscreen();
|
|
|
- }
|
|
|
-
|
|
|
- private bool on_key_press(Gdk.EventKey ev)
|
|
|
- {
|
|
|
- LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
+ public bool _fullscreen;
|
|
|
|
|
|
- if (ev.keyval == Gdk.Key.Control_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_down("ctrl_left"));
|
|
|
- else if (ev.keyval == Gdk.Key.Shift_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_down("shift_left"));
|
|
|
- else if (ev.keyval == Gdk.Key.Alt_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_down("alt_left"));
|
|
|
+ public LevelEditorWindow(Gtk.Application app)
|
|
|
+ {
|
|
|
+ Object(application: app);
|
|
|
|
|
|
- return Gdk.EVENT_PROPAGATE;
|
|
|
- }
|
|
|
+ this.add_action_entries(action_entries, this);
|
|
|
|
|
|
- private bool on_key_release(Gdk.EventKey ev)
|
|
|
- {
|
|
|
- LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
+ this.title = "Level Editor";
|
|
|
+ this.key_press_event.connect(this.on_key_press);
|
|
|
+ this.key_release_event.connect(this.on_key_release);
|
|
|
+ this.window_state_event.connect(this.on_window_state_event);
|
|
|
+ this.delete_event.connect(this.on_delete_event);
|
|
|
+ this.focus_out_event.connect(this.on_focus_out);
|
|
|
|
|
|
- if (ev.keyval == Gdk.Key.Control_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_up("ctrl_left"));
|
|
|
- else if (ev.keyval == Gdk.Key.Shift_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_up("shift_left"));
|
|
|
- else if (ev.keyval == Gdk.Key.Alt_L)
|
|
|
- app._editor.send_script(LevelEditorApi.key_up("alt_left"));
|
|
|
+ _fullscreen = false;
|
|
|
+ }
|
|
|
|
|
|
- return Gdk.EVENT_PROPAGATE;
|
|
|
- }
|
|
|
+ private void on_fullscreen(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_fullscreen)
|
|
|
+ unfullscreen();
|
|
|
+ else
|
|
|
+ fullscreen();
|
|
|
+ }
|
|
|
|
|
|
- private bool on_window_state_event(Gdk.EventWindowState ev)
|
|
|
- {
|
|
|
- _fullscreen = (ev.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
|
|
|
- return Gdk.EVENT_STOP;
|
|
|
- }
|
|
|
+ private bool on_key_press(Gdk.EventKey ev)
|
|
|
+ {
|
|
|
+ LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
|
|
|
- private bool on_delete_event()
|
|
|
- {
|
|
|
- LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
- if (app.should_quit())
|
|
|
- {
|
|
|
- app.close_all();
|
|
|
- return Gdk.EVENT_PROPAGATE; // Quit application
|
|
|
- }
|
|
|
+ if (ev.keyval == Gdk.Key.Control_L)
|
|
|
+ app._editor.send_script(LevelEditorApi.key_down("ctrl_left"));
|
|
|
+ else if (ev.keyval == Gdk.Key.Shift_L)
|
|
|
+ app._editor.send_script(LevelEditorApi.key_down("shift_left"));
|
|
|
+ else if (ev.keyval == Gdk.Key.Alt_L)
|
|
|
+ app._editor.send_script(LevelEditorApi.key_down("alt_left"));
|
|
|
|
|
|
- return Gdk.EVENT_STOP; // Keep alive
|
|
|
- }
|
|
|
+ return Gdk.EVENT_PROPAGATE;
|
|
|
+ }
|
|
|
|
|
|
- private bool on_focus_out(Gdk.EventFocus ev)
|
|
|
- {
|
|
|
- LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
+ private bool on_key_release(Gdk.EventKey ev)
|
|
|
+ {
|
|
|
+ LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
|
|
|
+ if (ev.keyval == Gdk.Key.Control_L)
|
|
|
app._editor.send_script(LevelEditorApi.key_up("ctrl_left"));
|
|
|
+ else if (ev.keyval == Gdk.Key.Shift_L)
|
|
|
app._editor.send_script(LevelEditorApi.key_up("shift_left"));
|
|
|
+ else if (ev.keyval == Gdk.Key.Alt_L)
|
|
|
app._editor.send_script(LevelEditorApi.key_up("alt_left"));
|
|
|
- return Gdk.EVENT_PROPAGATE;
|
|
|
- }
|
|
|
+
|
|
|
+ return Gdk.EVENT_PROPAGATE;
|
|
|
}
|
|
|
|
|
|
- public enum StartGame
|
|
|
+ private bool on_window_state_event(Gdk.EventWindowState ev)
|
|
|
{
|
|
|
- NORMAL,
|
|
|
- TEST
|
|
|
+ _fullscreen = (ev.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
|
|
|
+ return Gdk.EVENT_STOP;
|
|
|
}
|
|
|
|
|
|
- public class LevelEditorApplication : Gtk.Application
|
|
|
+ private bool on_delete_event()
|
|
|
{
|
|
|
- // Constants
|
|
|
- private const GLib.ActionEntry[] action_entries_file =
|
|
|
+ LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
+ if (app.should_quit())
|
|
|
{
|
|
|
- // parameter type
|
|
|
- // name activate() | state
|
|
|
- // | | | |
|
|
|
- { "menu-file", null, null, null },
|
|
|
- { "new-level", on_new_level, null, null },
|
|
|
- { "open-level", on_open_level, "s", null },
|
|
|
- { "new-project", on_new_project, null, null },
|
|
|
- { "open-project", on_open_project, null, null },
|
|
|
- { "save", on_save, null, null },
|
|
|
- { "save-as", on_save_as, null, null },
|
|
|
- { "import", on_import, null, null },
|
|
|
- { "preferences", on_preferences, null, null },
|
|
|
- { "deploy", on_deploy, null, null },
|
|
|
- { "close", on_close, null, null },
|
|
|
- { "quit", on_quit, null, null }
|
|
|
- };
|
|
|
+ app.close_all();
|
|
|
+ return Gdk.EVENT_PROPAGATE; // Quit application
|
|
|
+ }
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_edit =
|
|
|
- {
|
|
|
- { "menu-edit", null, null, null },
|
|
|
- { "undo", on_undo, null, null },
|
|
|
- { "redo", on_redo, null, null },
|
|
|
- { "duplicate", on_duplicate, null, null },
|
|
|
- { "delete", on_delete, null, null },
|
|
|
- { "tool", on_tool_changed, "s", "'move'" },
|
|
|
- { "snap", on_snap_mode_changed, "s", "'relative'" },
|
|
|
- { "reference-system", on_reference_system_changed, "s", "'local'" },
|
|
|
- { "snap-to-grid", on_snap_to_grid, null, "true" },
|
|
|
- { "menu-grid", null, null, null },
|
|
|
- { "grid-show", on_show_grid, null, "true" },
|
|
|
- { "grid-custom", on_custom_grid, null, null },
|
|
|
- { "grid-preset", on_grid_changed, "s", "'1'" },
|
|
|
- { "menu-rotation-snap", null, null, null },
|
|
|
- { "rotation-snap-custom", on_rotation_snap, null, null },
|
|
|
- { "rotation-snap-preset", on_rotation_snap_changed, "s", "'15'" }
|
|
|
- };
|
|
|
+ return Gdk.EVENT_STOP; // Keep alive
|
|
|
+ }
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_create =
|
|
|
- {
|
|
|
- { "menu-create", null, null, null },
|
|
|
- { "menu-primitives", null, null, null },
|
|
|
- { "primitive-cube", on_create_primitive, null, null },
|
|
|
- { "primitive-sphere", on_create_primitive, null, null },
|
|
|
- { "primitive-cone", on_create_primitive, null, null },
|
|
|
- { "primitive-cylinder", on_create_primitive, null, null },
|
|
|
- { "primitive-plane", on_create_primitive, null, null },
|
|
|
- { "camera", on_create_primitive, null, null },
|
|
|
- { "light", on_create_primitive, null, null },
|
|
|
- { "sound-source", on_create_primitive, null, null }
|
|
|
- };
|
|
|
+ private bool on_focus_out(Gdk.EventFocus ev)
|
|
|
+ {
|
|
|
+ LevelEditorApplication app = (LevelEditorApplication)application;
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_camera =
|
|
|
- {
|
|
|
- { "menu-camera", null, null, null },
|
|
|
- { "camera-view", on_camera_view, "s", "'perspective'" }
|
|
|
- };
|
|
|
+ app._editor.send_script(LevelEditorApi.key_up("ctrl_left"));
|
|
|
+ app._editor.send_script(LevelEditorApi.key_up("shift_left"));
|
|
|
+ app._editor.send_script(LevelEditorApi.key_up("alt_left"));
|
|
|
+ return Gdk.EVENT_PROPAGATE;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_view =
|
|
|
- {
|
|
|
- { "menu-view", null, null, null },
|
|
|
- { "resource-chooser", on_resource_chooser, null, null },
|
|
|
- { "project-browser", on_project_browser, null, null },
|
|
|
- { "console", on_console, null, null },
|
|
|
- { "statusbar", on_statusbar, null, null },
|
|
|
- { "inspector", on_inspector, null, null },
|
|
|
- { "debug-render-world", on_debug_render_world, null, "false" },
|
|
|
- { "debug-physics-world", on_debug_physics_world, null, "false" }
|
|
|
- };
|
|
|
+public enum StartGame
|
|
|
+{
|
|
|
+ NORMAL,
|
|
|
+ TEST
|
|
|
+}
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_debug =
|
|
|
- {
|
|
|
- { "menu-debug", null, null, null },
|
|
|
- { "test-level", on_run_game, null, null },
|
|
|
- { "run-game", on_run_game, null, null },
|
|
|
- { "build-data", on_build_data, null, null },
|
|
|
- { "reload-lua", on_refresh_lua, null, null },
|
|
|
- { "restart", on_editor_restart, null, null }
|
|
|
- };
|
|
|
+public class LevelEditorApplication : Gtk.Application
|
|
|
+{
|
|
|
+ // Constants
|
|
|
+ private const GLib.ActionEntry[] action_entries_file =
|
|
|
+ {
|
|
|
+ // parameter type
|
|
|
+ // name activate() | state
|
|
|
+ // | | | |
|
|
|
+ { "menu-file", null, null, null },
|
|
|
+ { "new-level", on_new_level, null, null },
|
|
|
+ { "open-level", on_open_level, "s", null },
|
|
|
+ { "new-project", on_new_project, null, null },
|
|
|
+ { "open-project", on_open_project, null, null },
|
|
|
+ { "save", on_save, null, null },
|
|
|
+ { "save-as", on_save_as, null, null },
|
|
|
+ { "import", on_import, null, null },
|
|
|
+ { "preferences", on_preferences, null, null },
|
|
|
+ { "deploy", on_deploy, null, null },
|
|
|
+ { "close", on_close, null, null },
|
|
|
+ { "quit", on_quit, null, null }
|
|
|
+ };
|
|
|
+
|
|
|
+ private const GLib.ActionEntry[] action_entries_edit =
|
|
|
+ {
|
|
|
+ { "menu-edit", null, null, null },
|
|
|
+ { "undo", on_undo, null, null },
|
|
|
+ { "redo", on_redo, null, null },
|
|
|
+ { "duplicate", on_duplicate, null, null },
|
|
|
+ { "delete", on_delete, null, null },
|
|
|
+ { "tool", on_tool_changed, "s", "'move'" },
|
|
|
+ { "snap", on_snap_mode_changed, "s", "'relative'" },
|
|
|
+ { "reference-system", on_reference_system_changed, "s", "'local'" },
|
|
|
+ { "snap-to-grid", on_snap_to_grid, null, "true" },
|
|
|
+ { "menu-grid", null, null, null },
|
|
|
+ { "grid-show", on_show_grid, null, "true" },
|
|
|
+ { "grid-custom", on_custom_grid, null, null },
|
|
|
+ { "grid-preset", on_grid_changed, "s", "'1'" },
|
|
|
+ { "menu-rotation-snap", null, null, null },
|
|
|
+ { "rotation-snap-custom", on_rotation_snap, null, null },
|
|
|
+ { "rotation-snap-preset", on_rotation_snap_changed, "s", "'15'" }
|
|
|
+ };
|
|
|
+
|
|
|
+ private const GLib.ActionEntry[] action_entries_create =
|
|
|
+ {
|
|
|
+ { "menu-create", null, null, null },
|
|
|
+ { "menu-primitives", null, null, null },
|
|
|
+ { "primitive-cube", on_create_primitive, null, null },
|
|
|
+ { "primitive-sphere", on_create_primitive, null, null },
|
|
|
+ { "primitive-cone", on_create_primitive, null, null },
|
|
|
+ { "primitive-cylinder", on_create_primitive, null, null },
|
|
|
+ { "primitive-plane", on_create_primitive, null, null },
|
|
|
+ { "camera", on_create_primitive, null, null },
|
|
|
+ { "light", on_create_primitive, null, null },
|
|
|
+ { "sound-source", on_create_primitive, null, null }
|
|
|
+ };
|
|
|
+
|
|
|
+ private const GLib.ActionEntry[] action_entries_camera =
|
|
|
+ {
|
|
|
+ { "menu-camera", null, null, null },
|
|
|
+ { "camera-view", on_camera_view, "s", "'perspective'" }
|
|
|
+ };
|
|
|
|
|
|
- private const GLib.ActionEntry[] action_entries_help =
|
|
|
- {
|
|
|
- { "menu-help", null, null, null },
|
|
|
- { "manual", on_manual, null, null },
|
|
|
- { "report-issue", on_report_issue, null, null },
|
|
|
- { "browse-logs", on_browse_logs, null, null },
|
|
|
- { "changelog", on_changelog, null, null },
|
|
|
- { "about", on_about, null, null }
|
|
|
- };
|
|
|
+ private const GLib.ActionEntry[] action_entries_view =
|
|
|
+ {
|
|
|
+ { "menu-view", null, null, null },
|
|
|
+ { "resource-chooser", on_resource_chooser, null, null },
|
|
|
+ { "project-browser", on_project_browser, null, null },
|
|
|
+ { "console", on_console, null, null },
|
|
|
+ { "statusbar", on_statusbar, null, null },
|
|
|
+ { "inspector", on_inspector, null, null },
|
|
|
+ { "debug-render-world", on_debug_render_world, null, "false" },
|
|
|
+ { "debug-physics-world", on_debug_physics_world, null, "false" }
|
|
|
+ };
|
|
|
+
|
|
|
+ private const GLib.ActionEntry[] action_entries_debug =
|
|
|
+ {
|
|
|
+ { "menu-debug", null, null, null },
|
|
|
+ { "test-level", on_run_game, null, null },
|
|
|
+ { "run-game", on_run_game, null, null },
|
|
|
+ { "build-data", on_build_data, null, null },
|
|
|
+ { "reload-lua", on_refresh_lua, null, null },
|
|
|
+ { "restart", on_editor_restart, null, null }
|
|
|
+ };
|
|
|
+
|
|
|
+ private const GLib.ActionEntry[] action_entries_help =
|
|
|
+ {
|
|
|
+ { "menu-help", null, null, null },
|
|
|
+ { "manual", on_manual, null, null },
|
|
|
+ { "report-issue", on_report_issue, null, null },
|
|
|
+ { "browse-logs", on_browse_logs, null, null },
|
|
|
+ { "changelog", on_changelog, null, null },
|
|
|
+ { "about", on_about, null, null }
|
|
|
+ };
|
|
|
+
|
|
|
+ // Command line options
|
|
|
+ private string? _source_dir = null;
|
|
|
+ private string _toolchain_dir = "";
|
|
|
+ private string? _level_resource = null;
|
|
|
+ private User _user;
|
|
|
+
|
|
|
+ // Editor state
|
|
|
+ private double _grid_size;
|
|
|
+ private double _rotation_snap;
|
|
|
+ private bool _show_grid;
|
|
|
+ private bool _snap_to_grid;
|
|
|
+ private bool _debug_render_world;
|
|
|
+ private bool _debug_physics_world;
|
|
|
+ private LevelEditorApi.ToolType _tool_type;
|
|
|
+ private LevelEditorApi.SnapMode _snap_mode;
|
|
|
+ private LevelEditorApi.ReferenceSystem _reference_system;
|
|
|
+
|
|
|
+ // Engine connections
|
|
|
+ private GLib.Subprocess _compiler_process;
|
|
|
+ private GLib.Subprocess _editor_process;
|
|
|
+ private GLib.Subprocess _game_process;
|
|
|
+ private ConsoleClient _compiler;
|
|
|
+ public ConsoleClient _editor;
|
|
|
+ private ConsoleClient _game;
|
|
|
+
|
|
|
+ // Level data
|
|
|
+ private Database _database;
|
|
|
+ private Project _project;
|
|
|
+ private ProjectStore _project_store;
|
|
|
+ private Level _level;
|
|
|
+ private DataCompiler _data_compiler;
|
|
|
+
|
|
|
+ // Widgets
|
|
|
+ private ProjectBrowser _project_browser;
|
|
|
+ private EditorView _editor_view;
|
|
|
+ private LevelTreeView _level_treeview;
|
|
|
+ private LevelLayersTreeView _level_layers_treeview;
|
|
|
+ private PropertiesView _properties_view;
|
|
|
+ private PreferencesDialog _preferences_dialog;
|
|
|
+ private ResourceChooser _resource_chooser;
|
|
|
+ private Gtk.Popover _resource_popover;
|
|
|
+ private Gtk.Overlay _editor_view_overlay;
|
|
|
+ private Slide _project_slide;
|
|
|
+ private Slide _editor_slide;
|
|
|
+ private Slide _inspector_slide;
|
|
|
+
|
|
|
+ private Gtk.Toolbar _toolbar;
|
|
|
+ private Gtk.ToolButton _toolbar_run;
|
|
|
+ private Gtk.Notebook _level_tree_view_notebook;
|
|
|
+ private Gtk.Paned _editor_pane;
|
|
|
+ private Gtk.Paned _content_pane;
|
|
|
+ private Gtk.Paned _inspector_pane;
|
|
|
+ private Gtk.Paned _main_pane;
|
|
|
+ private Statusbar _statusbar;
|
|
|
+ private Gtk.Box _main_vbox;
|
|
|
+ private Gtk.FileFilter _file_filter;
|
|
|
+ private Gtk.ComboBoxText _combo;
|
|
|
+ private PanelNewProject _panel_new_project;
|
|
|
+ private PanelProjectsList _panel_projects_list;
|
|
|
+ private PanelWelcome _panel_welcome;
|
|
|
+ private Gtk.Stack _main_stack;
|
|
|
+
|
|
|
+ private uint _save_timer_id;
|
|
|
+
|
|
|
+ public LevelEditorApplication()
|
|
|
+ {
|
|
|
+ Object(application_id: "org.crown.level_editor"
|
|
|
+ , flags: GLib.ApplicationFlags.FLAGS_NONE
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void startup()
|
|
|
+ {
|
|
|
+ base.startup();
|
|
|
|
|
|
- // Command line options
|
|
|
- private string? _source_dir = null;
|
|
|
- private string _toolchain_dir = "";
|
|
|
- private string? _level_resource = null;
|
|
|
- private User _user;
|
|
|
+ Intl.setlocale(LocaleCategory.ALL, "C");
|
|
|
+ Gtk.Settings.get_default().gtk_theme_name = "Adwaita";
|
|
|
+ Gtk.Settings.get_default().gtk_application_prefer_dark_theme = true;
|
|
|
|
|
|
- // Editor state
|
|
|
- private double _grid_size;
|
|
|
- private double _rotation_snap;
|
|
|
- private bool _show_grid;
|
|
|
- private bool _snap_to_grid;
|
|
|
- private bool _debug_render_world;
|
|
|
- private bool _debug_physics_world;
|
|
|
- private LevelEditorApi.ToolType _tool_type;
|
|
|
- private LevelEditorApi.SnapMode _snap_mode;
|
|
|
- private LevelEditorApi.ReferenceSystem _reference_system;
|
|
|
+ Gtk.CssProvider provider = new Gtk.CssProvider();
|
|
|
+ Gdk.Screen screen = Gdk.Display.get_default().get_default_screen();
|
|
|
+ Gtk.StyleContext.add_provider_for_screen(screen, provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
+ provider.load_from_resource("/org/crown/level_editor/css/style.css");
|
|
|
|
|
|
- // Engine connections
|
|
|
- private GLib.Subprocess _compiler_process;
|
|
|
- private GLib.Subprocess _editor_process;
|
|
|
- private GLib.Subprocess _game_process;
|
|
|
- private ConsoleClient _compiler;
|
|
|
- public ConsoleClient _editor;
|
|
|
- private ConsoleClient _game;
|
|
|
-
|
|
|
- // Level data
|
|
|
- private Database _database;
|
|
|
- private Project _project;
|
|
|
- private ProjectStore _project_store;
|
|
|
- private Level _level;
|
|
|
- private DataCompiler _data_compiler;
|
|
|
+ // HACK: register CrownClamp type within GObject's type system to
|
|
|
+ // make GtkBuilder able to find it when creating the widget from
|
|
|
+ // .ui files.
|
|
|
+ // https://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui
|
|
|
+ new Clamp().get_type().ensure();
|
|
|
|
|
|
- // Widgets
|
|
|
- private ProjectBrowser _project_browser;
|
|
|
- private EditorView _editor_view;
|
|
|
- private LevelTreeView _level_treeview;
|
|
|
- private LevelLayersTreeView _level_layers_treeview;
|
|
|
- private PropertiesView _properties_view;
|
|
|
- private PreferencesDialog _preferences_dialog;
|
|
|
- private ResourceChooser _resource_chooser;
|
|
|
- private Gtk.Popover _resource_popover;
|
|
|
- private Gtk.Overlay _editor_view_overlay;
|
|
|
- private Slide _project_slide;
|
|
|
- private Slide _editor_slide;
|
|
|
- private Slide _inspector_slide;
|
|
|
-
|
|
|
- private Gtk.Toolbar _toolbar;
|
|
|
- private Gtk.ToolButton _toolbar_run;
|
|
|
- private Gtk.Notebook _level_tree_view_notebook;
|
|
|
- private Gtk.Paned _editor_pane;
|
|
|
- private Gtk.Paned _content_pane;
|
|
|
- private Gtk.Paned _inspector_pane;
|
|
|
- private Gtk.Paned _main_pane;
|
|
|
- private Statusbar _statusbar;
|
|
|
- private Gtk.Box _main_vbox;
|
|
|
- private Gtk.FileFilter _file_filter;
|
|
|
- private Gtk.ComboBoxText _combo;
|
|
|
- private PanelNewProject _panel_new_project;
|
|
|
- private PanelProjectsList _panel_projects_list;
|
|
|
- private PanelWelcome _panel_welcome;
|
|
|
- private Gtk.Stack _main_stack;
|
|
|
-
|
|
|
- private uint _save_timer_id;
|
|
|
-
|
|
|
- public LevelEditorApplication()
|
|
|
- {
|
|
|
- Object(application_id: "org.crown.level_editor"
|
|
|
- , flags: GLib.ApplicationFlags.FLAGS_NONE
|
|
|
- );
|
|
|
- }
|
|
|
+ this.add_action_entries(action_entries_file, this);
|
|
|
+ this.add_action_entries(action_entries_edit, this);
|
|
|
+ this.add_action_entries(action_entries_create, this);
|
|
|
+ this.add_action_entries(action_entries_camera, this);
|
|
|
+ this.add_action_entries(action_entries_view, this);
|
|
|
+ this.add_action_entries(action_entries_debug, this);
|
|
|
+ this.add_action_entries(action_entries_help, this);
|
|
|
|
|
|
- protected override void startup()
|
|
|
- {
|
|
|
- base.startup();
|
|
|
+ _compiler = new ConsoleClient();
|
|
|
+ _compiler.connected.connect(on_compiler_connected);
|
|
|
+ _compiler.disconnected.connect(on_compiler_disconnected_unexpected);
|
|
|
+ _compiler.message_received.connect(on_message_received);
|
|
|
+
|
|
|
+ _data_compiler = new DataCompiler(_compiler);
|
|
|
|
|
|
- Intl.setlocale(LocaleCategory.ALL, "C");
|
|
|
- Gtk.Settings.get_default().gtk_theme_name = "Adwaita";
|
|
|
- Gtk.Settings.get_default().gtk_application_prefer_dark_theme = true;
|
|
|
+ _project = new Project(_data_compiler);
|
|
|
+ _project.set_toolchain_dir(_toolchain_dir);
|
|
|
|
|
|
- Gtk.CssProvider provider = new Gtk.CssProvider();
|
|
|
- Gdk.Screen screen = Gdk.Display.get_default().get_default_screen();
|
|
|
- Gtk.StyleContext.add_provider_for_screen(screen, provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
- provider.load_from_resource("/org/crown/level_editor/css/style.css");
|
|
|
+ _database = new Database();
|
|
|
|
|
|
- // HACK: register CrownClamp type within GObject's type system to
|
|
|
- // make GtkBuilder able to find it when creating the widget from
|
|
|
- // .ui files.
|
|
|
- // https://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui
|
|
|
- new Clamp().get_type().ensure();
|
|
|
+ _editor = new ConsoleClient();
|
|
|
+ _editor.connected.connect(on_editor_connected);
|
|
|
+ _editor.disconnected.connect(on_editor_disconnected_unexpected);
|
|
|
+ _editor.message_received.connect(on_message_received);
|
|
|
|
|
|
- this.add_action_entries(action_entries_file, this);
|
|
|
- this.add_action_entries(action_entries_edit, this);
|
|
|
- this.add_action_entries(action_entries_create, this);
|
|
|
- this.add_action_entries(action_entries_camera, this);
|
|
|
- this.add_action_entries(action_entries_view, this);
|
|
|
- this.add_action_entries(action_entries_debug, this);
|
|
|
- this.add_action_entries(action_entries_help, this);
|
|
|
+ _game = new ConsoleClient();
|
|
|
+ _game.connected.connect(on_game_connected);
|
|
|
+ _game.disconnected.connect(on_game_disconnected);
|
|
|
+ _game.message_received.connect(on_message_received);
|
|
|
|
|
|
- _compiler = new ConsoleClient();
|
|
|
- _compiler.connected.connect(on_compiler_connected);
|
|
|
- _compiler.disconnected.connect(on_compiler_disconnected_unexpected);
|
|
|
- _compiler.message_received.connect(on_message_received);
|
|
|
+ _level = new Level(_database, _editor, _project);
|
|
|
|
|
|
- _data_compiler = new DataCompiler(_compiler);
|
|
|
+ // Editor state
|
|
|
+ _grid_size = 1.0;
|
|
|
+ _rotation_snap = 15.0;
|
|
|
+ _show_grid = true;
|
|
|
+ _snap_to_grid = true;
|
|
|
+ _debug_render_world = false;
|
|
|
+ _debug_physics_world = false;
|
|
|
+ _tool_type = LevelEditorApi.ToolType.MOVE;
|
|
|
+ _snap_mode = LevelEditorApi.SnapMode.RELATIVE;
|
|
|
+ _reference_system = LevelEditorApi.ReferenceSystem.LOCAL;
|
|
|
|
|
|
- _project = new Project(_data_compiler);
|
|
|
- _project.set_toolchain_dir(_toolchain_dir);
|
|
|
+ // Engine connections
|
|
|
+ _compiler_process = null;
|
|
|
+ _editor_process = null;
|
|
|
+ _game_process = null;
|
|
|
|
|
|
- _database = new Database();
|
|
|
+ _project_store = new ProjectStore(_project);
|
|
|
|
|
|
- _editor = new ConsoleClient();
|
|
|
- _editor.connected.connect(on_editor_connected);
|
|
|
- _editor.disconnected.connect(on_editor_disconnected_unexpected);
|
|
|
- _editor.message_received.connect(on_message_received);
|
|
|
+ // Widgets
|
|
|
+ _combo = new Gtk.ComboBoxText();
|
|
|
+ _combo.append("editor", "Editor");
|
|
|
+ _combo.append("game", "Game");
|
|
|
+ _combo.set_active_id("editor");
|
|
|
|
|
|
- _game = new ConsoleClient();
|
|
|
- _game.connected.connect(on_game_connected);
|
|
|
- _game.disconnected.connect(on_game_disconnected);
|
|
|
- _game.message_received.connect(on_message_received);
|
|
|
+ _console_view = new ConsoleView(_project, _combo);
|
|
|
+ _project_browser = new ProjectBrowser(_project, _project_store);
|
|
|
+ _level_treeview = new LevelTreeView(_database, _level);
|
|
|
+ _level_layers_treeview = new LevelLayersTreeView(_database, _level);
|
|
|
+ _properties_view = new PropertiesView(_level, _project_store);
|
|
|
|
|
|
- _level = new Level(_database, _editor, _project);
|
|
|
+ _project_slide = new Slide();
|
|
|
+ _editor_slide = new Slide();
|
|
|
+ _inspector_slide = new Slide();
|
|
|
|
|
|
- // Editor state
|
|
|
- _grid_size = 1.0;
|
|
|
- _rotation_snap = 15.0;
|
|
|
- _show_grid = true;
|
|
|
- _snap_to_grid = true;
|
|
|
- _debug_render_world = false;
|
|
|
- _debug_physics_world = false;
|
|
|
- _tool_type = LevelEditorApi.ToolType.MOVE;
|
|
|
- _snap_mode = LevelEditorApi.SnapMode.RELATIVE;
|
|
|
- _reference_system = LevelEditorApi.ReferenceSystem.LOCAL;
|
|
|
+ Gtk.Builder builder = new Gtk.Builder.from_resource("/org/crown/level_editor/ui/toolbar.ui");
|
|
|
+ _toolbar = builder.get_object("toolbar") as Gtk.Toolbar;
|
|
|
+ _toolbar_run = builder.get_object("run") as Gtk.ToolButton;
|
|
|
|
|
|
- // Engine connections
|
|
|
- _compiler_process = null;
|
|
|
- _editor_process = null;
|
|
|
- _game_process = null;
|
|
|
+ _editor_view_overlay = new Gtk.Overlay();
|
|
|
+ _editor_view_overlay.add_overlay(_toolbar);
|
|
|
|
|
|
- _project_store = new ProjectStore(_project);
|
|
|
+ _resource_popover = new Gtk.Popover(_toolbar);
|
|
|
+ _resource_popover.delete_event.connect(() => { _resource_popover.hide(); return Gdk.EVENT_STOP; });
|
|
|
+ _resource_popover.modal = true;
|
|
|
|
|
|
- // Widgets
|
|
|
- _combo = new Gtk.ComboBoxText();
|
|
|
- _combo.append("editor", "Editor");
|
|
|
- _combo.append("game", "Game");
|
|
|
- _combo.set_active_id("editor");
|
|
|
+ _preferences_dialog = new PreferencesDialog(this);
|
|
|
+ _preferences_dialog.set_transient_for(this.active_window);
|
|
|
+ _preferences_dialog.delete_event.connect(() => { _preferences_dialog.hide(); return Gdk.EVENT_STOP; });
|
|
|
|
|
|
- _console_view = new ConsoleView(_project, _combo);
|
|
|
- _project_browser = new ProjectBrowser(_project, _project_store);
|
|
|
- _level_treeview = new LevelTreeView(_database, _level);
|
|
|
- _level_layers_treeview = new LevelLayersTreeView(_database, _level);
|
|
|
- _properties_view = new PropertiesView(_level, _project_store);
|
|
|
+ _resource_chooser = new ResourceChooser(_project, _project_store, true);
|
|
|
+ _resource_chooser.resource_selected.connect(on_resource_browser_resource_selected);
|
|
|
+ _resource_chooser.resource_selected.connect(() => { _resource_popover.hide(); });
|
|
|
+ _resource_popover.add(_resource_chooser);
|
|
|
|
|
|
- _project_slide = new Slide();
|
|
|
- _editor_slide = new Slide();
|
|
|
- _inspector_slide = new Slide();
|
|
|
+ _level_tree_view_notebook = new Notebook();
|
|
|
+ _level_tree_view_notebook.show_border = false;
|
|
|
+ _level_tree_view_notebook.append_page(_level_treeview, new Gtk.Image.from_icon_name("level-tree", IconSize.SMALL_TOOLBAR));
|
|
|
+ _level_tree_view_notebook.append_page(_level_layers_treeview, new Gtk.Image.from_icon_name("level-layers", IconSize.SMALL_TOOLBAR));
|
|
|
|
|
|
- Gtk.Builder builder = new Gtk.Builder.from_resource("/org/crown/level_editor/ui/toolbar.ui");
|
|
|
- _toolbar = builder.get_object("toolbar") as Gtk.Toolbar;
|
|
|
- _toolbar_run = builder.get_object("run") as Gtk.ToolButton;
|
|
|
+ _editor_pane = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
|
|
+ _editor_pane.pack1(_project_slide, false, false);
|
|
|
+ _editor_pane.pack2(_editor_slide, true, false);
|
|
|
|
|
|
- _editor_view_overlay = new Gtk.Overlay();
|
|
|
- _editor_view_overlay.add_overlay(_toolbar);
|
|
|
+ _content_pane = new Gtk.Paned(Gtk.Orientation.VERTICAL);
|
|
|
+ _content_pane.pack1(_editor_pane, true, false);
|
|
|
+ _content_pane.pack2(_console_view, false, false);
|
|
|
|
|
|
- _resource_popover = new Gtk.Popover(_toolbar);
|
|
|
- _resource_popover.delete_event.connect(() => { _resource_popover.hide(); return Gdk.EVENT_STOP; });
|
|
|
- _resource_popover.modal = true;
|
|
|
+ _inspector_pane = new Gtk.Paned(Gtk.Orientation.VERTICAL);
|
|
|
+ _inspector_pane.pack1(_level_tree_view_notebook, true, false);
|
|
|
+ _inspector_pane.pack2(_properties_view, false, false);
|
|
|
|
|
|
- _preferences_dialog = new PreferencesDialog(this);
|
|
|
- _preferences_dialog.set_transient_for(this.active_window);
|
|
|
- _preferences_dialog.delete_event.connect(() => { _preferences_dialog.hide(); return Gdk.EVENT_STOP; });
|
|
|
+ _main_pane = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
|
|
+ _main_pane.pack1(_content_pane, true, false);
|
|
|
+ _main_pane.pack2(_inspector_slide, false, false);
|
|
|
|
|
|
- _resource_chooser = new ResourceChooser(_project, _project_store, true);
|
|
|
- _resource_chooser.resource_selected.connect(on_resource_browser_resource_selected);
|
|
|
- _resource_chooser.resource_selected.connect(() => { _resource_popover.hide(); });
|
|
|
- _resource_popover.add(_resource_chooser);
|
|
|
+ _statusbar = new Statusbar();
|
|
|
|
|
|
- _level_tree_view_notebook = new Notebook();
|
|
|
- _level_tree_view_notebook.show_border = false;
|
|
|
- _level_tree_view_notebook.append_page(_level_treeview, new Gtk.Image.from_icon_name("level-tree", IconSize.SMALL_TOOLBAR));
|
|
|
- _level_tree_view_notebook.append_page(_level_layers_treeview, new Gtk.Image.from_icon_name("level-layers", IconSize.SMALL_TOOLBAR));
|
|
|
+ _main_vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
|
+ _main_vbox.pack_start(_main_pane, true, true, 0);
|
|
|
+ _main_vbox.pack_start(_statusbar, false, false, 0);
|
|
|
+ _main_vbox.set_visible(true);
|
|
|
|
|
|
- _editor_pane = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
|
|
- _editor_pane.pack1(_project_slide, false, false);
|
|
|
- _editor_pane.pack2(_editor_slide, true, false);
|
|
|
+ _file_filter = new Gtk.FileFilter();
|
|
|
+ _file_filter.set_filter_name("Level (*.level)");
|
|
|
+ _file_filter.add_pattern("*.level");
|
|
|
|
|
|
- _content_pane = new Gtk.Paned(Gtk.Orientation.VERTICAL);
|
|
|
- _content_pane.pack1(_editor_pane, true, false);
|
|
|
- _content_pane.pack2(_console_view, false, false);
|
|
|
+ _user = new User();
|
|
|
+ _panel_new_project = new PanelNewProject(this, _user, _project);
|
|
|
|
|
|
- _inspector_pane = new Gtk.Paned(Gtk.Orientation.VERTICAL);
|
|
|
- _inspector_pane.pack1(_level_tree_view_notebook, true, false);
|
|
|
- _inspector_pane.pack2(_properties_view, false, false);
|
|
|
+ _panel_welcome = new PanelWelcome();
|
|
|
+ _panel_projects_list = new PanelProjectsList(this, _user);
|
|
|
+ _panel_welcome.pack_start(_panel_projects_list);
|
|
|
+ _panel_welcome.set_visible(true); // To make Gtk.Stack work...
|
|
|
|
|
|
- _main_pane = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
|
|
- _main_pane.pack1(_content_pane, true, false);
|
|
|
- _main_pane.pack2(_inspector_slide, false, false);
|
|
|
+ _main_stack = new Gtk.Stack();
|
|
|
+ _main_stack.add_named(_panel_welcome, "panel_welcome");
|
|
|
+ _main_stack.add_named(_panel_new_project, "panel_new_project");
|
|
|
+ _main_stack.add_named(_main_vbox, "main_vbox");
|
|
|
|
|
|
- _statusbar = new Statusbar();
|
|
|
+ load_settings();
|
|
|
+ _user.load(_user_file.get_path());
|
|
|
+
|
|
|
+ if (_source_dir == null)
|
|
|
+ {
|
|
|
+ show_panel("panel_welcome");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ show_panel("main_vbox");
|
|
|
+ restart_compiler(_source_dir, _level_resource);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- _main_vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
|
- _main_vbox.pack_start(_main_pane, true, true, 0);
|
|
|
- _main_vbox.pack_start(_statusbar, false, false, 0);
|
|
|
- _main_vbox.set_visible(true);
|
|
|
+ public void load_settings()
|
|
|
+ {
|
|
|
+ Hashtable settings = SJSON.load(_settings_file.get_path());
|
|
|
|
|
|
- _file_filter = new Gtk.FileFilter();
|
|
|
- _file_filter.set_filter_name("Level (*.level)");
|
|
|
- _file_filter.add_pattern("*.level");
|
|
|
+ _preferences_dialog.load(settings.has_key("preferences") ? (Hashtable)settings["preferences"] : new Hashtable());
|
|
|
+ }
|
|
|
|
|
|
- _user = new User();
|
|
|
- _panel_new_project = new PanelNewProject(this, _user, _project);
|
|
|
+ public void save_settings()
|
|
|
+ {
|
|
|
+ Hashtable preferences = new Hashtable();
|
|
|
+ _preferences_dialog.save(preferences);
|
|
|
|
|
|
- _panel_welcome = new PanelWelcome();
|
|
|
- _panel_projects_list = new PanelProjectsList(this, _user);
|
|
|
- _panel_welcome.pack_start(_panel_projects_list);
|
|
|
- _panel_welcome.set_visible(true); // To make Gtk.Stack work...
|
|
|
+ Hashtable settings = new Hashtable();
|
|
|
+ settings["preferences"] = preferences;
|
|
|
|
|
|
- _main_stack = new Gtk.Stack();
|
|
|
- _main_stack.add_named(_panel_welcome, "panel_welcome");
|
|
|
- _main_stack.add_named(_panel_new_project, "panel_new_project");
|
|
|
- _main_stack.add_named(_main_vbox, "main_vbox");
|
|
|
+ SJSON.save(settings, _settings_file.get_path());
|
|
|
+ }
|
|
|
|
|
|
- load_settings();
|
|
|
- _user.load(_user_file.get_path());
|
|
|
+ protected override void activate()
|
|
|
+ {
|
|
|
+ if (this.active_window == null)
|
|
|
+ {
|
|
|
+ LevelEditorWindow win = new LevelEditorWindow(this);
|
|
|
+ win.set_default_size(WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT);
|
|
|
+ win.add(_main_stack);
|
|
|
|
|
|
- if (_source_dir == null)
|
|
|
+ try
|
|
|
{
|
|
|
- show_panel("panel_welcome");
|
|
|
+ win.icon = IconTheme.get_default().load_icon("pepper", 48, 0);
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- show_panel("main_vbox");
|
|
|
- restart_compiler(_source_dir, _level_resource);
|
|
|
+ loge(e.message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void load_settings()
|
|
|
+ this.active_window.show_all();
|
|
|
+ this.active_window.maximize();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override bool local_command_line(ref unowned string[] args, out int exit_status)
|
|
|
+ {
|
|
|
+ if (args.length > 1)
|
|
|
{
|
|
|
- Hashtable settings = SJSON.load(_settings_file.get_path());
|
|
|
+ if (!GLib.FileUtils.test(args[1], FileTest.EXISTS) || !GLib.FileUtils.test(args[1], FileTest.IS_DIR))
|
|
|
+ {
|
|
|
+ loge("Source directory does not exist or it is not a directory");
|
|
|
+ exit_status = 1;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- _preferences_dialog.load(settings.has_key("preferences") ? (Hashtable)settings["preferences"] : new Hashtable());
|
|
|
+ _source_dir = args[1];
|
|
|
}
|
|
|
|
|
|
- public void save_settings()
|
|
|
+ if (args.length > 2)
|
|
|
{
|
|
|
- Hashtable preferences = new Hashtable();
|
|
|
- _preferences_dialog.save(preferences);
|
|
|
-
|
|
|
- Hashtable settings = new Hashtable();
|
|
|
- settings["preferences"] = preferences;
|
|
|
-
|
|
|
- SJSON.save(settings, _settings_file.get_path());
|
|
|
+ // Validation is done below after the Project object instantiation
|
|
|
+ _level_resource = args[2];
|
|
|
}
|
|
|
|
|
|
- protected override void activate()
|
|
|
+ if (args.length > 3)
|
|
|
{
|
|
|
- if (this.active_window == null)
|
|
|
+ if (!GLib.FileUtils.test(args[3], FileTest.EXISTS) || !GLib.FileUtils.test(args[3], FileTest.IS_DIR))
|
|
|
{
|
|
|
- LevelEditorWindow win = new LevelEditorWindow(this);
|
|
|
- win.set_default_size(WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT);
|
|
|
- win.add(_main_stack);
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- win.icon = IconTheme.get_default().load_icon("pepper", 48, 0);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ loge("Toolchain directory does not exist or it is not a directory");
|
|
|
+ exit_status = 1;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- this.active_window.show_all();
|
|
|
- this.active_window.maximize();
|
|
|
+ _toolchain_dir = args[3];
|
|
|
}
|
|
|
-
|
|
|
- protected override bool local_command_line(ref unowned string[] args, out int exit_status)
|
|
|
+ else
|
|
|
{
|
|
|
- if (args.length > 1)
|
|
|
+ bool found = false;
|
|
|
+
|
|
|
+ /// More desirable paths come first
|
|
|
+ string toolchain_paths[] =
|
|
|
+ {
|
|
|
+ ".",
|
|
|
+ "../..",
|
|
|
+ "../../../samples"
|
|
|
+ };
|
|
|
+
|
|
|
+ for (int i = 0; i < toolchain_paths.length; ++i)
|
|
|
{
|
|
|
- if (!GLib.FileUtils.test(args[1], FileTest.EXISTS) || !GLib.FileUtils.test(args[1], FileTest.IS_DIR))
|
|
|
+ string path = Path.build_filename(toolchain_paths[i], "core");
|
|
|
+
|
|
|
+ // Try to locate the toolchain directory
|
|
|
+ if (GLib.FileUtils.test(path, FileTest.EXISTS) && GLib.FileUtils.test(path, FileTest.IS_DIR))
|
|
|
{
|
|
|
- loge("Source directory does not exist or it is not a directory");
|
|
|
- exit_status = 1;
|
|
|
- return true;
|
|
|
+ _toolchain_dir = toolchain_paths[i];
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- _source_dir = args[1];
|
|
|
}
|
|
|
|
|
|
- if (args.length > 2)
|
|
|
+ if (!found)
|
|
|
{
|
|
|
- // Validation is done below after the Project object instantiation
|
|
|
- _level_resource = args[2];
|
|
|
+ loge("Unable to find the toolchain directory");
|
|
|
+ exit_status = 1;
|
|
|
+ return true;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (args.length > 3)
|
|
|
- {
|
|
|
- if (!GLib.FileUtils.test(args[3], FileTest.EXISTS) || !GLib.FileUtils.test(args[3], FileTest.IS_DIR))
|
|
|
- {
|
|
|
- loge("Toolchain directory does not exist or it is not a directory");
|
|
|
- exit_status = 1;
|
|
|
- return true;
|
|
|
- }
|
|
|
+ exit_status = 0;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- _toolchain_dir = args[3];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bool found = false;
|
|
|
+ protected override int command_line(ApplicationCommandLine command_line)
|
|
|
+ {
|
|
|
+ this.activate();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- /// More desirable paths come first
|
|
|
- string toolchain_paths[] =
|
|
|
- {
|
|
|
- ".",
|
|
|
- "../..",
|
|
|
- "../../../samples"
|
|
|
- };
|
|
|
+ public ConsoleClient? current_selected_client()
|
|
|
+ {
|
|
|
+ if (_combo.get_active_id() == "editor")
|
|
|
+ return _editor;
|
|
|
+ else if (_combo.get_active_id() == "game")
|
|
|
+ return _game;
|
|
|
+ else
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < toolchain_paths.length; ++i)
|
|
|
- {
|
|
|
- string path = Path.build_filename(toolchain_paths[i], "core");
|
|
|
+ private void on_resource_browser_resource_selected(string type, string name)
|
|
|
+ {
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable(type, name));
|
|
|
+ activate_action("tool", new GLib.Variant.string("place"));
|
|
|
+ }
|
|
|
|
|
|
- // Try to locate the toolchain directory
|
|
|
- if (GLib.FileUtils.test(path, FileTest.EXISTS) && GLib.FileUtils.test(path, FileTest.IS_DIR))
|
|
|
- {
|
|
|
- _toolchain_dir = toolchain_paths[i];
|
|
|
- found = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ private void on_compiler_connected(string address, int port)
|
|
|
+ {
|
|
|
+ logi("Connected to data_compiler@%s:%d".printf(address, port));
|
|
|
+ _compiler.receive_async();
|
|
|
+ }
|
|
|
|
|
|
- if (!found)
|
|
|
- {
|
|
|
- loge("Unable to find the toolchain directory");
|
|
|
- exit_status = 1;
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
+ private void on_compiler_disconnected()
|
|
|
+ {
|
|
|
+ logi("Disconnected from data_compiler");
|
|
|
+ }
|
|
|
|
|
|
- exit_status = 0;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ private void on_compiler_disconnected_unexpected()
|
|
|
+ {
|
|
|
+ on_compiler_disconnected();
|
|
|
|
|
|
- protected override int command_line(ApplicationCommandLine command_line)
|
|
|
- {
|
|
|
- this.activate();
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ stop_game();
|
|
|
+ stop_editor();
|
|
|
|
|
|
- public ConsoleClient? current_selected_client()
|
|
|
- {
|
|
|
- if (_combo.get_active_id() == "editor")
|
|
|
- return _editor;
|
|
|
- else if (_combo.get_active_id() == "game")
|
|
|
- return _game;
|
|
|
- else
|
|
|
- return null;
|
|
|
- }
|
|
|
+ // Reset the callback
|
|
|
+ _data_compiler.finished(false);
|
|
|
|
|
|
- private void on_resource_browser_resource_selected(string type, string name)
|
|
|
- {
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable(type, name));
|
|
|
- activate_action("tool", new GLib.Variant.string("place"));
|
|
|
- }
|
|
|
+ _project_slide.show_widget(compiler_crashed_label());
|
|
|
+ _editor_slide.show_widget(compiler_crashed_label());
|
|
|
+ _inspector_slide.show_widget(compiler_crashed_label());
|
|
|
+ }
|
|
|
|
|
|
- private void on_compiler_connected(string address, int port)
|
|
|
- {
|
|
|
- logi("Connected to data_compiler@%s:%d".printf(address, port));
|
|
|
- _compiler.receive_async();
|
|
|
- }
|
|
|
+ private void on_editor_connected(string address, int port)
|
|
|
+ {
|
|
|
+ logi("Connected to level_editor@%s:%d".printf(address, port));
|
|
|
+ _editor.receive_async();
|
|
|
+ }
|
|
|
|
|
|
- private void on_compiler_disconnected()
|
|
|
- {
|
|
|
- logi("Disconnected from data_compiler");
|
|
|
- }
|
|
|
+ private void on_editor_disconnected()
|
|
|
+ {
|
|
|
+ logi("Disconnected from editor");
|
|
|
+ }
|
|
|
|
|
|
- private void on_compiler_disconnected_unexpected()
|
|
|
- {
|
|
|
- on_compiler_disconnected();
|
|
|
+ private void on_editor_disconnected_unexpected()
|
|
|
+ {
|
|
|
+ on_editor_disconnected();
|
|
|
|
|
|
- stop_game();
|
|
|
- stop_editor();
|
|
|
+ Gtk.Label label = new Gtk.Label(null);
|
|
|
+ label.set_markup("Something went wrong.\rTry to <a href=\"restart\">restart</a> this view.");
|
|
|
+ label.activate_link.connect(() => {
|
|
|
+ activate_action("restart", null);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ _editor_slide.show_widget(label);
|
|
|
+ }
|
|
|
|
|
|
- // Reset the callback
|
|
|
- _data_compiler.finished(false);
|
|
|
+ private void on_game_connected(string address, int port)
|
|
|
+ {
|
|
|
+ logi("Connected to game@%s:%d".printf(address, port));
|
|
|
+ _game.receive_async();
|
|
|
+ _combo.set_active_id("game");
|
|
|
+ }
|
|
|
|
|
|
- _project_slide.show_widget(compiler_crashed_label());
|
|
|
- _editor_slide.show_widget(compiler_crashed_label());
|
|
|
- _inspector_slide.show_widget(compiler_crashed_label());
|
|
|
- }
|
|
|
+ private void on_game_disconnected()
|
|
|
+ {
|
|
|
+ logi("Disconnected from game");
|
|
|
+ _project.delete_garbage();
|
|
|
+ _combo.set_active_id("editor");
|
|
|
+ _toolbar_run.icon_name = "game-run";
|
|
|
+ }
|
|
|
|
|
|
- private void on_editor_connected(string address, int port)
|
|
|
- {
|
|
|
- logi("Connected to level_editor@%s:%d".printf(address, port));
|
|
|
- _editor.receive_async();
|
|
|
- }
|
|
|
+ private void on_message_received(ConsoleClient client, uint8[] json)
|
|
|
+ {
|
|
|
+ Hashtable msg = JSON.decode(json) as Hashtable;
|
|
|
+ string msg_type = msg["type"] as string;
|
|
|
|
|
|
- private void on_editor_disconnected()
|
|
|
+ if (msg_type == "message")
|
|
|
{
|
|
|
- logi("Disconnected from editor");
|
|
|
+ log((string)msg["system"], (string)msg["severity"], (string)msg["message"]);
|
|
|
}
|
|
|
-
|
|
|
- private void on_editor_disconnected_unexpected()
|
|
|
+ else if (msg_type == "add_file")
|
|
|
{
|
|
|
- on_editor_disconnected();
|
|
|
+ string path = (string)msg["path"];
|
|
|
|
|
|
- Gtk.Label label = new Gtk.Label(null);
|
|
|
- label.set_markup("Something went wrong.\rTry to <a href=\"restart\">restart</a> this view.");
|
|
|
- label.activate_link.connect(() => {
|
|
|
- activate_action("restart", null);
|
|
|
- return true;
|
|
|
- });
|
|
|
- _editor_slide.show_widget(label);
|
|
|
+ _project.add_file(path);
|
|
|
}
|
|
|
-
|
|
|
- private void on_game_connected(string address, int port)
|
|
|
+ else if (msg_type == "remove_file")
|
|
|
{
|
|
|
- logi("Connected to game@%s:%d".printf(address, port));
|
|
|
- _game.receive_async();
|
|
|
- _combo.set_active_id("game");
|
|
|
- }
|
|
|
+ string path = (string)msg["path"];
|
|
|
|
|
|
- private void on_game_disconnected()
|
|
|
+ _project.remove_file(path);
|
|
|
+ }
|
|
|
+ else if (msg_type == "add_tree")
|
|
|
{
|
|
|
- logi("Disconnected from game");
|
|
|
- _project.delete_garbage();
|
|
|
- _combo.set_active_id("editor");
|
|
|
- _toolbar_run.icon_name = "game-run";
|
|
|
+ string path = (string)msg["path"];
|
|
|
+
|
|
|
+ _project.add_tree(path);
|
|
|
}
|
|
|
+ else if (msg_type == "remove_tree")
|
|
|
+ {
|
|
|
+ string path = (string)msg["path"];
|
|
|
|
|
|
- private void on_message_received(ConsoleClient client, uint8[] json)
|
|
|
+ _project.remove_tree(path);
|
|
|
+ }
|
|
|
+ else if (msg_type == "compile")
|
|
|
{
|
|
|
- Hashtable msg = JSON.decode(json) as Hashtable;
|
|
|
- string msg_type = msg["type"] as string;
|
|
|
+ // Guid id = Guid.parse((string)msg["id"]);
|
|
|
|
|
|
- if (msg_type == "message")
|
|
|
+ if (msg.has_key("start"))
|
|
|
{
|
|
|
- log((string)msg["system"], (string)msg["severity"], (string)msg["message"]);
|
|
|
+ // FIXME
|
|
|
}
|
|
|
- else if (msg_type == "add_file")
|
|
|
+ else if (msg.has_key("success"))
|
|
|
{
|
|
|
- string path = (string)msg["path"];
|
|
|
-
|
|
|
- _project.add_file(path);
|
|
|
+ _data_compiler.finished((bool)msg["success"]);
|
|
|
}
|
|
|
- else if (msg_type == "remove_file")
|
|
|
- {
|
|
|
- string path = (string)msg["path"];
|
|
|
+ }
|
|
|
+ else if (msg_type == "unit_spawned")
|
|
|
+ {
|
|
|
+ string id = (string) msg["id"];
|
|
|
+ string name = (string) msg["name"];
|
|
|
+ ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
|
|
|
+ ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
|
|
|
+ ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
|
|
|
|
|
|
- _project.remove_file(path);
|
|
|
- }
|
|
|
- else if (msg_type == "add_tree")
|
|
|
- {
|
|
|
- string path = (string)msg["path"];
|
|
|
+ _level.on_unit_spawned(Guid.parse(id)
|
|
|
+ , name
|
|
|
+ , Vector3.from_array(pos)
|
|
|
+ , Quaternion.from_array(rot)
|
|
|
+ , Vector3.from_array(scl)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if (msg_type == "sound_spawned")
|
|
|
+ {
|
|
|
+ string id = (string) msg["id"];
|
|
|
+ string name = (string) msg["name"];
|
|
|
+ ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
|
|
|
+ ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
|
|
|
+ ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
|
|
|
+ double range = (double) msg["range"];
|
|
|
+ double volume = (double) msg["volume"];
|
|
|
+ bool loop = (bool) msg["loop"];
|
|
|
+
|
|
|
+ _level.on_sound_spawned(Guid.parse(id)
|
|
|
+ , name
|
|
|
+ , Vector3.from_array(pos)
|
|
|
+ , Quaternion.from_array(rot)
|
|
|
+ , Vector3.from_array(scl)
|
|
|
+ , range
|
|
|
+ , volume
|
|
|
+ , loop
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if (msg_type == "move_objects")
|
|
|
+ {
|
|
|
+ Hashtable ids = (Hashtable)msg["ids"];
|
|
|
+ Hashtable new_positions = (Hashtable)msg["new_positions"];
|
|
|
+ Hashtable new_rotations = (Hashtable)msg["new_rotations"];
|
|
|
+ Hashtable new_scales = (Hashtable)msg["new_scales"];
|
|
|
|
|
|
- _project.add_tree(path);
|
|
|
- }
|
|
|
- else if (msg_type == "remove_tree")
|
|
|
- {
|
|
|
- string path = (string)msg["path"];
|
|
|
+ ArrayList<string> keys = new ArrayList<string>.wrap(ids.keys.to_array());
|
|
|
+ keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
|
|
|
|
|
|
- _project.remove_tree(path);
|
|
|
- }
|
|
|
- else if (msg_type == "compile")
|
|
|
- {
|
|
|
- // Guid id = Guid.parse((string)msg["id"]);
|
|
|
+ Guid[] n_ids = new Guid[keys.size];
|
|
|
+ Vector3[] n_positions = new Vector3[keys.size];
|
|
|
+ Quaternion[] n_rotations = new Quaternion[keys.size];
|
|
|
+ Vector3[] n_scales = new Vector3[keys.size];
|
|
|
|
|
|
- if (msg.has_key("start"))
|
|
|
- {
|
|
|
- // FIXME
|
|
|
- }
|
|
|
- else if (msg.has_key("success"))
|
|
|
- {
|
|
|
- _data_compiler.finished((bool)msg["success"]);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (msg_type == "unit_spawned")
|
|
|
- {
|
|
|
- string id = (string) msg["id"];
|
|
|
- string name = (string) msg["name"];
|
|
|
- ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
|
|
|
- ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
|
|
|
- ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
|
|
|
-
|
|
|
- _level.on_unit_spawned(Guid.parse(id)
|
|
|
- , name
|
|
|
- , Vector3.from_array(pos)
|
|
|
- , Quaternion.from_array(rot)
|
|
|
- , Vector3.from_array(scl)
|
|
|
- );
|
|
|
- }
|
|
|
- else if (msg_type == "sound_spawned")
|
|
|
+ for (int i = 0; i < keys.size; ++i)
|
|
|
{
|
|
|
- string id = (string) msg["id"];
|
|
|
- string name = (string) msg["name"];
|
|
|
- ArrayList<Value?> pos = (ArrayList<Value?>)msg["position"];
|
|
|
- ArrayList<Value?> rot = (ArrayList<Value?>)msg["rotation"];
|
|
|
- ArrayList<Value?> scl = (ArrayList<Value?>)msg["scale"];
|
|
|
- double range = (double) msg["range"];
|
|
|
- double volume = (double) msg["volume"];
|
|
|
- bool loop = (bool) msg["loop"];
|
|
|
-
|
|
|
- _level.on_sound_spawned(Guid.parse(id)
|
|
|
- , name
|
|
|
- , Vector3.from_array(pos)
|
|
|
- , Quaternion.from_array(rot)
|
|
|
- , Vector3.from_array(scl)
|
|
|
- , range
|
|
|
- , volume
|
|
|
- , loop
|
|
|
- );
|
|
|
- }
|
|
|
- else if (msg_type == "move_objects")
|
|
|
- {
|
|
|
- Hashtable ids = (Hashtable)msg["ids"];
|
|
|
- Hashtable new_positions = (Hashtable)msg["new_positions"];
|
|
|
- Hashtable new_rotations = (Hashtable)msg["new_rotations"];
|
|
|
- Hashtable new_scales = (Hashtable)msg["new_scales"];
|
|
|
-
|
|
|
- ArrayList<string> keys = new ArrayList<string>.wrap(ids.keys.to_array());
|
|
|
- keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
|
|
|
-
|
|
|
- Guid[] n_ids = new Guid[keys.size];
|
|
|
- Vector3[] n_positions = new Vector3[keys.size];
|
|
|
- Quaternion[] n_rotations = new Quaternion[keys.size];
|
|
|
- Vector3[] n_scales = new Vector3[keys.size];
|
|
|
-
|
|
|
- for (int i = 0; i < keys.size; ++i)
|
|
|
- {
|
|
|
- string k = keys[i];
|
|
|
-
|
|
|
- n_ids[i] = Guid.parse((string)ids[k]);
|
|
|
- n_positions[i] = Vector3.from_array((ArrayList<Value?>)(new_positions[k]));
|
|
|
- n_rotations[i] = Quaternion.from_array((ArrayList<Value?>)new_rotations[k]);
|
|
|
- n_scales[i] = Vector3.from_array((ArrayList<Value?>)new_scales[k]);
|
|
|
- }
|
|
|
+ string k = keys[i];
|
|
|
|
|
|
- _level.on_move_objects(n_ids, n_positions, n_rotations, n_scales);
|
|
|
+ n_ids[i] = Guid.parse((string)ids[k]);
|
|
|
+ n_positions[i] = Vector3.from_array((ArrayList<Value?>)(new_positions[k]));
|
|
|
+ n_rotations[i] = Quaternion.from_array((ArrayList<Value?>)new_rotations[k]);
|
|
|
+ n_scales[i] = Vector3.from_array((ArrayList<Value?>)new_scales[k]);
|
|
|
}
|
|
|
- else if (msg_type == "selection")
|
|
|
- {
|
|
|
- Hashtable objects = (Hashtable)msg["objects"];
|
|
|
|
|
|
- ArrayList<string> keys = new ArrayList<string>.wrap(objects.keys.to_array());
|
|
|
- keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
|
|
|
+ _level.on_move_objects(n_ids, n_positions, n_rotations, n_scales);
|
|
|
+ }
|
|
|
+ else if (msg_type == "selection")
|
|
|
+ {
|
|
|
+ Hashtable objects = (Hashtable)msg["objects"];
|
|
|
|
|
|
- Guid[] ids = new Guid[keys.size];
|
|
|
+ ArrayList<string> keys = new ArrayList<string>.wrap(objects.keys.to_array());
|
|
|
+ keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
|
|
|
|
|
|
- for (int i = 0; i < keys.size; ++i)
|
|
|
- {
|
|
|
- string k = keys[i];
|
|
|
- ids[i] = Guid.parse((string)objects[k]);
|
|
|
- }
|
|
|
+ Guid[] ids = new Guid[keys.size];
|
|
|
|
|
|
- _level.on_selection(ids);
|
|
|
- }
|
|
|
- else if (msg_type == "error")
|
|
|
- {
|
|
|
- loge((string)msg["message"]);
|
|
|
- }
|
|
|
- else
|
|
|
+ for (int i = 0; i < keys.size; ++i)
|
|
|
{
|
|
|
- loge("Unknown message type: " + msg_type);
|
|
|
+ string k = keys[i];
|
|
|
+ ids[i] = Guid.parse((string)objects[k]);
|
|
|
}
|
|
|
|
|
|
- // Receive next message
|
|
|
- client.receive_async();
|
|
|
+ _level.on_selection(ids);
|
|
|
}
|
|
|
-
|
|
|
- private void send_state()
|
|
|
+ else if (msg_type == "error")
|
|
|
{
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append(LevelEditorApi.set_grid_size(_grid_size));
|
|
|
- sb.append(LevelEditorApi.set_rotation_snap(_rotation_snap));
|
|
|
- sb.append(LevelEditorApi.enable_show_grid(_show_grid));
|
|
|
- sb.append(LevelEditorApi.enable_snap_to_grid(_snap_to_grid));
|
|
|
- sb.append(LevelEditorApi.enable_debug_render_world(_debug_render_world));
|
|
|
- sb.append(LevelEditorApi.enable_debug_physics_world(_debug_physics_world));
|
|
|
- sb.append(LevelEditorApi.set_tool_type(_tool_type));
|
|
|
- sb.append(LevelEditorApi.set_snap_mode(_snap_mode));
|
|
|
- sb.append(LevelEditorApi.set_reference_system(_reference_system));
|
|
|
- _editor.send_script(sb.str);
|
|
|
+ loge((string)msg["message"]);
|
|
|
}
|
|
|
-
|
|
|
- private bool on_button_press(Gdk.EventButton ev)
|
|
|
+ else
|
|
|
{
|
|
|
- return Gdk.EVENT_STOP;
|
|
|
+ loge("Unknown message type: " + msg_type);
|
|
|
}
|
|
|
|
|
|
- private bool on_button_release(Gdk.EventButton ev)
|
|
|
- {
|
|
|
- return Gdk.EVENT_STOP;
|
|
|
- }
|
|
|
+ // Receive next message
|
|
|
+ client.receive_async();
|
|
|
+ }
|
|
|
|
|
|
- Gtk.Widget starting_compiler_label()
|
|
|
- {
|
|
|
- return new Gtk.Label("Compiling resources, please wait...");
|
|
|
- }
|
|
|
+ private void send_state()
|
|
|
+ {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(LevelEditorApi.set_grid_size(_grid_size));
|
|
|
+ sb.append(LevelEditorApi.set_rotation_snap(_rotation_snap));
|
|
|
+ sb.append(LevelEditorApi.enable_show_grid(_show_grid));
|
|
|
+ sb.append(LevelEditorApi.enable_snap_to_grid(_snap_to_grid));
|
|
|
+ sb.append(LevelEditorApi.enable_debug_render_world(_debug_render_world));
|
|
|
+ sb.append(LevelEditorApi.enable_debug_physics_world(_debug_physics_world));
|
|
|
+ sb.append(LevelEditorApi.set_tool_type(_tool_type));
|
|
|
+ sb.append(LevelEditorApi.set_snap_mode(_snap_mode));
|
|
|
+ sb.append(LevelEditorApi.set_reference_system(_reference_system));
|
|
|
+ _editor.send_script(sb.str);
|
|
|
+ }
|
|
|
|
|
|
- Gtk.Widget compiler_crashed_label()
|
|
|
- {
|
|
|
- Gtk.Label label = new Gtk.Label(null);
|
|
|
- label.set_markup("Data Compiler disconnected.\rTry to <a href=\"restart\">restart</a> compiler to continue.");
|
|
|
- label.activate_link.connect(() => {
|
|
|
- restart_compiler(_project.source_dir(), _level._filename);
|
|
|
- return true;
|
|
|
- });
|
|
|
+ private bool on_button_press(Gdk.EventButton ev)
|
|
|
+ {
|
|
|
+ return Gdk.EVENT_STOP;
|
|
|
+ }
|
|
|
|
|
|
- return label;
|
|
|
- }
|
|
|
+ private bool on_button_release(Gdk.EventButton ev)
|
|
|
+ {
|
|
|
+ return Gdk.EVENT_STOP;
|
|
|
+ }
|
|
|
|
|
|
- Gtk.Widget compiler_failed_compilation_label()
|
|
|
- {
|
|
|
- Gtk.Label label = new Gtk.Label(null);
|
|
|
- label.set_markup("Data compilation failed.\rFix errors and <a href=\"restart\">restart</a> compiler to continue.");
|
|
|
- label.activate_link.connect(() => {
|
|
|
- restart_compiler(_project.source_dir(), _level._filename);
|
|
|
- return true;
|
|
|
- });
|
|
|
+ Gtk.Widget starting_compiler_label()
|
|
|
+ {
|
|
|
+ return new Gtk.Label("Compiling resources, please wait...");
|
|
|
+ }
|
|
|
|
|
|
- return label;
|
|
|
- }
|
|
|
+ Gtk.Widget compiler_crashed_label()
|
|
|
+ {
|
|
|
+ Gtk.Label label = new Gtk.Label(null);
|
|
|
+ label.set_markup("Data Compiler disconnected.\rTry to <a href=\"restart\">restart</a> compiler to continue.");
|
|
|
+ label.activate_link.connect(() => {
|
|
|
+ restart_compiler(_project.source_dir(), _level._filename);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
|
|
|
- public void restart_compiler(string source_dir, string? level_resource)
|
|
|
- {
|
|
|
- stop_compiler();
|
|
|
+ return label;
|
|
|
+ }
|
|
|
|
|
|
- _project.load(source_dir);
|
|
|
- if (level_resource != null)
|
|
|
- _level.load(Path.build_filename(_project.source_dir(), level_resource + ".level"));
|
|
|
- else
|
|
|
- _level.load_empty_level();
|
|
|
+ Gtk.Widget compiler_failed_compilation_label()
|
|
|
+ {
|
|
|
+ Gtk.Label label = new Gtk.Label(null);
|
|
|
+ label.set_markup("Data compilation failed.\rFix errors and <a href=\"restart\">restart</a> compiler to continue.");
|
|
|
+ label.activate_link.connect(() => {
|
|
|
+ restart_compiler(_project.source_dir(), _level._filename);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
|
|
|
- _project_slide.show_widget(starting_compiler_label());
|
|
|
- _editor_slide.show_widget(starting_compiler_label());
|
|
|
- _inspector_slide.show_widget(starting_compiler_label());
|
|
|
+ return label;
|
|
|
+ }
|
|
|
|
|
|
- string args[] =
|
|
|
- {
|
|
|
- ENGINE_EXE,
|
|
|
- "--source-dir", _project.source_dir(),
|
|
|
- "--data-dir", _project.data_dir(),
|
|
|
- "--map-source-dir", "core", _project.toolchain_dir(),
|
|
|
- "--server",
|
|
|
- "--wait-console",
|
|
|
- null
|
|
|
- };
|
|
|
-
|
|
|
- GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
- sl.set_cwd(ENGINE_DIR);
|
|
|
- try
|
|
|
- {
|
|
|
- _compiler_process = sl.spawnv(args);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ public void restart_compiler(string source_dir, string? level_resource)
|
|
|
+ {
|
|
|
+ stop_compiler();
|
|
|
|
|
|
- // It is an error if compiler disconnects after here.
|
|
|
- _compiler.disconnected.disconnect(on_compiler_disconnected);
|
|
|
- _compiler.disconnected.connect(on_compiler_disconnected_unexpected);
|
|
|
+ _project.load(source_dir);
|
|
|
+ if (level_resource != null)
|
|
|
+ _level.load(Path.build_filename(_project.source_dir(), level_resource + ".level"));
|
|
|
+ else
|
|
|
+ _level.load_empty_level();
|
|
|
|
|
|
- for (int tries = 0; !_compiler.is_connected() && tries < 5; ++tries)
|
|
|
- {
|
|
|
- _compiler.connect("127.0.0.1", CROWN_DEFAULT_SERVER_PORT);
|
|
|
- GLib.Thread.usleep(250*1000);
|
|
|
- }
|
|
|
+ _project_slide.show_widget(starting_compiler_label());
|
|
|
+ _editor_slide.show_widget(starting_compiler_label());
|
|
|
+ _inspector_slide.show_widget(starting_compiler_label());
|
|
|
|
|
|
- _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
- if (_data_compiler.compile.end(res))
|
|
|
- {
|
|
|
- restart_editor();
|
|
|
+ string args[] =
|
|
|
+ {
|
|
|
+ ENGINE_EXE,
|
|
|
+ "--source-dir", _project.source_dir(),
|
|
|
+ "--data-dir", _project.data_dir(),
|
|
|
+ "--map-source-dir", "core", _project.toolchain_dir(),
|
|
|
+ "--server",
|
|
|
+ "--wait-console",
|
|
|
+ null
|
|
|
+ };
|
|
|
|
|
|
- _project_slide.show_widget(_project_browser);
|
|
|
- _inspector_slide.show_widget(_inspector_pane);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _project_slide.show_widget(compiler_failed_compilation_label());
|
|
|
- _editor_slide.show_widget(compiler_failed_compilation_label());
|
|
|
- _inspector_slide.show_widget(compiler_failed_compilation_label());
|
|
|
- }
|
|
|
- });
|
|
|
+ GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
+ sl.set_cwd(ENGINE_DIR);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _compiler_process = sl.spawnv(args);
|
|
|
}
|
|
|
-
|
|
|
- private void stop_compiler()
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- _level.reset();
|
|
|
- _project.reset();
|
|
|
+ loge(e.message);
|
|
|
+ }
|
|
|
|
|
|
- stop_game();
|
|
|
- stop_editor();
|
|
|
+ // It is an error if compiler disconnects after here.
|
|
|
+ _compiler.disconnected.disconnect(on_compiler_disconnected);
|
|
|
+ _compiler.disconnected.connect(on_compiler_disconnected_unexpected);
|
|
|
+
|
|
|
+ for (int tries = 0; !_compiler.is_connected() && tries < 5; ++tries)
|
|
|
+ {
|
|
|
+ _compiler.connect("127.0.0.1", CROWN_DEFAULT_SERVER_PORT);
|
|
|
+ GLib.Thread.usleep(250*1000);
|
|
|
+ }
|
|
|
|
|
|
- if (_compiler != null)
|
|
|
+ _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
+ if (_data_compiler.compile.end(res))
|
|
|
{
|
|
|
- // Explicit call to this function should not produce error messages.
|
|
|
- _compiler.disconnected.disconnect(on_compiler_disconnected_unexpected);
|
|
|
- _compiler.disconnected.connect(on_compiler_disconnected);
|
|
|
+ restart_editor();
|
|
|
|
|
|
- _compiler.send(DataCompilerApi.quit());
|
|
|
- _compiler.close();
|
|
|
+ _project_slide.show_widget(_project_browser);
|
|
|
+ _inspector_slide.show_widget(_inspector_pane);
|
|
|
}
|
|
|
-
|
|
|
- if (_compiler_process != null)
|
|
|
+ else
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- _compiler_process.wait();
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ _project_slide.show_widget(compiler_failed_compilation_label());
|
|
|
+ _editor_slide.show_widget(compiler_failed_compilation_label());
|
|
|
+ _inspector_slide.show_widget(compiler_failed_compilation_label());
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stop_compiler()
|
|
|
+ {
|
|
|
+ _level.reset();
|
|
|
+ _project.reset();
|
|
|
|
|
|
- private void start_editor(uint window_xid)
|
|
|
+ stop_game();
|
|
|
+ stop_editor();
|
|
|
+
|
|
|
+ if (_compiler != null)
|
|
|
{
|
|
|
- if (window_xid == 0)
|
|
|
- return;
|
|
|
+ // Explicit call to this function should not produce error messages.
|
|
|
+ _compiler.disconnected.disconnect(on_compiler_disconnected_unexpected);
|
|
|
+ _compiler.disconnected.connect(on_compiler_disconnected);
|
|
|
|
|
|
- string args[] =
|
|
|
- {
|
|
|
- ENGINE_EXE,
|
|
|
- "--data-dir", _project.data_dir(),
|
|
|
- "--boot-dir", LEVEL_EDITOR_BOOT_DIR,
|
|
|
- "--parent-window", window_xid.to_string(),
|
|
|
- "--wait-console",
|
|
|
- null
|
|
|
- };
|
|
|
+ _compiler.send(DataCompilerApi.quit());
|
|
|
+ _compiler.close();
|
|
|
+ }
|
|
|
|
|
|
- GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
- sl.set_cwd(ENGINE_DIR);
|
|
|
+ if (_compiler_process != null)
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
- _editor_process = sl.spawnv(args);
|
|
|
+ _compiler_process.wait();
|
|
|
}
|
|
|
catch (Error e)
|
|
|
{
|
|
|
loge(e.message);
|
|
|
}
|
|
|
-
|
|
|
- // It is an error if editor disconnects after here.
|
|
|
- _editor.disconnected.disconnect(on_editor_disconnected);
|
|
|
- _editor.disconnected.connect(on_editor_disconnected_unexpected);
|
|
|
-
|
|
|
- for (int tries = 0; !_editor.is_connected() && tries < 10; ++tries)
|
|
|
- {
|
|
|
- _editor.connect("127.0.0.1", 10001);
|
|
|
- GLib.Thread.usleep(500*1000);
|
|
|
- }
|
|
|
-
|
|
|
- _level.send_level();
|
|
|
- send_state();
|
|
|
- _preferences_dialog.apply();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void stop_editor()
|
|
|
- {
|
|
|
- _resource_chooser.stop_editor();
|
|
|
-
|
|
|
- if (_editor != null)
|
|
|
- {
|
|
|
- // Explicit call to this function should not produce error messages.
|
|
|
- _editor.disconnected.disconnect(on_editor_disconnected_unexpected);
|
|
|
- _editor.disconnected.connect(on_editor_disconnected);
|
|
|
-
|
|
|
- _editor.send_script("Device.quit()");
|
|
|
- _editor.close();
|
|
|
- }
|
|
|
+ private void start_editor(uint window_xid)
|
|
|
+ {
|
|
|
+ if (window_xid == 0)
|
|
|
+ return;
|
|
|
|
|
|
- if (_editor_process != null)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- _editor_process.wait();
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
- }
|
|
|
+ string args[] =
|
|
|
+ {
|
|
|
+ ENGINE_EXE,
|
|
|
+ "--data-dir", _project.data_dir(),
|
|
|
+ "--boot-dir", LEVEL_EDITOR_BOOT_DIR,
|
|
|
+ "--parent-window", window_xid.to_string(),
|
|
|
+ "--wait-console",
|
|
|
+ null
|
|
|
+ };
|
|
|
|
|
|
- _editor_slide.show_widget(new Gtk.Label("Disconnected."));
|
|
|
+ GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
+ sl.set_cwd(ENGINE_DIR);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _editor_process = sl.spawnv(args);
|
|
|
}
|
|
|
-
|
|
|
- private void restart_editor()
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- stop_editor();
|
|
|
+ loge(e.message);
|
|
|
+ }
|
|
|
|
|
|
- if (_editor_view != null)
|
|
|
- {
|
|
|
- _editor_view_overlay.remove(_editor_view);
|
|
|
- _editor_view = null;
|
|
|
- }
|
|
|
+ // It is an error if editor disconnects after here.
|
|
|
+ _editor.disconnected.disconnect(on_editor_disconnected);
|
|
|
+ _editor.disconnected.connect(on_editor_disconnected_unexpected);
|
|
|
|
|
|
- _editor_view = new EditorView(_editor);
|
|
|
- _editor_view.realized.connect(on_editor_view_realized);
|
|
|
- _editor_view.button_press_event.connect(on_button_press);
|
|
|
- _editor_view.button_release_event.connect(on_button_release);
|
|
|
+ for (int tries = 0; !_editor.is_connected() && tries < 10; ++tries)
|
|
|
+ {
|
|
|
+ _editor.connect("127.0.0.1", 10001);
|
|
|
+ GLib.Thread.usleep(500*1000);
|
|
|
+ }
|
|
|
|
|
|
- _editor_view_overlay.add(_editor_view);
|
|
|
- _editor_slide.show_widget(_editor_view_overlay);
|
|
|
+ _level.send_level();
|
|
|
+ send_state();
|
|
|
+ _preferences_dialog.apply();
|
|
|
+ }
|
|
|
|
|
|
- _resource_chooser.restart_editor();
|
|
|
- }
|
|
|
+ private void stop_editor()
|
|
|
+ {
|
|
|
+ _resource_chooser.stop_editor();
|
|
|
|
|
|
- private void start_game(StartGame sg)
|
|
|
+ if (_editor != null)
|
|
|
{
|
|
|
- _project.dump_test_level(_database);
|
|
|
+ // Explicit call to this function should not produce error messages.
|
|
|
+ _editor.disconnected.disconnect(on_editor_disconnected_unexpected);
|
|
|
+ _editor.disconnected.connect(on_editor_disconnected);
|
|
|
|
|
|
- _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
- if (_data_compiler.compile.end(res))
|
|
|
- {
|
|
|
- string args[] =
|
|
|
- {
|
|
|
- ENGINE_EXE,
|
|
|
- "--data-dir", _project.data_dir(),
|
|
|
- "--console-port", "12345",
|
|
|
- "--wait-console",
|
|
|
- "--lua-string", sg == StartGame.TEST ? "TEST=true" : "",
|
|
|
- null
|
|
|
- };
|
|
|
-
|
|
|
- GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
- sl.set_cwd(ENGINE_DIR);
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- _game_process = sl.spawnv(args);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
-
|
|
|
- for (int tries = 0; !_game.is_connected() && tries < 10; ++tries)
|
|
|
- {
|
|
|
- _game.connect("127.0.0.1", 12345);
|
|
|
- GLib.Thread.usleep(500*1000);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _toolbar_run.icon_name = "game-run";
|
|
|
- }
|
|
|
- });
|
|
|
+ _editor.send_script("Device.quit()");
|
|
|
+ _editor.close();
|
|
|
}
|
|
|
|
|
|
- private void stop_game()
|
|
|
+ if (_editor_process != null)
|
|
|
{
|
|
|
- if (_game != null)
|
|
|
+ try
|
|
|
{
|
|
|
- _game.send_script("Device.quit()");
|
|
|
- _game.close();
|
|
|
+ _editor_process.wait();
|
|
|
}
|
|
|
-
|
|
|
- if (_game_process != null)
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- _game_process.wait();
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ loge(e.message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void deploy_game()
|
|
|
+ _editor_slide.show_widget(new Gtk.Label("Disconnected."));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void restart_editor()
|
|
|
+ {
|
|
|
+ stop_editor();
|
|
|
+
|
|
|
+ if (_editor_view != null)
|
|
|
{
|
|
|
- Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Select destination directory..."
|
|
|
- , this.active_window
|
|
|
- , FileChooserAction.SELECT_FOLDER
|
|
|
- , "Cancel"
|
|
|
- , ResponseType.CANCEL
|
|
|
- , "Open"
|
|
|
- , ResponseType.ACCEPT
|
|
|
- );
|
|
|
+ _editor_view_overlay.remove(_editor_view);
|
|
|
+ _editor_view = null;
|
|
|
+ }
|
|
|
|
|
|
- if (fcd.run() == ResponseType.ACCEPT)
|
|
|
- {
|
|
|
- GLib.File data_dir = File.new_for_path(fcd.get_filename());
|
|
|
+ _editor_view = new EditorView(_editor);
|
|
|
+ _editor_view.realized.connect(on_editor_view_realized);
|
|
|
+ _editor_view.button_press_event.connect(on_button_press);
|
|
|
+ _editor_view.button_release_event.connect(on_button_release);
|
|
|
+
|
|
|
+ _editor_view_overlay.add(_editor_view);
|
|
|
+ _editor_slide.show_widget(_editor_view_overlay);
|
|
|
+
|
|
|
+ _resource_chooser.restart_editor();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void start_game(StartGame sg)
|
|
|
+ {
|
|
|
+ _project.dump_test_level(_database);
|
|
|
|
|
|
+ _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
+ if (_data_compiler.compile.end(res))
|
|
|
+ {
|
|
|
string args[] =
|
|
|
{
|
|
|
ENGINE_EXE,
|
|
|
- "--source-dir", _project.source_dir(),
|
|
|
- "--map-source-dir", "core", _project.toolchain_dir(),
|
|
|
- "--data-dir", data_dir.get_path(),
|
|
|
- "--compile",
|
|
|
+ "--data-dir", _project.data_dir(),
|
|
|
+ "--console-port", "12345",
|
|
|
+ "--wait-console",
|
|
|
+ "--lua-string", sg == StartGame.TEST ? "TEST=true" : "",
|
|
|
null
|
|
|
};
|
|
|
|
|
|
GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
sl.set_cwd(ENGINE_DIR);
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
- GLib.Subprocess compiler = sl.spawnv(args);
|
|
|
- compiler.wait();
|
|
|
- if (compiler.get_exit_status() == 0)
|
|
|
- {
|
|
|
- string game_name = DEPLOY_DEFAULT_NAME;
|
|
|
- GLib.File engine_exe_src = File.new_for_path(DEPLOY_EXE);
|
|
|
- GLib.File engine_exe_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), game_name + EXE_SUFFIX));
|
|
|
- engine_exe_src.copy(engine_exe_dst, FileCopyFlags.OVERWRITE);
|
|
|
-
|
|
|
-#if CROWN_PLATFORM_WINDOWS
|
|
|
- string lua51_name = "lua51.dll";
|
|
|
- GLib.File lua51_dll_src = File.new_for_path(lua51_name);
|
|
|
- GLib.File lua51_dll_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), lua51_name));
|
|
|
- lua51_dll_src.copy(lua51_dll_dst, FileCopyFlags.OVERWRITE);
|
|
|
-
|
|
|
- string openal_name = "openal-release.dll";
|
|
|
- GLib.File openal_dll_src = File.new_for_path(openal_name);
|
|
|
- GLib.File openal_dll_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), openal_name));
|
|
|
- openal_dll_src.copy(openal_dll_dst, FileCopyFlags.OVERWRITE);
|
|
|
-#endif // CROWN_PLATFORM_WINDOWS
|
|
|
-
|
|
|
- logi("Project deployed to `%s`".printf(data_dir.get_path()));
|
|
|
- }
|
|
|
+ _game_process = sl.spawnv(args);
|
|
|
}
|
|
|
catch (Error e)
|
|
|
{
|
|
|
- logi("%s".printf(e.message));
|
|
|
- logi("Failed to deploy project");
|
|
|
+ loge(e.message);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- fcd.destroy();
|
|
|
- }
|
|
|
-
|
|
|
- private void on_editor_view_realized()
|
|
|
- {
|
|
|
- start_editor(_editor_view.window_id);
|
|
|
- }
|
|
|
-
|
|
|
- private void on_tool_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- string name = param.get_string();
|
|
|
- if (name == "place")
|
|
|
- _tool_type = LevelEditorApi.ToolType.PLACE;
|
|
|
- else if (name == "move")
|
|
|
- _tool_type = LevelEditorApi.ToolType.MOVE;
|
|
|
- else if (name == "rotate")
|
|
|
- _tool_type = LevelEditorApi.ToolType.ROTATE;
|
|
|
- else if (name == "scale")
|
|
|
- _tool_type = LevelEditorApi.ToolType.SCALE;
|
|
|
-
|
|
|
- send_state();
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
-
|
|
|
- private void on_snap_mode_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- string name = param.get_string();
|
|
|
- if (name == "relative")
|
|
|
- _snap_mode = LevelEditorApi.SnapMode.RELATIVE;
|
|
|
- else if (name == "absolute")
|
|
|
- _snap_mode = LevelEditorApi.SnapMode.ABSOLUTE;
|
|
|
-
|
|
|
- send_state();
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
-
|
|
|
- private void on_reference_system_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- string name = param.get_string();
|
|
|
- if (name == "local")
|
|
|
- _reference_system = LevelEditorApi.ReferenceSystem.LOCAL;
|
|
|
- else if (name == "world")
|
|
|
- _reference_system = LevelEditorApi.ReferenceSystem.WORLD;
|
|
|
-
|
|
|
- send_state();
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
-
|
|
|
- private void on_grid_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- _grid_size = float.parse(param.get_string());
|
|
|
- send_state();
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
-
|
|
|
- private void on_rotation_snap_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- _rotation_snap = float.parse(param.get_string());
|
|
|
- send_state();
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
-
|
|
|
- private void new_level()
|
|
|
- {
|
|
|
- _level.load_empty_level();
|
|
|
- _level.send_level();
|
|
|
- }
|
|
|
-
|
|
|
- private void load_level(string level)
|
|
|
- {
|
|
|
- string filename = level;
|
|
|
-
|
|
|
- if (filename == "")
|
|
|
- {
|
|
|
- Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open Level..."
|
|
|
- , this.active_window
|
|
|
- , FileChooserAction.OPEN
|
|
|
- , "Cancel"
|
|
|
- , ResponseType.CANCEL
|
|
|
- , "Open"
|
|
|
- , ResponseType.ACCEPT
|
|
|
- );
|
|
|
- fcd.add_filter(_file_filter);
|
|
|
- fcd.set_current_folder(_project.source_dir());
|
|
|
-
|
|
|
- if (fcd.run() == ResponseType.ACCEPT)
|
|
|
- filename = fcd.get_filename();
|
|
|
|
|
|
- fcd.destroy();
|
|
|
+ for (int tries = 0; !_game.is_connected() && tries < 10; ++tries)
|
|
|
+ {
|
|
|
+ _game.connect("127.0.0.1", 12345);
|
|
|
+ GLib.Thread.usleep(500*1000);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (filename == "")
|
|
|
- return;
|
|
|
-
|
|
|
- if (!_project.path_is_within_dir(filename, _project.source_dir()))
|
|
|
+ else
|
|
|
{
|
|
|
- loge("File must be within `%s`".printf(_project.source_dir()));
|
|
|
- return;
|
|
|
+ _toolbar_run.icon_name = "game-run";
|
|
|
}
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (filename.has_suffix(".level") && filename != _level._filename)
|
|
|
- {
|
|
|
- _level.load(filename);
|
|
|
- _level.send_level();
|
|
|
- send_state();
|
|
|
- }
|
|
|
+ private void stop_game()
|
|
|
+ {
|
|
|
+ if (_game != null)
|
|
|
+ {
|
|
|
+ _game.send_script("Device.quit()");
|
|
|
+ _game.close();
|
|
|
}
|
|
|
|
|
|
- private bool save_as(string? filename)
|
|
|
+ if (_game_process != null)
|
|
|
{
|
|
|
- string path;
|
|
|
-
|
|
|
- if (filename != null)
|
|
|
- {
|
|
|
- path = filename;
|
|
|
- }
|
|
|
- else
|
|
|
+ try
|
|
|
{
|
|
|
- Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Save As..."
|
|
|
- , this.active_window
|
|
|
- , FileChooserAction.SAVE
|
|
|
- , "Cancel"
|
|
|
- , ResponseType.CANCEL
|
|
|
- , "Save"
|
|
|
- , ResponseType.ACCEPT
|
|
|
- );
|
|
|
- fcd.add_filter(_file_filter);
|
|
|
- fcd.set_current_folder(_project.source_dir());
|
|
|
- int rt = fcd.run();
|
|
|
-
|
|
|
- if (rt != ResponseType.ACCEPT)
|
|
|
- {
|
|
|
- fcd.destroy();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- path = fcd.get_filename();
|
|
|
- fcd.destroy();
|
|
|
+ _game_process.wait();
|
|
|
}
|
|
|
-
|
|
|
- if (!_project.path_is_within_dir(path, _project.source_dir()))
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- loge("File must be within `%s`".printf(_project.source_dir()));
|
|
|
- return false;
|
|
|
+ loge(e.message);
|
|
|
}
|
|
|
-
|
|
|
- _level.save(path.has_suffix(".level") ? path : path + ".level");
|
|
|
- _statusbar.set_temporary_message("Saved %s".printf(_level._filename));
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private bool save()
|
|
|
- {
|
|
|
- return save_as(_level._filename);
|
|
|
- }
|
|
|
-
|
|
|
- private bool save_timeout()
|
|
|
- {
|
|
|
- if (_level._filename != null)
|
|
|
- save();
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- public void close_all()
|
|
|
- {
|
|
|
- _user.save(_user_file.get_path());
|
|
|
- save_settings();
|
|
|
-
|
|
|
- if (_save_timer_id > 0)
|
|
|
- GLib.Source.remove(_save_timer_id);
|
|
|
-
|
|
|
- if (_resource_chooser != null)
|
|
|
- _resource_chooser.destroy();
|
|
|
-
|
|
|
- if (_preferences_dialog != null)
|
|
|
- _preferences_dialog.destroy();
|
|
|
-
|
|
|
- stop_compiler();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- protected override void shutdown()
|
|
|
- {
|
|
|
- base.shutdown();
|
|
|
- }
|
|
|
+ private void deploy_game()
|
|
|
+ {
|
|
|
+ Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Select destination directory..."
|
|
|
+ , this.active_window
|
|
|
+ , FileChooserAction.SELECT_FOLDER
|
|
|
+ , "Cancel"
|
|
|
+ , ResponseType.CANCEL
|
|
|
+ , "Open"
|
|
|
+ , ResponseType.ACCEPT
|
|
|
+ );
|
|
|
|
|
|
- // Returns true if the level has been saved or the user decided it
|
|
|
- // should be discarded.
|
|
|
- public bool should_quit()
|
|
|
+ if (fcd.run() == ResponseType.ACCEPT)
|
|
|
{
|
|
|
- int rt = ResponseType.YES;
|
|
|
+ GLib.File data_dir = File.new_for_path(fcd.get_filename());
|
|
|
|
|
|
- if (_database.changed())
|
|
|
+ string args[] =
|
|
|
{
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
- }
|
|
|
-
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
- return true;
|
|
|
+ ENGINE_EXE,
|
|
|
+ "--source-dir", _project.source_dir(),
|
|
|
+ "--map-source-dir", "core", _project.toolchain_dir(),
|
|
|
+ "--data-dir", data_dir.get_path(),
|
|
|
+ "--compile",
|
|
|
+ null
|
|
|
+ };
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
+ sl.set_cwd(ENGINE_DIR);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ GLib.Subprocess compiler = sl.spawnv(args);
|
|
|
+ compiler.wait();
|
|
|
+ if (compiler.get_exit_status() == 0)
|
|
|
+ {
|
|
|
+ string game_name = DEPLOY_DEFAULT_NAME;
|
|
|
+ GLib.File engine_exe_src = File.new_for_path(DEPLOY_EXE);
|
|
|
+ GLib.File engine_exe_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), game_name + EXE_SUFFIX));
|
|
|
+ engine_exe_src.copy(engine_exe_dst, FileCopyFlags.OVERWRITE);
|
|
|
|
|
|
- private void on_new_level(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- int rt = ResponseType.YES;
|
|
|
+#if CROWN_PLATFORM_WINDOWS
|
|
|
+ string lua51_name = "lua51.dll";
|
|
|
+ GLib.File lua51_dll_src = File.new_for_path(lua51_name);
|
|
|
+ GLib.File lua51_dll_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), lua51_name));
|
|
|
+ lua51_dll_src.copy(lua51_dll_dst, FileCopyFlags.OVERWRITE);
|
|
|
+
|
|
|
+ string openal_name = "openal-release.dll";
|
|
|
+ GLib.File openal_dll_src = File.new_for_path(openal_name);
|
|
|
+ GLib.File openal_dll_dst = File.new_for_path(Path.build_filename(data_dir.get_path(), openal_name));
|
|
|
+ openal_dll_src.copy(openal_dll_dst, FileCopyFlags.OVERWRITE);
|
|
|
+#endif // CROWN_PLATFORM_WINDOWS
|
|
|
|
|
|
- if (_database.changed())
|
|
|
- {
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
+ logi("Project deployed to `%s`".printf(data_dir.get_path()));
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
- new_level();
|
|
|
- send_state();
|
|
|
+ logi("%s".printf(e.message));
|
|
|
+ logi("Failed to deploy project");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void on_open_level(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- int rt = ResponseType.YES;
|
|
|
+ fcd.destroy();
|
|
|
+ }
|
|
|
|
|
|
- if (_level._filename == param.get_string())
|
|
|
- return;
|
|
|
+ private void on_editor_view_realized()
|
|
|
+ {
|
|
|
+ start_editor(_editor_view.window_id);
|
|
|
+ }
|
|
|
|
|
|
- if (_database.changed())
|
|
|
- {
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
- }
|
|
|
+ private void on_tool_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ string name = param.get_string();
|
|
|
+ if (name == "place")
|
|
|
+ _tool_type = LevelEditorApi.ToolType.PLACE;
|
|
|
+ else if (name == "move")
|
|
|
+ _tool_type = LevelEditorApi.ToolType.MOVE;
|
|
|
+ else if (name == "rotate")
|
|
|
+ _tool_type = LevelEditorApi.ToolType.ROTATE;
|
|
|
+ else if (name == "scale")
|
|
|
+ _tool_type = LevelEditorApi.ToolType.SCALE;
|
|
|
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
- load_level(param.get_string());
|
|
|
- }
|
|
|
+ send_state();
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
|
|
|
- private void on_open_project(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- int rt = ResponseType.YES;
|
|
|
+ private void on_snap_mode_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ string name = param.get_string();
|
|
|
+ if (name == "relative")
|
|
|
+ _snap_mode = LevelEditorApi.SnapMode.RELATIVE;
|
|
|
+ else if (name == "absolute")
|
|
|
+ _snap_mode = LevelEditorApi.SnapMode.ABSOLUTE;
|
|
|
|
|
|
- if (_database.changed())
|
|
|
- {
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
- }
|
|
|
+ send_state();
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
- {
|
|
|
- DialogOpenProject op = new DialogOpenProject(this.active_window);
|
|
|
- rt = op.run();
|
|
|
- if (rt != ResponseType.ACCEPT)
|
|
|
- {
|
|
|
- op.destroy();
|
|
|
- return;
|
|
|
- }
|
|
|
+ private void on_reference_system_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ string name = param.get_string();
|
|
|
+ if (name == "local")
|
|
|
+ _reference_system = LevelEditorApi.ReferenceSystem.LOCAL;
|
|
|
+ else if (name == "world")
|
|
|
+ _reference_system = LevelEditorApi.ReferenceSystem.WORLD;
|
|
|
|
|
|
- string source_dir = op.get_filename();
|
|
|
- op.destroy();
|
|
|
+ send_state();
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
|
|
|
- if (_project.source_dir() == source_dir)
|
|
|
- return;
|
|
|
+ private void on_grid_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _grid_size = float.parse(param.get_string());
|
|
|
+ send_state();
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
|
|
|
- logi("Loading project: `%s`...".printf(source_dir));
|
|
|
- restart_compiler(source_dir, null);
|
|
|
- }
|
|
|
- }
|
|
|
+ private void on_rotation_snap_changed(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _rotation_snap = float.parse(param.get_string());
|
|
|
+ send_state();
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
|
|
|
- private void on_new_project(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ private void new_level()
|
|
|
+ {
|
|
|
+ _level.load_empty_level();
|
|
|
+ _level.send_level();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void load_level(string level)
|
|
|
+ {
|
|
|
+ string filename = level;
|
|
|
+
|
|
|
+ if (filename == "")
|
|
|
{
|
|
|
- int rt = ResponseType.YES;
|
|
|
+ Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open Level..."
|
|
|
+ , this.active_window
|
|
|
+ , FileChooserAction.OPEN
|
|
|
+ , "Cancel"
|
|
|
+ , ResponseType.CANCEL
|
|
|
+ , "Open"
|
|
|
+ , ResponseType.ACCEPT
|
|
|
+ );
|
|
|
+ fcd.add_filter(_file_filter);
|
|
|
+ fcd.set_current_folder(_project.source_dir());
|
|
|
|
|
|
- if (_database.changed())
|
|
|
- {
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
- }
|
|
|
+ if (fcd.run() == ResponseType.ACCEPT)
|
|
|
+ filename = fcd.get_filename();
|
|
|
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
- {
|
|
|
- stop_compiler();
|
|
|
- show_panel("panel_new_project");
|
|
|
- }
|
|
|
+ fcd.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_save(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- save();
|
|
|
- }
|
|
|
+ if (filename == "")
|
|
|
+ return;
|
|
|
|
|
|
- private void on_save_as(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_project.path_is_within_dir(filename, _project.source_dir()))
|
|
|
{
|
|
|
- save_as(null);
|
|
|
+ loge("File must be within `%s`".printf(_project.source_dir()));
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- private void on_import(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (filename.has_suffix(".level") && filename != _level._filename)
|
|
|
{
|
|
|
- _project.import(null, this.active_window);
|
|
|
+ _level.load(filename);
|
|
|
+ _level.send_level();
|
|
|
+ send_state();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void on_preferences(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- _preferences_dialog.show_all();
|
|
|
- }
|
|
|
+ private bool save_as(string? filename)
|
|
|
+ {
|
|
|
+ string path;
|
|
|
|
|
|
- private void on_deploy(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (filename != null)
|
|
|
{
|
|
|
- deploy_game();
|
|
|
+ path = filename;
|
|
|
}
|
|
|
-
|
|
|
- private void on_close(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ else
|
|
|
{
|
|
|
- int rt = ResponseType.YES;
|
|
|
+ Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Save As..."
|
|
|
+ , this.active_window
|
|
|
+ , FileChooserAction.SAVE
|
|
|
+ , "Cancel"
|
|
|
+ , ResponseType.CANCEL
|
|
|
+ , "Save"
|
|
|
+ , ResponseType.ACCEPT
|
|
|
+ );
|
|
|
+ fcd.add_filter(_file_filter);
|
|
|
+ fcd.set_current_folder(_project.source_dir());
|
|
|
+ int rt = fcd.run();
|
|
|
|
|
|
- if (_database.changed())
|
|
|
+ if (rt != ResponseType.ACCEPT)
|
|
|
{
|
|
|
- DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
- rt = lc.run();
|
|
|
- lc.destroy();
|
|
|
+ fcd.destroy();
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
- {
|
|
|
- stop_compiler();
|
|
|
- show_panel("panel_welcome");
|
|
|
- }
|
|
|
+ path = fcd.get_filename();
|
|
|
+ fcd.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_quit(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_project.path_is_within_dir(path, _project.source_dir()))
|
|
|
{
|
|
|
- this.active_window.close();
|
|
|
+ loge("File must be within `%s`".printf(_project.source_dir()));
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- private void on_show_grid(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- _show_grid = !action.get_state().get_boolean();
|
|
|
- send_state();
|
|
|
- action.set_state(new GLib.Variant.boolean(_show_grid));
|
|
|
- }
|
|
|
+ _level.save(path.has_suffix(".level") ? path : path + ".level");
|
|
|
+ _statusbar.set_temporary_message("Saved %s".printf(_level._filename));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- private void on_custom_grid()
|
|
|
- {
|
|
|
- Gtk.Dialog dg = new Gtk.Dialog.with_buttons("Grid size"
|
|
|
- , this.active_window
|
|
|
- , DialogFlags.MODAL
|
|
|
- , "Cancel"
|
|
|
- , ResponseType.CANCEL
|
|
|
- , "Ok"
|
|
|
- , ResponseType.OK
|
|
|
- , null
|
|
|
- );
|
|
|
+ private bool save()
|
|
|
+ {
|
|
|
+ return save_as(_level._filename);
|
|
|
+ }
|
|
|
|
|
|
- EntryDouble sb = new EntryDouble(_grid_size, 0.1, 1000);
|
|
|
- sb.activate.connect(() => { dg.response(ResponseType.OK); });
|
|
|
- dg.get_content_area().add(sb);
|
|
|
- dg.skip_taskbar_hint = true;
|
|
|
- dg.show_all();
|
|
|
+ private bool save_timeout()
|
|
|
+ {
|
|
|
+ if (_level._filename != null)
|
|
|
+ save();
|
|
|
|
|
|
- if (dg.run() == ResponseType.OK)
|
|
|
- {
|
|
|
- _grid_size = sb.value;
|
|
|
- send_state();
|
|
|
- }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- dg.destroy();
|
|
|
- }
|
|
|
+ public void close_all()
|
|
|
+ {
|
|
|
+ _user.save(_user_file.get_path());
|
|
|
+ save_settings();
|
|
|
|
|
|
- private void on_rotation_snap(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- Gtk.Dialog dg = new Gtk.Dialog.with_buttons("Rotation snap"
|
|
|
- , this.active_window
|
|
|
- , DialogFlags.MODAL
|
|
|
- , "Cancel"
|
|
|
- , ResponseType.CANCEL
|
|
|
- , "Ok"
|
|
|
- , ResponseType.OK
|
|
|
- , null
|
|
|
- );
|
|
|
+ if (_save_timer_id > 0)
|
|
|
+ GLib.Source.remove(_save_timer_id);
|
|
|
|
|
|
- EntryDouble sb = new EntryDouble(_rotation_snap, 1.0, 180.0);
|
|
|
- sb.activate.connect(() => { dg.response(ResponseType.OK); });
|
|
|
- dg.get_content_area().add(sb);
|
|
|
- dg.skip_taskbar_hint = true;
|
|
|
- dg.show_all();
|
|
|
+ if (_resource_chooser != null)
|
|
|
+ _resource_chooser.destroy();
|
|
|
|
|
|
- if (dg.run() == ResponseType.OK)
|
|
|
- {
|
|
|
- _rotation_snap = sb.value;
|
|
|
- send_state();
|
|
|
- }
|
|
|
+ if (_preferences_dialog != null)
|
|
|
+ _preferences_dialog.destroy();
|
|
|
+
|
|
|
+ stop_compiler();
|
|
|
+ }
|
|
|
|
|
|
- dg.destroy();
|
|
|
- }
|
|
|
+ protected override void shutdown()
|
|
|
+ {
|
|
|
+ base.shutdown();
|
|
|
+ }
|
|
|
|
|
|
- private void on_create_primitive(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- if (action.name == "primitive-cube")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cube"));
|
|
|
- else if (action.name == "primitive-sphere")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/sphere"));
|
|
|
- else if (action.name == "primitive-cone")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cone"));
|
|
|
- else if (action.name == "primitive-cylinder")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cylinder"));
|
|
|
- else if (action.name == "primitive-plane")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/plane"));
|
|
|
- else if (action.name == "camera")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/camera"));
|
|
|
- else if (action.name == "light")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/light"));
|
|
|
- else if (action.name == "sound-source")
|
|
|
- _editor.send_script(LevelEditorApi.set_placeable("sound", ""));
|
|
|
+ // Returns true if the level has been saved or the user decided it
|
|
|
+ // should be discarded.
|
|
|
+ public bool should_quit()
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
|
|
|
- activate_action("tool", new GLib.Variant.string("place"));
|
|
|
+ if (_database.changed())
|
|
|
+ {
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_camera_view(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- string name = param.get_string();
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
+ return true;
|
|
|
|
|
|
- if (name == "perspective")
|
|
|
- _editor.send_script("LevelEditor:camera_view_perspective()");
|
|
|
- else if (name == "front")
|
|
|
- _editor.send_script("LevelEditor:camera_view_front()");
|
|
|
- else if (name == "back")
|
|
|
- _editor.send_script("LevelEditor:camera_view_back()");
|
|
|
- else if (name == "right")
|
|
|
- _editor.send_script("LevelEditor:camera_view_right()");
|
|
|
- else if (name == "left")
|
|
|
- _editor.send_script("LevelEditor:camera_view_left()");
|
|
|
- else if (name == "top")
|
|
|
- _editor.send_script("LevelEditor:camera_view_top()");
|
|
|
- else if (name == "bottom")
|
|
|
- _editor.send_script("LevelEditor:camera_view_bottom()");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- action.set_state(param);
|
|
|
- }
|
|
|
+ private void on_new_level(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
|
|
|
- private void on_resource_chooser(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (_database.changed())
|
|
|
{
|
|
|
- _resource_popover.show_all();
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_project_browser(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
{
|
|
|
- if (_project_slide.is_visible())
|
|
|
- {
|
|
|
- _project_slide.hide();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _project_slide.show_all();
|
|
|
- }
|
|
|
+ new_level();
|
|
|
+ send_state();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_open_level(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
+
|
|
|
+ if (_level._filename == param.get_string())
|
|
|
+ return;
|
|
|
|
|
|
- private void on_console(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (_database.changed())
|
|
|
{
|
|
|
- if (_console_view.is_visible())
|
|
|
- {
|
|
|
- if (_console_view._entry.has_focus)
|
|
|
- _console_view.hide();
|
|
|
- else
|
|
|
- _console_view._entry.grab_focus();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _console_view.show_all();
|
|
|
- }
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_statusbar(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
+ load_level(param.get_string());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_open_project(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
+
|
|
|
+ if (_database.changed())
|
|
|
{
|
|
|
- if (_statusbar.is_visible())
|
|
|
- {
|
|
|
- _statusbar.hide();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _statusbar.show_all();
|
|
|
- }
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_inspector(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
{
|
|
|
- if (_inspector_slide.is_visible())
|
|
|
+ DialogOpenProject op = new DialogOpenProject(this.active_window);
|
|
|
+ rt = op.run();
|
|
|
+ if (rt != ResponseType.ACCEPT)
|
|
|
{
|
|
|
- _inspector_slide.hide();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _inspector_slide.show_all();
|
|
|
+ op.destroy();
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ string source_dir = op.get_filename();
|
|
|
+ op.destroy();
|
|
|
+
|
|
|
+ if (_project.source_dir() == source_dir)
|
|
|
+ return;
|
|
|
+
|
|
|
+ logi("Loading project: `%s`...".printf(source_dir));
|
|
|
+ restart_compiler(source_dir, null);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_new_project(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
|
|
|
- private void on_editor_restart(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (_database.changed())
|
|
|
{
|
|
|
- restart_editor();
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_build_data(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
{
|
|
|
- _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
- _data_compiler.compile.end(res);
|
|
|
- });
|
|
|
+ stop_compiler();
|
|
|
+ show_panel("panel_new_project");
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_save(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ save();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_save_as(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ save_as(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_import(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _project.import(null, this.active_window);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_preferences(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _preferences_dialog.show_all();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_deploy(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ deploy_game();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_close(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int rt = ResponseType.YES;
|
|
|
|
|
|
- private void on_refresh_lua(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (_database.changed())
|
|
|
{
|
|
|
- _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
- if (_data_compiler.compile.end(res))
|
|
|
- {
|
|
|
- _editor.send(DeviceApi.refresh());
|
|
|
- _game.send(DeviceApi.refresh());
|
|
|
- }
|
|
|
- });
|
|
|
+ DialogLevelChanged lc = new DialogLevelChanged(this.active_window);
|
|
|
+ rt = lc.run();
|
|
|
+ lc.destroy();
|
|
|
}
|
|
|
|
|
|
- private void on_snap_to_grid(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
|
|
|
{
|
|
|
- _snap_to_grid = !action.get_state().get_boolean();
|
|
|
- send_state();
|
|
|
- action.set_state(new GLib.Variant.boolean(_snap_to_grid));
|
|
|
+ stop_compiler();
|
|
|
+ show_panel("panel_welcome");
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_quit(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ this.active_window.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_show_grid(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _show_grid = !action.get_state().get_boolean();
|
|
|
+ send_state();
|
|
|
+ action.set_state(new GLib.Variant.boolean(_show_grid));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_custom_grid()
|
|
|
+ {
|
|
|
+ Gtk.Dialog dg = new Gtk.Dialog.with_buttons("Grid size"
|
|
|
+ , this.active_window
|
|
|
+ , DialogFlags.MODAL
|
|
|
+ , "Cancel"
|
|
|
+ , ResponseType.CANCEL
|
|
|
+ , "Ok"
|
|
|
+ , ResponseType.OK
|
|
|
+ , null
|
|
|
+ );
|
|
|
+
|
|
|
+ EntryDouble sb = new EntryDouble(_grid_size, 0.1, 1000);
|
|
|
+ sb.activate.connect(() => { dg.response(ResponseType.OK); });
|
|
|
+ dg.get_content_area().add(sb);
|
|
|
+ dg.skip_taskbar_hint = true;
|
|
|
+ dg.show_all();
|
|
|
|
|
|
- private void on_debug_render_world(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ if (dg.run() == ResponseType.OK)
|
|
|
{
|
|
|
- _debug_render_world = !action.get_state().get_boolean();
|
|
|
+ _grid_size = sb.value;
|
|
|
send_state();
|
|
|
- action.set_state(new GLib.Variant.boolean(_debug_render_world));
|
|
|
}
|
|
|
|
|
|
- private void on_debug_physics_world(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ dg.destroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_rotation_snap(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ Gtk.Dialog dg = new Gtk.Dialog.with_buttons("Rotation snap"
|
|
|
+ , this.active_window
|
|
|
+ , DialogFlags.MODAL
|
|
|
+ , "Cancel"
|
|
|
+ , ResponseType.CANCEL
|
|
|
+ , "Ok"
|
|
|
+ , ResponseType.OK
|
|
|
+ , null
|
|
|
+ );
|
|
|
+
|
|
|
+ EntryDouble sb = new EntryDouble(_rotation_snap, 1.0, 180.0);
|
|
|
+ sb.activate.connect(() => { dg.response(ResponseType.OK); });
|
|
|
+ dg.get_content_area().add(sb);
|
|
|
+ dg.skip_taskbar_hint = true;
|
|
|
+ dg.show_all();
|
|
|
+
|
|
|
+ if (dg.run() == ResponseType.OK)
|
|
|
{
|
|
|
- _debug_physics_world = !action.get_state().get_boolean();
|
|
|
+ _rotation_snap = sb.value;
|
|
|
send_state();
|
|
|
- action.set_state(new GLib.Variant.boolean(_debug_physics_world));
|
|
|
}
|
|
|
|
|
|
- private void on_run_game(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- if (_game.is_connected())
|
|
|
- {
|
|
|
- stop_game();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Always change icon state regardless of failures
|
|
|
- _toolbar_run.icon_name = "game-stop";
|
|
|
- start_game(action.name == "test-level" ? StartGame.TEST : StartGame.NORMAL);
|
|
|
- }
|
|
|
- }
|
|
|
+ dg.destroy();
|
|
|
+ }
|
|
|
|
|
|
- private void on_undo(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
- {
|
|
|
- int id = _database.undo();
|
|
|
- if (id != -1)
|
|
|
- _statusbar.set_temporary_message("Undo: " + ActionNames[id]);
|
|
|
- }
|
|
|
+ private void on_create_primitive(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (action.name == "primitive-cube")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cube"));
|
|
|
+ else if (action.name == "primitive-sphere")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/sphere"));
|
|
|
+ else if (action.name == "primitive-cone")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cone"));
|
|
|
+ else if (action.name == "primitive-cylinder")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/cylinder"));
|
|
|
+ else if (action.name == "primitive-plane")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/primitives/plane"));
|
|
|
+ else if (action.name == "camera")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/camera"));
|
|
|
+ else if (action.name == "light")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("unit", "core/units/light"));
|
|
|
+ else if (action.name == "sound-source")
|
|
|
+ _editor.send_script(LevelEditorApi.set_placeable("sound", ""));
|
|
|
+
|
|
|
+ activate_action("tool", new GLib.Variant.string("place"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_camera_view(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ string name = param.get_string();
|
|
|
+
|
|
|
+ if (name == "perspective")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_perspective()");
|
|
|
+ else if (name == "front")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_front()");
|
|
|
+ else if (name == "back")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_back()");
|
|
|
+ else if (name == "right")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_right()");
|
|
|
+ else if (name == "left")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_left()");
|
|
|
+ else if (name == "top")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_top()");
|
|
|
+ else if (name == "bottom")
|
|
|
+ _editor.send_script("LevelEditor:camera_view_bottom()");
|
|
|
+
|
|
|
+ action.set_state(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_resource_chooser(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _resource_popover.show_all();
|
|
|
+ }
|
|
|
|
|
|
- private void on_redo(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ private void on_project_browser(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_project_slide.is_visible())
|
|
|
{
|
|
|
- int id = _database.redo();
|
|
|
- if (id != -1)
|
|
|
- _statusbar.set_temporary_message("Redo: " + ActionNames[id]);
|
|
|
+ _project_slide.hide();
|
|
|
}
|
|
|
-
|
|
|
- private void on_duplicate(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ else
|
|
|
{
|
|
|
- _level.duplicate_selected_objects();
|
|
|
+ _project_slide.show_all();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void on_delete(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ private void on_console(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_console_view.is_visible())
|
|
|
{
|
|
|
- _level.destroy_selected_objects();
|
|
|
+ if (_console_view._entry.has_focus)
|
|
|
+ _console_view.hide();
|
|
|
+ else
|
|
|
+ _console_view._entry.grab_focus();
|
|
|
}
|
|
|
-
|
|
|
- private void on_manual(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ else
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- AppInfo.launch_default_for_uri("https://dbartolini.github.io/crown/html/v" + CROWN_VERSION, null);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ _console_view.show_all();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void on_report_issue(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ private void on_statusbar(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_statusbar.is_visible())
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- AppInfo.launch_default_for_uri("https://github.com/dbartolini/crown/issues", null);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ _statusbar.hide();
|
|
|
}
|
|
|
-
|
|
|
- private void on_browse_logs(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ else
|
|
|
{
|
|
|
- open_directory(_logs_dir.get_path());
|
|
|
+ _statusbar.show_all();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void on_changelog(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ private void on_inspector(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_inspector_slide.is_visible())
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- AppInfo.launch_default_for_uri("https://dbartolini.github.io/crown/html/v" + CROWN_VERSION + "/changelog.html", null);
|
|
|
- }
|
|
|
- catch (Error e)
|
|
|
- {
|
|
|
- loge(e.message);
|
|
|
- }
|
|
|
+ _inspector_slide.hide();
|
|
|
}
|
|
|
-
|
|
|
- private void on_about(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ else
|
|
|
{
|
|
|
- Gtk.AboutDialog dlg = new Gtk.AboutDialog();
|
|
|
- dlg.set_destroy_with_parent(true);
|
|
|
- dlg.set_transient_for(this.active_window);
|
|
|
- dlg.set_modal(true);
|
|
|
- dlg.set_logo_icon_name("pepper");
|
|
|
-
|
|
|
- dlg.program_name = "Crown Game Engine";
|
|
|
- dlg.version = CROWN_VERSION;
|
|
|
- dlg.website = "https://github.com/dbartolini/crown";
|
|
|
- dlg.copyright = "Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.";
|
|
|
- dlg.license = "Crown Game Engine.\n"
|
|
|
- + "Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.\n"
|
|
|
- + "\n"
|
|
|
- + "This program is free software; you can redistribute it and/or\n"
|
|
|
- + "modify it under the terms of the GNU General Public License\n"
|
|
|
- + "as published by the Free Software Foundation; either version 2\n"
|
|
|
- + "of the License, or (at your option) any later version.\n"
|
|
|
- + "\n"
|
|
|
- + "This program is distributed in the hope that it will be useful,\n"
|
|
|
- + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
|
|
- + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
|
|
- + "GNU General Public License for more details.\n"
|
|
|
- + "\n"
|
|
|
- + "You should have received a copy of the GNU General Public License\n"
|
|
|
- + "along with this program; if not, write to the Free Software\n"
|
|
|
- + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
|
|
|
- ;
|
|
|
- dlg.run();
|
|
|
- dlg.destroy();
|
|
|
+ _inspector_slide.show_all();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public void set_autosave_timer(uint minutes)
|
|
|
- {
|
|
|
- if (_save_timer_id > 0)
|
|
|
- GLib.Source.remove(_save_timer_id);
|
|
|
+ private void on_editor_restart(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ restart_editor();
|
|
|
+ }
|
|
|
|
|
|
- _save_timer_id = GLib.Timeout.add_seconds(minutes*60, save_timeout);
|
|
|
- }
|
|
|
+ private void on_build_data(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
+ _data_compiler.compile.end(res);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- public void menu_set_enabled(bool enabled, GLib.ActionEntry[] entries, string[]? whitelist = null)
|
|
|
- {
|
|
|
- for (int ii = 0; ii < entries.length; ++ii)
|
|
|
+ private void on_refresh_lua(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _data_compiler.compile.begin(_project.data_dir(), _project.platform(), (obj, res) => {
|
|
|
+ if (_data_compiler.compile.end(res))
|
|
|
{
|
|
|
- string action_name = entries[ii].name;
|
|
|
- int jj = 0;
|
|
|
- if (whitelist != null)
|
|
|
- {
|
|
|
- for (; jj < whitelist.length; ++jj)
|
|
|
- {
|
|
|
- if (action_name == whitelist[jj])
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (whitelist == null || whitelist != null && jj == whitelist.length)
|
|
|
- {
|
|
|
- GLib.SimpleAction sa = this.lookup_action(action_name) as GLib.SimpleAction;
|
|
|
- if (sa != null)
|
|
|
- sa.set_enabled(enabled);
|
|
|
- }
|
|
|
+ _editor.send(DeviceApi.refresh());
|
|
|
+ _game.send(DeviceApi.refresh());
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- public void show_panel(string name, Gtk.StackTransitionType stt = Gtk.StackTransitionType.NONE)
|
|
|
- {
|
|
|
- _main_stack.set_visible_child_full(name, stt);
|
|
|
+ private void on_snap_to_grid(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _snap_to_grid = !action.get_state().get_boolean();
|
|
|
+ send_state();
|
|
|
+ action.set_state(new GLib.Variant.boolean(_snap_to_grid));
|
|
|
+ }
|
|
|
|
|
|
- if (name == "main_vbox")
|
|
|
- {
|
|
|
- // FIXME: save/restore last known window state
|
|
|
- int win_w;
|
|
|
- int win_h;
|
|
|
- this.active_window.get_size(out win_w, out win_h);
|
|
|
- _editor_pane.set_position(210);
|
|
|
- _content_pane.set_position(win_h - 250);
|
|
|
- _inspector_pane.set_position(win_h - 600);
|
|
|
- _main_pane.set_position(win_w - 375);
|
|
|
-
|
|
|
- menu_set_enabled(true, action_entries_file);
|
|
|
- menu_set_enabled(true, action_entries_edit);
|
|
|
- menu_set_enabled(true, action_entries_create);
|
|
|
- menu_set_enabled(true, action_entries_camera);
|
|
|
- menu_set_enabled(true, action_entries_view);
|
|
|
- menu_set_enabled(true, action_entries_debug);
|
|
|
- menu_set_enabled(true, action_entries_help);
|
|
|
- }
|
|
|
- else if (name == "panel_welcome"
|
|
|
- || name == "panel_new_project"
|
|
|
- || name == "panel_projects_list"
|
|
|
- )
|
|
|
- {
|
|
|
- menu_set_enabled(false, action_entries_file, {"new-project", "open-project", "quit"});
|
|
|
- menu_set_enabled(false, action_entries_edit);
|
|
|
- menu_set_enabled(false, action_entries_create);
|
|
|
- menu_set_enabled(false, action_entries_camera);
|
|
|
- menu_set_enabled(false, action_entries_view);
|
|
|
- menu_set_enabled(false, action_entries_debug);
|
|
|
- menu_set_enabled( true, action_entries_help);
|
|
|
- }
|
|
|
- }
|
|
|
+ private void on_debug_render_world(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _debug_render_world = !action.get_state().get_boolean();
|
|
|
+ send_state();
|
|
|
+ action.set_state(new GLib.Variant.boolean(_debug_render_world));
|
|
|
}
|
|
|
|
|
|
- // Global paths
|
|
|
- public static GLib.File _config_dir;
|
|
|
- public static GLib.File _logs_dir;
|
|
|
- public static GLib.File _documents_dir;
|
|
|
- public static GLib.File _log_file;
|
|
|
- public static GLib.File _settings_file;
|
|
|
- public static GLib.File _user_file;
|
|
|
-
|
|
|
- public static GLib.FileStream _log_stream;
|
|
|
- public static ConsoleView _console_view;
|
|
|
-
|
|
|
- public static void log(string system, string severity, string message)
|
|
|
- {
|
|
|
- GLib.DateTime now = new GLib.DateTime.now_utc();
|
|
|
- string line = "%s.%06d %.4s %s: %s\n".printf(now.format("%H:%M:%S")
|
|
|
- , now.get_microsecond()
|
|
|
- , severity.ascii_up()
|
|
|
- , system
|
|
|
- , message
|
|
|
- );
|
|
|
+ private void on_debug_physics_world(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ _debug_physics_world = !action.get_state().get_boolean();
|
|
|
+ send_state();
|
|
|
+ action.set_state(new GLib.Variant.boolean(_debug_physics_world));
|
|
|
+ }
|
|
|
|
|
|
- if (_log_stream != null)
|
|
|
+ private void on_run_game(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ if (_game.is_connected())
|
|
|
+ {
|
|
|
+ stop_game();
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- _log_stream.puts(line);
|
|
|
- _log_stream.flush();
|
|
|
+ // Always change icon state regardless of failures
|
|
|
+ _toolbar_run.icon_name = "game-stop";
|
|
|
+ start_game(action.name == "test-level" ? StartGame.TEST : StartGame.NORMAL);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (_console_view != null)
|
|
|
- _console_view.log(severity, line);
|
|
|
+ private void on_undo(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ int id = _database.undo();
|
|
|
+ if (id != -1)
|
|
|
+ _statusbar.set_temporary_message("Undo: " + ActionNames[id]);
|
|
|
}
|
|
|
|
|
|
- public static void logi(string message)
|
|
|
+ private void on_redo(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
- log("editor", "info", message);
|
|
|
+ int id = _database.redo();
|
|
|
+ if (id != -1)
|
|
|
+ _statusbar.set_temporary_message("Redo: " + ActionNames[id]);
|
|
|
}
|
|
|
|
|
|
- public static void logw(string message)
|
|
|
+ private void on_duplicate(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
- log("editor", "warning", message);
|
|
|
+ _level.duplicate_selected_objects();
|
|
|
}
|
|
|
|
|
|
- public static void loge(string message)
|
|
|
+ private void on_delete(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
- log("editor", "error", message);
|
|
|
+ _level.destroy_selected_objects();
|
|
|
}
|
|
|
|
|
|
- public void open_directory(string directory)
|
|
|
+ private void on_manual(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
-#if CROWN_PLATFORM_LINUX
|
|
|
try
|
|
|
{
|
|
|
- GLib.AppInfo.launch_default_for_uri("file://" + directory, null);
|
|
|
+ AppInfo.launch_default_for_uri("https://dbartolini.github.io/crown/html/v" + CROWN_VERSION, null);
|
|
|
}
|
|
|
catch (Error e)
|
|
|
{
|
|
|
loge(e.message);
|
|
|
}
|
|
|
-#else
|
|
|
- GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void on_report_issue(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
- sl.spawnv({ "explorer.exe", directory, null });
|
|
|
+ AppInfo.launch_default_for_uri("https://github.com/dbartolini/crown/issues", null);
|
|
|
}
|
|
|
catch (Error e)
|
|
|
{
|
|
|
loge(e.message);
|
|
|
}
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
- public static GLib.SubprocessFlags subprocess_flags()
|
|
|
+ private void on_browse_logs(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
- GLib.SubprocessFlags flags = SubprocessFlags.NONE;
|
|
|
-#if !CROWN_DEBUG
|
|
|
- flags |= SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE;
|
|
|
-#endif
|
|
|
- return flags;
|
|
|
+ open_directory(_logs_dir.get_path());
|
|
|
}
|
|
|
|
|
|
- public static bool is_directory_empty(string path)
|
|
|
+ private void on_changelog(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
{
|
|
|
- GLib.File file = GLib.File.new_for_path(path);
|
|
|
try
|
|
|
{
|
|
|
- FileEnumerator enumerator = file.enumerate_children("standard::*"
|
|
|
- , FileQueryInfoFlags.NOFOLLOW_SYMLINKS
|
|
|
- );
|
|
|
- return enumerator.next_file() == null;
|
|
|
+ AppInfo.launch_default_for_uri("https://dbartolini.github.io/crown/html/v" + CROWN_VERSION + "/changelog.html", null);
|
|
|
}
|
|
|
- catch (GLib.Error e)
|
|
|
+ catch (Error e)
|
|
|
{
|
|
|
loge(e.message);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- return false;
|
|
|
+ private void on_about(GLib.SimpleAction action, GLib.Variant? param)
|
|
|
+ {
|
|
|
+ Gtk.AboutDialog dlg = new Gtk.AboutDialog();
|
|
|
+ dlg.set_destroy_with_parent(true);
|
|
|
+ dlg.set_transient_for(this.active_window);
|
|
|
+ dlg.set_modal(true);
|
|
|
+ dlg.set_logo_icon_name("pepper");
|
|
|
+
|
|
|
+ dlg.program_name = "Crown Game Engine";
|
|
|
+ dlg.version = CROWN_VERSION;
|
|
|
+ dlg.website = "https://github.com/dbartolini/crown";
|
|
|
+ dlg.copyright = "Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.";
|
|
|
+ dlg.license = "Crown Game Engine.\n"
|
|
|
+ + "Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.\n"
|
|
|
+ + "\n"
|
|
|
+ + "This program is free software; you can redistribute it and/or\n"
|
|
|
+ + "modify it under the terms of the GNU General Public License\n"
|
|
|
+ + "as published by the Free Software Foundation; either version 2\n"
|
|
|
+ + "of the License, or (at your option) any later version.\n"
|
|
|
+ + "\n"
|
|
|
+ + "This program is distributed in the hope that it will be useful,\n"
|
|
|
+ + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
|
|
+ + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
|
|
+ + "GNU General Public License for more details.\n"
|
|
|
+ + "\n"
|
|
|
+ + "You should have received a copy of the GNU General Public License\n"
|
|
|
+ + "along with this program; if not, write to the Free Software\n"
|
|
|
+ + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
|
|
|
+ ;
|
|
|
+ dlg.run();
|
|
|
+ dlg.destroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void set_autosave_timer(uint minutes)
|
|
|
+ {
|
|
|
+ if (_save_timer_id > 0)
|
|
|
+ GLib.Source.remove(_save_timer_id);
|
|
|
+
|
|
|
+ _save_timer_id = GLib.Timeout.add_seconds(minutes*60, save_timeout);
|
|
|
}
|
|
|
|
|
|
- public static int main(string[] args)
|
|
|
+ public void menu_set_enabled(bool enabled, GLib.ActionEntry[] entries, string[]? whitelist = null)
|
|
|
{
|
|
|
- // Global paths
|
|
|
- _config_dir = GLib.File.new_for_path(GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), "crown"));
|
|
|
- try { _config_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
|
|
|
- _logs_dir = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "logs"));
|
|
|
- try { _logs_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
|
|
|
- _documents_dir = GLib.File.new_for_path(GLib.Environment.get_user_special_dir(GLib.UserDirectory.DOCUMENTS));
|
|
|
+ for (int ii = 0; ii < entries.length; ++ii)
|
|
|
+ {
|
|
|
+ string action_name = entries[ii].name;
|
|
|
+ int jj = 0;
|
|
|
+ if (whitelist != null)
|
|
|
+ {
|
|
|
+ for (; jj < whitelist.length; ++jj)
|
|
|
+ {
|
|
|
+ if (action_name == whitelist[jj])
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (whitelist == null || whitelist != null && jj == whitelist.length)
|
|
|
+ {
|
|
|
+ GLib.SimpleAction sa = this.lookup_action(action_name) as GLib.SimpleAction;
|
|
|
+ if (sa != null)
|
|
|
+ sa.set_enabled(enabled);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void show_panel(string name, Gtk.StackTransitionType stt = Gtk.StackTransitionType.NONE)
|
|
|
+ {
|
|
|
+ _main_stack.set_visible_child_full(name, stt);
|
|
|
+
|
|
|
+ if (name == "main_vbox")
|
|
|
+ {
|
|
|
+ // FIXME: save/restore last known window state
|
|
|
+ int win_w;
|
|
|
+ int win_h;
|
|
|
+ this.active_window.get_size(out win_w, out win_h);
|
|
|
+ _editor_pane.set_position(210);
|
|
|
+ _content_pane.set_position(win_h - 250);
|
|
|
+ _inspector_pane.set_position(win_h - 600);
|
|
|
+ _main_pane.set_position(win_w - 375);
|
|
|
+
|
|
|
+ menu_set_enabled(true, action_entries_file);
|
|
|
+ menu_set_enabled(true, action_entries_edit);
|
|
|
+ menu_set_enabled(true, action_entries_create);
|
|
|
+ menu_set_enabled(true, action_entries_camera);
|
|
|
+ menu_set_enabled(true, action_entries_view);
|
|
|
+ menu_set_enabled(true, action_entries_debug);
|
|
|
+ menu_set_enabled(true, action_entries_help);
|
|
|
+ }
|
|
|
+ else if (name == "panel_welcome"
|
|
|
+ || name == "panel_new_project"
|
|
|
+ || name == "panel_projects_list"
|
|
|
+ )
|
|
|
+ {
|
|
|
+ menu_set_enabled(false, action_entries_file, {"new-project", "open-project", "quit"});
|
|
|
+ menu_set_enabled(false, action_entries_edit);
|
|
|
+ menu_set_enabled(false, action_entries_create);
|
|
|
+ menu_set_enabled(false, action_entries_camera);
|
|
|
+ menu_set_enabled(false, action_entries_view);
|
|
|
+ menu_set_enabled(false, action_entries_debug);
|
|
|
+ menu_set_enabled( true, action_entries_help);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Global paths
|
|
|
+public static GLib.File _config_dir;
|
|
|
+public static GLib.File _logs_dir;
|
|
|
+public static GLib.File _documents_dir;
|
|
|
+public static GLib.File _log_file;
|
|
|
+public static GLib.File _settings_file;
|
|
|
+public static GLib.File _user_file;
|
|
|
+
|
|
|
+public static GLib.FileStream _log_stream;
|
|
|
+public static ConsoleView _console_view;
|
|
|
+
|
|
|
+public static void log(string system, string severity, string message)
|
|
|
+{
|
|
|
+ GLib.DateTime now = new GLib.DateTime.now_utc();
|
|
|
+ string line = "%s.%06d %.4s %s: %s\n".printf(now.format("%H:%M:%S")
|
|
|
+ , now.get_microsecond()
|
|
|
+ , severity.ascii_up()
|
|
|
+ , system
|
|
|
+ , message
|
|
|
+ );
|
|
|
+
|
|
|
+ if (_log_stream != null)
|
|
|
+ {
|
|
|
+ _log_stream.puts(line);
|
|
|
+ _log_stream.flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_console_view != null)
|
|
|
+ _console_view.log(severity, line);
|
|
|
+}
|
|
|
+
|
|
|
+public static void logi(string message)
|
|
|
+{
|
|
|
+ log("editor", "info", message);
|
|
|
+}
|
|
|
+
|
|
|
+public static void logw(string message)
|
|
|
+{
|
|
|
+ log("editor", "warning", message);
|
|
|
+}
|
|
|
+
|
|
|
+public static void loge(string message)
|
|
|
+{
|
|
|
+ log("editor", "error", message);
|
|
|
+}
|
|
|
|
|
|
- _log_file = GLib.File.new_for_path(GLib.Path.build_filename(_logs_dir.get_path(), new GLib.DateTime.now_utc().format("%Y-%m-%d") + ".log"));
|
|
|
- _settings_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "settings.sjson"));
|
|
|
- _user_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "user.sjson"));
|
|
|
+public void open_directory(string directory)
|
|
|
+{
|
|
|
+#if CROWN_PLATFORM_LINUX
|
|
|
+ try
|
|
|
+ {
|
|
|
+ GLib.AppInfo.launch_default_for_uri("file://" + directory, null);
|
|
|
+ }
|
|
|
+ catch (Error e)
|
|
|
+ {
|
|
|
+ loge(e.message);
|
|
|
+ }
|
|
|
+#else
|
|
|
+ GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
|
|
|
+ try
|
|
|
+ {
|
|
|
+ sl.spawnv({ "explorer.exe", directory, null });
|
|
|
+ }
|
|
|
+ catch (Error e)
|
|
|
+ {
|
|
|
+ loge(e.message);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+}
|
|
|
|
|
|
- _log_stream = GLib.FileStream.open(_log_file.get_path(), "a");
|
|
|
+public static GLib.SubprocessFlags subprocess_flags()
|
|
|
+{
|
|
|
+ GLib.SubprocessFlags flags = SubprocessFlags.NONE;
|
|
|
+#if !CROWN_DEBUG
|
|
|
+ flags |= SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE;
|
|
|
+#endif
|
|
|
+ return flags;
|
|
|
+}
|
|
|
|
|
|
- LevelEditorApplication app = new LevelEditorApplication();
|
|
|
- return app.run(args);
|
|
|
+public static bool is_directory_empty(string path)
|
|
|
+{
|
|
|
+ GLib.File file = GLib.File.new_for_path(path);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FileEnumerator enumerator = file.enumerate_children("standard::*"
|
|
|
+ , FileQueryInfoFlags.NOFOLLOW_SYMLINKS
|
|
|
+ );
|
|
|
+ return enumerator.next_file() == null;
|
|
|
}
|
|
|
+ catch (GLib.Error e)
|
|
|
+ {
|
|
|
+ loge(e.message);
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+public static int main(string[] args)
|
|
|
+{
|
|
|
+ // Global paths
|
|
|
+ _config_dir = GLib.File.new_for_path(GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), "crown"));
|
|
|
+ try { _config_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
|
|
|
+ _logs_dir = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "logs"));
|
|
|
+ try { _logs_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
|
|
|
+ _documents_dir = GLib.File.new_for_path(GLib.Environment.get_user_special_dir(GLib.UserDirectory.DOCUMENTS));
|
|
|
+
|
|
|
+ _log_file = GLib.File.new_for_path(GLib.Path.build_filename(_logs_dir.get_path(), new GLib.DateTime.now_utc().format("%Y-%m-%d") + ".log"));
|
|
|
+ _settings_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "settings.sjson"));
|
|
|
+ _user_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "user.sjson"));
|
|
|
+
|
|
|
+ _log_stream = GLib.FileStream.open(_log_file.get_path(), "a");
|
|
|
+
|
|
|
+ LevelEditorApplication app = new LevelEditorApplication();
|
|
|
+ return app.run(args);
|
|
|
+}
|
|
|
+
|
|
|
}
|