Ejemplo n.º 1
0
        private void ReadKeySettingFromXml(string fileName)
        {
            var reader = XmlReader.Create(fileName, new XmlReaderSettings());

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "KeyConfigs":
                        keyConfigs.Clear();
                        break;

                    case "KeyConfig":
                        var keyConfig = new KeyConfig
                        {
                            Name = reader.GetAttribute("Name")
                        };
                        keyConfigs.Add(keyConfig);
                        ReadKeySetting(reader.ReadSubtree(), keyConfig);
                        break;
                    }
                }
            }
            reader.Close();

            if (keyConfigs.Count == 0)
            {
                keyConfigs.Add(new KeyConfig());
            }
        }
Ejemplo n.º 2
0
 private void WriteSetting(XmlWriter writer, KeyConfig keyConfig)
 {
     foreach (ButtonType buttonType in ButtonUtility.Array)
     {
         writer.WriteStartElement("Config");
         writer.WriteAttributeString("Type", buttonType.ToString());
         writer.WriteAttributeString("Key", ((int)keyConfig.GetKeyMap(buttonType)).ToString());
         writer.WriteAttributeString("Button", keyConfig.GetButtonMap(buttonType).ToString());
         writer.WriteEndElement();
     }
 }
Ejemplo n.º 3
0
        private void ReadKeySettingFromIni(string fileName)
        {
            var keyConfig = new KeyConfig();
            var sr        = new StreamReader(fileName);
            var s         = sr.ReadToEnd().Replace("\r\n", "\n").Replace("\r", "\n");

            sr.Close();
            var sp = s.Split('\n');

            for (int i = 0; i < Math.Min(sp.Length, ButtonUtility.Array.Length); i++)
            {
                var secondsp = sp[i].Split(':');
                if (secondsp.Length >= 2)
                {
                    keyConfig.SetKeyMap(ButtonUtility.Array[i], (Key)int.Parse(secondsp[0]));
                    keyConfig.SetButtonMap(ButtonUtility.Array[i], int.Parse(secondsp[1]));
                }
            }
            keyConfigs.Add(keyConfig);
        }
Ejemplo n.º 4
0
 private void ReadKeySetting(XmlReader reader, KeyConfig keyConfig)
 {
     while (reader.Read())
     {
         if (reader.IsStartElement())
         {
             switch (reader.LocalName)
             {
             case "Config":
                 var key = (Key)int.Parse(reader.GetAttribute("Key"));
                 int button = int.Parse(reader.GetAttribute("Button")), index = FindIndex(reader.GetAttribute("Type"));
                 if (index >= 0)
                 {
                     keyConfig.SetKeyMap(ButtonUtility.Array[index], key);
                     keyConfig.SetButtonMap(ButtonUtility.Array[index], button);
                 }
                 break;
             }
         }
     }
     reader.Close();
 }
Ejemplo n.º 5
0
        public StartPanel(PPDDevice device, MyGame myGame, PPDFramework.Resource.ResourceManager resourceManager) : base(device)
        {
            this.myGame          = myGame;
            this.resourceManager = resourceManager;

            contentSprite = new SpriteObject(device);
            this.AddChild(contentSprite);

            var sprite = new SpriteObject(device);

            sprite.AddChild(new TextureString(device, Utility.Language["WelcomeToPPD"], 20, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 200)
            });
            sprite.AddChild(new TextureString(device, Utility.Language["StartInitialSetting"], 16, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 240)
            });
            Add(sprite);

            sprite = new SpriteObject(device);
            sprite.AddChild(new TextureString(device, Utility.Language["StartKeyButtonSetting"], 20, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 200)
            });
            sprite.AddChild(new TextureString(device, Utility.Language["InsertKeyboardAndController"], 16, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 240)
            });
            Add(sprite);

            sprite = new SpriteObject(device);
            sprite.AddChild((controllerNameText = new TextureString(device, "", 14, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 10)
            }));
            reload = new FadableButton(device, resourceManager, Utility.Path.Combine("reload.png"), Utility.Path.Combine("reload_select.png"), "");
            reload.MouseLeftClick += reload_MouseLeftClick;
            up = new FadableButton(device, resourceManager, Utility.Path.Combine("up.png"), Utility.Path.Combine("up_select.png"), "");
            up.MouseLeftClick += up_MouseLeftClick;
            down = new FadableButton(device, resourceManager, Utility.Path.Combine("down.png"), Utility.Path.Combine("down_select.png"), "");
            down.MouseLeftClick += down_MouseLeftClick;
            sprite.AddChild(up);
            sprite.AddChild(down);
            sprite.AddChild(reload);
            up.Position = down.Position = reload.Position = new SharpDX.Vector2(400, 225);
            sprite.AddChild(new PictureObject(device, resourceManager, Utility.Path.Combine("keysettinggrid.png"))
            {
                Position = new SharpDX.Vector2(290, 30)
            });
            sprite.AddChild(new TextButton(device, resourceManager)
            {
                Position = new SharpDX.Vector2(320, 390), Text = Utility.Language["Start"]
            });
            sprite.AddChild(new TextButton(device, resourceManager)
            {
                Position = new SharpDX.Vector2(320, 420), Text = Utility.Language["Home"]
            });
            keys    = new TextureString[ButtonUtility.Array.Length];
            buttons = new TextureString[ButtonUtility.Array.Length];
            if (myGame.KeyConfigManager.Configs.Length > 0)
            {
                keyConfig = myGame.KeyConfigManager[0];
            }
            for (int i = 0; i < ButtonUtility.Array.Length; i++)
            {
                var textButton = new TextButton(device, resourceManager)
                {
                    Position = new SharpDX.Vector2(530, 90 + i * 30), Text = Utility.Language["Change"], Index = i
                };
                textButton.MouseLeftDown += textButton_MouseLeftDown;

                keys[i] = new TextureString(device, keyConfig.GetKeyMap((ButtonType)i).ToString(), 14, true, PPDColors.White)
                {
                    Position = new SharpDX.Vector2(388, 82 + i * 30)
                };
                buttons[i] = new TextureString(device, keyConfig.GetButtonMap((ButtonType)i).ToString(), 14, true, PPDColors.White)
                {
                    Position = new SharpDX.Vector2(460, 82 + i * 30)
                };
                sprite.AddChild(textButton);
                sprite.AddChild(keys[i]);
                sprite.AddChild(buttons[i]);
            }
            Add(sprite);

            sprite = new SpriteObject(device);
            sprite.AddChild(new TextureString(device, Utility.Language["SettingCompleted"], 20, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 200)
            });
            sprite.AddChild(new TextureString(device, Utility.Language["UserKeyboardOrController"], 16, true, PPDColors.White)
            {
                Position = new SharpDX.Vector2(400, 240)
            });
            Add(sprite);

            right = new FadableButton(device, resourceManager, Utility.Path.Combine("right.png"), Utility.Path.Combine("right_select.png"), "Next")
            {
                Position = new SharpDX.Vector2(770, 225)
            };
            this.AddChild(right);
            left = new FadableButton(device, resourceManager, Utility.Path.Combine("left.png"), Utility.Path.Combine("left_select.png"), "Back")
            {
                Position = new SharpDX.Vector2(30, 225)
            };
            this.AddChild(left);

            left.MouseLeftClick  += left_MouseLeftClick;
            right.MouseLeftClick += right_MouseLeftClick;

            focusManager = new FocusManager();
            focusManager.Focus(this);

            left.Alpha = 0;
            this.Alpha = 0;
        }
Ejemplo n.º 6
0
            public ChangeKeyConfigSprite(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager, MyGame myGame, KeyConfig keyConfig, ISound sound) : base(device)
            {
                this.resourceManager = resourceManager;
                this.myGame          = myGame;
                this.keyConfig       = keyConfig;
                this.sound           = sound;

                var sprite = new SpriteObject(device);

                sprite.AddChild(new PictureObject(device, resourceManager, Utility.Path.Combine("keysettinggrid.png"))
                {
                    Position = new SharpDX.Vector2(290, 30)
                });
                sprite.AddChild(new TextButton(device, resourceManager)
                {
                    Position = new SharpDX.Vector2(320, 390), Text = Utility.Language["Start"]
                });
                sprite.AddChild(new TextButton(device, resourceManager)
                {
                    Position = new SharpDX.Vector2(320, 420), Text = Utility.Language["Home"]
                });
                keys        = new TextureString[ButtonUtility.Array.Length];
                buttons     = new TextureString[ButtonUtility.Array.Length];
                textButtons = new TextButton[ButtonUtility.Array.Length];
                if (myGame.KeyConfigManager.CurrentConfigIndex < myGame.KeyConfigManager.Configs.Length)
                {
                    keyConfig = myGame.KeyConfigManager.Configs[myGame.KeyConfigManager.CurrentConfigIndex];
                }
                for (int i = 0; i < ButtonUtility.Array.Length; i++)
                {
                    var textButton = new TextButton(device, resourceManager)
                    {
                        Position = new SharpDX.Vector2(530, 90 + i * 30), Text = Utility.Language["Change"], Index = i
                    };
                    textButton.MouseLeftDown += textButton_MouseLeftDown;
                    textButtons[i]            = textButton;

                    keys[i] = new TextureString(device, keyConfig.GetKeyMap((ButtonType)i).ToString(), 14, true, PPDColors.White)
                    {
                        Position = new SharpDX.Vector2(388, 82 + i * 30)
                    };
                    buttons[i] = new TextureString(device, keyConfig.GetButtonMap((ButtonType)i).ToString(), 14, true, PPDColors.White)
                    {
                        Position = new SharpDX.Vector2(460, 82 + i * 30)
                    };
                    sprite.AddChild(textButton);
                    sprite.AddChild(keys[i]);
                    sprite.AddChild(buttons[i]);
                }

                this.AddChild(sprite);
                this.AddChild((select = new PictureObject(device, resourceManager, Utility.Path.Combine("right.png"), true)
                {
                    Position = new SharpDX.Vector2(280, 0),
                    Scale = new SharpDX.Vector2(0.5f, 0.5f)
                }));

                Inputed     += ChangeKeyConfigSprite_Inputed;
                LostFocused += ChangeKeyConfigSprite_LostFocused;
                GotFocused  += ChangeKeyConfigSprite_GotFocused;
            }