#!/usr/bin/python ############################################################################ # Copyright (C) 2007 by mots # # i.am.dumb@gmx.net # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the # # Free Software Foundation, Inc., # # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ import wx import ConfigParser import os import string class MainFrame(wx.Frame): def __init__(self, parent, id, title): self.readcfg() self.getdefaultmaps() #Create Stuff wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(350, 350)) self.panel = wx.Panel(self, -1) self.sizer = wx.BoxSizer(wx.VERTICAL) #Mods mod = wx.StaticBox(self.panel, -1, 'Select a mod') self.mod_sizer = wx.StaticBoxSizer(mod) self.selectmod = wx.ListBox(self.panel, 4, choices=self.mods, size=(-1, 80)) #Maps map = wx.StaticBox(self.panel, -1, 'Select a map') self.map_sizer = wx.StaticBoxSizer(map) self.selectmap = wx.ListBox(self.panel, 5, choices=self.maps, size=(-1, 80)) #Buttons buttons = wx.StaticBox(self.panel, -1, '') self.button_sizer = wx.StaticBoxSizer(buttons,) self.quitbutton = wx.Button(self.panel, -1, 'Quit') self.aboutbutton = wx.Button(self.panel, -1, 'About') self.moddetectbutton= wx.Button(self.panel, -1, 'Detect Mods') self.launchbutton = wx.Button(self.panel, -1, 'Launch!') #Netplay net= wx.StaticBox(self.panel, -1, 'Multiplayer') self.net_sizer = wx.StaticBoxSizer(net, wx.VERTICAL) self.cb_sizer = wx.GridSizer(rows=2, cols=2,) self.sv_sizer = wx.StaticBoxSizer(net, wx.HORIZONTAL) self.server = wx.RadioButton(self.panel, -1, 'Connect to Server', style=wx.RB_GROUP) self.splitscreencb = wx.RadioButton(self.panel, -1, 'Splitscreen') self.host = wx.RadioButton(self.panel, -1, 'Host Server') self.single = wx.RadioButton(self.panel, -1, 'SinglePlayer') self.serverip = wx.TextCtrl(self.panel, -1, self.ip, size=(200,-1)) self.register = wx.CheckBox(self.panel, -1, 'Register Online') self.updatevisibility(-1) self.loadcfg() #Set the mod to default in case the user hasn't selected anything self.currentmod= 'default' self.currentmodname= 'Default Gusanos-Mod' #Set the map to blat in case the user hasn't selected anything self.currentmap = 'blat' self.Centre() self.Bind(wx.EVT_BUTTON, self.quit, self.quitbutton) self.Bind(wx.EVT_BUTTON, self.about, self.aboutbutton) self.Bind(wx.EVT_BUTTON, self.launch, self.launchbutton) self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=4) self.Bind(wx.EVT_LISTBOX, self.OnMapSelect, id=5) self.Bind(wx.EVT_BUTTON, self.detectmods, id=6) self.Bind(wx.EVT_RADIOBUTTON, self.updatevisibility) #Layout the previously created stuff self.layoutstuff() if len(self.mods) != len(self.moddirs): warning = wx.MessageDialog(self, "The number of moddirs in your guslauncher.cfg doesn't seem to to be the same as the number of mods!\n\n" 'Please try to fix that, otherwise things might start getting nasty.' ,'Warning!', wx.OK | wx.ICON_WARNING) warning.ShowModal() warning.Destroy() def layoutstuff(self): self.button_sizer.Add(self.quitbutton,1, wx.ALIGN_BOTTOM) self.button_sizer.Add(self.aboutbutton,1, wx.ALIGN_BOTTOM) self.button_sizer.Add(self.moddetectbutton,1, wx.ALIGN_BOTTOM) self.button_sizer.Add(self.launchbutton,1, wx.ALIGN_BOTTOM) self.sizer.Add(self.mod_sizer, 0, wx.EXPAND) self.sizer.Add(self.map_sizer, 0, wx.EXPAND) self.sizer.Add(self.net_sizer, 1, wx.EXPAND) self.sizer.Add(self.button_sizer, 0, wx.EXPAND) self.mod_sizer.Add(self.selectmod, 1) self.map_sizer.Add(self.selectmap, 1) self.cb_sizer.Add(self.server) self.cb_sizer.Add(self.splitscreencb) self.cb_sizer.Add(self.host) self.cb_sizer.Add(self.single) self.sv_sizer.Add(self.serverip) self.sv_sizer.Add(self.register) self.net_sizer.Add(self.cb_sizer, 0,wx.EXPAND) self.net_sizer.Add(self.sv_sizer, 0,wx.EXPAND) self.panel.SetSizer(self.sizer) def detectmods(self, event): newmods = [i for i in os.listdir('.') if os.path.isdir(i)] newmods = list(set(newmods) - set(self.moddirs) -set(['screenshots'])) self.moddirs += newmods self.mods += newmods popup = wx.MessageDialog(self, 'Successfully detected '+str(len(newmods))+' new mod(s).', 'Success!', wx.OK | wx.ICON_INFORMATION) popup.ShowModal() popup.Destroy() self.selectmod.SetItems(self.mods) def updatevisibility(self, event): if self.server.GetValue(): self.serverip.Enable() self.selectmap.Disable() else: self.serverip.Disable() self.selectmap.Enable() if self.host.GetValue(): self.register.Enable() else: self.register.Disable() def readcfg(self): config = ConfigParser.ConfigParser() config.read('guslauncher.cfg') self.ip = config.get('MULTIPLAYER', 'ip') self.mptype = config.get('MULTIPLAYER', 'type') self.register_online = config.get('MULTIPLAYER', 'register_online') self.mods = config.get('MODS','mods').split(',') self.moddirs = config.get('MODS','moddirs').split(',') print 'Loaded cfg:',self.ip, self.mptype, self.mods, self.moddirs,self.register_online def loadcfg(self): if self.mptype == 'connect': self.server.SetValue(True) if self.mptype == 'splitscreen': self.splitscreencb.SetValue(True) if self.mptype == 'host': self.host.SetValue(True) if self.mptype == 'single': self.single.SetValue(True) if self.register_online == 'true': self.register.SetValue(True) else: self.register.SetValue(False) def getdefaultmaps(self): self.defaultmaps = os.listdir('./default/maps') self.defaultmaps.remove('llp') llpmaps =os.listdir('./default/maps/llp') llpmaps = [string[:-4] for string in llpmaps] self.defaultmaps += llpmaps self.defaultmaps.insert(0,'====DEFAULT MAPS====') self.maps = self.defaultmaps def getmodmaps(self): if self.currentmod != 'default': modmaps = os.listdir('./'+self.currentmod+'/maps') if modmaps != []: modmaps.insert(0,'===='+self.currentmodname+'\'s MAPS====') self.maps = self.defaultmaps+modmaps else: self.maps = self.defaultmaps self.selectmap.SetItems(self.maps) def OnSelect(self, event): item = event.GetSelection() self.currentmod= self.moddirs[item] self.currentmodname = self.mods[item] self.getmodmaps() def OnMapSelect(self, event): item = event.GetSelection() if self.maps[item]!='====DEFAULT MAPS====' and self.maps[item]!='===='+self.currentmodname+'\'s MAPS====': self.currentmap = self.maps[item] def quit(self, event): self.savecfg() self.Close(True) def savecfg(self): config = ConfigParser.ConfigParser() config.read('guslauncher.cfg') if self.server.GetValue(): config.set('MULTIPLAYER', 'type', 'connect') if self.splitscreencb.GetValue(): config.set('MULTIPLAYER', 'type', 'splitscreen') if self.host.GetValue(): config.set('MULTIPLAYER', 'type', 'host') if self.single.GetValue(): config.set('MULTIPLAYER', 'type', 'single') config.set('MULTIPLAYER', 'ip', str(self.serverip.GetValue())) if self.register.GetValue(): config.set('MULTIPLAYER', 'register_online', 'true') else: config.set('MULTIPLAYER', 'register_online', 'false') config.set('MODS', 'mods', ','.join(self.mods)) config.set('MODS', 'moddirs', ','.join(self.moddirs)) config.write(open('guslauncher.cfg', 'w')) def launch(self, event): guscmd = './gusanos -c \'game '+string.replace(self.currentmod,"'",'')+'\' -c \'map '+string.replace(self.currentmap,"'",'')+' \''+'-c \'cl_splitscreen ' if self.splitscreencb.GetValue(): guscmd += '1\'' else: guscmd += '0\'' if self.server.GetValue(): guscmd+=' -c'+' \'connect '+str(self.serverip.GetValue())+'\'' if self.host.GetValue(): guscmd += ' -c'+' \'host 1\'' if self.register.GetValue(): guscmd+=' -c'+' \'net_register 1\'' else: guscmd+=' -c'+' \'net_register 0\'' print 'Launching: \''+guscmd + '\'' os.system(guscmd) def about(self): popup = wx.MessageDialog(self, 'Gusanos Launcher by mots\n' 'Version 0.1\n\n' 'visit #liero on irc.quakenet.org for more information', 'About', wx.OK | wx.ICON_INFORMATION) popup.ShowModal() popup.Destroy() class App(wx.App): def OnInit(self): frame = MainFrame(None, -1, 'Gusanos Launcher') frame.Show(True) return True app = App(0) app.MainLoop()