Example #1
0
        public MappingWidget(IContainer Parent) : base(Parent)
        {
            Editor.MainWindow.MainEditorWidget = this;
            Grid layout = new Grid(this);

            layout.SetColumns(
                new GridSize(222, Unit.Pixels),
                new GridSize(1, Unit.Pixels),
                new GridSize(1)
                );

            // Left sidebar
            MapSelectPanel = new MapSelectPanel(layout);

            // Left sidebar divider
            Widget LeftSidebarDivider = new Widget(layout);

            LeftSidebarDivider.SetBackgroundColor(28, 50, 73);
            LeftSidebarDivider.SetGridColumn(1);

            Submodes = new SubmodeView(layout);
            Submodes.OnSelectionChanged += delegate(BaseEventArgs e)
            {
                ChangeSubmode();
            };
            Submodes.SetHeaderHeight(31);
            Submodes.SetHeaderSelHeight(1);
            Submodes.SetTextY(6);

            Submodes.SetGridColumn(2);
            Submodes.CreateTab("Tiles");
            //Submodes.CreateTab("Events");
            Submodes.CreateTab("Connections");
            //Submodes.CreateTab("Encounters");
            //Submodes.CreateTab("Properties");
            MapViewerTiles = new MapViewerTiles(Submodes.GetTab(0));
            //MapViewerEvents = new MapViewerEvents(Submodes.GetTab(1));
            MapViewerConnections = new MapViewerConnections(Submodes.GetTab(1));
            //MapViewerEncounters = new MapViewerEncounters(Submodes.GetTab(3));
            //MapViewerProperties = new MapViewerProperties(Submodes.GetTab(4));

            MapImageWidget = new MapImageWidget(MapViewerTiles.MainContainer);
            MapImageWidget.SetZIndex(3); // 1 for normal map connections, 2 for the selected map connection, so 3 for the main map.

            MapViewerTiles.MapWidget = MapImageWidget;
            //MapViewerEvents.MapWidget = MapImageWidget;
            MapViewerConnections.MapWidget = MapImageWidget;
            //MapViewerEncounters.MapWidget = MapImageWidget;
            //mapViewerProperties.MapWidget = MapImageWidget;

            SetHorizontalScroll(0.5);
            SetVerticalScroll(0.5);
        }
Example #2
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);
        }