[gbrainy/gbrainy-17x] Enhacements to Web client
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy/gbrainy-17x] Enhacements to Web client
- Date: Sat, 5 Feb 2011 23:09:12 +0000 (UTC)
commit 01e5d41c834bbf2518b6eed990cd3eae74544d4c
Author: Jordi Mas <jmas softcatala org>
Date: Sun Feb 6 00:10:53 2011 +0100
Enhacements to Web client
data/app-graphics/gbrainy.ico | Bin 0 -> 91750 bytes
src/Clients/WebForms/Default.aspx | 34 ++---
src/Clients/WebForms/Default.aspx.cs | 31 +---
src/Clients/WebForms/Default.aspx.designer.cs | 10 --
src/Clients/WebForms/Game.aspx | 9 +-
src/Clients/WebForms/Game.aspx.cs | 141 +++++++++++++-------
src/Clients/WebForms/Game.aspx.designer.cs | 8 +-
src/Clients/WebForms/LanguageSupport.cs | 16 ++-
src/Clients/WebForms/MasterPage.master | 4 +-
src/Clients/WebForms/MasterPage.master.designer.cs | 2 +
src/Clients/WebForms/TranslationsWeb.cs | 3 +
src/Clients/WebForms/WebSession.cs | 2 +
src/Clients/WebForms/package.sh | 19 ++--
13 files changed, 157 insertions(+), 122 deletions(-)
---
diff --git a/data/app-graphics/gbrainy.ico b/data/app-graphics/gbrainy.ico
new file mode 100644
index 0000000..5af5223
Binary files /dev/null and b/data/app-graphics/gbrainy.ico differ
diff --git a/src/Clients/WebForms/Default.aspx b/src/Clients/WebForms/Default.aspx
index 016d39d..7e3a43b 100644
--- a/src/Clients/WebForms/Default.aspx
+++ b/src/Clients/WebForms/Default.aspx
@@ -7,7 +7,8 @@
<br/>
<br/>
- <asp:Label id="intro_label" runat="server"/>
+ <br/>
+ gbrainy is a brain teaser game and trainer to have fun and to keep your brain trained. gbrainy includes the following games:
<br/>
<br/>
@@ -17,7 +18,7 @@
</span>
<span class="WelcomeRight">
- <asp:Label id="logic_label" runat="server"/>
+ Logic puzzles. Challenge your reasoning and thinking skills.
</span>
<br/>
<br/>
@@ -28,18 +29,7 @@
</span>
<span class="WelcomeRight">
- <asp:Label id="calculation_label" runat="server"/>
- </span>
- <br/>
- <br/>
-
- <!-- Memory -->
- <span class="WelcomeLeft">
- <img src = "images/memory-games-32.png"/>
- </span>
-
- <span class="WelcomeRight">
- <asp:Label id="memory_label" runat="server"/>
+ Mental calculation. Arithmetical operations that test your mental calculation abilities.
</span>
<br/>
<br/>
@@ -50,15 +40,19 @@
</span>
<span class="WelcomeRight">
- <asp:Label id="verbal_label" runat="server"/>
+ Verbal analogies. Challenge your verbal aptitude.
</span>
<br/>
<br/>
- <asp:Button id="start_button" Text="Start game!" OnClick="OnStartGame" runat="server"/>
-
- <asp:DropDownList id = "languages_drop" AutoPostBack="True" ViewStateMode="Enabled"
- onselectedindexchanged="OnSelectedIndexChanged" runat="server">
+ <asp:Button id="start_button" Text="Start a new game" OnClick="OnStartGame" runat="server"/>
+ in
+ <asp:DropDownList id = "languages_drop" ViewStateMode="Enabled" runat="server">
</asp:DropDownList>
-
+ language
+ <p>
+ <small>
+ This web site is based on in the open source project called <a href="http://live.gnome.org/gbrainy">gbrainy</a>. Contact e-mail address: jmas at softcatala dot org
+ </small>
+ </p>
</asp:content>
diff --git a/src/Clients/WebForms/Default.aspx.cs b/src/Clients/WebForms/Default.aspx.cs
index 980ee32..722440f 100644
--- a/src/Clients/WebForms/Default.aspx.cs
+++ b/src/Clients/WebForms/Default.aspx.cs
@@ -38,12 +38,6 @@ namespace gbrainy.Clients.WebForms
web_session = Global.Sessions [Session.SessionID];
- intro_label.Text = "gbrainy is a brain teaser game and trainer to have fun and to keep your brain trained. It includes:";
- logic_label.Text = "Logic puzzles. Challenge your reasoning and thinking skills.";
- calculation_label.Text = "Mental calculation. Arithmetical operations that test your mental calculation abilities.";
- memory_label.Text = "Memory trainers. To prove your short term memory.";
- verbal_label.Text = "Verbal analogies. Challenge your verbal aptitude.";
-
for (int i = 0; i <LanguageSupport.Languages.Length; i++)
{
languages_drop.Items.Add (new ListItem (LanguageSupport.Languages[i].Name,
@@ -59,28 +53,19 @@ namespace gbrainy.Clients.WebForms
Int32.Parse (languages_drop.SelectedValue);
}
- protected void OnSelectedIndexChanged (object sender, EventArgs e)
- {
- if (Response.Cookies[CookieName].Value == languages_drop.SelectedValue)
- return;
-
- Response.Cookies[CookieName].Value = languages_drop.SelectedValue;
- Response.Cookies[CookieName].Expires = DateTime.Now.AddYears (1);
-
- Logger.Debug ("MasterPage.OnSelectedIndexChanged. Set lang cookie to: {0}",
- languages_drop.SelectedValue);
-
- Global.Sessions [Session.SessionID].LanguageIndex =
- Int32.Parse (languages_drop.SelectedValue);
-
- ///Response.Redirect ("Default.aspx");
-
- }
protected void OnStartGame (Object sender, EventArgs e)
{
web_session = Global.Sessions [Session.SessionID];
web_session.GameState = null;
+
+ // Collect language cookie
+ Global.Sessions [Session.SessionID].LanguageIndex =
+ Int32.Parse (languages_drop.SelectedValue);
+
+ Response.Cookies[CookieName].Value = languages_drop.SelectedValue;
+ Response.Cookies[CookieName].Expires = DateTime.Now.AddYears (1);
+
Logger.Debug ("Default.OnStartGame. Start game button click");
Response.Redirect ("Game.aspx");
}
diff --git a/src/Clients/WebForms/Default.aspx.designer.cs b/src/Clients/WebForms/Default.aspx.designer.cs
index 501e3ce..fbc0555 100644
--- a/src/Clients/WebForms/Default.aspx.designer.cs
+++ b/src/Clients/WebForms/Default.aspx.designer.cs
@@ -15,16 +15,6 @@ namespace gbrainy.Clients.WebForms {
protected System.Web.UI.WebControls.Content main_content;
- protected System.Web.UI.WebControls.Label intro_label;
-
- protected System.Web.UI.WebControls.Label logic_label;
-
- protected System.Web.UI.WebControls.Label calculation_label;
-
- protected System.Web.UI.WebControls.Label memory_label;
-
- protected System.Web.UI.WebControls.Label verbal_label;
-
protected System.Web.UI.WebControls.Button start_button;
protected System.Web.UI.WebControls.DropDownList languages_drop;
diff --git a/src/Clients/WebForms/Game.aspx b/src/Clients/WebForms/Game.aspx
index 5ebb466..b990709 100644
--- a/src/Clients/WebForms/Game.aspx
+++ b/src/Clients/WebForms/Game.aspx
@@ -35,7 +35,7 @@
-->
<tr>
<td align = "center">
- <asp:ImageButton ImageUrl = "images/endgame-32.png" OnClick="OnClickEndGame" runat="server"></asp:ImageButton>
+ <asp:ImageButton ImageUrl = "images/endgame-32.png" id = "endgames_button" OnClick="OnClickEndGame" runat="server"></asp:ImageButton>
<div>
<asp:Label id="endgames_label" runat="server"/>
</div>
@@ -54,17 +54,16 @@
</tr>
<tr>
<td>
- <asp:Image id="image" runat="server" />
+ <asp:Image id="game_image" runat="server" />
</td>
</tr>
<tr>
<td>
- <asp:TextBox id = "answer_textbox" AutoCompleteType="None" EnableViewState="true" runat="server"></asp:TextBox>
+ <asp:TextBox id = "answer_textbox" AutoCompleteType="Disabled" EnableViewState="true" runat="server"></asp:TextBox>
<asp:Button id = "answer_button" Text = "Answer" OnClick ="OnClickAnswer" runat="server"></asp:Button>
+ <asp:Button id = "nextgame_link" OnClick ="OnClickNextGame" runat="server" />
<asp:Label id="result_label" runat="server"></asp:Label>
<asp:Label id="rationale_label" runat="server"></asp:Label>
-
- <asp:LinkButton id="nextgame_link" OnClick ="OnClickNextGame" runat="server" />
</td>
</tr>
diff --git a/src/Clients/WebForms/Game.aspx.cs b/src/Clients/WebForms/Game.aspx.cs
index d54c1eb..3fe4ba8 100644
--- a/src/Clients/WebForms/Game.aspx.cs
+++ b/src/Clients/WebForms/Game.aspx.cs
@@ -21,6 +21,8 @@ using System;
using System.IO;
using System.Web;
using System.Web.UI;
+using System.Web.UI.HtmlControls;
+
using gbrainy.Core.Main;
using gbrainy.Core.Toolkit;
@@ -30,10 +32,14 @@ namespace gbrainy.Clients.WebForms
{
public partial class Game : System.Web.UI.Page
{
+ static GameManager manager;
+ const int image_width = 400;
+ const int image_height = 400;
+
gbrainy.Core.Main.Game _game;
gbrainy.Core.Main.GameSession session;
WebSession web_session;
- static GameManager manager;
+
static public GameManager CreateManager ()
{
@@ -48,93 +54,126 @@ namespace gbrainy.Clients.WebForms
return manager;
}
+ public WebSession WebSession {
+ get {
+ if (web_session == null)
+ web_session = Global.Sessions [Session.SessionID];
+
+ return web_session;
+ }
+ }
+
int GetLanguageIndexFromSessionHandler ()
{
- web_session = Global.Sessions [Session.SessionID];
- return web_session.LanguageIndex;
+ return WebSession.LanguageIndex;
+ }
+
+ // Page Life-Cycle Events
+ //
+ // - Page_Load
+ // - Control events
+ // - Page_LoadComplete
+ //
+ private void Page_LoadComplete (Object sender, EventArgs e)
+ {
+ if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
+ return;
+
+ if (WebSession.NextGame == true)
+ {
+ _game = GetNextGame ();
+ UpdateGame ();
+ }
+ WebSession.NextGame = false;
}
private void Page_Load (Object sender, EventArgs e)
{
- web_session = Global.Sessions [Session.SessionID];
+ if (IsPostBack == false)
+ InitPage ();
Logger.Debug ("Game.Page_Load. Page load starts. Session ID {0}, IsPostBack {1}", Session.SessionID,
IsPostBack);
- TranslationsWeb service = (TranslationsWeb) ServiceLocator.Instance.GetService <ITranslations> ();
-
- service.GetLanguageIndexFromSession = GetLanguageIndexFromSessionHandler;
+ HtmlForm form = (HtmlForm) Master.FindControl("main_form");
+ form.DefaultButton = answer_button.UniqueID;
- if (web_session.GameState == null)
+ if (WebSession.GameState == null)
{
Logger.Debug ("Game.Page_Load creating new session");
session = new gbrainy.Core.Main.GameSession ();
session.GameManager = CreateManager ();
session.New ();
- web_session.GameState = session;
+ WebSession.GameState = session;
+
+ _game = GetNextGame ();
+ UpdateGame ();
// If the first time that loads this does not have a session
// send the user to the home page
//Logger.Debug ("New Session, redirecting to Default.aspx");
//Response.Redirect ("Default.aspx");
- } else if (web_session.GameState != null && web_session.GameState.Status == GameSession.SessionStatus.Finished)
+ } else if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
{
- image.ImageUrl = Game.CreateImage (web_session);
- }
+ // Finished game
+ game_image.ImageUrl = Game.CreateImage (WebSession);
+ answer_button.Enabled = false;
+ answer_textbox.Text = string.Empty;
+ answer_textbox.Enabled = false;
+ nextgame_link.Enabled = false;
+ endgames_button.Enabled = false;
+ UpdateGame ();
+ }
else {
- session = web_session.GameState;
+ session = WebSession.GameState;
+ UpdateGame ();
}
if (IsPostBack == true) {
-
- if (web_session.GameState.Status != GameSession.SessionStatus.Finished)
- UpdateGame ();
-
Logger.Debug ("Game.Page_Load. Ignoring postback");
return;
}
- string answer = answer_textbox.Text;
+ Logger.Debug ("Game.Page_Load. Page load completed");
+ }
+
+ void InitPage ()
+ {
+ TranslationsWeb service = (TranslationsWeb) ServiceLocator.Instance.GetService <ITranslations> ();
+ service.GetLanguageIndexFromSession = GetLanguageIndexFromSessionHandler;
+
+ game_image.Width = image_width;
+ game_image.Height = image_height;
+
+ nextgame_link.Text = "Next Game";
- Logger.Debug ("Game.Page_Load. Got answer: {0}", answer);
-
- if (web_session.GameState.Status != GameSession.SessionStatus.Finished)
- {
- _game = GetNextGame ();
- UpdateGame ();
- }
-
// Toolbar
allgames_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("All");
endgames_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Finish");
-
- nextgame_link.Text = "Next Game";
- Logger.Debug ("Game.Page_Load. Page load completed");
}
-
#if _IMAGEMAP_
-
+
string ProcessWidget (Widget widget)
{
string str;
-
+
str = String.Format ("<area shape=\"rect\" coords=\"{0},{1},{2},{3}\" href=http://en.wikipedia.org/ />",
widget.X, widget.Y, widget.Width, widget.Height);
return str;
}
-
+
public string ImageMap
- {
+ {
get {
string str;
-
+
if (_game == null)
return "Nothing";
-
+
str = String.Format ("<img src={0} usemap=\"#mapname\" />",
image.ImageUrl);
-
+
foreach (Widget widget in _game.Widgets)
{
if (widget is Container)
@@ -159,7 +198,7 @@ namespace gbrainy.Clients.WebForms
status.Text = session.StatusText;
question.Text = _game.Question;
- image.ImageUrl = CreateImage (web_session);
+ game_image.ImageUrl = CreateImage (WebSession);
}
public gbrainy.Core.Main.Game GetNextGame ()
@@ -203,6 +242,9 @@ namespace gbrainy.Clients.WebForms
Logger.Error ("Game.CreateImage. Error writting {0}", file);
else
Logger.Debug ("Game.CreateImage. Wrote image {0}", file);
+
+ // Prevent IE from caching the image
+ file += "?" + DateTime.Now.Ticks;
}
finally
@@ -224,6 +266,8 @@ namespace gbrainy.Clients.WebForms
// TODO: This should be done at GameSession.Level
session.ScoreGame (String.Empty);
// TODO: Use Ajax for dynamic loading
+
+ WebSession.NextGame = true;
Response.Redirect ("Game.aspx");
}
@@ -235,32 +279,33 @@ namespace gbrainy.Clients.WebForms
if (String.IsNullOrEmpty (answer) == false)
{
- if (session.ScoreGame (answer) == true) {
+ if (web_session.GameState.ScoreGame (answer) == true) {
result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Congratulations.");
result_label.CssClass = "CorrectAnswer";
}
else {
- result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Incorrect. ");
+ result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Incorrect answer.");
result_label.CssClass = null;
}
- rationale_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString (session.CurrentGame.Answer);
- } else
-
- answer_button.Enabled = false;
+ rationale_label.Text = WebSession.GameState.CurrentGame.Answer;
+ answer_button.Enabled = false;
+ }
}
protected void OnClickEndGame (Object sender, EventArgs e)
{
Logger.Debug ("Game.OnClickEndGame");
- session.End ();
-
+
+ if (session != null)
+ session.End ();
+
Response.Redirect ("Game.aspx");
}
-
+
protected void OnStartAllGames (Object sender, EventArgs e)
{
- web_session.GameState = null;
+ WebSession.GameState = null;
Response.Redirect ("Game.aspx");
}
}
diff --git a/src/Clients/WebForms/Game.aspx.designer.cs b/src/Clients/WebForms/Game.aspx.designer.cs
index b8caeba..9122695 100644
--- a/src/Clients/WebForms/Game.aspx.designer.cs
+++ b/src/Clients/WebForms/Game.aspx.designer.cs
@@ -17,22 +17,24 @@ namespace gbrainy.Clients.WebForms {
protected System.Web.UI.WebControls.Label allgames_label;
+ protected System.Web.UI.WebControls.ImageButton endgames_button;
+
protected System.Web.UI.WebControls.Label endgames_label;
protected System.Web.UI.WebControls.Label question;
- protected System.Web.UI.WebControls.Image image;
+ protected System.Web.UI.WebControls.Image game_image;
protected System.Web.UI.WebControls.TextBox answer_textbox;
protected System.Web.UI.WebControls.Button answer_button;
+ protected System.Web.UI.WebControls.Button nextgame_link;
+
protected System.Web.UI.WebControls.Label result_label;
protected System.Web.UI.WebControls.Label rationale_label;
- protected System.Web.UI.WebControls.LinkButton nextgame_link;
-
protected System.Web.UI.WebControls.Label status;
}
}
diff --git a/src/Clients/WebForms/LanguageSupport.cs b/src/Clients/WebForms/LanguageSupport.cs
index b5e3965..4a9f626 100644
--- a/src/Clients/WebForms/LanguageSupport.cs
+++ b/src/Clients/WebForms/LanguageSupport.cs
@@ -39,9 +39,23 @@ namespace gbrainy.Clients.WebForms
static Language [] languages =
{
new Language ("English", "en_US.utf8"),
+ new Language ("Afrikaans", "af_ZA.utf8"),
new Language ("Catalan", "ca_ES.utf8"),
+ new Language ("Czech", "cs_CZ.utf8"),
+ new Language ("Danish", "da_DK.utf8"),
+ new Language ("German", "de_DE.utf8"),
+ new Language ("Basque", "eu_ES.utf8"),
new Language ("Spanish", "es_ES.utf8"),
- new Language ("German", "de_DE.utf8")
+ new Language ("French", "fr_FR.utf8"),
+ new Language ("Galician", "gl_ES.utf8"),
+ new Language ("Hungarian", "hu_HU.utf8"),
+ new Language ("Dutch", "nl_NL.utf8"),
+ new Language ("Portuguese", "pt_PT.utf8"),
+ new Language ("Romanian", "ro_RO.utf8"),
+ new Language ("Brazilian Portuguese", "pt_BR.utf8"),
+ new Language ("Slovenian", "sl_SI.utf8"),
+ new Language ("Swedish", "sv_SE.utf8"),
+ new Language ("Serbian", "sr_RS.utf8")
};
static public Language [] Languages
diff --git a/src/Clients/WebForms/MasterPage.master b/src/Clients/WebForms/MasterPage.master
index dfefee7..a2bf12c 100644
--- a/src/Clients/WebForms/MasterPage.master
+++ b/src/Clients/WebForms/MasterPage.master
@@ -4,12 +4,12 @@
<head>
<title>Welcome to gbrainy.com main page</title>
<link href="styles.css" rel="stylesheet" type="text/css"/>
+ <link rel="shortcut icon" href="images/gbrainy.ico" />
</head>
<body>
-<form runat="server">
+<form runat="server" id = "main_form">
<div class="Header">
<asp:HyperLink class="HeaderText" text ="Home" NavigateUrl ="Default.aspx" runat="server"/>
- <span class="HeaderText">Play</span>
<asp:HyperLink class="HeaderText" text ="Download" NavigateUrl ="Download.aspx" runat="server"/>
<span class="HeaderText">Help</span>
<span class="HeaderText">About</span>
diff --git a/src/Clients/WebForms/MasterPage.master.designer.cs b/src/Clients/WebForms/MasterPage.master.designer.cs
index 493eb9c..feef474 100644
--- a/src/Clients/WebForms/MasterPage.master.designer.cs
+++ b/src/Clients/WebForms/MasterPage.master.designer.cs
@@ -13,6 +13,8 @@ namespace gbrainy.Clients.WebForms {
public partial class MasterPage {
+ protected System.Web.UI.HtmlControls.HtmlForm main_form;
+
protected System.Web.UI.WebControls.ContentPlaceHolder main_placeholder;
}
}
diff --git a/src/Clients/WebForms/TranslationsWeb.cs b/src/Clients/WebForms/TranslationsWeb.cs
index 33df792..007cd9e 100644
--- a/src/Clients/WebForms/TranslationsWeb.cs
+++ b/src/Clients/WebForms/TranslationsWeb.cs
@@ -19,6 +19,7 @@
using System;
using Mono.Unix;
+using System.IO;
using gbrainy.Core.Services;
@@ -33,6 +34,8 @@ namespace gbrainy.Clients.WebForms
public void Init (string package, string localedir)
{
+ string s = Directory.GetCurrentDirectory ();
+
Catalog.Init (package, localedir);
}
diff --git a/src/Clients/WebForms/WebSession.cs b/src/Clients/WebForms/WebSession.cs
index 188a023..6722874 100644
--- a/src/Clients/WebForms/WebSession.cs
+++ b/src/Clients/WebForms/WebSession.cs
@@ -6,6 +6,7 @@ namespace gbrainy.Clients.WebForms
{
public class WebSession
{
+ public bool NextGame;
public HttpSessionState Session { get; set; }
public DateTime Started { get; set; }
public gbrainy.Core.Main.GameSession GameState { get; set; }
@@ -15,6 +16,7 @@ namespace gbrainy.Clients.WebForms
{
Session = session;
Started = DateTime.Now;
+ NextGame = false;
}
}
}
diff --git a/src/Clients/WebForms/package.sh b/src/Clients/WebForms/package.sh
index a390a81..25639ca 100755
--- a/src/Clients/WebForms/package.sh
+++ b/src/Clients/WebForms/package.sh
@@ -8,7 +8,6 @@ cd package
mkdir bin
mkdir tmp
-mkdir po
mkdir data
mkdir images
mkdir locale
@@ -26,17 +25,17 @@ cp ../../../../data/game-graphics/* images
cp ../../../../data/app-graphics/* images
cp ../../../../data/themes/* themes
-mkdir locale/ca
-mkdir locale/ca/LC_MESSAGES
-cp ../../../../po/ca.gmo locale/ca/LC_MESSAGES/gbrainy.mo
+LOCALES=(af ca cs da de eu es fr gl hu nl pt ro pt_BR sl sr sv)
-mkdir locale/es
-mkdir locale/es/LC_MESSAGES
-cp ../../../../po/es.gmo locale/es/LC_MESSAGES/gbrainy.mo
+for i in "${LOCALES[ ]}"
+do
+ :
+ mkdir locale/$i
+ mkdir locale/$i/LC_MESSAGES
+ cp ../../../../po/$i.gmo locale/$i/LC_MESSAGES/gbrainy.mo
+ echo $i
+done
-mkdir locale/de
-mkdir locale/de/LC_MESSAGES
-cp ../../../../po/de.gmo locale/de/LC_MESSAGES/gbrainy.mo
tar -cvf gbrainy_web.tar *
cp gbrainy_web.tar ../
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]