Exemplo n.º 1
0
 private void Confirm(PhControl sender)
 {
     if (onInput!=null)
         onInput(this);
     this.Hide();
     this.Destroyed = true;
 }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
 private void StartSelectEntity(PhControl sender)
 {
     if (layers[currentLayer].Type == LayerType.Tiles)
         tilesWindow.Show();
     if (layers[currentLayer].Type == LayerType.Entities)
         entitiesWindow.Show();
 }
Exemplo n.º 4
0
 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;
             }
         }
     }
 }
Exemplo n.º 5
0
 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();
     }
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 private void Cancel(PhControl sender)
 {
     this.Hide();
     this.Destroyed = true;
 }
Exemplo n.º 8
0
 public void DoMouseDown()
 {
     if (hovering != null)
     {
         if (Focus != null)
             Focus.OnBlur();
         hovering.OnMouseDown();
         Focus = hovering;
         Focus.OnFocus();
     }
 }
Exemplo n.º 9
0
 public override void OnAncestryChanged()
 {
     base.OnAncestryChanged();
     ParentControl = GetAncestor<PhControl>();
     if (ParentControl != null)
     {
         RealLeft = ParentControl.RealLeft + Left;
         RealTop = ParentControl.RealTop + Top;
     }
 }
Exemplo n.º 10
0
 private void ConfirmOpen(PhControl sender)
 {
     MapLoader.OpenMap((sender as PhInputDialog).Result);
     if (Editing.Camera != null)
         this.Editing.Camera.HandleMessage(Messages.CameraStopFollowing, null);
 }
Exemplo n.º 11
0
 private void CloseProperties(PhControl sender)
 {
     propertiesWindow.Hide();
     windows.RemoveComponent(propertiesWindow);
     propertiesWindow = null;
 }
Exemplo n.º 12
0
 private void CloseMenu(PhControl sender)
 {
     main.Hide();
 }
Exemplo n.º 13
0
 private void CloseEditor(PhControl sender)
 {
     Editing.HandleMessage(Messages.MapLoaded, null);
     PhantomGame.Game.PopState();
 }
Exemplo n.º 14
0
 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();
 }
Exemplo n.º 15
0
 private void StartSelectLayer(PhControl sender)
 {
     layerWindow.Show();
 }
Exemplo n.º 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;
 }
Exemplo n.º 17
0
 private void ConfirmSave(PhControl sender)
 {
     MapLoader.SaveMap((sender as PhInputDialog).Result);
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 private void DoX(PhControl sender)
 {
     this.Hide();
 }
Exemplo n.º 21
0
 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));
 }