# Simple Script to add Items to the PartyLine PopUp menu
# and the PlayerList PopUp menu

## CONFIGURATION ##

set popups(Actions^Smile) { plinemsg ":)" }
set popups(Actions^Frown) { plinemsg ":(" }
set popups(Actions^Dance) { plineact "Dances the boogie woogie!" }
set popups(Servers^Connect^TetriNET.us) { doconnect TetriNET.us }
set popups(Servers^Connect^Tetridome.com) { doconnect Tetridome.com } ;# See Below for doconnect procedure
set popups(Servers^Connect^TSrv.com) { doconnect TSrv.com }
set popups(Servers^Connect^TetriNET.de) { doconnect TetriNET.de }
set popups(Servers^Connect^server.blocktrix.org) { doconnect server.blocktrix.org Blocktrix }
set popups(Servers^Disconnect) { catch "disconnect" }
set popups(Client\ Commands^Rehash) { catch "rehash" }
set popups(Server\ Commands^/Who) { plinemsg "/who" }
set popups(Server\ Commands^/List) { plinemsg "/list" }
set popups(Server\ Commands^/CWho) { plinemsg "/cwho" }
set popups(Server\ Commands^/Motd) { plinemsg "/motd" }
set popups(Server\ Commands^/Help) { plinemsg "/help" }
set popups(Client\ Commands^Version) { plinemsg "[version]" }
set popups(Client\ Commands^ErrorInfo) { plinelog "$errorInfo" }
set playerpopups(Actions^Slap) { popupslap } ;# See Below for popupslap procedure
set playerpopups(Control^Ignore\ User) { popupignore } ;# See Below for popupignore procedure
set playerpopups(Control^Unignore\ User) { popupunignore } ;# See Below for popupunignore procedure
set playerpopups(Team\ With) { popupteamwith } ;# See Below for popupteamwith procedure
set popups(-) ""
set lobbychatpopups(-) ""
set lobbychatpopups(Actions^Smile) { lobbymsg ":)" }
set lobbychatpopups(Actions^Frown) { lobbymsg ":(" }
set lobbychatpopups(Actions^Dance) { lobbyact "Dances the boogie woogie!" }
set lobbyuserpopups(Actions^Slap) { lobbypopupslap } ;# See Below for lobbypopupslap procedure

## END OF CONFIGURATION -- STOP EDITTING ##

describe "Adds Items to the PartyLine PopUp menu"


# This procedure corresponds to the popups(Slap) popup
proc popupslap {} {
  plineact "slaps [selectedplayer] with a large trout"
}

# This procedure corresponds to the lobbyuserpopups(Actions^Slap) popup
proc lobbypopupslap {} {
  lobbyact "slaps [lobbyplayerselected] with a large trout"
}

# This procedure corresponds to the Server Connect popups listed above
proc doconnect {server {mode "TetriNET"}} {
  if {[isconnected]} {
    plinelog "Error: You are already connected to a server. Disconnect first."
    return
  }
  if {[isserver]} {
    plinelog "Error: You are currently in server mode.  Turn off server first."
    return
  }
  setmode $mode
  set res [setserver $server]
  connect
}


# This procedure corresponds to the playerpopups(Control^Ignore\ User) popup
proc popupignore {} {
  set user [selectedplayer]
  regsub -all {(\?|\*|\.|\||\[\|^\|$|\\)} $user {\\\1} user
  if {$user == ""} {
    plinelog "Please select a user in the player list, and try again."
    return
  } elseif {[lsearch [ignorelist] $user] > -1} {
    plinelog "User is already on ignore."
    return
  }
  ignore $user
  plinelog "Added $user to ignorelist."
}


# This procedure corresponds to the playerpopups(Control^UnIgnore\ User) popup
proc popupunignore {} {
  set user [selectedplayer]
  regsub -all {(\?|\*|\.|\||\[\|^\|$|\\)} $user {\\\1} user
  if {$user == ""} {
    plinelog "Please select a user in the player list, and try again."
    return
  } elseif {[lsearch [ignorelist] $user] == -1} {
    plinelog "User is not currently being ignored."
    return
  }
  unignore $user
  plinelog "Removed $user from ignorelist."
}

# This procedure corresponds to the playerpopups(Team\ With) popup
proc popupteamwith {} {
  set user [selectedplayer]
  if {$user == ""} {
    plinelog "Please select a user in the player list, and try again."
    return
  }
  set newteam [getteam $user]
  if {$newteam == ""} {
    plinelog "$user is not on a team."
    return
  }
  if {[isserver]} {
    set mynick [setservernick]
  } else {
    set mynick [setnick]
  }
  if {[getteam $mynick] == $newteam} {
    plinelog "You are already on the same team as $user\."
    return
  }
  if {[inprogress]} {
    plinelog "You may not change teams while game is in progress."
    return
  }
  if {[catch {setteam $newteam} err]} {
    plinelog "$err"
  }
}


# This procedure adds our defined popups above to the popup menus
proc popupload {} {
  global popups playerpopups lobbychatpopups lobbyuserpopups
  foreach item [lsort [array names popups]] {
    addmenuitem "$item" "[string trim $popups($item)]"
  }
  foreach item [lsort [array names playerpopups]] {
   addplayeritem "$item" "[string trim $playerpopups($item)]"
  }
  foreach item [lsort [array names lobbychatpopups]] {
    addlobbychatmenu "$item" "[string trim $lobbychatpopups($item)]"
  }
  foreach item [lsort [array names lobbyuserpopups]] {
    addlobbyusermenu "$item" "[string trim $lobbyuserpopups($item)]"
  }
}
popupload


plinelog "popups.tcl v1.3 by strikelight now loaded"
