class Chat: def __init__(self, size, background, position, parent): global font self.visible = True self.size = size self.background = None self.parent = parent self.x, self.y = position self.GenerateBackground(background) self.input = Input() self.input.AllowAll() self.input.SetSize(self.size[0], 25) self.input.SetBackgroundColor(0, 0, 255) self.input.SetTextColor(0, 255, 0) self.input.x = 0 self.input.y = self.size[1] - self.input.size[1] self.input.SetParent(self) self.input.GenerateFont(font) self.input.GenerateBackground() self.chats_zone = MsgBox( (self.size[0] - 10, self.size[1] - 10 - self.input.size[1]), (self.x + 5, self.y + 5), self) self.recently_pressed = False def AddMessage(self, sender, message): self.chats_zone.AddMessage(sender, message) def GenerateBackground(self, color): self.background = pygame.Surface(self.size) self.background.fill(color) AddBorder(self.background, 2) self.background.set_alpha(100) def LogicUpdate(self): self.input.Event(self.parent.parent.events) self.input.LogicUpdate() self.chats_zone.LogicUpdate() if pygame.key.get_pressed()[K_RETURN] or pygame.key.get_pressed( )[K_KP_ENTER]: if not self.recently_pressed and self.input.selected: self.recently_pressed = True self.parent.parent.Send({ "action": "send_chat", "message": self.input.text }) self.input.text = "" else: self.recently_pressed = False def GraphicUpdate(self, screen): if self.visible: back = self.background.copy() self.input.GraphicUpdate(back) self.chats_zone.GraphicUpdate(screen) screen.blit(back, (self.x, self.y))
def AddInput(self): interpolationConstantText = Text(fonts.BebasNeue.c20,"Interpolation constant:",(255,255,255)) interpolationConstantText.y = 60 - interpolationConstantText.surface.get_size()[1]/2 interpolationConstantText.x = self.width/4 - interpolationConstantText.surface.get_size()[0]/2 self.AddElement(interpolationConstantText,"textIC") interpolationConstantInput = Input() interpolationConstantInput.AllowNumbers() interpolationConstantInput.SetSize(100,30) interpolationConstantInput.y = 60 - interpolationConstantInput.size[1]/2 interpolationConstantInput.x = self.width/4*3 - interpolationConstantInput.size[0]/2 interpolationConstantInput.text = str(config.interpolation_constant) self.AddElement(interpolationConstantInput,"IConstant") thresholdText = Text(fonts.BebasNeue.c20,"Threshold correction:",(255,255,255)) thresholdText.y = 100 - thresholdText.surface.get_size()[1]/2 thresholdText.x = self.width/4 - thresholdText.surface.get_size()[0]/2 self.AddElement(thresholdText,"textTH") thresholdInput = Input() thresholdInput.AllowNumbers() thresholdInput.SetSize(100,30) thresholdInput.y = 100 - thresholdInput.size[1]/2 thresholdInput.x = self.width/4*3 - thresholdInput.size[0]/2 thresholdInput.text = str(config.threshold) self.AddElement(thresholdInput,"TH")
def Start(self,error=None): self.Send({"action":"req_av_players"}) y_act = 40 if error != None: error = Text(fonts.BebasNeue.c20,error,(255,0,0)) error.x = self.width/2-error.surface.get_size()[0]/2 error.y = y_act self.AddElement(error,"Error") y_act += error.surface.get_size()[1]+10 textName = Text(fonts.BebasNeue.c30,"Player Name:",(255,255,255)) textName.x = self.width/4-textName.surface.get_size()[0]/2 textName.y = y_act self.AddElement(textName,"TextName") inputName = Input() inputName.x = self.width/4*3-inputName.size[0]/2 inputName.y = y_act inputName.AllowAll() inputName.SetSize(200,30) self.AddElement(inputName,"inputName") y_act += 60 loading = LoadingAnimation(0.4,5) loading.x = self.width/2-loading.width/2 loading.y = y_act self.AddElement(loading,"LoadingA") y_act += 30 loadingText = Text(fonts.BebasNeue.c20,"Loading players...",(255,255,255)) loadingText.x = self.width/2-loadingText.surface.get_size()[0]/2 loadingText.y = y_act self.AddElement(loadingText,"LoadingT") y_act += 70 cancelButton = RejectButton("Cancel") cancelButton.x = self.width/2-cancelButton.imageA.get_size()[0]/2 cancelButton.y = y_act self.AddElement(cancelButton,"CancelButton") y_act += cancelButton.size[1] self.SetHeight(y_act+10) self.originalPlayer = None
def SetInputName(self): self.DeleteAllElements() nameInputTitle = Text(fonts.BebasNeue.c30,"Name:",(255,255,255)) nameInputTitle.y = 100 - nameInputTitle.surface.get_size()[1]/2 nameInputTitle.x = self.width / 4 - nameInputTitle.surface.get_size()[0]/2 self.AddElement(nameInputTitle,"nameInput") inputField = Input() inputField.SetSize(150,30) inputField.y = 100 - inputField.size[1]/2 inputField.x = self.width / 4 * 3 - inputField.size[0]/2 inputField.AllowAll() self.AddElement(inputField,"inputField") okButton = AcceptButton("Accept",200) okButton.y = 150 - okButton.size[1]/2 okButton.x = self.width/ 2 - okButton.imageA.get_size()[0]/2 self.AddElement(okButton,"okButton")
def __init__(self,parent,save): self.save = save Window.__init__(self,"Login",(36, 107, 97),(43, 76, 111),0,0,400,160,(255,255,255)) self.parent = parent font = fonts.AldoTheApache UserText = Text(font.c30,"Username:"******"User Text") PassText = Text(font.c30,"Password:"******"Pass Text") UserInput = Input() UserInput.AllowAll() UserInput.SetParent(self) UserInput.SetSize(150,30) UserInput.x = self.width/2 + 5 UserInput.y = self.height/2 - UserInput.size[1] - 2-15 self.AddElement(UserInput,"User Input") PassInput = copy.copy(UserInput) PassInput.y += PassInput.size[1] + 5 PassInput.password = True self.AddElement(PassInput,"Pass Input") UserInput.SetNextInput(PassInput) Accept = AcceptButton("Login",150,(0,0),font) Accept.x = self.width/2+10 Accept.y = PassInput.y + PassInput.size[1] + 20 self.AddElement(Accept,"Accept") Reject = RejectButton("Cancel",150,(0,0),font) Reject.x = self.width/2 - 10 - Reject.size[0] Reject.y = Accept.y self.AddElement(Reject,"Cancel") self.was_pressed1 = False self.was_pressed2 = False self.parent.SetLoginDef(self.Login) self.loging_in = False self.username = "" self.password = ""
def SetNameInput(self,with_error = None): self.RemoveLoading() self.RemoveMSJ() self.RemoveQuit() self.mode = "setting-name" self.RemoveLoading() self.RemoveMSJ() self.RemoveQuit() y_act = 30 if with_error != None: error = Text(fonts.BebasNeue.c20,with_error,(255,0,0)) error.x = self.width/2 - error.surface.get_size()[0]/2 error.y = y_act self.AddElement(error,"Error") y_act += error.surface.get_size()[1] + 5 textQuestion = Text(fonts.BebasNeue.c30,"Name:",(255,255,255)) textQuestion.x = self.width/4 textQuestion.y = y_act self.AddElement(textQuestion,"Question") input = Input() input.AllowAll() input.SetSize(200,30) input.x = textQuestion.x + textQuestion.surface.get_size()[0] + 10 input.y = y_act input.SetTextColor(0,0,0) input.SetBackgroundColor(100,100,100) self.AddElement(input,"Input") y_act += 50 confirmButton = AcceptButton("Confirm") confirmButton.x = self.width/2-confirmButton.size[0]/2 confirmButton.y = y_act self.AddElement(confirmButton,"Confirm") y_act += confirmButton.size[1] self.SetHeight(y_act)
def __init__(self, size, background, position, parent): global font self.visible = True self.size = size self.background = None self.parent = parent self.x, self.y = position self.GenerateBackground(background) self.input = Input() self.input.AllowAll() self.input.SetSize(self.size[0], 25) self.input.SetBackgroundColor(0, 0, 255) self.input.SetTextColor(0, 255, 0) self.input.x = 0 self.input.y = self.size[1] - self.input.size[1] self.input.SetParent(self) self.input.GenerateFont(font) self.input.GenerateBackground() self.chats_zone = MsgBox( (self.size[0] - 10, self.size[1] - 10 - self.input.size[1]), (self.x + 5, self.y + 5), self) self.recently_pressed = False
def __init__(self, parent, save): self.save = save Window.__init__(self, "Login", (36, 107, 97), (43, 76, 111), 0, 0, 400, 160, (255, 255, 255)) self.parent = parent font = fonts.AldoTheApache UserText = Text(font.c30, "Username:"******"User Text") PassText = Text(font.c30, "Password:"******"Pass Text") UserInput = Input() UserInput.AllowAll() UserInput.SetParent(self) UserInput.SetSize(150, 30) UserInput.x = self.width / 2 + 5 UserInput.y = self.height / 2 - UserInput.size[1] - 2 - 15 self.AddElement(UserInput, "User Input") PassInput = copy.copy(UserInput) PassInput.y += PassInput.size[1] + 5 PassInput.password = True self.AddElement(PassInput, "Pass Input") UserInput.SetNextInput(PassInput) Accept = AcceptButton("Login", 150, (0, 0), font) Accept.x = self.width / 2 + 10 Accept.y = PassInput.y + PassInput.size[1] + 20 self.AddElement(Accept, "Accept") Reject = RejectButton("Cancel", 150, (0, 0), font) Reject.x = self.width / 2 - 10 - Reject.size[0] Reject.y = Accept.y self.AddElement(Reject, "Cancel") self.was_pressed1 = False self.was_pressed2 = False self.parent.SetLoginDef(self.Login) self.loging_in = False self.username = "" self.password = ""
def __init__(self,parent): self.parent = parent Window.__init__(self, "Add server", (36, 107, 97), (43, 76, 111), 0, 0, 500, 250, (255,255,255), 250) y_act = 40 + 5 name = Text(BebasNeue.c30,"Server name",(0,0,0)) name.x = self.width/4 - name.surface.get_size()[0]/2 name.y = y_act self.AddElement(name,"Name") #y_act += 3+name.surface.get_size()[1] name_input = Input() name_input.AllowAll() name_input.SetSize(200,30) name_input.x = self.width/4*3 - name_input.size[0]/2 name_input.y = y_act name_input.SetTextColor(255,0,0) name_input.SetBackgroundColor(100,100,100) self.AddElement(name_input,"Name input") y_act += name_input.size[1]+name_input.border_size*2+10 ip = Text(BebasNeue.c30,"IP Adress",(0,0,0)) ip.x = self.width/4 - ip.surface.get_size()[0]/2 ip.y = y_act self.AddElement(ip,"IP") #y_act += ip.surface.get_size()[1]+3 ip_input = Input() ip_input.AllowNumbers() ip_input.SetSize(200,30) ip_input.x = self.width/4*3 - ip_input.size[0]/2 ip_input.y = y_act ip_input.SetTextColor(255,0,0) ip_input.SetBackgroundColor(100,100,100) name_input.SetNextInput(ip_input) self.AddElement(ip_input,"IP input") y_act += ip_input.size[1]+2*ip_input.border_size+15 accept_button = AcceptButton("Create",150,[self.width/2+20,y_act]) self.AddElement(accept_button,"Create button") cancel_button = RejectButton("Cancel",150,[self.width/2-150-20,y_act]) self.AddElement(cancel_button,"Cancel button") y_act += cancel_button.size[1]+5 self.height = y_act self.GenerateSurface() self.tab = False self.tab_elements = ["Name input","IP input"] self.current_tab = -1
def SetNameInput(self, with_error=None): self.RemoveLoading() self.RemoveMSJ() self.RemoveQuit() self.mode = "setting-name" self.RemoveLoading() self.RemoveMSJ() self.RemoveQuit() y_act = 30 if with_error != None: error = Text(fonts.BebasNeue.c20, with_error, (255, 0, 0)) error.x = self.width / 2 - error.surface.get_size()[0] / 2 error.y = y_act self.AddElement(error, "Error") y_act += error.surface.get_size()[1] + 5 textQuestion = Text(fonts.BebasNeue.c30, "Name:", (255, 255, 255)) textQuestion.x = self.width / 4 textQuestion.y = y_act self.AddElement(textQuestion, "Question") input = Input() input.AllowAll() input.SetSize(200, 30) input.x = textQuestion.x + textQuestion.surface.get_size()[0] + 10 input.y = y_act input.SetTextColor(0, 0, 0) input.SetBackgroundColor(100, 100, 100) self.AddElement(input, "Input") y_act += 50 confirmButton = AcceptButton("Confirm") confirmButton.x = self.width / 2 - confirmButton.size[0] / 2 confirmButton.y = y_act self.AddElement(confirmButton, "Confirm") y_act += confirmButton.size[1] self.SetHeight(y_act)
def Start(self, error=None): self.Send({"action": "req_av_players"}) y_act = 40 if error != None: error = Text(fonts.BebasNeue.c20, error, (255, 0, 0)) error.x = self.width / 2 - error.surface.get_size()[0] / 2 error.y = y_act self.AddElement(error, "Error") y_act += error.surface.get_size()[1] + 10 textName = Text(fonts.BebasNeue.c30, "Player Name:", (255, 255, 255)) textName.x = self.width / 4 - textName.surface.get_size()[0] / 2 textName.y = y_act self.AddElement(textName, "TextName") inputName = Input() inputName.x = self.width / 4 * 3 - inputName.size[0] / 2 inputName.y = y_act inputName.AllowAll() inputName.SetSize(200, 30) self.AddElement(inputName, "inputName") y_act += 60 loading = LoadingAnimation(0.4, 5) loading.x = self.width / 2 - loading.width / 2 loading.y = y_act self.AddElement(loading, "LoadingA") y_act += 30 loadingText = Text(fonts.BebasNeue.c20, "Loading players...", (255, 255, 255)) loadingText.x = self.width / 2 - loadingText.surface.get_size()[0] / 2 loadingText.y = y_act self.AddElement(loadingText, "LoadingT") y_act += 70 cancelButton = RejectButton("Cancel") cancelButton.x = self.width / 2 - cancelButton.imageA.get_size()[0] / 2 cancelButton.y = y_act self.AddElement(cancelButton, "CancelButton") y_act += cancelButton.size[1] self.SetHeight(y_act + 10) self.originalPlayer = None
def SetInputName(self): self.DeleteAllElements() nameInputTitle = Text(fonts.BebasNeue.c30, "Name:", (255, 255, 255)) nameInputTitle.y = 100 - nameInputTitle.surface.get_size()[1] / 2 nameInputTitle.x = self.width / 4 - nameInputTitle.surface.get_size( )[0] / 2 self.AddElement(nameInputTitle, "nameInput") inputField = Input() inputField.SetSize(150, 30) inputField.y = 100 - inputField.size[1] / 2 inputField.x = self.width / 4 * 3 - inputField.size[0] / 2 inputField.AllowAll() self.AddElement(inputField, "inputField") okButton = AcceptButton("Accept", 200) okButton.y = 150 - okButton.size[1] / 2 okButton.x = self.width / 2 - okButton.imageA.get_size()[0] / 2 self.AddElement(okButton, "okButton")
def __init__(self, parent, save): Window.__init__(self, "Sign up", (36, 107, 97), (43, 76, 111), 0, 0, 400, 210, (255, 255, 255)) self.parent = parent self.save = save font = fonts.BebasNeue.c25 y_act = 29 ### User text ### UserText = Text(font, "Username:"******"User Text") ### User input ### UserInput = Input() UserInput.AllowAll() UserInput.SetParent(self) UserInput.SetSize(150, 30) UserInput.x = self.width / 2 + 5 UserInput.y = UserText.y + (UserText.surface.get_size()[1] / 2 - UserInput.size[1] / 2) self.AddElement(UserInput, "User Input") ### Password text ### y_act += UserText.surface.get_size()[1] + 5 PassText = Text(font, "Password:"******"Pass Text") ### Password input ### PassInput = copy.copy(UserInput) PassInput.y = PassText.y + (PassText.surface.get_size()[1] / 2 - PassInput.size[1] / 2) PassInput.password = True self.AddElement(PassInput, "Pass Input") ### Pass Confirm text ### y_act += PassText.surface.get_size()[1] + 5 PassConfText = Text(font, "Confirm password:"******"Confirm Password Text") ### Pass Confirm input ### PassConfInput = copy.copy(PassInput) PassConfInput.y = PassConfText.y + ( PassConfText.surface.get_size()[1] / 2 - PassConfInput.size[1] / 2) self.AddElement(PassConfInput, "Confirm Password Input") ### Email text ### y_act += PassConfText.surface.get_size()[1] + 5 EmailText = Text(font, "Email:", (0, 0, 0)) EmailText.x = self.width / 2 - EmailText.surface.get_size()[0] - 5 EmailText.y = y_act self.AddElement(EmailText, "Email Text") ### Email input ### EmailInput = copy.copy(PassConfInput) EmailInput.password = False EmailInput.y = EmailText.y - (EmailText.surface.get_size()[1] / 2 - EmailInput.size[1] / 2) self.AddElement(EmailInput, "Email Input") ### Setting next inputs ### UserInput.next_input = PassInput PassInput.next_input = PassConfInput PassConfInput.next_input = EmailInput EmailInput.next_input = UserInput ### Accept button ### y_act += EmailText.surface.get_size()[1] + 10 Accept = AcceptButton("Sign up", 150, (0, 0), font) Accept.x = self.width / 2 + 10 Accept.y = y_act self.AddElement(Accept, "Accept") ### Reject button ### Reject = RejectButton("Cancel", 150, (0, 0), font) Reject.x = self.width / 2 - 10 - Reject.size[0] Reject.y = y_act self.AddElement(Reject, "Cancel") ### Extra variables ### self.pressed = False self.pressed2 = False self.parent.SetRegisterDef(self.RegisterConfirm) self.sending_data = False
def __init__(self,parent,save): Window.__init__(self,"Sign up",(36, 107, 97),(43, 76, 111),0,0,400,210,(255,255,255)) self.parent = parent self.save = save font = fonts.BebasNeue.c25 y_act = 29 ### User text ### UserText = Text(font,"Username:"******"User Text") ### User input ### UserInput = Input() UserInput.AllowAll() UserInput.SetParent(self) UserInput.SetSize(150,30) UserInput.x = self.width/2 + 5 UserInput.y = UserText.y + (UserText.surface.get_size()[1]/2 - UserInput.size[1]/2) self.AddElement(UserInput,"User Input") ### Password text ### y_act += UserText.surface.get_size()[1] + 5 PassText = Text(font,"Password:"******"Pass Text") ### Password input ### PassInput = copy.copy(UserInput) PassInput.y = PassText.y + (PassText.surface.get_size()[1]/2 - PassInput.size[1]/2) PassInput.password = True self.AddElement(PassInput,"Pass Input") ### Pass Confirm text ### y_act += PassText.surface.get_size()[1] + 5 PassConfText = Text(font,"Confirm password:"******"Confirm Password Text") ### Pass Confirm input ### PassConfInput = copy.copy(PassInput) PassConfInput.y = PassConfText.y + (PassConfText.surface.get_size()[1]/2 - PassConfInput.size[1]/2) self.AddElement(PassConfInput,"Confirm Password Input") ### Email text ### y_act += PassConfText.surface.get_size()[1] + 5 EmailText = Text(font,"Email:",(0,0,0)) EmailText.x = self.width/2 - EmailText.surface.get_size()[0] - 5 EmailText.y = y_act self.AddElement(EmailText,"Email Text") ### Email input ### EmailInput = copy.copy(PassConfInput) EmailInput.password = False EmailInput.y = EmailText.y - (EmailText.surface.get_size()[1]/2 - EmailInput.size[1]/2) self.AddElement(EmailInput,"Email Input") ### Setting next inputs ### UserInput.next_input = PassInput PassInput.next_input = PassConfInput PassConfInput.next_input = EmailInput EmailInput.next_input = UserInput ### Accept button ### y_act += EmailText.surface.get_size()[1] + 10 Accept = AcceptButton("Sign up",150,(0,0),font) Accept.x = self.width/2+10 Accept.y = y_act self.AddElement(Accept,"Accept") ### Reject button ### Reject = RejectButton("Cancel",150,(0,0),font) Reject.x = self.width/2 - 10 - Reject.size[0] Reject.y = y_act self.AddElement(Reject,"Cancel") ### Extra variables ### self.pressed = False self.pressed2 = False self.parent.SetRegisterDef(self.RegisterConfirm) self.sending_data = False
def __init__(self, parent): self.parent = parent Window.__init__(self, "Add server", (36, 107, 97), (43, 76, 111), 0, 0, 500, 250, (255, 255, 255), 250) y_act = 40 + 5 name = Text(BebasNeue.c30, "Server name", (0, 0, 0)) name.x = self.width / 4 - name.surface.get_size()[0] / 2 name.y = y_act self.AddElement(name, "Name") #y_act += 3+name.surface.get_size()[1] name_input = Input() name_input.AllowAll() name_input.SetSize(200, 30) name_input.x = self.width / 4 * 3 - name_input.size[0] / 2 name_input.y = y_act name_input.SetTextColor(255, 0, 0) name_input.SetBackgroundColor(100, 100, 100) self.AddElement(name_input, "Name input") y_act += name_input.size[1] + name_input.border_size * 2 + 10 ip = Text(BebasNeue.c30, "IP Adress", (0, 0, 0)) ip.x = self.width / 4 - ip.surface.get_size()[0] / 2 ip.y = y_act self.AddElement(ip, "IP") #y_act += ip.surface.get_size()[1]+3 ip_input = Input() ip_input.AllowNumbers() ip_input.SetSize(200, 30) ip_input.x = self.width / 4 * 3 - ip_input.size[0] / 2 ip_input.y = y_act ip_input.SetTextColor(255, 0, 0) ip_input.SetBackgroundColor(100, 100, 100) name_input.SetNextInput(ip_input) self.AddElement(ip_input, "IP input") y_act += ip_input.size[1] + 2 * ip_input.border_size + 15 accept_button = AcceptButton("Create", 150, [self.width / 2 + 20, y_act]) self.AddElement(accept_button, "Create button") cancel_button = RejectButton("Cancel", 150, [self.width / 2 - 150 - 20, y_act]) self.AddElement(cancel_button, "Cancel button") y_act += cancel_button.size[1] + 5 self.height = y_act self.GenerateSurface() self.tab = False self.tab_elements = ["Name input", "IP input"] self.current_tab = -1
def AddInput(self): interpolationConstantText = Text(fonts.BebasNeue.c20, "Interpolation constant:", (255, 255, 255)) interpolationConstantText.y = 60 - interpolationConstantText.surface.get_size( )[1] / 2 interpolationConstantText.x = self.width / 4 - interpolationConstantText.surface.get_size( )[0] / 2 self.AddElement(interpolationConstantText, "textIC") interpolationConstantInput = Input() interpolationConstantInput.AllowNumbers() interpolationConstantInput.SetSize(100, 30) interpolationConstantInput.y = 60 - interpolationConstantInput.size[ 1] / 2 interpolationConstantInput.x = self.width / 4 * 3 - interpolationConstantInput.size[ 0] / 2 interpolationConstantInput.text = str(config.interpolation_constant) self.AddElement(interpolationConstantInput, "IConstant") thresholdText = Text(fonts.BebasNeue.c20, "Threshold correction:", (255, 255, 255)) thresholdText.y = 100 - thresholdText.surface.get_size()[1] / 2 thresholdText.x = self.width / 4 - thresholdText.surface.get_size( )[0] / 2 self.AddElement(thresholdText, "textTH") thresholdInput = Input() thresholdInput.AllowNumbers() thresholdInput.SetSize(100, 30) thresholdInput.y = 100 - thresholdInput.size[1] / 2 thresholdInput.x = self.width / 4 * 3 - thresholdInput.size[0] / 2 thresholdInput.text = str(config.threshold) self.AddElement(thresholdInput, "TH")