Sauerworld Forum

BFTP - Favorite Servers GUI

RaZgRiZ

  • *
  • 12
  • +0/-1
BFTP - Favorite Servers GUI
« on: December 06, 2016, 04:23:36 PM »
Introducing the Blast From The Past series, code lost to time and space brought back from beyond the grave, touched up just a little bit to not be as horrible given my new standards and given to you so you might learn a thing or two :P

For this trick, a simple script which a lot of people attempt, but the ones who actually made anything worthwhile can probably be counted on one hand. Favorite Servers GUI!

Now this is fairly straightforward; no fancy icons or excess of code. It's nice, clean and simple. The fields are automatically filled out when you're already connected (except for the name) so you don't have to type them out.





Code: [Select]
init = [ if (=s (getalias $arg1) "") [ $arg1 = $arg2 ] ]
favserv = [ showgui "favserv" ]

init _fs_servers 5
looplist p "serv addr port" [
   loop i 15 [
      init [_fs_@@p@i] ""
   ]
]


newgui favserv [
   guititle "^f2Select your favorite server to connect"
   guibar
   loop i $_fs_servers [
      if (&& [!=s $_fs_serv@i ""] [!=s $_fs_addr@i ""]) [
         guibutton (concat "Connect to^f2" $_fs_serv@i) [
            connect $_fs_addr@i $_fs_port@i
         ] cube
      ]
   ]
   guinoautotab [
      guitab "Config"
      guistayopen [
         guilist [
            guilist [
               guititle "^f2Server Name"
               guibar
               loop i $_fs_servers [
                  guilist [
                     guibutton "" [
                        looplist p "serv addr port" [
                           [_fs_@[p]@@@i] = ""
                        ]
                     ] exit
                     guifield _fs_serv@i 20
                  ]
               ]
            ]
            guibar
            guilist [
               guititle "^f2Address"
               guibar
               loop i $_fs_servers [
                  guifield [_fs_addr@i] 20 [
                     if (=s $_fs_addr@i "") [
                        _fs_addr@@i = (? $isconnected $connectedip "")
                     ]
                  ]
               ]
            ]
            guibar
            guilist [
               guititle "^f2Port"
               guibar
               loop i $_fs_servers [
                  guifield [_fs_port@i] 5 [
                     if (=s $_fs_port@i "") [
                        _fs_port@@i = (? $isconnected $connectedport 28785)
                     ]
                  ]
               ]
            ]
         ]
         guititle
         guilist [
            if (< $_fs_servers 15) [
               guibutton "Add Server" [
                  _fs_servers = (min 15 (+ $_fs_servers 1))
               ]
            ]
            guispring
            if (> $_fs_servers 5) [
               guibutton "Remove Server" [
                  _fs_servers = (max 5 (- $_fs_servers 1))
               ]
            ]
         ]
      ]
   ]
] "Join Server"