From: <che...@us...> - 2007-05-24 21:16:08
|
Revision: 437 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=437&view=rev Author: chef_koch Date: 2007-05-24 14:16:06 -0700 (Thu, 24 May 2007) Log Message: ----------- added simonsay is now full localisable Modified Paths: -------------- trunk/plugins/MySimon/Source/SimonSay/MySimon.cs trunk/plugins/MySimon/Source/SimonSay/MySimon.csproj Added Paths: ----------- trunk/plugins/MySimon/Source/SimonSay/LocalizeStrings.cs trunk/plugins/MySimon/language/ trunk/plugins/MySimon/language/MySimon/ trunk/plugins/MySimon/language/MySimon/strings_de.xml trunk/plugins/MySimon/language/MySimon/strings_en.xml Removed Paths: ------------- trunk/plugins/MySimon/Source/SimonSay.suo Added: trunk/plugins/MySimon/Source/SimonSay/LocalizeStrings.cs =================================================================== --- trunk/plugins/MySimon/Source/SimonSay/LocalizeStrings.cs (rev 0) +++ trunk/plugins/MySimon/Source/SimonSay/LocalizeStrings.cs 2007-05-24 21:16:06 UTC (rev 437) @@ -0,0 +1,260 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.IO; +using System.Globalization; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; +using MediaPortal.Localisation; + +namespace MediaPortal.GUI.MySimon +{ + /// <summary> + /// This class will hold all text used in the application + /// The text is loaded for the current language from + /// the file language/[language]/strings.xml + /// </summary> + public class GUILocalizeStrings + { + #region Variables + static LocalisationProvider _stringProvider; + static Dictionary<string, string> _cultures; + static string[] _languages; + #endregion + + #region Constructors/Destructors + // singleton. Dont allow any instance of this class + private GUILocalizeStrings() + { + } + + static public void Dispose() + { + if (_stringProvider != null) + _stringProvider.Dispose(); + } + #endregion + + #region Public Methods + /// <summary> + /// Public method to load the text from a strings/xml file into memory + /// </summary> + /// <param name="strFileName">Contains the filename+path for the string.xml file</param> + /// <returns> + /// true when text is loaded + /// false when it was unable to load the text + /// </returns> + //[Obsolete("This method has changed", true)] + static public bool Load(string language) + { + bool isPrefixEnabled = true; + + using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + isPrefixEnabled = reader.GetValueAsBool("general", "myprefix", true); + + string directory = Config.GetSubFolder(Config.Dir.Language, "MySimon"); + string cultureName = null; + if (language != null) + cultureName = GetCultureName(language); + + Log.Info(" Loading localised Strings - Path: {0} Culture: {1} Language: {2} Prefix: {3}", directory, cultureName, language, isPrefixEnabled); + + _stringProvider = new LocalisationProvider(directory, cultureName, isPrefixEnabled); + + GUIGraphicsContext.CharsInCharacterSet = _stringProvider.Characters; + + return true; + } + + static public string CurrentLanguage() + { + if (_stringProvider == null) + Load(null); + + return _stringProvider.CurrentLanguage.EnglishName; + } + + static public void ChangeLanguage(string language) + { + if (_stringProvider == null) + Load(language); + else + _stringProvider.ChangeLanguage(GetCultureName(language)); + } + + /// <summary> + /// Get the translation for a given id and format the sting with + /// the given parameters + /// </summary> + /// <param name="dwCode">id of text</param> + /// <param name="parameters">parameters used in the formating</param> + /// <returns> + /// string containing the translated text + /// </returns> + static public string Get(int dwCode, object[] parameters) + { + if (_stringProvider == null) + Load(null); + + string translation = _stringProvider.GetString("unmapped", dwCode); + // if parameters or the translation is null, return the translation. + if ((translation == null) || (parameters == null)) + { + return translation; + } + // return the formatted string. If formatting fails, log the error + // and return the unformatted string. + try + { + return String.Format(translation, parameters); + } + catch (System.FormatException e) + { + Log.Error("Error formatting translation with id {0}", dwCode); + Log.Error("Unformatted translation: {0}", translation); + Log.Error(e); + return translation; + } + } + + /// <summary> + /// Get the translation for a given id + /// </summary> + /// <param name="dwCode">id of text</param> + /// <returns> + /// string containing the translated text + /// </returns> + static public string Get(int dwCode) + { + if (_stringProvider == null) + Load(null); + + string translation = _stringProvider.GetString("unmapped", dwCode); + + if (translation == null) + { + Log.Error("No translation found for id {0}", dwCode); + return String.Empty; + } + + return translation; + } + + static public void LocalizeLabel(ref string strLabel) + { + if (_stringProvider == null) + Load(null); + + if (strLabel == null) strLabel = String.Empty; + if (strLabel == "-") strLabel = ""; + if (strLabel == "") return; + // This can't be a valid string code if the first character isn't a number. + // This check will save us from catching unnecessary exceptions. + if (!char.IsNumber(strLabel, 0)) + return; + + int dwLabelID; + + try + { + dwLabelID = System.Int32.Parse(strLabel); + } + catch (FormatException e) + { + Log.Error(e); + strLabel = String.Empty; + return; + } + + strLabel = _stringProvider.GetString("unmapped", dwLabelID); + if (strLabel == null) + { + Log.Error("No translation found for id {0}", dwLabelID); + strLabel = String.Empty; + } + } + + public static string LocalSupported() + { + if (_stringProvider == null) + Load(null); + + CultureInfo culture = _stringProvider.GetBestLanguage(); + + return culture.EnglishName; + } + + public static string[] SupportedLanguages() + { + if (_languages == null) + { + if (_stringProvider == null) + Load(null); + + CultureInfo[] cultures = _stringProvider.AvailableLanguages(); + + SortedList sortedLanguages = new SortedList(); + foreach (CultureInfo culture in cultures) + sortedLanguages.Add(culture.EnglishName, culture.EnglishName); + + _languages = new string[sortedLanguages.Count]; + + for (int i = 0; i < sortedLanguages.Count; i++) + { + _languages[i] = (string)sortedLanguages.GetByIndex(i); + } + } + + return _languages; + } + + static public string GetCultureName(string language) + { + if (_cultures == null) + { + _cultures = new Dictionary<string, string>(); + + CultureInfo[] cultureList = CultureInfo.GetCultures(CultureTypes.AllCultures); + + for (int i = 0; i < cultureList.Length; i++) + { + _cultures.Add(cultureList[i].EnglishName, cultureList[i].Name); + } + } + + if (_cultures.ContainsKey(language)) + return _cultures[language]; + + return null; + } + #endregion + } +} \ No newline at end of file Modified: trunk/plugins/MySimon/Source/SimonSay/MySimon.cs =================================================================== --- trunk/plugins/MySimon/Source/SimonSay/MySimon.cs 2007-05-24 21:11:19 UTC (rev 436) +++ trunk/plugins/MySimon/Source/SimonSay/MySimon.cs 2007-05-24 21:16:06 UTC (rev 437) @@ -35,590 +35,611 @@ namespace MediaPortal.GUI.MySimon { - [PluginIcons("MySimon.simon.png", "MySimon.simonDisabled.png")] - public class MySimonGUI : GUIWindow , ISetupForm - { - #region SkinControl - [SkinControlAttribute(2)] protected GUIButtonControl BtnStart = null; - [SkinControlAttribute(3)] protected GUIButtonControl BtnLevel = null; - - [SkinControlAttribute(6)] protected GUIButtonControl BtnWhatsThis = null; + [PluginIcons("MySimon.simon.png", "MySimon.simonDisabled.png")] + public class MySimonGUI : GUIWindow, ISetupForm + { + #region SkinControl + [SkinControlAttribute(2)] + protected GUIButtonControl BtnStart = null; + [SkinControlAttribute(3)] + protected GUIButtonControl BtnLevel = null; - [SkinControlAttribute(101)] protected GUIButtonControl BtnRed = null; - [SkinControlAttribute(102)] protected GUIButtonControl BtnBlue = null; - [SkinControlAttribute(103)] protected GUIButtonControl BtnGreen = null; - [SkinControlAttribute(104)] protected GUIButtonControl BtnYellow = null; - #endregion + [SkinControlAttribute(6)] + protected GUIButtonControl BtnWhatsThis = null; - #region Private variables - string Level="Am"; //Choosen level + [SkinControlAttribute(101)] + protected GUIButtonControl BtnRed = null; + [SkinControlAttribute(102)] + protected GUIButtonControl BtnBlue = null; + [SkinControlAttribute(103)] + protected GUIButtonControl BtnGreen = null; + [SkinControlAttribute(104)] + protected GUIButtonControl BtnYellow = null; + #endregion - Boolean SimonOn = false; - Boolean PlayerOn = false; + #region Private variables + string Level = "Am"; //Choosen level - int[] Code = new int[100]; + Boolean SimonOn = false; + Boolean PlayerOn = false; - int timeBase = 0; - int timeActual = 0; - int timeWait = 0; + int[] Code = new int[100]; - int round = 0; - int cnt = 0; + int timeBase = 0; + int timeActual = 0; + int timeWait = 0; - bool test = true; + int round = 0; + int cnt = 0; - private static OnActionHandler ah; + bool test = true; - private System.Windows.Forms.Timer _Game = new System.Windows.Forms.Timer(); - #endregion + private static OnActionHandler ah; - #region ISetupForm Members + private System.Windows.Forms.Timer _Game = new System.Windows.Forms.Timer(); + #endregion - // Returns the name of the plugin which is shown in the plugin menu - public string PluginName() - { - return "My Simon Say"; - } + #region ISetupForm Members - // Returns the description of the plugin is shown in the plugin menu - public string Description() - { - return "Simon Say"; - } + // Returns the name of the plugin which is shown in the plugin menu + public string PluginName() + { + return "My Simon Say"; + } - // Returns the author of the plugin which is shown in the plugin menu - public string Author() - { - return "Mark Koenig (kroko)"; - } + // Returns the description of the plugin is shown in the plugin menu + public string Description() + { + return "Simon Say"; + } - // show the setup dialog - public void ShowPlugin() - { - MessageBox.Show("Nothing to configure, this is just an example"); - } + // Returns the author of the plugin which is shown in the plugin menu + public string Author() + { + return "Mark Koenig (kroko)"; + } - // Indicates whether plugin can be enabled/disabled - public bool CanEnable() + // show the setup dialog + public void ShowPlugin() + { + MessageBox.Show("Nothing to configure, this is just an example"); + } + + // Indicates whether plugin can be enabled/disabled + public bool CanEnable() + { + return true; + } + + // get ID of windowplugin belonging to this setup + public int GetWindowId() + { + return 04071975; + } + + // Indicates if plugin is enabled by default; + public bool DefaultEnabled() + { + return true; + } + + // indicates if a plugin has its own setup screen + public bool HasSetup() + { + return false; + } + + /// <summary> + /// If the plugin should have its own button on the main menu of MediaPortal then it + /// should return true to this method, otherwise if it should not be on home + /// it should return false + /// </summary> + /// <param name="strButtonText">text the button should have</param> + /// <param name="strButtonImage">image for the button, or empty for default</param> + /// <param name="strButtonImageFocus">image for the button, or empty for default</param> + /// <param name="strPictureImage">subpicture for the button or empty for none</param> + /// <returns>true : plugin needs its own button on home + /// false : plugin does not need its own button on home</returns> + + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = MySimon.GUILocalizeStrings.Get(0); + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = "hover_my simon.png"; + return true; + } + + #endregion + + public override int GetID + { + get { - return true; + return 04071975; } - - // get ID of windowplugin belonging to this setup - public int GetWindowId() + set { - return 04071975; + base.GetID = value; } + } - // Indicates if plugin is enabled by default; - public bool DefaultEnabled() - { - return true; - } + public override bool Init() + { + MySimon.GUILocalizeStrings.Load(GUI.Library.GUILocalizeStrings.CurrentLanguage()); - // indicates if a plugin has its own setup screen - public bool HasSetup() - { - return false; - } + bool result = Load(GUIGraphicsContext.Skin + @"\MySimon.xml"); + if (ah == null) ah = new OnActionHandler(OnAction2); - /// <summary> - /// If the plugin should have its own button on the main menu of MediaPortal then it - /// should return true to this method, otherwise if it should not be on home - /// it should return false - /// </summary> - /// <param name="strButtonText">text the button should have</param> - /// <param name="strButtonImage">image for the button, or empty for default</param> - /// <param name="strButtonImageFocus">image for the button, or empty for default</param> - /// <param name="strPictureImage">subpicture for the button or empty for none</param> - /// <returns>true : plugin needs its own button on home - /// false : plugin does not need its own button on home</returns> + return result; + } - public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + #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 (PlayerOn) { - strButtonText = PluginName(); - strButtonImage = String.Empty; - strButtonImageFocus = String.Empty; - strPictureImage = "hover_my simon.png"; - return true; + switch (action.wID) + { + //normal + case Action.ActionType.ACTION_REMOTE_RED_BUTTON: + Check(0); + break; + case Action.ActionType.ACTION_REMOTE_BLUE_BUTTON: + Check(1); + break; + case Action.ActionType.ACTION_REMOTE_GREEN_BUTTON: + Check(2); + break; + case Action.ActionType.ACTION_REMOTE_YELLOW_BUTTON: + Check(3); + break; + //my PC + case Action.ActionType.ACTION_SHOW_GUI: + Check(0); + break; + case Action.ActionType.ACTION_ASPECT_RATIO: + Check(1); + break; + case Action.ActionType.ACTION_NEXT_AUDIO: + Check(2); + break; + case Action.ActionType.ACTION_SHOW_INFO: + Check(3); + break; + // for use with arrows + case Action.ActionType.ACTION_MOVE_UP: + Check(0); + break; + case Action.ActionType.ACTION_MOVE_RIGHT: + Check(1); + break; + case Action.ActionType.ACTION_MOVE_DOWN: + Check(3); + break; + case Action.ActionType.ACTION_MOVE_LEFT: + Check(2); + break; + // play with 2 + // play with 4 6 + // play with 8 + case Action.ActionType.ACTION_KEY_PRESSED: + switch (action.m_key.KeyChar) + { + case '2': + Check(0); + break; + case '6': + Check(1); + break; + case '4': + Check(2); + break; + case '8': + Check(3); + break; + } + break; + default: + break; + } } + else + { + if (test) + { + switch (action.wID) + { + //my PC + case Action.ActionType.ACTION_SHOW_GUI: + Reset(); + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_ASPECT_RATIO: + Reset(); + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_NEXT_AUDIO: + Reset(); + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_SHOW_INFO: + Reset(); + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); + timeWait = 30; + break; - #endregion + case Action.ActionType.ACTION_MOVE_UP: + Reset(); + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_MOVE_RIGHT: + Reset(); + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_MOVE_DOWN: + Reset(); + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); + timeWait = 30; + break; + case Action.ActionType.ACTION_MOVE_LEFT: + Reset(); + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); + timeWait = 30; + break; - public override int GetID - { - get - { - return 04071975; + case Action.ActionType.ACTION_KEY_PRESSED: + switch (action.m_key.KeyChar) + { + case '2': + Reset(); + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); + timeWait = 30; + break; + case '6': + Reset(); + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); + timeWait = 30; + break; + case '8': + Reset(); + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); + timeWait = 30; + break; + case '4': + Reset(); + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); + timeWait = 30; + break; + } + break; } - set - { - base.GetID = value; - } + } } - - public override bool Init() - { - bool result = Load(GUIGraphicsContext.Skin + @"\MySimon.xml"); - if (ah == null) ah = new OnActionHandler(OnAction2); - return result; - } - #region Actions - public override void OnAction(Action action) - { - base.OnAction(action); - } - public void OnAction2(Action action) - { + } + #endregion - if (GUIWindowManager.ActiveWindowEx == (int)GUIWindow.Window.WINDOW_DIALOG_MENU) return; + public override bool OnMessage(GUIMessage message) + { + return base.OnMessage(message); + } - //string t = action.wID.ToString(); - //GUIPropertyManager.SetProperty("#Round", t); + public void Dispose() + { + _Game.Stop(); + _Game.Tick -= new EventHandler(_Game_Tick); + } - if (PlayerOn) - { - switch (action.wID) - { - //normal - case Action.ActionType.ACTION_REMOTE_RED_BUTTON: - Check(0); - break; - case Action.ActionType.ACTION_REMOTE_BLUE_BUTTON: - Check(1); - break; - case Action.ActionType.ACTION_REMOTE_GREEN_BUTTON: - Check(2); - break; - case Action.ActionType.ACTION_REMOTE_YELLOW_BUTTON: - Check(3); - break; - //my PC - case Action.ActionType.ACTION_SHOW_GUI: - Check(0); - break; - case Action.ActionType.ACTION_ASPECT_RATIO: - Check(1); - break; - case Action.ActionType.ACTION_NEXT_AUDIO: - Check(2); - break; - case Action.ActionType.ACTION_SHOW_INFO: - Check(3); - break; - // for use with arrows - case Action.ActionType.ACTION_MOVE_UP: - Check(0); - break; - case Action.ActionType.ACTION_MOVE_RIGHT: - Check(1); - break; - case Action.ActionType.ACTION_MOVE_DOWN: - Check(3); - break; - case Action.ActionType.ACTION_MOVE_LEFT: - Check(2); - break; - // play with 2 - // play with 4 6 - // play with 8 - case Action.ActionType.ACTION_KEY_PRESSED: - switch (action.m_key.KeyChar) - { - case '2': - Check(0); - break; - case '6': - Check(1); - break; - case '4': - Check(2); - break; - case '8': - Check(3); - break; - } - break; - default: - break; - } - } - else - { - if (test) - { - switch (action.wID) - { - //my PC - case Action.ActionType.ACTION_SHOW_GUI: - Reset(); - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_ASPECT_RATIO: - Reset(); - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_NEXT_AUDIO: - Reset(); - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_SHOW_INFO: - Reset(); - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); - timeWait = 30; - break; + protected override void OnPageLoad() + { + _Game.Interval = 5; + _Game.Tick += new EventHandler(_Game_Tick); + _Game.Start(); - case Action.ActionType.ACTION_MOVE_UP: - Reset(); - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_MOVE_RIGHT: - Reset(); - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_MOVE_DOWN: - Reset(); - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); - timeWait = 30; - break; - case Action.ActionType.ACTION_MOVE_LEFT: - Reset(); - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); - timeWait = 30; - break; + SimonOn = false; + PlayerOn = false; + Level = "Am"; - case Action.ActionType.ACTION_KEY_PRESSED: - switch (action.m_key.KeyChar) - { - case '2': - Reset(); - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); - timeWait = 30; - break; - case '6': - Reset(); - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); - timeWait = 30; - break; - case '8': - Reset(); - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); - timeWait = 30; - break; - case '4': - Reset(); - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); - timeWait = 30; - break; - } - break; - } - } - } + GUIGraphicsContext.OnNewAction -= ah; + GUIGraphicsContext.OnNewAction += ah; - } - #endregion + base.OnPageLoad(); - public override bool OnMessage(GUIMessage message) - { - return base.OnMessage(message); - } + Reset(); - public void Dispose() - { - _Game.Stop(); - _Game.Tick -= new EventHandler(_Game_Tick); - } - protected override void OnPageLoad() - { - _Game.Interval = 5; - _Game.Tick += new EventHandler(_Game_Tick); - _Game.Start(); + GUIPropertyManager.SetProperty("#header_label", MySimon.GUILocalizeStrings.Get(0)); // My Simon - SimonOn = false; - PlayerOn = false; - Level = "Am"; + GUIControl.SetControlLabel(GetID, BtnStart.GetID, MySimon.GUILocalizeStrings.Get(1)); // Start + GUIControl.SetControlLabel(GetID, BtnWhatsThis.GetID, MySimon.GUILocalizeStrings.Get(31)); // What is My Simon? - GUIGraphicsContext.OnNewAction -= ah; - GUIGraphicsContext.OnNewAction += ah; + GUIPropertyManager.SetProperty("#Status", " "); + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, + MySimon.GUILocalizeStrings.Get(10) + // Level: + MySimon.GUILocalizeStrings.Get(12)); // Normal - base.OnPageLoad(); + GUIPropertyManager.SetProperty("#Round", MySimon.GUILocalizeStrings.Get(5) + "1"); // Round: 1 + GUIPropertyManager.SetProperty("#Player", MySimon.GUILocalizeStrings.Get(6)); // GAME OVER - Reset(); + GUIControl.EnableControl(GetID, 6); // what this - GUIPropertyManager.SetProperty("#Round", "Round: 1"); - GUIPropertyManager.SetProperty("#Player", "GAME OVER"); + } - GUIControl.EnableControl(GetID, 6); // what this + protected override void OnPageDestroy(int new_windowId) + { + _Game.Stop(); + _Game.Tick -= new EventHandler(_Game_Tick); + } - } + protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) + { + if (control == BtnLevel) + OnBtnLevel(); + if (control == BtnWhatsThis) + OnBtnWhatsThis(); + if (control == BtnStart) + { //start game + if ((!PlayerOn) && (!SimonOn)) + { - protected override void OnPageDestroy(int new_windowId) - { - _Game.Stop(); - _Game.Tick -= new EventHandler(_Game_Tick); - } + test = false; + GUIControl.DisableControl(GetID, 6); // what this - protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) - { - if (control == BtnLevel) - OnBtnLevel(); - if (control == BtnWhatsThis) - OnBtnWhatsThis(); - if (control == BtnStart) - { //start game - if ((!PlayerOn) && (!SimonOn)) - { + Random randObj = new Random(); + for (int i = 0; i <= 99; i++) + { // do random colors for 100 rounds + Code[i] = (int)(randObj.NextDouble() * 4); + } + // set timebase for game + if (Level == "Pro") + timeBase = 4; + if (Level == "Nor") + timeBase = 10; + if (Level == "Am") + timeBase = 20; - test = false; - GUIControl.DisableControl(GetID, 6); // what this - - Random randObj = new Random(); - for (int i = 0; i <= 99; i++) - { // do random colors for 100 rounds - Code[i] = (int)(randObj.NextDouble() * 4); - } - // set timebase for game - if (Level == "Pro") - timeBase = 4; - if (Level == "Nor") - timeBase = 10; - if (Level == "Am") - timeBase = 20; + // disable level selection + GUIControl.DisableControl(GetID, 3); - // disable level selection - GUIControl.DisableControl(GetID, 3); + timeActual = timeBase; + Reset(); - timeActual = timeBase; - Reset(); - - //init round - round = 0; - cnt = 0; - //simonn starts - SimonOn = true; - } - } - if (PlayerOn) - { - if ((controlId >= 101) && (controlId <= 104)) - { //which button has clicked ? - if (controlId == 101) Check(0); - if (controlId == 102) Check(1); - if (controlId == 103) Check(2); - if (controlId == 104) Check(3); - } - } - - base.OnClicked(controlId, control, actionType); + //init round + round = 0; + cnt = 0; + //simonn starts + SimonOn = true; + } } + if (PlayerOn) + { + if ((controlId >= 101) && (controlId <= 104)) + { //which button has clicked ? + if (controlId == 101) Check(0); + if (controlId == 102) Check(1); + if (controlId == 103) Check(2); + if (controlId == 104) Check(3); + } + } - protected override void OnShowContextMenu() - { - base.OnShowContextMenu(); - } + base.OnClicked(controlId, control, actionType); + } - private void OnBtnLevel() - { //Choose level for the game - if ((!PlayerOn) && (!SimonOn)) - { - if (Level == "Nor") - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Professional"); - Level = "Pro"; - } - else if (Level == "Pro") - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Amateur"); - Level = "Am"; - } - else - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Normal"); - Level = "Nor"; - } - } - } + protected override void OnShowContextMenu() + { + base.OnShowContextMenu(); + } - private void OnBtnWhatsThis() + private void OnBtnLevel() + { //Choose level for the game + if ((!PlayerOn) && (!SimonOn)) { - GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); - dlg.SetHeading("What's Simon Say (Senso)"); - dlg.SetText("Simon Say is a game where your object is to repeat a code of\n" + - "tones and colors.\n" + - "Level Amateur/Normal/Professional: Speed is increasing\n\n" + - "Gameboard design by Mikael S\xF6derstr\xF6m.\n\n" + - "Remote play with the colored buttons or\n" + - "use 2 - 4 - 6 - 8 or arrow keys.\n\n" + - "Good luck\nMark Koenig (kroko)"); - dlg.DoModal(GetID); + if (Level == "Nor") + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, + MySimon.GUILocalizeStrings.Get(10) + // Level: + MySimon.GUILocalizeStrings.Get(13)); // Professional + Level = "Pro"; + } + else if (Level == "Pro") + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, + MySimon.GUILocalizeStrings.Get(10) + // Level: + MySimon.GUILocalizeStrings.Get(11)); // Amateur + Level = "Am"; + } + else + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, + MySimon.GUILocalizeStrings.Get(10) + // Level: + MySimon.GUILocalizeStrings.Get(12)); // Normal + Level = "Nor"; + } } + } - private void Red() - { // draw red field on - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); - MediaPortal.Util.Utils.PlaySound ("MySimon_c.wav", false, true); - } - private void Blue() - { // draw blue field on - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); - MediaPortal.Util.Utils.PlaySound("MySimon_e.wav", false, true); - } - private void Green() - { // draw green field on - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); - MediaPortal.Util.Utils.PlaySound("MySimon_g.wav", false, true); - } - private void Yellow() - { // draw yellow field on - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); - MediaPortal.Util.Utils.PlaySound("MySimon_a.wav", false, true); - } - private void Error(int errNo) - { // draw correct field on - Reset(); - if (errNo== 0) - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); - if (errNo == 1) - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); - if (errNo == 2) - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); - if (errNo == 3) - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); + private void OnBtnWhatsThis() + { + GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); + dlg.SetHeading(MySimon.GUILocalizeStrings.Get(31)); // help dialog heading + dlg.SetText(MySimon.GUILocalizeStrings.Get(32)); // help dialog text + dlg.DoModal(GetID); + } - MediaPortal.Util.Utils.PlaySound("MySimon_err.wav", false, true); + private void Red() + { // draw red field on + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); + MediaPortal.Util.Utils.PlaySound("MySimon_c.wav", false, true); + } + private void Blue() + { // draw blue field on + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); + MediaPortal.Util.Utils.PlaySound("MySimon_e.wav", false, true); + } + private void Green() + { // draw green field on + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); + MediaPortal.Util.Utils.PlaySound("MySimon_g.wav", false, true); + } + private void Yellow() + { // draw yellow field on + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); + MediaPortal.Util.Utils.PlaySound("MySimon_a.wav", false, true); + } + private void Error(int errNo) + { // draw correct field on + Reset(); + if (errNo == 0) + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_Focus.png"); + if (errNo == 1) + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_Focus.png"); + if (errNo == 2) + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_Focus.png"); + if (errNo == 3) + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_Focus.png"); - // Enable level selection - GUIControl.EnableControl(GetID, 3); - } - private void Reset() - { // draw all fields off - GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_noFocus.png"); - GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_noFocus.png"); - GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_noFocus.png"); - GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_noFocus.png"); - } + MediaPortal.Util.Utils.PlaySound("MySimon_err.wav", false, true); - private void Check(int Button) - { - Reset(); // reset display - timeActual = timeBase; // set time to base + // Enable level selection + GUIControl.EnableControl(GetID, 3); + } + private void Reset() + { // draw all fields off + GUIPropertyManager.SetProperty("#Senso1", "MySimon_Red_noFocus.png"); + GUIPropertyManager.SetProperty("#Senso2", "MySimon_Blue_noFocus.png"); + GUIPropertyManager.SetProperty("#Senso3", "MySimon_Green_noFocus.png"); + GUIPropertyManager.SetProperty("#Senso4", "MySimon_Yellow_noFocus.png"); + } - if (Button == 0) - { //red is pressed - Red(); - } - if (Button == 1) - { //blue is pressed - Blue(); - } - if (Button == 2) - { //green is pressed - Green(); - } - if (Button == 3) - { //yellow is pressed - Yellow(); - } - if (Code[cnt] != Button ) - { //wrong color is pressed - PlayerOn = false; - Error(Code[cnt]); - GUIControl.EnableControl(GetID, 6); // what this - } - else - { // color is correct - cnt++; // next tone - timeActual = 30; // check time for player - if (cnt > round) // last tone reached ? - { - PlayerOn = false; // Simon is now on - SimonOn = true; + private void Check(int Button) + { + Reset(); // reset display + timeActual = timeBase; // set time to base - cnt = 0; // Start with tone 0 - round++; // next Round + if (Button == 0) + { //red is pressed + Red(); + } + if (Button == 1) + { //blue is pressed + Blue(); + } + if (Button == 2) + { //green is pressed + Green(); + } + if (Button == 3) + { //yellow is pressed + Yellow(); + } + if (Code[cnt] != Button) + { //wrong color is pressed + PlayerOn = false; + Error(Code[cnt]); + GUIControl.EnableControl(GetID, 6); // what this + } + else + { // color is correct + cnt++; // next tone + timeActual = 30; // check time for player + if (cnt > round) // last tone reached ? + { + PlayerOn = false; // Simon is now on + SimonOn = true; - if (timeBase >4) // increased difficulty - timeBase--; + cnt = 0; // Start with tone 0 + round++; // next Round - timeWait = 30; // wait a little - timeActual = timeBase; // reset timer - } - } - } + if (timeBase > 4) // increased difficulty + timeBase--; - void _Game_Tick(object sender, EventArgs e) - { //display status of the game - if ((!PlayerOn) && (!SimonOn)) - GUIPropertyManager.SetProperty("#Player", "GAME OVER"); - if (PlayerOn) - GUIPropertyManager.SetProperty("#Player", "PLAYER"); - if (SimonOn) - GUIPropertyManager.SetProperty("#Player", "SIMON"); - //Simon is on and no wait - if ((SimonOn) && (timeWait==0)) - { // just started ? - if (timeBase == timeActual) - { //Display color - if (Code[cnt] == 0) - Red(); - if (Code[cnt] == 1) - Blue(); - if (Code[cnt] == 2) - Green(); - if (Code[cnt] == 3) - Yellow(); - - //Display round - int tmp = round + 1; - GUIPropertyManager.SetProperty("#Round", "Round: " + tmp.ToString() + " "); - } //count timer down - if (timeActual > 0) - timeActual = timeActual - 1; - else - { //if timer is 0 - timeActual = timeBase; - Reset(); - //next tone - if (cnt < round) - cnt++; - else - { //player is next - SimonOn = false; - PlayerOn = true; - // first tone a lot of time - timeActual = 50; - cnt = 0; - } - } - } + timeWait = 30; // wait a little + timeActual = timeBase; // reset timer + } + } + } - if (timeWait > 0) - { //wait timer for little break - timeWait = timeWait - 1; - if (timeWait==timeBase) - Reset(); - } + void _Game_Tick(object sender, EventArgs e) + { //display status of the game + if ((!PlayerOn) && (!SimonOn)) + GUIPropertyManager.SetProperty("#Player", MySimon.GUILocalizeStrings.Get(6)); // GAME OVER + if (PlayerOn) + GUIPropertyManager.SetProperty("#Player", MySimon.GUILocalizeStrings.Get(2)); // PLAYER + if (SimonOn) + GUIPropertyManager.SetProperty("#Player", MySimon.GUILocalizeStrings.Get(3)); // SIMON + //Simon is on and no wait + if ((SimonOn) && (timeWait == 0)) + { // just started ? + if (timeBase == timeActual) + { //Display color + if (Code[cnt] == 0) + Red(); + if (Code[cnt] == 1) + Blue(); + if (Code[cnt] == 2) + Green(); + if (Code[cnt] == 3) + Yellow(); - if (PlayerOn) - { // if player is on count down timer - if (timeActual > 0) - timeActual = timeActual - 1; - else - { //Player wait too long - PlayerOn = false; - Error(Code[cnt]); - GUIControl.EnableControl(GetID, 6); // what this - //Reset(); - } - } - } - } -} + //Display round + int tmp = round + 1; + GUIPropertyManager.SetProperty("#Round", MySimon.GUILocalizeStrings.Get(5) + tmp.ToString()); // Round: + } //count timer down + if (timeActual > 0) + timeActual = timeActual - 1; + else + { //if timer is 0 + timeActual = timeBase; + Reset(); + //next tone + if (cnt < round) + cnt++; + else + { //player is next + SimonOn = false; + PlayerOn = true; + // first tone a lot of time + timeActual = 50; + cnt = 0; + } + } + } + + if (timeWait > 0) + { //wait timer for little break + timeWait = timeWait - 1; + if (timeWait == timeBase) + Reset(); + } + + if (PlayerOn) + { // if player is on count down timer + if (timeActual > 0) + timeActual = timeActual - 1; + else + { //Player wait too long + PlayerOn = false; + Error(Code[cnt]); + GUIControl.EnableControl(GetID, 6); // what this + //Reset(); + } + } + } + } +} \ No newline at end of file Modified: trunk/plugins/MySimon/Source/SimonSay/MySimon.csproj =================================================================== --- trunk/plugins/MySimon/Source/SimonSay/MySimon.csproj 2007-05-24 21:11:19 UTC (rev 436) +++ trunk/plugins/MySimon/Source/SimonSay/MySimon.csproj 2007-05-24 21:16:06 UTC (rev 437) @@ -49,6 +49,7 @@ </Reference> </ItemGroup> <ItemGroup> + <Compile Include="LocalizeStrings.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="MySimon.cs" /> </ItemGroup> Deleted: trunk/plugins/MySimon/Source/SimonSay.suo =================================================================== (Binary files differ) Added: trunk/plugins/MySimon/language/MySimon/strings_de.xml =================================================================== --- trunk/plugins/MySimon/language/MySimon/strings_de.xml (rev 0) +++ trunk/plugins/MySimon/language/MySimon/strings_de.xml 2007-05-24 21:16:06 UTC (rev 437) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<Language name="German" characters="255"> + <Section name="unmapped"> + <String id="0" prefix="Mein ">Simon Say</String> + <String id="1">Neues Spiel</String> + <String id="2">Spieler</String> + <String id="3">SIMON</String> + <String id="5">Runde: </String> + <String id="6">GAME OVER</String> + <String id="10">Stufe: </String> + <String id="11">leicht</String> + <String id="12">mittel</String> + <String id="13">schwer</String> + <String id="31">Was ist Simon Say?</String> + <String id="32">Simon Say is a game where your object is to repeat a code of +tones and colors. +Level Amateur/Normal/Professional: Speed is increasing + +Gameboard design by Mikael Söderström. + +Remote play with the colored buttons or +use 2 - 4 - 6 - 8 or arrow keys. + +Good luck +Mark Koenig (kroko)</String> + </Section> +</Language> \ No newline at end of file Added: trunk/plugins/MySimon/language/MySimon/strings_en.xml =================================================================== --- trunk/plugins/MySimon/language/MySimon/strings_en.xml (rev 0) +++ trunk/plugins/MySimon/language/MySimon/strings_en.xml 2007-05-24 21:16:06 UTC (rev 437) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<Language name="English" characters="255"> + <Section name="unmapped"> + <String id="0" prefix="My ">Simon Say</String> + <String id="1">Start</String> + <String id="2">Player</String> + <String id="3">SIMON</String> + <String id="5">Round: </String> + <String id="6">GAME OVER</String> + <String id="10">Level: </String> + <String id="11">easy</String> + <String id="12">medium</String> + <String id="13">difficult</String> + <String id="31">What's Simon Say</String> + <String id="32">Simon Say is a game where your object is to repeat a code of +tones and colors. +Level Amateur/Normal/Professional: Speed is increasing + +Gameboard design by Mikael Söderström. + +Remote play with the colored buttons or +use 2 - 4 - 6 - 8 or arrow keys. + +Good luck +Mark Koenig (kroko)</String> + </Section> +</Language> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |