Beispiel #1
0
        private void Initialise()
        {
            if (_helper == null)
            {
                width         = 400;
                height        = 500;
                isInteractive = true;
                enabled       = true;

                _helper           = new UIHelper(this);
                _titleBar         = AddUIComponent <UITitleBar>();
                _informationLabel = AddUIComponent <UILabel>();
                _totalPanel       = AddUIComponent <UIPanel>();
                _totalAmountLabel = _totalPanel.AddUIComponent <UILabel>();
                _totalIncomeLabel = _totalPanel.AddUIComponent <UILabel>();
                _costLabel        = _totalPanel.AddUIComponent <UILabel>();
                _incomeLabel      = _totalPanel.AddUIComponent <UILabel>();
                _incentiveList    = UIFastList.Create <UIFastListIncentives>(this);

                _titleBar.Initialise(CimTools.CimToolsHandler.CimToolBase);

                _ticketSlider = _helper.AddSlider("Tickets", 100, 9000, 10, 500, delegate(float value)
                {
                    if (_incentiveList != null)
                    {
                        FastList <object> optionItems = _incentiveList.rowsData;

                        foreach (IncentiveOptionItem optionItemObject in optionItems)
                        {
                            optionItemObject.ticketCount = value;
                            optionItemObject.UpdateTicketSize();
                        }
                    }
                }) as UISlider;

                _startDaySlider = _helper.AddSlider("Days", 0, 7, 1, 0, delegate(float value)
                {
                    CalculateTotal();
                }) as UISlider;

                TimeOfDaySlider startTimeSliderOptions = new TimeOfDaySlider()
                {
                    uniqueName = "Time", value = 12f
                };
                _startTimeSlider = startTimeSliderOptions.Create(_helper) as UISlider;
                _startTimeSlider.eventValueChanged += delegate(UIComponent component, float value)
                {
                    CalculateTotal();
                };

                _createButton = _helper.AddButton("Create", new OnButtonClicked(CreateEvent)) as UIButton;

                CimTools.CimToolsHandler.CimToolBase.Translation.OnLanguageChanged += Translation_OnLanguageChanged;
            }
        }
Beispiel #2
0
        public void CalculateTotal()
        {
            if (_linkedEvent != null && _ticketSlider != null)
            {
                EconomyManager    economyManager = Singleton <EconomyManager> .instance;
                CityEventXmlCosts costs          = _linkedEvent.GetCosts();

                totalCost = 0f;
                maxIncome = 0f;

                totalCost += costs._creation;
                totalCost += _ticketSlider.value * costs._perHead;

                maxIncome += _ticketSlider.value * costs._entry;

                if (_incentiveList != null)
                {
                    FastList <object> optionItems = _incentiveList.rowsData;

                    foreach (IncentiveOptionItem optionItemObject in optionItems)
                    {
                        totalCost += optionItemObject.cost * optionItemObject.sliderValue;
                        maxIncome += optionItemObject.returnCost * optionItemObject.sliderValue;
                    }
                }

                if (_costLabel != null)
                {
                    _costLabel.text   = totalCost.ToString(Settings.moneyFormat, LocaleManager.cultureInfo);
                    _incomeLabel.text = maxIncome.ToString(Settings.moneyFormat, LocaleManager.cultureInfo);
                }

                if (_ticketSlider != null)
                {
                    UIPanel sliderPanel = _ticketSlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_TICKETCOUNT, _ticketSlider.value);
                }

                if (_startTimeSlider != null)
                {
                    UIPanel sliderPanel = _startTimeSlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_STARTTIMESLIDER, TimeOfDaySlider.getTimeFromFloatingValue(_startTimeSlider.value));
                }

                if (_startDaySlider != null)
                {
                    UIPanel sliderPanel = _startDaySlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_STARTDAYSLIDER, _startDaySlider.value);
                }

                if (_createButton != null)
                {
                    int adjustedCost = Mathf.RoundToInt(totalCost * 100f);
                    if (economyManager.PeekResource(EconomyManager.Resource.Construction, adjustedCost) != adjustedCost)
                    {
                        _createButton.Disable();
                    }
                    else
                    {
                        _createButton.Enable();
                    }
                }
            }
        }