Пример #1
0
        public void OnSaveData()
        {
            try
            {
                byte[] data;

                using (var stream = new MemoryStream())
                {
                    EnhancedDisastersManager edm = Singleton <EnhancedDisastersManager> .instance;

                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new DisastersContainer.Data());

                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedForestFire.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedThunderstorm.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedSinkhole.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedTsunami.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedTornado.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedEarthquake.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedMeteorStrike.Data());
                    data = stream.ToArray();
                }

                serializableData.SaveData(DataID, data);
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "(save error) " + ex.Message);
            }
        }
        public override void Update()
        {
            base.Update();

            if (!isVisible)
            {
                return;
            }

            if (--Counter > 0)
            {
                return;
            }
            Counter = 10;

            EnhancedDisastersManager edm = Singleton <EnhancedDisastersManager> .instance;
            int disasterCount            = edm.container.AllDisasters.Count;

            for (int i = 0; i < disasterCount; i++)
            {
                EnhancedDisaster d            = edm.container.AllDisasters[i];
                float            p            = d.GetCurrentOccurrencePerYear();
                byte             maxIntensity = d.GetMaximumIntensity();
                if (d.Enabled)
                {
                    labels[i].text = string.Format(labelFormat, d.GetName(), p, maxIntensity);

                    progressBars_probability[i].value = getProgressValueLog(p);
                    setProgressBarColor(progressBars_probability[i]);
                    progressBars_probability[i].tooltip = d.GetProbabilityTooltip();

                    progressBars_maxIntensity[i].value = maxIntensity * 0.01f;
                    setProgressBarColor(progressBars_maxIntensity[i]);
                    progressBars_maxIntensity[i].tooltip = d.GetIntensityTooltip();
                }
                else
                {
                    labels[i].text = "Disabled";

                    progressBars_probability[i].value         = 0;
                    progressBars_probability[i].progressColor = Color.black;

                    progressBars_maxIntensity[i].value         = 0;
                    progressBars_maxIntensity[i].progressColor = Color.black;
                }
            }
        }
        protected void startDisaster(byte intensity)
        {
            DisasterInfo disasterInfo = EnhancedDisastersManager.GetDisasterInfo(DType);

            if (disasterInfo == null)
            {
                return;
            }

            Vector3 targetPosition;
            float   angle;
            bool    targetFound = findTarget(disasterInfo, out targetPosition, out angle);

            if (!targetFound)
            {
                DebugLogger.Log(getDebugStr() + "target not found");
                return;
            }

            DisasterManager dm = Singleton <DisasterManager> .instance;

            ushort disasterIndex;
            bool   disasterCreated = dm.CreateDisaster(out disasterIndex, disasterInfo);

            if (!disasterCreated)
            {
                DebugLogger.Log(getDebugStr() + "could not create disaster");
                return;
            }

            DisasterLogger.StartedByMod = true;

            disasterStarting(disasterInfo);

            dm.m_disasters.m_buffer[(int)disasterIndex].m_targetPosition = targetPosition;
            dm.m_disasters.m_buffer[(int)disasterIndex].m_angle          = angle;
            dm.m_disasters.m_buffer[(int)disasterIndex].m_intensity      = intensity;
            DisasterData[] expr_98_cp_0 = dm.m_disasters.m_buffer;
            ushort         expr_98_cp_1 = disasterIndex;

            expr_98_cp_0[(int)expr_98_cp_1].m_flags = (expr_98_cp_0[(int)expr_98_cp_1].m_flags | DisasterData.Flags.SelfTrigger);
            disasterInfo.m_disasterAI.StartNow(disasterIndex, ref dm.m_disasters.m_buffer[(int)disasterIndex]);

            DebugLogger.Log(getDebugStr() + string.Format("disaster intensity: {0}, area: {1}", intensity, unlocked ? OccurrenceAreaAfterUnlock : OccurrenceAreaBeforeUnlock));
        }
        public override void Start()
        {
            base.Start();

            UILabel lTitle = this.AddUIComponent <UILabel>();

            lTitle.position = new Vector3(10, -15);
            lTitle.text     = "Disasters info";

            int y = -50;
            int h = -20;

            addAxisTitle(200, y, "Probability");
            addAxisTitle(300, y, "Max intensity");
            y -= 15;

            addAxisLabel(200, y, "0.1");
            addAxisLabel(240, y, "1");
            addAxisLabel(275, y, "10");
            addAxisLabel(300, y, "1");
            addAxisLabel(375, y, "10");
            y -= 15;

            int disasterCount = Singleton <EnhancedDisastersManager> .instance.container.AllDisasters.Count;

            labels = new UILabel[disasterCount];
            progressBars_probability  = new UIProgressBar[disasterCount];
            progressBars_maxIntensity = new UIProgressBar[disasterCount];

            EnhancedDisastersManager edm = Singleton <EnhancedDisastersManager> .instance;

            for (int i = 0; i < disasterCount; i++)
            {
                EnhancedDisaster d = edm.container.AllDisasters[i];
                labels[i]      = addLabel(10, y);
                labels[i].text = string.Format(labelFormat, d.GetName(), 0, 0);
                progressBars_probability[i]  = addProgressBar(200, y);
                progressBars_maxIntensity[i] = addProgressBar(300, y);
                y += h;
            }

            UIButton bigRedBtn = this.AddUIComponent <UIButton>();

            bigRedBtn.name     = "bigRedBtn";
            bigRedBtn.position = new Vector3(10, -height + 30);
            bigRedBtn.size     = new Vector2(22, 22);
            //bigRedBtn.color = Color.red;
            bigRedBtn.focusedColor     = Color.red;
            bigRedBtn.textColor        = Color.red;
            bigRedBtn.focusedTextColor = Color.red;
            bigRedBtn.text             = "■";
            bigRedBtn.normalBgSprite   = "ButtonMenu";
            bigRedBtn.hoveredBgSprite  = "ButtonMenuHovered";
            bigRedBtn.eventClick      += BigRedBtn_eventClick;

            UILabel bigRedBtnLabel = this.AddUIComponent <UILabel>();

            bigRedBtnLabel.name      = "bigRedBtnLabel";
            bigRedBtnLabel.position  = new Vector3(40, -height + 27);
            bigRedBtnLabel.size      = new Vector2(width - 30, 20);
            bigRedBtnLabel.textColor = Color.white;
            //bigRedBtnLabel.textScale = 0.7f;
            bigRedBtnLabel.text = "← Emergency Button (stop all disasters)";

            UIButton btn = this.AddUIComponent <UIButton>();

            btn.position       = new Vector3(365, -5);
            btn.size           = new Vector2(30, 30);
            btn.normalFgSprite = "buttonclose";
            btn.eventClick    += Btn_eventClick;
        }