private TabItem NewIncentiveTab(string title, object content = null) { TabItem tab = new TabItem(); tab.Header = title; tab.Margin = new Thickness(0d); tab.MaxWidth = 85; tab.MinWidth = 85; MenuItem _deleteMenuItem = new MenuItem(); _deleteMenuItem.Header = "Delete this incentive"; _deleteMenuItem.Click += (object sender, RoutedEventArgs e) => { RemoveIncentiveTab(tab); }; ContextMenu _contextMenu = new ContextMenu(); _contextMenu.Items.Add(_deleteMenuItem); tab.ContextMenu = _contextMenu; if (content == null) { IncentiveEditorPanel editor = new IncentiveEditorPanel(new CityEventXmlIncentive(), tab); content = editor; } tab.Content = content; _incentiveTabs.Items.Add(tab); _incentiveTabs.SelectedItem = tab; return(tab); }
public bool ApplyXmlEvent() { bool success = true; _container = new CityEventXmlContainer() { _name = _eventName.Text, _userEventName = _readableName.Text, _eventBuildingClassName = _buildingName.Text, _supportsRandomEvents = _randomEvents.IsChecked.HasValue ? _randomEvents.IsChecked.Value : false, _supportUserEvents = _playerEvents.IsChecked.HasValue ? _playerEvents.IsChecked.Value : false, _canBeWatchedOnTV = _watchedOnTv.IsChecked.HasValue ? _watchedOnTv.IsChecked.Value : false, _initialisedMessages = TearDownText(_initialisedMessages), _beginMessages = TearDownText(_startedMessages), _endedMessages = TearDownText(_endedMessages), _chances = new CityEventXmlChances() { _children = (int)(Math.Round(_children.Value)), _teens = (int)(Math.Round(_teens.Value)), _adults = (int)(Math.Round(_adults.Value)), _seniors = (int)(Math.Round(_seniors.Value)), _lowWealth = (int)(Math.Round(_lowWealth.Value)), _mediumWealth = (int)(Math.Round(_mediumWealth.Value)), _highWealth = (int)(Math.Round(_highWealth.Value)), _uneducated = (int)(Math.Round(_uneducated.Value)), _oneSchool = (int)(Math.Round(_oneSchool.Value)), _twoSchools = (int)(Math.Round(_twoSchools.Value)), _threeSchools = (int)(Math.Round(_threeSchools.Value)), _badHappiness = (int)(Math.Round(_badHappiness.Value)), _poorHappiness = (int)(Math.Round(_poorHappiness.Value)), _goodHappiness = (int)(Math.Round(_goodHappiness.Value)), _excellentHappiness = (int)(Math.Round(_excellentHappiness.Value)), _superbHappiness = (int)(Math.Round(_superbHappiness.Value)), _veryUnhappyWellbeing = (int)(Math.Round(_veryUnhappy.Value)), _unhappyWellbeing = (int)(Math.Round(_unhappy.Value)), _satisfiedWellbeing = (int)(Math.Round(_satisfied.Value)), _happyWellbeing = (int)(Math.Round(_happy.Value)), _veryHappyWellbeing = (int)(Math.Round(_veryHappy.Value)), }, _costs = new CityEventXmlCosts() { }, _incentives = new CityEventXmlIncentive[] { } }; success = success && SafelyConvert.SafelyParseWithError(_capacity.Text, ref _container._eventCapacity, "capacity"); success = success && SafelyConvert.SafelyParseWithError(_length.Text, ref _container._eventLength, "event length"); success = success && SafelyConvert.SafelyParseWithError(_creationCost.Text, ref _container._costs._creation, "creation cost"); success = success && SafelyConvert.SafelyParseWithError(_perHeadCost.Text, ref _container._costs._perHead, "cost per citizen"); success = success && SafelyConvert.SafelyParseWithError(_advertSignCost.Text, ref _container._costs._advertisingSigns, "advertising sign cost"); success = success && SafelyConvert.SafelyParseWithError(_advertTVCost.Text, ref _container._costs._advertisingTV, "advertising TV cost"); success = success && SafelyConvert.SafelyParseWithError(_entryCost.Text, ref _container._costs._entry, "ticket cost"); List <CityEventXmlIncentive> incentiveList = new List <CityEventXmlIncentive>(); foreach (TabItem tab in _incentiveTabs.Items) { IncentiveEditorPanel editor = tab.Content as IncentiveEditorPanel; if (editor != null) { success = success && editor.ApplyUserEvent(); if (success) { incentiveList.Add(editor._incentive); } } } _container._incentives = incentiveList.ToArray(); return(success); }
public void LoadXmlEvent() { if (_container != null) { _eventName.Text = _container._name; _readableName.Text = _container._userEventName; _buildingName.Text = _container._eventBuildingClassName; _capacity.Text = _container._eventCapacity.ToString(); _length.Text = _container._eventLength.ToString(); _randomEvents.IsChecked = _container._supportsRandomEvents; _playerEvents.IsChecked = _container._supportUserEvents; _watchedOnTv.IsChecked = _container._canBeWatchedOnTV; SetUpText(_container._initialisedMessages, _initialisedMessages); SetUpText(_container._beginMessages, _startedMessages); SetUpText(_container._endedMessages, _endedMessages); if (_container._chances != null) { _males.Value = _container._chances._males; _females.Value = _container._chances._females; _children.Value = _container._chances._children; _teens.Value = _container._chances._teens; _adults.Value = _container._chances._adults; _seniors.Value = _container._chances._seniors; _lowWealth.Value = _container._chances._lowWealth; _mediumWealth.Value = _container._chances._mediumWealth; _highWealth.Value = _container._chances._highWealth; _uneducated.Value = _container._chances._uneducated; _oneSchool.Value = _container._chances._oneSchool; _twoSchools.Value = _container._chances._twoSchools; _threeSchools.Value = _container._chances._threeSchools; _badHappiness.Value = _container._chances._badHappiness; _poorHappiness.Value = _container._chances._poorHappiness; _goodHappiness.Value = _container._chances._goodHappiness; _excellentHappiness.Value = _container._chances._excellentHappiness; _superbHappiness.Value = _container._chances._superbHappiness; _veryUnhappy.Value = _container._chances._veryUnhappyWellbeing; _unhappy.Value = _container._chances._unhappyWellbeing; _satisfied.Value = _container._chances._satisfiedWellbeing; _happy.Value = _container._chances._happyWellbeing; _veryHappy.Value = _container._chances._veryHappyWellbeing; } if (_container._costs != null) { _creationCost.Text = _container._costs._creation.ToString(); _perHeadCost.Text = _container._costs._perHead.ToString(); _advertSignCost.Text = _container._costs._advertisingSigns.ToString(); _advertTVCost.Text = _container._costs._advertisingTV.ToString(); _entryCost.Text = _container._costs._entry.ToString(); } if (_container._incentives != null) { _incentiveTabs.Items.Clear(); foreach (CityEventXmlIncentive incentive in _container._incentives) { IncentiveEditorPanel editor = new IncentiveEditorPanel(incentive); TabItem createdTab = NewIncentiveTab(incentive._name, editor); editor.ParentTab = createdTab; } } } _playerEvents_Checked(this, new RoutedEventArgs()); }