# This file is part of CatchX.
#
# CatchX 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 3 of the License, or
# (at your option) any later version.
#
# CatchX 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 CatchX. If not, see <http://www.gnu.org/licenses/>.
import pygtk
import gtk
import os
import xmlrpclib
import time
punkte = {411 : 392, 641 : 553, 943 : 537, 853 : 655, 664 : 796, 638 : 795}
def create_window(window_name):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title(window_name)
window.set_border_width(5)
return window
def init_connection(server):
print("Trying to connect to " + server)
s = xmlrpclib.ServerProxy('http://' + server + ':20211')
ping = s.ping()
if ping != "pong":
print("Error - Couldn't establish a connecting to the server.")
return False
else:
print("Connected to " + server + ':20211')
return s
def get_gamedata(s, password, name):
runs = s.running()
if runs == True:
print "Game is already running"
return "err_running"
playerid = s.connect()
print("Got assigned playerid #" + str(playerid))
auth = s.auth(playerid, password, name)
if auth == False:
print "Wrong password"
return "err_login"
players = s.get_players(playerid)
#print "Players on the server: " + str(players)
return (playerid,players)
def load_maingui(cliwindow, players, playerid): #This is the most complex GUI, the maingui...
cliwindow.maximize() #We need the complete space
size = cliwindow.get_size() #Now get the size of the maximized window
print "WSize = " + str(size)
uppersize = int(((size[0] / 95) *100) + 100)
print uppersize
clibox = gtk.VBox(False, 0)
cliwindow.add(clibox)
mapbox = gtk.VBox(False, 0)
#clibox.add(mapbox)
toolbox = gtk.HBox(False, 0)
#clibox.add(toolbox)
leftdnbox = gtk.VBox(False, 0)
#toolbox.add(leftdnbox)
rightdnbox = gtk.VBox(False, 0)
#toolbox.add(rightdnbox)
image = gtk.Image()
image.set_from_file("map.png")
pixelsize = image.get_pixbuf() # get the size of the picture to adjust the Layout size
pixelwidth = pixelsize.get_width()
pixelheight = pixelsize.get_height()
#Layout and Scrollbar settings
layout = gtk.Layout()
vadjust = layout.get_vadjustment()
hadjust = layout.get_hadjustment()
vadjust.step_increment = 10
hadjust.step_increment = 10
layout.set_size(pixelwidth, pixelheight)
vscrollbar = gtk.VScrollbar(vadjust)
hscrollbar = gtk.HScrollbar(hadjust)
vscrollbar.show()
hscrollbar.show()
layout.set_events(gtk.gdk.BUTTON_PRESS_MASK)
layout.connect("button_press_event", button_press)
layout.put(image, 0, 0)
#packing the layout and the scrollbars in the Table
table = gtk.Table(2, 2, 0)
table.attach(layout, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL, 0, 0)
table.attach(vscrollbar, 1, 2, 0, 1, 0, gtk.EXPAND|gtk.FILL, 0, 0)
table.attach(hscrollbar, 0, 1, 1, 2, gtk.EXPAND|gtk.FILL, 0, 0, 0)
mapbox.pack_end(table)
label3 = gtk.Label(str)
label3.set_text("Right Toolbox")
rightdnbox.add(label3)
#The user-list
liststore = gtk.ListStore(str, str)
treeview = gtk.TreeView(liststore)
tvcolumn = gtk.TreeViewColumn('Id')
tvcolumn1 = gtk.TreeViewColumn('Name')
treeview.append_column(tvcolumn)
treeview.append_column(tvcolumn1)
#print players
for name in players:
liststore.append([name[1], name[0]])
cell = gtk.CellRendererText()
cell1 = gtk.CellRendererText()
#tvcolumn.pack_start(cellpb, False)
tvcolumn.pack_start(cell, True)
tvcolumn1.pack_start(cell1, True)
tvcolumn.set_attributes(cell, text=0)
tvcolumn1.set_attributes(cell1, text=1)
treeview.set_search_column(0)
tvcolumn.set_sort_column_id(0)
leftdnbox.add(treeview)
#
vpan = gtk.VPaned()
vpan.add1(mapbox)
vpan.add2(toolbox)
clibox.add(vpan)
hpan = gtk.HPaned()
hpan.add1(leftdnbox)
hpan.add2(rightdnbox)
toolbox.add(hpan)
vpan.set_position(uppersize)
hpan.set_position(150)
cliwindow.show_all()
def button_press(widget, event):
correct = 0
print event.x, event.y
for xwert, ywert in punkte.items():
if (-10 < (event.x - xwert) < 10) and (-10 < (event.y - ywert)):
correct = 1
if correct == 1:
print "True"
#buttonlist = place_selected()
else:
print "False"
return True
def keepalive(s,pid): # To be improved :D
s.keepalive(pid)
time.sleep(1)
self.keepalive(s, pid)
i = 0
while(True): #infinite loop
i += 1
s.keepalive(pid)
print "Keepalive to Server..."
time.sleep(1)
#def place_selected():
# plane = gtk.Button("plane")
# ship = gtk.Button("ship")
# taxi = gtk.Button("taxi")
# train = gtk.Button("train")
# travel_box = gtk.VBox()
# travel_box.add(plane)
# travel_box.add(ship)
# travel_box.add(train)
# travel_box.add(taxi)
# plane.show()
# ship.show()
# taxi.show()
# train.show()
# travel_box.show()
def load_mappoints():
spots = []
i = 0
point = []
f = file("mapname.mapdata", "r")
while True:
line = f.readline()
if len(line) == 0:
break
point.append(line)
i = i + 1
for n in range(0, len(point)):
point[n] = point[n].split(":")
point[n][1] = (point[n][1].rstrip("\n"))
print point[n]
return point