示例#1
0
        public override void SizeChanged(BaseEventArgs e)
        {
            base.SizeChanged(e);
            if (Size.Width == 50 && Size.Height == 50)
            {
                return;
            }
            GridLayout.SetSize(this.Size);
            PositionMap();

            (Sprites["hslider"].Bitmap as SolidBitmap).SetSize(HScrollContainer.Size);
            Sprites["hslider"].Y = MainContainer.Size.Height + 1;

            (Sprites["vslider"].Bitmap as SolidBitmap).SetSize(VScrollContainer.Size);
            Sprites["vslider"].X = MainContainer.Size.Width + 1;

            Sprites["block"].X = Sprites["vslider"].X - 1;
            Sprites["block"].Y = Sprites["hslider"].Y - 1;

            MainContainer.HScrollBar.SetWidth(HScrollContainer.Size.Width - 2);
            MainContainer.VScrollBar.SetHeight(VScrollContainer.Size.Height - 2);

            Fade.SetSize(MainContainer.Size);
        }
示例#2
0
        public override void SizeChanged(BaseEventArgs e)
        {
            base.SizeChanged(e);

            VignetteFade.SetSize(this.Size);

            #region Sidebar
            Sprites["sidebar"].SrcRect.Height = Sprites["sidebar"].Bitmap.Height;
            if (Size.Height <= Sprites["sidebar"].Bitmap.Height)
            {
                Sprites["sidebar"].SrcRect.Height = Size.Height;
            }
            else
            {
                double factor = Size.Height / (double)Sprites["sidebar"].Bitmap.Height;
                Sprites["sidebar"].ZoomY = factor;
            }
            #endregion

            #region Map
            if (Sprites["map"].Bitmap != null)
            {
                int    dx = Size.Width - Sprites["map"].Bitmap.Width;
                int    dy = Size.Height - Sprites["map"].Bitmap.Height;
                double px = dx / (double)Sprites["map"].Bitmap.Width;
                double py = dy / (double)Sprites["map"].Bitmap.Height;
                if (dx != 0 || dy != 0)
                {
                    // Zooms the sprite (maintaining aspect ratio) and centers it
                    if (px > py)
                    {
                        Sprites["map"].ZoomX = Sprites["map"].ZoomY = 1 + px;
                    }
                    else
                    {
                        Sprites["map"].ZoomX = Sprites["map"].ZoomY = 1 + py;
                    }
                    Sprites["map"].X = Size.Width / 2 - (int)Math.Round(Sprites["map"].Bitmap.Width * Sprites["map"].ZoomX / 2d);
                    Sprites["map"].Y = Size.Height / 2 - (int)Math.Round(Sprites["map"].Bitmap.Height * Sprites["map"].ZoomY / 2d);
                }
            }
            #endregion

            #region Recent Files
            if (Sprites["files"].Bitmap != null)
            {
                Sprites["files"].Bitmap.Dispose();
            }
            int height = Size.Height - 190;
            if (height < 1)
            {
                return;
            }
            RecentCapacity          = (int)Math.Floor(height / 48d);
            Sprites["files"].Bitmap = new Bitmap(314, 48 * RecentCapacity);
            Sprites["files"].Bitmap.Unlock();
            Font boldfont    = Font.Get("Fonts/Ubuntu-B", 16);
            Font regularfont = Font.Get("Fonts/ProductSans-M", 14);
            for (int i = 0; i < Editor.GeneralSettings.RecentFiles.Count; i++)
            {
                if (i >= RecentCapacity)
                {
                    break;
                }
                string name        = Editor.GeneralSettings.RecentFiles[i][0];
                string projectpath = Editor.GeneralSettings.RecentFiles[i][1];
                while (projectpath.Contains("\\"))
                {
                    projectpath = projectpath.Replace("\\", "/");
                }
                Sprites["files"].Bitmap.Font = boldfont;
                Sprites["files"].Bitmap.DrawText(name, 0, 48 * i + 4, Color.WHITE);
                Sprites["files"].Bitmap.Font = regularfont;
                List <string> folders = projectpath.Split('/').ToList();
                string        path    = "";
                for (int j = folders.Count - 2; j >= 0; j--)
                {
                    string add = "/";
                    if (folders[j].Contains(":"))
                    {
                        add = "";
                    }
                    Size s = Sprites["files"].Bitmap.Font.TextSize(add + folders[j] + path);
                    if (s.Width > Sprites["files"].Bitmap.Width - 39)
                    {
                        path = "..." + path;
                        break;
                    }
                    else
                    {
                        path = add + folders[j] + path;
                    }
                }
                Sprites["files"].Bitmap.DrawText(path, 30, 48 * i + 22, Color.WHITE);
            }
            Sprites["files"].Bitmap.Lock();
            NoProjects.SetVisible(Editor.GeneralSettings.RecentFiles.Count == 0);
            #endregion

            #region Buttons
            int windowheight = Window.Height;

            bool Hor3     = true;
            bool CenterY  = false;
            bool Hor2Ver1 = false;
            bool Ver3     = false;
            bool Invis    = false;
            bool HorSM    = true;
            bool VerSM    = false;
            bool InvisSM  = false;

            if (Size.Width < 1180)
            {
                Hor3     = false;
                Hor2Ver1 = true;
            }
            if (Size.Width < 930)
            {
                Hor2Ver1 = false;
                Ver3     = true;
                HorSM    = false;
                VerSM    = true;
            }
            if (Size.Width < 860)
            {
                VerSM   = false;
                InvisSM = true;
            }
            if (Size.Width < 780)
            {
                Ver3    = false;
                Invis   = true;
                InvisSM = false;
                VerSM   = true;
            }

            if (Hor3 && HorSM && windowheight < 500)
            {
                HorSM   = false;
                InvisSM = true;
                CenterY = true;
                if (Size.Width < 1210)
                {
                    Hor3    = false;
                    CenterY = false;
                    VerSM   = true;
                    InvisSM = false;
                    Invis   = true;
                }
                else if (Size.Width >= 1300)
                {
                    VerSM   = true;
                    InvisSM = false;
                }
            }

            if (Hor2Ver1 && windowheight < 650)
            {
                Hor2Ver1 = false;
                Invis    = true;
                HorSM    = false;
                VerSM    = true;
            }

            if (Ver3)
            {
                if (windowheight < 720)
                {
                    Ver3  = false;
                    Invis = true;
                    HorSM = false;
                    VerSM = true;
                }
                else if (windowheight >= 810)
                {
                    VerSM   = false;
                    HorSM   = true;
                    InvisSM = false;
                }
            }

            NewProjectButton.SetVisible(true);
            OpenProjectButton.SetVisible(true);
            TutorialsButton.SetVisible(true);
            if (Hor3)
            {
                int y    = CenterY ? Size.Height / 2 - NewProjectButton.Size.Height / 2 : 108;
                int addx = CenterY ? 30 : 0;
                NewProjectButton.SetPosition(445 + addx, y);
                OpenProjectButton.SetPosition(690 + addx, y);
                TutorialsButton.SetPosition(935 + addx, y);
            }
            else if (Hor2Ver1)
            {
                NewProjectButton.SetPosition(445, 108);
                OpenProjectButton.SetPosition(690, 108);
                TutorialsButton.SetPosition(445, 329);
            }
            else if (Ver3)
            {
                NewProjectButton.SetPosition(520, 4);
                OpenProjectButton.SetPosition(520, 210);
                TutorialsButton.SetPosition(520, 415);
            }
            else if (Invis)
            {
                NewProjectButton.SetVisible(false);
                OpenProjectButton.SetVisible(false);
                TutorialsButton.SetVisible(false);
            }

            YoutubeButton.SetVisible(true);
            TwitterButton.SetVisible(true);
            if (HorSM)
            {
                YoutubeButton.SetPosition(Size.Width - 89, Size.Height - 87);
                TwitterButton.SetPosition(Size.Width - 182, Size.Height - 87);
            }
            else if (VerSM)
            {
                YoutubeButton.SetPosition(Size.Width - 89, Size.Height - 87);
                TwitterButton.SetPosition(Size.Width - 89, Size.Height - 180);
            }
            else if (InvisSM)
            {
                YoutubeButton.SetVisible(false);
                TwitterButton.SetVisible(false);
            }
            #endregion
        }
示例#3
0
        public TilesetEditor(IContainer Parent) : base(Parent)
        {
            Submodes = new SubmodeView(this);
            Submodes.SetHeaderHeight(31);
            Submodes.SetHeaderWidth(96);
            Submodes.SetHeaderSelHeight(1);
            Submodes.SetTextY(6);

            PassageContainer = Submodes.CreateTab("Passage");
            VignetteFade PassageFade = new VignetteFade(PassageContainer);

            PassageContainer.OnSizeChanged += delegate(BaseEventArgs e) { PassageFade.SetSize(PassageContainer.Size); };

            FourDirContainer = Submodes.CreateTab("4-Dir");
            VignetteFade FourDirFade = new VignetteFade(FourDirContainer);

            FourDirContainer.OnSizeChanged += delegate(BaseEventArgs e) { FourDirFade.SetSize(FourDirContainer.Size); };

            //PriorityContainer = Submodes.CreateTab("Priority");
            //VignetteFade PriorityFade = new VignetteFade(PriorityContainer);
            //PriorityContainer.OnSizeChanged += delegate (BaseEventArgs e) { PriorityFade.SetSize(PriorityContainer.Size); };

            //Submodes.CreateTab("Terrain Tag");
            //Submodes.CreateTab("Bush Flag");
            //Submodes.CreateTab("Counter Flag");

            Container PassageSubContainer = new Container(PassageContainer);

            PassageList = new TilesetDisplay(PassageSubContainer);
            PassageList.OnTilesetLoaded += delegate(BaseEventArgs e) { PassageDrawAll(); };
            PassageList.OnTileClicked   += delegate(MouseEventArgs e) { PassageInput(e); };

            Container FourDirSubContainer = new Container(FourDirContainer);

            FourDirList = new TilesetDisplay(FourDirSubContainer);
            FourDirList.OnTilesetLoaded += delegate(BaseEventArgs e) { FourDirDrawAll(); };
            FourDirList.OnTileClicked   += delegate(MouseEventArgs e) { FourDirInput(e); };

            PassageContainer.SetBackgroundColor(28, 50, 73);
            FourDirContainer.SetBackgroundColor(28, 50, 73);
            //PriorityContainer.SetBackgroundColor(28, 50, 73);

            SharedContainer = new Container(this);
            SharedContainer.SetPosition(22, 41);
            SharedContainer.Sprites["bg"] = new Sprite(SharedContainer.Viewport);
            SimpleFade fade = new SimpleFade(SharedContainer);

            fade.SetPosition(4, 4);
            NameLabel = new Label(SharedContainer);
            NameLabel.SetText("Name");
            NameLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14));
            NameLabel.SetPosition(19, 16);
            NameBox = new TextBox(SharedContainer);
            NameBox.SetPosition(19, 40);
            NameBox.SetSize(156, 21);
            NameBox.SetSkin(1);
            // Updates tileset list
            NameBox.OnTextChanged += delegate(BaseEventArgs e)
            {
                if (this.Tileset == null)
                {
                    return;
                }
                this.Tileset.Name = NameBox.Text;
                ListItem item = DBDataList.DataList.Items[TilesetID - 1];
                item.Name = item.Name.Split(':')[0] + ": " + this.Tileset.Name;
                DBDataList.DataList.Redraw();
            };

            GraphicLabel = new Label(SharedContainer);
            GraphicLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14));
            GraphicLabel.SetPosition(19, 79);
            GraphicLabel.SetText("Tileset Graphic");

            GraphicBox = new BrowserBox(SharedContainer);
            GraphicBox.SetPosition(19, 103);
            GraphicBox.SetSize(156, 21);
            GraphicBox.OnDropDownClicked += delegate(BaseEventArgs e)
            {
                OpenFileDialog of = new OpenFileDialog();
                of.SetFilter(new FileFilter("PNG Image", "png"));
                of.SetInitialDirectory(Game.Data.ProjectPath + "/gfx/tilesets");
                of.SetTitle("Pick a tileset...");
                object result = of.Show();
                if (result != null)
                {
                    // Converts path (C:/.../.../tileset_image.png) to filename (tileset_image)
                    string path = result as string;
                    while (path.Contains('\\'))
                    {
                        path = path.Replace('\\', '/');
                    }
                    string[] folders  = path.Split('/');
                    string   file_ext = folders[folders.Length - 1];
                    string[] dots     = file_ext.Split('.');
                    string   file     = "";
                    for (int i = 0; i < dots.Length - 1; i++)
                    {
                        file += dots[i];
                        if (i != dots.Length - 2)
                        {
                            file += '.';
                        }
                    }
                    string tilesetsfolder = Game.Data.ProjectPath + "/gfx/tilesets";
                    // Selected file not in the tilesets folder
                    // Copies source to tilesets folder
                    string chosenparent = System.IO.Directory.GetParent(path).FullName;
                    while (chosenparent.Contains('\\'))
                    {
                        chosenparent = chosenparent.Replace('\\', '/');
                    }
                    if (chosenparent != tilesetsfolder)
                    {
                        MessageBox box = new MessageBox("Error",
                                                        "The selected file doesn't exist in the gfx/tilesets folder. Would you like to copy it in?", ButtonType.YesNo);
                        box.OnButtonPressed += delegate(BaseEventArgs e)
                        {
                            if (box.Result == 0) // Yes
                            {
                                string newfilename = null;
                                if (System.IO.File.Exists(tilesetsfolder + "/" + file_ext))
                                {
                                    int iterator = 1;
                                    while (string.IsNullOrEmpty(newfilename))
                                    {
                                        if (!System.IO.File.Exists(tilesetsfolder + "/" + file + " (" + iterator.ToString() + ")." + dots[dots.Length - 1]))
                                        {
                                            newfilename = tilesetsfolder + "/" + file + " (" + iterator.ToString() + ")." + dots[dots.Length - 1];
                                            file        = file + " (" + iterator.ToString() + ")";
                                        }
                                        iterator++;
                                    }
                                }
                                else
                                {
                                    newfilename = tilesetsfolder + "/" + file_ext;
                                }
                                System.IO.File.Copy(path, newfilename);
                                SetTilesetGraphic(file);
                            }
                        };
                    }
                    // File is in tilesets folder
                    else
                    {
                        SetTilesetGraphic(file);
                    }
                }
            };
            // Updates graphic if typed
            GraphicBox.TextArea.OnWidgetDeselected += delegate(BaseEventArgs e)
            {
                string file = GraphicBox.Text;
                if (!System.IO.File.Exists(Game.Data.ProjectPath + "/gfx/tilesets/" + file + ".png"))
                {
                    new MessageBox("Error", "No tileset with the name '" + file + "' exists in gfx/tilesets.", IconType.Error);
                }
                else
                {
                    SetTilesetGraphic(file);
                }
            };

            ClearTilesetButton = new Button(SharedContainer);
            ClearTilesetButton.SetPosition(25, 150);
            ClearTilesetButton.SetSize(140, 44);
            ClearTilesetButton.SetFont(Font.Get("Fonts/Ubuntu-B", 16));
            ClearTilesetButton.SetText("Clear Tileset");
            ClearTilesetButton.OnClicked += delegate(BaseEventArgs e)
            {
                ConfirmClearTileset();
            };

            Submodes.SelectTab(1);
        }