From f11ee3cfe3c7a15103573fe786bde15b2c8569e7 Mon Sep 17 00:00:00 2001 From: Arnaud Bonatti Date: Mon, 25 May 2020 23:50:33 +0200 Subject: [PATCH] Drop Clutter dependency. --- meson.build | 2 -- src/meson.build | 2 -- 2 files changed, 4 deletions(-) diff --git a/meson.build b/meson.build index fba3df89..e19ec212 100644 --- a/meson.build +++ b/meson.build @@ -18,8 +18,6 @@ bindir = join_paths(prefix, get_option ('bindir')) # Dependencies glib_version = '2.42.0' -clutter_dep = dependency('clutter-1.0', version: '>= 1.22.0') -clutter_gtk_dep = dependency('clutter-gtk-1.0', version: '>= 1.4.0') gee_dep = dependency('gee-0.8') gio_dep = dependency('gio-2.0', version: '>= @0@'.format(glib_version)) glib_dep = dependency('glib-2.0', version: '>= @0@'.format(glib_version)) diff --git a/src/meson.build b/src/meson.build index 0d704c7b..c02937f5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -37,8 +37,6 @@ gnome_nibbles_sources = [ ] gnome_nibbles_deps = [ - clutter_dep, - clutter_gtk_dep, gee_dep, gio_dep, glib_dep, -- GitLab From 3c3db09b45e747929e7b2adf48b326fd4f339e2e Mon Sep 17 00:00:00 2001 From: Arnaud Bonatti Date: Sat, 30 May 2020 18:06:06 +0200 Subject: [PATCH] Comment Clutter things. --- src/nibbles-view.vala | 724 ++++++++++++++++++++-------------------- src/nibbles-window.vala | 6 +- 2 files changed, 368 insertions(+), 362 deletions(-) diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala index c6600c3c..588972bc 100644 --- a/src/nibbles-view.vala +++ b/src/nibbles-view.vala @@ -16,98 +16,107 @@ * along with this program. If not, see . */ -private class NibblesView : GtkClutter.Embed +using Gtk; + +private class NibblesView : Widget { - private class WormActor : Clutter.Actor + private class WormView : Object { - protected override void show () - { - base.show (); - - set_opacity (0); - set_scale (3.0, 3.0); - - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC); - set_easing_duration (GAMEDELAY * 26); - set_scale (1.0, 1.0); - set_pivot_point (0.5f, 0.5f); - set_opacity (0xff); - restore_easing_state (); - } + private List widgets; - protected override void hide () + internal void set_opacity (uint8 new_opacity) { - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); - set_easing_duration (GAMEDELAY * 15); - set_scale (0.4f, 0.4f); - set_opacity (0); - restore_easing_state (); + foreach (Widget widget in widgets) + widget.set_opacity (new_opacity); } +// protected override void show () +// { +// base.show (); + +// set_opacity (0); +// set_scale (3.0, 3.0); + +// save_easing_state (); +// set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC); +// set_easing_duration (GAMEDELAY * 26); +// set_scale (1.0, 1.0); +// set_pivot_point (0.5f, 0.5f); +// set_opacity (0xff); +// restore_easing_state (); +// } + +// protected override void hide () +// { +// save_easing_state (); +// set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); +// set_easing_duration (GAMEDELAY * 15); +// set_scale (0.4f, 0.4f); +// set_opacity (0); +// restore_easing_state (); +// } } - private class BonusTexture : GtkClutter.Texture + private class BonusTexture : Object { - private const float SIZE_MULTIPLIER = 2; +// private const float SIZE_MULTIPLIER = 2; - protected override void show () - { - base.show (); - - set_opacity (0); - set_scale (3.0, 3.0); - - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE); - set_easing_duration (GAMEDELAY * 20); - set_scale (1.0, 1.0); - set_pivot_point (0.5f, 0.5f); - set_opacity (0xff); - restore_easing_state (); - } +// protected override void show () +// { +// base.show (); - internal new void set_size (float width, float height) - { - base.set_size (SIZE_MULTIPLIER * width, SIZE_MULTIPLIER * height); - } +// set_opacity (0); +// set_scale (3.0, 3.0); + +// save_easing_state (); +// set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE); +// set_easing_duration (GAMEDELAY * 20); +// set_scale (1.0, 1.0); +// set_pivot_point (0.5f, 0.5f); +// set_opacity (0xff); +// restore_easing_state (); +// } + +// internal new void set_size (float width, float height) +// { +// base.set_size (SIZE_MULTIPLIER * width, SIZE_MULTIPLIER * height); +// } } - private class WarpTexture: GtkClutter.Texture + private class WarpTexture: Object { - private const float SIZE_MULTIPLIER = 2; +// private const float SIZE_MULTIPLIER = 2; - protected override void show () - { - base.show (); - - set_opacity (0); - set_scale (3.0, 3.0); - - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC); - set_easing_duration (GAMEDELAY * 15); - set_scale (1.0, 1.0); - set_pivot_point (0.5f, 0.5f); - set_opacity (0xff); - restore_easing_state (); - } +// protected override void show () +// { +// base.show (); - protected override void hide () - { - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); - set_easing_duration (GAMEDELAY * 15); - set_scale (0.4f, 0.4f); - set_pivot_point (0.5f, 0.5f); - set_opacity (0); - restore_easing_state (); - } +// set_opacity (0); +// set_scale (3.0, 3.0); - internal new void set_size (float width, float height) - { - base.set_size (SIZE_MULTIPLIER * width, SIZE_MULTIPLIER * height); - } +// save_easing_state (); +// set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC); +// set_easing_duration (GAMEDELAY * 15); +// set_scale (1.0, 1.0); +// set_pivot_point (0.5f, 0.5f); +// set_opacity (0xff); +// restore_easing_state (); +// } + +// protected override void hide () +// { +// save_easing_state (); +// set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); +// set_easing_duration (GAMEDELAY * 15); +// set_scale (0.4f, 0.4f); +// set_pivot_point (0.5f, 0.5f); +// set_opacity (0); +// restore_easing_state (); +// } + +// internal new void set_size (float width, float height) +// { +// base.set_size (SIZE_MULTIPLIER * width, SIZE_MULTIPLIER * height); +// } } internal const uint8 WIDTH = 92; @@ -123,14 +132,16 @@ private class NibblesView : GtkClutter.Embed private Gdk.Pixbuf boni_pixmaps[9]; /* Actors */ - private Clutter.Stage stage; - private Clutter.Actor level; - internal Clutter.Actor name_labels { get; private set; } +// private Clutter.Stage stage; +// private Clutter.Actor level; +// internal Clutter.Actor name_labels { get; private set; } - private Gee.HashMap worm_actors = new Gee.HashMap (); + private Gee.HashMap worm_actors = new Gee.HashMap (); private Gee.HashMap bonus_actors = new Gee.HashMap (); private Gee.HashSet warp_actors = new Gee.HashSet (); + private GridLayout layout; + /* Game being played */ private NibblesGame _game; public NibblesGame game @@ -153,13 +164,19 @@ private class NibblesView : GtkClutter.Embed } } + construct + { + layout = new GridLayout (); + set_layout_manager (layout); + } + internal NibblesView (NibblesGame game, int tile_size, bool is_muted) { Object (game: game, tile_size: tile_size, is_muted: is_muted); - stage = (Clutter.Stage) get_stage (); - Clutter.Color stage_color = { 0x00, 0x00, 0x00, 0xff }; - stage.set_background_color (stage_color); +// stage = (Clutter.Stage) get_stage (); +// Clutter.Color stage_color = { 0x00, 0x00, 0x00, 0xff }; +// stage.set_background_color (stage_color); set_size_request (MINIMUM_TILE_SIZE * WIDTH, MINIMUM_TILE_SIZE * HEIGHT); @@ -215,23 +232,23 @@ private class NibblesView : GtkClutter.Embed error ("Nibbles couldn't find pixmap file: %s", filename); foreach (var actor in worm_actors.values) - actor.destroy (); + actor.unparent (); worm_actors.clear (); foreach (var actor in bonus_actors.values) - actor.destroy (); + actor.unparent (); bonus_actors.clear (); foreach (var actor in warp_actors) - actor.destroy (); + actor.unparent (); warp_actors.clear (); if (level != null) { - level.remove_all_children (); - stage.remove_child (level); +// level.remove_all_children (); +// stage.remove_child (level); } - level = new Clutter.Actor (); +// level = new Clutter.Actor (); string? line; string [] board = {}; @@ -242,14 +259,14 @@ private class NibblesView : GtkClutter.Embed foreach (Worm worm in game.worms) { - var actors = new WormActor (); - stage.add_child (actors); + var actors = new WormView (); +// stage.add_child (actors); worm_actors.@set (worm, actors); } /* Load wall_pixmaps onto the surface */ int x_pos, y_pos; - GtkClutter.Texture? tmp; + Image? tmp; for (int i = 0; i < HEIGHT; i++) { y_pos = i * tile_size; @@ -264,48 +281,37 @@ private class NibblesView : GtkClutter.Embed break; case 'b': // straight up - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[0]); + tmp = new Image.from_pixbuf (wall_pixmaps[0]); break; case 'c': // straight side - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[1]); + tmp = new Image.from_pixbuf (wall_pixmaps[1]); break; case 'd': // corner bottom left - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[2]); + tmp = new Image.from_pixbuf (wall_pixmaps[2]); break; case 'e': // corner bottom right - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[3]); + tmp = new Image.from_pixbuf (wall_pixmaps[3]); break; case 'f': // corner up left - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[4]); + tmp = new Image.from_pixbuf (wall_pixmaps[4]); break; case 'g': // corner up right - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[5]); + tmp = new Image.from_pixbuf (wall_pixmaps[5]); break; case 'h': // tee up - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[6]); + tmp = new Image.from_pixbuf (wall_pixmaps[6]); break; case 'i': // tee right - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[7]); + tmp = new Image.from_pixbuf (wall_pixmaps[7]); break; case 'j': // tee left - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[8]); + tmp = new Image.from_pixbuf (wall_pixmaps[8]); break; case 'k': // tee down - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[9]); + tmp = new Image.from_pixbuf (wall_pixmaps[9]); break; case 'l': // tee cross - tmp = new GtkClutter.Texture (); - tmp.set_from_pixbuf (wall_pixmaps[10]); + tmp = new Image.from_pixbuf (wall_pixmaps[10]); break; case 'r': // should have been repleced by NibblesGame.EMPTYCHAR @@ -340,26 +346,24 @@ private class NibblesView : GtkClutter.Embed if (tmp != null) { - x_pos = j * tile_size; - - ((!) tmp).set_size (tile_size, tile_size); - ((!) tmp).set_position (x_pos, y_pos); - level.add_child ((!) tmp); + ((!) tmp).insert_after (this, /* insert first */ null); + GridLayoutChild child_layout = layout.get_layout_child ((!) tmp); + child_layout.set_position (i, j); } } } - stage.add_child (level); +// stage.add_child (level); - level.set_opacity (0); - level.set_scale (0.2, 0.2); +// level.set_opacity (0); +// level.set_scale (0.2, 0.2); - level.save_easing_state (); - level.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE); - level.set_easing_duration (GAMEDELAY * GAMEDELAY); - level.set_scale (1.0, 1.0); - level.set_pivot_point (0.5f, 0.5f); - level.set_opacity (0xff); - level.restore_easing_state (); +// level.save_easing_state (); +// level.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE); +// level.set_easing_duration (GAMEDELAY * GAMEDELAY); +// level.set_scale (1.0, 1.0); +// level.set_pivot_point (0.5f, 0.5f); +// level.set_opacity (0xff); +// level.restore_easing_state (); } /*\ @@ -456,12 +460,12 @@ private class NibblesView : GtkClutter.Embed uint8 opacity; opacity = worm.is_materialized ? 0xff : 0x50; - var actors = worm_actors.@get (worm); + WormView actors = worm_actors.@get (worm); - actors.save_easing_state (); - actors.set_easing_duration (GAMEDELAY * 10); +// actors.save_easing_state (); +// actors.set_easing_duration (GAMEDELAY * 10); actors.set_opacity (opacity); - actors.restore_easing_state (); +// actors.restore_easing_state (); }); } } @@ -469,7 +473,7 @@ private class NibblesView : GtkClutter.Embed private void board_rescale (int new_tile_size) { int board_width, board_height; - float x_pos, y_pos; +// float x_pos, y_pos; if (level == null) return; @@ -477,33 +481,35 @@ private class NibblesView : GtkClutter.Embed board_width = WIDTH * new_tile_size; board_height = HEIGHT * new_tile_size; - foreach (var actor in level.get_children ()) - { - actor.get_position (out x_pos, out y_pos); - actor.set_position ((x_pos / tile_size) * new_tile_size, - (y_pos / tile_size) * new_tile_size); - actor.set_size (new_tile_size, new_tile_size); - } - - if (!name_labels.visible) - return; - - foreach (var worm in game.worms) - { - var actor = name_labels.get_child_at_index (worm.id); - - var middle = worm.length / 2; - if (worm.direction == WormDirection.UP || worm.direction == WormDirection.DOWN) - { - actor.set_x (worm.list[middle].x * new_tile_size - actor.width / 2 + new_tile_size / 2); - actor.set_y (worm.list[middle].y * new_tile_size - 5 * new_tile_size); - } - else if (worm.direction == WormDirection.LEFT || worm.direction == WormDirection.RIGHT) - { - actor.set_x (worm.list[middle].x * new_tile_size - actor.width / 2 + new_tile_size / 2); - actor.set_y (worm.head.y * new_tile_size - 3 * new_tile_size); - } - } + warning (@"new board size: $board_width, $board_height"); + +// foreach (var actor in level.get_children ()) +// { +// actor.get_position (out x_pos, out y_pos); +// actor.set_position ((x_pos / tile_size) * new_tile_size, +// (y_pos / tile_size) * new_tile_size); +// actor.set_size (new_tile_size, new_tile_size); +// } + +// if (!name_labels.visible) +// return; + +// foreach (var worm in game.worms) +// { +// var actor = name_labels.get_child_at_index (worm.id); + +// var middle = worm.length / 2; +// if (worm.direction == WormDirection.UP || worm.direction == WormDirection.DOWN) +// { +// actor.set_x (worm.list[middle].x * new_tile_size - actor.width / 2 + new_tile_size / 2); +// actor.set_y (worm.list[middle].y * new_tile_size - 5 * new_tile_size); +// } +// else if (worm.direction == WormDirection.LEFT || worm.direction == WormDirection.RIGHT) +// { +// actor.set_x (worm.list[middle].x * new_tile_size - actor.width / 2 + new_tile_size / 2); +// actor.set_y (worm.head.y * new_tile_size - 3 * new_tile_size); +// } +// } } private void animate_end_game_cb () @@ -514,44 +520,44 @@ private class NibblesView : GtkClutter.Embed foreach (var actor in warp_actors) actor.hide (); - level.save_easing_state (); - level.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); - level.set_easing_duration (GAMEDELAY * 20); - level.set_scale (0.4f, 0.4f); - level.set_pivot_point (0.5f, 0.5f); - level.set_opacity (0); - level.restore_easing_state (); - } - - internal void create_name_labels () - { - name_labels = new Clutter.Actor (); - foreach (var worm in game.worms) - { - var color = game.worm_props.@get (worm).color; - - /* Translators: the player's number, e.g. "Player 1" or "Player 2". */ - var player_id = _("Player %d").printf (worm.id + 1); - var label = new Clutter.Text.with_text ("Monospace 10", @"$(player_id)"); - label.set_use_markup (true); - label.set_color (Clutter.Color.from_string (colorval_name_untranslated (color))); - - var middle = worm.length / 2; - if (worm.direction == WormDirection.UP || worm.direction == WormDirection.DOWN) - { - label.set_x (worm.list[middle].x * tile_size - label.width / 2 + tile_size / 2); - label.set_y (worm.list[middle].y * tile_size - 5 * tile_size); - } - else if (worm.direction == WormDirection.LEFT || worm.direction == WormDirection.RIGHT) - { - label.set_x (worm.list[middle].x * tile_size - label.width / 2 + tile_size / 2); - label.set_y (worm.head.y * tile_size - 3 * tile_size); - } - name_labels.add (label); - } - - level.add_child (name_labels); - } +// level.save_easing_state (); +// level.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD); +// level.set_easing_duration (GAMEDELAY * 20); +// level.set_scale (0.4f, 0.4f); +// level.set_pivot_point (0.5f, 0.5f); +// level.set_opacity (0); +// level.restore_easing_state (); + } + +// internal void create_name_labels () +// { +// name_labels = new Clutter.Actor (); +// foreach (var worm in game.worms) +// { +// var color = game.worm_props.@get (worm).color; + +// /* Translators: the player's number, e.g. "Player 1" or "Player 2". */ +// var player_id = _("Player %d").printf (worm.id + 1); +// var label = new Clutter.Text.with_text ("Monospace 10", @"$(player_id)"); +// label.set_use_markup (true); +// label.set_color (Clutter.Color.from_string (colorval_name_untranslated (color))); + +// var middle = worm.length / 2; +// if (worm.direction == WormDirection.UP || worm.direction == WormDirection.DOWN) +// { +// label.set_x (worm.list[middle].x * tile_size - label.width / 2 + tile_size / 2); +// label.set_y (worm.list[middle].y * tile_size - 5 * tile_size); +// } +// else if (worm.direction == WormDirection.LEFT || worm.direction == WormDirection.RIGHT) +// { +// label.set_x (worm.list[middle].x * tile_size - label.width / 2 + tile_size / 2); +// label.set_y (worm.head.y * tile_size - 3 * tile_size); +// } +// name_labels.add (label); +// } + +// level.add_child (name_labels); +// } /*\ * * Worms drawing @@ -559,159 +565,159 @@ private class NibblesView : GtkClutter.Embed private void worm_added_cb (Worm worm) { - var actor = new GtkClutter.Texture (); - try - { - actor.set_from_pixbuf (worm_pixmaps[game.worm_props.@get (worm).color]); - } - catch (Clutter.TextureError e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - catch (Error e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - actor.set_size (tile_size, tile_size); - actor.set_position (worm.list.first ().x * tile_size, worm.list.first ().y * tile_size); - - var actors = worm_actors.@get (worm); - actors.add_child (actor); +// var actor = new GtkClutter.Texture (); +// try +// { +// actor.set_from_pixbuf (worm_pixmaps[game.worm_props.@get (worm).color]); +// } +// catch (Clutter.TextureError e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// catch (Error e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// actor.set_size (tile_size, tile_size); +// actor.set_position (worm.list.first ().x * tile_size, worm.list.first ().y * tile_size); + +// var actors = worm_actors.@get (worm); +// actors.add_child (actor); } private void worm_finish_added_cb (Worm worm) { - var actors = worm_actors.@get (worm); + WormView actors = worm_actors.@get (worm); actors.set_opacity (0); - actors.set_scale (3.0, 3.0); +// actors.set_scale (3.0, 3.0); - actors.save_easing_state (); - actors.set_easing_mode (Clutter.AnimationMode.EASE_OUT); - actors.set_easing_duration (GAMEDELAY * 20); - actors.set_scale (1.0, 1.0); - actors.set_pivot_point (0.5f, 0.5f); - actors.set_opacity (0xff); - actors.restore_easing_state (); +// actors.save_easing_state (); +// actors.set_easing_mode (Clutter.AnimationMode.EASE_OUT); +// actors.set_easing_duration (GAMEDELAY * 20); +// actors.set_scale (1.0, 1.0); +// actors.set_pivot_point (0.5f, 0.5f); +// actors.set_opacity (0xff); +// actors.restore_easing_state (); } private void worm_moved_cb (Worm worm) { var actors = worm_actors.@get (worm); - var tail_actor = actors.first_child; - actors.remove_child (tail_actor); +// var tail_actor = actors.first_child; +// actors.remove_child (tail_actor); worm_added_cb (worm); } private void worm_rescaled_cb (Worm worm, int new_tile_size) { - float x_pos, y_pos; +// float x_pos, y_pos; var actors = worm_actors.@get (worm); if (actors == null) return; - foreach (var actor in actors.get_children ()) - { - actor.get_position (out x_pos, out y_pos); - actor.set_position ((x_pos / tile_size) * new_tile_size, - (y_pos / tile_size) * new_tile_size); - actor.set_size (new_tile_size, new_tile_size); - } +// foreach (var actor in actors.get_children ()) +// { +// actor.get_position (out x_pos, out y_pos); +// actor.set_position ((x_pos / tile_size) * new_tile_size, +// (y_pos / tile_size) * new_tile_size); +// actor.set_size (new_tile_size, new_tile_size); +// } } private void worm_died_cb (Worm worm) { - float x, y; - var group = new Clutter.Actor (); - var actors = worm_actors.@get (worm); - foreach (var actor in actors.get_children ()) - { - GtkClutter.Texture texture = new GtkClutter.Texture (); - var color = game.worm_props.@get (worm).color; - try - { - texture.set_from_pixbuf (worm_pixmaps[color]); - } - catch (Clutter.TextureError e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - catch (Error e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - - actor.get_position (out x, out y); - - texture.set_position (x, y); - texture.set_size (tile_size, tile_size); - group.add_child (texture); - } - - actors.remove_all_children (); - - level.add_child (group); - - group.save_easing_state (); - group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); - group.set_easing_duration (GAMEDELAY * 9); - group.set_scale (2.0f, 2.0f); - group.set_pivot_point (0.5f, 0.5f); - group.set_opacity (0); - group.restore_easing_state (); +// float x, y; +// var group = new Clutter.Actor (); +// var actors = worm_actors.@get (worm); +// foreach (var actor in actors.get_children ()) +// { +// GtkClutter.Texture texture = new GtkClutter.Texture (); +// var color = game.worm_props.@get (worm).color; +// try +// { +// texture.set_from_pixbuf (worm_pixmaps[color]); +// } +// catch (Clutter.TextureError e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// catch (Error e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } + +// actor.get_position (out x, out y); + +// texture.set_position (x, y); +// texture.set_size (tile_size, tile_size); +// group.add_child (texture); +// } + +// actors.remove_all_children (); + +// level.add_child (group); + +// group.save_easing_state (); +// group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); +// group.set_easing_duration (GAMEDELAY * 9); +// group.set_scale (2.0f, 2.0f); +// group.set_pivot_point (0.5f, 0.5f); +// group.set_opacity (0); +// group.restore_easing_state (); play_sound ("crash"); } private void worm_tail_reduced_cb (Worm worm, int erase_size) { - float x, y; - var group = new Clutter.Actor (); - var worm_actors = worm_actors.@get (worm); - var color = game.worm_props.@get (worm).color; - for (int i = 0; i < erase_size; i++) - { - var texture = new GtkClutter.Texture (); - try - { - texture.set_from_pixbuf (worm_pixmaps[color]); - } - catch (Clutter.TextureError e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - catch (Error e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - - worm_actors.first_child.get_position (out x, out y); - worm_actors.remove_child (worm_actors.first_child); - - texture.set_position (x, y); - texture.set_size (tile_size, tile_size); - group.add_child (texture); - } - level.add_child (group); - - group.save_easing_state (); - group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO); - group.set_easing_duration (GAMEDELAY * 25); - group.set_opacity (0); - group.restore_easing_state (); +// float x, y; +// var group = new Clutter.Actor (); +// var worm_actors = worm_actors.@get (worm); +// var color = game.worm_props.@get (worm).color; +// for (int i = 0; i < erase_size; i++) +// { +// var texture = new GtkClutter.Texture (); +// try +// { +// texture.set_from_pixbuf (worm_pixmaps[color]); +// } +// catch (Clutter.TextureError e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// catch (Error e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } + +// worm_actors.first_child.get_position (out x, out y); +// worm_actors.remove_child (worm_actors.first_child); + +// texture.set_position (x, y); +// texture.set_size (tile_size, tile_size); +// group.add_child (texture); +// } +// level.add_child (group); + +// group.save_easing_state (); +// group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO); +// group.set_easing_duration (GAMEDELAY * 25); +// group.set_opacity (0); +// group.restore_easing_state (); } private void worm_reversed_cb (Worm worm) { - var actors = worm_actors.@get (worm); +// var actors = worm_actors.@get (worm); - var count = 0; - foreach (var actor in actors.get_children ()) - { - actor.set_position (worm.list[count].x * tile_size, worm.list[count].y * tile_size); - count++; - } +// var count = 0; +// foreach (var actor in actors.get_children ()) +// { +// actor.set_position (worm.list[count].x * tile_size, worm.list[count].y * tile_size); +// count++; +// } } /*\ @@ -721,23 +727,23 @@ private class NibblesView : GtkClutter.Embed private void bonus_added_cb (Bonus bonus) { var actor = new BonusTexture (); - try - { - actor.set_from_pixbuf (boni_pixmaps[bonus.bonus_type]); - } - catch (Clutter.TextureError e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - catch (Error e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - - actor.set_size (tile_size, tile_size); - actor.set_position ((int) bonus.x * tile_size, (int) bonus.y * tile_size); - - level.add_child (actor); +// try +// { +// actor.set_from_pixbuf (boni_pixmaps[bonus.bonus_type]); +// } +// catch (Clutter.TextureError e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// catch (Error e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } + +// actor.set_size (tile_size, tile_size); +// actor.set_position ((int) bonus.x * tile_size, (int) bonus.y * tile_size); + +// level.add_child (actor); if (bonus.bonus_type != BonusType.REGULAR) play_sound ("appear"); @@ -749,7 +755,7 @@ private class NibblesView : GtkClutter.Embed var bonus_actor = bonus_actors.@get (bonus); bonus_actors.unset (bonus); bonus_actor.hide (); - level.remove_child (bonus_actor); +// level.remove_child (bonus_actor); } private void bonus_applied_cb (Bonus bonus, Worm worm) @@ -757,12 +763,12 @@ private class NibblesView : GtkClutter.Embed var actors = worm_actors.@get (worm); var actor = actors.last_child; - actor.save_easing_state (); - actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT); - actor.set_easing_duration (GAMEDELAY * 15); - actor.set_scale (1.45f, 1.45f); - actor.set_pivot_point (0.5f, 0.5f); - actor.restore_easing_state (); +// actor.save_easing_state (); +// actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT); +// actor.set_easing_duration (GAMEDELAY * 15); +// actor.set_scale (1.45f, 1.45f); +// actor.set_pivot_point (0.5f, 0.5f); +// actor.restore_easing_state (); switch (bonus.bonus_type) { @@ -791,7 +797,7 @@ private class NibblesView : GtkClutter.Embed foreach (var bonus in bonus_actors.keys) { var actor = bonus_actors.@get (bonus); - actor.set_size (new_tile_size, new_tile_size); +// actor.set_size (new_tile_size, new_tile_size); } } @@ -802,31 +808,31 @@ private class NibblesView : GtkClutter.Embed private void warp_added_cb (uint8 x, uint8 y) { var actor = new WarpTexture (); - try - { - actor.set_from_pixbuf (boni_pixmaps[BonusType.WARP]); - } - catch (Clutter.TextureError e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - catch (Error e) - { - error ("Nibbles failed to set texture: %s", e.message); - } - - actor.set_size (tile_size, tile_size); - actor.set_position ((int) x * tile_size, (int) y * tile_size); - - level.add_child (actor); +// try +// { +// actor.set_from_pixbuf (boni_pixmaps[BonusType.WARP]); +// } +// catch (Clutter.TextureError e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } +// catch (Error e) +// { +// error ("Nibbles failed to set texture: %s", e.message); +// } + +// actor.set_size (tile_size, tile_size); +// actor.set_position ((int) x * tile_size, (int) y * tile_size); + +// level.add_child (actor); warp_actors.add (actor); } private void warps_rescale (int new_tile_size) { - foreach (var actor in warp_actors) - actor.set_size (new_tile_size, new_tile_size); +// foreach (var actor in warp_actors) +// actor.set_size (new_tile_size, new_tile_size); } /*\ diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala index 0acf95de..81ed03a0 100644 --- a/src/nibbles-window.vala +++ b/src/nibbles-window.vala @@ -252,7 +252,7 @@ private class NibblesWindow : ApplicationWindow if (seconds == 0) { statusbar_stack.set_visible_child_name ("scoreboard"); - view.name_labels.hide (); +// view.name_labels.hide (); game.start (/* add initial bonus */ true); @@ -344,7 +344,7 @@ private class NibblesWindow : ApplicationWindow } game.add_worms (); - view.create_name_labels (); +// view.create_name_labels (); show_game_view (); @@ -359,7 +359,7 @@ private class NibblesWindow : ApplicationWindow back_action.set_enabled (true); seconds = COUNTDOWN_TIME; - view.name_labels.show (); +// view.name_labels.show (); countdown.set_label (COUNTDOWN_TIME.to_string ()); countdown_id = Timeout.add_seconds (1, countdown_cb); -- GitLab From 6d55b0f6f8d8259acff93ad1c365d6562fbffb1a Mon Sep 17 00:00:00 2001 From: Arnaud Bonatti Date: Sat, 30 May 2020 18:07:08 +0200 Subject: [PATCH] Comment EventConfigure thing. --- src/nibbles-view.vala | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala index 588972bc..82c05ef5 100644 --- a/src/nibbles-view.vala +++ b/src/nibbles-view.vala @@ -184,39 +184,39 @@ private class NibblesView : Widget load_pixmap (); } - protected override bool configure_event (Gdk.EventConfigure event) - { - int new_tile_size, ts_x, ts_y; - - /* Compute the new tile size based on the size of the - * drawing area, rounded down. - */ - ts_x = event.width / WIDTH; - ts_y = event.height / HEIGHT; - if (ts_x * WIDTH > event.width) - ts_x--; - if (ts_y * HEIGHT > event.height) - ts_y--; - new_tile_size = int.min (ts_x, ts_y); - - if (new_tile_size == 0 || tile_size == 0) - return true; - - if (tile_size != new_tile_size) - { - get_stage ().set_size (new_tile_size * WIDTH, new_tile_size * HEIGHT); +// protected override bool configure_event (Gdk.EventConfigure event) +// { +// int new_tile_size, ts_x, ts_y; + +// /* Compute the new tile size based on the size of the +// * drawing area, rounded down. +// */ +// ts_x = event.width / WIDTH; +// ts_y = event.height / HEIGHT; +// if (ts_x * WIDTH > event.width) +// ts_x--; +// if (ts_y * HEIGHT > event.height) +// ts_y--; +// new_tile_size = int.min (ts_x, ts_y); + +// if (new_tile_size == 0 || tile_size == 0) +// return true; + +// if (tile_size != new_tile_size) +// { +// get_stage ().set_size (new_tile_size * WIDTH, new_tile_size * HEIGHT); - board_rescale (new_tile_size); - boni_rescale (new_tile_size); - warps_rescale (new_tile_size); - foreach (var worm in game.worms) - worm.rescaled (new_tile_size); +// board_rescale (new_tile_size); +// boni_rescale (new_tile_size); +// warps_rescale (new_tile_size); +// foreach (var worm in game.worms) +// worm.rescaled (new_tile_size); - tile_size = new_tile_size; - } +// tile_size = new_tile_size; +// } - return false; - } +// return false; +// } /*\ * * Level creation and loading -- GitLab From 49630b5de1cba018fbd7f3cf7f3f9d216319dcea Mon Sep 17 00:00:00 2001 From: Arnaud Bonatti Date: Sun, 31 May 2020 00:02:39 +0200 Subject: [PATCH] Things 1. --- src/nibbles-view.vala | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala index 82c05ef5..5d45c0a5 100644 --- a/src/nibbles-view.vala +++ b/src/nibbles-view.vala @@ -22,13 +22,19 @@ private class NibblesView : Widget { private class WormView : Object { - private List widgets; + private List widgets = new List (); internal void set_opacity (uint8 new_opacity) { foreach (Widget widget in widgets) widget.set_opacity (new_opacity); } + + internal void unparent () + { + foreach (Widget widget in widgets) + widget.unparent (); + } // protected override void show () // { // base.show (); @@ -56,7 +62,7 @@ private class NibblesView : Widget // } } - private class BonusTexture : Object + private class BonusTexture : Widget { // private const float SIZE_MULTIPLIER = 2; @@ -82,7 +88,7 @@ private class NibblesView : Widget // } } - private class WarpTexture: Object + private class WarpTexture: Widget { // private const float SIZE_MULTIPLIER = 2; @@ -243,11 +249,11 @@ private class NibblesView : Widget actor.unparent (); warp_actors.clear (); - if (level != null) - { +// if (level != null) +// { // level.remove_all_children (); // stage.remove_child (level); - } +// } // level = new Clutter.Actor (); string? line; @@ -347,8 +353,9 @@ private class NibblesView : Widget if (tmp != null) { ((!) tmp).insert_after (this, /* insert first */ null); - GridLayoutChild child_layout = layout.get_layout_child ((!) tmp); - child_layout.set_position (i, j); + GridLayoutChild child_layout = (GridLayoutChild) layout.get_layout_child ((!) tmp); + child_layout.set_left_attach (i); + child_layout.set_top_attach (j); } } } @@ -475,8 +482,8 @@ private class NibblesView : Widget int board_width, board_height; // float x_pos, y_pos; - if (level == null) - return; +// if (level == null) +// return; board_width = WIDTH * new_tile_size; board_height = HEIGHT * new_tile_size; @@ -514,8 +521,8 @@ private class NibblesView : Widget private void animate_end_game_cb () { - foreach (var worm in game.worms) - worm_actors.@get (worm).hide (); +// foreach (var worm in game.worms) +// worm_actors.@get (worm).hide (); foreach (var actor in warp_actors) actor.hide (); @@ -761,7 +768,7 @@ private class NibblesView : Widget private void bonus_applied_cb (Bonus bonus, Worm worm) { var actors = worm_actors.@get (worm); - var actor = actors.last_child; +// var actor = actors.last_child; // actor.save_easing_state (); // actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT); -- GitLab