Exemplo n.º 1
0
        public List <IFunctionControl> CompileFunctionControlsList(Control parentControl)
        {
            List <IFunctionControl> list = new List <IFunctionControl>();

            foreach (Control control in parentControl.Controls)
            {
                if (control is IFunctionControl)
                {
                    //AFunctionControl func = (AFunctionControl)control;
                    //func.SubscribeToUpdate(this.OnFunctionControlUpdate);
                    list.Add((IFunctionControl)control);
                }

                //recursively add other controls
                //however, don't do this if either disabled or a FlxieFunction
                //Especially the latter because it will definitely contain more
                //controls inside that should not be exposed
                if (control.Controls.Count > 0 && control.Enabled)
                {
                    IFunctionControl con = control as IFunctionControl;
                    if (con == null || con.ParameterType != FuncParamType.MultiParamFunction)
                    {
                        list.AddRange(CompileFunctionControlsList(control));
                    }
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receives input from function controls (after being wired up through the ItemViewManager)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnFunctionControlUpdate(object sender, EventArgs args)
        {
            Saved = false;
            IFunctionControl control = (IFunctionControl)sender;

            if (control.FunctionName == "inherit LIB_STORAGE;")
            {
                Check box  = (Check)sender;
                bool  flag = box.Checked;
                this.SetCanClose.Enabled  = flag;
                this.SetCanLock.Enabled   = flag;
                this.SetClosed.Enabled    = flag;
                this.SetLocked.Enabled    = flag;
                this.SetMaxCarry.Enabled  = flag;
                this.SetKey.Enabled       = flag;
                this.SetInventory.Enabled = flag;
                this.SetOpacity.Enabled   = flag;

                //set the inherit LIB_ITEM control that was added
                //dynamically when the form was created
                if (this.InheritTab.Controls != null && this.InheritContainer.Controls.Count > 0)
                {
                    Check itemLib = this.InheritTab.Controls[0] as Check;
                    itemLib.Checked = (!flag);
                }
            }
        }
Exemplo n.º 3
0
        private bool SearchForControlToDisable(Control parent, string functionName)
        {
            if (parent == null || !parent.HasChildren || parent.Controls == null)
            {
                return(false);
            }

            foreach (Control con in parent.Controls)
            {
                IFunctionControl funcControl = con as IFunctionControl;
                if (funcControl != null && funcControl.FunctionName == functionName)
                {
                    con.Enabled = false;
                    return(true);
                }
                else
                {
                    if (SearchForControlToDisable(con, functionName) == true)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        private void WireEvents(Control parentControl, EventHandler eventHandler)
        {
            foreach (Control control in parentControl.Controls)
            {
                if (control is IFunctionControl)
                {
                    IFunctionControl func = (IFunctionControl)control;
                    func.SubscribeToUpdate(eventHandler);
                }

                //recursively add other controls
                if (control.Controls.Count > 0)
                {
                    WireEvents(control, eventHandler);
                }
            }

            return;
        }
Exemplo n.º 5
0
		public void Init(string functionName,string functionDec,FunctionControlParam[] paramControls)
			{
			if(Initialized) return;
			
			this.Label.Text = functionDec;
			if(paramControls != null)
				{
				foreach(FunctionControlParam param in paramControls)
					{
					#region giant switch that creates each control
					switch(param.ControlType)
						{
						case ControlType.CheckBox:
								{
								ParameterControls.Add(new Stellarmap.Check());
								break;
								}
						case ControlType.CheckList:
								{
								ParameterControls.Add(new CheckList());
								break;
								}
						case ControlType.ListBuilder:
								{
								ParameterControls.Add(new ListBuilder());
								break;
								}
						case ControlType.MapBuilder:
								{
								ParameterControls.Add(new MapBuilder());
								break;
								}
						case ControlType.ComboSelection:
								{
								ParameterControls.Add(new ComboSelection());
								break;
								}
						case ControlType.ComboListBuilder:
								{
								ParameterControls.Add(new ComboListBuilder());
								break;
								}
						case ControlType.ComboMapBuilder:
								{
								ParameterControls.Add(new ComboMapBuilder());
								break;
								}
						case ControlType.DoubleComboMap:
								{
								ParameterControls.Add(new DoubleComboMap());
								break;
								}
						case ControlType.NumberEntry:
								{
								ParameterControls.Add(new NumberEntry());
								break;
								}
						case ControlType.TextEntry:
								{
								ParameterControls.Add(new TextEntry());
								break;
								}
						case ControlType.TextDump:
								{
								ParameterControls.Add(new TextDump());
								break;
								}
						}
					#endregion
					
					if(ParameterControls.Count > 0)
						{
						IFunctionControl newestControl = (IFunctionControl)ParameterControls[ParameterControls.Count - 1];
						newestControl.FunctionName = "butts";//param.ParamName;
						newestControl.LabelText = param.DisplayName;
						newestControl.ParameterType = param.ParamType;
						newestControl.KeyType = param.KeyType;
						newestControl.ValueType = param.ValueType;
						
						if(param.InitValue != null && param.InitValue.Length > 0)
							{
							newestControl.PushEntry(param.InitValue);
							}
						}
					
					}//end foreach
				
				ArrangeParamControls();
				}
			
			FunctionName = functionName;
			Initialized = true;
			return;
			}
Exemplo n.º 6
0
 /// <summary>
 /// Receives input from function controls (after being wired up through the ItemViewManager)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnFunctionControlUpdate(object sender, EventArgs args)
 {
     Saved = false;
     IFunctionControl control = (IFunctionControl)sender;
 }
Exemplo n.º 7
0
        public object CreateControl(Tag c)
        {
            Control control = null;

            //get the list of initial values that a control might have
            List <string> Values      = GetControlValues(c, "");
            List <string> Values2     = GetControlValues(c, "2");
            string        Init        = GetControlInit(c, "");
            string        Init2       = GetControlInit(c, "2");
            string        subType     = "";
            string        displayName = "";
            string        header      = "";
            FuncParamType paramType   = FuncParamType.None;
            EntryType     keyType     = EntryType.NA;
            EntryType     valueType   = EntryType.NA;
            bool          enabled     = true;

            //check if this control has paramtype specified. If not,
            //either it doesn't need one or someone forgot it!
            if (c.Attributes.ContainsKey("paramtype"))
            {
                foreach (Stellarmap.FuncParamType check in Stellarmap.FuncParamTypesList.List)
                {
                    //yeah, the ToLower() was 'cause I was too lazy to
                    //go back and change either the tags or the enums.
                    //Bite me >:B
                    string attribute = c.Attributes["paramtype"].ToLower();
                    string converted = check.ToString().ToLower();
                    if (attribute == converted)
                    {
                        paramType = check;
                        break;
                    }
                }
                //MessageBox.Show("XMLFile: " + c.Attributes["paramtype"] + "\nResult: " + paramType.ToString().ToLower());
            }
            if (c.Attributes.ContainsKey("keytype"))
            {
                foreach (Stellarmap.EntryType check in Stellarmap.EntryTypesList.List)
                {
                    //yeah, the ToLower() was 'cause I was too lazy to
                    //go back and change either the tags or the enums.
                    //Bite me >:B
                    string attribute = c.Attributes["keytype"].ToLower();
                    string converted = check.ToString().ToLower();
                    if (attribute == converted)
                    {
                        keyType = check;
                        break;
                    }
                }
            }
            if (c.Attributes.ContainsKey("valuetype"))
            {
                foreach (Stellarmap.EntryType check in Stellarmap.EntryTypesList.List)
                {
                    //yeah, the ToLower() was 'cause I was too lazy to
                    //go back and change either the tags or the enums.
                    //Bite me >:B
                    string attribute = c.Attributes["valuetype"].ToLower();
                    string converted = check.ToString().ToLower();
                    if (attribute == converted)
                    {
                        valueType = check;
                        break;
                    }
                }
            }
            if (c.Attributes.ContainsKey("enable"))
            {
                if (c.Attributes["enable"] == "false")
                {
                    enabled = false;
                }
            }
            if (c.Attributes.ContainsKey("text"))
            {
                displayName = c.Attributes["text"];
            }
            if (c.Attributes.ContainsKey("subtype"))
            {
                subType = c.Attributes["subtype"];
            }
            if (c.Attributes.ContainsKey("header"))
            {
                header = c.Attributes["header"];
            }


            try {
                //process each control tag
                #region control creation switch
                switch (c.Attributes["type"].ToLower())
                {
                case "checklist":
                {
                    control = new CheckList(displayName, Values.ToArray(), paramType);
                    break;
                }

                case "comboselection":
                {
                    control = new ComboSelection(displayName, Values.ToArray(), Init, paramType);
                    break;
                }

                case "comboselectiontypeable":
                {
                    control = new ComboSelectionTypeable(displayName, Values.ToArray(), Init, paramType);
                    break;
                }

                case "listbuilder":
                {
                    control = new ListBuilder(displayName, paramType);
                    break;
                }

                case "mapbuilder":
                {
                    control = new MapBuilder(displayName);
                    break;
                }

                case "numberentry":
                {
                    decimal     temp = 0;
                    NumberEntry numCon;

                    if (Init != "")
                    {
                        temp = Convert.ToDecimal(Init);
                    }
                    control = new NumberEntry(displayName, temp, 0, 10000);
                    numCon  = control as NumberEntry;
                    if (numCon != null)
                    {
                        if (c.Attributes.ContainsKey("min"))
                        {
                            numCon.EntryMinimum = Convert.ToDecimal(c.Attributes["min"]);
                        }
                        if (c.Attributes.ContainsKey("max"))
                        {
                            numCon.EntryMaxmimum = Convert.ToDecimal(c.Attributes["max"]);
                        }
                        if (c.Attributes.ContainsKey("inc"))
                        {
                            numCon.EntryIncrement = Convert.ToDecimal(c.Attributes["inc"]);
                        }
                        if (c.Attributes.ContainsKey("decimalplaces"))
                        {
                            numCon.DecimalPlaces = Convert.ToInt32(c.Attributes["decimalplaces"]);
                        }
                    }
                    break;
                }

                case "textentry":
                {
                    control = new TextEntry(displayName, Init, paramType);
                    break;
                }

                case "textdump":
                {
                    control = new TextDump(displayName, Init, paramType);
                    break;
                }

                case "checkbox":
                {
                    int  val  = 0;
                    bool temp = false;
                    if (Init != "")
                    {
                        val = Convert.ToInt32(Init);
                        if (val >= 1)
                        {
                            temp = true;
                        }
                        else
                        {
                            temp = false;
                        }
                        //temp = Convert.ToBoolean(Init);
                    }
                    control = new Stellarmap.Check(displayName, temp, paramType, "");
                    break;
                }

                case "combomapbuilder":
                {
                    control = new Stellarmap.ComboMapBuilder(displayName, Values.ToArray(), Init, paramType);
                    break;
                }

                case "rightcombomapbuilder":
                {
                    control = new Stellarmap.RightComboMapBuilder(displayName, Values.ToArray(), Init, paramType);
                    break;
                }

                case "doublecombomapbuilder":
                {
                    control = new Stellarmap.DoubleComboMap(displayName, Values.ToArray(), Values2.ToArray(), Init, Init2, paramType);
                    break;
                }

                case "combolistbuilder":
                {
                    control = new Stellarmap.ComboListBuilder(displayName, Values.ToArray(), Init, paramType);
                    break;
                }

                case "param":
                {
                    break;
                }

                case "multiparam":
                {
                    if (c.Children != null)
                    {
                        List <FunctionControlParam> paramList = new List <FunctionControlParam>();
                        foreach (object obj in CreateControlsList(c.Children))
                        {
                            IFunctionControl funcControl = obj as IFunctionControl;
                            if (funcControl != null)
                            {
                                string init = funcControl.PullEntry();
                                if (init.Length < 1 || init == "({})" || init == "([])" || init == "")
                                {
                                    init = null;
                                }
                                paramList.Add(new FunctionControlParam(funcControl.FunctionName, funcControl.LabelText,
                                                                       funcControl.FunctionControlType, funcControl.ParameterType,
                                                                       funcControl.KeyType, funcControl.ValueType, init));
                            }
                        }

                        control = (Control) new FlexiFunction(displayName, c.Attributes["function"], (List <FunctionControlParam>)paramList);
                    }
                    else
                    {
                        break;
                    }
                    //MessageBox.Show("Failed to load a dynamic control. No support for 'Multiparam' yet.");

                    IFunctionControl func = control as IFunctionControl;
                    if (func != null)
                    {
                        func.FunctionName   = c.Attributes["function"];
                        func.Enabled        = enabled;
                        func.RequiredHeader = header;
                        //TODO: set tool tip here as well
                    }
                    return(control);
                }

                //case "window":
                //    {
                //    break;
                //    }
                case "tab":
                {
                    TabControl tab = new TabControl();
                    tab.Name = displayName;

                    //List<Control> subcons = this.CreateControlsList(c.Children);
                    List <Control> subcons = new List <Control>();
                    foreach (object obj in CreateControlsList(c.Children))
                    {
                        Control c2 = obj as Control;
                        if (c2 != null)
                        {
                            subcons.Add(c2);
                        }
                    }
                    if (subcons != null)
                    {
                        tab.Controls.AddRange(subcons.ToArray());
                    }
                    break;
                }
                }
                #endregion
            }                    //end try

            catch (Stellarmap.InvalidFunctionControlParamException e)
            {
                MessageBox.Show("Could not generate dynamic controls. You hosed one of the xml file's ParamTypes.\n" + e.Message);
                return(null);
            }

            if (control as Control != null)
            {
                IFunctionControl func = control as IFunctionControl;
                if (func != null)
                {
                    func.FunctionName   = c.Attributes["function"];
                    func.Enabled        = enabled;
                    func.RequiredHeader = header;
                    if (keyType != EntryType.NA)
                    {
                        func.KeyType = keyType;
                    }
                    if (valueType != EntryType.NA)
                    {
                        func.ValueType = valueType;
                    }
                    //TODO: set tool tip here as well
                }

                keyType     = EntryType.NA;
                valueType   = EntryType.NA;
                Values      = null;
                Values2     = null;
                Init        = null;
                Init2       = null;
                displayName = "";
                paramType   = FuncParamType.None;
            }

            return(control);
        }