Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
 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)
Пример #5
0
    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
Пример #6
0
 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)
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
 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)
Пример #10
0
 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
Пример #11
0
 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
Пример #12
0
 def point_over_element(self, element, x, y):
     if contains(element.local_bounds, sf.Vector2(x, y)):
         return True
     
     return False
Пример #13
0
 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