Пример #1
0
        public static StringBuilder AppendInputBind(this StringBuilder sb, MyStringId controlId)
        {
            IMyControl control = MyAPIGateway.Input.GetGameControl(controlId);

            if (control == null)
            {
                return(sb.Append("<Unknown:").Append(controlId.String).Append(">"));
            }

            string mouse = control.GetControlButtonName(MyGuiInputDeviceEnum.Mouse);

            if (!string.IsNullOrEmpty(mouse))
            {
                return(sb.Append(mouse));
            }

            string key = control.GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);

            if (string.IsNullOrEmpty(key))
            {
                key = control.GetControlButtonName(MyGuiInputDeviceEnum.KeyboardSecond);
            }
            if (!string.IsNullOrEmpty(key))
            {
                return(sb.Append(key));
            }

            return(sb.Append("<").Append(control.GetControlName().String).Append(">"));
        }
Пример #2
0
        private static string GetControlAssignedName(IMyControl control)
        {
            var assign = control.GetControlButtonName(MyGuiInputDeviceEnum.Mouse);

            if (!string.IsNullOrWhiteSpace(assign))
            {
                return(assign);
            }

            assign = control.GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);

            if (!string.IsNullOrWhiteSpace(assign))
            {
                return(assign);
            }

            assign = control.GetControlButtonName(MyGuiInputDeviceEnum.KeyboardSecond);

            if (!string.IsNullOrWhiteSpace(assign))
            {
                return(assign);
            }

            return("(unassigned)");
        }
Пример #3
0
        public void InsertRow()
        {
            IFreeForm dw = (IFreeForm)Assembly.Load("BaseData").CreateInstance("Redsoft." + dataObject);

            if (this.Controls.Count == 0)
            {
                this.Controls.Add(dw.GetPanel);
                foreach (Control c in this.Controls[0].Controls)
                {
                    c.TextChanged += new EventHandler(c_TextChanged);
                }
            }

            for (int i = 0; i < this.Controls[0].Controls.Count; i++)
            {
                string controlName = this.Controls[0].Controls[i].Name;

                IMyControl mycontrol = this.Controls[0].Controls[i] as IMyControl;
                if (mycontrol != null)
                {
                    mycontrol.OldText = "";
                    mycontrol.SetText("");

                    //设置一些默认字段
                    if (controlName == "collrsj")
                    {
                        mycontrol.SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }
            rowState = RowStatus.Add;
        }
Пример #4
0
        public void FocusOn(IMyControl control)
        {
            if (Controls.IndexOf(control) != m_focusedControl)
            {
                if (m_focusedControl != -1)
                {
                    Controls[m_focusedControl].LostFocus();
                }

                m_focusedControl = Controls.IndexOf(control);
                control.GotFocus();
            }
        }
Пример #5
0
        /// <summary>
        /// Reads the bound button or key from the given control to bypass control blocking.
        /// </summary>
        public static bool IsControlPressedIgnoreBlock(MyStringId controlId, bool newPress = false)
        {
            IMyControl control = MyAPIGateway.Input.GetGameControl(controlId);

            // WARNING: IsKeyPress(MyKeys.None) returns true for some people!

            if (newPress)
            {
                MyMouseButtonsEnum button = control.GetMouseControl();
                if (button != MyMouseButtonsEnum.None && MyAPIGateway.Input.IsNewMousePressed(button))
                {
                    return(true);
                }

                MyKeys kb1 = control.GetKeyboardControl();
                if (kb1 != MyKeys.None && MyAPIGateway.Input.IsNewKeyPressed(kb1))
                {
                    return(true);
                }

                MyKeys kb2 = control.GetSecondKeyboardControl();
                if (kb2 != MyKeys.None && MyAPIGateway.Input.IsNewKeyPressed(kb2))
                {
                    return(true);
                }
            }
            else
            {
                MyMouseButtonsEnum button = control.GetMouseControl();
                if (button != MyMouseButtonsEnum.None && MyAPIGateway.Input.IsMousePressed(button))
                {
                    return(true);
                }

                MyKeys kb1 = control.GetKeyboardControl();
                if (kb1 != MyKeys.None && MyAPIGateway.Input.IsKeyPress(kb1))
                {
                    return(true);
                }

                MyKeys kb2 = control.GetSecondKeyboardControl();
                if (kb2 != MyKeys.None && MyAPIGateway.Input.IsKeyPress(kb2))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        public static string GetAssignedGameControlNames(IMyControl control)
        {
            var inputs = new List<string>();

            if(control.GetMouseControl() != MyMouseButtonsEnum.None)
                inputs.Add(Input.GetName(control.GetMouseControl()));

            if(control.GetKeyboardControl() != MyKeys.None)
                inputs.Add(Input.GetKeyName(control.GetKeyboardControl()));

            if(control.GetSecondKeyboardControl() != MyKeys.None)
                inputs.Add(Input.GetKeyName(control.GetSecondKeyboardControl()));

            return (inputs.Count == 0 ? Input.GetUnassignedName() : string.Join(" or ", inputs));
        }
Пример #7
0
        public static string GetAssignedGameControlNames(IMyControl control, bool oneResult = false)
        {
            List <string> inputs = (oneResult ? null : new List <string>());

            if (control.GetMouseControl() != MyMouseButtonsEnum.None)
            {
                string name = Input.GetName(control.GetMouseControl());

                if (oneResult)
                {
                    return(name);
                }
                else
                {
                    inputs.Add(name);
                }
            }

            if (control.GetKeyboardControl() != MyKeys.None)
            {
                string name = Input.GetKeyName(control.GetKeyboardControl());

                if (oneResult)
                {
                    return(name);
                }
                else
                {
                    inputs.Add(name);
                }
            }

            if (control.GetSecondKeyboardControl() != MyKeys.None)
            {
                string name = Input.GetKeyName(control.GetSecondKeyboardControl());

                if (oneResult)
                {
                    return(name);
                }
                else
                {
                    inputs.Add(name);
                }
            }

            return(oneResult || inputs.Count == 0 ? "{Unassigned:" + control.GetControlName() + "}" : string.Join(" or ", inputs));
        }
Пример #8
0
        public string GetFriendlyString(bool xboxChars = true)
        {
            List <string> combined = new List <string>();

            foreach (object o in combination)
            {
                if (o is MyStringId)
                {
                    IMyControl control = MyAPIGateway.Input.GetGameControl((MyStringId)o);

                    if (control.GetMouseControl() != MyMouseButtonsEnum.None)
                    {
                        combined.Add(InputHandler.inputNames[control.GetMouseControl()]);
                    }
                    else if (control.GetKeyboardControl() != MyKeys.None)
                    {
                        combined.Add(InputHandler.inputNames[control.GetKeyboardControl()]);
                    }
                    else if (control.GetSecondKeyboardControl() != MyKeys.None)
                    {
                        combined.Add(InputHandler.inputNames[control.GetSecondKeyboardControl()]);
                    }
                    else
                    {
                        combined.Add(InputHandler.inputNames[control]);
                    }
                }
                else if (xboxChars && (o is MyJoystickAxesEnum || o is MyJoystickButtonsEnum))
                {
                    char c = InputHandler.xboxCodes.GetValueOrDefault(o, ' ');
                    combined.Add(c == ' ' ? InputHandler.inputNames[o] : c.ToString());
                }
                else
                {
                    combined.Add(InputHandler.inputNames[o]);
                }
            }

            return(String.Join(" ", combined));
        }
Пример #9
0
 public static void GetUIValue(MAction action, Control panel1, RowStatus rowState)
 {
     for (int i = 0; i < panel1.Controls.Count; i++)
     {
         IMyControl mc = panel1.Controls[i] as IMyControl;
         if (mc != null)
         {
             string text = mc.GetText();
             if (rowState == RowStatus.Add)
             {
                 if (text != "")
                 {
                     action.Set(panel1.Controls[i].Name, text);
                 }
             }
             else
             {
                 action.Set(panel1.Controls[i].Name, text);
             }
         }
     }
 }
Пример #10
0
        public static string GetFriendlyStringForControl(IMyControl control)
        {
            tmp.Clear();

            if (control.GetKeyboardControl() != MyKeys.None)
            {
                if (tmp.Length > 0)
                {
                    tmp.Append(" or ");
                }

                string def = control.GetKeyboardControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetKeyboardControl(), def), def));
            }

            if (control.GetMouseControl() != MyMouseButtonsEnum.None)
            {
                string def = control.GetMouseControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetMouseControl(), def), def));
            }
            else if (control.GetSecondKeyboardControl() != MyKeys.None)
            {
                if (tmp.Length > 0)
                {
                    tmp.Append(" or ");
                }

                string def = control.GetSecondKeyboardControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetSecondKeyboardControl(), def), def));
            }

            string val = tmp.ToString();

            tmp.Clear();
            return(val);
        }
Пример #11
0
        public static string GetFriendlyStringForControl(IMyControl control)
        {
            tmp.Clear();

            if(control.GetKeyboardControl() != MyKeys.None)
            {
                if(tmp.Length > 0)
                    tmp.Append(" or ");

                var def = control.GetKeyboardControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetKeyboardControl(), def), def));
            }

            if(control.GetMouseControl() != MyMouseButtonsEnum.None)
            {
                var def = control.GetMouseControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetMouseControl(), def), def));
            }
            else if(control.GetSecondKeyboardControl() != MyKeys.None)
            {
                if(tmp.Length > 0)
                    tmp.Append(" or ");

                var def = control.GetSecondKeyboardControl().ToString();
                tmp.Append(inputNiceNames.GetValueOrDefault(inputNames.GetValueOrDefault(control.GetSecondKeyboardControl(), def), def));
            }

            var val = tmp.ToString();
            tmp.Clear();
            return val;
        }
Пример #12
0
 public static void SetIconsColor(IMyControl control)
 {
     _colorBase.SetIconsColor(control);
 }
Пример #13
0
        public static string CheckValid(MAction action, Control panel1, RowStatus rowState, ErrorProvider ep)
        {
            if (ep != null)
            {
                ep.Clear();
            }
            for (int i = 0; i < panel1.Controls.Count; i++)
            {
                IMyControl mc = panel1.Controls[i] as IMyControl;
                if (mc != null)
                {
                    if (panel1.Controls[i].Visible)
                    {
                        if (!action.Data[panel1.Controls[i].Name].Struct.IsCanNull &&
                            mc.GetText() == "")
                        {
                            mc.SetInValid();
                            if (ep != null)
                            {
                                ep.SetError(panel1.Controls[i], "不能为空");
                            }

                            return("不能为空");
                        }
                        SqlDbType dbtype = action.Data[panel1.Controls[i].Name].Struct.SqlType;
                        if (dbtype == SqlDbType.Decimal ||
                            dbtype == SqlDbType.Float ||
                            dbtype == SqlDbType.Int ||
                            dbtype == SqlDbType.Money ||
                            dbtype == SqlDbType.Real ||
                            dbtype == SqlDbType.SmallInt ||
                            dbtype == SqlDbType.SmallMoney ||
                            dbtype == SqlDbType.TinyInt)
                        {
                            double d = 0;
                            if (mc.GetText() != "" && !double.TryParse(mc.GetText(), out d))
                            {
                                if (ep != null)
                                {
                                    ep.SetError(panel1.Controls[i], "不能转化为数字");
                                }
                                return("不能转化为数字");
                            }
                        }
                        if (dbtype == SqlDbType.DateTime ||
                            dbtype == SqlDbType.DateTime2 ||
                            dbtype == SqlDbType.Date ||
                            dbtype == SqlDbType.SmallDateTime)
                        {
                            DateTime dt = DateTime.MinValue;
                            if (mc.GetText() != "" && !DateTime.TryParse(mc.GetText(), out dt))
                            {
                                if (ep != null)
                                {
                                    ep.SetError(panel1.Controls[i], "不能转化为日期");
                                }
                                return("不能转化为日期");
                            }
                        }
                    }
                }
            }

            return("");
        }
Пример #14
0
 public virtual void SetPrimaryMoreLightColor(IMyControl control)
 {
     control.SetColor(PrimaryMoreLightColor);
 }
Пример #15
0
 public virtual void SetPrimaryDarkColor(IMyControl control)
 {
     control.SetColor(PrimaryDark);
 }
Пример #16
0
 public virtual void SetIconsColor(IMyControl control)
 {
     control.SetColor(Icons);
     control.SetTextColor(IconsTextColor);
 }
Пример #17
0
 public static void SetPrimaryDarkColor(IMyControl control)
 {
     _colorBase.SetPrimaryDarkColor(control);
 }
Пример #18
0
 public static void SetPrimaryMoreLightColor(IMyControl control)
 {
     _colorBase.SetPrimaryMoreLightColor(control);
 }