Пример #1
0
def groupEdit(w, g, l):
    pygame.display.set_caption('Group Edit: {}'.format(g.groupName))

    length = len(l)
    for x in range(length, 0, -1):  # Loops through the objects
        menu = l[x - 1]
        # Removes objects that are generated for the menu
        if menu.checkInside(0, 600, 200, 800):
            l.remove(menu)
            classy.Object.counterStorage.append(menu.id)

    while True:
        w.fill(v.BACKGROUND)

        x, y = pygame.mouse.get_pos()

        h.highlightGroupEdit(w, g, x, y)

        drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

        pygame.draw.rect(w, v.BLUE, (0, 600, 100, 100), 2)
        drawText(w, "Links", 50, 650, 35, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (100, 600, 100, 100), 2)
        drawText(w, "Members", 150, 650, 31, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (100, 700, 100, 100), 2)
        drawText(w, "Host", 50, 750, 35, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 700, 100, 100), 2)
        drawText(w, "Done", 150, 750, 35, v.BLUE)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if x > 0 and x < 100:
                    if y > 600 and y < 700:
                        g = groupLink(g, w, l)
                    elif y > 700 and y < 800:
                        g = mainGroupElementDraw(g, w, l)
                if x > 100 and x < 200:
                    if y > 600 and y < 700:
                        g = groupMemberEditDraw(w, g, l)
                    elif y > 700 and y < 800:
                        return g

        for i in l:
            i.draw(w)

        pygame.display.flip()
Пример #2
0
def groupNameDraw(w):
    name = []

    listener = keyboard.Listener(on_press=onPress, on_release=onRelease)
    listener.start()

    clock = pygame.time.Clock()
    lastKey = None

    while True:
        global globalKey

        clock.tick(60)

        x, y = pygame.mouse.get_pos()

        w.fill(v.BACKGROUND)

        back = h.highlighterGroupName(w, x, y)

        drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

        drawText(w, "Enter The Group Name", 600, 300, 35, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (400, 400, 400, 100), 5)

        temp = ''.join(name)

        drawText(w, temp, 600, 450, 30, v.BLUE)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if back:
                    logging.warning("Leaving Group Naming")
                    listener.stop()
                    return None

        if len(name) > 30:
            return temp
        else:
            if globalKey != lastKey:
                if globalKey != None:
                    if globalKey == 'Wait, Go Back':
                        try:
                            name.pop()
                        except:
                            pass
                    elif globalKey == 'Aight, That Will Do':
                        return temp
                    else:
                        name.append(globalKey)

        lastKey = globalKey

        pygame.display.flip()
Пример #3
0
def drawJunctionMenu(w, obj, x, y):
    objX = str(math.floor(obj.x))
    objY = str(math.floor(obj.y))
    objRot = obj.rotation
    if objRot == 360:
        objRot = "0"
    else:
        objRot = str(objRot)

    w.fill(v.BACKGROUND)

    h.highlighterEdit(w, x, y)

    drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

    drawText(w, "Edit Menu", 600, 150, 44, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (500, 125, 200, 50), 2)

    drawText(w, "Done", 600, 650, 40, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (550, 625, 100, 50), 2)

    image = pygame.transform.scale(obj.pygameImgID, (150, 150))
    w.blit(image, (100, 100))

    pygame.draw.rect(w, v.OFFBLUE, (40, 280, 120, 130), 5)
    drawText(w, "Info:", 100, 300, 40, v.BLUE)
    drawText(w, "x: " + objX, 100, 350, 30, v.BLUE)
    drawText(w, "y: " + objY, 100, 370, 30, v.BLUE)
    drawText(w, "rotation: " + objRot, 100, 390, 30, v.BLUE)

    #JUNCTION THINGS

    drawText(w, "Different Traffic Cycles:", 600, 200, 35, v.BLUE)
    drawText(w, "Pink", 450, 250, 30, v.PINK)
    drawText(w, "Blue", 550, 250, 30, v.REALBLUE)
    drawText(w, "Green", 650, 250, 30, v.GREEN)
    if obj.getTyp() == "4J":
        drawText(w, "Orange", 750, 250, 30, v.REALORANGE)

    objAttributes = obj.getSpecial()

    junctionEditBlock(w, objAttributes, obj)

    pygame.display.flip()
Пример #4
0
def drawAll(w, x, y, l, menu, si):
    w.fill(v.BACKGROUND)

    h.highlighter(w, x, y)

    drawText(w, "Return To Menu", 60, 20, 20, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (0, 10, 120, 20), 2)

    drawText(w, "Run MRS", 1120, 760, 40, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (1050, 740, 140, 35), 2)
    drawText(w, "Run GUI", 1120, 700, 40, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (1050, 680, 140, 35), 2)
    w.blit(v.binny, (200, 740))

    if si == 0:
        pygame.draw.rect(w, v.BLUE, (1000, 0, 100, 30), 2)
        drawText(w, "Save", 1050, 15, 30, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (1100, 0, 100, 30), 2)
        drawText(w, "Import", 1150, 15, 30, v.BLUE)
    elif si == 1:
        pygame.draw.rect(w, v.BLUE, (1000, 0, 100, 30), 2)
        drawText(w, "File 1", 1050, 15, 30, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (1100, 0, 100, 30), 2)
        drawText(w, "File 2", 1150, 15, 30, v.BLUE)
    elif si == 2:
        pygame.draw.rect(w, v.BLUE, (1000, 0, 100, 30), 2)
        drawText(w, "File 1", 1050, 15, 30, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (1100, 0, 100, 30), 2)
        drawText(w, "File 2", 1150, 15, 30, v.BLUE)

    if menu == 0:
        l = m.normalMenu(w, l)

    elif menu == 1:
        l = m.junctionMenu(w, l)

    elif menu == 2:
        l = m.otherMenu(w, l)

    for i in l:
        i.draw(w)

    pygame.display.flip()
Пример #5
0
def drawTime(w, x, y, time):

    w.fill(v.BACKGROUND)

    h.highlighterTime(w, x, y)

    text = "Time = " + str(int((time - 350) * 2))

    drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

    drawText(w, "Time Menu", 600, 150, 55, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (450, 100, 300, 100), 2)

    drawText(w, "One Unit of 'Time' = One Minute per in Simulation Second",
             600, 350, 25, v.BLUE)

    drawText(w, text, 600, 400, 30, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (500, 375, 200, 50), 2)

    pygame.draw.rect(w, v.ORANGE, (350, 498, 500, 4))

    drawText(w, "0", 350, 450, 25, v.BLUE)
    pygame.draw.rect(w, v.ORANGE, (348, 470, 4, 30))
    drawText(w, "250", 475, 550, 25, v.BLUE)
    pygame.draw.rect(w, v.ORANGE, (473, 500, 4, 30))
    drawText(w, "500", 600, 450, 25, v.BLUE)
    pygame.draw.rect(w, v.ORANGE, (598, 470, 4, 30))
    drawText(w, "750", 725, 550, 25, v.BLUE)
    pygame.draw.rect(w, v.ORANGE, (723, 500, 4, 30))
    drawText(w, "1000", 850, 450, 25, v.BLUE)
    pygame.draw.rect(w, v.ORANGE, (848, 470, 4, 30))

    drawText(w, "Done", 600, 600, 35, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (560, 580, 80, 40), 2)

    if time:
        pygame.draw.circle(w, v.BLACK, (time, 500), 8)
        pygame.draw.rect(w, v.BLACK, (time - 1, 470, 2, 60))

    pygame.display.flip()
Пример #6
0
def drawRoadMenu(w, obj, x, y):
    objX = str(math.floor(obj.x))
    objY = str(math.floor(obj.y))
    objRot = obj.rotation
    if objRot == 360:
        objRot = "0"
    else:
        objRot = str(objRot)

    w.fill(v.BACKGROUND)

    h.highlighterEdit(w, x, y)

    drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

    drawText(w, "Edit Menu", 600, 150, 44, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (500, 125, 200, 50), 2)

    drawText(w, "Done", 600, 650, 40, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (550, 625, 100, 50), 2)

    image = pygame.transform.scale(obj.pygameImgID, (150, 150))
    w.blit(image, (100, 100))

    pygame.draw.rect(w, v.OFFBLUE, (40, 280, 120, 130), 5)
    drawText(w, "Info:", 100, 300, 40, v.BLUE)
    drawText(w, "x: " + objX, 100, 350, 30, v.BLUE)
    drawText(w, "y: " + objY, 100, 370, 30, v.BLUE)
    drawText(w, "rotation: " + objRot, 100, 390, 30, v.BLUE)

    displayEdit(w, "Length in Metres", 340, obj.length,
                math.floor((((obj.length - 1) * 500) / 999) + 350))

    displayEdit(w, "Red Side Lanes", 400, obj.laneDistro[0],
                int(((obj.laneDistro[0] * 500) / 4) + 350))
    displayEdit(w, "Blue Side Lanes", 460, obj.laneDistro[1],
                int(((obj.laneDistro[1] * 500) / 4) + 350))

    pygame.display.flip()
Пример #7
0
def mainGroupElementDraw(g, w, l):
    pygame.display.set_caption('Select Host Element:')

    length = len(l)
    for x in range(length, 0, -1):  # Loops through the objects
        menu = l[x - 1]
        # Removes objects that are generated for the menu
        if menu.checkInside(0, 600, 200, 800):
            l.remove(menu)
            classy.Object.counterStorage.append(menu.id)

    while True:
        groupHost = g.getGroupHost()

        x, y = pygame.mouse.get_pos()

        w.fill(v.BACKGROUND)

        back = h.highlighterGroupHost(w, x, y, groupHost)

        drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

        drawText(w, "Done", 100, 700, 40, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 600, 200, 200), 2)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if back:
                    logging.warning("Leaving Group Naming")
                    return None
                elif x > 0 and x < 200:
                    if y > 600 and y < 800:
                        return g

                for item in l:
                    if item.typ == "4J" or item.typ == "TJ" or item.typ == "RD":
                        if item.checkWithin(x, y):
                            if groupHost == item:
                                g.setGroupHost(None)
                                item.setGroup(None)
                            else:
                                g.setGroupHost(item)
                                item.setGroup(g)

        for i in l:
            i.draw(w)

        pygame.display.flip()
Пример #8
0
def groupMemberEditDraw(w, g, l):
    pygame.display.set_caption('Select Group Members:')

    while True:
        groupMembers = g.getGroupMembers()

        x, y = pygame.mouse.get_pos()

        w.fill(v.BACKGROUND)

        back = h.highlighterGroupHost(w, x, y)

        for item in groupMembers:
            temp = item.getXY()
            pygame.draw.rect(
                w, v.OFFBLUE,
                (temp[0] - 4, temp[1] - 4, temp[2] + 8, temp[3] + 8))

        drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

        drawText(w, "Done", 100, 700, 40, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 600, 200, 200), 2)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if back:
                    logging.warning("Leaving Group Naming")
                    return g
                elif x > 0 and x < 200:
                    if y > 600 and y < 800:
                        return g

                for item in l:
                    temp = item.getXY()
                    if x > temp[0] and x < temp[0] + temp[2]:
                        if y > temp[1] and y < temp[1] + temp[3]:
                            if item.typ == "TL":
                                if item in groupMembers:
                                    g.removeMember(item)
                                    item.setGroup(None)
                                else:
                                    g.addMember(item)
                                    item.setGroup(g)

        for i in l:
            i.draw(w)

        pygame.display.flip()
Пример #9
0
def drawEdit(w, x, y, initialX, initialY, obj, rot, special1, special2, t1,
             t2):

    #rotConverted=int((rot*(500/360))-350)
    rotConverted = rot

    w.fill(v.BACKGROUND)

    h.highlighterEdit(w, x, y)

    drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

    drawText(w, "Edit Menu", 600, 150, 44, v.BLUE)
    pygame.draw.rect(w, v.BLUE, (500, 125, 200, 50), 2)

    w.blit(obj, (100, 100))

    truncatedX = math.floor(initialX)
    truncatedY = math.floor(initialY)

    xConverted = int((truncatedX * (500 / 1200)) - 350)
    yConverted = int((truncatedY * (500 / 800)) - 350)

    displayEdit(w, "X-Position", 280, truncatedX, xConverted)

    displayEdit(w, "Y-Position", 340, truncatedY, yConverted)

    displayEdit(w, "Rotation", 400, rot, rotConverted)

    temp = 460
    forCountOne = 0
    forCountTwo = 0

    if type(special1) == int:
        specialOneConverted = int((special1 * (500 / 4)) + 350)
        displayEdit(w, t1, temp, special1, specialOneConverted)
        temp += 60
    else:
        specialOneList = []
        for spec in special1:
            specialOneConverted = int((spec * (500 / 4)) + 350)
            specialOneList.append(specialOneConverted)
            displayEdit(w, t1[forCountOne], temp, spec, specialOneConverted)
            temp += 60
            forCountOne += 1

    if type(special2) == int:
        specialTwoConverted = int((special2 * (500 / 4)) + 350)
        displayEdit(w, t2, temp, special2, specialTwoConverted)
    else:
        specialTwoList = []
        for spec in special2:
            specialTwoConverted = int((spec * (500 / 4)) + 350)
            specialTwoList.append(specialTwoConverted)
            displayEdit(w, t2[forCountTwo], temp, spec, specialTwoConverted)
            temp += 60
            forCountTwo += 1

    pygame.display.flip()
    listy = [(xConverted, 280, truncatedX), (yConverted, 340, truncatedY),
             (rotConverted, 400, rot)]

    base = 460

    if forCountOne == 0:
        listy.append((specialOneConverted, base))
        base += 60
    else:
        for spec in specialOneList:
            listy.append((spec, base))
            base += 60

    if forCountTwo == 0:
        listy.append((specialTwoConverted, base))
    else:
        for spec in specialTwoList:
            listy.append((spec, base))
            base += 60

    return listy
Пример #10
0
def editJunction(w, x, y, objectX, objectY, obj, rot, states, exits):
    w.fill(v.BACKGROUND)

    h.highlighterEdit(w, x, y)
Пример #11
0
def groupLink(g, w, l):
    pygame.display.set_caption("Link Traffic Lights")

    currentItem = None
    colourList = [v.GREEN, v.ORANGE, v.REALBLUE, v.REALORANGE]

    while True:
        w.fill(v.BACKGROUND)

        x, y = pygame.mouse.get_pos()

        h.highlightGroupLink(w, currentItem, x, y)

        tempIndex = 0
        for index in g.direction:
            colour = colourList[tempIndex]
            tempIndex += 1
            for item in index:
                temp = item.getXY()
                pygame.draw.rect(
                    w, colour,
                    (temp[0] - 4, temp[1] - 4, temp[2] + 8, temp[3] + 8))

        drawText(w, "Return To Design Phase", 80, 20, 20, v.BLUE)
        pygame.draw.rect(w, v.BLUE, (0, 10, 160, 20), 2)

        if currentItem:
            pygame.draw.rect(w, v.BLUE, (0, 600, 100, 100), 2)
            drawText(w, "North", 50, 650, 35, v.BLUE)
            pygame.draw.rect(w, v.BLUE, (100, 600, 100, 100), 2)
            drawText(w, "East", 150, 650, 31, v.BLUE)
            pygame.draw.rect(w, v.BLUE, (100, 700, 100, 100), 2)
            drawText(w, "South", 50, 750, 35, v.BLUE)
            pygame.draw.rect(w, v.BLUE, (0, 700, 100, 100), 2)
            drawText(w, "West", 150, 750, 35, v.BLUE)
        else:
            drawText(w, "Done", 100, 700, 40, v.BLUE)
            pygame.draw.rect(w, v.BLUE, (0, 600, 200, 200), 2)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if not currentItem:
                    if x > 0 and x < 200:
                        if y > 600 and y < 800:
                            return g

                    for item in l:
                        if item.typ == "TL":
                            temp = item.getXY()
                            if x > temp[0] and x < temp[0] + temp[2]:
                                if y > temp[1] and y < temp[1] + temp[3]:
                                    currentItem = item

                if currentItem:
                    if g.inDirections(currentItem):
                        if x > 0 and x < 100:
                            if y > 600 and y < 700:
                                g.removeDirection(currentItem, 0)
                                currentItem = None
                            elif y > 700 and y < 800:
                                g.removeDirection(currentItem, 1)
                                currentItem = None
                        elif x > 100 and x < 200:
                            if y > 600 and y < 700:
                                g.removeDirection(currentItem, 2)
                                currentItem = None
                            elif y > 700 and y < 800:
                                g.removeDirection(currentItem, 3)
                                currentItem = None
                    else:
                        if x > 0 and x < 100:
                            if y > 600 and y < 700:
                                g.addDirection(currentItem, 0)
                                currentItem = None
                            elif y > 700 and y < 800:
                                g.addDirection(currentItem, 1)
                                currentItem = None
                        elif x > 100 and x < 200:
                            if y > 600 and y < 700:
                                g.addDirection(currentItem, 2)
                                currentItem = None
                            elif y > 700 and y < 800:
                                g.addDirection(currentItem, 3)
                                currentItem = None
                    try:
                        print(currentItem.id, g.direction)
                    except:
                        pass

        for i in l:
            i.draw(w)

        pygame.display.flip()