[four-in-a-row: 55/72] made GameBoardView not a singleton
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row: 55/72] made GameBoardView not a singleton
- Date: Sun, 16 Dec 2018 21:01:24 +0000 (UTC)
commit 35d3187254482ece304c5557ada3b48957ad8209
Author: Jacob Humphrey <jacob ryan humphrey gmail com>
Date: Sat Dec 15 05:20:11 2018 -0600
made GameBoardView not a singleton
src/four-in-a-row.vala | 31 ++++++++++++++++---------------
src/game-board-view.vala | 15 +++++----------
src/main.vala | 3 ---
src/prefs.vala | 7 ++-----
4 files changed, 23 insertions(+), 33 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index a2994d0..e905458 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -32,6 +32,7 @@ class FourInARow : Gtk.Application {
public PlayerID who_starts;
PrefsBox? prefsbox = null;
Scorebox scorebox;
+ GameBoardView game_board_view;
/**
* socre:
*
@@ -84,7 +85,7 @@ class FourInARow : Gtk.Application {
clear_board();
set_status_message(null);
- GameBoardView.instance.draw_all();
+ game_board_view.draw_all();
move_cursor(column);
gameover = false;
@@ -177,7 +178,7 @@ class FourInARow : Gtk.Application {
do {
done = (r1 == r2 && c1 == c2);
Board.instance.set(r1, c1, (Tile) tile);
- GameBoardView.instance.draw_tile(r1, c1);
+ game_board_view.draw_tile(r1, c1);
if (r1 != r2)
r1 += d_row;
if (c1 != c2)
@@ -205,8 +206,8 @@ class FourInARow : Gtk.Application {
protected override void activate() {
if (!window.is_visible()) {
window.show_all();
- GameBoardView.instance.refresh_pixmaps();
- GameBoardView.instance.draw_all();
+ game_board_view.refresh_pixmaps();
+ game_board_view.draw_all();
scorebox.update(score); /* update visible player descriptions */
prompt_player();
game_reset();
@@ -368,7 +369,6 @@ class FourInARow : Gtk.Application {
score[PlayerID.NOBODY] = 0;
who_starts = PlayerID.PLAYER2; /* This gets reversed immediately. */
-
clear_board();
}
@@ -407,7 +407,7 @@ class FourInARow : Gtk.Application {
Tile tile = player == PlayerID.PLAYER1 ? Tile.PLAYER1 : Tile.PLAYER2;
Board.instance.set(r, c, tile);
- GameBoardView.instance.draw_tile(r, c);
+ game_board_view.draw_tile(r, c);
column = column_moveto = c;
row = row_dropto = r;
@@ -417,21 +417,21 @@ class FourInARow : Gtk.Application {
Tile tile = player == PLAYER1 ? Tile.PLAYER1 : Tile.PLAYER2;
Board.instance.set(row, column, Tile.CLEAR);
- GameBoardView.instance.draw_tile(row, column);
+ game_board_view.draw_tile(row, column);
row++;
Board.instance.set(row, column, tile);
- GameBoardView.instance.draw_tile(row, column);
+ game_board_view.draw_tile(row, column);
}
public void move(int c) {
Board.instance.set(0, column, Tile.CLEAR);
- GameBoardView.instance.draw_tile(0, column);
+ game_board_view.draw_tile(0, column);
column = c;
Board.instance.set(0, c, player == PlayerID.PLAYER1 ? Tile.PLAYER1 : Tile.PLAYER2);
- GameBoardView.instance.draw_tile(0, c);
+ game_board_view.draw_tile(0, c);
}
public void move_cursor(int c) {
@@ -619,7 +619,7 @@ class FourInARow : Gtk.Application {
move_cursor(c);
Board.instance.set(r, c, Tile.CLEAR);
- GameBoardView.instance.draw_tile(r, c);
+ game_board_view.draw_tile(r, c);
if (Prefs.instance.get_n_human_players() == 1 && !is_player_human()) {
if (moves > 0) {
@@ -631,7 +631,7 @@ class FourInARow : Gtk.Application {
swap_player();
move_cursor(c);
Board.instance.set(r, c, Tile.CLEAR);
- GameBoardView.instance.draw_tile(r, c);
+ game_board_view.draw_tile(r, c);
}
}
}
@@ -704,6 +704,7 @@ class FourInARow : Gtk.Application {
protected override void startup() {
base.startup();
+
scorebox = new Scorebox(this);
Gtk.AspectFrame frame;
GLib.Menu app_menu, section;
@@ -723,7 +724,7 @@ class FourInARow : Gtk.Application {
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-
+ game_board_view = new GameBoardView();
builder = new Gtk.Builder.from_file(Config.DATA_DIRECTORY + "/four-in-a-row.ui");
window = builder.get_object("fiar-window") as Gtk.ApplicationWindow;
@@ -749,8 +750,8 @@ class FourInARow : Gtk.Application {
frame = builder.get_object("frame") as Gtk.AspectFrame;
- frame.add(GameBoardView.instance);
- GameBoardView.instance.column_clicked.connect(column_clicked_cb);
+ frame.add(game_board_view);
+ game_board_view.column_clicked.connect(column_clicked_cb);
window.key_press_event.connect(on_key_press);
hint_action.set_enabled(false);
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index e6480d5..4b056e2 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -29,17 +29,8 @@ class GameBoardView : Gtk.DrawingArea {
/* scaled pixbufs */
Gdk.Pixbuf pb_tileset;
Gdk.Pixbuf pb_bground;
- //public Gtk.DrawingArea drawarea;
-
- static Once<GameBoardView> _instance;
- public static GameBoardView instance {
- get {
- return _instance.once(() => {return new GameBoardView();});
- }
- }
public GameBoardView() {
- Object();
/* set a min size to avoid pathological behavior of gtk when scaling down */
set_size_request(350, 350);
halign = Gtk.Align.FILL;
@@ -48,6 +39,10 @@ class GameBoardView : Gtk.DrawingArea {
events = Gdk.EventMask.EXPOSURE_MASK |
Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK;
+ Prefs.instance.notify["theme_id"].connect(() =>{
+ change_theme();
+ });
+ load_pixmaps();
}
public int get_column(int xpos) {
@@ -95,7 +90,7 @@ class GameBoardView : Gtk.DrawingArea {
return false;
refresh_pixmaps();
- instance.draw_all();
+ draw_all();
return true;
}
diff --git a/src/main.vala b/src/main.vala
index ce796ce..d110db2 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -98,9 +98,6 @@ public int main(string[] argv) {
application.game_init();
- if (!GameBoardView.instance.load_pixmaps())
- return 1;
-
var app_retval = application.run(argv);
return app_retval;
diff --git a/src/prefs.vala b/src/prefs.vala
index c390324..8706dda 100644
--- a/src/prefs.vala
+++ b/src/prefs.vala
@@ -59,9 +59,6 @@ class Prefs : Object {
level[PlayerID.PLAYER1] = sane_player_level(level[PlayerID.PLAYER1]);
level[PlayerID.PLAYER2] = sane_player_level(level[PlayerID.PLAYER2]);
theme_id = sane_theme_id(theme_id);
- notify["theme_id"].connect(() =>{
- GameBoardView.instance.change_theme();
- });
}
static int sane_theme_id(int val) {
@@ -84,8 +81,8 @@ class Prefs : Object {
int val = sane_theme_id(settings.get_int("theme-id"));
if (val != theme_id) {
theme_id = val;
- if (!GameBoardView.instance.change_theme())
- return;
+ //if (!GameBoardView.instance.change_theme())
+ //return;
theme_changed(theme_id);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]