[atomix] Code cleanup around play/pause (Fixes #3)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [atomix] Code cleanup around play/pause (Fixes #3)
- Date: Sun, 25 Mar 2018 03:10:42 +0000 (UTC)
commit 56677314815aaa026f090a994bb4ac4dc4630aa6
Author: Robert Roth <robert roth off gmail com>
Date: Sun Mar 25 06:10:24 2018 +0300
Code cleanup around play/pause (Fixes #3)
data/ui/interface.ui | 522 ++++++++++++++++-----------------------------------
data/ui/menu.ui | 51 +++++
src/main.c | 214 ++++++++++-----------
3 files changed, 315 insertions(+), 472 deletions(-)
---
diff --git a/data/ui/interface.ui b/data/ui/interface.ui
index be5b251..ea251c0 100644
--- a/data/ui/interface.ui
+++ b/data/ui/interface.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkApplicationWindow" id="mainwin">
@@ -8,433 +8,243 @@
<property name="can_focus">False</property>
<property name="border_width">0</property>
<property name="icon_name">atomix</property>
- <property name="title" translatable="yes">Atomix</property>
+ <property name="show_menubar">False</property>
<child>
- <object class="GtkBox" id="win_content">
+ <object class="GtkBox" id="content_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
<child>
- <object class="GtkMenuBar" id="menubar">
+ <object class="GtkAlignment" id="game_alignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkMenuItem" id="game_menu">
+ <object class="GtkAspectFrame" id="game_aspectaspect">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">_File</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="menu1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkMenuItem" id="gameNew">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_New Game</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameNew</property>
- <accelerator key="n" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameEnd">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_End Game</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameEnd</property>
- </object>
- </child>
- <child>
- <object class="GtkSeparatorMenuItem" id="menuitem1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameSkip">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Skip Level</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameSkip</property>
- <accelerator key="s" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameReset">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Reset Level</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameReset</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameUndo">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Undo Move</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameUndo</property>
- <accelerator key="z" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gamePause">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Pause Game</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GamePause</property>
- <accelerator key="c" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameContinue">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Continue Game</property>
- <property name="use_underline">True</property>
- <property name="action_name">win.GameContinue</property>
- <accelerator key="c" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- <child>
- <object class="GtkSeparatorMenuItem" id="menuitem7">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="gameQuit">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Quit</property>
- <property name="use_underline">True</property>
- <property name="action_name">app.GameQuit</property>
- <accelerator key="q" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="help_menu">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Help</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="menu3">
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkFixed" id="game_fixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkMenuItem" id="gameAbout">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_About</property>
- <property name="action_name">app.GameAbout</property>
- <property name="use_underline">True</property>
- </object>
- </child>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkBox" id="content_hbox">
+ <object class="GtkBox" id="sidebar">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">12</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
<child>
- <object class="GtkFrame" id="game_frame">
+ <object class="GtkFrame" id="stats_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
- <property name="label_yalign">0</property>
- <property name="shadow_type">none</property>
+ <property name="shadow_type">in</property>
<child>
- <object class="GtkAlignment" id="game_alignment">
+ <object class="GtkAlignment" id="stats_alignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkFixed" id="game_fixed">
+ <object class="GtkGrid" id="stats_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
+ <property name="border_width">12</property>
+ <property name="row_spacing">4</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="level_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Level:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="molecule_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Molecule:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="formula_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Formula:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="score_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Score:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="time_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Time:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="level_value">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">empty</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="molecule_value">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">empty</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="formula_value">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">empty</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="score_value">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">empty</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</object>
</child>
</object>
</child>
- <child type="label_item">
- <placeholder/>
+ <child type="label">
+ <object class="GtkLabel" id="stats_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Statistics</property>
+ </object>
</child>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkBox" id="sidebar">
+ <object class="GtkFrame" id="preview_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
<child>
- <object class="GtkFrame" id="stats_frame">
+ <object class="GtkAlignment" id="preview_alignment">
+ <property name="width_request">200</property>
+ <property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">in</property>
<child>
- <object class="GtkAlignment" id="stats_alignment">
+ <object class="GtkFixed" id="preview_fixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkGrid" id="stats_grid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">12</property>
- <property name="column_spacing">6</property>
- <property name="row_spacing">4</property>
- <child>
- <object class="GtkLabel" id="level_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="label" translatable="yes">Level:</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="molecule_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="label" translatable="yes">Molecule:</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="formula_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="label" translatable="yes">Formula:</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="score_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="label" translatable="yes">Score:</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="time_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="label" translatable="yes">Time:</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="level_value">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes">empty</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="molecule_value">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">empty</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="formula_value">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">empty</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="score_value">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">empty</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">3</property>
- </packing>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child type="label">
- <object class="GtkLabel" id="stats_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Statistics</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
- <child>
- <object class="GtkFrame" id="preview_frame">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">none</property>
- <child>
- <object class="GtkAlignment" id="preview_alignment">
- <property name="width_request">200</property>
- <property name="height_request">50</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkFixed" id="preview_fixed">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- </object>
- </child>
- </object>
- </child>
- <child type="label_item">
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
+ <child type="label_item">
+ <placeholder/>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
+ <child type="titlebar">
+ <object class="GtkHeaderBar" id="headerbar">
+ <property name="name">headerbar</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="title">Atomix</property>
+ <property name="show_close_button">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
</object>
- <menu id="app-menu">
- <section>
- <item>
- <attribute name="label" translatable="yes">New Game</attribute>
- <attribute name="action">win.GameNew</attribute>
- <attribute name="accel"><Primary>n</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">End Game</attribute>
- <attribute name="action">win.GameEnd</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Skip Level</attribute>
- <attribute name="action">win.GameSkip</attribute>
- <attribute name="accel"><Primary>s</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Reset Level</attribute>
- <attribute name="action">win.GameReset</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Undo Move</attribute>
- <attribute name="action">win.GameUndo</attribute>
- <attribute name="accel"><Primary>z</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Pause Game</attribute>
- <attribute name="action">win.GamePause</attribute>
- <attribute name="accel"><Primary>c</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Continue Game</attribute>
- <attribute name="action">win.GameContinue</attribute>
- <attribute name="accel"><Primary>c</attribute>
- </item>
- </section>
- <section>
- <item>
- <attribute name="label" translatable="yes">About</attribute>
- <attribute name="action">app.GameAbout</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Quit</attribute>
- <attribute name="action">app.GameQuit</attribute>
- <attribute name="accel"><Primary>q</attribute>
- </item>
- </section>
- </menu>
</interface>
diff --git a/data/ui/menu.ui b/data/ui/menu.ui
new file mode 100644
index 0000000..973b31a
--- /dev/null
+++ b/data/ui/menu.ui
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">New Game</attribute>
+ <attribute name="action">win.GameNew</attribute>
+ <attribute name="accel"><Primary>n</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Pause/Continue Game</attribute>
+ <attribute name="action">win.GamePause</attribute>
+ <attribute name="accel"><Primary>p</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">End Game</attribute>
+ <attribute name="action">win.GameEnd</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Skip Level</attribute>
+ <attribute name="action">win.LevelSkip</attribute>
+ <attribute name="accel"><Primary>s</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Reset Level</attribute>
+ <attribute name="action">win.LevelReset</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Undo Move</attribute>
+ <attribute name="action">win.GameUndo</attribute>
+ <attribute name="accel"><Primary>z</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">About</attribute>
+ <attribute name="action">app.GameAbout</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Quit</attribute>
+ <attribute name="action">app.GameQuit</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
index e77299c..a041e2b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,13 +19,6 @@
#include "config.h"
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
#include "board-gtk.h"
#include "playfield.h"
#include "main.h"
@@ -89,12 +82,11 @@ static void verb_GameReset_cb (GSimpleAction *action, GVariant *variant, gpointe
static void verb_GamePause_cb (GSimpleAction *action, GVariant *variant, gpointer data)
{
- controller_handle_action (GAME_ACTION_PAUSE);
-}
-
-static void verb_GameContinue_cb (GSimpleAction *action, GVariant *variant, gpointer data)
-{
- controller_handle_action (GAME_ACTION_CONTINUE);
+ if (app->state != GAME_STATE_PAUSED) {
+ controller_handle_action (GAME_ACTION_PAUSE);
+ } else {
+ controller_handle_action (GAME_ACTION_CONTINUE);
+ }
}
static void verb_GameUndo_cb (GSimpleAction *action, GVariant *variant, gpointer data)
@@ -126,10 +118,10 @@ static void verb_HelpAbout_cb (GSimpleAction *action, GVariant *variant, gpointe
gtk_show_about_dialog(GTK_WINDOW(app->mainwin),
"program-name", _("Atomix"),
- "logo-icon-name", "atomix",
+ "logo-icon-name", "atomix",
"version", VERSION,
"comments", _("A puzzle game about atoms and molecules"),
- "website", "https://wiki.gnome.org/Apps/Atomix",
+ "website", "https://wiki.gnome.org/Apps/Atomix",
"authors", authors,
"artists", artists,
"translator_credits", _("translator-credits"),
@@ -155,92 +147,87 @@ static void controller_handle_action (GameAction action)
switch (app->state)
{
case GAME_STATE_NOT_RUNNING:
- if (action == GAME_ACTION_NEW)
- {
- if (set_next_level ())
- {
- app->level_no = 1;
- app->score = 0;
- setup_level ();
- app->state = GAME_STATE_RUNNING_UNMOVED;
- }
- }
+ if (action == GAME_ACTION_NEW && set_next_level ())
+ {
+ app->level_no = 1;
+ app->score = 0;
+ setup_level ();
+ app->state = GAME_STATE_RUNNING_UNMOVED;
+ }
break;
case GAME_STATE_RUNNING_UNMOVED:
case GAME_STATE_RUNNING:
switch (action)
- {
- case GAME_ACTION_END:
- level_cleanup_view ();
- set_game_not_running_state ();
- break;
-
- case GAME_ACTION_PAUSE:
- clock_stop (CLOCK (app->clock));
- board_gtk_hide ();
- app->state = GAME_STATE_PAUSED;
- break;
-
- case GAME_ACTION_SKIP:
- level_cleanup_view ();
-
- if (set_next_level ())
- setup_level ();
-
- else
- set_game_not_running_state ();
-
- break;
-
- case GAME_ACTION_FINISHED:
- calculate_score ();
- if (level_manager_is_last_level (app->lm, app->level))
{
- view_congratulations ();
- level_cleanup_view ();
- set_game_not_running_state ();
+ case GAME_ACTION_END:
+ level_cleanup_view ();
+ set_game_not_running_state ();
+ break;
+
+ case GAME_ACTION_PAUSE:
+ clock_stop (CLOCK (app->clock));
+ board_gtk_hide ();
+ app->state = GAME_STATE_PAUSED;
+ break;
+
+ case GAME_ACTION_SKIP:
+ level_cleanup_view ();
+
+ if (set_next_level ())
+ setup_level ();
+ else
+ set_game_not_running_state ();
+
+ break;
+
+ case GAME_ACTION_FINISHED:
+ calculate_score ();
+ if (level_manager_is_last_level (app->lm, app->level))
+ {
+ view_congratulations ();
+ level_cleanup_view ();
+ set_game_not_running_state ();
+ }
+ else
+ {
+ level_cleanup_view ();
+ set_next_level ();
+ setup_level ();
+ }
+ break;
+
+ case GAME_ACTION_RESTART:
+ g_assert (app->state != GAME_STATE_RUNNING_UNMOVED);
+
+ level_cleanup_view ();
+ setup_level ();
+ break;
+
+ case GAME_ACTION_UNDO:
+ g_assert (app->state != GAME_STATE_RUNNING_UNMOVED);
+
+ board_gtk_undo_move ();
+ break;
+
+ case GAME_ACTION_NEW:
+ case GAME_ACTION_CONTINUE:
+ default:
+ break;
}
- else
- {
- level_cleanup_view ();
- set_next_level ();
- setup_level ();
- }
- break;
-
- case GAME_ACTION_RESTART:
- g_assert (app->state != GAME_STATE_RUNNING_UNMOVED);
-
- level_cleanup_view ();
- setup_level ();
- break;
-
- case GAME_ACTION_UNDO:
- g_assert (app->state != GAME_STATE_RUNNING_UNMOVED);
-
- board_gtk_undo_move ();
- break;
-
- case GAME_ACTION_NEW:
- case GAME_ACTION_CONTINUE:
- default:
- break;
- }
break;
case GAME_STATE_PAUSED:
if (action == GAME_ACTION_CONTINUE)
- {
- clock_resume (CLOCK(app->clock));
- board_gtk_show ();
- app->state = (undo_exists())?GAME_STATE_RUNNING:GAME_STATE_RUNNING_UNMOVED;
- }
+ {
+ clock_resume (CLOCK(app->clock));
+ board_gtk_show ();
+ app->state = (undo_exists())?GAME_STATE_RUNNING:GAME_STATE_RUNNING_UNMOVED;
+ }
break;
-
default:
g_assert_not_reached ();
- }
+ }
update_menu_item_state ();
update_statistics ();
@@ -342,9 +329,7 @@ static void atomix_exit (void)
g_return_if_fail (app != NULL);
if (app->state != GAME_STATE_NOT_RUNNING)
- {
- set_game_not_running_state ();
- }
+ set_game_not_running_state ();
board_gtk_destroy ();
@@ -369,9 +354,7 @@ static gboolean on_key_press_event (GObject *widget, GdkEventKey *event,
gpointer user_data)
{
if ((app->state == GAME_STATE_RUNNING) || (app->state == GAME_STATE_RUNNING_UNMOVED))
- {
- return board_gtk_handle_key_event (NULL, event, NULL);
- }
+ return board_gtk_handle_key_event (NULL, event, NULL);
return FALSE;
}
@@ -505,22 +488,20 @@ static const GActionEntry win_entries[] =
{
{ "GameNew", verb_GameNew_cb, NULL, NULL, NULL},
{ "GameEnd", verb_GameEnd_cb, NULL, NULL, NULL},
- { "GameSkip", verb_GameSkip_cb, NULL, NULL, NULL},
- { "GameReset", verb_GameReset_cb, NULL, NULL, NULL},
+ { "LevelSkip", verb_GameSkip_cb, NULL, NULL, NULL},
+ { "LevelReset", verb_GameReset_cb, NULL, NULL, NULL},
{ "GameUndo", verb_GameUndo_cb, NULL, NULL, NULL},
{ "GamePause", verb_GamePause_cb, NULL, NULL, NULL},
- { "GameContinue", verb_GameContinue_cb, NULL, NULL, NULL},
};
static const CmdEnable not_running[] =
{
{ "GameNew", TRUE },
{ "GameEnd", FALSE },
- { "GameSkip", FALSE },
- { "GameReset", FALSE },
+ { "LevelSkip", FALSE },
+ { "LevelReset", FALSE },
{ "GameUndo", FALSE },
{ "GamePause", FALSE },
- { "GameContinue", FALSE },
{ NULL, FALSE }
};
@@ -528,11 +509,10 @@ static const CmdEnable running_unmoved[] =
{
{ "GameNew", FALSE },
{ "GameEnd", TRUE },
- { "GameSkip", TRUE },
- { "GameReset", FALSE },
+ { "LevelSkip", TRUE },
+ { "LevelReset", FALSE },
{ "GameUndo", FALSE },
{ "GamePause", TRUE },
- { "GameContinue", FALSE },
{ NULL, FALSE }
};
@@ -540,11 +520,10 @@ static const CmdEnable running[] =
{
{ "GameNew", FALSE },
{ "GameEnd", TRUE },
- { "GameSkip", TRUE },
- { "GameReset", TRUE },
+ { "LevelSkip", TRUE },
+ { "LevelReset", TRUE },
{ "GameUndo", TRUE },
{ "GamePause", TRUE },
- { "GameContinue", FALSE },
{ NULL, FALSE }
};
@@ -552,11 +531,10 @@ static const CmdEnable paused[] =
{
{ "GameNew", FALSE },
{ "GameEnd", FALSE },
- { "GameSkip", FALSE },
- { "GameReset", FALSE },
+ { "LevelSkip", FALSE },
+ { "LevelReset", FALSE },
{ "GameUndo", FALSE },
- { "GamePause", FALSE },
- { "GameContinue", TRUE },
+ { "GamePause", TRUE },
{ NULL, FALSE }
};
@@ -589,6 +567,7 @@ static AtomixApp *create_gui (GApplication *app_instance)
GtkBuilder *builder;
GtkWidget *stats_grid;
GtkWidget *time_label;
+ GtkWidget *headerbar;
app = g_new0 (AtomixApp, 1);
app->level = NULL;
@@ -600,6 +579,10 @@ static AtomixApp *create_gui (GApplication *app_instance)
gtk_builder_add_from_file (builder, ui_path, NULL);
g_free (ui_path);
+ ui_path = g_build_filename (PKGDATADIR, "ui", "menu.ui", NULL);
+ gtk_builder_add_from_file (builder, ui_path, NULL);
+ g_free (ui_path);
+
app->mainwin = GTK_WIDGET (gtk_builder_get_object (builder, "mainwin"));
g_signal_connect (G_OBJECT (app->mainwin), "delete_event",
@@ -626,13 +609,13 @@ static AtomixApp *create_gui (GApplication *app_instance)
gtk_widget_show_all (GTK_WIDGET (app->mainwin));
+ headerbar = GTK_WIDGET (gtk_builder_get_object(builder, "headerbar"));
+ gtk_application_add_window (GTK_APPLICATION (app->app_instance), GTK_WINDOW (app->mainwin));
+ gtk_window_set_titlebar (GTK_WINDOW (app->mainwin), headerbar);
+ GMenu * menu = G_MENU (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (app->app_instance), G_MENU_MODEL (menu));
+
- if (gtk_application_prefers_app_menu (GTK_APPLICATION (app_instance))) {
- GMenu * menu = G_MENU (gtk_builder_get_object (builder, "app-menu"));
- gtk_application_set_app_menu (GTK_APPLICATION (app->app_instance), G_MENU_MODEL (menu));
-// GtkWidget *menubar = GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
-// gtk_widget_set_visible (menubar, FALSE);
- }
g_object_unref (builder);
@@ -655,7 +638,6 @@ app_activate (GApplication *app_instance, gpointer user_data)
//gtk_window_set_resizable (GTK_WINDOW (app->mainwin), FALSE);
gtk_widget_show (app->mainwin);
- gtk_application_add_window (GTK_APPLICATION (app_instance), GTK_WINDOW (app->mainwin));
} else {
gtk_window_present (GTK_WINDOW (app->mainwin));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]