示例#1
0
 private void Confirm(PhControl sender)
 {
     if (onInput!=null)
         onInput(this);
     this.Hide();
     this.Destroyed = true;
 }
示例#2
0
        public PhInputDialog(float left, float top, string title, string caption, string text, PhControl.GUIAction onInput)
            : base(left, top, 400, 120, title)
        {
            edit = new PhTextEdit(10, 60, 380, 20, text, caption, PhTextEdit.ValueType.String, null, null);
            edit.CaptionPosition = new Microsoft.Xna.Framework.Vector2(5, -30);

            this.onInput = onInput;

            AddComponent(edit);
            AddComponent(new PhButton(200, 90, 80, 24, "OK", Confirm));
            AddComponent(new PhButton(300, 90, 80, 24, "Cancel", Cancel));
        }
示例#3
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void StartSelectEntity(PhControl sender)
 {
     if (layers[currentLayer].Type == LayerType.Tiles)
         tilesWindow.Show();
     if (layers[currentLayer].Type == LayerType.Entities)
         entitiesWindow.Show();
 }
示例#4
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void SelectLayer(PhControl sender)
 {
     layerWindow.Hide();
     PhButton button = sender as PhButton;
     if (button != null)
     {
         for (int i = 0; i < layers.Count; i++)
         {
             if (button.Text == layers[i].Name)
             {
                 switch (layers[i].Type)
                 {
                     case LayerType.Entities:
                     case LayerType.Tiles:
                         currentLayer = i;
                         ChangeLayer();
                         break;
                     case LayerType.Properties:
                         selectedEntity = null;
                         CreatePropertiesWindow(layers[i].Name, layers[i].Layer);
                         break;
                 }
                 break;
             }
         }
     }
 }
示例#5
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void SelectEntity(PhControl sender)
 {
     PhButton button = sender as PhButton;
     if (layers[currentLayer].Type == LayerType.Tiles)
     {
         drawingType = null;
         drawingEntity = null;
         for (int i = 0; i < MapLoader.TileList.Length; i++)
         {
             if (MapLoader.ShortTypeName(MapLoader.TileList[i]) == button.Text)
             {
                 drawingType = MapLoader.TileList[i];
                 drawingEntity = (Entity)Activator.CreateInstance(drawingType, mousePosition);
                 break;
             }
         }
         tilesWindow.Hide();
     }
     else
     {
         for (int i = 0; i < MapLoader.EntityList.Length; i++)
         {
             if (MapLoader.ShortTypeName(MapLoader.EntityList[i]) == button.Text)
             {
                 drawingType = MapLoader.EntityList[i];
                 drawingEntity = (Entity)Activator.CreateInstance(drawingType, mousePosition);
                 break;
             }
         }
         entitiesWindow.Hide();
     }
 }
示例#6
0
文件: Editor.cs 项目: HuntiXz/phantom
        private void SaveProperties(PhControl sender)
        {
            Component selectedComponent = propertiesWindowTarget;
            Entity selectedEntity = selectedComponent as Entity;
            if (selectedComponent == null)
                return;
            foreach (Component c in propertiesWindow.Components)
            {
                PhTextEdit edit = c as PhTextEdit;
                if (edit != null)
                {
                    if (edit.Caption == "X" && selectedEntity!=null)
                    {
                        float.TryParse(edit.Text, out selectedEntity.Position.X);
                    }
                    else if (edit.Caption == "Y" && selectedEntity != null)
                    {
                        float.TryParse(edit.Text, out selectedEntity.Position.Y);
                    }
                    else if (edit.Caption == "Orientation" && selectedEntity != null)
                    {
                        if (float.TryParse(edit.Text, out selectedEntity.Orientation))
                        {
                            selectedEntity.Orientation = MathHelper.ToRadians(selectedEntity.Orientation);
                        }
                    }
                    else
                    {

                        switch (edit.Type)
                        {
                            case PhTextEdit.ValueType.String:
                                selectedComponent.Properties.Objects[edit.Caption] = edit.Text;
                                break;
                            case PhTextEdit.ValueType.Int:
                                int i = 0;
                                int.TryParse(edit.Text, out i);
                                selectedComponent.Properties.Ints[edit.Caption] = i;
                                break;
                            case PhTextEdit.ValueType.Color:
                                int col = 0;
                                int.TryParse(edit.Text.Substring(1), NumberStyles.HexNumber, null, out col);
                                selectedComponent.Properties.Objects[edit.Caption] = col.ToColor();
                                break;
                            case PhTextEdit.ValueType.Float:
                                float f = 0;
                                float.TryParse(edit.Text, out f);
                                selectedComponent.Properties.Floats[edit.Caption] = f;
                                break;

                        }
                    }
                }
            }

            if (selectedEntity!=null)
                selectedEntity.Integrate(0);
            selectedComponent.HandleMessage(Messages.PropertiesChanged, null);
            propertiesWindow.Hide();
            windows.RemoveComponent(propertiesWindow);
            propertiesWindow = null;
        }
示例#7
0
 private void Cancel(PhControl sender)
 {
     this.Hide();
     this.Destroyed = true;
 }
示例#8
0
 public void DoMouseDown()
 {
     if (hovering != null)
     {
         if (Focus != null)
             Focus.OnBlur();
         hovering.OnMouseDown();
         Focus = hovering;
         Focus.OnFocus();
     }
 }
示例#9
0
 public override void OnAncestryChanged()
 {
     base.OnAncestryChanged();
     ParentControl = GetAncestor<PhControl>();
     if (ParentControl != null)
     {
         RealLeft = ParentControl.RealLeft + Left;
         RealTop = ParentControl.RealTop + Top;
     }
 }
示例#10
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void ConfirmOpen(PhControl sender)
 {
     MapLoader.OpenMap((sender as PhInputDialog).Result);
     if (Editing.Camera != null)
         this.Editing.Camera.HandleMessage(Messages.CameraStopFollowing, null);
 }
示例#11
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void CloseProperties(PhControl sender)
 {
     propertiesWindow.Hide();
     windows.RemoveComponent(propertiesWindow);
     propertiesWindow = null;
 }
示例#12
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void CloseMenu(PhControl sender)
 {
     main.Hide();
 }
示例#13
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void CloseEditor(PhControl sender)
 {
     Editing.HandleMessage(Messages.MapLoaded, null);
     PhantomGame.Game.PopState();
 }
示例#14
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void ClearMap(PhControl sender)
 {
     for (int i = 0; i < layers.Count; i++)
     {
         if (layers[i].Layer is EntityLayer && layers[i].Type == LayerType.Properties)
         {
             ((EntityLayer)layers[i].Layer).ClearComponents();
         }
     }
     main.Hide();
 }
示例#15
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void StartSelectLayer(PhControl sender)
 {
     layerWindow.Show();
 }
示例#16
0
 public PhControl DoMouseMove(float x, float y)
 {
     if (!Destroyed && !Ghost && x >= RealLeft && x <= RealLeft + Width && y >= RealTop && y < RealTop + Height)
     {
         PhControl mouseOverControl = this;
         foreach (Component c in Components)
         {
             PhControl control = c as PhControl;
             if (control != null)
             {
                 PhControl mouseOverControl2 = control.DoMouseMove(x, y);
                 if (mouseOverControl2 != null)
                 {
                     mouseOverControl = mouseOverControl2;
                     break;
                 }
             }
         }
         if (ParentControl == null && mouseOverControl != hovering)
         {
             if (hovering != null)
                 hovering.OnMouseOut();
             hovering = mouseOverControl;
             if (hovering != null)
                 hovering.OnMouseOver();
             return hovering;
         }
         return mouseOverControl;
     }
     return null;
 }
示例#17
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void ConfirmSave(PhControl sender)
 {
     MapLoader.SaveMap((sender as PhInputDialog).Result);
 }
示例#18
0
 public void SetFocus(PhControl control)
 {
     if (ParentControl != null)
     {
         ParentControl.SetFocus(control);
     }
     else
     {
         if (Focus != null)
             Focus.OnBlur();
         Focus = control;
         if (Focus != null)
             Focus.OnFocus();
     }
 }
示例#19
0
文件: Editor.cs 项目: HuntiXz/phantom
        private void CreateWindows()
        {
            windows = new PhControl(0, 0, PhantomGame.Game.Resolution.Width, PhantomGame.Game.Resolution.Height);
            windows.Ghost = true;
            AddComponent(windows);

            main = new PhWindow(100, 100, 500, 500, "Main Menu");
            main.Ghost = true;
            int y = 30;
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Layers", StartSelectLayer));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Entities", StartSelectEntity));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Clear Map", ClearMap));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Save Map", SaveMap));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Open Map", OpenMap));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Close Menu", CloseMenu));
            main.AddComponent(new PhButton(10, y += 32, 480, 24, "Close Editor", CloseEditor));
            windows.AddComponent(main);

            layerWindow = new PhWindow(100, 100, 500, 500, "Layers");
            layerWindow.Ghost = true;
            for (int i = 0; i < layers.Count; i++)
                layerWindow.AddComponent(new PhButton(10, 30+i*32, 480, 24, layers[i].Name, SelectLayer));
            windows.AddComponent(layerWindow);

            tilesWindow = new PhWindow(100, 100, 500, 500, "Tiles");
            tilesWindow.Ghost = true;
            int x = 10;
            y = 30;
            tilesWindow.AddComponent(new PhButton(x, y, 160, 24, "<none>", SelectEntity));
            y += 32;
            for (int i = 0; i < MapLoader.TileList.Length; i++)
            {
                tilesWindow.AddComponent(new PhButton(x, y, 160, 24, MapLoader.ShortTypeName(MapLoader.TileList[i]), SelectEntity));
                y += 32;
                if (y > 500 - 32)
                {
                    x += 168;
                    y = 30;
                }
            }
            windows.AddComponent(tilesWindow);

            entitiesWindow = new PhWindow(100, 100, 500, 500, "Entities");
            entitiesWindow.Ghost = true;
            x = 10;
            y = 30;
            for (int i = 0; i < MapLoader.EntityList.Length; i++)
            {
                entitiesWindow.AddComponent(new PhButton(x, y, 160, 24, MapLoader.ShortTypeName(MapLoader.EntityList[i]), SelectEntity));
                y += 32;
                if (y > 500 - 32)
                {
                    x += 168;
                    y = 30;
                }
            }
            windows.AddComponent(entitiesWindow);
        }
示例#20
0
 private void DoX(PhControl sender)
 {
     this.Hide();
 }
示例#21
0
文件: Editor.cs 项目: HuntiXz/phantom
 private void SaveMap(PhControl sender)
 {
     string filename = "";
     if (Editing.Properties != null)
         filename = Editing.Properties.GetString("filename", "");
     windows.AddComponent(new PhInputDialog(100, 100, "Save Map", "Filename:", filename, ConfirmSave));
 }