コード例 #1
0
ファイル: game_state.py プロジェクト: boulware/puzzle
    def __init__(self, game):
        GameState.__init__(self, game)

        self.input_map = {
            Input(key=pg.K_ESCAPE): lambda _: self.return_to_menu(),
            Input(key=pg.K_RETURN): lambda _: self._start_host()
        }

        self.port_textentry = UI.TextEntry(pos=(c.screen_size[0] // 2 - 100,
                                                c.screen_size[1] // 2 + 100),
                                           type='port',
                                           font=fonts.main_menu_font_med,
                                           label='Port',
                                           default_text='4141')

        self.host_button = UI.Button(pos=(c.screen_size[0] // 2 - 100,
                                          c.screen_size[1] // 2 + 200),
                                     font=fonts.main_menu_font_med,
                                     text='Host')

        self.disconnect_button = UI.Button(pos=(c.screen_size[0] // 2 - 100,
                                                c.screen_size[1] // 2 + 250),
                                           font=fonts.main_menu_font_med,
                                           text='Disconnect')

        self.ui_container.add_element(self.port_textentry)
        self.ui_container.add_element(self.host_button)
        self.ui_container.add_element(self.disconnect_button)
コード例 #2
0
def test():
    my_test_engine = TestEngine(400, 300, 'Testing different UI elements')

    # Create UI elements
    text1 = UI.Text(my_test_engine,
                    rect=pygame.Rect(30, 30, 60, 20),
                    text='Hello')
    text2 = UI.Text(my_test_engine,
                    rect=pygame.Rect(30, 65, 60, 20),
                    text='World!',
                    background_color=(200, 200, 200, 50))
    text3 = UI.Text(my_test_engine,
                    rect=pygame.Rect(30, 100, 150, 20),
                    z=5,
                    text='0',
                    background_color=(70, 200, 70))
    text4 = UI.Text(my_test_engine,
                    rect=pygame.Rect(100, 120, 120, 20),
                    z=4,
                    text='')
    textbox1 = UI.TextBox(my_test_engine,
                          rect=pygame.Rect(100, 30, 180, 20),
                          background_text='Username')
    textbox2 = UI.TextBox(my_test_engine,
                          rect=pygame.Rect(100, 65, 180, 20),
                          background_text='Password')
    checkbox1 = UI.CheckBox(my_test_engine, rect=pygame.Rect(290, 30, 14, 14))
    checkbox2 = UI.CheckBox(my_test_engine, rect=pygame.Rect(290, 65, 14, 14))
    button1 = UI.Button(my_test_engine,
                        rect=pygame.Rect(310, 30, 70, 20),
                        text='Press me')
    button2 = UI.Button(my_test_engine,
                        rect=pygame.Rect(310, 65, 50, 20),
                        text='Don\'t')

    textbox1.set_callback(display_text_input)
    textbox2.set_callback(display_text_input)

    checkbox1.set_callback(display_checked)
    checkbox2.set_callback(display_checked)

    button1.set_callback(display_button)
    button2.set_callback(display_button)

    # Test setting and getting of each UI element (only one per class is necessary)
    test_text(text1)
    test_textbox(textbox1)

    # test moving text and setting visibility
    text1.rect = pygame.Rect(30, 20, text1.rect.width, text1.rect.height)
    text2.visible = False
    text3.text = 'This was an update counter'
    text4.text = 'This was blank'

    while True:
        my_test_engine.update()
        my_test_engine.render()

        pygame.time.delay(20)
コード例 #3
0
ファイル: ControlBar.py プロジェクト: DevmanAuthor/Neural
def Load(self):
    self.Buttons["Cycle"] = UI.Button(0, 0, "gfx/ball.png")
    self.Buttons["Cycle"].scale(20, 20, True, 1.5, 1.5)
    self.Buttons["Cycle"].place(
        System.screen.get_width() -
        (self.Buttons["Cycle"].rect.width + self.Buttons["Cycle"].reliefsize),
        0)

    self.Buttons["Exit"] = UI.Button(0, 0, "gfx/UI/eyexit.png")
    self.Buttons["Exit"].scale(50, 40, True, 2, 2)
    self.Buttons["Exit"].place(
        System.width - self.Buttons["Exit"].rect.width -
        self.Buttons["Exit"].reliefsize, System.height -
        self.Buttons["Exit"].rect.height - self.Buttons["Exit"].reliefsize)
コード例 #4
0
    def end_game(self):
        self.level_completed = True
        self.end_screen.fill((75, 0, 130, 200))

        #Texts
        font = pygame.font.SysFont(pygame.font.get_default_font(), 150)

        level_completed_text = font.render("Level Completed !", 1,
                                           (255, 255, 255))
        x_pos = self.end_screen.get_width(
        ) / 2 - level_completed_text.get_width() / 2
        self.end_screen.blit(level_completed_text, (x_pos, 50))

        timer_text = font.render('{:06.2f}'.format(self.start_time), 1,
                                 (255, 255, 255))
        x_pos = self.end_screen.get_width() / 2 - timer_text.get_width() / 2
        self.end_screen.blit(timer_text, (x_pos, 300))

        #Buttons
        button_y_pos = self.game.DESING_H / 2 + 50
        w_center = self.game.DESING_W / 2
        reload_button = UI.Button(w_center - 650,
                                  button_y_pos,
                                  400,
                                  80,
                                  "Restart", (150, 150, 150),
                                  self.reload_level, [],
                                  center_text=True)

        save_replay_button = UI.Button(w_center - 200,
                                       button_y_pos,
                                       400,
                                       80,
                                       "Save Replay", (150, 150, 150),
                                       self.save_replay, [],
                                       center_text=True)

        main_menu_button = UI.Button(w_center + 250,
                                     button_y_pos,
                                     400,
                                     80,
                                     "Main Menu", (150, 150, 150),
                                     self.game.load_main_menu, [],
                                     center_text=True)

        self.ui_manager.add(reload_button)
        self.ui_manager.add(main_menu_button)
        self.ui_manager.add(save_replay_button)
コード例 #5
0
    def __init__(self, main_menu):
        super().__init__(main_menu)
        self.category_selector_ui = UI.UIManager()
        self.category_selector_ui.add(
            UI.Button(15,
                      15,
                      300,
                      60,
                      "Load replay", (150, 150, 150),
                      self.load_replay, [],
                      center_text=True,
                      font_size=46))
        self.category_selector_ui.add(
            UI.Button(self.main_menu.game.DESING_W / 2 - 450,
                      self.main_menu.game.DESING_H / 2 - 200,
                      400,
                      400,
                      "Official", (150, 150, 150),
                      self.open_categorie,
                      "official",
                      center_text=True))

        self.category_selector_ui.add(
            UI.Button(self.main_menu.game.DESING_W / 2,
                      self.main_menu.game.DESING_H / 2 - 200,
                      400,
                      400,
                      "Community", (150, 150, 150),
                      self.open_categorie,
                      "community",
                      center_text=True))

        BUTTON_WIDTH = 800
        BUTTON_HEIGHT = 100
        self.scrollview = UI.ScrollView(
            0, 0, main_menu.game.DESING_W, main_menu.game.DESING_H,
            (75, 0, 130), BUTTON_WIDTH, BUTTON_HEIGHT,
            main_menu.game.DESING_W / 2 - BUTTON_WIDTH / 2, 25)
        self.LevelSelectorUI = UI.UIManager()
        self.LevelSelectorUI.add(self.scrollview)

        self.search_bar = UI.InputField(10, 10, 400, 60, self.update_levels,
                                        'search_icon.png')
        self.LevelSelectorUI.add(self.search_bar)
        self.ui_manager = self.category_selector_ui
コード例 #6
0
 def __init__(self, main_menu):
     super().__init__(main_menu)
     x_pos = self.main_menu.game.DESING_W / 2 - 150
     y_center = self.main_menu.game.DESING_H / 2
     self.ui_manager.add(
         UI.Button(x_pos,
                   y_center - 150,
                   300,
                   70,
                   "Load Map", (150, 150, 150),
                   self.main_menu.play,
                   'maps/map',
                   center_text=True,
                   font_size=64))
     self.ui_manager.add(
         UI.Button(x_pos,
                   y_center - 50,
                   300,
                   70,
                   "Editor", (150, 150, 150),
                   self.main_menu.start_editor,
                   '',
                   center_text=True,
                   font_size=64))
     self.ui_manager.add(
         UI.Button(x_pos,
                   y_center + 50,
                   300,
                   70,
                   "Options", (150, 150, 150),
                   self.main_menu.options,
                   '',
                   center_text=True,
                   font_size=64))
     self.ui_manager.add(
         UI.Button(x_pos,
                   y_center + 150,
                   300,
                   70,
                   "Quit", (150, 150, 150),
                   self.main_menu.exit,
                   '',
                   center_text=True,
                   font_size=64))
コード例 #7
0
ファイル: Battle.py プロジェクト: WaltonSimons/LCDQuest
 def __init__(self, player=None, enemy1=None, enemy2=None, enemy3=None):
     Globals.battle = self
     self.b1 = UI.Button(3, 33, None, True)
     self.b2 = UI.Button(3, 41, None, False)
     self.b3 = UI.Button(44, 33, None, False)
     self.b4 = UI.Button(44, 41, None, False)
     self.currentbutton = self.b1
     self.downbox = UI.Static(0, 31, 'bottombox')
     self.upbox = UI.Static(0, 0, 'upperbox')
     self.bars = UI.Static(0, 26, 'statusbars')
     self.uptext = DrawableObject.Text(2, 2, '')
     self.downtext1 = DrawableObject.Text(3, 33, '')
     self.downtext2 = DrawableObject.Text(3, 41, '')
     self.o1 = DrawableObject.Text(13, 33, 'attack')
     self.o2 = DrawableObject.Text(13, 41, 'skills')
     self.o3 = DrawableObject.Text(54, 33, 'items')
     self.o4 = DrawableObject.Text(54, 41, 'status')
     self.enemyarrow = UI.Static(40, 10, 'enemyarrow', False)
     self.hpbar = UI.PixelBar(2, 30, 20)
     self.mpbar = UI.PixelBar(62, 30, 20)
     self.player = player
     self.enemy1 = enemy1
     self.enemy2 = enemy2
     self.enemy3 = enemy3
     self._currenttarget = enemy1
     if self.enemy1 is not None:
         self.enemy1.x = 34
         self.enemy1.y = 13
     if self.enemy2 is not None:
         self.enemy2.x = 9
         self.enemy2.y = 13
     if self.enemy3 is not None:
         self.enemy3.x = 59
         self.enemy3.y = 13
     self.turnorder = []
     self.battleover = False
     self.c = Controller.Control()
     self.action = None
     self.orderqueue = [player, enemy1, enemy2, enemy3]
     self.orderqueue.sort(key=lambda x: x.current_dex(), reverse=True)
コード例 #8
0
ファイル: http_gui.py プロジェクト: wagnerjw/SamplerBox
    def do_POST(self):
        length = int(self.headers.getheader('content-length'))
        field_data = self.rfile.read(length)
        fields=parse_qs(field_data)
        display=True
        #----------------------------------------------#
        # Process fields with special logic first      #
        #----------------------------------------------#
        if "SB_RenewMedia" in fields:
            if UI.RenewMedia(fields["SB_RenewMedia"]):
                self.do_GET()   # answer the browser
                return
        if "SB_Preset" in fields:
            loading=UI.Preset(UI.procs["Presetlist"][1]()[int(fields["SB_Preset"][0])][0])
            if loading:
                self.do_GET()   # answer the browser
                return
        if "SB_DefinitionTxt" in fields:
            loading=UI.DefinitionTxt(fields["SB_DefinitionTxt"][0])
            if loading:
                self.do_GET()   # answer the browser
                return
        voicechange=False
        if "SB_Voice" in fields: voicechange=UI.Voice(int(fields["SB_Voice"][0]))
        notemapchange=False
        if "SB_Notemap" in fields and not voicechange: UI.Notemap(int(fields["SB_Notemap"][0]))
        if not (voicechange or notemapchange):
            if "SB_nm_inote"  in fields:    # inote is used as a signal: remapping requires it and html page sends it regardless of it being changed
                if UI.nm_inote(int(fields["SB_nm_inote"][0])):   # so now we know something has changed on a screen containing remapping fields
                    if "SB_nm_Q" in fields: UI.nm_Q(int(fields["SB_nm_Q"][0]))    # needs to be before onote to get proper name2note translation
                    if "SB_nm_unote" in fields: UI.nm_unote(int(fields["SB_nm_unote"][0]))    # needs to be before onote, so onote can reset it
                    if "SB_nm_onote" in fields: UI.nm_onote(int(fields["SB_nm_onote"][0]))
                    if "SB_nm_retune" in fields: UI.nm_retune(int(fields["SB_nm_retune"][0]))
                    if "SB_nm_voice" in fields: UI.nm_voice(int(fields["SB_nm_voice"][0])-1)
                    UI.nm_consolidate()
        scalechange=False       # Scale takes precedence over Chord
        if "SB_Scale" in fields: scalechange=(UI.Scale()!=UI.Scale(int(fields["SB_Scale"][0])))
        if "SB_Chord" in fields and not scalechange: UI.Chord(int(fields["SB_Chord"][0]))
        if "SB_Button" in fields: display = not (UI.Button(fields["SB_Button"][0])) # if we had succesfull button, a display was shown already
        #----------------------------------------------#
        # Next process straightforward fields in bulk  #
        #----------------------------------------------#
        for n in fields:
            nam=n[3:]
            if nam not in ["RenewMedia","Preset","DefinitionTxt","Voice","Notemap","nm_inote","nm_Q","nm_onote","nm_retune","nm_voice","Scale","Chord","Button"]:    #"nm_map","nm_sav",
                self.set_UI_parm(nam,fields[n][0])

        if display: UI.display("") # show it on the box if not done already
        self.do_GET()       # as well as on the gui
コード例 #9
0
    def start(self):
        mainScreen = UI.Screen(width=100, height=20, verticalOffset=2, horizontalOffset=10)
        title = UI.Text('Greet-o-machine')
        
        helloCommand = UI.Command(self, self.sayHello)
        helloButton = UI.Button('Hello', helloCommand)

        goodByeCommand = UI.Command(self, self.sayGoodBye)
        goodByeButton = UI.Button('Good bye', goodByeCommand)

        exitCommand = UI.Command(self, mainScreen.exit)
        exitButton = UI.Button('Exit', exitCommand)

        mainMenu = UI.Menu(helloButton, goodByeButton, exitCommand, horizontalOffset=5)
        menuHandler = UI.MenuHandler(mainMenu)

        mainScreen.appendElement(title)
        mainScreen.appendElement(mainMenu)
        
        mainScreen.start()
        while mainScreen.running:
            mainScreen.draw()
            key = ord(getch())
            menuHandler.handle(key)
コード例 #10
0
ファイル: game.py プロジェクト: Atech1/CS-Intro-Final-Project
def main():
    music = musicpicker.music()
    musicplayer = music.play(-1)

    global camera_controller, button
    camera_controller = CameraController()
    button = UI.Button(300, 250,
                       "CLICK ANYWHERE TO START""\n"
                       "|--Tilden and Alec's Roguelike--| \n |-----Dungeon Dive-----|"
                       " \nTry the dungeon if you dare!\n""\n""Controls:\n""WASD to move Character\n"
                       "Arrow keys to move screen\n""\n"
                       "Alec Ross (asr3b)\n""Tilden Winston (tw8rt)\n",
                       "black", UI.text_descriptor(), None, splash_end)
    gamebox.timer_loop(30, splash_screen)
    button.deactivate()
    UI.background()
    camera_controller.world.load()
    gamebox.timer_loop(15, play)
    return
コード例 #11
0
ファイル: main.py プロジェクト: PK1725/Dijkstras-Algorithm
import pyglet
from pyglet.window import key, mouse
import graphics, UI
import graphGenerator, eventHandler, constants

window = pyglet.window.Window(vsync=True,
                              resizable=True,
                              width=constants.SCREEN_WIDTH,
                              height=constants.SCREEN_HEIGHT,
                              caption="Dijkstras Algoritme")
constants.SCREEN_WIDTH = window.width
constants.SCREEN_HEIGHT = window.height

handler = eventHandler.Handler()
button1 = UI.Button('Generate', window.width - 275, window.height - 200, 180,
                    50, (79, 77, 73))
button2 = UI.Button2('Dijkstra',
                     constants.SCREEN_WIDTH - 275,
                     constants.SCREEN_HEIGHT - 600,
                     180,
                     50, (79, 77, 73),
                     button1=button1)
text = UI.Start("", constants.SCREEN_WIDTH - 205,
                constants.SCREEN_HEIGHT - 300, 25, "Start:")
text2 = UI.Start("", constants.SCREEN_WIDTH - 205,
                 constants.SCREEN_HEIGHT - 400, 25, "Stop:")

handler.add(button1)
handler.add(button2)
handler.add(text)
handler.add(text2)
コード例 #12
0
 def __init__(self):
     #sys vars
     self.running = True
     self.click = False
     self.hold = False
     self.startHold = None
     self.size = (300,500)
     self.screen = pygame.display.set_mode(self.size)        
     self.clock = pygame.time.Clock()
     self.current_screen = self.Main_menu
     self.sys_font = pygame.font.Font(pygame.font.match_font('Calibri'), 40)
     self.mouse_drag_start = None
     self.swipe_dir = []
     self.swipe = ''
     
     #hunt specefic vars
     self.hunt_id = None
     self.all_questions = []
     self.current_question = 0
     
     #BUTTONS
     button_theme = {
         'outline': True,
         'curve': 0.4,
         'background_color': (255, 0, 0)
     }
     button_theme_new = button_theme.copy()
     button_theme_new.update({'dont_generate': True})
     #buttons for Main menu
     self.Main_menu_buttons = [
         UI.Button(
             self.size[0]//2 - 100, 100 + dy*100, 200, 40,
                 button_theme_new) for dy in range(3)]
     #set text and actions to main menu buttons
     self.Main_menu_buttons[0].Update_text("history")
     self.Main_menu_buttons[1].Update_text("Hunt")
     self.Main_menu_buttons[2].Update_text("Scan")
     self.Main_menu_buttons[0].on_click = History_button
     self.Main_menu_buttons[1].on_click = Start_hunt_button
     self.Main_menu_buttons[2].on_click = Scan_button
     button_theme_new = button_theme.copy()
     button_theme_new.update({'on_click': Question_button, 'text': 'Question'})
     self.current_question_button = UI.Button(
         self.size[0]//2 - 100, 400, 200, 40, button_theme_new)
     #create the buttons on camera screen
     surf = pygame.Surface((30,30), pygame.SRCALPHA)
     for y in range(3):
         pygame.draw.line(surf,(255,255,255),(0,5 + y*10),(30,5 + y*10), 1)
     button_theme_new = button_theme.copy()
     button_theme_new.update({'image': surf, 'enlarge': True, 'on_click': Camera_main_menu_button})
     self.Camera_menu_button = UI.Button(self.size[0] - 60,self.size[1] - 60,
                                         param_options=button_theme_new)
     surf = pygame.Surface((30,30),pygame.SRCALPHA)
     surf2 = pygame.Surface((40,40),pygame.SRCALPHA)
     pygame.draw.circle(surf,(255,255,255),(15,15),15,2)
     pygame.draw.circle(surf2, (255,255,255), (20,20), 20,2)
     button_theme_new = button_theme.copy()
     button_theme_new.update({'image': surf, 'hover_image': surf2 })       
     self.Camera_settings_button = UI.Button(self.size[0]//4-20, self.size[1] - 60,
                                             param_options=button_theme_new) 
     surf = pygame.Surface((60,60),pygame.SRCALPHA)
     surf2 = pygame.Surface((60,60),pygame.SRCALPHA)
     pygame.draw.circle(surf, (255,255,255),(30,30),30,4)
     pygame.draw.circle(surf2, (255,255,255),(30,30),30,8)
     button_theme_new = button_theme.copy()
     button_theme_new.update({'image': surf, 'hover_image': surf2 })         
     self.Camera_take_photo_button = UI.Button(self.size[0]//2 - 30,self.size[1] - 90,
                                               param_options=button_theme_new)
     
     #Settings
     self.settings_check_boxes = [UI.CheckBox(200,150 + 50*i,40,
                                              {'background_color': (200,200,200),
                                               'outline': True}
                                              ) for i in range(3)]
     self.setting_back_button = UI.Button(50, 400, 200, 40,
                                          {'background_color': (255, 0, 0),
                                           'curve': 0.4,
                                           'text': 'Back',
                                           'outline': True
                                           }
                                          )
     #all hunts
     self.hunt_names = db.get_all_hunts() + [['Cancel']]
     self.hunt_names_buttons = [UI.Button(50, 100 + 100*i,200, 40, {
                                          'background_color': (255,0,0),
                                          'outline': True,
                                          'text': self.hunt_names[i][0],
                                          'curve': 0.4}
                                          ) for i in range(len(self.hunt_names))]
     num_hunts = db.num_hunts()
     if num_hunts > 3:
         scroll_amount = (num_hunts - 3) * 100
         self.hunt_screen_scroll = UI.Scroll({'range_y': scroll_amount})
     else:
         self.hunt_screen_scroll = None
コード例 #13
0
ファイル: GameLayer.py プロジェクト: CritBear/PeacefulVillage
 def _create_button(self, img, pos, event, parent=None, scale=1):
     button = UI.Button(img, pos, event, scale)
     self.add(button)
     if parent is not None:
         parent.add(button)
     return button
コード例 #14
0
    def __init__(self,
                 x,
                 y,
                 width,
                 height,
                 clear_colour,
                 autoplay=False,
                 view_all_cards=False,
                 terminal=False):
        # TODO: Reduce the amount of update_table call
        self.update_table = Signal()
        self.x = x
        self.y = y
        self.width = width
        self.height = height

        self.table_font = pygame.font.SysFont("None", 25)
        self.player_font = pygame.font.SysFont("None", 25)

        # For gameplay
        self.game_state = GameState.DEALING
        self.reshuffling_players = []
        self.current_round = 0
        self.passes = 0
        self.current_player = 0
        self.first_player = False  # This is for bidding purposes
        self.players = []
        self.players_playzone = []
        # Table status will be made known to the player by reference
        self.table_status = {
            'played cards': [0, 0, 0, 0],
            'leading player': 0,
            'trump suit': 1,
            'trump broken': False,
            'round history': [],
            'bid': 0,
            'partner': 0,
            'partner reveal': False,
            'defender': {
                'target': 0,
                'wins': 0
            },
            'attacker': {
                'target': 0,
                'wins': 0
            }
        }

        # Prepare the surfaces for displaying
        self.background = pygame.Surface((self.width, self.height))
        self.background.fill(clear_colour)
        self.background = self.background.convert()

        # TODO: Update the drawing of the table?
        # Prepare the card with dimensions
        w_deck = min(self.height, self.width) * 0.18
        l_deck = min(self.width, self.height) * 0.7
        # This is not a deck as it will never be drawn
        self.discard_deck = cards.prepare_playing_cards(
            int(w_deck * 0.6), int(w_deck * 0.6 * 97 / 71))
        game_margins = 5

        # Players' deck positioning
        playerx = ((self.width - l_deck) // 2, game_margins,
                   (self.width - l_deck) // 2,
                   self.width - w_deck - game_margins)
        playery = (self.height - w_deck - game_margins,
                   (self.height - l_deck) // 2, game_margins,
                   (self.height - l_deck) // 2)
        h_spacing = 20
        v_spacing = 25

        # Middle playfield for announcer and player playing deck positioning
        playfield_margins = 5
        margins_with_w_deck = w_deck + playfield_margins + game_margins
        playfield_x = margins_with_w_deck
        playfield_y = margins_with_w_deck
        playfield_width = self.width - margins_with_w_deck * 2
        playfield_height = self.height - margins_with_w_deck * 2

        playdeckx = (playfield_x + (playfield_width - w_deck) / 2, playfield_x,
                     playfield_x + (playfield_width - w_deck) / 2,
                     playfield_x + playfield_width - w_deck)
        playdecky = (playfield_y + playfield_height - w_deck,
                     playfield_y + (playfield_height - w_deck) / 2,
                     playfield_y,
                     playfield_y + (playfield_height - w_deck) / 2)

        # Player stats positioning
        stats_width = 100
        self.stats_height = 100
        stats_spacing = 10
        self.player_stats_x = (playdeckx[0] - stats_width - stats_spacing,
                               playdeckx[1],
                               playdeckx[2] + w_deck + stats_spacing,
                               playdeckx[3])
        self.player_stats_y = (playdecky[0] + w_deck - self.stats_height,
                               playdecky[1] - self.stats_height -
                               stats_spacing, playdecky[2],
                               playdecky[3] - w_deck - stats_spacing)

        self.player_stats = [[], [], [], []]

        # TODO: change surface to use colorkey, maybe, if the performance is tanked
        # Prepare all the player surfaces
        for i in range(NUM_OF_PLAYERS):
            vert = i % 2 == 1
            spacing = h_spacing
            if vert:
                spacing = v_spacing

            reveal_mode = cards.DeckReveal.HIDE_ALL
            if i == 0 or view_all_cards:
                reveal_mode = cards.DeckReveal.SHOW_ALL

            if i == 0:
                player_class = players.MainPlayer
                if terminal:
                    player_class = players.Player
                self.players.append(
                    player_class(playerx[i],
                                 playery[i],
                                 l_deck,
                                 w_deck,
                                 spacing,
                                 vert_orientation=vert,
                                 deck_reveal=reveal_mode))
            else:
                self.players.append(
                    players.Player(playerx[i],
                                   playery[i],
                                   l_deck,
                                   w_deck,
                                   spacing,
                                   vert_orientation=vert,
                                   deck_reveal=reveal_mode,
                                   flip=(i == 1 or i == 2),
                                   draw_from_last=(i == 2 or i == 3)))

            self.players[i].connect_to_table(self.table_status)
            if i > 0:
                self.players[i].add_ai(ai.VivianAI(self.table_status))

            self.players_playzone.append(
                cards.Deck(playdeckx[i], playdecky[i], w_deck, w_deck, 0))
            for j in range(3):
                surf = pygame.Surface((stats_width, self.stats_height / 3),
                                      pygame.SRCALPHA)
                rendered_text = self.player_font.render(
                    "Player {0:d}".format(i), True,
                    (255, 0, 255)).convert_alpha()
                self.center_text_on_surface(
                    surf, rendered_text,
                    (255, 255, 255, 255 * VIEW_TRANSPARENT))
                self.player_stats[i].append(surf)

        if autoplay:
            self.players[0].add_ai(ai.VivianAI(self.table_status))

        # Announcer positioning and surface creation
        announcer_margins = 5
        announcer_spacing = announcer_margins + w_deck
        self.announcer_x = playfield_x + announcer_spacing
        self.announcer_y = playfield_y + announcer_spacing
        self.announcer_width = playfield_width - 2 * announcer_spacing
        self.announcer_height = playfield_height - 2 * announcer_spacing
        self.announcer_line = []
        for i in range(3):
            surf = pygame.Surface(
                (self.announcer_width, self.announcer_height / 3),
                pygame.SRCALPHA)
            self.announcer_line.append(surf)

        self.update_all_players(role=True, wins=True, clear_wins=True)

        self.write_message("Press P to play!")

        self.ongoing = False
        self.require_player_input = False

        self.terminal_play = terminal
        self.calling_panel = UI.CallPanel(playdeckx[0] + w_deck + 5,
                                          playdecky[0] + w_deck - 100, 220,
                                          100)
        self.calling_panel.parent = self
        self.calling_panel.visible = False
        self.parent = None

        self.calling_panel.confirm_output.connect(self.emit_call)

        self.yes_button = UI.Button(playdeckx[0] + w_deck + 5,
                                    playdecky[0],
                                    50,
                                    25,
                                    text='yes')
        self.yes_button.visible = False
        self.yes_button.clicked.connect(lambda **z: pygame.event.post(
            pygame.event.Event(CALL_EVENT, call=True)))

        self.no_button = UI.Button(playdeckx[0] + w_deck + 5,
                                   playdecky[0] + 25 + 25,
                                   50,
                                   25,
                                   text='no')
        self.no_button.clicked.connect(lambda **z: pygame.event.post(
            pygame.event.Event(CALL_EVENT, call=False)))
        self.no_button.visible = False

        self.UI_elements = [
            self.calling_panel, self.yes_button, self.no_button
        ]
コード例 #15
0
 def add_button(self, text, signal, alignment):
     button = UI.Button(None, text, signal)
     button.align(*alignment)
     self.objects.append(button)
     self.buttons.append(button)
コード例 #16
0
ファイル: Example.py プロジェクト: Abdur-rahmaanJ/PygameUI
#create our textBoxes and Buttons
InputBox = UI.TextBox(
    x = 100,
    y = 100,
    w = 300,
    h = 30,
    background=(200,200,200), 
    lines = 2,
    cursor = True
)
button1 = UI.Button(
    x = 100,
    y = 300,
    w = 10,
    h = 5,
    calculateSize = True,
    outline = UI.Outline(),
    background = (200,200,200), 
    action = button_clicked,
    dont_generate = True,
    curve_amount=0.5
)

#becuase we want to calculate the size of button1 without text or an image, we can use 'dont_generate = True'
#then use Update_text(text) to calculate the size

button1.Update_text("Button")

print(button1)

button2 = UI.Button(
    x = 200,
コード例 #17
0
    def __init__(self, game):
        self.game = game
        self.custom_blitting = pygame.Surface((DESIGN_W, DESIGN_H))
        self.mouse_moving = 0
        self.camera = Camera((self.game.w, self.game.h), (DESIGN_W, DESIGN_H))

        self.rect_start = None
        self.rect_started = False
        self.drag_start = None
        self.resizing = False

        self.editor_ui = UI.UIManager()
        self.property_panel = None
        self.property_panel_recently_closed = False

        self.selected_object = Wall

        self.grid = self.generate_grid(16, 9)

        self.wall_button = UI.Button(2, 200, 200, 60, "Wall", (255, 0, 0),
                                     self.change_object, Wall)
        self.door_button = UI.Button(2, 280, 200, 60, "Door", (150, 150, 150),
                                     self.change_object, Door)
        self.spawn_button = UI.Button(2, 360, 200, 60, "Spawn",
                                      (150, 150, 150), self.change_object,
                                      SpawnPoint)
        self.plate_button = UI.Button(2, 440, 200, 60, "Plate",
                                      (150, 150, 150), self.change_object,
                                      Plate)
        self.goal_button = UI.Button(2, 520, 200, 60, "Goal", (150, 150, 150),
                                     self.change_object, EndGoal)
        self.option_button = UI.Button(5,
                                       DESIGN_H - 110,
                                       100,
                                       100,
                                       "O", (150, 150, 150),
                                       self.map_options, [],
                                       center_text=True)
        self.x_grid_text = UI.Text(740, DESIGN_H - 110, self.grid_x, 72,
                                   (255, 255, 255))
        self.y_grid_text = UI.Text(740, DESIGN_H - 50, self.grid_y, 72,
                                   (255, 255, 255))
        self.x_grid_slider = UI.Slider(130,
                                       DESIGN_H - 110,
                                       600,
                                       40,
                                       1,
                                       32, (150, 150, 150), (200, 200, 200),
                                       self.update_grid,
                                       self.x_grid_text,
                                       whole_numbers=True)
        self.y_grid_slider = UI.Slider(130,
                                       DESIGN_H - 50,
                                       600,
                                       40,
                                       1,
                                       32, (150, 150, 150), (200, 200, 200),
                                       self.update_grid,
                                       self.y_grid_text,
                                       whole_numbers=True)
        self.x_grid_slider.set_value(self.grid_x / 33)
        self.y_grid_slider.set_value(self.grid_y / 33)

        self.exit_button = UI.Button(DESIGN_W - 110,
                                     5,
                                     100,
                                     100,
                                     "X", (150, 150, 150),
                                     self.game.start_main_menu,
                                     '',
                                     center_text=True)

        self.selected_button = self.wall_button

        self.editor_ui.add(self.wall_button)
        self.editor_ui.add(self.door_button)
        self.editor_ui.add(self.spawn_button)
        self.editor_ui.add(self.plate_button)
        self.editor_ui.add(self.goal_button)
        self.editor_ui.add(self.option_button)
        self.editor_ui.add(self.x_grid_text)
        self.editor_ui.add(self.y_grid_text)
        self.editor_ui.add(self.x_grid_slider)
        self.editor_ui.add(self.y_grid_slider)
        self.editor_ui.add(self.exit_button)

        self.spawn_points_count = 0

        self.rects = pygame.sprite.Group(Background((DESIGN_W, DESIGN_H)))
        self.selected_rect = -1
        self.selected_arrow = ""
        self.vertical_arrow = None
        self.horizontal_arrow = None
        self.moving_offset = None
        self.fixed_point = None

        self.save_options_ui = UI.UIManager()

        self.back_button = UI.Button(DESIGN_W / 2 - 480,
                                     DESIGN_H - 150,
                                     200,
                                     60,
                                     "Back", (150, 150, 150),
                                     self.map_options, [],
                                     center_text=True)

        self.save_button = UI.Button(DESIGN_W / 2 + 250,
                                     DESIGN_H - 150,
                                     200,
                                     60,
                                     "Save", (150, 150, 150),
                                     self.save_to_file, [],
                                     center_text=True)

        self.open_button = UI.Button(DESIGN_W / 2,
                                     DESIGN_H - 150,
                                     200,
                                     60,
                                     "Open", (150, 150, 150),
                                     self.open_map, [],
                                     center_text=True)

        self.map_name_text = UI.Text(DESIGN_W / 2 - 500, DESIGN_H / 2 - 450,
                                     "Map name", 72, (255, 255, 255))
        self.map_name = UI.InputField(DESIGN_W / 2 - 500, DESIGN_H / 2 - 400,
                                      800, 60, None, None, 100)
        self.map_author_text = UI.Text(DESIGN_W / 2 - 500, DESIGN_H / 2 - 300,
                                       "Map author", 72, (255, 255, 255))
        self.map_author = UI.InputField(DESIGN_W / 2 - 500, DESIGN_H / 2 - 250,
                                        800, 60, None, None, 100)
        self.player_size_text = UI.Text(DESIGN_W / 2 - 500, DESIGN_H / 2 - 150,
                                        "Player size", 72, (255, 255, 255))
        self.player_size = UI.InputField(DESIGN_W / 2 - 440 +
                                         self.player_size_text.get_width(),
                                         DESIGN_H / 2 - 150,
                                         100,
                                         60,
                                         None,
                                         None,
                                         100,
                                         text_type=int,
                                         char_limit=2)
        self.player_size.set_text('64')

        self.save_options_ui.add(
            UI.Image(DESIGN_W / 2 - 510,
                     DESIGN_H / 2 - 510,
                     1000,
                     1000,
                     color=(200, 200, 200, 240)))
        self.save_options_ui.add(self.back_button)
        self.save_options_ui.add(self.save_button)
        self.save_options_ui.add(self.map_name_text)
        self.save_options_ui.add(self.map_name)
        self.save_options_ui.add(self.map_author_text)
        self.save_options_ui.add(self.map_author)
        self.save_options_ui.add(self.player_size_text)
        self.save_options_ui.add(self.player_size)
        self.save_options_ui.add(self.open_button)

        self.ui_to_draw = self.editor_ui

        #self.map_path = map_path
        #if self.map_path:
        #self.map_data = self.load_map(map_path)
        self.dialogues = []
        self.clicked_on_ui = -1
コード例 #18
0
    w = 300,
    h = 30,
    param_options={
        'background':(200,200,200), 
        'lines' : 2,
        'cursor' : True
    }
)
button1 = UI.Button(
    x = 100,
    y = 300,
    w = 10,
    h = 5,
    param_options={
        'calculate_size' : True,
        'outline' : True,
        'background_color' : (200,200,200), 
        'on_click' : button_clicked,
        'dont_generate' : True,
        'curve':0.5,
        'center': True
    }
)

#becuase we want to calculate the size of button1 without text or an image, we can use 'dont_generate = True'
#then use Update_text(text) to calculate the size

button1.Update_text("Button")

print(button1)
コード例 #19
0
    def __init__(self, main_menu):
        super().__init__(main_menu)
        self.fullscreen_toggle = UI.Toggle(20, 20, 400, 64, "Fullscreen",
                                           self.toggle_fullscreen)
        self.ui_manager.add(self.fullscreen_toggle)

        self.resolution_dropdown = UI.DropDown(20, 100, 400, 60, [
            "1920x1080", "1366x768", "1280x720", "1152x664", "960x540",
            "640x360"
        ], (100, 100, 100), (75, 75, 75), self.change_resolution)

        self.ui_manager.add(self.resolution_dropdown)

        self.fps_counter_toggle = UI.Toggle(20, 180, 400, 64, "FPS Counter",
                                            self.toggle_fps)
        self.ui_manager.add(self.fps_counter_toggle)

        self.ui_manager.add(
            UI.Button(main_menu.game.DESING_W - 250,
                      main_menu.game.DESING_H - 100,
                      200,
                      60,
                      "Back", (200, 200, 200),
                      main_menu.main_menu, [],
                      center_text=True,
                      font_size=70))

        p1_text = UI.Text(720, 20, "Player 1", 56, (255, 255, 255))
        p2_text = UI.Text(930, 20, "Player 2", 56, (255, 255, 255))
        left_text = UI.Text(520, 95, "Left", 56, (255, 255, 255))
        right_text = UI.Text(520, 175, "Right", 56, (255, 255, 255))
        jump_text = UI.Text(520, 255, "Jump", 56, (255, 255, 255))
        self.ui_manager.add(p1_text)
        self.ui_manager.add(p2_text)
        self.ui_manager.add(left_text)
        self.ui_manager.add(right_text)
        self.ui_manager.add(jump_text)

        keybind_grid = UI.Grid(675, 70, 600, 300, 200, 60, 20, 20)
        cfg = main_menu.game.config
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg['p1_left']),
            (200, 200, 200), self.set_keybind, ['p1_left'], True
        ])
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg["p2_left"]),
            (200, 200, 200), self.set_keybind, ['p2_left'], True
        ])
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg["p1_right"]),
            (200, 200, 200), self.set_keybind, ['p1_right'], True
        ])
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg["p2_right"]),
            (200, 200, 200), self.set_keybind, ['p2_right'], True
        ])
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg["p1_jump"]),
            (200, 200, 200), self.set_keybind, ['p1_jump'], True
        ])
        keybind_grid.add(UI.Button, [
            self.key_to_char(cfg["p2_jump"]),
            (200, 200, 200), self.set_keybind, ['p2_jump'], True
        ])
        self.ui_manager.add(keybind_grid)

        editor_grid = UI.Grid(1200, 70, 600, 900, 200, 60, 20, 20)
        editor_grid.add(UI.Text, ["Clear", 56, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_clear']),
            (200, 200, 200), self.set_keybind, ['ed_clear'], True
        ])
        editor_grid.add(UI.Text, ["Reload", 56, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_reload']),
            (200, 200, 200), self.set_keybind, ['ed_reload'], True
        ])
        editor_grid.add(UI.Text, ["Camera reset", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_camera_reset']),
            (200, 200, 200), self.set_keybind, ['ed_camera_reset'], True
        ])
        editor_grid.add(UI.Text, ["Delete", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_delete']),
            (200, 200, 200), self.set_keybind, ['ed_delete'], True
        ])
        editor_grid.add(UI.Text, ["Wall", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_wall']),
            (200, 200, 200), self.set_keybind, ['ed_wall'], True
        ])
        editor_grid.add(UI.Text, ["Door", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_door']),
            (200, 200, 200), self.set_keybind, ['ed_door'], True
        ])
        editor_grid.add(UI.Text, ["Spawn", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_spawn']),
            (200, 200, 200), self.set_keybind, ['ed_spawn'], True
        ])
        editor_grid.add(UI.Text, ["Plate", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_plate']),
            (200, 200, 200), self.set_keybind, ['ed_plate'], True
        ])
        editor_grid.add(UI.Text, ["Goal", 46, (255, 255, 255)])
        editor_grid.add(UI.Button, [
            self.key_to_char(cfg['ed_goal']),
            (200, 200, 200), self.set_keybind, ['ed_goal'], True
        ])
        self.ui_manager.add(editor_grid)

        self.fullscreen_toggle.activated = main_menu.game.config[
            'fullscreen'] == 1
        self.fps_counter_toggle.activated = main_menu.game.config[
            'fps_counter']
        self.fps_counter_toggle.update_surface()
        self.fullscreen_toggle.update_surface()
        self.resolution_dropdown.set_choice(
            None, "{}x{}".format(main_menu.game.w, main_menu.game.h))

        self.waiting_for_key = False
        self.keybind = None
        self.btn = None