private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                try
                {
                    String uriDir = uri + listBox1.SelectedItem.ToString() + @"/";

                    var list = new List <string>();
                    // Get the object used to communicate with the server.
                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uriDir);
                    request.Method = WebRequestMethods.Ftp.ListDirectory;

                    // This example assumes the FTP site uses anonymous logon.
                    request.Credentials = new NetworkCredential("Admin", "Bubbi100");

                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                    Stream       responseStream = response.GetResponseStream();
                    StreamReader reader         = new StreamReader(responseStream);

                    List <string> files = new List <string>();

                    string line = reader.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        files.Add(line);
                        line = reader.ReadLine();
                    }

                    Console.WriteLine("Directory List Complete, status: {0}", response.StatusDescription);

                    reader.Close();
                    response.Close();

                    List <String> finalDLlocs = new List <string>();
                    foreach (var item in files)
                    {
                        finalDLlocs.Add(AttemptDownload(uriDir, item));
                    }

                    var map = EditorFileWriter.MapReader(finalDLlocs.Find(loc => loc.EndsWith(".cgmapc", StringComparison.OrdinalIgnoreCase)));

                    richTextBox1.Text = "Succesfully loaded the map :'" + finalDLlocs.Find(loc => loc.EndsWith(".cgmapc", StringComparison.OrdinalIgnoreCase)) + "'";
                }
                catch (Exception)
                {
                }
            }
        }
Beispiel #2
0
        public override void Update(GameTime gameTime, Game1 game)
        {
            if (MapEditor.bIsRunning)
            {
                #region firstrun
                if (firstRun)
                {
                    mapXSizeInput = new ActiveInput("X-Size map: ", "0", Vector2.Zero, game);
                    mapYSizeInput = new ActiveInput("Y-Size map: ", "0", Vector2.Zero, game);
                    mapNameInput  = new ActiveInput("Map name: ", "Map", Vector2.Zero, game);
                    mapXSizeInput.bNumericInputOnly = true;
                    mapYSizeInput.bNumericInputOnly = true;
                    activeInputButtons.Add(mapXSizeInput);
                    activeInputButtons.Add(mapYSizeInput);
                    activeInputButtons.Add(mapNameInput);
                    mapXSizeInput.bHasMinValue = true;
                    mapXSizeInput.minValue     = 1;
                    mapYSizeInput.bHasMinValue = true;
                    mapYSizeInput.minValue     = 1;

                    firstRun = false;

                    localScenes.Add(mapBuilder);
                }
                #endregion

                if (Game1.bIsDebug)
                {
                    openMap.Filter           = "CGMAPC Files (.cgmapc)|*.cgmapc";
                    openMap.InitialDirectory = Game1.rootTBAGW;
                }
                else
                {
                    openMap.Filter           = "CGMAP Files (.cgmap)|*.cgmap";
                    openMap.InitialDirectory = Game1.rootContentExtra;
                }
                openMap.FilterIndex = 1;
                openMap.Multiselect = false;
                saveMap.Filter      = "CGMAP Files (.cgmap)|*.cgmap";
                saveMap.Title       = "Save a CGMAP File";
                if (Game1.bIsDebug)
                {
                    saveMap.InitialDirectory = Game1.rootTBAGW;
                }
                else
                {
                    saveMap.InitialDirectory = Game1.rootContentExtra;
                }

                bool usingActiveInput = false;

                Vector2 EditorCursorPos = Mouse.GetState().Position.ToVector2() + new Vector2(cameraPosX, -cameraPosY);
                loadMapButton.Update(gameTime);
                if (loadMapButton.buttonBox.Contains(EditorCursorPos))
                {
                    if (Mouse.GetState().LeftButton == ButtonState.Pressed && Game1.bIsActive && !KeyboardMouseUtility.AnyButtonsPressed())
                    {
                        System.Windows.Forms.DialogResult testDia = openMap.ShowDialog();

                        if (testDia == System.Windows.Forms.DialogResult.OK && openMap.FileName.Contains(openMap.InitialDirectory))
                        {
                            //  Console.WriteLine("You selected: " + openMap.FileName);
                            loadedMap = EditorFileWriter.MapReader(openMap.FileName);
                        }
                    }
                }

                #region MapEditor only logic

                foreach (var item in activeInputButtons)
                {
                    item.Update(gameTime);
                    item.Contains(EditorCursorPos);
                }

                foreach (var item in activeInputButtons)
                {
                    if (item.bEnableInput)
                    {
                        usingActiveInput = true;
                        break;
                    }
                }

                int i = 0;
                foreach (var item in activeInputButtons)
                {
                    item.position = new Vector2(100, 200 + 75 * i);
                    i++;
                }

                CreateMapButton.position = new Vector2(activeInputButtons[activeInputButtons.Count - 1].position.X, activeInputButtons[activeInputButtons.Count - 1].position.Y + 75);

                CreateMapButton.Update(gameTime);
                if (CreateMapButton.ButtonBox().Contains(EditorCursorPos) && Mouse.GetState().LeftButton == ButtonState.Pressed && !KeyboardMouseUtility.AnyButtonsPressed())
                {
                    bool bCorrectSave = false;
                    while (!bCorrectSave)
                    {
                        try
                        {
                            if (Game1.bIsDebug)
                            {
                                BasicMap newMap = new BasicMap();
                                newMap.mapName           = mapNameInput.ReturnInputString();
                                saveMap.InitialDirectory = Game1.rootTBAGW;
                                System.Windows.Forms.DialogResult dia = saveMap.ShowDialog();
                                if (saveMap.FileName != "" && dia == System.Windows.Forms.DialogResult.OK && saveMap.FileName.StartsWith(saveMap.InitialDirectory))
                                {
                                    newMap.mapName = Path.GetFileNameWithoutExtension(saveMap.FileName);
                                    mapNameInput.AssignInput(Path.GetFileNameWithoutExtension(saveMap.FileName));
                                    //  Console.WriteLine("Line= " + Path.GetDirectoryName(saveMap.FileName));
                                    EditorFileWriter.MapWriter(saveMap.FileName, newMap);
                                    Console.WriteLine(newMap.mapLocation);
                                    loadedMap    = EditorFileWriter.MapReader(saveMap.FileName);;
                                    bCorrectSave = true;
                                }
                                else if (dia == System.Windows.Forms.DialogResult.Cancel)
                                {
                                    bCorrectSave = true;
                                }
                                else
                                {
                                    //  Console.WriteLine("Yow");
                                    System.Windows.Forms.MessageBox.Show("Make sure you save the map within the application folder.");
                                }
                            }
                            else
                            {
                                BasicMap newMap = new BasicMap();
                                newMap.mapName           = mapNameInput.ReturnInputString();
                                saveMap.InitialDirectory = Game1.rootContentExtra;
                                System.Windows.Forms.DialogResult dia = saveMap.ShowDialog();
                                if (saveMap.FileName != "" && dia == System.Windows.Forms.DialogResult.OK && saveMap.FileName.StartsWith(Game1.rootContentExtra))
                                {
                                    newMap.mapName = Path.GetFileNameWithoutExtension(saveMap.FileName);
                                    mapNameInput.AssignInput(Path.GetFileNameWithoutExtension(saveMap.FileName));
                                    //  Console.WriteLine("Line= " + Path.GetDirectoryName(saveMap.FileName));
                                    EditorFileWriter.MapWriter(saveMap.FileName, newMap);
                                    Console.WriteLine(newMap.mapLocation);
                                    loadedMap    = EditorFileWriter.MapReader(saveMap.FileName);;
                                    bCorrectSave = true;
                                }
                                else if (dia == System.Windows.Forms.DialogResult.Cancel)
                                {
                                    bCorrectSave = true;
                                }
                                else
                                {
                                    //  Console.WriteLine("Yow");
                                    System.Windows.Forms.MessageBox.Show("Make sure you save the map within the application folder.");
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.Out.WriteLine("Error:\n" + e);
                        }
                    }
                }

                if (currentScene == 0 && !usingActiveInput)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.S))
                    {
                        cameraPosY -= cameraSpeed;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.Z))
                    {
                        cameraPosY += cameraSpeed;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.Q))
                    {
                        cameraPosX -= cameraSpeed;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.D))
                    {
                        cameraPosX += cameraSpeed;
                    }
                }
                #endregion

                if (loadedMap != default(BasicMap))
                {
                    currentScene     = (int)MapEditor.MapEditorScenes.MapBuilder;
                    bRerunFileLoader = true;
                    mapBuilder.Start(game, loadedMap);
                    loadedMap  = default(BasicMap);
                    bIsRunning = false;
                }



                if (Mouse.GetState().RightButton == ButtonState.Pressed && !KeyboardMouseUtility.AnyButtonsPressed() && currentScene > 0)
                {
                    switch (currentScene)
                    {
                    case (int)MapEditorScenes.MapEditor:
                        System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("You sure want to exit Map editing? NOTE: be sure to save first!", "Leaving", System.Windows.Forms.MessageBoxButtons.YesNo);
                        if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            currentScene--;
                        }
                        else if (dialogResult == System.Windows.Forms.DialogResult.No)
                        {
                            //do something else
                        }

                        break;
                    }
                }
            }
            else if (!MapEditor.bIsRunning)
            {
                mapBuilder.Update(gameTime, game);
            }

            MapEditorMatrix = Matrix.CreateTranslation(-cameraPosX, cameraPosY, 1);
        }