예제 #1
0
        public static void Draw(SpriteBatch spriteBatch, int screenwidth, int screenheight)
        {
            map_.Draw(spriteBatch, screenwidth, screenheight);
            //mouseState_.X <= 100 && mouseState_.Y <= 60
            spriteBatch.Draw(Textures.Pixel_, new Rectangle(0 + (!side_ ? 0 : screenwidth - 105), 0, 105, 55), new Color(0, 0, 0, 128));
            spriteBatch.DrawString(Textures.Font_, "Layer: " + layer_, Vector2.Zero + (!side_ ? Vector2.Zero : new Vector2(screenwidth - 105, 0)), Color.White);
            spriteBatch.DrawString(Textures.Font_, "Content:", new Vector2(0, 30) + (!side_ ? Vector2.Zero : new Vector2(screenwidth - 105, 0)), Color.White);
            int[] content = { contents_[content_].Item1_, -1, -1 };
            new CellEditor(content).Draw(spriteBatch, (int)Textures.Font_.MeasureString("Content:").X + (!side_ ? 0 : screenwidth - 105), 30, 20);
            int n = 0;

            spriteBatch.Draw(Textures.Pixel_, new Rectangle(x_, 55, max_width_ + 30 + 5, 25 * contents_.Count() + 10), new Color(0, 0, 0, 128));
            foreach (var i in contents_)
            {
                if (content_ == n)
                {
                    spriteBatch.Draw(Textures.Pixel_, new Rectangle(x_ + 2, 65 + n * 25 - 3, max_width_ + 30 + 1, 26), new Color(0, 0, 0, 128));
                }
                int[] temp = { i.Item1_, -1, -1 };
                new CellEditor(temp).Draw(spriteBatch, 5 + x_, 65 + n * 25, 20);
                spriteBatch.DrawString(Textures.Font_, i.Item2_, new Vector2(30 + x_, 65 + n * 25), Color.White);
                n++;
            }
            if (MapChooser.Active_)
            {
                MapChooser.Draw(spriteBatch, screenwidth, screenheight);
            }
            else if (EditorOptions.Active_)
            {
                EditorOptions.Draw(spriteBatch, screenwidth, screenheight);
            }
            if (thread_part1_)
            {
                spriteBatch.Draw(Textures.Pixel_, new Rectangle(0, 0, screenwidth, screenheight), new Color(0f, 0f, 0f, shade_));
                Vector2 v = Textures.Font_.MeasureString(thread_part1_str_);
                spriteBatch.DrawString(Textures.Font_, thread_part1_str_, new Vector2(screenwidth, screenheight) / 2 - v / 2, new Color(1f, 1f, 1f, shade_));
            }
            else if (thread_part2_)
            {
                spriteBatch.Draw(Textures.Pixel_, new Rectangle(0, 0, screenwidth, screenheight), new Color(0f, 0f, 0f, shade_));
                Vector2 v = Textures.Font_.MeasureString(thread_part2_str_);
                spriteBatch.DrawString(Textures.Font_, thread_part2_str_, new Vector2(screenwidth, screenheight) / 2 - v / 2, new Color(1f, 1f, 1f, shade_));
            }
        }
예제 #2
0
        public static void Update(int screenwidth, int screenheight)
        {
            mouseState_ = Mouse.GetState();
            if (!thread_part1_ && !thread_part2_)
            {
                if (MapChooser.Active_)
                {
                    MapChooser.Update(screenwidth, screenheight);
                }
                else if (EditorOptions.Active_)
                {
                    EditorOptions.Update(screenwidth, screenheight);
                }
                else
                {
                    #region Zoom
                    if (mouseState_.ScrollWheelValue - oldMouseState_.ScrollWheelValue < 0)
                    {
                        if (Map.Size_ > 2)
                        {
                            Map.Size_--;
                        }
                        int max_shift_x = Math.Max(0, width_ * Map.Size_ - screenwidth);
                        int max_shift_y = Math.Max(0, height_ * Map.Size_ - screenheight);
                        map_.Shift_x_ = Math.Min(max_shift_x, map_.Shift_x_);
                        map_.Shift_y_ = Math.Min(max_shift_y, map_.Shift_y_);
                    }
                    else if (mouseState_.ScrollWheelValue - oldMouseState_.ScrollWheelValue > 0)
                    {
                        if (Map.Size_ < 200)
                        {
                            Map.Size_++;
                        }
                        int max_shift_x = Math.Max(0, width_ * Map.Size_ - screenwidth);
                        int max_shift_y = Math.Max(0, height_ * Map.Size_ - screenheight);
                        map_.Shift_x_ = Math.Min(max_shift_x, map_.Shift_x_);
                        map_.Shift_y_ = Math.Min(max_shift_y, map_.Shift_y_);
                    }
                    #endregion
                    if (mouseState_.X <= 105 && mouseState_.Y <= 55)
                    {
                        side_ = true;
                    }
                    else
                    {
                        side_ = false;
                    }
                    #region Shift
                    if (width_ * Map.Size_ < screenwidth)
                    {
                        map_.F_shift_x_ = -(screenwidth - width_ * Map.Size_) / 2;
                        map_.Shift_x_   = 0;
                    }
                    else
                    {
                        map_.F_shift_x_ = 0;
                        if (mouseState_.X < 100 && map_.Shift_x_ - 4 >= 0)
                        {
                            map_.Shift_x_ -= 4;
                        }
                        if (mouseState_.X >= screenwidth - 100 && map_.Shift_x_ + 4 <= width_ * Map.Size_ - screenwidth)
                        {
                            map_.Shift_x_ += 4;
                        }
                    }
                    if (height_ * Map.Size_ < screenheight)
                    {
                        map_.F_shift_y_ = -(screenheight - height_ * Map.Size_) / 2;
                        map_.Shift_y_   = 0;
                    }
                    else
                    {
                        map_.F_shift_y_ = 0;
                        if (mouseState_.Y < 100 && map_.Shift_y_ - 4 >= 0)
                        {
                            map_.Shift_y_ -= 4;
                        }
                        if (mouseState_.Y >= screenheight - 100 && map_.Shift_y_ + 4 <= height_ * Map.Size_ - screenheight)
                        {
                            map_.Shift_y_ += 4;
                        }
                    }
                    #endregion
                    #region Inputs
                    if (mouseState_.LeftButton == ButtonState.Pressed)
                    {
                        if (Input.IsPressed(Keys.LeftShift) || Input.IsPressed(Keys.RightShift))
                        {
                            map_.SetPosition((mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_);
                        }
                        else
                        {
                            map_.ChangeCell((mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_, layer_, contents_[content_].Item1_);
                        }
                    }
                    else if (mouseState_.RightButton == ButtonState.Pressed)
                    {
                        try
                        {
                            int n = 0;
                            foreach (var w in contents_)
                            {
                                if (w.Item1_ == map_.Cells_[(mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_].Content_[layer_])
                                {
                                    break;
                                }
                                n++;
                            }
                            content_ = n;
                            if (move_panel_.IsAlive)
                            {
                                move_panel_.Abort();
                            }
                            InitThread();
                            move_panel_.Start();
                        }
                        catch { }
                    }
                    if (oldMouseState_.LeftButton == ButtonState.Pressed && mouseState_.LeftButton == ButtonState.Released)
                    {
                        if (contents_[content_].Item1_ == 6)
                        {
                            MapChooser.Initialize(screenwidth, screenheight);
                            MapChooser.Activate();
                        }
                    }
                    if (Input.IsPressedOnce(Keys.Up))
                    {
                        content_--;
                        if (content_ < 0)
                        {
                            content_ = contents_.Count() - 1;
                        }
                        if (move_panel_.IsAlive)
                        {
                            move_panel_.Abort();
                        }
                        InitThread();
                        move_panel_.Start();
                    }
                    else if (Input.IsPressedOnce(Keys.Down))
                    {
                        content_++;
                        content_ %= contents_.Count();
                        if (move_panel_.IsAlive)
                        {
                            move_panel_.Abort();
                        }
                        InitThread();
                        move_panel_.Start();
                    }
                    if (Input.IsPressedOnce(Keys.Right))
                    {
                        layer_ = layer_ == 2 ? layer_ : layer_ + 1; /* FIXME: 3 layers => layer_ == 2 */
                    }
                    else if (Input.IsPressedOnce(Keys.Left))
                    {
                        layer_ = layer_ == 0 ? layer_ : layer_ - 1;
                    }
                    if (Input.IsPressedOnce(Keys.S))
                    {
                        Save();
                    }
                    if (Input.IsPressedOnce(Keys.O))
                    {
                        EditorOptions.Initialize(screenwidth, screenheight);
                        EditorOptions.Activate();
                    }
                    if (Input.IsPressedOnce(Keys.Escape))
                    {
                        Thread thread2 = new Thread(() =>
                        {
                            thread_part1_str_ = "Updating map...";
                            Thread thread1    = new Thread(() =>
                            {
                                thread_part1_ = true;
                                Maps.Initialize(name_);
                                thread_part1_     = false;
                                thread_part2_str_ = "Map updated.";
                                thread_part2_     = true;
                            });
                            thread1.Start();
                            DateTime start = DateTime.Now;
                            while (DateTime.Now - start < new TimeSpan(0, 0, 0, 0, 250))
                            {
                                shade_ = 0.75f * (float)(DateTime.Now - start).TotalMilliseconds / 250f;
                            }
                            while (thread_part1_)
                            {
                                ;
                            }
                            Thread.Sleep(500);
                            start = DateTime.Now;
                            while (DateTime.Now - start < new TimeSpan(0, 0, 0, 0, 250))
                            {
                                shade_ = 0.75f + 0.25f * (float)(DateTime.Now - start).TotalMilliseconds / 250f;
                            }
                            TitleScreen.Initialize();
                            TitleScreen.Activate();
                            Map.Size_ = 20;
                            Thread.Sleep(50);
                            thread_part2_ = false;
                        });
                        thread2.Start();
                    }
                    #endregion
                    #region Auto update layer
                    switch (contents_[content_].Item1_)
                    {
                    case 3:
                    case 7:
                        layer_ = 1;
                        break;

                    case -2:
                        layer_ = 2;
                        break;

                    case 2:
                    case 4:
                    case 5:
                    case 6:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                    case 15:
                    case 16:
                        layer_ = 0;
                        break;

                    default:
                        break;
                    }
                    #endregion
                }
            }
            oldMouseState_ = mouseState_;
        }