<commit_before>import pygame, sys
from pygame.locals import *
from pgu import gui
from twisted.internet import reactor

import global_vars as g
from constants import *

import gui.pygUI as pygUI

class characterControl(gui.Table):
    def __init__(self, **params):
        gui.Table.__init__(self, **params)
        self.value = gui.Form()
        self.engine = None

        def btnNextChar(btn):
            self.engine.charIndex += 1
            self.engine.updateCharSelection()

        def btnPrevChar(btn):
            self.engine.charIndex -= 1
            self.engine.updateCharSelection()

        def btnUseChar(btn):
            if self.lblPlayerName.value != 'Create a new character':
                g.tcpConn.sendUseChar(self.engine.charIndex-1)
                g.gameEngine.setState(MENU_INGAME)
            else:
                # new char
                g.tcpConn.sendGetClasses()
                g.gameEngine.setState(MENU_NEWCHAR)

        def btnDelChar(btn):
            print "lawl"

        self.tr()
        self.lblPlayerName = gui.Label('PLAYER NAME', color=(255, 0, 0))
        self.td(self.lblPlayerName, colspan=3, valign=1)

        self.tr()
        self.lblPlayerExtra = gui.Label('PLAYER LEVEL/CLASS', color=(255, 0, 0))
        self.td(self.lblPlayerExtra, colspan=3)

        self.tr()
        btn = gui.Button("Previous", width=160, height=40)
        btn.connect(gui.CLICK, btnPrevChar, None)
        self.td(btn)
        self.td(gui.Spacer(300, 160))
        btn = gui.Button("Next", width=160, height=40)
        btn.connect(gui.CLICK, btnNextChar, None)
        self.td(btn)

        self.tr()
        self.td(gui.Spacer(0, 0))
        self.btnSelChar = gui.Button("Use Character", width=160, height=30)
        self.btnSelChar.connect(gui.CLICK, btnUseChar, None)
        self.td(self.btnSelChar)
        self.td(gui.Spacer(0, 0))

        self.tr()
        self.td(gui.Spacer(0, 20))

        self.tr()
        self.td(gui.Spacer(0, 0))
        btn = gui.Button("Delete Character", width=160, height=30)
        btn.connect(gui.CLICK, btnDelChar, None)
        self.td(btn)
        self.td(gui.Spacer(0, 0))

class menuCharacters():
    def __init__(self, surface):
        self.surface = surface
        self.backgroundImage = pygame.image.load(g.dataPath + '/gui/menu_background.png')

        # character selection
        self.characters = []
        self.charIndex = 1

        self.charName = ""
        self.charLevel = 0
        self.charClass = "WAAZZOR"
        self.charSprite = 1

        # sprite image
        self.spriteScale = 3
        self.spriteImage = pygame.Surface((PIC_X * self.spriteScale, PIC_Y * self.spriteScale))
        self.spriteImageRect = self.spriteImage.get_rect()
        self.spriteImageRect.centerx = 800/2
        self.spriteImageRect.centery = 600/2

        # GUI
        self.app = gui.App()

        self.charControl = characterControl()
        self.charControl.engine = self

        self.c = gui.Container(align=0, valign=0)
        self.c.add(self.charControl, 0, 0)

        self.app.init(self.c)

    def draw(self):
        # background
        self.surface.blit(self.backgroundImage, (0, 0))
        self.surface.blit(self.spriteImage, self.spriteImageRect)

        self.app.paint()

        pygame.display.update()

    def _handleEvents(self, event):
        # keyboard shortcuts
        self.app.event(event)

        if event.type == KEYDOWN and event.key == K_ESCAPE:
            g.gameState = MENU_LOGIN
            
        elif event.type == KEYDOWN and event.key == K_RETURN:
            self.doUseChar()


    def updateCharacters(self, data):
        # update character list
        self.characters = data
        self.updateCharSelection()

    def updateCharSelection(self):
        if self.charIndex > MAX_CHARS:
            self.charIndex = 1
        elif self.charIndex < 1:
            self.charIndex = MAX_CHARS
<commit_msg>Added shortcut for choosing char<commit_after>import pygame, sys
from pygame.locals import *
from pgu import gui
from twisted.internet import reactor

import global_vars as g
from constants import *

import gui.pygUI as pygUI

class characterControl(gui.Table):
    def __init__(self, **params):
        gui.Table.__init__(self, **params)
        self.value = gui.Form()
        self.engine = None

        def btnNextChar(btn):
            self.engine.charIndex += 1
            self.engine.updateCharSelection()

        def btnPrevChar(btn):
            self.engine.charIndex -= 1
            self.engine.updateCharSelection()

        def btnUseChar(btn=None):
            if self.lblPlayerName.value != 'Create a new character':
                g.tcpConn.sendUseChar(self.engine.charIndex-1)
                g.gameEngine.setState(MENU_INGAME)
            else:
                # new char
                g.tcpConn.sendGetClasses()
                g.gameEngine.setState(MENU_NEWCHAR)

        def btnDelChar(btn):
            print "lawl"

        self.tr()
        self.lblPlayerName = gui.Label('PLAYER NAME', color=(255, 0, 0))
        self.td(self.lblPlayerName, colspan=3, valign=1)

        self.tr()
        self.lblPlayerExtra = gui.Label('PLAYER LEVEL/CLASS', color=(255, 0, 0))
        self.td(self.lblPlayerExtra, colspan=3)

        self.tr()
        btn = gui.Button("Previous", width=160, height=40)
        btn.connect(gui.CLICK, btnPrevChar, None)
        self.td(btn)
        self.td(gui.Spacer(300, 160))
        btn = gui.Button("Next", width=160, height=40)
        btn.connect(gui.CLICK, btnNextChar, None)
        self.td(btn)

        self.tr()
        self.td(gui.Spacer(0, 0))
        self.btnSelChar = gui.Button("Use Character", width=160, height=30)
        self.btnSelChar.connect(gui.CLICK, btnUseChar, None)
        self.td(self.btnSelChar)
        self.td(gui.Spacer(0, 0))

        self.tr()
        self.td(gui.Spacer(0, 20))

        self.tr()
        self.td(gui.Spacer(0, 0))
        btn = gui.Button("Delete Character", width=160, height=30)
        btn.connect(gui.CLICK, btnDelChar, None)
        self.td(btn)
        self.td(gui.Spacer(0, 0))

class menuCharacters():
    def __init__(self, surface):
        self.surface = surface
        self.backgroundImage = pygame.image.load(g.dataPath + '/gui/menu_background.png')

        # character selection
        self.characters = []
        self.charIndex = 1

        self.charName = ""
        self.charLevel = 0
        self.charClass = "WAAZZOR"
        self.charSprite = 1

        # sprite image
        self.spriteScale = 3
        self.spriteImage = pygame.Surface((PIC_X * self.spriteScale, PIC_Y * self.spriteScale))
        self.spriteImageRect = self.spriteImage.get_rect()
        self.spriteImageRect.centerx = 800/2
        self.spriteImageRect.centery = 600/2

        # GUI
        self.app = gui.App()

        self.charControl = characterControl()
        self.charControl.engine = self

        self.c = gui.Container(align=0, valign=0)
        self.c.add(self.charControl, 0, 0)

        self.app.init(self.c)

    def draw(self):
        # background
        self.surface.blit(self.backgroundImage, (0, 0))
        self.surface.blit(self.spriteImage, self.spriteImageRect)

        self.app.paint()

        pygame.display.update()

    def _handleEvents(self, event):
        # keyboard shortcuts
        self.app.event(event)

        if event.type == KEYDOWN and event.key == K_ESCAPE:
            g.gameState = MENU_LOGIN
            
        elif event.type == KEYDOWN and event.key == K_RETURN:
            self.doUseChar()

    def doUseChar(self):
        if self.charControl.lblPlayerName.value != 'Create a new character':
            g.tcpConn.sendUseChar(self.charIndex-1)
            g.gameEngine.setState(MENU_INGAME)
        else:
            # new char
            g.tcpConn.sendGetClasses()
            g.gameEngine.setState(MENU_NEWCHAR)


    def updateCharacters(self, data):
        # update character list
        self.characters = data
        self.updateCharSelection()

    def updateCharSelection(self):
        if self.charIndex > MAX_CHARS:
            self.charIndex = 1
        elif self.charIndex < 1:
            self.charIndex = MAX_CHARS

{'fraction_non_alphanumeric': 0.11402868952103087, 'fraction_numerical': 0.01787016776075857, 'mean_word_length': 2.0789670658682633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '769702', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2572, 'n_words': 493}