Esempio n. 1
0
        // This defines the field
        public void Define(object value)
        {
            //mxd. Don't count as defined when default value is passed
            if (value.ToString() == fieldtype.GetDefaultValue().ToString())
            {
                return;
            }

            // Now defined
            fieldtype.SetValue(value);
            this.Cells[2].Value             = fieldtype.GetStringValue();
            this.DefaultCellStyle.ForeColor = (rowtype == FieldsEditorRowType.USERVAR ? SystemColors.HotTrack : SystemColors.WindowText);
            isdefined = true;
        }
		// Constructor
		internal UniversalFieldInfo(string path, string name, string configname, Configuration cfg, IDictionary<string, EnumList> enums)
		{
			string setting = "universalfields." + path + "." + name;

			// Initialize
			this.name = name.ToLowerInvariant();

			// Read type
			this.type = cfg.ReadSetting(setting + ".type", int.MinValue);
			this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null);

			//mxd. Check type
			if(this.type == int.MinValue)
			{
				General.ErrorLogger.Add(ErrorType.Warning, "No type is defined for universal field \"" + name + "\" defined in \"" + configname + "\". Integer type will be used.");
				this.type = (int)UniversalType.Integer;
			}

			TypeHandler th = General.Types.GetFieldHandler(this);
			if(th is NullHandler)
			{
				General.ErrorLogger.Add(ErrorType.Warning, "Universal field \"" + name + "\" defined in \"" + configname + "\" has unknown type " + this.type + ". String type will be used instead.");
				this.type = (int)UniversalType.String;
				if(this.defaultvalue == null) this.defaultvalue = "";
			}

			//mxd. Default value is missing? Get it from typehandler
			if(this.defaultvalue == null) this.defaultvalue = th.GetDefaultValue();
			
			// Read enum
			object enumsetting = cfg.ReadSettingObject(setting + ".enum", null);
			if(enumsetting != null)
			{
				// Reference to existing enums list?
				if(enumsetting is string)
				{
					// Link to it
					enumlist = enums[enumsetting.ToString()];
				}
				else if(enumsetting is IDictionary)
				{
					// Make list
					enumlist = new EnumList(enumsetting as IDictionary);
				}
			}
			
			// We have no destructor
			GC.SuppressFinalize(this);
		}
Esempio n. 3
0
        //mxd
        public void SetUserVars(Dictionary <string, UniversalType> vars, UniFields fromfields, bool first)
        {
            foreach (KeyValuePair <string, UniversalType> group in vars)
            {
                // Go for all rows
                bool        foundrow = false;
                TypeHandler vartype  = General.Types.GetFieldHandler((int)group.Value, 0);
                object      value    = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue();

                foreach (DataGridViewRow row in fieldslist.Rows)
                {
                    // Row is a field?
                    if (row is FieldsEditorRow)
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        // Row name matches with user var?
                        if (frow.RowType == FieldsEditorRowType.USERVAR && frow.Name == group.Key)
                        {
                            // First time?
                            if (first)
                            {
                                frow.Define(value);
                            }
                            // Check if the value is different
                            else if (!frow.TypeHandler.GetValue().Equals(value))
                            {
                                // Clear the value in the row
                                frow.Define(value);
                                frow.Clear();
                            }

                            // Done
                            foundrow = true;
                            break;
                        }
                    }
                }

                // Row not found?
                if (!foundrow)
                {
                    // Make new row
                    object          defaultvalue = vartype.GetDefaultValue();
                    FieldsEditorRow frow         = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true);
                    if (!value.Equals(defaultvalue))
                    {
                        frow.Define(value);
                    }
                    fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
                }
            }

            // Now check for rows that the givens fields do NOT have
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Don't undefine user var rows defined by other actor types
                    if (frow.RowType == FieldsEditorRowType.USERVAR || vars.ContainsKey(frow.Name))
                    {
                        continue;
                    }

                    // Is this row defined previously?
                    if (frow.IsDefined)
                    {
                        // Check if this row can not be found in the fields at all
                        if (!fromfields.ContainsKey(frow.Name))
                        {
                            // It is not defined in these fields, undefine the value
                            frow.Undefine();
                        }
                    }
                }
            }

            // Sort fields
            Sort();
        }
        // Constructor
        internal UniversalFieldInfo(string path, string name, string configname, Configuration cfg, IDictionary <string, EnumList> enums)
        {
            string setting = "universalfields." + path + "." + name;

            // Initialize
            this.name    = name.ToLowerInvariant();
            associations = new Dictionary <string, UDMFFieldAssociation>();

            // Read type
            this.type         = cfg.ReadSetting(setting + ".type", int.MinValue);
            this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null);

            //mxd. Check type
            if (this.type == int.MinValue)
            {
                General.ErrorLogger.Add(ErrorType.Warning, "No type is defined for universal field \"" + name + "\" defined in \"" + configname + "\". Integer type will be used.");
                this.type = (int)UniversalType.Integer;
            }

            TypeHandler th = General.Types.GetFieldHandler(this);

            if (th is NullHandler)
            {
                General.ErrorLogger.Add(ErrorType.Warning, "Universal field \"" + name + "\" defined in \"" + configname + "\" has unknown type " + this.type + ". String type will be used instead.");
                this.type = (int)UniversalType.String;
                if (this.defaultvalue == null)
                {
                    this.defaultvalue = "";
                }
            }

            //mxd. Default value is missing? Get it from typehandler
            if (this.defaultvalue == null)
            {
                this.defaultvalue = th.GetDefaultValue();
            }

            // Read enum
            object enumsetting = cfg.ReadSettingObject(setting + ".enum", null);

            if (enumsetting != null)
            {
                // Reference to existing enums list?
                if (enumsetting is string)
                {
                    // Link to it
                    enumlist = enums[enumsetting.ToString()];
                }
                else if (enumsetting is IDictionary)
                {
                    // Make list
                    enumlist = new EnumList(enumsetting as IDictionary);
                }
            }

            // Read associations
            IDictionary assocdict = cfg.ReadSetting(setting + ".associations", new Hashtable());

            foreach (DictionaryEntry section in assocdict)
            {
                string property                   = cfg.ReadSetting(setting + ".associations." + section.Key + ".property", string.Empty);
                string modifystr                  = cfg.ReadSetting(setting + ".associations." + section.Key + ".modify", string.Empty);
                bool   nevershoweventlines        = cfg.ReadSetting(setting + ".associations." + section.Key + ".nevershoweventlines", false);
                UDMFFieldAssociationModifier ufam = UDMFFieldAssociationModifier.None;

                if (!string.IsNullOrWhiteSpace(property))
                {
                    switch (modifystr)
                    {
                    case "abs":
                        ufam = UDMFFieldAssociationModifier.Absolute;
                        break;
                    }

                    associations[property] = new UDMFFieldAssociation(property, ufam, nevershoweventlines);
                }
            }

            // We have no destructor
            GC.SuppressFinalize(this);
        }