Exemple #1
0
        public void SetSelectedIndex(int Index)
        {
            if (Index != Submodes.SelectedIndex)
            {
                Submodes.SelectTab(Index);
            }
            if (MapImageWidget.Parent == ActiveMapViewer.MainContainer)
            {
                return;                                                         // Already selected
            }
            string Submode = new List <string>()
            {
                "TILES", "CONNECTIONS"
            }[Index];

            Editor.ProjectSettings.LastMappingSubmode = Submode;
            MapImageWidget.SetParent(ActiveMapViewer.MainContainer);
            MapImageWidget.SetVisible(true);
            if (ActiveMapViewer.Map != null)
            {
                ActiveMapViewer.PositionMap();
            }

            if (Submode == "TILES") // Select Tiles submode
            {
                for (int i = 0; i < Map.Layers.Count; i++)
                {
                    MapImageWidget.Sprites[i.ToString()].Visible = Map.Layers[i].Visible;
                }
            }
            else // Deselect Tiles submode
            {
            }
            if (Submode == "CONNECTIONS") // Select Connections submode
            {
                MapImageWidget.GridBackground.SetVisible(false);
                for (int i = 0; i < Map.Layers.Count; i++)
                {
                    MapImageWidget.Sprites[i.ToString()].Visible = true;
                }
            }
            else // Deselect Selections submode
            {
                MapImageWidget.GridBackground.SetVisible(Editor.GeneralSettings.ShowGrid);
            }
            MapImageWidget.MapViewer = ActiveMapViewer;
            OldSelectedIndex         = Submodes.SelectedIndex;
        }
        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);
        }