Esempio n. 1
0
 /// <summary>called by the 'hardware' to initiate state change</summary>
 protected virtual void OnStateChange(bool down)
 {
     // keyboard in particular creates repeat downs, so ignore if already in this state:
     if (down == m_State)
     {
         return;
     }
     // only one can be selected at a time, record which, and ignore presses of other switches if one is downl
     if (down)
     {
         if (g_SelectedSwitch != null && g_SelectedSwitch != this)
         {
             return;
         }
         g_SelectedSwitch = this;
     }
     else
     {
         if (g_SelectedSwitch == this)
         {
             g_SelectedSwitch = null;
         }
     }
     m_State = down;
     StateChanged?.Invoke(down);
 }
Esempio n. 2
0
 public static void ClearSwitches()
 {
     for (int index = 0; index <= g_Switches.Count - 1; index++)
     {
         g_Switches[index]?.Destroy();
         g_Switches[index] = null;
     }
     g_SelectedSwitch = null;
 }
Esempio n. 3
0
        /// <summary>this is the ONLY correct public way of creating any switch</summary>
        public static void AssignSwitch(int index, Types type, int param)
        {
            if (g_Switches == null)
            {
                throw new InvalidOperationException("Initialise not called on Physical switch");
            }
            if (index < 0 || index > 7)
            {
                throw (new ArgumentException("Switch index should be 0-7"));                 // could be increased, this is just arbitrary sanity limit
            }
            while (g_Switches.Count <= index)
            {
                g_Switches.Add(null);
            }
            if (g_Switches[index] != null)
            {
                if (g_SelectedSwitch == g_Switches[index])
                {
                    g_SelectedSwitch = null;
                }
                g_Switches[index].Destroy();
                g_Switches[index] = null;
            }
            PhysicalSwitch create = null;

            switch (type)
            {
            case Types.Null:                     // leave as nothing
                break;

            case Types.Joystick:
                create = (PhysicalSwitch)JoySwitch.CreateSwitch(param);
                break;

            case Types.Keyboard:
                create = KeySwitch.CreateSwitch((Keys)param);
                break;

            case Types.Pointer:
                create = PointerSwitch.Create(param);
                break;

            default:
                throw new ArgumentException("Invalid switch type: " + type);
            }
            g_Switches[index] = create;
        }
Esempio n. 4
0
        public static void CreateSwitches(Number number, Engine engine)
        {
            Switches = new List <Logical>();
            var switch0 = PhysicalSwitch.Switch(0);

            switch (number)
            {
            case Number.One:
                Switches.Add(new Logical(switch0, engine));
                break;

            case Number.Two:
                var switch1 = PhysicalSwitch.Switch(1);
                if (Globals.Root.CurrentConfig.ReadBoolean(Config.Reverse_Switches) || Globals.Root.CurrentConfig.ReadBoolean(Config.Use_Swap_Switch))
                {                         // feed switches through the swap logic:
                    Switches.Add(new Logical(new LogicalSwapper(switch0, switch1, engine), engine));
                    Switches.Add(new Logical(new LogicalSwapper(switch1, switch0, engine), engine));
                }
                else
                {
                    Switches.Add(new Logical(switch0, engine));
                    Switches.Add(new Logical(switch1, engine));
                }
                break;

            case Number.ShortLong:
                var rising = new LogicalRising(switch0, engine);
                Switches.Add(rising);
                Switches.Add(new LogicalLong(switch0, rising, engine));
                break;

            case Number.DwellOnly:
                Switches.Add(new LogicalDwell(switch0, engine));
                break;

            case Number.PassThrough:
                Switches.Add(new LogicalPassThrough(switch0, engine));
                break;

            default:
                throw (new ArgumentException("Logical.SetSwitches: invalid number"));
            }
        }