示例#1
0
	def __init__(self, x, y, w, h, parent=None, gui=None):
		Widget.__init__(self, x, y, w, h, parent)
		self.gui = gui
		self.makeSurface()
		self.entry = TextEntry("", width = w, parent=self)
		self.scrollTextWindow = ScrollTextWindow(0, 0, w, h-20, parent=self)
		
		#print "created chatwindow, after init, w = %s, h = %s, x = %s, y = %s" % (self.w, self.h, self.x, self.y)
		self.entry.setPos(0, self.h-20)
示例#2
0
	def __init__(self, game):
		self.game = game
		self.screen = self.game.screen
		
		screen_w = self.screen.get_width()
		screen_h = self.screen.get_height()
		self.x = 220
		self.y = 180
		self.step1 = 140
		self.step2 = 40
		
		self.title = renderText("LOGIN", FONT_MANGA, True)
		
		self.loginLabel = Label("  Name  ", FONT, width=100)
		self.loginLabel.setPos(self.x,self.y)
		
		self.loginEntry = TextEntry("", width = 180)
		self.loginEntry.setPos(self.x + self.step1 ,self.y)
		self.loginEntry.getFocus()
		
		
		self.passwordLabel = Label("  Password  ", FONT, width=100)
		self.passwordLabel.setPos(self.x,self.y + 2*self.step2)
		
		self.passwordEntry = TextEntry("", width = 180)
		self.passwordEntry.setPos(self.x + self.step1, self.y +  + 2*self.step2)
		
		self.infoLabel = Label("Info", width = screen_w-40)
		#self.infoLabel.setPos(self.x,self.y + 5*self.step1)
		self.infoLabel.setPos(20,screen_h *0.9)
		
		self.loginButton = TextButton(text='  LOG IN  ')
		#self.loginButton.setPos(0, self.y + 4*self.step2)
		self.loginButton.setPos(screen_w*0.5, screen_h*0.8)
		#self.loginButton.centerH(self.screen)
		self.loginButton.bind(self.sendLoginRequest)
		
		self.registerButton = TextButton(text='  REGISTER  ')
		self.registerButton.setPos(screen_w*0.75, screen_h*0.8)
		self.registerButton.bind(self.sendRegisterRequest)
示例#3
0
class ChatWindow(Widget):
	def __init__(self, x, y, w, h, parent=None, gui=None):
		Widget.__init__(self, x, y, w, h, parent)
		self.gui = gui
		self.makeSurface()
		self.entry = TextEntry("", width = w, parent=self)
		self.scrollTextWindow = ScrollTextWindow(0, 0, w, h-20, parent=self)
		
		#print "created chatwindow, after init, w = %s, h = %s, x = %s, y = %s" % (self.w, self.h, self.x, self.y)
		self.entry.setPos(0, self.h-20)
		
	def addText(self, text):
		self.scrollTextWindow.addText(text)
		
	def getFocus(self):
		self.entry.getFocus()
		
	def loseFocus(self):
		self.entry.loseFocus()
		
	def handleEvents(self, events=[]):
		self.scrollTextWindow.handleEvents(events)
		self.entry.handleEvents(events)
		if events:
			self.updateSurface()
		
		
	def hide(self):
		if not self.visible:
			return
		# do not send the widget itself to the map, it would get modified
		self.gui.game.addDirtyRect(self.copy())
		
		self.visible = False
		for child in self._children:
			child.hide()
	
	def setPos(self, x, y):
		"""Sets the widget position
		if the widget is a child of another widget the position
		is relative to the parent widget"""
		self.topleft = (x, y)
		for child in self._children:
			child.dx = x
			child.dy = y
示例#4
0
	def __init__(self,
		x,y,
		width = 400,
		height = 300,
		bgcolor = (86,111,175),
		bordercolor = (200,200,200),
		hoverbordercolor = (255,255,255),
		borderwidth = 1,
		parent=None,
		gui = None):
		
		Window.__init__(self, "Configuration", width, height, bgcolor, bordercolor, hoverbordercolor, borderwidth, parent, gui)
		#print "created config window, self.surface = %s" % (self.surface)
		
		Label('Keys', parent=self).setPadding(5)
		Frame(0,50, parent=self)
		Label('Up', parent=self).setPadding(5)
		self.kup = TextEntry('', parent=self)
		self.kup.setPadding(5)
		Label('Down', parent=self).setPadding(5)
		self.kdown = TextEntry('', parent=self)
		self.kdown.setPadding(5)
		Label('Left', parent=self).setPadding(5)
		self.kleft = TextEntry('', parent=self)
		self.kleft.setPadding(5)
		Label('Right', parent=self).setPadding(5)
		self.kright = TextEntry('', parent=self)
		self.kright.setPadding(5)
		Label('Select', parent=self).setPadding(5)
		self.kselect = TextEntry('', parent=self)
		self.kselect.setPadding(5)
		Label('Attack', parent=self).setPadding(5)
		self.kattack = TextEntry('', parent=self)
		self.kattack.setPadding(5)
		
		self.autolayout(offset = (0, 20), griditems=2)
		self.setPos(x,y)
		self.OnResize(1,1)
		self.hide()
示例#5
0
class LoginGUI(Widget):
	def __init__(self, game):
		self.game = game
		self.screen = self.game.screen
		
		screen_w = self.screen.get_width()
		screen_h = self.screen.get_height()
		self.x = 220
		self.y = 180
		self.step1 = 140
		self.step2 = 40
		
		self.title = renderText("LOGIN", FONT_MANGA, True)
		
		self.loginLabel = Label("  Name  ", FONT, width=100)
		self.loginLabel.setPos(self.x,self.y)
		
		self.loginEntry = TextEntry("", width = 180)
		self.loginEntry.setPos(self.x + self.step1 ,self.y)
		self.loginEntry.getFocus()
		
		
		self.passwordLabel = Label("  Password  ", FONT, width=100)
		self.passwordLabel.setPos(self.x,self.y + 2*self.step2)
		
		self.passwordEntry = TextEntry("", width = 180)
		self.passwordEntry.setPos(self.x + self.step1, self.y +  + 2*self.step2)
		
		self.infoLabel = Label("Info", width = screen_w-40)
		#self.infoLabel.setPos(self.x,self.y + 5*self.step1)
		self.infoLabel.setPos(20,screen_h *0.9)
		
		self.loginButton = TextButton(text='  LOG IN  ')
		#self.loginButton.setPos(0, self.y + 4*self.step2)
		self.loginButton.setPos(screen_w*0.5, screen_h*0.8)
		#self.loginButton.centerH(self.screen)
		self.loginButton.bind(self.sendLoginRequest)
		
		self.registerButton = TextButton(text='  REGISTER  ')
		self.registerButton.setPos(screen_w*0.75, screen_h*0.8)
		self.registerButton.bind(self.sendRegisterRequest)
		
	def blit(self):
		self.screen.blit(self.title, (50,50))
		self.infoLabel.blit(self.screen)
		self.loginLabel.blit(self.screen)
		self.passwordLabel.blit(self.screen)
		self.loginEntry.blit(self.screen)
		self.passwordEntry.blit(self.screen)
		self.loginButton.blit(self.screen)
		self.registerButton.blit(self.screen)
		
	def handleEvents(self, events=[]):
		if not events:
			return False
			
		self.loginEntry.handleEvents(events)
		self.passwordEntry.handleEvents(events)
		self.loginButton.handleEvents(events)
		self.registerButton.handleEvents(events)
		
		for event in events:
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_TAB:
					if self.loginEntry.has_focus:
						self.loginEntry.loseFocus()
						self.passwordEntry.getFocus()
					elif self.passwordEntry.has_focus:
						self.loginEntry.getFocus()
						self.passwordEntry.loseFocus()
						
				elif event.key == pygame.K_RETURN:
					if self.loginEntry.has_focus:
						self.loginEntry.loseFocus()
						self.passwordEntry.getFocus()
					elif self.passwordEntry.has_focus:
						if len(self.passwordEntry.baseText):
							self.sendLoginRequest()
						#self.loginEntry.getFocus()
						#self.passwordEntry.loseFocus()
						
				
						
			elif event.type == pygame.MOUSEBUTTONDOWN:
				if event.button == 1:
					if self.loginEntry.hover and not self.loginEntry.has_focus:
						self.loginEntry.getFocus()
						self.passwordEntry.loseFocus()
					elif self.passwordEntry.hover and not self.passwordEntry.has_focus:
						self.loginEntry.loseFocus()
						self.passwordEntry.getFocus()
			
			elif event.type == pygame.QUIT:
				pygame.quit()
			
		return False
		
	def sendLoginRequest(self):
		self.name = self.loginEntry.getText()
		self.password = self.passwordEntry.getText()
		print "Sending login request with name = %s, pass = %s" % (self.name, self.password)
		self.game.SendLogin(self.name, self.password)
		
	def sendRegisterRequest(self):
		self.name = self.loginEntry.getText()
		self.password = self.passwordEntry.getText()
		print "Sending register request with name = %s, pass = %s" % (self.name, self.password)
		self.game.SendRegister(self.name, self.password)
		
	def launch(self):
		self.running = True
		while self.running:
			self.update()
		
	def update(self):
		self.screen.fill((100,140,160))
		events = pygame.event.get()
		self.handleEvents(events)
		self.blit()
		pygame.display.flip()
示例#6
0
class ConfigWindow(Window):
	def __init__(self,
		x,y,
		width = 400,
		height = 300,
		bgcolor = (86,111,175),
		bordercolor = (200,200,200),
		hoverbordercolor = (255,255,255),
		borderwidth = 1,
		parent=None,
		gui = None):
		
		Window.__init__(self, "Configuration", width, height, bgcolor, bordercolor, hoverbordercolor, borderwidth, parent, gui)
		#print "created config window, self.surface = %s" % (self.surface)
		
		Label('Keys', parent=self).setPadding(5)
		Frame(0,50, parent=self)
		Label('Up', parent=self).setPadding(5)
		self.kup = TextEntry('', parent=self)
		self.kup.setPadding(5)
		Label('Down', parent=self).setPadding(5)
		self.kdown = TextEntry('', parent=self)
		self.kdown.setPadding(5)
		Label('Left', parent=self).setPadding(5)
		self.kleft = TextEntry('', parent=self)
		self.kleft.setPadding(5)
		Label('Right', parent=self).setPadding(5)
		self.kright = TextEntry('', parent=self)
		self.kright.setPadding(5)
		Label('Select', parent=self).setPadding(5)
		self.kselect = TextEntry('', parent=self)
		self.kselect.setPadding(5)
		Label('Attack', parent=self).setPadding(5)
		self.kattack = TextEntry('', parent=self)
		self.kattack.setPadding(5)
		
		self.autolayout(offset = (0, 20), griditems=2)
		self.setPos(x,y)
		self.OnResize(1,1)
		self.hide()

	def handleEvents(self, events=[]):
		#seems slow
		for event in filter(lambda x: x.type == pygame.MOUSEBUTTONDOWN and x.button == 1, events):
			for widget in [self.kup, self.kdown, self.kleft, self.kright, self.kselect, self.kattack]:
				if widget.hover:
					widget.getFocus()
				else:
					widget.loseFocus()
								
		Window.handleEvents(self, events)