Example #1
0
        private void buttonModify_Click(object sender, System.EventArgs e)
        {
            string str = (string)listBox1.SelectedItem;

            if (str == null)
            {
                return;
            }
            SwitchManager swm    = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
            Switch        sw     = swm[str];
            string        strNew = EditStringForm.DoModal("Modify Switch", "New switch name:", str);

            if (strNew == null)
            {
                return;
            }
            if (strNew != str)
            {
                sw.Name = strNew;
                listBox1.Items.Remove(str);
                int i = listBox1.Items.Add(strNew);
                listBox1.SelectedIndex = i;
                // UNDONE: doc is modified
            }
        }
Example #2
0
        public Switch GetSelectedSwitch()
        {
            if (listBox1.SelectedIndex == -1)
            {
                return(null);
            }
            SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;

            return(swm[(string)listBox1.SelectedItem]);
        }
Example #3
0
        private void buttonDelete_Click(object sender, System.EventArgs e)
        {
            string str = (string)listBox1.SelectedItem;

            if (str == null)
            {
                return;
            }
            SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
            Switch        sw  = swm[str];

            swm.RemoveSwitch(sw);
            listBox1.Items.Remove(str);
            // UNDONE: doc is modified
        }
Example #4
0
        private void buttonNew_Click(object sender, System.EventArgs e)
        {
            string str = EditStringForm.DoModal("New Switch", "New switch name:", null);

            if (str != null)
            {
                SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
                if (swm[str] == null)
                {
                    swm.AddSwitch(new Switch(str));
                    int i = listBox1.Items.Add(str);
                    listBox1.SelectedIndex = i;
                    // UNDONE: doc is modified
                }
            }
        }
Example #5
0
        // ISerializable implemented to prevent events from being serialized
        public LevelDoc(SerializationInfo info, StreamingContext ctx)
            : base((DocTemplate)(((Hashtable)ctx.Context)["DocTemplate"]), (string)(((Hashtable)ctx.Context)["Filename"]))
        {
            s_fLoading = true;
            CaTypeSwitch.InitFixupList();

            Title = info.GetString("Title");
            m_trcBounds.X = info.GetInt32("BoundsX");
            m_trcBounds.Y = info.GetInt32("BoundsY");
            m_trcBounds.Width = info.GetInt32("BoundsWidth");
            m_trcBounds.Height = info.GetInt32("BoundsHeight");

            try {
                // These were introduced at the same time so either they're both present or they both aren't

                m_ctx = info.GetInt32("Width");
                m_cty = info.GetInt32("Height");
            } catch (SerializationException) {
            }

            // Default values in case they aren't present

            m_nPlayersMin = 1;
            m_nPlayersMax = 1;
            try {
                // These were introduced at the same time so either they're both present or they both aren't

                m_nPlayersMin = info.GetInt32("MinPlayers");
                m_nPlayersMax = info.GetInt32("MaxPlayers");
            } catch (SerializationException) {
            }

            // Side info

            try {
                m_asidiDeserializationTemp = (SideInfo[])info.GetValue("SideInfos", typeof(SideInfo[]));
            } catch (SerializationException) {
            }

            // TriggerManager

            try {
                m_tgrm = (TriggerManager)info.GetValue("TriggerManager", typeof(TriggerManager));
            } catch (SerializationException) {
                m_tgrm = new TriggerManager();
            }

            // UnitGroupManager

            try {
                m_ugm = (UnitGroupManager)info.GetValue("UnitGroupManager", typeof(UnitGroupManager));
            } catch (SerializationException) {
                m_ugm = new UnitGroupManager();
            }

            // SwitchManager

            try {
                m_swm = (SwitchManager)info.GetValue("SwitchManager", typeof(SwitchManager));
            } catch (SerializationException) {
                m_swm = new SwitchManager();
            }

            // CounterManager

            try {
                m_ctrm = (CounterManager)info.GetValue("CounterManager", typeof(CounterManager));
            } catch (SerializationException) {
                m_ctrm = new CounterManager();
            }

            // Comment string

            try {
                m_strComment = info.GetString("Comment");
            } catch (SerializationException) {
            }

            // Support old .ld's that have separate .map files

            string strTemplatesFileName = null;
            try {
                string strFile = info.GetString("MapFileName");
                if (strFile != null) {
                    Stream stm = null;
                    try {
                        IFormatter fmtr = new BinaryFormatter();
                        stm = new FileStream(m_strDir + Path.DirectorySeparatorChar + strFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                        strTemplatesFileName = (string)fmtr.Deserialize(stm);
                        SetTemplateDoc((TemplateDoc)DocManager.OpenDocument(m_strDir + Path.DirectorySeparatorChar + strTemplatesFileName));
                        m_alsmi.AddRange((IMapItem[])fmtr.Deserialize(stm));
                        stm.Close();
                    } catch {
                        if (stm != null)
                            stm.Close();
                    }
                }
            } catch(SerializationException) {
            }

            // Load the desired template set

            if (m_tmpd == null) {
                try {
                    strTemplatesFileName = info.GetString("TemplatesFileName");
                    SetTemplateDoc((TemplateDoc)DocManager.OpenDocument(m_strDir + Path.DirectorySeparatorChar + strTemplatesFileName));
                } catch (SerializationException) {
                    // If couldn't load it, use the active one

                    SetTemplateDoc(null);
                    string strT = "Couldn't load " + strTemplatesFileName;
                    if (m_tmpd != null)
                        strT += " - Using " + m_tmpd.GetName();
                    MessageBox.Show(strT);
                }
            }

            // Load the map items

            m_amiDeserializationTemp = (IMapItem[])info.GetValue("MapItems", typeof(IMapItem[]));
        }