Exemplo n.º 1
0
        public static Map LoadMap(ModAssetInfo mapFile, GameCore game)
        {
            if (mapFile.AssetName == null)
            {
                return(new Map(game));// it's null
            }
            var data = mapFile.ReadAsString();

            var map = new Map(game, MapJSON.Load(data), data);

            map.AssetInfo = mapFile;

            return(map);
        }
Exemplo n.º 2
0
        private void UI_ShowPrimaryMenu()
        {
            _ui.UnwindAndEmpty();
            _ui.GoToPageIfNotThere("mapmakermainmenu", page =>
            {
                page.Element <Button>("LoadMapBtn").Click += (a, b) =>
                {
                    var fd    = new System.Windows.Forms.OpenFileDialog();
                    fd.Filter = "MP Tanks 2D map files (*.json)|*.json";
                    if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (!File.Exists(fd.FileName))
                        {
                            return;
                        }
                        try
                        {
                            _game = _map.CreateFromMap(MapJSON.Load(
                                                           File.ReadAllText(fd.FileName)));
                            _renderer.Game = _game;
                        }
                        catch
                        {
                            _ui.ShowMessageBox("Load error",
                                               "An error occurred while loading that map.",
                                               UserInterface.MessageBoxType.ErrorMessageBox);
                        }
                    }
                };
                page.Element <Button>("SaveMapBtn").Click += (a, b) =>
                {
                    var fd    = new System.Windows.Forms.SaveFileDialog();
                    fd.Filter = "MP Tanks 2D map files (*.json)|*.json";
                    if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (!Directory.Exists(new FileInfo(fd.FileName).Directory.FullName))
                        {
                            return;
                        }
                        try
                        { File.WriteAllText(fd.FileName, _map.GenerateMap(_game)); }
                        catch
                        {
                            _ui.ShowMessageBox("Save error!",
                                               "An error occurred while saving that map for you.",
                                               UserInterface.MessageBoxType.ErrorMessageBox);
                        }
                    }
                };
                page.Element <StackPanel>("ModsListPanel");
                page.Element <Button>("LoadModBtn").Click += (a, b) => UI_LoadMod();
                page.Element <CheckBox>("LockToGridChkBox", elem =>
                {
                    elem.Checked   += (a, b) => UI_LockToGrid = true;
                    elem.Unchecked += (a, b) => UI_LockToGrid = false;
                });
                page.Element <TextBox>("SearchBox", elem =>
                {
                    elem.KeyUp += (a, b) =>
                    {
                        var selector = page.Element <StackPanel>("MapObjectSelectorPanel");
                        foreach (var itm in selector.Children)
                        {
                            var info = Engine.Helpers.ReflectionHelper.GetGameObjectInfo((string)itm.Tag);
                            if (info.DisplayName.ToLower().Contains(elem.Text.ToLower()) ||
                                info.DisplayDescription.ToLower().Contains(elem.Text.ToLower()))
                            {
                                //Visible
                                itm.Visibility = EmptyKeys.UserInterface.Visibility.Visible;
                            }
                            else
                            {
                                itm.Visibility = EmptyKeys.UserInterface.Visibility.Collapsed;
                            }
                        }
                    };
                });
                page.Element <StackPanel>("MapObjectSelectorPanel");

                page.Element <Button>("MoreSettingsBtn").Click += (a, b) => UI_ShowMoreSettingsMenu();
            }, (page, state) =>
            {
                //update types
                var modListPanel = page.Element <StackPanel>("ModsListPanel");
                foreach (var mod in _map.Mods)
                {
                    var existing = modListPanel.Children.FirstOrDefault(a => a.Tag.Equals(mod));
                    if (existing != null)
                    {
                        //it exists, ignore it
                    }
                    else
                    {
                        var tblk        = new TextBlock();
                        tblk.Tag        = mod;
                        tblk.Text       = mod.ModName + "(v" + mod.ModMajor + "." + mod.ModMinor + ")";
                        tblk.FontFamily = new FontFamily("JHUF");
                        tblk.FontSize   = 12;
                        tblk.Foreground = new SolidColorBrush(ColorW.White);
                        tblk.HorizontalContentAlignment = EmptyKeys.UserInterface.HorizontalAlignment.Center;
                        tblk.Padding = new EmptyKeys.UserInterface.Thickness(5);
                        modListPanel.Children.Add(tblk);
                    }
                }
                //update map object types
                var selector = page.Element <StackPanel>("MapObjectSelectorPanel");
                //get all map objects and their information
                foreach (var mapObjReflName in Engine.Maps.MapObjects.MapObject.AvailableTypes.Keys)
                {
                    var info     = Engine.Helpers.ReflectionHelper.GetGameObjectInfo(mapObjReflName);
                    var existing = (Button)selector.Children.FirstOrDefault(a => a.Tag as string == mapObjReflName);
                    if (existing != null)
                    {
                        //It exists, ignore it
                    }
                    else
                    {
                        //create one
                        var btn   = new Button();
                        var panel = new StackPanel();
                        var head  = new TextBlock();
                        var desc  = new TextBlock();

                        head.FontFamily          = new FontFamily("JHUF");
                        head.FontSize            = 12;
                        head.Text                = info.DisplayName;
                        head.Width               = 175;
                        desc.FontFamily          = new FontFamily("JHUF");
                        desc.FontSize            = 12;
                        desc.Text                = UserInterface.SplitStringIntoLines(info.DisplayDescription, 28);
                        desc.Width               = 175;
                        desc.HorizontalAlignment = EmptyKeys.UserInterface.HorizontalAlignment.Center;
                        desc.Foreground          = new SolidColorBrush(new ColorW(Color.Gray.R, Color.Gray.G, Color.Gray.B));

                        panel.Orientation = EmptyKeys.UserInterface.Orientation.Vertical;
                        panel.Width       = 175;
                        panel.Children.Add(head);
                        panel.Children.Add(desc);

                        btn.Content = panel;
                        btn.Width   = 175;

                        btn.Tag     = mapObjReflName;
                        btn.Padding = new EmptyKeys.UserInterface.Thickness(0, 0, 0, 10);

                        btn.Click += (a, b) =>
                        {
                            //Spawn and select an object
                            var reflName = (string)btn.Tag;
                            var obj      = _game.AddMapObject(reflName);
                            obj.Position = UI_ComputeWorldSpaceFromMouse(
                                new Vector2(
                                    Window.ClientBounds.Width / 2,
                                    Window.ClientBounds.Height / 2
                                    ));
                        };

                        selector.Children.Add(btn);
                    }
                }
            });

            _ui.UpdateState(new object());
        }
Exemplo n.º 3
0
        public static Map Load(string map, GameCore game)
        {
            var m = new Map(game, MapJSON.Load(map), map);

            return(m);
        }