Beispiel #1
0
 void Start()
 {
     _rb          = GetComponent <Rigidbody>();
     _dingSound   = GetComponent <AudioSource>();
     _timer       = GameObject.Find("Timer").GetComponent <Timer>();
     _score       = GameObject.Find("Score").GetComponent <Score>();
     _keys        = FindObjectsOfType <GameObject>().Where(obj => obj.name == "Key").ToArray();
     _selectedKey = _keys[Random.Range(0, _keys.Length)].GetComponent <KeyCap>();
     _selectedKey.SelectKey();
 }
Beispiel #2
0
        // Draw the on-screen keyboard.  This draws a highlight rectangle
        // around each pressed key.
        private void kbPic_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            using (Pen pen = new Pen(Color.Red, 4))
            {
                int x = 0, y = 0;
                foreach (uint vk in keysDown.Keys)
                {
                    if (vkeyCaps.ContainsKey(vk))
                    {
                        KeyCap kc = vkeyCaps[vk];
                        g.DrawRectangle(pen, x + kc.x * kbPicScale, y + kc.y * kbPicScale,
                                        kc.wid * kbPicScale + 4, kc.ht * kbPicScale + 4);
                    }
                }
            }
        }
Beispiel #3
0
        void InitKeyCap(
            Dictionary <int, KeyCap> dict, int usbkey, uint vkey, String name,
            int x, int y, int wid, int ht, int cx, int cy, int cwid, int cht)
        {
            // create the key cap and add it to the dictionary for the device key code mapping
            KeyCap kc = new KeyCap(usbkey, vkey, name, x, y, wid, ht, cx, cy, cwid, cht);

            dict.Add(usbkey, kc);

            // If it's not already in the Windows vkey mapping dictionary, add it.  Note that
            // some keys have device mappings in both the regular keyboard keys and media keys,
            // but the Windows vkey system unifies them both in one namespace, so we only need
            // one version of the key cap for the Windows mapping.
            if (!vkeyCaps.ContainsKey(vkey))
            {
                vkeyCaps.Add(vkey, kc);
            }
        }
Beispiel #4
0
 void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.name == "DeathPlane")
     {
         _rb.velocity       = Vector3.zero;
         transform.position = resetPos;
         _timer.AddTime(-2);
     }
     else if (collision.collider.CompareTag("Goal"))
     {
         _dingSound.Play(0);
         _timer.AddTime(4);
         _score.AddScore(1);
         _selectedKey.DeselectKey();
         _selectedKey = _keys[Random.Range(0, _keys.Length)].GetComponent <KeyCap>();
         _selectedKey.SelectKey();
     }
 }
        void keyCap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            KeyCap         keyCap = sender as KeyCap;
            ContentControl cc     = keyCap.LayoutRoot.Children[0] as ContentControl;
            //데이터 셋팅
            KeyCapEventArgs keyCapEventArgs = GetKeyCapEventArgs(keyCap);

            //키데이터 셋팅

            if (keyCap.KeyCapType == KeyCapTypes.Symbol)
            {
                OnSymbolKeyCapTap(keyCapEventArgs);
            }
            else if (keyCap.KeyCapType == KeyCapTypes.Language)
            {
                OnLanguageKeyCapTap(keyCapEventArgs);
            }
        }
        private KeyCapEventArgs GetKeyCapEventArgs(KeyCap keyCap)
        {
            KeyCapEventArgs keyCapEventArgs = new KeyCapEventArgs()
            {
                ImeKey     = keyCap.KeyCapType == KeyCapTypes.Language ? this.LanguageKeyboard.OriginalKeyboardLayoutType : this.OriginalKeyboardLayoutType,
                KeyCapType = keyCap.KeyCapType,
                KeyCode    = keyCap.KeyCode
            };

            foreach (Grid grd in this.Children)
            {
                foreach (KeyCap kc in grd.Children)
                {
                    if (kc.LayoutRoot.Children[0] is ToggleButton)
                    {
                        ToggleButton tb = kc.LayoutRoot.Children[0] as ToggleButton;
                        switch (kc.KeyCapType)
                        {
                        case KeyCapTypes.Shift:
                            keyCapEventArgs.IsShiftKey = (bool)tb.IsChecked;
                            break;

                        case KeyCapTypes.Control:
                            keyCapEventArgs.IsControlKey = (bool)tb.IsChecked;
                            break;

                        case KeyCapTypes.Alt:
                            keyCapEventArgs.IsAltKey = (bool)tb.IsChecked;
                            break;

                        case KeyCapTypes.Window:
                            keyCapEventArgs.IsWindowKey = (bool)tb.IsChecked;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(keyCapEventArgs);
        }
        void keyCap_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            KeyCap         keyCap = sender as KeyCap;
            ContentControl cc     = keyCap.LayoutRoot.Children[0] as ContentControl;
            //데이터 셋팅
            KeyCapEventArgs keyCapEventArgs = GetKeyCapEventArgs(keyCap);

            //릴리즈 데이터
            keyCapEventArgs.KeyCode = 0;
            //키데이터 셋팅

            if (cc is Button)
            {
                OnKeyCapReleased(keyCapEventArgs);
            }
            else if (cc is ToggleButton && (cc as ToggleButton).IsChecked == false)
            {
                if (keyCap.KeyCapType == KeyCapTypes.Function)
                {
                    OnFunctionKeyCapUnchecked(keyCapEventArgs);
                }
                else
                {
                    OnKeyCapUnchecked(keyCapEventArgs);

                    if (keyCapEventArgs.KeyCapType == KeyCapTypes.Shift)
                    {
                        foreach (Grid grd in this.Children)
                        {
                            foreach (KeyCap kc in grd.Children)
                            {
                                if (kc.KeyCapType == KeyCapTypes.Normal || kc.KeyCapType == KeyCapTypes.Backspace)
                                {
                                    UpdateKeyCapLayout(kc, false);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        private void ButtonStatus_Load(object sender, EventArgs e)
        {
            // load the small on-screen keyboard image
            kbPic.Image = new Bitmap("html\\kbSmall.png");

            // figure the scale relative to the full keyboard image, which is
            // what the layout coordinates in the keycaps are based on
            kbPicScale = (float)kbPic.Image.Width / kbImage.Width;

            // set up the pin display object
            pinDisplay = new KL25ZPinDisplay(picKl25z);

            // note layout items for resizing purposes
            int w = ClientRectangle.Width, h = ClientRectangle.Height;

            icon1MarginX       = w - icon1.Right;
            btnMarginX         = w - btnClose.Right;
            btnSpacingX        = btnClose.Left - btnHelp.Right;
            bottomPanelMarginY = h - bottomPanel.Top;

            // start with the prototype row
            Panel      btnPanel = btnPanel1;
            Label      btnNum   = btnNum1;
            Label      btnPort  = btnPort1;
            Label      btnState = btnState1;
            PictureBox btnKeyA  = btnKey1a;
            PictureBox btnKeyB  = btnKey1b;
            PictureBox btnShift = btnShift1;

            // row copying functions
            Func <Panel, Panel> CopyPanel = (p) =>
            {
                Panel n = new Panel();
                btnListPanel.Controls.Add(n);
                n.Left   = p.Left;
                n.Top    = p.Top + p.Height;
                n.Width  = p.Width;
                n.Height = p.Height;
                return(n);
            };
            Func <Label, Label> CopyLabel = (l) =>
            {
                Label n = new Label();
                btnPanel.Controls.Add(n);
                n.AutoSize  = false;
                n.TextAlign = ContentAlignment.MiddleCenter;
                n.Left      = l.Left;
                n.Width     = l.Width;
                n.Height    = l.Height;
                n.Top       = l.Top;
                n.Font      = l.Font;
                n.Padding   = l.Padding;
                return(n);
            };
            Func <PictureBox, PictureBox> CopyPic = (p) =>
            {
                PictureBox n = new PictureBox();
                btnPanel.Controls.Add(n);
                n.Left     = p.Left;
                n.Top      = p.Top;
                n.Width    = p.Width;
                n.Height   = p.Height;
                n.SizeMode = PictureBoxSizeMode.StretchImage;
                return(n);
            };

            StringFormat centerText = new StringFormat();

            centerText.Alignment     = StringAlignment.Center;
            centerText.LineAlignment = StringAlignment.Center;
            Action <PictureBox, int, int> SetKeyCap = (pic, keyType, keyCode) =>
            {
                switch (keyType)
                {
                case 0:
                    // no key assignment
                    break;

                case 1:
                    // joystick
                    pic.Image = new Bitmap(jsImage);
                    using (var g = Graphics.FromImage(pic.Image))
                    {
                        Font   font = captionFont;
                        String num  = keyCode.ToString();
                        g.MeasureString(num, font);
                        g.DrawString(num, font, Brushes.White, new Point(jsImage.Height / 2, jsImage.Width / 2), centerText);
                    }
                    break;

                case 2:
                case 3:
                    // keyboard or media key
                    Dictionary <int, KeyCap> dict = keyType == 2 ? keyCaps : mediaCaps;
                    if (dict.ContainsKey(keyCode))
                    {
                        KeyCap    kc  = dict[keyCode];
                        Bitmap    cb  = new Bitmap(kc.cwid, kc.cht);
                        Rectangle src = new Rectangle(kc.cx, kc.cy, kc.cwid, kc.cht);
                        Rectangle dst = new Rectangle(0, 0, kc.cwid, kc.cht);
                        using (var g = Graphics.FromImage(cb))
                        {
                            g.DrawImage(kbImage, dst, src, GraphicsUnit.Pixel);
                        }
                        pic.Image = cb;
                    }
                    break;
                }
            };

            // check to see if a shift button is enabled
            int shiftButtonIdx = 0;

            byte[] buf = dev.QueryConfigVar(16);
            if (buf != null)
            {
                shiftButtonIdx = buf[0];
            }

            // gray out the "Shifted" column header if there's no shift button
            if (shiftButtonIdx == 0)
            {
                lblShifted.ForeColor = Color.Gray;
            }

            // Mouse enter/leave handler generators.  Highlight the associated pin
            // on the KL25Z diagram.
            Action <String, bool> SetPinHover = (pin, hilite) =>
            {
                pinDisplay.SetHover(pin, hilite);
            };
            Func <String, EventHandler> PanelMouseEnter = (pin) =>
            {
                EventHandler h1 = (object s1, EventArgs e1) =>
                {
                    SetPinHover(pin, true);
                    btnListPanel.Focus();
                };
                return(new EventHandler(h1));
            };
            Func <String, EventHandler> PanelMouseLeave = (pin) =>
            {
                EventHandler h1 = (object s1, EventArgs e1) => { SetPinHover(pin, false); };
                return(new EventHandler(h1));
            };

            // load the button configuration
            buf = dev.QueryConfigVar(254, 0);
            if (buf != null)
            {
                byte nButtons = buf[0];
                statusLabels = new Label[nButtons];
                pinNames     = new String[nButtons];
                for (byte i = 1; i <= nButtons; ++i)
                {
                    // if this isn't the first row, copy the prototype
                    if (i > 1)
                    {
                        btnPanel = CopyPanel(btnPanel);
                        btnNum   = CopyLabel(btnNum);
                        btnPort  = CopyLabel(btnPort);
                        btnState = CopyLabel(btnState);
                        btnKeyA  = CopyPic(btnKeyA);
                        btnKeyB  = CopyPic(btnKeyB);
                        btnShift = CopyPic(btnShift);
                    }

                    if ((i & 1) == 0)
                    {
                        btnPanel.BackColor = Color.GhostWhite;
                    }

                    // retrieve the button description
                    buf = dev.QueryConfigVar(254, i);
                    byte[] xbuf = dev.QueryConfigVar(253, i);

                    // fill in the labels
                    btnNum.Text = i.ToString();
                    String pin = DeviceInfo.WireToPinName(buf[0]);
                    btnPort.Text  = (pin == "NC" ? "None" : pin);
                    btnState.Text = "Off";

                    // Set up the mouse event handlers on the panel and its children.
                    // It's a little tedious, but we have to install the handlers on
                    // all of the children, because the event model doesn't stack: the
                    // mouse is only in one control at a time, so it leaves the parent
                    // when entering a child.  We want the parent and all children to
                    // be the same for the purposes of the hovering, so we need the same
                    // handlers on all of them.
                    EventHandler enter = PanelMouseEnter(pin);
                    EventHandler leave = PanelMouseLeave(pin);
                    btnPanel.MouseEnter += enter;
                    btnPanel.MouseLeave += leave;
                    foreach (Control chi in btnPanel.Controls)
                    {
                        chi.MouseEnter += enter;
                        chi.MouseLeave += leave;
                    }

                    // set the key caps
                    SetKeyCap(btnKeyA, buf[1], buf[2]);
                    if (shiftButtonIdx != 0 && shiftButtonIdx != i)
                    {
                        SetKeyCap(btnKeyB, xbuf[0], xbuf[1]);
                    }

                    // if this is the shift button, set the shift button image
                    if (i == shiftButtonIdx)
                    {
                        btnShift.Image = new Bitmap("html\\shiftButtonSmall.png");
                    }

                    // remember the status label and pin name
                    statusLabels[i - 1] = btnState;
                    pinNames[i - 1]     = pin;
                }
            }
        }
Beispiel #9
0
        virtual public void UpdateKeyCapLayout(KeyCap keyCap, bool isShift)
        {
            ContentControl button = keyCap.LayoutRoot.Children[0] as ContentControl;
            Grid           grd    = button.Content as Grid;

            button.Padding = new Thickness();
            grd.Width      = keyCap.Width - keyCap.LayoutRoot.Margin.Left - keyCap.LayoutRoot.Margin.Right;
            grd.Height     = keyCap.Height - keyCap.LayoutRoot.Margin.Top - keyCap.LayoutRoot.Margin.Bottom;

            if ((keyCap.BKImage != null && !isShift) ||
                (keyCap.SubBKImage != null && isShift))
            {
                Image img = null;
                if (grd.Children.Count == 0)
                {
                    grd.Children.Add(new Image());
                }
                else if (!(grd.Children[0] is Image))
                {
                    grd.Children.RemoveAt(0);
                    grd.Children.Add(new Image());
                }

                img        = grd.Children[0] as Image;
                img.Source = !isShift ? keyCap.BKImage : keyCap.SubBKImage;
                img.Width  = grd.Width;
                img.Height = grd.Height;

                Grid.SetRowSpan(img, 2);
                Grid.SetColumnSpan(img, 2);
            }
            else
            {
                //사용될 텍스트
                string label = !isShift ? keyCap.Text : keyCap.SubText;

                int len = label.Length;
                //업데이트할 텍스트가 없으면 리턴
                if (len == 0)
                {
                    return;
                }

                if (grd.Children.Count == 0)
                {
                    grd.Children.Add(new TextBlock());
                }
                else if (!(grd.Children[0] is TextBlock))
                {
                    grd.Children.RemoveAt(0);
                    grd.Children.Add(new TextBlock());
                }
                TextBlock tbUp = grd.Children[0] as TextBlock;

                button.FontWeight = FontWeights.SemiBold;
                //글짜수에 따르 크기 변경
                //button.FontSize = keyCap.GetFontSize(label) * (Apps.WowPad.Manager.SettingManager.Instance.SettingInfo.FullSizeKeyboard ? 1 : 0.9);
                button.FontSize = keyCap.GetFontSize(label);

                tbUp.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                tbUp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                tbUp.Text = label;

                Grid.SetRowSpan(tbUp, 2);
                Grid.SetColumnSpan(tbUp, 2);
            }
        }
Beispiel #10
0
        public override void UpdateKeyCapLayout(KeyCap keyCap, bool isShift)
        {
            ContentControl button = keyCap.LayoutRoot.Children[0] as ContentControl;
            Grid           grd    = button.Content as Grid;

            button.Padding = new Thickness();
            grd.Width      = keyCap.Width - keyCap.LayoutRoot.Margin.Left - keyCap.LayoutRoot.Margin.Right;
            grd.Height     = keyCap.Height - keyCap.LayoutRoot.Margin.Top - keyCap.LayoutRoot.Margin.Bottom;

            if ((keyCap.BKImage != null && !isShift) ||
                (keyCap.SubBKImage != null && isShift))
            {
                Image img = null;
                if (grd.Children.Count == 0)
                {
                    grd.Children.Add(new Image());
                }
                else if (!(grd.Children[0] is Image))
                {
                    grd.Children.Clear();
                    grd.Children.Add(new Image());
                }

                img        = grd.Children[0] as Image;
                img.Source = !isShift ? keyCap.BKImage : keyCap.SubBKImage;
                img.Width  = grd.Width;
                img.Height = grd.Height;

                Grid.SetRowSpan(img, 2);
                Grid.SetColumnSpan(img, 2);
            }
            else
            {
                //사용될 텍스트
                string label = !isShift ? keyCap.Text : keyCap.SubText;
                //업데이트할 텍스트가 없으면 리턴
                if (label.Length == 0)
                {
                    return;
                }

                if (grd.Children.Count == 0)
                {
                    grd.Children.Add(new TextBlock());
                }
                if (!(grd.Children[0] is TextBlock))
                {
                    grd.Children.RemoveAt(0);
                    grd.Children.Add(new TextBlock());
                }
                TextBlock tbUp = grd.Children[0] as TextBlock;
                Border    bd   = new Border();
                Grid.SetRow(tbUp, 0);
                Grid.SetColumn(tbUp, 0);

                button.FontWeight = FontWeights.SemiBold;
                //글짜수에 따르 크기 변경
                button.FontSize = keyCap.GetFontSize(label) * (Apps.WowPad.Manager.SettingManager.Instance.SettingInfo.FullSizeKeyboard ? 1 : 0.9);

                string[] labels = label.Split("|".ToArray());

                if (labels.Length < 2)
                {
                    tbUp.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                    tbUp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    Grid.SetRowSpan(tbUp, 2);
                    Grid.SetColumnSpan(tbUp, 2);
                    tbUp.Text = label;
                }
                else
                {
                    string txtUp = string.Empty;
                    string txtDn = string.Empty;

                    if (labels.Length == 2)
                    {
                        txtUp = labels[0];
                        txtDn = labels[1];
                    }
                    else
                    {
                        txtUp = (string.IsNullOrEmpty(labels[0])) ? "|" : labels[0];
                        txtDn = (string.IsNullOrEmpty(labels[0])) ? labels[2] : "|";
                    }

                    if (grd.Children.Count == 1)
                    {
                        grd.Children.Add(new TextBlock());
                    }
                    else if (!(grd.Children[1] is TextBlock))
                    {
                        grd.Children.RemoveAt(1);
                        grd.Children.Add(new TextBlock());
                    }

                    TextBlock tbDn = grd.Children[1] as TextBlock;
                    Grid.SetRow(tbDn, 1);
                    Grid.SetColumn(tbDn, 1);

                    tbUp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    tbUp.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                    tbUp.FontSize            = (Apps.WowPad.Manager.SettingManager.Instance.SettingInfo.FullSizeKeyboard ? 1.1 : 0.9) * (double)Application.Current.Resources["PhoneFontSizeMedium"];
                    tbUp.Text = txtUp;

                    tbDn.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    tbDn.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                    tbDn.Margin     = new Thickness(0, -10, 0, 0);
                    tbDn.FontSize   = (Apps.WowPad.Manager.SettingManager.Instance.SettingInfo.FullSizeKeyboard ? 0.8 : 0.6) * (double)Application.Current.Resources["PhoneFontSizeMedium"];;
                    tbDn.Foreground = new SolidColorBrush(Color.FromArgb(255, 180, 180, 180));
                    tbDn.Text       = txtDn;
                }
            }
        }