/// <summary>Создаёт новый экземпляр класса <see cref="MenuItem"/>. </summary> public MenuItem(XmlNode Node,MenuItem Parent,SourceryGame game) { _Node = Node; _Parent = Parent; _Name = _Node.SelectSingleNode("Name").InnerText; _Description = _Node.SelectSingleNode("Description").InnerText; _Position = Convert.ToInt32(_Node.SelectSingleNode("Position").InnerText); Values = new List<string>(); var val = _Node.SelectSingleNode("Values"); if (val != null) { var nodeSelection = val.SelectNodes("Value"); foreach (XmlNode node in nodeSelection) Values.Add(node.InnerText); } var type = _Node.SelectSingleNode("Action").InnerText; _Action = (ActionType)Enum.Parse(typeof(ActionType), type); var controltype = _Node.SelectSingleNode("Type").InnerText; _ControlType = (ControlType)Enum.Parse(typeof(ControlType), controltype); switch (_ControlType) { case ControlType.Button: { ItemControl = new Button(game, _Name); break; } case ControlType.CheckBox: { ItemControl = new CheckBox(game, _Name); break; } case ControlType.ComboBox: { ItemControl = new ComboBox(game, Values); break; } case ControlType.TrackBar: { ItemControl = new TrackBar(game,_Name); break; } } ItemControl.OnValueChanged += OnControlChanged; var selection = _Node.SelectNodes("Item"); if (selection != null && selection.Count > 0) { Items = new List<MenuItem>(); foreach (XmlNode node in selection) Items.Add(new MenuItem(node,this,game)); } }
/// <summary> /// Совершаем действие предусмотренное элементом /// </summary> /// <param name="item">Элемент</param> public void DoAction(MenuItem item) { switch (item.Action) { case ActionType.SubMenu: { LoadSettings(item.Items); _CurrentMenu = item.Items; if (item.Name == "Звук") _Delay = 2; _Delay = 15; break; } case ActionType.PreviousMenu: { _Delay = 15; if (item.Parent.Parent != null) { LoadSettings(item.Parent.Parent.Items); _CurrentMenu = item.Parent.Parent.Items; } else { LoadSettings(_Menu.Items); _CurrentMenu = _Menu.Items; } break; } case ActionType.ReturnToGame: { _Parent.CloseSettings(); break; } case ActionType.LeaveToSystem: { _CurrentDialog = new Dialog(_Game,"Вы дейтсвительно хотите выйти из системы?"); _CurrentDialog.OnDialogClose += OnLeaveToSystem; break; } case ActionType.Leave: { _Game.ChangeScreen(ScreenType.TitleScreen); break; } } }
/// <summary> /// Выполняем действие /// </summary> /// <param name="item">Элемент</param> private void DoAction(MenuItem item) { switch (item.Action) { case ActionType.NewGame: { _CurrentPanel = new NewGamePanel(_Game); break; } case ActionType.Load: { _CurrentPanel = new SaveLoadPanel(_Game, false); break; } case ActionType.Save: { _CurrentPanel = new SaveLoadPanel(_Game, true); break; } case ActionType.SubMenu: { ReloadMenu(item.Items); _CurrentMenu = item.Items; _CurrentPanel = null; _Delay = 15; break; } case ActionType.PreviousMenu: { if (item.Parent.Parent != null) { ReloadMenu(item.Parent.Parent.Items); _CurrentMenu = item.Parent.Parent.Items; } else { ReloadMenu(_Menu.Items); _CurrentMenu = _Menu.Items; } _CurrentPanel = null; break; } case ActionType.Help: { _CurrentPanel = new HelpPanel(_Game); break; } case ActionType.exit: { _Game.CloseGame(); break; } } }