def on_mouse_button_pressed(self, mouse_button, x, y): if contains(self.local_bounds, sf.Vector2(x, y)): self.typing = True if self.text.string == self.default_text: # if it's the default text, get rid of it self.text.string = "" elif not contains(self.local_bounds, sf.Vector2(x, y)): self.typing = False if self.text.string == "": # if you unclick it and there's nothing there, make it the default text self.text.string = self.default_text
def on_mouse_button_pressed(self, mouse_button, x, y): if contains(self.local_bounds, sf.Vector2(x, y)): self.typing = True if self.text.string == self.default_text: # if it's the default text, get rid of it self.text.string = " " elif not contains(self.local_bounds, sf.Vector2(x, y)): self.typing = False if self.text.string == " ": # if you unclick it and there's nothing there, make it the default text self.text.string = self.default_text
def on_mouse_button_pressed(self, mouse_button, x, y): ## LEFT CLICK ## if mouse_button == sf.Mouse.LEFT: # Check to see if clicked on SystemButton for button in self.buttons: if contains(button.rectangle, sf.Vector2(x, y)): # TODO change internal color if button.system.get_max_usable_power() > button.system.power: button.system.power += 1 ## RIGHT CLICK ## elif mouse_button == sf.Mouse.RIGHT: # Check to see if clicked on a SystemButton for button in self.buttons: if contains(button.rectangle, sf.Vector2(x, y)): if button.system.power > 0: button.system.power -= 1 return
def on_mouse_button_pressed(self, mouse_button, x, y): super().on_mouse_button_pressed(mouse_button, x , y) if mouse_button == sf.Mouse.LEFT: # login button pressed if contains(self.login_button.local_bounds, sf.Vector2(x, y)): login_packet = net.Packet() login_packet.write(const.PacketTypes.LOGIN) login_packet.write(self.first_textbox.last_text) # username login_packet.write(self.last_textbox.last_text) # password self.client.send(login_packet)
def on_mouse_button_pressed(self, mouse_button, x, y): super().on_mouse_button_pressed(mouse_button, x, y) # left if mouse_button == sf.Mouse.LEFT: if self.gui_manager.point_over_any_element(x, y) is not True and self.loaded is True: # mouse isn't over window packet = net.Packet() packet.write(const.PacketTypes.ADD_FARM_ITEM) packet.write(self.get_current_item()) packet.write(self.input.window.map_pixel_to_coords(sf.Vector2(x, y), self.view).x) packet.write(self.input.window.map_pixel_to_coords(sf.Vector2(x, y), self.view).y) self.client.send(packet) elif self.gui_manager.point_over_element(self.load_button, x, y) is True: if self.textbox.last_text is not self.user.user_name: packet = net.Packet() packet.write(const.PacketTypes.SWITCH_FARM) packet.write(self.textbox.last_text) self.client.send(packet) elif self.gui_manager.point_over_element(self.save_button, x, y) is True: packet = net.Packet() packet.write(const.PacketTypes.SAVE_FARM) self.user.farm.serialize(packet) self.client.send(packet) elif self.gui_manager.point_over_element(self.shop_button, x, y) is True: self.user.switch_state(const.GameStates.SHOP) elif self.gui_manager.point_over_element(self.stats_button, x, y) is True: self.user.switch_state(const.GameStates.STATS) # RIGHT if mouse_button == sf.Mouse.RIGHT: for item in reversed(self.user.farm.farm_items): if contains(item.local_bounds, self.input.window.map_pixel_to_coords(sf.Vector2(x, y), self.view)): print("hello world") self.user.farm.farm_items.remove(item) break # only delete one tree
def on_mouse_moved(self, position, move): if contains(self.vertices.bounds, sf.Vector2(position.x, position.y)): if self.mouse_state == 'down': # mouse is down self.move(move.x, move.y)
def on_mouse_button_pressed(self, mouse_button, x, y): if contains(self.local_bounds, sf.Vector2(x, y)): self.sprite.set_frame(2) # down
def on_mouse_moved(self, position, move): if contains(self.local_bounds, sf.Vector2(position.x, position.y)): self.sprite.set_frame(1) # hover else: self.sprite.set_frame(0) # up
def on_mouse_moved(self, position, move): if contains(self.local_bounds, sf.Vector2(position.x, position.y)): self.sprite.set_frame(self.hover) # hover else: self.sprite.set_frame(self.up) # up
def on_mouse_button_pressed(self, mouse_button, x, y): if contains(self.local_bounds, sf.Vector2(x, y)): self.sprite.set_frame(self.down) # down
def point_over_element(self, element, x, y): if contains(element.local_bounds, sf.Vector2(x, y)): return True return False
def point_over_any_element(self, x, y): for i in range(0, len(self.children)): if contains(self.children[i].local_bounds, sf.Vector2(x, y)): return True return False