Example #1
0
class DriverPageGui(ThanksPageGui):
    def __init__(self, mdt, menu_args, driverpage_props):
        self.props = driverpage_props
        ThanksPageGui.__init__(self, mdt, menu_args)

    def bld_page(self):
        self.skills = [drv[2] for drv in self.props.drivers]
        menu_gui = self.mdt.menu.gui
        menu_args = self.mdt.menu.gui.menu_args
        widgets = [
            OnscreenText(text=_('Select the driver'),
                         pos=(0, .8),
                         **menu_gui.menu_args.text_args)
        ]
        self.track_path = self.mdt.menu.track
        t_a = self.mdt.menu.gui.menu_args.text_args.copy()
        del t_a['scale']
        name = OnscreenText(_('Write your name:'),
                            pos=(-.1, .6),
                            scale=.06,
                            align=TextNode.A_right,
                            **t_a)
        self.ent = DirectEntry(scale=.08,
                               pos=(0, 1, .6),
                               entryFont=menu_args.font,
                               width=12,
                               frameColor=menu_args.btn_color,
                               initialText=self.props.player_name
                               or _('your name'))
        self.ent.onscreenText['fg'] = menu_args.text_fg
        self.drivers = []
        for row, col in product(range(2), range(4)):
            idx = (col + 1) + row * 4
            widgets += [
                ImgBtn(scale=.24,
                       pos=(-.75 + col * .5, 1, .25 - row * .5),
                       frameColor=(0, 0, 0, 0),
                       image=self.props.drivers_img[0] % idx,
                       command=self.on_click,
                       extraArgs=[idx],
                       **self.mdt.menu.gui.menu_args.imgbtn_args)
            ]
            self.drivers += [widgets[-1]]
            sign = lambda x: '\1green\1+\2' if x > 0 else ''
            psign = lambda x: '+' if x == 0 else sign(x)

            def ppcol(x):
                return '\1green\1%s\2' % x if x > 0 else '\1red\1%s\2' % x

            pcol = lambda x: x if x == 0 else ppcol(x)

            def add_lab(txt, pos_z):
                return OnscreenText(txt + ':',
                                    pos=(-.95 + col * .5, pos_z - row * .5),
                                    scale=.046,
                                    align=TextNode.A_left,
                                    **t_a)

            def add_txt(val, pos_z):
                return OnscreenText('%s%s%%' % (psign(val), pcol(val)),
                                    pos=(-.55 + col * .5, pos_z - row * .5),
                                    scale=.052,
                                    align=TextNode.A_right,
                                    **t_a)

            lab_lst = [(_('adherence'), .04), (_('speed'), .16),
                       (_('stability'), .1)]
            widgets += map(lambda lab_def: add_lab(*lab_def), lab_lst)
            txt_lst = [(self.skills[idx - 1][1], .04),
                       (self.skills[idx - 1][0], .16),
                       (self.skills[idx - 1][2], .1)]
            widgets += map(lambda txt_def: add_txt(*txt_def), txt_lst)
        self.img = OnscreenImage(self.props.cars_img % self.mdt.car,
                                 parent=base.a2dBottomRight,
                                 pos=(-.38, 1, .38),
                                 scale=.32)
        widgets += [self.img, name, self.ent]
        map(self.add_widget, widgets)
        fpath = eng.curr_path + 'yyagl/assets/shaders/filter.vert'
        with open(fpath) as ffilter:
            vert = ffilter.read()
        shader = Shader.make(Shader.SL_GLSL, vert, frag)
        self.img.setShader(shader)
        self.img.setTransparency(True)
        self.t_s = TextureStage('ts')
        self.t_s.setMode(TextureStage.MDecal)
        empty_img = PNMImage(1, 1)
        empty_img.add_alpha()
        empty_img.alpha_fill(0)
        tex = Texture()
        tex.load(empty_img)
        self.img.setTexture(self.t_s, tex)
        ThanksPageGui.bld_page(self)
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        self.enable_buttons(False)

    def enable_buttons(self, enable):
        for drv in self.drivers:
            drv['state'] = NORMAL if enable else DISABLED
            drv.setShaderInput('enable', 1 if enable else .2)
            # do wdg.enable, wdg.disable

    def update_text(self, task):
        has_name = self.ent.get() != _('your name')
        if has_name and self.ent.get().startswith(_('your name')):
            self.ent.enterText(self.ent.get()[len(_('your name')):])
            self.enable_buttons(True)
        elif self.ent.get() in [_('your name')[:-1], '']:
            self.ent.enterText('')
            self.enable_buttons(False)
        elif self.ent.get() not in [_('your name'), '']:
            self.enable_buttons(True)
        return task.cont  # don't do a task, attach to modifications events

    def on_click(self, i):
        txt_path = self.props.drivers_img[1]
        self.img.setTexture(self.t_s, loader.loadTexture(txt_path % i))
        self.widgets[-1]['state'] = DISABLED
        self.enable_buttons(False)
        taskMgr.remove(self.update_tsk)
        names = Utils().get_thanks(6)
        cars = self.props.cars[:]
        cars.remove(self.mdt.car)
        shuffle(cars)
        drv_idx = range(1, 9)
        drv_idx.remove(i)
        shuffle(drv_idx)
        drivers = [(i, self.ent.get(), self.skills[i - 1], self.mdt.car)]
        drivers += [(drv_idx[j], names[j], self.skills[j - 1], cars[j])
                    for j in range(6)]
        self.mdt.menu.gui.notify('on_driver_selected', self.ent.get(), drivers,
                                 self.mdt.track, self.mdt.car)

    def destroy(self):
        self.img = None
        taskMgr.remove(self.update_tsk)
        PageGui.destroy(self)
Example #2
0
class Bship(ShowBase):

    PLposb = []
    PLposs = []
    PLposp = []
    AIposp = []
    AIposs = []
    AIposb = []
    AImemb = []
    AImems = []
    AImemp = []
    logText = ''
    c = 0
    s = 0
    b = 0
    p = 0
    helptext = ""

    def __init__(self):
        super().__init__()

        self.AISettup()
        # camera settup
        self.camera.setHpr(-35, -24, 0)
        self.camera.setPos(-2.5, -4, 7)

        # disable camera
        self.disable_mouse()

        # env settup
        self.setBackgroundColor(0.1, 0.6, 1.0)

        self.myFrame = DirectFrame(frameColor=(0, 0, 0, 0.3),
                                   frameSize=(-0.2, 1, -0.3, 0.155),
                                   pos=(1, 0, -0.75))

        # add text entry
        self.entry = DirectEntry(text='',
                                 scale=.05,
                                 command=self.event,
                                 numLines=1,
                                 focus=1,
                                 focusOutCommand=self.clearText,
                                 pos=(-0.195, 0, -0.235))
        self.entry.reparentTo(self.myFrame)
        print(self.entry.getPos())

        self.logTextBox = OnscreenText(text='',
                                       pos=(-0.145, 0.11, 0),
                                       scale=0.05,
                                       align=TextNode.ALeft)
        self.logTextBox.reparentTo(self.myFrame)
        constanttext = OnscreenText(text="write h for help, n to hide help",
                                    pos=(0.4, -0.9),
                                    scale=0.05,
                                    fg=(0, 0, 0, 1),
                                    mayChange=0)
        self.htext = OnscreenText(text=self.helptext,
                                  pos=(0.325, -0.625),
                                  scale=0.055,
                                  fg=(0, 0, 0, 1),
                                  mayChange=1)
        coordtext = OnscreenText(
            text=
            "b(1<x<10 si 4<y<13),\ns(1<x<10 si 4<y<12),\np(1<x<10 si 4<y<13),\nc(1<x<10 si 4<y<11)",
            pos=(1.5, -0.4),
            scale=0.05,
            fg=(0, 0, 0, 1),
            mayChange=0)
        mksgridp = "     Planes\n  2    3    4    5    6    7    8    9\n5 |     |     |     |     |     |     |     |     |\n   --------------------------------\n6 |     |     |     |     |     |     |     |     |\n   --------------------------------\n7 |     |     |     |     |     |     |     |     |\n   --------------------------------\n8 |     |     |     |     |     |     |     |     |\n   --------------------------------\n" \
                   "9 |     |     |     |     |     |     |     |     |\n   --------------------------------\n10|     |     |     |     |     |     |     |     |\n   --------------------------------\n11 |     |     |     |     |     |     |     |     |\n   --------------------------------\n12|     |     |     |     |     |     |     |     |"
        mksgridb = "    Boats\n  2    3    4    5    6    7    8    9\n5 |     |     |     |     |     |     |     |     |\n   --------------------------------\n6 |     |     |     |     |     |     |     |     |\n   --------------------------------\n7 |     |     |     |     |     |     |     |     |\n   --------------------------------\n8 |     |     |     |     |     |     |     |     |\n   --------------------------------\n" \
                   "9 |     |     |     |     |     |     |     |     |\n   --------------------------------\n10|     |     |     |     |     |     |     |     |\n   --------------------------------\n11 |     |     |     |     |     |     |     |     |\n   --------------------------------\n12|     |     |     |     |     |     |     |     |"
        mksgrids = "Submarines\n  2    3    4    5    6    7    8    9\n5 |     |     |     |     |     |     |     |     |\n   --------------------------------\n6 |     |     |     |     |     |     |     |     |\n   --------------------------------\n7 |     |     |     |     |     |     |     |     |\n   --------------------------------\n8 |     |     |     |     |     |     |     |     |\n   --------------------------------\n" \
                   "9 |     |     |     |     |     |     |     |     |\n   --------------------------------\n10|     |     |     |     |     |     |     |     |\n   --------------------------------\n11 |     |     |     |     |     |     |     |     |\n   --------------------------------\n12|     |     |     |     |     |     |     |     |"
        showx = OnscreenText(text="X",
                             pos=(0.56, 0.43),
                             scale=0.065,
                             fg=(0, 0, 0, 1),
                             mayChange=0)
        showy = OnscreenText(text="Y",
                             pos=(0.325, 0.675),
                             scale=0.065,
                             fg=(0, 0, 0, 1),
                             mayChange=0)
        xorient = OnscreenText(text="X",
                               pos=(-0.7, 0.45),
                               scale=0.2,
                               fg=(0, 0, 0, 1),
                               mayChange=0)
        yorient = OnscreenText(text="Y",
                               pos=(-1.25, -0.75),
                               scale=0.2,
                               fg=(0, 0, 0, 1),
                               mayChange=0)
        makeshiftgridplane = OnscreenText(text=mksgridp,
                                          pos=(1.55, 0.95),
                                          scale=0.03,
                                          fg=(0, 0, 0, 1),
                                          mayChange=0)
        makeshiftgridboat = OnscreenText(text=mksgridb,
                                         pos=(1.05, 0.95),
                                         scale=0.03,
                                         fg=(0, 0, 0, 1),
                                         mayChange=0)
        makeshiftgridsubmar = OnscreenText(text=mksgrids,
                                           pos=(0.55, 0.95),
                                           scale=0.03,
                                           fg=(0, 0, 0, 1),
                                           mayChange=0)

        # TaskManager
        taskMgr.add(self.movCameraTask, 'movCameraTask')

    def clearText(self):
        self.entry.enterText('')

    def event(self, bk_text):
        try:
            if bk_text[0] == 's':
                if self.s <= 1:
                    t = bk_text[2:]
                    self.submarineSpawn(t)
                else:
                    self.logTextBox.text = 'Submarines limit reached 2/2'
            elif bk_text[0] == 'b':
                if self.b <= 1:
                    t = bk_text[2:]
                    self.boatSpawn(t)
                else:
                    self.logTextBox.text = 'Boats limit reached 2/2'
            elif bk_text[0] == 'c':
                if self.c == 0:
                    t = bk_text[2:]
                    self.cruiserSpawn(t)
                else:
                    self.logTextBox.text = 'Cruisers limit reached 1/1'
            elif bk_text[0] == 'h':
                self.htext.text = "Ctrl + 1/2/3 schimba planul\nplasarea se face in felul urmator:\ns/p/b/c coord x apoi coord y Ex: b 5 8\nPentru atac formatul este:\n(planul)1/2/3 coord x apoi coord y Ex 3 8 10"
            elif bk_text[0] == 'n':
                self.htext.text = ""
            elif bk_text[0] == 'p':
                if self.p <= 1:
                    t = bk_text[2:]
                    self.planeSpawn(t)
                else:
                    self.logTextBox.text = 'Planes limit reached 2/2'
            else:
                if self.c != 1 or self.b != 2 or self.s != 2 or self.p != 2:
                    self.logTextBox.text = 'Preparation phase still ongoing\nPlease deploy all your units\n'
                else:
                    self.check(bk_text)
        except ValueError:
            self.logTextBox.text = 'Incorrect input!Try again'

    def movCameraTask(self, task):
        pos = self.camera.getPos()
        if keyboard.is_pressed('ctrl'):
            if keyboard.is_pressed('1'):
                pos.z = 7
            if keyboard.is_pressed('2'):
                pos.z = -7
            if keyboard.is_pressed('3'):
                pos.z = 21
        self.camera.setPos(pos)
        return task.cont

    # Entities

    def corners_b(self):
        for i in range(2, 10):
            for j in range(5, 13):
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(i, j, 0)
                box.setScale(0.5)
                texocean = self.loader.load_texture("modeleBS3D/oceancub.jpg")
                box.setTexture(texocean)
                box.reparentTo(self.render)

    def corners_a(self):
        for i in range(2, 10):
            for j in range(5, 13):
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(i, j, 14)
                box.setScale(0.5)
                texcer = self.loader.load_texture("modeleBS3D/noricub.jpg")
                box.setTexture(texcer)
                box.reparentTo(self.render)

    def corners_s(self):
        for i in range(2, 10):
            for j in range(5, 13):
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(i, j, -14)
                box.setScale(0.5)
                texsubapa = self.loader.load_texture(
                    "modeleBS3D/subapanisip.jpg")
                box.setColor(0.2, 0.5, 0.8)
                box.setTexture(texsubapa)
                box.reparentTo(self.render)

    def cruiser(self, x, y):
        if 1 < x < 10 and 4 < y < 11:
            carrier = self.loader.loadModel("modeleBS3D/Carrier.obj")
            carrier.setPos(x, y + 1, 0.5)
            carrier.setHpr(-180, 90, 0)
            carrier.setScale(0.0125, 0.01, 0.01)
            texcarrier = self.loader.load_texture("modeleBS3D/texboat3.jpg")
            carrier.setTexture(texcarrier)
            carrier.reparentTo(self.render)
            self.c += 1
        else:
            self.logTextBox.text = 'Object outside Area'

    def boat(self, x, y):
        if 1 < x < 10 and 4 < y < 13:
            boat2 = self.loader.load_model("modeleBS3D/Boat2.obj")
            boat2.setPos(x, y, 0.5)
            boat2.setHpr(-90, 0, 0)
            boat2.setScale(0.0005)
            texboat2 = self.loader.load_texture("modeleBS3D/texboat3.jpg")
            boat2.setTexture(texboat2)
            boat2.reparentTo(self.render)
            self.b += 1
        else:
            self.logTextBox.text = 'Object outside Area'

    def submarine(self, x, y):
        if 1 < x < 10 and 4 < y < 12:
            sub1 = self.loader.loadModel("modeleBS3D/Submarine1.obj")
            sub1.setPos(x + 0.425, y + 1.5, -13)
            sub1.setHpr(-180, 90, 0)
            sub1.setScale(0.04)
            texsub1 = self.loader.load_texture("modeleBS3D/texplane.jpg")
            sub1.setTexture(texsub1)
            sub1.reparentTo(self.render)
            self.s += 1
        else:
            self.logTextBox.text = 'Object outside Area'

    def plane(self, x, y):
        if 1 < x < 10 and 4 < y < 13:
            plane3 = self.loader.loadModel("modeleBS3D/Plane5.obj")
            plane3.setPos(x, y, 15)
            plane3.setHpr(180, -270, 180)
            plane3.setScale(0.08)
            texplane3 = self.loader.load_texture("modeleBS3D/texplane3.jpg")
            plane3.setTexture(texplane3)
            plane3.reparentTo(self.render)
            self.p += 1
        else:
            self.logTextBox.text = 'Object outside Area'

    # Model Spawn

    def submarineSpawn(self, bk_text):
        x, y = bk_text.split(" ")
        x = int(x)
        y = int(y)
        l = []
        l2 = []
        l.append(x)
        l.append(y)
        l2.append(x)
        l2.append(y + 1)
        if l in self.PLposs or l2 in self.PLposs:
            self.logTextBox.text = 'There already is a unit on that position'
        else:
            self.logTextBox.text = 'Submarine deployed ' + str(self.s +
                                                               1) + '/2'
            self.PLposs.append([x, y])
            self.PLposs.append([x, y + 1])
            self.submarine(x, y)

    def boatSpawn(self, bk_text):
        x, y = bk_text.split(" ")
        x = int(x)
        y = int(y)
        l = []
        l.append(x)
        l.append(y)
        if l in self.PLposb:
            self.logTextBox.text = 'There already is a unit on that position'
        else:
            self.logTextBox.text = 'Boat deployed ' + str(self.b + 1) + '/2'
            self.PLposb.append([x, y])
            self.boat(x, y)

    def cruiserSpawn(self, bk_text):
        x, y = bk_text.split(" ")
        x = int(x)
        y = int(y)
        l = []
        l2 = []
        l3 = []
        l.append(x)
        l.append(y)
        l2.append(x)
        l2.append(y + 1)
        print(l2)
        l3.append(x)
        l3.append(y + 2)
        if l in self.PLposb or l2 in self.PLposb or l3 in self.PLposb:
            self.logTextBox.text = 'There already is a unit on that position'
        else:
            self.logTextBox.text = 'Cruiser deployed ' + str(self.c + 1) + '/1'
            self.PLposb.append([x, y])
            self.PLposb.append([x, y + 1])
            self.PLposb.append([x, y + 2])
            self.cruiser(x, y)

    def planeSpawn(self, bk_text):
        x, y = bk_text.split(" ")
        x = int(x)
        y = int(y)
        l = []
        l.append(x)
        l.append(y)
        if l in self.PLposp:
            self.logTextBox.text = 'There already is a unit on that position'
        else:
            self.logTextBox.text = 'Plane deployed ' + str(self.p + 1) + '/2'
            self.PLposp.append([x, y])
            self.plane(x, y)

    def AISettup(self):
        c = 0
        p = 0
        b = 0
        s = 0
        for i in range(6):
            if s < 2:
                x = random.randint(2, 9)
                y = random.randint(5, 11)
                self.AIposs.append([x, y])
                self.AIposs.append([x, y + 1])
                s += 1
            elif c < 1:
                x = random.randint(2, 9)
                y = random.randint(5, 10)
                self.AIposb.append([x, y])
                self.AIposb.append([x, y + 1])
                self.AIposb.append([x, y + 2])
                c += 1
            elif p < 2:
                x = random.randint(2, 9)
                y = random.randint(5, 12)
                self.AIposp.append([x, y])
                p += 1
            elif b < 2:
                x = random.randint(2, 9)
                y = random.randint(5, 12)
                self.AIposb.append([x, y])
                b += 1

    def check(self, bk_text):
        if self.PLposs == [] and self.PLposb == [] and self.PLposp == []:
            self.logTextBox.text = 'You lost!'
        elif self.AIposs == [] and self.AIposb == [] and self.AIposp == []:
            self.logTextBox.text = 'You won!'
        else:
            if bk_text[0] == '1':
                bk_text = bk_text[2:]
                l = []
                if bk_text == "":
                    pass
                else:
                    x, y = bk_text.split(" ")
                    l.append(int(x))
                    l.append(int(y))
                    print(l)
                    if 1 < int(x) < 10 and 4 < int(y) < 13:
                        if l in self.AIposs:
                            self.logTextBox.text = "Hit"
                            self.hit = OnscreenText(
                                text='X',
                                pos=(0.39 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                        else:
                            self.logTextBox.text = "Miss"
                            self.hit = OnscreenText(
                                text='O',
                                pos=(0.39 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                    else:
                        self.logTextBox.text = 'Outside Area'
            elif bk_text[0] == '2':
                bk_text = bk_text[2:]
                l = []
                if bk_text == "":
                    pass
                else:
                    x, y = bk_text.split(" ")
                    l.append(int(x))
                    l.append(int(y))
                    print(l)
                    if 1 < int(x) < 10 and 4 < int(y) < 13:
                        if l in self.AIposb:
                            self.logTextBox.text = "Hit"
                            self.hit = OnscreenText(
                                text='X',
                                pos=(0.89 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                        else:
                            self.logTextBox.text = "Miss"
                            self.hit = OnscreenText(
                                text='O',
                                pos=(0.89 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                    else:
                        self.logTextBox.text = 'Outside Area'
            elif bk_text[0] == '3':
                bk_text = bk_text[2:]
                l = []
                if bk_text == "":
                    pass
                else:
                    x, y = bk_text.split(" ")
                    l.append(int(x))
                    l.append(int(y))
                    print(l)
                    if 1 < int(x) < 10 and 4 < int(y) < 13:
                        if l in self.AIposp:
                            self.logTextBox.text = "Hit"
                            self.hit = OnscreenText(
                                text='X',
                                pos=(1.39 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                        else:
                            self.logTextBox.text = "Miss"
                            self.hit = OnscreenText(
                                text='O',
                                pos=(1.39 + 0.0442857142857143 * (int(x) - 2),
                                     0.88 - 0.0592857142857143 * (int(y) - 5),
                                     0),
                                scale=0.05,
                                align=TextNode.ALeft)
                    else:
                        self.logTextBox.text = 'Outside Area'

        AIl = []
        AIx = random.randint(2, 9)
        AIy = random.randint(5, 12)
        AIl.append(AIx)
        AIl.append(AIy)
        AIz = random.randint(1, 3)
        print(AIz)
        if AIz == 1:
            if AIl in self.PLposs:
                self.logTextBox.text = 'One of our units has been hit!'
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(AIx, AIy, -13)
                box.setScale(0.48)
                texfoc = self.loader.load_texture("modeleBS3D/flama.jpg")
                box.setTexture(texfoc)
                box.reparentTo(self.render)
                self.PLposs.remove(AIl)
            else:

                if AIl in self.AImems:
                    while AIl in self.AImems:
                        AIl = []
                        AIx = random.randint(2, 9)
                        AIy = random.randint(5, 12)
                        AIl.append(AIx)
                        AIl.append(AIy)
                    self.AImems.append(AIl)
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, -13.75)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                else:
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, -13.75)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                    self.AImems.append(AIl)
        if AIz == 2:
            if AIl in self.PLposb:
                self.logTextBox.text = 'One of our units has been hit!'
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(AIx, AIy, 0.5)
                box.setScale(0.48)
                texfoc = self.loader.load_texture("modeleBS3D/flama.jpg")
                box.setTexture(texfoc)
                box.reparentTo(self.render)
                self.PLposb.remove(AIl)
            else:

                if AIl in self.AImemb:
                    while AIl in self.AImemb:
                        AIl = []
                        AIx = random.randint(2, 9)
                        AIy = random.randint(5, 12)
                        AIl.append(AIx)
                        AIl.append(AIy)
                    self.AImems.append(AIl)
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, 0.25)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                else:
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, 0.25)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                    self.AImemb.append(AIl)
        if AIz == 3:
            if AIl in self.PLposp:
                self.logTextBox.text = 'One of our units has been hit!'
                box = self.loader.loadModel("modeleBS3D/cube.obj")
                box.setPos(AIx, AIy, 15)
                box.setScale(0.48)
                texfoc = self.loader.load_texture("modeleBS3D/flama.jpg")
                box.setTexture(texfoc)
                box.reparentTo(self.render)
                self.PLposp.remove(AIl)
            else:

                if AIl in self.AImemp:
                    while AIl in self.AImemp:
                        AIl = []
                        AIx = random.randint(2, 9)
                        AIy = random.randint(5, 12)
                        AIl.append(AIx)
                        AIl.append(AIy)
                    self.AImemp.append(AIl)
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, 14.25)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                else:
                    box = self.loader.loadModel("modeleBS3D/cube.obj")
                    box.setPos(AIx, AIy, 14.25)
                    box.setScale(0.3)
                    box.setColor(1, 0.1, 0.1, 0.3)
                    box.reparentTo(self.render)
                    self.AImemp.append(AIl)
Example #3
0
class CustomizeScreen(DirectFrame):
    notify = directNotify.newCategory('CustomizeScreen')

    def __init__(self, callback, **kw):
        self._callback = callback
        geom = loader.loadModel('phase_6/models/gui/ui_frame')
        optiondefs = (('relief', None, None), ('geom', geom,
                                               None), ('geom_scale', 1.5, 1.5),
                      ('text', base.localAvatar.getName(),
                       None), ('text_align', TextNode.ACenter, None),
                      ('text_font', FONT, None), ('text_scale', 0.075, None),
                      ('text_pos', (0, 0.65), None), ('pos', (-0.7, 0, 0.16),
                                                      None))
        self.defineoptions(kw, optiondefs)
        DirectFrame.__init__(self, aspect2d)
        self.initialiseoptions(CustomizeScreen)

        self.genderOptions = None
        self.genderLabel = None
        self.speciesOptions = None
        self.speciesLabel = None
        self.legOptions = None
        self.legLabel = None
        self.torsoOptions = None
        self.torsoLabel = None
        self.headOptions = None
        self.headLabel = None
        self.muzzleOptions = None
        self.muzzleLabel = None
        self.gloveOptions = None
        self.gloveLabel = None
        self.headColorOptions = None
        self.headColorLabel = None
        self.armColorOptions = None
        self.armColorLabel = None
        self.legColorOptions = None
        self.legColorLabel = None
        self.shirtColorOptions = None
        self.shirtColorLabel = None
        self.bottomsColorOptions = None
        self.bottomsColorLabel = None
        self.shirtLabel = None
        self.shirtEntry = None
        self.shortsLabel = None
        self.shortsEntry = None
        self.doneButton = None

        geom.removeNode()
        rotateGeoms = loader.loadModel('phase_6/models/gui/ui_arrow_buttons')
        leftGeom = (rotateGeoms.find('**/*ArrowLeft*Up'),
                    rotateGeoms.find('**/*ArrowLeft*Down'),
                    rotateGeoms.find('**/*ArrowLeft*Rollover'))

        rightGeom = (rotateGeoms.find('**/*ArrowRight*Up'),
                     rotateGeoms.find('**/*ArrowRight*Down'),
                     rotateGeoms.find('**/*ArrowRight*Rollover'))
        self.leftButton = DirectButton(parent=self,
                                       relief=None,
                                       image=leftGeom,
                                       pos=(-0.11, 0, -0.07))
        self.rightButton = DirectButton(parent=self,
                                        relief=None,
                                        image=rightGeom,
                                        pos=(0.11, 0, -0.07))

        self.leftButton.bind(DGG.B1PRESS, self.__rotateToon, [-3])
        self.leftButton.bind(DGG.B1RELEASE, self.__stopRotation)
        self.rightButton.bind(DGG.B1PRESS, self.__rotateToon, [3])
        self.rightButton.bind(DGG.B1RELEASE, self.__stopRotation)
        rotateGeoms.removeNode()

        self.toon = None
        self.dna = None
        self.pitch = self.attachNewNode('pitch')
        self.rotate = self.pitch.attachNewNode('rotate')
        self.scale = self.rotate.attachNewNode('scale')
        self.pitch.setP(0)

        self.makeToon()

    def makeToon(self, dna=None):
        if self.toon:
            self.toon.cleanup()
            self.toon.delete()
            self.toon.removeNode()
            self.toon = None
            self.dna = None

        if not dna:
            dna = base.localAvatar.getDNAString()

        self.toon = Toon.Toon()
        self.dna = ToonDNA.ToonDNA()
        self.dna.makeFromNetString(dna)
        self.toon.setDNA(self.dna)
        self.toon.getGeomNode().setDepthWrite(1)
        self.toon.getGeomNode().setDepthTest(1)
        self.toon.setHpr(180, 0, 0)
        self.toon.setZ(-0.45)

        scaleFactor = 0.2
        if self.dna.legs == 'l':
            scaleFactor = 0.19

        self.toon.setScale(scaleFactor)
        self.toon.reparentTo(self.scale)

    def __rotateToon(self, *args):
        taskMgr.add(self.__rotateTask,
                    'toonRotateTask',
                    extraArgs=[args[0]],
                    appendTask=True)

    def __rotateTask(self, direction, task):
        if hasattr(self, 'pitch'):
            self.pitch.setH((self.pitch.getH() % 360) + 0.4 * direction)
            return task.cont
        else:
            return task.done

    def __stopRotation(self, *args):
        taskMgr.remove('toonRotateTask')

    def __selectHead(self, *args):
        species = name2code.get(args[0].lower())

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(head=species + self.dna.head[1:])
        self.makeToon(newDNA.makeNetString())

    def __selectLegs(self, *args):
        legs = args[0].lower()
        if legs == 'long':
            legs = 'l'
        elif legs == 'medium':
            legs = 'm'
        else:
            legs = 's'

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())

        newDNA.updateToonProperties(legs=legs)
        self.makeToon(newDNA.makeNetString())

    def __selectGloves(self, *args):
        color = args[0]

        if color == 'White':
            index = len(ToonDNA.NumToColor) + 1
        else:
            index = ToonDNA.NumToColor.index(color)

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(gloveColor=index)
        self.makeToon(newDNA.makeNetString())

    def __selectTorso(self, *args):
        torso = args[0][0].lower()
        if self.dna.gender == 'f':
            torso += 'd'
        else:
            torso += 's'

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(torso=torso)
        self.makeToon(newDNA.makeNetString())

    def __selectHeadSize(self, *args):
        size = args[0][0].lower()
        head = self.dna.head

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(head=head[0] + size + head[2])
        self.makeToon(newDNA.makeNetString())

    def __selectMuzzleSize(self, *args):
        size = args[0][0].lower()
        head = self.dna.head

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(head=head[0] + head[1] + size)
        if newDNA.head in ToonDNA.toonHeadTypes:
            self.makeToon(newDNA.makeNetString())

    def __selectGender(self, *args):
        gender = args[0].lower()
        if gender == 'boy':
            gender = 'm'
        else:
            gender = 'f'

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        #newDNA.updateToonProperties(gender=gender)
        newDNA.updateToonProperties(gender=gender, bottomTexture=0)
        self.makeToon(newDNA.makeNetString())

    def __choseHeadColor(self, *args):
        color = args[0]

        if color == 'White':
            index = len(ToonDNA.NumToColor) + 1
        else:
            index = ToonDNA.NumToColor.index(color)
        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(headColor=index)
        self.makeToon(newDNA.makeNetString())

    def __choseArmColor(self, *args):
        color = args[0]

        if color == 'White':
            index = len(ToonDNA.NumToColor) + 1
        else:
            index = ToonDNA.NumToColor.index(color)
        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(armColor=index)
        self.makeToon(newDNA.makeNetString())

    def __choseLegColor(self, *args):
        color = args[0]

        if color == 'White':
            index = len(ToonDNA.NumToColor) + 1
        else:
            index = ToonDNA.NumToColor.index(color)
        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(legColor=index)
        self.makeToon(newDNA.makeNetString())

    def __choseShirtColor(self, *args):
        color = args[0]
        index = ToonDNA.ClothesColorNames.index(color)
        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(topTextureColor=index,
                                    sleeveTextureColor=index)
        self.makeToon(newDNA.makeNetString())

    def __choseShortsColor(self, *args):
        color = args[0]
        index = ToonDNA.ClothesColorNames.index(color)
        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(bottomTextureColor=index)
        self.makeToon(newDNA.makeNetString())

    def __changeShirt(self, *args):
        index = int(args[0])
        if index not in range(0, len(ToonDNA.Shirts)):
            return

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(topTexture=index)
        self.makeToon(newDNA.makeNetString())

    def __changeShorts(self, *args):
        index = int(args[0])

        bottoms = ToonDNA.BoyShorts if self.dna.gender == 'm' else ToonDNA.GirlBottoms
        if index not in range(0, len(bottoms)):
            return

        newDNA = ToonDNA.ToonDNA()
        newDNA.makeFromNetString(self.dna.makeNetString())
        newDNA.updateToonProperties(bottomTexture=index)
        self.makeToon(newDNA.makeNetString())

    def load(self):
        genders = ['Boy', 'Girl']
        gMap = {'m': genders[0], 'f': genders[1]}
        gIndex = gMap.get(self.dna.gender)
        self.genderOptions = CustomizeOption(parent=self,
                                             command=self.__selectGender,
                                             initialitem=gIndex,
                                             items=genders,
                                             pos=(1.15, 0, 0.7))
        self.genderLabel = DirectLabel(parent=self.genderOptions,
                                       relief=None,
                                       text_font=FONT,
                                       text='Gender:',
                                       text_scale=0.85,
                                       pos=(-2.59, 0, 0))

        species = [
            'Bear', 'Cat', 'Dog', 'Duck', 'Horse', 'Monkey', 'Mouse', 'Pig',
            'Rabbit'
        ]
        sIndex = species.index(code2name.get(self.dna.head[0]).capitalize())
        self.speciesOptions = CustomizeOption(parent=self,
                                              command=self.__selectHead,
                                              initialitem=sIndex,
                                              items=species,
                                              pos=(1.15, 0, 0.55))
        self.speciesLabel = DirectLabel(parent=self.speciesOptions,
                                        relief=None,
                                        text_font=FONT,
                                        text='Species:',
                                        text_scale=0.85,
                                        pos=(-2.7, 0, 0))

        headOptions = ['Short', 'Long']
        types = {'s': headOptions[0], 'l': headOptions[1]}
        hIndex = headOptions.index(types.get(self.dna.head[1]))

        self.headOptions = CustomizeOption(parent=self,
                                           command=self.__selectHeadSize,
                                           initialitem=hIndex,
                                           items=headOptions,
                                           pos=(1.15, 0, 0.4))
        self.headLabel = DirectLabel(parent=self.headOptions,
                                     relief=None,
                                     text_font=FONT,
                                     text='Head Size:',
                                     text_scale=0.85,
                                     pos=(-3.07, 0, 0))

        mIndex = headOptions.index(types.get(self.dna.head[2]))
        self.muzzleOptions = CustomizeOption(parent=self,
                                             command=self.__selectMuzzleSize,
                                             initialitem=mIndex,
                                             items=headOptions,
                                             pos=(1.15, 0, 0.25))
        self.muzzleLabel = DirectLabel(parent=self.muzzleOptions,
                                       relief=None,
                                       text_font=FONT,
                                       text='Muzzle Size:',
                                       text_scale=0.85,
                                       pos=(-3.4, 0, 0))

        legs = ['Small', 'Medium', 'Long']
        legType = {'s': 'Small', 'm': 'Medium', 'l': 'Long'}
        lIndex = legs.index(legType.get(self.dna.legs))

        self.legOptions = CustomizeOption(parent=self,
                                          command=self.__selectLegs,
                                          initialitem=lIndex,
                                          items=legs,
                                          pos=(1.15, 0, 0.1))
        self.legLabel = DirectLabel(parent=self.legOptions,
                                    relief=None,
                                    text_font=FONT,
                                    text='Leg Length:',
                                    text_scale=0.85,
                                    pos=(-3.21, 0, 0))

        tIndex = legs.index(legType.get(self.dna.torso[0]))
        self.torsoOptions = CustomizeOption(parent=self,
                                            command=self.__selectTorso,
                                            initialitem=tIndex,
                                            items=legs,
                                            pos=(1.15, 0, -0.05))
        self.torsoLabel = DirectLabel(parent=self.torsoOptions,
                                      relief=None,
                                      text_font=FONT,
                                      text='Torso Length:',
                                      text_scale=0.85,
                                      pos=(-3.57, 0, 0))

        gloveColor = self.dna.gloveColor
        length = len(ToonDNA.NumToColor)
        if gloveColor > length:
            gloveColor = 0
        headColor = self.dna.headColor
        if headColor > length:
            headColor = 0
        armColor = self.dna.armColor
        if armColor > length:
            armColor = 0
        legColor = self.dna.legColor
        if legColor > length:
            legColor = 0

        self.gloveOptions = CustomizeOption(parent=self,
                                            command=self.__selectGloves,
                                            initialitem=gloveColor,
                                            items=ToonDNA.NumToColor,
                                            pos=(1.15, 0, -0.2),
                                            image_pos=(1.55, 0, 0.15),
                                            text_pos=(-0.13, -.1))
        self.gloveLabel = DirectLabel(parent=self.gloveOptions,
                                      relief=None,
                                      text_font=FONT,
                                      text='Glove Color:',
                                      text_scale=0.85,
                                      pos=(-3.35, 0, 0))

        self.headColorOptions = CustomizeOption(parent=self,
                                                command=self.__choseHeadColor,
                                                initialitem=headColor,
                                                items=ToonDNA.NumToColor,
                                                pos=(1.15, 0, -0.35),
                                                image_pos=(1.55, 0, 0.15),
                                                text_pos=(-0.13, -.1))
        self.headColorLabel = DirectLabel(parent=self.headColorOptions,
                                          relief=None,
                                          text_font=FONT,
                                          text='Head Color:',
                                          text_scale=0.85,
                                          pos=(-3.27, 0, 0))

        self.armColorOptions = CustomizeOption(parent=self,
                                               command=self.__choseArmColor,
                                               initialitem=armColor,
                                               items=ToonDNA.NumToColor,
                                               pos=(1.15, 0, -0.5),
                                               image_pos=(1.55, 0, 0.15),
                                               text_pos=(-0.13, -.1))
        self.armColorLabel = DirectLabel(parent=self.armColorOptions,
                                         relief=None,
                                         text_font=FONT,
                                         text='Arm Color:',
                                         text_scale=0.85,
                                         pos=(-3.074, 0, 0))

        self.legColorOptions = CustomizeOption(parent=self,
                                               command=self.__choseLegColor,
                                               initialitem=legColor,
                                               items=ToonDNA.NumToColor,
                                               pos=(1.15, 0, -0.65),
                                               image_pos=(1.55, 0, 0.15),
                                               text_pos=(-0.13, -.1))
        self.legColorLabel = DirectLabel(parent=self.legColorOptions,
                                         relief=None,
                                         text_font=FONT,
                                         text='Leg Color:',
                                         text_scale=0.85,
                                         pos=(-3, 0, 0))

        self.shirtColorOptions = CustomizeOption(
            parent=self,
            command=self.__choseShirtColor,
            initialitem=self.dna.topTexColor - 1,
            items=ToonDNA.ClothesColorNames[1:],
            pos=(1.15, 0, -0.8),
            image_pos=(1.55, 0, 0.15),
            text_pos=(-0.13, -.1))
        self.shirtColorLabel = DirectLabel(parent=self.shirtColorOptions,
                                           relief=None,
                                           text_font=FONT,
                                           text='Shirt Color:',
                                           text_scale=0.85,
                                           pos=(-3, 0, 0))

        self.bottomsColorOptions = CustomizeOption(
            parent=self,
            command=self.__choseShortsColor,
            initialitem=self.dna.botTexColor - 1,
            items=ToonDNA.ClothesColorNames[1:],
            pos=(1.15, 0, -0.95),
            image_pos=(1.55, 0, 0.15),
            text_pos=(-0.13, -.1))
        self.bottomsColorLabel = DirectLabel(parent=self.bottomsColorOptions,
                                             relief=None,
                                             text_font=FONT,
                                             text='Shorts Color:',
                                             text_scale=0.85,
                                             pos=(-3, 0, 0))

        self.shirtEntry = DirectEntry(parent=self,
                                      relief=DGG.GROOVE,
                                      scale=0.08,
                                      pos=(1.6, 0, 0.3),
                                      borderWidth=(0.05, 0.05),
                                      state=DGG.NORMAL,
                                      text_font=FONT,
                                      frameColor=((1, 1, 1, 1), (1, 1, 1, 1),
                                                  (0.5, 0.5, 0.5, 0.5)),
                                      text_align=TextNode.ALeft,
                                      text_scale=0.8,
                                      width=3.5,
                                      numLines=1,
                                      focus=1,
                                      backgroundFocus=0,
                                      cursorKeys=1,
                                      text_fg=(0, 0, 0, 1),
                                      suppressMouse=1,
                                      autoCapitalize=0,
                                      command=self.__changeShirt)
        self.shirtEntry.enterText(str(self.dna.topTex))
        self.shirtLabel = DirectLabel(parent=self.shirtEntry,
                                      relief=None,
                                      text_font=FONT,
                                      text='Shirt:',
                                      text_scale=0.85,
                                      pos=(1.25, 0, 1.25))

        self.shortsEntry = DirectEntry(parent=self,
                                       relief=DGG.GROOVE,
                                       scale=0.08,
                                       pos=(1.6, 0, 0.0),
                                       borderWidth=(0.05, 0.05),
                                       state=DGG.NORMAL,
                                       text_font=FONT,
                                       frameColor=((1, 1, 1, 1), (1, 1, 1, 1),
                                                   (0.5, 0.5, 0.5, 0.5)),
                                       text_align=TextNode.ALeft,
                                       text_scale=0.8,
                                       width=3.5,
                                       numLines=1,
                                       focus=1,
                                       backgroundFocus=0,
                                       cursorKeys=1,
                                       text_fg=(0, 0, 0, 1),
                                       suppressMouse=1,
                                       autoCapitalize=0,
                                       command=self.__changeShorts)
        self.shortsEntry.enterText(str(self.dna.botTex))
        self.shortsLabel = DirectLabel(parent=self.shortsEntry,
                                       relief=None,
                                       text_font=FONT,
                                       text='Shorts:',
                                       text_scale=0.85,
                                       pos=(1.25, 0, 1.25))

        buttonModels = loader.loadModel('phase_3.5/models/gui/inventory_gui')
        upButton = buttonModels.find('**//InventoryButtonUp')
        downButton = buttonModels.find('**/InventoryButtonDown')
        rolloverButton = buttonModels.find('**/InventoryButtonRollover')
        self.doneButton = DirectButton(parent=self,
                                       text_font=FONT,
                                       text='Done',
                                       command=self.__handleDone,
                                       scale=0.2,
                                       image=(upButton, downButton,
                                              rolloverButton),
                                       relief=None,
                                       text_fg=(1, 1, 0.65, 1),
                                       pos=(0, 0, -0.94),
                                       text_pos=(0, -.23),
                                       image_color=(1, 0, 0, 1),
                                       image_scale=(20, 1, 15),
                                       sortOrder=DGG.GEOM_SORT_INDEX)
        buttonModels.removeNode()

    def __handleDone(self):
        base.localAvatar.b_setDNAString(self.dna.makeNetString())
        self.unload()

    def unload(self):
        if self.genderLabel:
            self.genderLabel.destroy()
            self.genderLabel = None

        if self.genderOptions:
            self.genderOptions.destroy()
            self.genderOptions = None

        if self.speciesLabel:
            self.speciesLabel.destroy()
            self.speciesLabel = None

        if self.speciesOptions:
            self.speciesOptions.destroy()
            self.speciesOptions = None

        if self.headLabel:
            self.headLabel.destroy()
            self.headLabel = None

        if self.headOptions:
            self.headOptions.destroy()
            self.headOptions = None

        if self.muzzleLabel:
            self.muzzleLabel.destroy()
            self.muzzleLabel = None

        if self.muzzleOptions:
            self.muzzleOptions.destroy()
            self.muzzleOptions = None

        if self.torsoLabel:
            self.torsoLabel.destroy()
            self.torsoLabel = None

        if self.torsoOptions:
            self.torsoOptions.destroy()
            self.torsoOptions = None

        if self.legLabel:
            self.legLabel.destroy()
            self.legLabel = None

        if self.legOptions:
            self.legOptions.destroy()
            self.legOptions = None

        if self.gloveLabel:
            self.gloveLabel.destroy()
            self.gloveLabel = None

        if self.gloveOptions:
            self.gloveOptions.destroy()
            self.gloveOptions = None

        if self.headColorOptions:
            self.headColorOptions.destroy()
            self.headColorOptions = None

        if self.headColorLabel:
            self.headColorLabel.destroy()
            self.headColorLabel = None

        if self.armColorOptions:
            self.armColorOptions.destroy()
            self.armColorOptions = None

        if self.armColorLabel:
            self.armColorLabel.destroy()
            self.armColorLabel = None

        if self.legColorOptions:
            self.legColorOptions.destroy()
            self.legColorOptions = None

        if self.legColorLabel:
            self.legColorLabel.destroy()
            self.legColorLabel = None

        if self.shirtColorLabel:
            self.shirtColorLabel.destroy()
            self.shirtColorLabel = None

        if self.shirtColorOptions:
            self.shirtColorOptions.destroy()
            self.shirtColorOptions = None

        if self.bottomsColorLabel:
            self.bottomsColorLabel.destroy()
            self.bottomsColorLabel = None

        if self.bottomsColorOptions:
            self.bottomsColorOptions.destroy()
            self.bottomsColorOptions = None

        if self.shirtLabel:
            self.shirtLabel.destroy()
            self.shirtLabel = None

        if self.shirtEntry:
            self.shirtEntry.destroy()
            self.shirtEntry = None

        if self.shortsLabel:
            self.shortsLabel.destroy()
            self.shortsLabel = None

        if self.shortsEntry:
            self.shortsEntry.destroy()
            self.shortsEntry = None

        if self.doneButton:
            self.doneButton.destroy()
            self.doneButton = None

        if self.toon:
            self.toon.cleanup()
            self.toon.delete()
            self.toon.removeNode()
            self.toon = None
            self.dna = None

        self._callback(self)
        self.destroy()