|
From: <che...@us...> - 2007-05-26 07:14:29
|
Revision: 452
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=452&view=rev
Author: chef_koch
Date: 2007-05-26 00:14:27 -0700 (Sat, 26 May 2007)
Log Message:
-----------
added option to enable/disable sound effects
fixed some navi issues when buttons are disabled
Modified Paths:
--------------
trunk/plugins/My Connect4/Skin/Blue Two/MyConnect4.xml
trunk/plugins/My Connect4/Skin/SimpleMP/MyConnect4.xml
trunk/plugins/My Connect4/Source/MyConnect4/MyConnect4.cs
trunk/plugins/My Connect4/language/MyConnect4/strings_de.xml
trunk/plugins/My Connect4/language/MyConnect4/strings_en.xml
Modified: trunk/plugins/My Connect4/Skin/Blue Two/MyConnect4.xml
===================================================================
--- trunk/plugins/My Connect4/Skin/Blue Two/MyConnect4.xml 2007-05-26 07:11:42 UTC (rev 451)
+++ trunk/plugins/My Connect4/Skin/Blue Two/MyConnect4.xml 2007-05-26 07:14:27 UTC (rev 452)
@@ -9,7 +9,7 @@
<control>
<description>BackGround</description>
<type>image</type>
- <id>10</id>
+ <id>1</id>
<posX>0</posX>
<posY>0</posY>
<width>720</width>
@@ -19,7 +19,7 @@
<control>
<description>header label</description>
<type>label</type>
- <id>11</id>
+ <id>1</id>
<posX>250</posX>
<posY>70</posY>
<label>#header_label</label>
@@ -36,23 +36,22 @@
<animation effect="fade" time="500">WindowClose</animation>
<animation effect="slide" time="250" start="-300,0">WindowOpen</animation>
<animation effect="slide" time="500" end="0,-300">WindowClose</animation>
+ <posX>60</posX>
+ <posY>97</posY>
+ <layout>StackLayout</layout>
<control>
<description>Start</description>
<type>button</type>
<id>2</id>
- <posX>60</posX>
- <posY>97</posY>
<onleft>2</onleft>
<onright>301</onright>
- <onup>7</onup>
+ <onup>6</onup>
<ondown>3</ondown>
</control>
<control>
<description>Mode</description>
<type>button</type>
<id>3</id>
- <posX>60</posX>
- <posY>131</posY>
<onleft>3</onleft>
<onright>301</onright>
<onup>2</onup>
@@ -62,44 +61,47 @@
<description>Level</description>
<type>button</type>
<id>4</id>
- <posX>60</posX>
- <posY>165</posY>
<onleft>4</onleft>
<onright>301</onright>
<onup>3</onup>
- <ondown>7</ondown>
+ <ondown>5</ondown>
</control>
<control>
+ <description>Sounds</description>
+ <type>togglebutton</type>
+ <id>5</id>
+ <onleft>5</onleft>
+ <onright>301</onright>
+ <onup>4</onup>
+ <ondown>6</ondown>
+ </control>
+ <control>
<description>Round</description>
- <type>label</type>
- <id>5</id>
- <posX>70</posX>
- <posY>205</posY>
+ <type>button</type>
+ <id>1</id>
<label>#Round</label>
<font>font12</font>
- <align>Left</align>
- <textcolor>White</textcolor>
+ <enabled>false</enabled>
+ <textureFocus>-</textureFocus>
+ <textureNoFocus>-</textureNoFocus>
</control>
<control>
<description>Player: / GameOver</description>
- <type>label</type>
- <id>6</id>
- <posX>70</posX>
- <posY>240</posY>
+ <type>button</type>
+ <id>1</id>
<label>#Player</label>
<font>font12</font>
- <align>Left</align>
- <textcolor>White</textcolor>
+ <enabled>false</enabled>
+ <textureFocus>-</textureFocus>
+ <textureNoFocus>-</textureNoFocus>
</control>
<control>
<description>What is this?</description>
<type>button</type>
- <id>7</id>
- <posX>60</posX>
- <posY>270</posY>
- <onleft>7</onleft>
+ <id>6</id>
+ <onleft>6</onleft>
<onright>301</onright>
- <onup>4</onup>
+ <onup>5</onup>
<ondown>2</ondown>
</control>
</control>
Modified: trunk/plugins/My Connect4/Skin/SimpleMP/MyConnect4.xml
===================================================================
--- trunk/plugins/My Connect4/Skin/SimpleMP/MyConnect4.xml 2007-05-26 07:11:42 UTC (rev 451)
+++ trunk/plugins/My Connect4/Skin/SimpleMP/MyConnect4.xml 2007-05-26 07:14:27 UTC (rev 452)
@@ -47,27 +47,24 @@
<description>group element</description>
<animation effect="fade" time="150">WindowOpen</animation>
<animation effect="fade" time="150">WindowClose</animation>
+ <posX>60</posX>
+ <posY>97</posY>
+ <layout>StackLayout</layout>
<control>
<description>Start</description>
<type>button</type>
<id>2</id>
- <posX>60</posX>
- <posY>97</posY>
- <label>Start</label>
<onleft>2</onleft>
<onright>301</onright>
- <onup>7</onup>
+ <onup>6</onup>
<ondown>3</ondown>
</control>
<control>
<description>Mode</description>
<type>button</type>
<id>3</id>
- <posX>60</posX>
- <posY>131</posY>
- <label>Mode: Play vs Player</label>
<onleft>3</onleft>
- <onright>3</onright>
+ <onright>301</onright>
<onup>2</onup>
<ondown>4</ondown>
</control>
@@ -75,46 +72,47 @@
<description>Level</description>
<type>button</type>
<id>4</id>
- <posX>60</posX>
- <posY>165</posY>
- <label>Level: Amateur</label>
<onleft>4</onleft>
- <onright>4</onright>
+ <onright>301</onright>
<onup>3</onup>
- <ondown>7</ondown>
+ <ondown>5</ondown>
</control>
<control>
- <description>text label</description>
- <type>label</type>
+ <description>Sounds</description>
+ <type>togglebutton</type>
<id>5</id>
- <posX>70</posX>
- <posY>205</posY>
+ <onleft>5</onleft>
+ <onright>301</onright>
+ <onup>4</onup>
+ <ondown>6</ondown>
+ </control>
+ <control>
+ <description>Round</description>
+ <type>button</type>
+ <id>1</id>
<label>#Round</label>
<font>font12</font>
- <align>Left</align>
- <textcolor>ffffffff</textcolor>
+ <enabled>false</enabled>
+ <textureFocus>-</textureFocus>
+ <textureNoFocus>-</textureNoFocus>
</control>
<control>
- <description>text label</description>
- <type>label</type>
- <id>6</id>
- <posX>70</posX>
- <posY>240</posY>
+ <description>Player: / GameOver</description>
+ <type>button</type>
+ <id>1</id>
<label>#Player</label>
<font>font12</font>
- <align>Left</align>
- <textcolor>ffffffff</textcolor>
+ <enabled>false</enabled>
+ <textureFocus>-</textureFocus>
+ <textureNoFocus>-</textureNoFocus>
</control>
<control>
<description>Whatsthis</description>
<type>button</type>
- <id>7</id>
- <posX>60</posX>
- <posY>270</posY>
- <label>What's this?</label>
- <onleft>7</onleft>
+ <id>6</id>
+ <onleft>6</onleft>
<onright>301</onright>
- <onup>4</onup>
+ <onup>5</onup>
<ondown>2</ondown>
</control>
</control>
Modified: trunk/plugins/My Connect4/Source/MyConnect4/MyConnect4.cs
===================================================================
--- trunk/plugins/My Connect4/Source/MyConnect4/MyConnect4.cs 2007-05-26 07:11:42 UTC (rev 451)
+++ trunk/plugins/My Connect4/Source/MyConnect4/MyConnect4.cs 2007-05-26 07:14:27 UTC (rev 452)
@@ -39,28 +39,46 @@
[PluginIcons("MyConnect4.connect4.png", "MyConnect4.connect4Disabled.png")]
public class MyConnect4GUI : GUIWindow, ISetupForm
{
+ #region enums
+
+ private enum Level
+ {
+ Easy = 0,
+ Medium = 1,
+ Hard = 2
+ }
+
+ private enum Mode
+ {
+ PlayerVsComputer = 0,
+ PlayerVsPlayer = 1
+ }
+
+ #endregion
+
#region SkinControl
- [SkinControlAttribute(11)]
- protected GUILabelControl lblHeader = null;
[SkinControlAttribute(2)]
- protected GUIButtonControl BtnStart = null;
+ protected GUIButtonControl btnStart = null;
+ [SkinControlAttribute(3)]
+ protected GUIButtonControl btnMode = null;
[SkinControlAttribute(4)]
- protected GUIButtonControl BtnLevel = null;
- [SkinControlAttribute(3)]
- protected GUIButtonControl BtnMode = null;
+ protected GUIButtonControl btnLevel = null;
+ [SkinControlAttribute(5)]
+ protected GUIToggleButtonControl btnSound = null;
+ [SkinControlAttribute(6)]
+ protected GUIButtonControl btnWhatsThis = null;
- [SkinControlAttribute(7)]
- protected GUIButtonControl BtnWhatsThis = null;
#endregion
#region Private variables
- string Level = "Nor"; //Choosen level
+ Level _currentLevel = Level.Easy;
+ Mode _currentMode = Mode.PlayerVsComputer;
+ bool _soundOn = true;
+
int AI = 5;
- string Mode = "1p"; //2player
-
int Player = 0;
int round = 0;
@@ -147,6 +165,8 @@
#endregion
+ #region Overrides
+
public override int GetID
{
get
@@ -169,50 +189,11 @@
return result;
}
- #region Actions
- public override void OnAction(Action action)
- {
- base.OnAction(action);
- }
- public void OnAction2(Action action)
- {
-
- if (GUIWindowManager.ActiveWindowEx == (int)GUIWindow.Window.WINDOW_DIALOG_MENU) return;
-
- //string t = action.wID.ToString();
- //GUIPropertyManager.SetProperty("#Round", t);
-
- if ((Player == 1) | (Player == 2 && Mode == "2p"))
- {
- switch (action.wID)
- {
- case Action.ActionType.ACTION_MOVE_LEFT:
-
- break;
- case Action.ActionType.ACTION_MOVE_RIGHT:
-
- break;
- case Action.ActionType.ACTION_SELECT_ITEM:
-
- break;
- default:
- break;
- }
- }
- }
- #endregion
-
public override bool OnMessage(GUIMessage message)
{
return base.OnMessage(message);
}
- public void Dispose()
- {
- _Game.Stop();
- _Game.Tick -= new EventHandler(_Game_Tick);
- }
-
protected override void OnPageLoad()
{
_Game.Interval = 300;
@@ -220,28 +201,9 @@
_Game.Start();
Player = 0;
- Level = "Nor";
- Mode = "1p";
- AI = 5;
- GUIPropertyManager.SetProperty("#header_label", MyConnect.GUILocalizeStrings.Get(0)); // My Connect 4
-
- GUIControl.SetControlLabel(GetID, BtnStart.GetID, MyConnect.GUILocalizeStrings.Get(1)); // Start
- GUIControl.SetControlLabel(GetID, BtnWhatsThis.GetID, MyConnect.GUILocalizeStrings.Get(31)); // What is Connect4?
-
GUIPropertyManager.SetProperty("#Status", " ");
- GUIControl.SetControlLabel(GetID, BtnLevel.GetID,
- MyConnect.GUILocalizeStrings.Get(10) + // Level:
- MyConnect.GUILocalizeStrings.Get(12)); // Normal
- GUIControl.SetControlLabel(GetID, BtnMode.GetID,
- MyConnect.GUILocalizeStrings.Get(20) + // Mode: Play vs
- MyConnect.GUILocalizeStrings.Get(21)); // Comp
- // Disable level selection
- GUIControl.DisableControl(GetID, 4);
-
- RelButtons();
-
GUIGraphicsContext.OnNewAction -= ah;
GUIGraphicsContext.OnNewAction += ah;
@@ -252,6 +214,7 @@
Drawfield();
+ UpdateButtonStates();
}
protected override void OnPageDestroy(int new_windowId)
@@ -262,38 +225,18 @@
protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
{
- if (control == BtnLevel)
+ if (control == btnStart)
+ OnBtnStart();
+ else if (control == btnLevel)
OnBtnLevel();
- if (control == BtnMode)
+ else if (control == btnMode)
OnBtnMode();
- if (control == BtnWhatsThis)
+ else if (control == btnSound)
+ OnBtnSound();
+ else if (control == btnWhatsThis)
OnBtnWhatsThis();
- if (control == BtnStart)
- { //start game
- if (Player == 0 && wait == 0)
- {
- Player = 1;
- round = 0;
- GUIPropertyManager.SetProperty("#Status", " ");
-
- // Disable start button
- GUIControl.DisableControl(GetID, 2);
- // Disable level selection
- GUIControl.DisableControl(GetID, 3);
- // Disable mode selection
- GUIControl.DisableControl(GetID, 4);
-
- this.gameEngine = null;
- this.gameEngine = new Engine(7, 6, 4);
-
- Drawfield();
-
- wait = 2;
- GUIControl.FocusControl(GetID, 15);
- }
- }
- if ((Player == 1) | (Player == 2 && Mode == "2p"))
+ if ((Player == 1) | (Player == 2 && _currentMode == Mode.PlayerVsPlayer))
{
if ((controlId >= 301) && (controlId <= 307))
@@ -313,62 +256,80 @@
base.OnShowContextMenu();
}
+ #endregion
+
+ #region Implementation
+
+ private void OnBtnStart()
+ {
+ //start game
+ if (Player != 0)
+ return;
+ if (wait != 0)
+ return;
+
+ Player = 1;
+ round = 0;
+ GUIPropertyManager.SetProperty("#Status", " ");
+
+ this.gameEngine = null;
+ this.gameEngine = new Engine(7, 6, 4);
+
+ Drawfield();
+
+ wait = 2;
+ GUIControl.FocusControl(GetID, 15);
+
+ UpdateButtonStates();
+ }
+
private void OnBtnLevel()
- { //Choose level for the game
- if (Player == 0)
+ {
+ //Choose level for the game
+ if (Player != 0)
+ return;
+
+ switch (_currentLevel)
{
- if (Level == "Nor")
- {
- GUIControl.SetControlLabel(GetID, BtnLevel.GetID,
- MyConnect.GUILocalizeStrings.Get(10) + // Level:
- MyConnect.GUILocalizeStrings.Get(13)); // Professional
- Level = "Pro";
- AI = 8;
- }
- else if (Level == "Pro")
- {
- GUIControl.SetControlLabel(GetID, BtnLevel.GetID,
- MyConnect.GUILocalizeStrings.Get(10) + // Level:
- MyConnect.GUILocalizeStrings.Get(11)); // Amateur
- Level = "Am";
- AI = 3;
- }
- else
- {
- GUIControl.SetControlLabel(GetID, BtnLevel.GetID,
- MyConnect.GUILocalizeStrings.Get(10) + // Level:
- MyConnect.GUILocalizeStrings.Get(12)); // Normal
- Level = "Nor";
- AI = 5;
- }
+ case Level.Easy:
+ _currentLevel = Level.Medium;
+ break;
+ case Level.Medium:
+ _currentLevel = Level.Hard;
+ break;
+ case Level.Hard:
+ _currentLevel = Level.Easy;
+ break;
}
+
+ UpdateButtonStates();
}
private void OnBtnMode()
- { //Choose mode for the game
- if (Player == 0)
+ {
+ //Choose mode for the game
+ if (Player != 0)
+ return;
+
+ switch (_currentMode)
{
- if (Mode == "2p")
- {
- GUIControl.SetControlLabel(GetID, BtnMode.GetID,
- MyConnect.GUILocalizeStrings.Get(20) + // Mode: Play vs
- MyConnect.GUILocalizeStrings.Get(21)); // Comp
- Mode = "1p";
- // Enable level selection
- GUIControl.EnableControl(GetID, 4);
- }
- else
- {
- GUIControl.SetControlLabel(GetID, BtnMode.GetID,
- MyConnect.GUILocalizeStrings.Get(20) + // Mode: Play vs
- MyConnect.GUILocalizeStrings.Get(22)); // Player
- Mode = "2p";
- // Disable level selection
- GUIControl.DisableControl(GetID, 4);
- }
+ case Mode.PlayerVsComputer:
+ _currentMode = Mode.PlayerVsPlayer;
+ break;
+ case Mode.PlayerVsPlayer:
+ _currentMode = Mode.PlayerVsComputer;
+ break;
}
+
+ UpdateButtonStates();
}
+ private void OnBtnSound()
+ {
+ _soundOn = btnSound.Selected;
+ UpdateButtonStates();
+ }
+
private void OnBtnWhatsThis()
{
GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT);
@@ -377,6 +338,100 @@
dlg.DoModal(GetID);
}
+ private void OnRenderSound(string strFilePath)
+ {
+ if (_soundOn)
+ {
+ MediaPortal.Util.Utils.PlaySound(strFilePath, false, true);
+ }
+ }
+
+ private void UpdateButtonStates()
+ {
+ GUIPropertyManager.SetProperty("#header_label", MyConnect.GUILocalizeStrings.Get(0)); // MyConnect
+
+ GUIControl.SetControlLabel(GetID, btnStart.GetID, MyConnect.GUILocalizeStrings.Get(1)); // Start
+ btnStart.Disabled = (Player != 0);
+
+ string strLine = MyConnect.GUILocalizeStrings.Get(10); // Level:
+ switch (_currentLevel)
+ {
+ case Level.Easy:
+ strLine += MyConnect.GUILocalizeStrings.Get(11); // easy
+ AI = 3;
+ break;
+ case Level.Medium:
+ strLine += MyConnect.GUILocalizeStrings.Get(12); // medium
+ AI = 5;
+ break;
+ case Level.Hard:
+ strLine += MyConnect.GUILocalizeStrings.Get(13); // difficult
+ AI = 8;
+ break;
+ }
+ GUIControl.SetControlLabel(GetID, btnLevel.GetID, strLine);
+ btnLevel.Disabled = ((Player != 0) || (_currentMode == Mode.PlayerVsPlayer));
+
+ strLine = MyConnect.GUILocalizeStrings.Get(20); // Mode: Play vs
+ switch (_currentMode)
+ {
+ case Mode.PlayerVsComputer:
+ strLine += MyConnect.GUILocalizeStrings.Get(21); // Comp
+ break;
+ case Mode.PlayerVsPlayer:
+ strLine += MyConnect.GUILocalizeStrings.Get(22); // Player
+ break;
+ }
+ GUIControl.SetControlLabel(GetID, btnMode.GetID, strLine);
+ btnMode.Disabled = (Player != 0);
+
+ GUIControl.SetControlLabel(GetID, btnSound.GetID, MyConnect.GUILocalizeStrings.Get(9)); // Sounds
+ btnSound.Selected = _soundOn;
+
+ GUIControl.SetControlLabel(GetID, btnWhatsThis.GetID, MyConnect.GUILocalizeStrings.Get(31)); // What is MyConnect?
+ }
+
+ #endregion
+
+ #region Actions
+ public override void OnAction(Action action)
+ {
+ base.OnAction(action);
+ }
+ public void OnAction2(Action action)
+ {
+
+ if (GUIWindowManager.ActiveWindowEx == (int)GUIWindow.Window.WINDOW_DIALOG_MENU) return;
+
+ //string t = action.wID.ToString();
+ //GUIPropertyManager.SetProperty("#Round", t);
+
+ if ((Player == 1) | (Player == 2 && _currentMode == Mode.PlayerVsPlayer))
+ {
+ switch (action.wID)
+ {
+ case Action.ActionType.ACTION_MOVE_LEFT:
+
+ break;
+ case Action.ActionType.ACTION_MOVE_RIGHT:
+
+ break;
+ case Action.ActionType.ACTION_SELECT_ITEM:
+
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ #endregion
+
+ public void Dispose()
+ {
+ _Game.Stop();
+ _Game.Tick -= new EventHandler(_Game_Tick);
+ }
+
private void Drawfield()
{ // draw all fields
@@ -407,9 +462,8 @@
{
round++;
Drawfield();
- MediaPortal.Util.Utils.PlaySound("MyConnect4_klick.wav", false, true);
+ OnRenderSound("MyConnect4_klick.wav");
-
if (gameEngine.isWinner(Player - 1) == true)
{
int tmp = Player;
@@ -419,7 +473,7 @@
MyConnect.GUILocalizeStrings.Get(3) // wins the game!
);
Player = 0;
- RelButtons();
+ UpdateButtonStates();
gameEngine.getState().flashit(3);
Drawfield();
}
@@ -427,7 +481,7 @@
{
GUIPropertyManager.SetProperty("#Status", MyConnect.GUILocalizeStrings.Get(4)); // Nobody wins the game ! Its a draw !
Player = 0;
- RelButtons();
+ UpdateButtonStates();
GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
}
NextPlayer();
@@ -446,20 +500,6 @@
}
}
- private void RelButtons()
- {
- // Enable start button
- GUIControl.EnableControl(GetID, 2);
- // Enable mode selection
- GUIControl.EnableControl(GetID, 3);
- if (Mode == "1p") // Enable level selection
- GUIControl.EnableControl(GetID, 4);
- // Enable What this
- GUIControl.EnableControl(GetID, 7);
-
- //GUIControl.FocusControl(GetID, 2);
- }
-
void _Game_Tick(object sender, EventArgs e)
{
//display status of the game
@@ -478,7 +518,7 @@
wait = wait - 1;
}
- if (Player == 2 && Mode == "1p" && wait == 0)
+ if (Player == 2 && _currentMode == Mode.PlayerVsComputer && wait == 0)
{
Point pos = gameEngine.computerMove(1, AI);
if (pos.Y >= 0)
@@ -486,7 +526,7 @@
wait = 2;
round++;
Drawfield();
- MediaPortal.Util.Utils.PlaySound("MyConnect4_klick.wav", false, true);
+ OnRenderSound("MyConnect4_klick.wav");
if (gameEngine.isWinner(Player - 1) == true)
@@ -499,13 +539,13 @@
gameEngine.getState().flashit(3);
Drawfield();
Player = 0;
- RelButtons();
+ UpdateButtonStates();
}
if (gameEngine.isTie() == true)
{
GUIPropertyManager.SetProperty("#Status", MyConnect.GUILocalizeStrings.Get(4)); // Nobody wins the game ! Its a draw !
Player = 0;
- RelButtons();
+ UpdateButtonStates();
}
NextPlayer();
}
@@ -513,6 +553,5 @@
}
}
-
}
}
\ No newline at end of file
Modified: trunk/plugins/My Connect4/language/MyConnect4/strings_de.xml
===================================================================
--- trunk/plugins/My Connect4/language/MyConnect4/strings_de.xml 2007-05-26 07:11:42 UTC (rev 451)
+++ trunk/plugins/My Connect4/language/MyConnect4/strings_de.xml 2007-05-26 07:14:27 UTC (rev 452)
@@ -8,6 +8,7 @@
<String id="4">Unentschieden! Keiner hat gewonnen!</String>
<String id="5">Runde: </String>
<String id="6">GAME OVER</String>
+ <String id="9">Spielgeräusche</String>
<String id="10">Stufe: </String>
<String id="11">leicht</String>
<String id="12">mittel</String>
Modified: trunk/plugins/My Connect4/language/MyConnect4/strings_en.xml
===================================================================
--- trunk/plugins/My Connect4/language/MyConnect4/strings_en.xml 2007-05-26 07:11:42 UTC (rev 451)
+++ trunk/plugins/My Connect4/language/MyConnect4/strings_en.xml 2007-05-26 07:14:27 UTC (rev 452)
@@ -2,12 +2,13 @@
<Language name="English" characters="255">
<Section name="unmapped">
<String id="0" prefix="My ">Connect 4</String>
- <String id="1">Start</String>
+ <String id="1">New Game</String>
<String id="2">Player</String>
<String id="3">wins the game!</String>
<String id="4">Nobody wins the game ! Its a draw !</String>
<String id="5">Round: </String>
<String id="6">GAME OVER</String>
+ <String id="9">Sounds</String>
<String id="10">Level: </String>
<String id="11">easy</String>
<String id="12">medium</String>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|