Beispiel #1
0
        public void Update(GameTime gameTime)
        {
            if (Screens.Count > 0)
            {
                Screen foregroundScreen = Screens.Peek();
                List<Screen> Temp = Screens.ToList();
                foreach (Screen screen in Temp)
                {
                    if (screen.State == Screen.States.FullyClosed)
                    {
                        if (screen == foregroundScreen)
                            Screens.Pop();
                        else
                            continue;
                    }
                    screen.Update(gameTime, screen == foregroundScreen);
                }
            }

            if (toOpenWhenCleared != null && Screens.Count == 0)
            {
                OpenScreen(toOpenWhenCleared);
                toOpenWhenCleared = null;
            }
        }
Beispiel #2
0
        public World(Screen screen, XmlDocument doc, XmlElement parent)
        {
            Tiles = new Tile[Width, Height];
            Entities = new Dictionary<int, Entity>();

            gDevice = PokeSiGame.Instance.GraphicsDevice;
            spriteBatch = new SpriteBatch(gDevice);
            renderDone = false;

            Load(doc, parent);

            view = new Rectangle(0, 0, Tile.Width * Width, Tile.Height * Height);

            font = PokeSiGame.Instance.Content.Load<SpriteFont>("Fonts/Hud");
        }
Beispiel #3
0
 public abstract Matrix GetTransformation(Screen screen);
 public override Matrix GetTransformation(Screen screen) 
 {
     return Matrix.Identity;
 }
Beispiel #5
0
        public override void Update(GameTime gameTime, bool isInForeground)
        {
            base.Update(gameTime, isInForeground);

            if (!isInForeground)
            {
                leftButtonRealsed = false;
                return;
            }

            if (lastScreenOpen != null)
            {
                if (lastScreenOpen is AddTileScreen)
                    UpdateDatas();
                lastScreenOpen = null;
            }

            World.Update(gameTime);

            tabPanel.Update(gameTime);
            UpdateTileDataControls();
            UpdateEntityDataControls();
            UpdateLocTileDataControls();

            if (Input.MiddleButton.Down)
            {
                World.MoveView(-Input.XDelta, -Input.YDelta);
            }

            if (!Input.LeftButton.Down)
                leftButtonRealsed = true;
            if (Input.LeftButton.Down && leftButtonRealsed)
            {
                // Set tile
                if (tileList.SelectedItem != null && tabPanel.CurrentPanel == tilePanel)
                {
                    Tile selectedTile = Tile.UnLocatedTile[tileList.SelectedItem];
                    int x = (Input.X - worldBound.X + World.View.X) / Tile.Width;
                    int y = (Input.Y - worldBound.Y + World.View.Y) / Tile.Height;
                    if (worldBound.Contains(Input.X, Input.Y) && (lastXTileSet != x || lastYTileSet != y))
                        World.SetTile(x, y, selectedTile);
                    lastXTileSet = x;
                    lastYTileSet = y;
                }
            }
            if (Input.LeftButton.Pressed)
            {
                lastXTileSet = -1;
                lastYTileSet = -1;

                if (worldBound.Contains(Input.X, Input.Y))
                {
                    // Place entity
                    if (entityToPlace != null)
                    {
                        Vector2 pos = Vector2.Zero;
                        pos.X = Input.X - worldBound.X + World.View.X;
                        pos.Y = Input.Y - worldBound.Y + World.View.Y;
                        entityToPlace.Position = pos;
                        World.Entities.Add(World.GetNextEntityId(), entityToPlace);
                        entityToPlace = null;
                    }
                    // Place LocTile
                    if (locTileToPlace != null)
                    {
                        Vector2 pos = Vector2.Zero;
                        pos.X = (Input.X - worldBound.X + World.View.X) / Tile.Width;
                        pos.Y = (Input.Y - worldBound.Y + World.View.Y) / Tile.Height;
                        World.SetTile((int)pos.X, (int)pos.Y, locTileToPlace);
                        locTileToPlace = null;
                    }
                    // Start Drag and Drop
                    if (selectedEntity != null && selectedEntity is IMoveable && selectedEntity.DestinationRect.Contains(Input.X, Input.Y))
                    {
                        dragingElement = (IMoveable)selectedEntity;
                        dragingStartPos = selectedEntity.Position;
                    }
                    else if (selectedLocTile != null && selectedLocTile is IMoveable && selectedLocTile.Bound.Contains(Input.X, Input.Y))
                    {
                        dragingElement = (IMoveable)selectedLocTile;
                        dragingStartPos = selectedLocTile.Position;
                        World.SetTile((int)selectedLocTile.X, (int)selectedLocTile.Y, null);
                    }
                    // Select IBounded
                    bool foundOne = false;
                    int x = Input.X - worldBound.X;
                    int y = Input.Y - worldBound.Y;
                    foreach (Entity ent in World.Entities.Values)
                    {
                        if (ent is IBounded)
                        {
                            IBounded bounded = (IBounded)ent;
                            if (bounded.Bound.Contains(x, y))
                            {
                                selectedEntity = ent;
                                ReconstructEntityDataPanel();
                                foundOne = true;
                                break;
                            }
                        }
                    }
                    if (!foundOne)
                    {
                        selectedEntity = null;
                        ReconstructEntityDataPanel();
                    }
                    foundOne = false;
                    Tile tile = World.GetTile((x + World.View.X) / Tile.Width, (y + World.View.Y) / Tile.Height);
                    if (tile is LocatedTile && tile is IBounded)
                    {
                        IBounded bounded = (IBounded)tile;
                        if (bounded.Bound.Contains(x, y))
                        {
                            selectedLocTile = (LocatedTile)tile;
                            ReconstructLocTileDataPanel();
                            foundOne = true;
                        }
                    }
                    if (!foundOne && selectedLocTile != dragingElement)
                    {
                        selectedLocTile = null;
                        ReconstructLocTileDataPanel();
                    }
                }
            }
            if (Input.LeftButton.Released)
            {
                if (dragingElement != null)
                {
                    if (worldBound.Contains(Input.X, Input.Y))
                    {
                        if (dragingElement is Entity)
                        {
                            dragingElement.X = Input.X - worldBound.X + World.View.X;
                            dragingElement.Y = Input.Y - worldBound.Y + World.View.Y;
                            ReconstructEntityDataPanel();
                        }
                        if (dragingElement is LocatedTile)
                        {
                            LocatedTile tile = (LocatedTile)dragingElement;
                            World.SetTile((Input.X - worldBound.X + World.View.X) / Tile.Width, (Input.Y - worldBound.Y + World.View.Y) / Tile.Height, tile);
                            ReconstructLocTileDataPanel();
                        }
                        dragingElement = null;
                    }
                    else
                    {
                        dragingElement.X = dragingStartPos.X;
                        dragingElement.Y = dragingStartPos.Y;
                        dragingElement = null;
                    }
                }
            }
            if (tileList.SelectedItem != lastSelectedTile)
            {
                lastSelectedTile = tileList.SelectedItem;
                ReconstructTileDataPanel();
            }

            if (tileAddButton.IsPressed())
            {
                lastScreenOpen = new AddTileScreen(Manager, World.Resources);
                Manager.OpenScreen(lastScreenOpen);
            }
            if (tileRemoveButton.IsPressed())
            {
                if (tileList.SelectedItem != null)
                {
                    Tile.UnLocatedTile.Remove(tileList.SelectedItem);
                    UpdateDatas();
                }
            }
            if (tileDataSubmitButton != null && tileDataForm != null && tileDataSubmitButton.IsPressed())
                SubmitTileData();

            if (entityAddButton.IsPressed())
            {
                Type type = this.GetType().Assembly.GetType(typeof(Entity).Namespace + "." + entityListButton.List[entityListButton.CurrentIndex]);
                if (type != null)
                    entityToPlace = (Entity)type.GetConstructor(new Type[] { typeof(World) }).Invoke(new object[] { World });
            }
            if (entityRemoveButton != null && entityRemoveButton.IsPressed() && selectedEntity != null)
            {
                IEnumerable<KeyValuePair<int, Entity>> result = World.Entities.Where(pair => pair.Value == selectedEntity);
                if (result.Count() > 0)
                    World.Entities.Remove(result.ElementAt(0).Key);
                selectedEntity = null;
                ReconstructEntityDataPanel();
            }
            if (entityDataSubmitButton != null && entityDataForm != null && entityDataSubmitButton.IsPressed())
                SubmitEntityData();

            if (locTileAddButton.IsPressed())
            {
                Type type = this.GetType().Assembly.GetType(typeof(Tile).Namespace + "." + locTileListButton.List[locTileListButton.CurrentIndex]);
                if (type != null)
                    locTileToPlace = (LocatedTile)type.GetConstructor(new Type[] { typeof(World), typeof(int), typeof(int) }).Invoke(new object[] { World, 0, 0 });
            }
            if (locTileRemoveButton != null && locTileRemoveButton.IsPressed() && selectedLocTile != null)
            {
                World.SetTile((int)selectedLocTile.X, (int)selectedLocTile.Y, null);
                selectedLocTile = null;
                ReconstructLocTileDataPanel();
            }
            if (locTileDataSubmitButton != null && locTileDataForm != null && locTileDataSubmitButton.IsPressed())
                SubmitLocTileData();
        }
Beispiel #6
0
 public void CloseAllAndThenOpen(Screen toOpen)
 {
     foreach (Screen toClose in Screens)
         toClose.Close();
     toOpenWhenCleared = toOpen;
 }
Beispiel #7
0
 public void OpenScreen(Screen toOpen)
 {
     Screens.Push(toOpen);
     toOpen.Open();
 }