public void Close(bool force = false) { try { var player = CAMain.PlayerList[this.PlayerID]; if (player != null) { MenuEventArgs args = new MenuEventArgs(this.contents, this.PlayerID, -1, (force)?MenuStatus.ForceExit:MenuStatus.Exit); if (this.MenuActionHandler != null) this.MenuActionHandler(this, args); if (force || !args.Handled) { player.InMenu = false; player.Menu = null; if (!player.quitting) CAMain.DisplayLog(player, 7); } } } catch (Exception ex) { Log.ConsoleError(ex.ToString()); } }
public static void OnMenu(Object menu, MenuEventArgs args) { var player = PlayerList[args.PlayerID]; if (player != null) { if (args.Status == MenuStatus.Exit) { player.ClearOutline(); player.Menu = null; return; } else if (args.Status == MenuStatus.Select && args.Selected >= 0 && args.Selected < args.Data.Count) { player.Menu = (Menu)menu; int value = args.Data[args.Selected].Value; switch (value) { case -1: { player.CloseMenu(); break; } case 1: // Main Menu { player.Menu.title = "Factions"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("[ Plot information & management ]", 2, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Faction information & management ]", 3, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Player information & management ]", 4, Color.LightGray)); /* if (player.TSplayer.Group.Name == "superadmin" || player.TSplayer.Group.HasPermission("factions.admin")) player.Menu.contents.Add(new MenuItem("Factions Administration", 9, Color.LightGray));*/ player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 2: // plot manager { DisplayRegionInfo(player); args.Handled = true; break; } case 20: // buying plot { int price = GetPlotPrice(player, new Point(player.TSplayer.TileX, player.TSplayer.TileY)); if (price < 0) return; player.Menu.contents.Clear(); OutlineRegion(player); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem(String.Format("Buy this plot for {0} power?", price), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Yes ]", 21, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ No ]", 2, Color.DarkRed)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 21: // claim plot { int price = GetPlotPrice(player, new Point(player.TSplayer.TileX, player.TSplayer.TileY)); if (price < 0) return; if ((player.Faction == null && player.ChangePower(-1 * price)) || (player.Faction != null && player.Faction.IsAdmin(player.UserID) && player.Faction.RemovePower(price))) { AddRegion(player); DisplayRegionInfo(player); args.Handled = true; } break; } case 22: // unclaim plot { player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Are you sure you want to unclaim this land?", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Yes ]", 23, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ No ]", 2, Color.DarkRed)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 23: // unclaim plot confirmation { var region = Region.GetRegionFromLocation(player.TSplayer.TileX, player.TSplayer.TileY); if (region.ID != -1) { if ((region.Owner != 0 && player.UserID == region.Owner) || (region.Faction != 0 && player.Faction != null && player.Faction.ID == region.Faction && player.Faction.IsAdmin(player.UserID))) { if (UnclaimRegion(region)) { DisplayRegionInfo(player); args.Handled = true; } else player.TSplayer.SendMessage("Error: Could not unclaim region", Color.Red); } } break; } case 3: // faction management { player.Menu.title = "Faction Manager"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("[ Faction List ]", 31, Color.LightGray)); if (player.Faction != null) player.Menu.contents.Add(new MenuItem("[ My Faction ]", 33, Color.LightGray)); else player.Menu.contents.Add(new MenuItem("[ New Faction ]", 32, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 1, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 4: //player management { player.changingMoney = false; player.Menu.title = "Player information"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem(String.Format("Power: {0}", player.Power), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("[ Convert gold to Power ]", player.Power), 41, Color.LightGray)); if (player.Faction != null) player.Menu.contents.Add(new MenuItem(String.Format("[ My faction: {0} ]", player.Faction.Name), 33, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 1, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 41: // convert money to power { player.changingMoney = true; player.Menu.title = "Player information"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Drop gold from your inventory", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("to exchange it for Power.", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("1 Gold = 2 Power", 0, false, Color.Goldenrod)); player.Menu.contents.Add(new MenuItem("Click [Back] when you're done", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 4, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } /*case 9: //admin { break; */ case 31: // List Factions { player.Menu.title = "Faction List"; var factname = player.Menu.GetItemByValue(3101); player.Menu.contents.Clear(); player.Menu.index = 0; foreach (Faction fact in Faction.GetTopFactionsByPower()) { if (factname != null && factname.Text == fact.Name) player.Menu.index = player.Menu.contents.Count; var menuI = new MenuItem("- @0", 310, Color.Gray); menuI.Input = fact.Name; player.Menu.contents.Add(menuI); player.Menu.contents.Add(new MenuItem(String.Format(" Power: {0}, Members: {1}", fact.Power, fact.Members.Count), 0, false, Color.LightGray)); } player.Menu.contents.Add(new MenuItem("[ <- Back ]", 3, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 310: // Faction Information { var faction = Faction.GetFactionByName(args.Data[args.Selected].Input); if (faction != null) { player.Menu.title = "Faction information"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem(faction.Name, 3101, false, Color.YellowGreen)); player.Menu.contents.Add(new MenuItem(String.Format(" \"{0}\"", faction.Desc), 0, false, Color.Gray)); player.Menu.contents.Add(new MenuItem("", 0, false, Color.White)); player.Menu.contents.Add(new MenuItem(String.Format("Join status: {0}", faction.Private ? "Invite Only" : "Open to all"), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("PVP status: {0}", faction.Hostile ? "Hostile" : "Peaceful"), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Team color: {0}", faction.TeamColor), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Admins ({0}):", faction.Admins.Count), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Join(", ", faction.AdminNames()), 0, false, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem(String.Format("Members ({0}):", faction.Members.Except(faction.Admins).ToList().Count), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Join(", ", faction.MemberNames(true)), 0, false, Color.DarkBlue)); player.Menu.contents.Add(new MenuItem(String.Format("Power: {0}:", faction.Power), 0, false, Color.LightGray)); if (faction.Allies.Count > 0) player.Menu.contents.Add(new MenuItem(String.Format("Allies: {0}:", faction.GetAlliesString()), 0, false, Color.LightGray)); if (faction.Enemies.Count > 0) player.Menu.contents.Add(new MenuItem(String.Format("Enemies: {0}:", faction.GetEnemiesString()), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("", 0, false, Color.White)); if (player.Faction == null) { if (faction.Private) { if (faction.Invites.Contains(player.UserID)) player.Menu.contents.Add(new MenuItem("[ Join ] (You have been invited to join)", 3100, Color.DarkGreen)); else player.Menu.contents.Add(new MenuItem("[ Join ] (To join request invitation from faction Admins)", 0, false, Color.Gray)); } else player.Menu.contents.Add(new MenuItem("[ Join ]", 3100, Color.DarkGreen)); } else if (player.Faction.ID != faction.ID && player.Faction.IsAdmin(player.UserID)) { if (player.Faction.Allies.Contains(faction.ID)) { player.Menu.contents.Add(new MenuItem("[ Revoke Ally status ]", 3103, Color.DarkRed)); } else if (faction.AllyInvites.Contains(player.Faction.ID)) { player.Menu.contents.Add(new MenuItem("Avaiting Ally confirmation", 0, false, Color.LightGray)); } else if (player.Faction.AllyInvites.Contains(faction.ID)) { player.Menu.contents.Add(new MenuItem("[ Confirm Alliance ]", 3102, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ Decline Alliance ]", 3103, Color.DarkRed)); } else if (player.Faction.Enemies.Contains(faction.ID)) { player.Menu.contents.Add(new MenuItem("[ Revoke Enemy status ]", 3105, Color.DarkRed)); } else { player.Menu.contents.Add(new MenuItem("[ Request Alliance ]", 3102, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ Declare War ]", 3104, Color.DarkRed)); } } if (player.Menu.GetItemByValue(1) != null) player.Menu.contents.Add(new MenuItem("[ <- Back ]", 1, Color.BurlyWood)); else player.Menu.contents.Add(new MenuItem("[ <- Back ]", 31, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); } break; } case 3100: // Join Faction { var faction = Faction.GetFactionByName(player.Menu.GetItemByValue(3101).Text); if (faction != null) { if ((faction.Private && faction.Invites.Contains(player.UserID)) || !faction.Private) { player.Menu.title = "Faction information"; player.Menu.contents.Clear(); player.Menu.index = 0; if (faction.AddMember(player)) { player.Menu.contents.Add(new MenuItem(String.Format("Success, you have joined the {0}", faction.Name), 0, false, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ My faction ]", 33, Color.BurlyWood)); } else player.Menu.contents.Add(new MenuItem(String.Format("Error, could not join faction: {0}", faction.Name), 0, false, Color.DarkRed)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 3, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); } } break; } case 3102: // request alliance { try { var faction = Faction.GetFactionByName(player.Menu.GetItemByValue(3101).Text); if (faction != null) { player.Menu.contents.Clear(); player.Menu.index = 0; if (player.Faction.AllyInvites.Contains(faction.ID)) { Faction.AllyFactions(faction, player.Faction); string allyString = String.Format("{0} and {1} are now Allies", player.Faction.Name, faction.Name); player.Menu.contents.Add(new MenuItem(allyString, 0, false, Color.DarkGreen)); TShock.Utils.Broadcast(allyString, Color.DarkGreen); } else { faction.AllyInvites.Add(player.Faction.ID); db.Query("UPDATE factions_Factions SET AllyInvites = @0 WHERE ID = @1", String.Join(",", faction.AllyInvites), faction.ID); player.Menu.contents.Add(new MenuItem("Ally request sent", 0, false, Color.DarkGreen)); faction.MessageMembers(String.Format("Faction '{0}' requests an Alliance with you", player.Faction.Name)); } var backbutton = new MenuItem("[ <- Back to @0 overview ]", 310, Color.BurlyWood); backbutton.Input = faction.Name; player.Menu.contents.Add(backbutton); player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); } } catch (Exception ex) { Log.ConsoleError(ex.ToString()); } break; } case 3103: // revoke alliance { try { var faction = Faction.GetFactionByName(player.Menu.GetItemByValue(3101).Text); if (faction != null) { player.Menu.contents.Clear(); player.Menu.index = 0; Faction.BreakAlly(faction, player.Faction); TShock.Utils.Broadcast(String.Format("Factions {0} and {1} have broken off the Alliance", faction.Name, player.Faction.Name), Color.LightSalmon); player.Menu.contents.Add(new MenuItem(String.Format("You've broken off the alliance with {0}", faction.Name), 0, false, Color.LightGray)); var backbutton = new MenuItem("[ <- Back to @0 overview ]", 310, Color.BurlyWood); backbutton.Input = faction.Name; player.Menu.contents.Add(backbutton); player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); } } catch (Exception ex) { Log.ConsoleError(ex.ToString()); } break; } case 3104: // declare war { try { var faction = Faction.GetFactionByName(player.Menu.GetItemByValue(3101).Text); if (faction != null) { player.Menu.contents.Clear(); player.Menu.index = 0; player.Faction.Enemies.Add(faction.ID); db.Query("UPDATE factions_Factions SET Enemies = @0 WHERE ID = @1", String.Join(",", player.Faction.Enemies), player.Faction.ID); TShock.Utils.Broadcast(String.Format("Faction {0} has declared war on {1}", player.Faction.Name, faction.Name), Color.LightSalmon); player.Menu.contents.Add(new MenuItem(String.Format("You are now at war with {0}", faction.Name), 0, false, Color.LightGray)); var backbutton = new MenuItem("[ <- Back to @0 overview ]", 310, Color.BurlyWood); backbutton.Input = faction.Name; player.Menu.contents.Add(backbutton); player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); } } catch (Exception ex) { Log.ConsoleError(ex.ToString()); } break; } case 3105: // revoke enemy { try { var faction = Faction.GetFactionByName(player.Menu.GetItemByValue(3101).Text); if (faction != null) { player.Menu.contents.Clear(); player.Menu.index = 0; player.Faction.Enemies.Remove(faction.ID); db.Query("UPDATE factions_Factions SET Enemies = @0 WHERE ID = @1", String.Join(",", player.Faction.Enemies), player.Faction.ID); TShock.Utils.Broadcast(String.Format("Faction {0} has declared neutral towards {1}", player.Faction.Name, faction.Name), Color.LightSalmon); player.Menu.contents.Add(new MenuItem(String.Format("You are now at neutral towards {0}", faction.Name), 0, false, Color.LightGray)); var backbutton = new MenuItem("[ <- Back to @0 overview ]", 310, Color.BurlyWood); backbutton.Input = faction.Name; player.Menu.contents.Add(backbutton); player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); } } catch (Exception ex) { Log.ConsoleError(ex.ToString()); } break; } case 32: // New Faction { player.Menu.title = "Faction Creator"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Name: ", 321, false, true, Color.LightGray)); player.Menu.contents.Add(new MenuItem("Description: ", 322, false, true, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Create ]", 320, false, Color.BurlyWood)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 3, true, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 320: // Create faction { var nameitem = player.Menu.GetItemByValue(321); var descitem = player.Menu.GetItemByValue(322); if (descitem == null || nameitem == null) break; MenuItem newNameItem = new MenuItem(nameitem); MenuItem newDescItem = new MenuItem(descitem); player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Notice:", 0, false, Color.Red)); player.Menu.contents.Add(new MenuItem("+------------------------------------------------+", 0, false, Color.LightSalmon)); player.Menu.contents.Add(new MenuItem("| If you already own any regions, they will get deleted |", 0, false, Color.LightSalmon)); player.Menu.contents.Add(new MenuItem("| and be made available for anyone to aquire. |", 0, false, Color.LightSalmon)); player.Menu.contents.Add(new MenuItem("| Number of allowed regions for Factions = number of faction members |", 0, false, Color.LightSalmon)); player.Menu.contents.Add(new MenuItem("+------------------------------------------------+", 0, false, Color.LightSalmon)); player.Menu.contents.Add(new MenuItem("", 0, false, Color.LightGray)); newNameItem.Text = " Name: <@0> "; newNameItem.Color = Color.LightGray; newNameItem.Writable = false; player.Menu.contents.Add(newNameItem); newDescItem.Text = " Description: <@0> "; newDescItem.Color = Color.LightGray; newDescItem.Writable = false; player.Menu.contents.Add(newDescItem); player.Menu.contents.Add(new MenuItem("", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("Accept & Create a faction:", 0, false, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("Yes", 325, Color.BurlyWood)); player.Menu.contents.Add(new MenuItem("No", -1, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 325: // faction create confirmation { String newFactName = player.Menu.GetItemByValue(321).Input; String newFactDesc = player.Menu.GetItemByValue(322).Input; if (Faction.GetFactionByName(newFactName) == null) { db.Query("INSERT INTO factions_Factions (Name, Description, Members, Admins, Power, Flags, WorldID) VALUES (@0, @1, @2, @3, @4, @5, @6)", newFactName, newFactDesc, player.TSplayer.UserID, player.TSplayer.UserID, player.Power, 0, Main.worldID); int newFactID = -1; using (QueryResult reader = db.QueryReader("SELECT ID FROM factions_Factions WHERE Name = @0", newFactName)) { if (reader.Read()) { newFactID = reader.Get<int>("ID"); } } if (newFactID != -1) { Faction newFaction = new Faction(newFactID, newFactName, newFactDesc, player); FactionList.Add(newFaction); player.Faction = newFaction; player.TSplayer.SendMessage("Faction created"); var playerregions = Region.GetRegionsByUserID(player.UserID); foreach (Region region in playerregions) { UnclaimRegion(region); } newFaction.RefreshPVPStatus(); newFaction.RefreshTeamStatus(); } } break; } case 33: // Your Faction { if (player.Faction != null) { player.Menu.title = "Your Faction"; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem(player.Faction.Name, 0, false, false, Color.GreenYellow)); player.Menu.contents.Add(new MenuItem(String.Format(" \"{0}\"", player.Faction.Desc), 0, false, false, Color.Gray)); player.Menu.contents.Add(new MenuItem("", 0, false, false)); player.Menu.contents.Add(new MenuItem(String.Format("Join status: {0}", player.Faction.Private ? "Invite Only" : "Open to all"), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("PVP status: {0}", player.Faction.Hostile ? "Hostile" : "Peaceful"), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Team color: {0}", player.Faction.TeamColor), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Admins ({0}):", player.Faction.Admins.Count), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Join(", ", player.Faction.AdminNames()), 0, false, false, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem(String.Format("Members ({0}):", player.Faction.Members.Except(player.Faction.Admins).ToList().Count), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Join(", ", player.Faction.MemberNames(true)), 0, false, Color.DarkBlue)); player.Menu.contents.Add(new MenuItem(String.Format("Power: {0}", player.Faction.Power), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Territory: {0}/{1}", player.Faction.Regions.Count, player.Faction.Members.Count), 0, false, Color.LightGray)); if (player.Faction.Allies.Count > 0) player.Menu.contents.Add(new MenuItem(String.Format("Allies: {0}:", player.Faction.GetAlliesString()), 0, false, Color.LightGray)); if (player.Faction.Enemies.Count > 0) player.Menu.contents.Add(new MenuItem(String.Format("Enemies: {0}:", player.Faction.GetEnemiesString()), 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("", 0, false, Color.White)); if (player.Faction.IsAdmin(player.TSplayer.UserID)) player.Menu.contents.Add(new MenuItem("[ Faction Settings ]", 30, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Leave Faction ]", 35, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 3, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); } break; } case 35: // leave faction { player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Are you sure you want to leave the faction?", 0, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Yes ]", 36, Color.DarkGreen)); player.Menu.contents.Add(new MenuItem("[ No ]", 33, Color.DarkRed)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 36: // leave faction confirmation { if (player.Faction != null) player.Faction.RemoveMember(player.UserID); break; } case 30: // Faction Settings (Admins only) { if (!player.Faction.IsAdmin(player.TSplayer.UserID)) break; player.Menu.title = "Faction Settings"; player.Menu.contents.Clear(); player.Menu.index = 0; var nameitem = new MenuItem("Name: @0", 301, false, true, Color.LightGray); nameitem.Input = player.Faction.Name; var descitem = new MenuItem("Desctiption: @0", 302, false, true, Color.LightGray); descitem.Input = player.Faction.Desc; player.Menu.contents.Add(nameitem); player.Menu.contents.Add(descitem); player.Menu.contents.Add(new MenuItem(String.Format("Join status: [{0}]", player.Faction.Private ? "Invite Only" : "Open to all"), 306, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("PvP status: [{0}]", player.Faction.Hostile ? "Hostile" : "Peaceful"), 304, Color.LightGray)); player.Menu.contents.Add(new MenuItem(String.Format("Team color: [{0}]", player.Faction.TeamColor), 305, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ Manage members ]", 303, true, false, Color.LightGray)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 3, true, false, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 303: // Faction Member management { if (!player.Faction.IsAdmin(player.TSplayer.UserID)) break; player.Menu.title = String.Format("{0} Members", player.Faction.Name); player.Menu.contents.Clear(); player.Menu.index = 0; foreach (int userid in player.Faction.Members) { using (QueryResult reader = db.QueryReader("SELECT Name, Power FROM factions_Players WHERE UserID = @0 ORDER BY Name ASC", userid)) { if (reader.Read()) { player.Menu.contents.Add(new MenuItem(String.Format("- (@0) {0} [Power: {1}] {2}", reader.Get<string>("Name"), reader.Get<int>("Power"), (player.Faction.IsAdmin(userid)) ? "<Admin>" : ""), 3030, (player.UserID == userid) ? false : true, Color.BurlyWood)); player.Menu.contents.Last().Input = userid.ToString(); } } } player.Menu.contents.Add(new MenuItem("[ <- Back ]", 30, true, false, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 3030: { if (!player.Faction.IsAdmin(player.TSplayer.UserID)) break; player.Menu.title = String.Format("{0} Members", player.Faction.Name); int userid = 0; if (int.TryParse(args.Data[args.Selected].Input, out userid)) { player.Menu.contents.Clear(); player.Menu.index = 0; using (QueryResult reader = db.QueryReader("SELECT Name, Power FROM factions_Players WHERE UserID = @0", userid)) { if (reader.Read()) { player.Menu.contents.Add(new MenuItem(String.Format("Name: {0} (userID: @0)", reader.Get<string>("Name")), 3035, false, Color.GreenYellow)); player.Menu.contents.Last().Input = userid.ToString(); player.Menu.contents.Add(new MenuItem(String.Format("Power: {0}", reader.Get<int>("Power")), 0, false, Color.LightGray)); if (player.Faction.Admins.Contains(userid)) { player.Menu.contents.Add(new MenuItem("Status: Admin", 0, false, Color.DarkOrange)); player.Menu.contents.Add(new MenuItem("[ Demote to default ]", 3032, Color.BurlyWood)); } else { player.Menu.contents.Add(new MenuItem("Status: Default", 0, false, Color.Gray)); player.Menu.contents.Add(new MenuItem("[ Promote to admin ]", 3032, Color.BurlyWood)); } player.Menu.contents.Add(new MenuItem("[ Kick from Faction ]", 3031, Color.BurlyWood)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 303, Color.BurlyWood)); } } args.Handled = true; player.Menu.DisplayMenu(); } break; } case 3031: //Kick from Faction { int userid = -1; var useridItem = player.Menu.GetItemByValue(3035); if (useridItem != null && player.Faction != null && player.Faction.IsAdmin(player.UserID) && int.TryParse(useridItem.Input, out userid) && player.UserID != userid && player.Faction.Members.Contains(userid)) { player.Faction.RemoveMember(userid); player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Player has been kicked from faction.", 0, false, Color.Green)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 303, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); } break; } case 3032: // promote /demote { int userid = -1; var useridItem = player.Menu.GetItemByValue(3035); if (useridItem != null && player.Faction != null && player.Faction.IsAdmin(player.UserID) && int.TryParse(useridItem.Input, out userid) && player.UserID != userid && player.Faction.Members.Contains(userid)) { player.Menu.contents.Clear(); player.Menu.index = 0; if (player.Faction.Admins.Remove(userid)) player.Menu.contents.Add(new MenuItem("Member demoted to default.", 0, false, Color.LightGray)); else { player.Faction.Admins.Add(userid); player.Menu.contents.Add(new MenuItem("Member promoted to Admin.", 0, false, Color.LightGray)); } db.Query("UPDATE factions_Factions SET Admins = @0 WHERE ID = @1", String.Join(",", player.Faction.Admins), player.Faction.ID); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 303, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); } break; } case 304: // faction pvp status { player.Faction.Hostile = !player.Faction.Hostile; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Faction PVP status has been changed.", 0, false, Color.Green)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 30, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 305: //faction team color { player.Faction.Team = (byte)(player.Faction.Team + 1); player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Faction team color been changed.", 0, false, Color.Green)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 30, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 306: //faction Join status { player.Faction.Private = !player.Faction.Private; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Faction Join status has been changed.", 0, false, Color.Green)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 30, Color.BurlyWood)); args.Handled = true; player.Menu.DisplayMenu(); break; } case 309: // Save faction name & desc { player.Faction.Name = player.Menu.GetItemByValue(301).Input; player.Faction.Desc = player.Menu.GetItemByValue(302).Input; player.Menu.contents.Clear(); player.Menu.index = 0; player.Menu.contents.Add(new MenuItem("Faction settings saved.", 0, false, Color.Green)); player.Menu.contents.Add(new MenuItem("[ <- Back ]", 30, Color.BurlyWood)); player.Menu.contents.Add(new MenuItem("[ Exit ]", -1, Color.Gray)); args.Handled = true; player.Menu.DisplayMenu(); break; } default: { Console.WriteLine("Got value: {0} from menu. Closing", value); player.CloseMenu(); break; } } } else if (args.Status == MenuStatus.Input) { player.Menu = (Menu)menu; int value = args.Data[args.Selected].Value; string input = args.Data[args.Selected].Input; switch (value) { case 301: // Faction name { var saveButton = player.Menu.GetItemByValue(309); if (Faction.IsValidName(input)) { args.Data[args.Selected].Color = Color.Green; if (saveButton == null && player.Menu.GetItemByValue(302).Color != Color.Red) player.Menu.contents.Insert(2, new MenuItem("[ Save & Exit ]", 309, Color.DarkGreen)); } else { args.Data[args.Selected].Color = Color.Red; if (saveButton != null) player.Menu.contents.Remove(saveButton); } break; } case 302: // Faction description { var saveButton = player.Menu.GetItemByValue(309); if (input.Length > 0 && input[0] != ' ') { args.Data[args.Selected].Color = Color.Green; if (saveButton == null && player.Menu.GetItemByValue(301).Color != Color.Red) player.Menu.contents.Insert(2, new MenuItem("[ Save & Exit ]", 309, Color.DarkGreen)); } else { args.Data[args.Selected].Color = Color.Red; if (saveButton != null) player.Menu.contents.Remove(saveButton); } break; } case 321: // new faction name { if (!Faction.IsValidName(input)) { player.Menu.contents[args.Selected].Color = Color.Red; player.Menu.contents[args.Selected].Text = "Name: @0 [invalid]"; } else if (Faction.GetFactionByName(input) == null) { player.Menu.contents[args.Selected].Color = Color.Green; player.Menu.contents[args.Selected].Text = "Name: @0 [ok]"; if (player.Menu.contents[args.Selected + 1].Color != Color.Red) { player.Menu.contents[args.Selected + 2].Color = Color.BurlyWood; player.Menu.contents[args.Selected + 2].Selectable = true; break; } } else { player.Menu.contents[args.Selected].Color = Color.Red; player.Menu.contents[args.Selected].Text = "Name: @0 [taken]"; } player.Menu.contents[args.Selected + 2].Color = Color.Gray; player.Menu.contents[args.Selected + 2].Selectable = false; break; } case 322: // new faction description { if (input.Length > 0 && !input.StartsWith(" ")) { player.Menu.contents[args.Selected].Color = Color.Green; if (player.Menu.contents[args.Selected - 1].Color != Color.Red) { player.Menu.contents[args.Selected + 1].Color = Color.BurlyWood; player.Menu.contents[args.Selected + 1].Selectable = true; break; } } else player.Menu.contents[args.Selected].Color = Color.Red; player.Menu.contents[args.Selected + 1].Color = Color.Gray; player.Menu.contents[args.Selected + 1].Selectable = false; break; } default: { Console.WriteLine("Value: {0}, Input: {1}", value, input); break; } } } else { Log.ConsoleError(String.Format("Got Status {0} from menu", args.Status)); } } }
public void Select() { if (this.contents[this.index].Selectable) { MenuEventArgs args = new MenuEventArgs(this.contents, this.PlayerID, this.index, MenuStatus.Select); if (this.MenuActionHandler != null) this.MenuActionHandler(this, args); } }
internal static void MainMenuCallback(Object m, MenuEventArgs args) { // var player = CAMain.PlayerList[args.PlayerID]; var menu = (Menu)m; if (args.Status == MenuStatus.Select) { var selected = args.Data[args.Selected]; menu.index = 0; switch (selected.Value) { case -1: { menu.Close(true); return; } case 1: // Main menu { menu.title = "Chat Assistant menu"; menu.contents = GetContentsMain(); break; } case 2: // Channel list { menu.title = "Channel list"; menu.contents = GetContentsChannelList((TShock.Players[menu.PlayerID].Group.HasPermission("CA.channel.bypass.hidden")) ? true : false); break; } case 3: // channel chat log { var player = CAMain.PlayerList[menu.PlayerID]; menu.contents = GetContentsLog(player); menu.title = String.Format("Log [{0}]", DateTime.Now.ToString()); menu.index = menu.contents.Count - 1; break; } case 4: // Personal settings { var player = CAMain.PlayerList[menu.PlayerID]; menu.contents = GetContentsPersonalSettings(player); menu.title = "Personal settings"; break; } case 41: // toggle display join/quit msgs { var player = CAMain.PlayerList[menu.PlayerID]; player.Flags ^= PlayerSettings.HideJoinQuitMsg; menu.contents = GetContentsPersonalSettings(player); break; } case 42: // toggle display death msgs { var player = CAMain.PlayerList[menu.PlayerID]; player.Flags ^= PlayerSettings.HideDeathMsg; menu.contents = GetContentsPersonalSettings(player); menu.index = 1; break; } case 43: // display ignore list { var player = CAMain.PlayerList[menu.PlayerID]; menu.contents = GetContentsIgnoreList(player); menu.title = "My ignore list"; break; } default: return; } menu.DisplayMenu(); } }
public void OnInput(String text) { var player = CAMain.PlayerList[this.PlayerID]; if (player != null) { string oldinput = this.contents[this.index].Input; this.contents[this.index].Input = text; MenuEventArgs args = new MenuEventArgs(this.contents, this.PlayerID, this.index, MenuStatus.Input); if (this.MenuActionHandler != null) this.MenuActionHandler(this, args); if (!args.Handled) DisplayMenu(); else this.contents[this.index].Input = oldinput; } }