コード例 #1
0
        private void worldView_DragDrop(object sender, DragEventArgs e)
        {
            Vector2 worldPos = ScreenToWorld(e.X, e.Y);

            if (snapping)
            {
                worldPos = SnapToGrid(worldPos);
            }

            //get item
            ListViewItem item = new ListViewItem();
            if (e.Data.GetData(typeof(ListViewItem)) != null)
                item = (ListViewItem)e.Data.GetData(typeof(ListViewItem));

            object selectedObject = null;

            switch ((string)item.Tag)
            {
                case "Light":
                    if (level.Lights.Count < 8)
                    {
                        Light l = new Light();
                        l.Diffuse = Color4.White;
                        l.Ambient = new Color4(0.1f, 0.1f, 0.1f, 1f);
                        l.Position = new Vector4(worldPos.X, worldPos.Y, 36, 1);
                        l.ConstantAttenuation = 1f;
                        l.LinearAttenuation = 1f / 3000f;
                        l.QuadraticAttenuation = 1f / 40000f;
                        level.Lights.Add(l);

                        for (int i = 0; i < 8; i++)
                        {
                            bool inUse = false;
                            for (int j = 0; j < level.Lights.Count; j++)
                            {
                                if (level.Lights[j].Index == i)
                                {
                                    inUse = true;
                                }
                            }
                            if (!inUse)
                            {
                                l.Index = i;
                            }
                        }
                        selectedObject = l;
                    }
                    else
                    {
                        MessageBox.Show("To many lights. Max light count is 8.", "Light Count", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    break;
                case "Ball":
                    Ball ball = new Ball(worldPos.X, worldPos.Y);
                    level.Entities.Add(ball);
                    selectedObject = ball;
                    break;
                case "Block":
                    Block block = new Block(worldPos.X, worldPos.Y);
                    level.Entities.Add(block);
                    selectedObject = block;
                    break;
                case "BreakableDoor":
                    BreakableDoor bdoor = new BreakableDoor(worldPos.X, worldPos.Y);
                    bdoor.MaxHits = 3;
                    level.Entities.Add(bdoor);
                    selectedObject = bdoor;
                    break;
                case "Button":
                    Entities.Button button = new Entities.Button(worldPos.X, worldPos.Y);
                    level.Entities.Add(button);
                    selectedObject = button;
                    break;
                case "Cannon":
                    Cannon cannon = new Cannon(worldPos.X, worldPos.Y);
                    level.Entities.Add(cannon);
                    selectedObject = cannon;
                    break;
                case "Door":
                    Door door = new Door(worldPos.X, worldPos.Y);
                    level.Entities.Add(door);
                    selectedObject = door;
                    break;
                /*case "LaserShooter":
                    LaserShooter ls = new LaserShooter(worldPos.X, worldPos.Y);
                    level.Entities.Add(ls);
                    selectedObject = ls;
                    break;*/
                case "Player":
                    Player p = new Player(worldPos.X, worldPos.Y);
                    level.Entities.Add(p);
                    selectedObject = p;
                    break;
                /*case "PuzzleBox":
                    PuzzleBox pb = new PuzzleBox(worldPos.X, worldPos.Y);
                    level.Entities.Add(pb);
                    selectedObject = pb;
                    break;*/
                case "SpikeWall":
                    SpikeWall sw = new SpikeWall(worldPos.X, worldPos.Y);
                    level.Entities.Add(sw);
                    selectedObject = sw;
                    break;
                /*case "Teleporter":
                    Teleporter tp = new Teleporter(worldPos.X, worldPos.Y);
                    level.Entities.Add(tp);
                    selectedObject = tp;
                    break;*/
                case "CauseAND":
                    CauseAND cAnd = new CauseAND();
                    level.Causes.Add(cAnd);
                    selectedObject = cAnd;
                    break;
                case "CauseNOT":
                    CauseNOT cNot = new CauseNOT();
                    level.Causes.Add(cNot);
                    selectedObject = cNot;
                    break;
                case "CauseOR":
                    CauseOR cOr = new CauseOR();
                    level.Causes.Add(cOr);
                    selectedObject = cOr;
                    break;
                case "CauseXOR":
                    CauseXOR cXor = new CauseXOR();
                    level.Causes.Add(cXor);
                    selectedObject = cXor;
                    break;
                case "CauseButton":
                    CauseButton cBtn = new CauseButton();
                    level.Causes.Add(cBtn);
                    selectedObject = cBtn;
                    break;
                case "CauseEntityDestruction":
                    CauseEntityDestruction cEntD = new CauseEntityDestruction();
                    level.Causes.Add(cEntD);
                    selectedObject = cEntD;
                    break;
                case "CauseLocation":
                    CauseLocation cLoc = new CauseLocation();
                    level.Causes.Add(cLoc);
                    selectedObject = cLoc;
                    break;
                case "CauseTimePassed":
                    CauseTimePassed cTime = new CauseTimePassed();
                    level.Causes.Add(cTime);
                    selectedObject = cTime;
                    break;
                case "EffectAND":
                    EffectAND eAnd = new EffectAND();
                    level.Effects.Add(eAnd);
                    selectedObject = eAnd;
                    break;
                case "EffectList":
                    EffectList eList = new EffectList();
                    level.Effects.Add(eList);
                    selectedObject = eList;
                    break;
                case "EffectDoor":
                    EffectDoor eDoor = new EffectDoor();
                    level.Effects.Add(eDoor);
                    selectedObject = eDoor;
                    break;
                case "EffectEndGame":
                    EffectEndGame eEnd = new EffectEndGame();
                    level.Effects.Add(eEnd);
                    selectedObject = eEnd;
                    break;
                case "EffectRaiseBridge":
                    EffectRaiseBridge eBridge = new EffectRaiseBridge();
                    level.Effects.Add(eBridge);
                    selectedObject = eBridge;
                    break;
                case "EffectRemoveEntity":
                    EffectRemoveEntity eRemove = new EffectRemoveEntity();
                    level.Effects.Add(eRemove);
                    selectedObject = eRemove;
                    break;
                case "EffectTriggerTimer":
                    EffectTriggerTimer eTimer = new EffectTriggerTimer();
                    level.Effects.Add(eTimer);
                    selectedObject = eTimer;
                    break;
                case "Trigger":
                    Trigger t = new Trigger();
                    level.Triggers.Add(t);
                    selectedObject = t;
                    break;
            }

            selectedItemProperties.SelectedObject = selectedObject;

            UpdateWorldTree();
        }
コード例 #2
0
        private void worldView_DragDrop(object sender, DragEventArgs e)
        {
            Vector2 worldPos = ScreenToWorld(e.X, e.Y);

            if (snapping)
            {
                worldPos = SnapToGrid(worldPos);
            }

            //get item
            ListViewItem item = new ListViewItem();

            if (e.Data.GetData(typeof(ListViewItem)) != null)
            {
                item = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
            }

            object selectedObject = null;

            switch ((string)item.Tag)
            {
            case "Light":
                if (level.Lights.Count < 8)
                {
                    Light l = new Light();
                    l.Diffuse              = Color4.White;
                    l.Ambient              = new Color4(0.1f, 0.1f, 0.1f, 1f);
                    l.Position             = new Vector4(worldPos.X, worldPos.Y, 36, 1);
                    l.ConstantAttenuation  = 1f;
                    l.LinearAttenuation    = 1f / 3000f;
                    l.QuadraticAttenuation = 1f / 40000f;
                    level.Lights.Add(l);

                    for (int i = 0; i < 8; i++)
                    {
                        bool inUse = false;
                        for (int j = 0; j < level.Lights.Count; j++)
                        {
                            if (level.Lights[j].Index == i)
                            {
                                inUse = true;
                            }
                        }
                        if (!inUse)
                        {
                            l.Index = i;
                        }
                    }
                    selectedObject = l;
                }
                else
                {
                    MessageBox.Show("To many lights. Max light count is 8.", "Light Count", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                break;

            case "Ball":
                Ball ball = new Ball(worldPos.X, worldPos.Y);
                level.Entities.Add(ball);
                selectedObject = ball;
                break;

            case "Block":
                Block block = new Block(worldPos.X, worldPos.Y);
                level.Entities.Add(block);
                selectedObject = block;
                break;

            case "BreakableDoor":
                BreakableDoor bdoor = new BreakableDoor(worldPos.X, worldPos.Y);
                bdoor.MaxHits = 3;
                level.Entities.Add(bdoor);
                selectedObject = bdoor;
                break;

            case "Button":
                Entities.Button button = new Entities.Button(worldPos.X, worldPos.Y);
                level.Entities.Add(button);
                selectedObject = button;
                break;

            case "Cannon":
                Cannon cannon = new Cannon(worldPos.X, worldPos.Y);
                level.Entities.Add(cannon);
                selectedObject = cannon;
                break;

            case "Door":
                Door door = new Door(worldPos.X, worldPos.Y);
                level.Entities.Add(door);
                selectedObject = door;
                break;

            /*case "LaserShooter":
             *      LaserShooter ls = new LaserShooter(worldPos.X, worldPos.Y);
             *      level.Entities.Add(ls);
             *      selectedObject = ls;
             *      break;*/
            case "Player":
                Player p = new Player(worldPos.X, worldPos.Y);
                level.Entities.Add(p);
                selectedObject = p;
                break;

            /*case "PuzzleBox":
             *      PuzzleBox pb = new PuzzleBox(worldPos.X, worldPos.Y);
             *      level.Entities.Add(pb);
             *      selectedObject = pb;
             *      break;*/
            case "SpikeWall":
                SpikeWall sw = new SpikeWall(worldPos.X, worldPos.Y);
                level.Entities.Add(sw);
                selectedObject = sw;
                break;

            /*case "Teleporter":
             *      Teleporter tp = new Teleporter(worldPos.X, worldPos.Y);
             *      level.Entities.Add(tp);
             *      selectedObject = tp;
             *      break;*/
            case "CauseAND":
                CauseAND cAnd = new CauseAND();
                level.Causes.Add(cAnd);
                selectedObject = cAnd;
                break;

            case "CauseNOT":
                CauseNOT cNot = new CauseNOT();
                level.Causes.Add(cNot);
                selectedObject = cNot;
                break;

            case "CauseOR":
                CauseOR cOr = new CauseOR();
                level.Causes.Add(cOr);
                selectedObject = cOr;
                break;

            case "CauseXOR":
                CauseXOR cXor = new CauseXOR();
                level.Causes.Add(cXor);
                selectedObject = cXor;
                break;

            case "CauseButton":
                CauseButton cBtn = new CauseButton();
                level.Causes.Add(cBtn);
                selectedObject = cBtn;
                break;

            case "CauseEntityDestruction":
                CauseEntityDestruction cEntD = new CauseEntityDestruction();
                level.Causes.Add(cEntD);
                selectedObject = cEntD;
                break;

            case "CauseLocation":
                CauseLocation cLoc = new CauseLocation();
                level.Causes.Add(cLoc);
                selectedObject = cLoc;
                break;

            case "CauseTimePassed":
                CauseTimePassed cTime = new CauseTimePassed();
                level.Causes.Add(cTime);
                selectedObject = cTime;
                break;

            case "EffectAND":
                EffectAND eAnd = new EffectAND();
                level.Effects.Add(eAnd);
                selectedObject = eAnd;
                break;

            case "EffectList":
                EffectList eList = new EffectList();
                level.Effects.Add(eList);
                selectedObject = eList;
                break;

            case "EffectDoor":
                EffectDoor eDoor = new EffectDoor();
                level.Effects.Add(eDoor);
                selectedObject = eDoor;
                break;

            case "EffectEndGame":
                EffectEndGame eEnd = new EffectEndGame();
                level.Effects.Add(eEnd);
                selectedObject = eEnd;
                break;

            case "EffectRaiseBridge":
                EffectRaiseBridge eBridge = new EffectRaiseBridge();
                level.Effects.Add(eBridge);
                selectedObject = eBridge;
                break;

            case "EffectRemoveEntity":
                EffectRemoveEntity eRemove = new EffectRemoveEntity();
                level.Effects.Add(eRemove);
                selectedObject = eRemove;
                break;

            case "EffectTriggerTimer":
                EffectTriggerTimer eTimer = new EffectTriggerTimer();
                level.Effects.Add(eTimer);
                selectedObject = eTimer;
                break;

            case "Trigger":
                Trigger t = new Trigger();
                level.Triggers.Add(t);
                selectedObject = t;
                break;
            }

            selectedItemProperties.SelectedObject = selectedObject;

            UpdateWorldTree();
        }