Beispiel #1
0
        private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            switch (eventName)
            {
            case "F2KeyPressed":
                Menu menu = new Menu
                {
                    Title    = "Map Editor",
                    SubTitle = "by ~b~Neta"
                };
                if (CurrentMap == null)
                {
                    menu.AddItem(new MenuItem("Create new Map")
                    {
                        SelectEvent      = "createnewtrack",
                        UserInput        = true,
                        DefaultUserInput = "Enter Map Name"
                    });
                    menu.AddItem(new MenuItem("Load Map")
                    {
                        SelectEvent = "loadtrackdialog"
                    });
                    menu.AddItem(new MenuItem("Load MapEditor Map", "~y~Guadmaz Map Editor")
                    {
                        SelectEvent = "loadmapeditordialog"
                    });
                }
                else
                {
                    if (sender.GetObject() == null)
                    {
                        menu.AddItem(new MenuItem("Title", "", CurrentMap.Name)
                        {
                            SelectEvent      = "settracktitle",
                            UserInput        = true,
                            DefaultUserInput = "Enter new Map Title"
                        });
                        menu.AddItem(new MenuItem("Open object placer")
                        {
                            SelectEvent = "forceobjectmenu"
                        });
                        menu.AddItem(new MenuItem("~r~Cancel creation")
                        {
                            SelectEvent = "cancelcreationdialog",
                        });
                        menu.AddItem(new MenuItem("~b~Save Map")
                        {
                            SelectEvent = "savetrack"
                        });
                        menu.AddItem(new MenuItem("~b~Save as MapEditor Map", "~y~Guadmaz Map Editor")
                        {
                            SelectEvent = "savemapeditor"
                        });
                    }
                    else
                    {
                        menu.Items.AddRange(ObjectBuilder.GetEditorMenuItems());     // Menu Item functions not implemented ... todo
                    }
                }
                menu.Show(sender);
                break;

                #region UnloadedTrackMenu
            case "createnewtrack":
            {
                if (CurrentMap != null)
                {
                    return;
                }
                if ((string)arguments[0] == "" || (string)arguments[0] == " " || (string)arguments[0] == "  " || (string)arguments[0] == "Enter Track Name")
                {
                    API.sendNotificationToPlayer(sender, "~r~Name cannot be empty..");
                    return;
                }
                API.sendNotificationToAll("Map creation started. (~b~" + arguments[0] + "~w~)");
                CurrentMap = new Map
                {
                    Name   = (string)arguments[0],
                    Author = sender.socialClubName
                };
                sender.CloseAllMenus();
            }
            break;

            case "loadtrack":
            {
                LoadMapCmd(sender, Convert.ToString(arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "loadmapeditormap":
            {
                LoadEditorMapCmd(sender, Convert.ToString(arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "loadtrackdialog":
            {
                var mapmenu = new Menu("Map List", "Select a Map");
                if (!Directory.Exists("Maps"))
                {
                    Directory.CreateDirectory("Maps");
                    API.shared.consoleOutput("Created Maps Folder at Root Directory");
                }
                var maps = Directory.GetFiles("Maps");
                if (maps.Length <= 0)
                {
                    mapmenu.AddItem(new MenuItem("No maps found..")
                        {
                            SelectEvent = "F2KeyPressed"
                        });
                }
                else
                {
                    foreach (string map in maps)
                    {
                        var mapfile = map.Split('.');
                        mapmenu.AddItem(new MenuItem(mapfile[0])
                            {
                                SelectEvent    = "loadtrack",
                                SelectEventArg = mapfile[0].Split('\\')[1]
                            });
                    }
                }
                mapmenu.Show(sender);
            }
            break;

            case "loadmapeditordialog":
            {
                var mapmenu = new Menu("MapEditor List", "Select a Map");
                if (!Directory.Exists("MapEditorMaps"))
                {
                    Directory.CreateDirectory("MapEditorMaps");
                    API.shared.consoleOutput("Created MapEditorMaps Folder at Root Directory");
                }
                var maps = Directory.GetFiles("MapEditorMaps");
                if (maps.Length <= 0)
                {
                    mapmenu.AddItem(new MenuItem("No maps found..")
                        {
                            SelectEvent = "F2KeyPressed"
                        });
                }
                else
                {
                    foreach (string map in maps)
                    {
                        var mapfile = map.Split('.');
                        mapmenu.AddItem(new MenuItem(mapfile[0])
                            {
                                SelectEvent    = "loadmapeditormap",
                                SelectEventArg = mapfile[0].Split('\\')[1]
                            });
                    }
                }
                mapmenu.Show(sender);
            }
            break;

                #endregion UnloadedTrackMenu
                #region LoadedTrackMenu
            case "forceobjectmenu":
            {
                var objmenu = new Menu("Object Placer");
                objmenu.Items.AddRange(ObjectBuilder.GetEditorMenuItems());
                objmenu.Show(sender);
            }
            break;

            case "savetrack":
            {
                API.sendNotificationToAll($"~o~{sender.name}~w~ saved the map as ~b~Maps/{CurrentMap.Name}.xml");
                SaveRace(sender);
                sender.CloseAllMenus();
            }
            break;

            case "savemapeditor":
            {
                API.sendNotificationToAll($"~o~{sender.name}~w~ saved the map as ~b~MapEditorMaps/{CurrentMap.Name}.xml");
                SaveRace(sender, true);
                sender.CloseAllMenus();
            }
            break;

            case "settracktitle":
            {
                CurrentMap.Name = (string)arguments[0];
                sender.CloseAllMenus();
                API.sendNotificationToAll($"~o~{sender.name}~w~ changed the map name to ~b~{CurrentMap.Name}");
            }
            break;

            case "cancelcreationdialog":
            {
                var cancelmenu = new Menu("Cancel Creation", "Do you want to cancel the creation?");
                cancelmenu.AddItem(new MenuItem("No")
                    {
                        SelectEvent    = "cancelcreation",
                        SelectEventArg = "0"
                    });
                cancelmenu.AddItem(new MenuItem("~r~Yes")
                    {
                        SelectEvent    = "cancelcreation",
                        SelectEventArg = "1"
                    });
                cancelmenu.Show(sender);
            }
            break;

            case "cancelcreation":
            {
                if (Convert.ToInt32((string)arguments[0]) == 1)
                {
                    ClearMap();
                    API.sendNotificationToAll($"Map cleared by ~b~{sender.name}");
                }
                sender.CloseAllMenus();
            }
            break;

                #endregion LoadedTrackMenu
                #region Object Editor
            case "showplacedobjects":
            {
                var placedobjmenu = new Menu("Placed Objects", "Select to Edit");
                Objects.ToList().ForEach(obj =>
                    {
                        placedobjmenu.AddItem(new MenuItem($"ID: {obj.Key}", $"Model: {obj.Value.model}")
                        {
                            SelectEvent    = "placedobjectdialog",
                            SelectEventArg = obj.Key.ToString()
                        });
                    });
                if (placedobjmenu.Items.Count == 0)
                {
                    placedobjmenu.AddItem(new MenuItem("No Objects placed..")
                        {
                            SelectEvent = "forceobjectmenu"
                        });
                }
                placedobjmenu.Show(sender);
            }
            break;

            case "placedobjectdialog":
            {
                int objid           = Convert.ToInt32((string)arguments[0]);
                var placedobjdialog = new Menu("Object ID: " + objid);
                placedobjdialog.AddItem(new MenuItem("~b~Edit")
                    {
                        SelectEvent    = "editobjectfrommenu",
                        SelectEventArg = objid.ToString()
                    });
                placedobjdialog.AddItem(new MenuItem("~y~Copy")
                    {
                        SelectEvent    = "copyobjectfrommenu",
                        SelectEventArg = objid.ToString()
                    });
                placedobjdialog.AddItem(new MenuItem("~r~Delete")
                    {
                        SelectEvent    = "deleteobjectfrommenu",
                        SelectEventArg = objid.ToString()
                    });
                placedobjdialog.Show(sender);
            }
            break;

            case "editobjectfrommenu":
            {
                ObjectBuilder.EditObjectCmd(sender, Convert.ToInt32((string)arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "copyobjectfrommenu":
            {
                ObjectBuilder.CopyObject(sender, Convert.ToInt32((string)arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "deleteobjectfrommenu":
            {
                ObjectBuilder.DeleteObjectCmd(sender, Convert.ToInt32((string)arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "showobjectgallery":
            {
                var objectgallery = new Menu("Object Gallery", "Select a Category");
                ObjectBuilder.ObjectModels.Categories.ForEach(category =>
                    {
                        objectgallery.AddItem(new MenuItem(category.Name, "", $"({category.Models.Count})")
                        {
                            SelectEvent    = "showobjectgallerycategory",
                            SelectEventArg = category.Name
                        });
                    });
                if (objectgallery.Items.Count == 0)
                {
                    objectgallery.AddItem(new MenuItem("No Categories found..")
                        {
                            SelectEvent = "forceobjectmenu"
                        });
                }
                objectgallery.Show(sender);
            }
            break;

            case "showobjectgallerycategory":
            {
                string selectedcategory = (string)arguments[0];
                var    categorygallery  = new Menu(selectedcategory);
                ObjectBuilder.ObjectModels.Categories.First(x => x.Name == selectedcategory).Models.ForEach(model =>
                    {
                        categorygallery.AddItem(new MenuItem(model.Name, $"~b~Model Hash:~w~ {model.ModelHash}")
                        {
                            SelectEvent    = "createobjectfromhash",
                            SelectEventArg = model.ModelHash.ToString()
                        });
                    });
                categorygallery.Show(sender);
            }
            break;

            case "createobjectfromhash":
            {
                ObjectBuilder.AddObjectCmd(sender, Convert.ToInt32((string)arguments[0]));
                sender.CloseAllMenus();
            }
            break;

            case "exitobjecteditor":
            {
                ObjectBuilder.DisableObjectEditor(sender);
                API.sendNotificationToPlayer(sender, "Object Editor ~r~Disabled");
                sender.CloseAllMenus();
            }
            break;

            case "objecteditorhelp":
            {
                API.sendChatMessageToPlayer(sender, "~o~========================================");
                API.sendChatMessageToPlayer(sender, "~o~=========== ~y~Object Editor Help ~o~==========");
                API.sendChatMessageToPlayer(sender, "~o~========================================");
                API.sendChatMessageToPlayer(sender, "~b~NumPad8 ~w~|| ~g~X-Axis +");
                API.sendChatMessageToPlayer(sender, "~b~NumPad2 ~w~|| ~g~X-Axis -");
                API.sendChatMessageToPlayer(sender, "~b~NumPad4 ~w~|| ~g~Y-Axis +");
                API.sendChatMessageToPlayer(sender, "~b~NumPad6 ~w~|| ~g~Y-Axis -");
                API.sendChatMessageToPlayer(sender, "~b~NumPad+ ~w~|| ~g~Z-Axis +");
                API.sendChatMessageToPlayer(sender, "~b~NumPad- ~w~|| ~g~Z-Axis -");
                API.sendChatMessageToPlayer(sender, "~b~NumPad0 ~w~|| ~g~Switch Position/Rotation Mode");
                sender.CloseAllMenus();
            }
            break;
                #endregion Object Editor
            }
        }