Exemplo n.º 1
0
def ClientMain():
    # set up the gui
    guiMan = getGuiManager()
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    neroImg = gui.create_image( guiMan, 'nero_background', Pos2i(0,0), Pos2i(800,600), 'data/gui/nero_background.png' )

    x_offset, y_offset = (800 - 200)/2, (600 - 100)/2

    combo_box = gui.create_combo_box(guiMan, "mod_selector", Pos2i(x_offset, y_offset + 50), Pos2i(200, 25))
    for i, mod_id in enumerate(mods):
        combo_box.addItem(MOD_TITLES.get(mod_id, mod_id))

    startButton = gui.create_button( guiMan, 'start', Pos2i(x_offset, y_offset), Pos2i(60,25), '' )
    startButton.text = 'Start'
    startButton.OnMouseLeftClick = SwitchToSelectedMod(combo_box)

    helpButton = gui.create_button( guiMan, 'help', Pos2i(x_offset + 70, y_offset), Pos2i(60,25), '' )
    helpButton.text = 'Help'
    helpButton.OnMouseLeftClick = openWiki('RunningOpenNero')

    killButton = gui.create_button( guiMan, 'kill', Pos2i(x_offset + 140, y_offset), Pos2i(60,25), '' )
    killButton.text = 'Quit'
    killButton.OnMouseLeftClick = lambda: getSimContext().killGame()

    ioMap = createInputMapping()
    getSimContext().setInputMapping(ioMap)
Exemplo n.º 2
0
def CreateGui(guiMan):
    print 'CreateGui'
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    towerButton3 = gui.create_button(guiMan, 'tower3', Pos2i(0,0), Pos2i(150,30), '')
    towerButton3.text = '3 Layer Towers of Hanoi'
    towerButton3.OnMouseLeftClick = lambda: getMod().start_tower(3)

    agentWindow = gui.create_window(guiMan, 'agentWindow', Pos2i(20, 20), Pos2i(150, 120), 'Agent')
    agentWindow.addChild(towerButton3)

    speedupValue = gui.create_text(guiMan, 'speedupEditBox', Pos2i(260, 30), Pos2i(100, 30), str(0))

    speedupLabel = gui.create_text(guiMan, 'speedupLabel', Pos2i(10, 30), Pos2i(100, 30), 'Speedup:')

    speedupScroll = gui.create_scroll_bar(guiMan, 'speedupScroll', Pos2i(100, 30), Pos2i(150,20), True)
    speedupScroll.setMax(100)
    speedupScroll.setLargeStep(10)
    speedupScroll.setSmallStep(1)
    speedupScroll.setPos(0)
    getMod().set_speedup(0)
    speedupScroll.OnScrollBarChange = speedup_adjusted(speedupScroll, speedupValue)

    paramWindow = gui.create_window(guiMan, 'paramWindow', Pos2i(20, 500), Pos2i(300,100), 'Parameters')
    paramWindow.addChild(speedupLabel)
    paramWindow.addChild(speedupScroll)
    paramWindow.addChild(speedupValue)
Exemplo n.º 3
0
def CreateGui(guiMan, mode):
    print 'CreateGui'
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    ui = UI()  # a collection of all the UI elements

    window_width = 250  # width
    control_height = 30  # height

    # AGENT SELECTION BOX
    x, y = 5, 2 * control_height + 5
    w, h = window_width - 15, control_height - 10
    ui.agentBoxLabel = gui.create_text(guiMan, 'agentLabel', Pos2i(x, y),
                                       Pos2i(3 * w / 10, h), 'Agent Type:')
    ui.agentComboBox = gui.create_combo_box(guiMan, "agentComboBox",
                                            Pos2i(x + 5 + 3 * w / 10, y),
                                            Pos2i(7 * w / 10, h))
    ui.active_agents = []
    for agent_name, agent_function, agent_mode in getMod().AGENTS:
        if mode == agent_mode:
            ui.active_agents.append((agent_name, agent_function, agent_mode))
            ui.agentComboBox.addItem(agent_name)

    # START/RESET AND PAUSE/CONTINUE AGENT BUTTONS AND HELP BUTTON
    x, y = 5, 0 * control_height + 5
    w, h = (window_width - 25) / 4, control_height - 5
    ui.startAgentButton = gui.create_button(guiMan, 'startAgentButton',
                                            Pos2i(x, y), Pos2i(w, h), '')
    ui.pauseAgentButton = gui.create_button(guiMan, 'pauseAgentButton',
                                            Pos2i(x + w + 5, y), Pos2i(w, h),
                                            '')
    ui.helpButton = gui.create_button(guiMan, 'helpButton',
                                      Pos2i(x + 2 * w + 10, y), Pos2i(w, h),
                                      '')
    ui.exitButton = gui.create_button(guiMan, 'exitButton',
                                      Pos2i(x + 3 * w + 15, y), Pos2i(w, h),
                                      '')
    ui.startAgentButton.text = 'Start'
    ui.pauseAgentButton.text = 'Pause'
    ui.helpButton.text = 'Help'
    ui.exitButton.text = 'Exit'
    ui.pauseAgentButton.enabled = False
    ui.startAgentButton.OnMouseLeftClick = startAgent(ui)
    ui.pauseAgentButton.OnMouseLeftClick = pauseAgent(ui)
    ui.helpButton.OnMouseLeftClick = openWiki('BlocksWorldMod')
    ui.exitButton.OnMouseLeftClick = lambda: switchToHub()

    # SPEEDUP SLIDER
    x, y = 5, 1 * control_height + 5
    w, h = window_width - 20, control_height - 5
    ui.speedupLabel = gui.create_text(guiMan, 'speedupLabel', Pos2i(x, y),
                                      Pos2i(3 * w / 10, h), 'Speedup:')
    ui.speedupScroll = gui.create_scroll_bar(guiMan, 'speedupScroll',
                                             Pos2i(x + 5 + 3 * w / 10, y),
                                             Pos2i(3 * w / 5, h - 5), True)
    ui.speedupValue = gui.create_text(guiMan, 'speedupEditBox',
                                      Pos2i(x + 10 + 9 * w / 10, y),
                                      Pos2i(w / 10, h), str(0))
    ui.speedupScroll.setMax(100)
    ui.speedupScroll.setLargeStep(10)
    ui.speedupScroll.setSmallStep(1)
    ui.speedupScroll.setPos(0)
    getMod().set_speedup(0)
    ui.speedupScroll.OnScrollBarChange = speedup_adjusted(ui)

    # THE WINDOW THAT HOLDS ALL THE CONTROLS ABOVE
    ui.agentWindow = gui.create_window(
        guiMan, 'agentWindow', Pos2i(10, 10),
        Pos2i(window_width, 3 * control_height + 25), 'Agent')
    ui.agentWindow.addChild(ui.agentBoxLabel)
    ui.agentWindow.addChild(ui.agentComboBox)
    ui.agentWindow.addChild(ui.startAgentButton)
    ui.agentWindow.addChild(ui.pauseAgentButton)
    ui.agentWindow.addChild(ui.helpButton)
    ui.agentWindow.addChild(ui.exitButton)
    ui.agentWindow.addChild(ui.speedupLabel)
    ui.agentWindow.addChild(ui.speedupScroll)
    ui.agentWindow.addChild(ui.speedupValue)
Exemplo n.º 4
0
def CreateGui(guiMan):
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    ui = UI()

    window_width = 300 # width
    control_height = 30  # height

    # AGENT SELECTION BOX
    x, y = 5, 4 * control_height + 5
    w, h = window_width - 15, control_height - 10
    ui.agentBoxLabel = gui.create_text(guiMan, 'agentLabel', Pos2i(x,y), Pos2i(3*w/10,h), 'Agent Type:')
    ui.agentComboBox = gui.create_combo_box(guiMan, "agentComboBox", Pos2i(x + 5 + 3*w/10, y), Pos2i(7*w/10, h))
    for agent_name, agent_function, ee_enabled in AGENTS:
        ui.agentComboBox.addItem(agent_name)

    # EXPLORE/EXPLOIT TRADE-OFF SLIDER
    x, y = 5, 0 * control_height + 5
    w, h = window_width - 20, control_height - 5
    epsilon_percent = int(INITIAL_EPSILON * 100)
    ui.epsilonLabel = gui.create_text(guiMan, 'epsilonLabel', Pos2i(x, y), Pos2i(3*w/10, h), 'Exploit-Explore:')
    ui.epsilonScroll = gui.create_scroll_bar(guiMan, 'epsilonScroll', Pos2i(x + 3*w/10 + 5, y), Pos2i(6*w/10, h - 5), True)
    ui.epsilonValue = gui.create_text(guiMan, 'epsilonEditBox', Pos2i(x + 9*w/10 + 10, y), Pos2i(w/10, h), str(epsilon_percent))
    ui.epsilonScroll.setMax(100)
    ui.epsilonScroll.setLargeStep(10)
    ui.epsilonScroll.setSmallStep(1)
    ui.epsilonScroll.setPos(epsilon_percent)
    ui.epsilonScroll.enabled = False
    ui.epsilonValue.visible = False
    ui.epsilonLabel.visible = False
    ui.epsilonScroll.visible = False
    getMod().set_epsilon(INITIAL_EPSILON)
    ui.epsilonScroll.OnScrollBarChange = epsilon_adjusted(ui)

    # START/RESET AND PAUSE/CONTINUE AGENT BUTTONS
    x, y = 5, 3 * control_height
    w, h = (window_width - 15) / 2, control_height - 5
    ui.startAgentButton = gui.create_button(guiMan, 'startAgentButton', Pos2i(x, y), Pos2i(w, h), '')
    ui.pauseAgentButton = gui.create_button(guiMan, 'pauseAgentButton', Pos2i(x + w + 5, y), Pos2i(w, h), '')
    ui.startAgentButton.text = 'Start'
    ui.pauseAgentButton.text = 'Pause'
    ui.pauseAgentButton.enabled = False
    ui.startAgentButton.OnMouseLeftClick = startAgent(ui)
    ui.pauseAgentButton.OnMouseLeftClick = pauseAgent(ui)

    # HELP BUTTON
    w, h = (window_width - 15) / 2, control_height - 5
    x, y = 5, 2 * control_height
    ui.helpButton = gui.create_button(guiMan, 'helpButton', Pos2i(x, y), Pos2i(w, h), '')
    ui.helpButton.text = 'Help'
    ui.helpButton.OnMouseLeftClick = openWiki('MazeMod')

    # NEW MAZE BUTTON
    x = 10 + w
    ui.newMazeButton = gui.create_button(guiMan, 'newMazeButton', Pos2i(x, y), Pos2i(w, h), '')
    ui.newMazeButton.text = 'New Maze'
    ui.newMazeButton.OnMouseLeftClick = lambda: getMod().generate_new_maze()

    # SPEEDUP SLIDER
    x, y = 5, 1 * control_height
    w, h = window_width - 20, control_height - 5
    ui.speedupLabel = gui.create_text(guiMan, 'speedupLabel', Pos2i(x, y), Pos2i(3*w/10, h), 'Speedup:')
    ui.speedupScroll = gui.create_scroll_bar(guiMan, 'speedupScroll', Pos2i(x + 5 + 3*w/10, y), Pos2i(3*w/5, h-5), True)
    ui.speedupValue = gui.create_text(guiMan, 'speedupEditBox', Pos2i(x + 10 + 9*w/10, y), Pos2i(w/10, h), str(0))
    ui.speedupScroll.setMax(100)
    ui.speedupScroll.setLargeStep(10)
    ui.speedupScroll.setSmallStep(1)
    ui.speedupScroll.setPos(0)
    getMod().set_speedup(0)
    ui.speedupScroll.OnScrollBarChange = speedup_adjusted(ui)

    # THE WINDOW THAT HOLDS ALL THE CONTROLS ABOVE
    ui.agentWindow = gui.create_window(guiMan, 'agentWindow', Pos2i(10, 10), Pos2i(window_width, 5*control_height+25), 'Agent')
    ui.agentWindow.addChild(ui.agentBoxLabel)
    ui.agentWindow.addChild(ui.agentComboBox)
    ui.agentWindow.addChild(ui.newMazeButton)
    ui.agentWindow.addChild(ui.startAgentButton)
    ui.agentWindow.addChild(ui.pauseAgentButton)
    ui.agentWindow.addChild(ui.helpButton)
    ui.agentWindow.addChild(ui.epsilonLabel)
    ui.agentWindow.addChild(ui.epsilonScroll)
    ui.agentWindow.addChild(ui.epsilonValue)
    ui.agentWindow.addChild(ui.speedupLabel)
    ui.agentWindow.addChild(ui.speedupScroll)
    ui.agentWindow.addChild(ui.speedupValue)
Exemplo n.º 5
0
def show_context_menu():
    global modify_object_id
    global object_ids

    if len(modify_object_id) > 0:
        return

    guiMan.setTransparency(1.0)

    sim_context = OpenNero.getSimContext()

    # find the screen position at which to open the context menu
    cursor = sim_context.getMousePosition()
    location = sim_context.getClickedPosition(cursor.x, cursor.y)
    selected_object_id = sim_context.getClickedEntityId(cursor.x, cursor.y)

    if selected_object_id not in object_ids and abs(location.z) > 10: return

    print "location:", location

    contextMenu = gui.create_context_menu(guiMan, 'context', cursor)

    def add_wall():
        obj_id = common.addObject(
            "data/shapes/cube/Cube.xml",
            OpenNero.Vector3f(location.x, location.y,
                              constants.HEIGHT + constants.OFFSET),
            OpenNero.Vector3f(0, 0, 90),
            scale=OpenNero.Vector3f(5, 30, constants.HEIGHT * 2),
            type=1)
        object_ids[obj_id] = set(['rotate', 'move', 'scale', 'remove'])

    def rotate_object():
        modify_object_id['rot'] = selected_object_id

    def scale_object():
        modify_object_id['scale'] = selected_object_id

    def move_object():
        modify_object_id['move'] = selected_object_id

    def remove_flag():
        module.getMod().remove_flag()

    def place_flag():
        module.getMod().change_flag([location.x, location.y, 0])

    def place_basic_turret():
        obj_id = module.getMod().place_basic_turret(
            [location.x, location.y, 0])
        object_ids[obj_id] = set(['move', 'remove'])

    def set_spawn_1():
        module.getMod().set_spawn(location.x, location.y,
                                  constants.OBJECT_TYPE_TEAM_0)

    def set_spawn_2():
        module.getMod().set_spawn(location.x, location.y,
                                  constants.OBJECT_TYPE_TEAM_1)

    def remove_wall():
        common.removeObject(selected_object_id)

    if selected_object_id in object_ids:
        operations = object_ids[selected_object_id]

        if 'rotate' in operations:
            rotateButton = gui.create_button(guiMan, 'rotate',
                                             OpenNero.Pos2i(0, 0),
                                             OpenNero.Pos2i(0, 0), '')
            rotateButton.OnMouseLeftClick = lambda: rotate_object()
            contextMenu.addItem('Rotate Object', rotateButton)

        if 'scale' in operations:
            scaleButton = gui.create_button(guiMan, 'scale',
                                            OpenNero.Pos2i(0, 0),
                                            OpenNero.Pos2i(0, 0), '')
            scaleButton.OnMouseLeftClick = lambda: scale_object()
            contextMenu.addItem('Scale Object', scaleButton)

        if 'move' in operations:
            moveButton = gui.create_button(guiMan, 'move',
                                           OpenNero.Pos2i(0, 0),
                                           OpenNero.Pos2i(0, 0), '')
            moveButton.OnMouseLeftClick = lambda: move_object()
            contextMenu.addItem('Move Object', moveButton)

        if 'remove' in operations:
            removeButton = gui.create_button(guiMan, 'remove',
                                             OpenNero.Pos2i(0, 0),
                                             OpenNero.Pos2i(0, 0), '')
            removeButton.OnMouseLeftClick = lambda: remove_wall()
            contextMenu.addItem('Remove Object', removeButton)

    else:
        wallButton = gui.create_button(guiMan, 'wall', OpenNero.Pos2i(0, 0),
                                       OpenNero.Pos2i(0, 0), '')
        wallButton.OnMouseLeftClick = lambda: add_wall()
        contextMenu.addItem('Add wall', wallButton)

        rmFlagButton = gui.create_button(guiMan, 'flag', OpenNero.Pos2i(0, 0),
                                         OpenNero.Pos2i(0, 0), '')
        rmFlagButton.OnMouseLeftClick = lambda: remove_flag()
        contextMenu.addItem('Remove Flag', rmFlagButton)

        flagButton = gui.create_button(guiMan, 'flag', OpenNero.Pos2i(0, 0),
                                       OpenNero.Pos2i(0, 0), '')
        flagButton.OnMouseLeftClick = lambda: place_flag()
        contextMenu.addItem('Place Flag', flagButton)

        turretButton = gui.create_button(guiMan, 'b_turret',
                                         OpenNero.Pos2i(0, 0),
                                         OpenNero.Pos2i(0, 0), '')
        turretButton.OnMouseLeftClick = lambda: place_basic_turret()
        contextMenu.addItem('Place Basic Turret', turretButton)

        spawn1Button = gui.create_button(guiMan, 'blue spawn',
                                         OpenNero.Pos2i(0, 0),
                                         OpenNero.Pos2i(0, 0), '')
        spawn1Button.OnMouseLeftClick = lambda: set_spawn_1()
        contextMenu.addItem('Set Blue Spawn Location', spawn1Button)

        spawn2Button = gui.create_button(guiMan, 'red spawn',
                                         OpenNero.Pos2i(0, 0),
                                         OpenNero.Pos2i(0, 0), '')
        spawn2Button.OnMouseLeftClick = lambda: set_spawn_2()
        contextMenu.addItem('Set Red Spawn Location', spawn2Button)
Exemplo n.º 6
0
def CreateGui(guiMan, mode):
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    ui = UI()

    window_width = 300  # width
    control_height = 30  # height

    # AGENT SELECTION BOX
    x, y = 5, 2 * control_height + 5
    w, h = window_width - 15, control_height - 10
    ui.agentBoxLabel = gui.create_text(guiMan, 'agentLabel', Pos2i(x, y),
                                       Pos2i(3 * w / 10, h), 'Agent Type:')
    ui.agentComboBox = gui.create_combo_box(guiMan, "agentComboBox",
                                            Pos2i(x + 5 + 3 * w / 10, y),
                                            Pos2i(7 * w / 10, h))
    ui.active_agents = []
    for agent_name, agent_function, ee_enabled, agent_mode in getMod().AGENTS:
        if mode == agent_mode:
            ui.active_agents.append(
                (agent_name, agent_function, ee_enabled, agent_mode))
            ui.agentComboBox.addItem(agent_name)

    # EXPLORE/EXPLOIT TRADE-OFF SLIDER
    x, y = 5, 5 * control_height + 5
    w, h = window_width - 20, control_height - 5
    epsilon_percent = int(INITIAL_EPSILON * 100)
    ui.epsilonLabel = gui.create_text(guiMan, 'epsilonLabel', Pos2i(x, y),
                                      Pos2i(3 * w / 10, h), 'Explore-Exploit:')
    ui.epsilonScroll = gui.create_scroll_bar(guiMan, 'epsilonScroll',
                                             Pos2i(x + 3 * w / 10 + 5, y),
                                             Pos2i(6 * w / 10, h - 5), True)
    ui.epsilonValue = gui.create_text(guiMan, 'epsilonEditBox',
                                      Pos2i(x + 9 * w / 10 + 10, y),
                                      Pos2i(w / 10, h), str(epsilon_percent))
    ui.epsilonScroll.setMax(100)
    ui.epsilonScroll.setLargeStep(10)
    ui.epsilonScroll.setSmallStep(1)
    ui.epsilonScroll.setPos(epsilon_percent)
    ui.epsilonScroll.enabled = False
    ui.epsilonValue.visible = False
    ui.epsilonLabel.visible = False
    ui.epsilonScroll.visible = False
    getMod().set_epsilon(INITIAL_EPSILON)
    ui.epsilonScroll.OnScrollBarChange = epsilon_adjusted(ui)

    # INITIAL DISTANCE SLIDER
    x, y = 5, 3 * control_height + 5
    w, h = window_width - 20, control_height - 5
    initdist = INITIAL_DIST
    ui.initdistLabel = gui.create_text(guiMan, 'initdistLabel', Pos2i(x, y),
                                       Pos2i(3 * w / 10, h),
                                       'Starting Offset:')
    ui.initdistScroll = gui.create_scroll_bar(guiMan, 'initdistScroll',
                                              Pos2i(x + 3 * w / 10 + 5, y),
                                              Pos2i(6 * w / 10, h - 5), True)
    ui.initdistValue = gui.create_text(guiMan, 'initdistEditBox',
                                       Pos2i(x + 9 * w / 10 + 10, y),
                                       Pos2i(w / 10, h), str(initdist))
    ui.initdistScroll.setMax(2 * ROWS - 3)
    ui.initdistScroll.setLargeStep(2)
    ui.initdistScroll.setSmallStep(1)
    ui.initdistScroll.setPos(initdist)
    #    ui.initdistScroll.enabled = False
    #    ui.initdistValue.visible = False
    #    ui.initdistLabel.visible = False
    #    ui.initdistScroll.visible = False
    ui.initdistScroll.enabled = True
    ui.initdistValue.visible = True
    ui.initdistLabel.visible = True
    ui.initdistScroll.visible = True
    getMod().set_initdist(INITIAL_DIST)
    ui.initdistScroll.OnScrollBarChange = initdist_adjusted(ui)

    # START/RESET AND PAUSE/CONTINUE AGENT BUTTONS
    x, y = 5, 1 * control_height + 5
    w, h = (window_width - 15) / 2, control_height - 5
    ui.startAgentButton = gui.create_button(guiMan, 'startAgentButton',
                                            Pos2i(x, y), Pos2i(w, h), '')
    ui.pauseAgentButton = gui.create_button(guiMan, 'pauseAgentButton',
                                            Pos2i(x + w + 5, y), Pos2i(w, h),
                                            '')
    ui.startAgentButton.text = 'Start'
    ui.pauseAgentButton.text = 'Pause'
    ui.pauseAgentButton.enabled = False
    ui.startAgentButton.OnMouseLeftClick = startAgent(ui)
    ui.pauseAgentButton.OnMouseLeftClick = pauseAgent(ui)

    # HELP BUTTON
    w, h = (window_width - 20) / 3, control_height - 5
    x, y = 5, 0 * control_height + 5
    ui.helpButton = gui.create_button(guiMan, 'helpButton', Pos2i(x, y),
                                      Pos2i(w, h), '')
    ui.helpButton.text = 'Help'
    ui.helpButton.OnMouseLeftClick = openWiki('MazeMod')

    # NEW MAZE BUTTON
    x = 10 + w
    ui.newMazeButton = gui.create_button(guiMan, 'newMazeButton', Pos2i(x, y),
                                         Pos2i(w, h), '')
    ui.newMazeButton.text = 'New Maze'
    ui.newMazeButton.OnMouseLeftClick = lambda: getMod().generate_new_maze()

    # EXIT BUTTON
    x = 15 + w * 2
    ui.exitButton = gui.create_button(guiMan, 'exitButton', Pos2i(x, y),
                                      Pos2i(w, h), '')
    ui.exitButton.text = 'Exit'
    ui.exitButton.OnMouseLeftClick = lambda: switchToHub()

    # SPEEDUP SLIDER
    x, y = 5, 4 * control_height + 5
    w, h = window_width - 20, control_height - 5
    ui.speedupLabel = gui.create_text(guiMan, 'speedupLabel', Pos2i(x, y),
                                      Pos2i(3 * w / 10, h), 'Speedup:')
    ui.speedupScroll = gui.create_scroll_bar(guiMan, 'speedupScroll',
                                             Pos2i(x + 5 + 3 * w / 10, y),
                                             Pos2i(3 * w / 5, h - 5), True)
    ui.speedupValue = gui.create_text(guiMan, 'speedupEditBox',
                                      Pos2i(x + 10 + 9 * w / 10, y),
                                      Pos2i(w / 10, h), str(0))
    ui.speedupScroll.setMax(100)
    ui.speedupScroll.setLargeStep(10)
    ui.speedupScroll.setSmallStep(1)
    ui.speedupScroll.setPos(0)
    getMod().set_speedup(0)
    ui.speedupScroll.OnScrollBarChange = speedup_adjusted(ui)

    # THE WINDOW THAT HOLDS ALL THE CONTROLS ABOVE
    ui.agentWindow = gui.create_window(
        guiMan, 'agentWindow', Pos2i(10, 10),
        Pos2i(window_width, 6 * control_height + 30), 'Agent')
    ui.agentWindow.addChild(ui.agentBoxLabel)
    ui.agentWindow.addChild(ui.agentComboBox)
    ui.agentWindow.addChild(ui.newMazeButton)
    ui.agentWindow.addChild(ui.exitButton)
    ui.agentWindow.addChild(ui.startAgentButton)
    ui.agentWindow.addChild(ui.pauseAgentButton)
    ui.agentWindow.addChild(ui.helpButton)
    ui.agentWindow.addChild(ui.epsilonLabel)
    ui.agentWindow.addChild(ui.epsilonScroll)
    ui.agentWindow.addChild(ui.epsilonValue)
    ui.agentWindow.addChild(ui.initdistLabel)
    ui.agentWindow.addChild(ui.initdistScroll)
    ui.agentWindow.addChild(ui.initdistValue)
    ui.agentWindow.addChild(ui.speedupLabel)
    ui.agentWindow.addChild(ui.speedupScroll)
    ui.agentWindow.addChild(ui.speedupValue)
Exemplo n.º 7
0
def show_context_menu():
    global modify_object_id
    global object_ids

    if len(modify_object_id) > 0:
        return

    guiMan.setTransparency(1.0)

    sim_context = OpenNero.getSimContext()

    # find the screen position at which to open the context menu
    cursor = sim_context.getMousePosition()
    location = sim_context.getClickedPosition(cursor.x, cursor.y)
    selected_object_id = sim_context.getClickedEntityId(cursor.x, cursor.y)

    if selected_object_id not in object_ids and abs(location.z) > 1:
        return

    print "location:", location

    contextMenu = gui.create_context_menu(guiMan, "context", cursor)

    def add_wall():
        object_ids.append(
            common.addObject(
                "data/shapes/cube/Cube.xml",
                OpenNero.Vector3f(location.x, location.y, constants.HEIGHT + constants.OFFSET),
                OpenNero.Vector3f(0, 0, 90),
                scale=OpenNero.Vector3f(1, 30, constants.HEIGHT),
                type=1,
            )
        )

    def rotate_object():
        modify_object_id["rot"] = selected_object_id

    def scale_object():
        modify_object_id["scale"] = selected_object_id

    def move_object():
        modify_object_id["move"] = selected_object_id

    def place_flag():
        module.getMod().change_flag([location.x, location.y, 0])

    def place_basic_turret():
        module.getMod().place_basic_turret([location.x, location.y, 0])

    def set_spawn():
        module.getMod().set_spawn(location.x, location.y)

    def remove_wall():
        common.removeObject(selected_object_id)

    if selected_object_id in object_ids:
        rotateButton = gui.create_button(guiMan, "rotate", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        rotateButton.OnMouseLeftClick = lambda: rotate_object()
        contextMenu.addItem("Rotate Object", rotateButton)

        scaleButton = gui.create_button(guiMan, "scale", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        scaleButton.OnMouseLeftClick = lambda: scale_object()
        contextMenu.addItem("Scale Object", scaleButton)

        moveButton = gui.create_button(guiMan, "move", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        moveButton.OnMouseLeftClick = lambda: move_object()
        contextMenu.addItem("Move Object", moveButton)

        removeButton = gui.create_button(guiMan, "remove", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        removeButton.OnMouseLeftClick = lambda: remove_wall()
        contextMenu.addItem("Remove Object", removeButton)

    else:
        wallButton = gui.create_button(guiMan, "wall", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        wallButton.OnMouseLeftClick = lambda: add_wall()
        contextMenu.addItem("Add wall", wallButton)

        flagButton = gui.create_button(guiMan, "flag", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        flagButton.OnMouseLeftClick = lambda: place_flag()
        contextMenu.addItem("Place Flag", flagButton)

        turretButton = gui.create_button(guiMan, "b_turret", OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), "")
        turretButton.OnMouseLeftClick = lambda: place_basic_turret()
        contextMenu.addItem("Place Basic Turret", turretButton)
Exemplo n.º 8
0
def CreateGui(guiMan, mode):
    print 'CreateGui'
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    ui = UI() # a collection of all the UI elements

    window_width = 250 # width
    control_height = 30  # height

    # AGENT SELECTION BOX
    x, y = 5, 1 * control_height + 5
    w, h = window_width - 15, control_height - 10
    ui.agentBoxLabel = gui.create_text(guiMan, 'agentLabel', Pos2i(x,y), Pos2i(3*w/10,h), 'Agent Type:')
    ui.agentComboBox = gui.create_combo_box(guiMan, "agentComboBox", Pos2i(x + 5 + 3*w/10, y), Pos2i(7*w/10, h))
    ui.active_agents = []
    for agent_name, agent_function, agent_mode in getMod().AGENTS:
        if mode == agent_mode:
            ui.active_agents.append((agent_name, agent_function, agent_mode))
            ui.agentComboBox.addItem(agent_name)

    # START/RESET AND PAUSE/CONTINUE AGENT BUTTONS AND HELP BUTTON
    x, y = 5, 0 * control_height + 5
    w, h = (window_width - 25) / 4, control_height - 5
    ui.startAgentButton = gui.create_button(guiMan, 'startAgentButton', Pos2i(x, y), Pos2i(w, h), '')
    ui.pauseAgentButton = gui.create_button(guiMan, 'pauseAgentButton', Pos2i(x + w + 5, y), Pos2i(w, h), '')
    ui.helpButton = gui.create_button(guiMan, 'helpButton', Pos2i(x + 2*w + 10, y), Pos2i(w, h), '')
    ui.exitButton = gui.create_button(guiMan, 'exitButton', Pos2i(x + 3*w + 15, y), Pos2i(w, h), '')
    ui.startAgentButton.text = 'Start'
    ui.pauseAgentButton.text = 'Pause'
    ui.helpButton.text = 'Help'
    ui.exitButton.text = 'Exit'
    ui.pauseAgentButton.enabled = False
    ui.startAgentButton.OnMouseLeftClick = startAgent(ui)
    ui.pauseAgentButton.OnMouseLeftClick = pauseAgent(ui)
    ui.helpButton.OnMouseLeftClick = openWiki('BlocksWorldMod')
    ui.exitButton.OnMouseLeftClick = lambda: switchToHub()

    # SPEEDUP SLIDER
    x, y = 5, 2 * control_height + 5
    w, h = window_width - 20, control_height - 5
    ui.speedupLabel = gui.create_text(guiMan, 'speedupLabel', Pos2i(x, y), Pos2i(3*w/10, h), 'Speedup:')
    ui.speedupScroll = gui.create_scroll_bar(guiMan, 'speedupScroll', Pos2i(x + 5 + 3*w/10, y), Pos2i(3*w/5, h-5), True)
    ui.speedupValue = gui.create_text(guiMan, 'speedupEditBox', Pos2i(x + 10 + 9*w/10, y), Pos2i(w/10, h), str(0))
    ui.speedupScroll.setMax(100)
    ui.speedupScroll.setLargeStep(10)
    ui.speedupScroll.setSmallStep(1)
    ui.speedupScroll.setPos(0)
    getMod().set_speedup(0)
    ui.speedupScroll.OnScrollBarChange = speedup_adjusted(ui)
    
    # THE WINDOW THAT HOLDS ALL THE CONTROLS ABOVE
    ui.agentWindow = gui.create_window(guiMan, 'agentWindow', Pos2i(10, 10), Pos2i(window_width, 3*control_height+25), 'Agent')
    ui.agentWindow.addChild(ui.agentBoxLabel)
    ui.agentWindow.addChild(ui.agentComboBox)
    ui.agentWindow.addChild(ui.startAgentButton)
    ui.agentWindow.addChild(ui.pauseAgentButton)
    ui.agentWindow.addChild(ui.helpButton)
    ui.agentWindow.addChild(ui.exitButton)
    ui.agentWindow.addChild(ui.speedupLabel)
    ui.agentWindow.addChild(ui.speedupScroll)
    ui.agentWindow.addChild(ui.speedupValue)
Exemplo n.º 9
0
def CreateGui(guiMan, mode):
    guiMan.setTransparency(1.0)
    guiMan.setFont("data/gui/fonthaettenschweiler.bmp")

    ui = UI()

    window_width = 300  # width
    control_height = 30  # height

    # AGENT SELECTION BOX
    x, y = 5, 2 * control_height + 5
    w, h = window_width - 15, control_height - 10
    ui.agentBoxLabel = gui.create_text(guiMan, "agentLabel", Pos2i(x, y), Pos2i(3 * w / 10, h), "Agent Type:")
    ui.agentComboBox = gui.create_combo_box(guiMan, "agentComboBox", Pos2i(x + 5 + 3 * w / 10, y), Pos2i(7 * w / 10, h))
    ui.active_agents = []
    for agent_name, agent_function, ee_enabled, agent_mode in getMod().AGENTS:
        if mode == agent_mode:
            ui.active_agents.append((agent_name, agent_function, ee_enabled, agent_mode))
            ui.agentComboBox.addItem(agent_name)

    # EXPLORE/EXPLOIT TRADE-OFF SLIDER
    x, y = 5, 5 * control_height + 5
    w, h = window_width - 20, control_height - 5
    epsilon_percent = int(INITIAL_EPSILON * 100)
    ui.epsilonLabel = gui.create_text(guiMan, "epsilonLabel", Pos2i(x, y), Pos2i(3 * w / 10, h), "Explore-Exploit:")
    ui.epsilonScroll = gui.create_scroll_bar(
        guiMan, "epsilonScroll", Pos2i(x + 3 * w / 10 + 5, y), Pos2i(6 * w / 10, h - 5), True
    )
    ui.epsilonValue = gui.create_text(
        guiMan, "epsilonEditBox", Pos2i(x + 9 * w / 10 + 10, y), Pos2i(w / 10, h), str(epsilon_percent)
    )
    ui.epsilonScroll.setMax(100)
    ui.epsilonScroll.setLargeStep(10)
    ui.epsilonScroll.setSmallStep(1)
    ui.epsilonScroll.setPos(epsilon_percent)
    ui.epsilonScroll.enabled = False
    ui.epsilonValue.visible = False
    ui.epsilonLabel.visible = False
    ui.epsilonScroll.visible = False
    getMod().set_epsilon(INITIAL_EPSILON)
    ui.epsilonScroll.OnScrollBarChange = epsilon_adjusted(ui)

    # INITIAL DISTANCE SLIDER
    x, y = 5, 3 * control_height + 5
    w, h = window_width - 20, control_height - 5
    initdist = INITIAL_DIST
    ui.initdistLabel = gui.create_text(guiMan, "initdistLabel", Pos2i(x, y), Pos2i(3 * w / 10, h), "Starting Offset:")
    ui.initdistScroll = gui.create_scroll_bar(
        guiMan, "initdistScroll", Pos2i(x + 3 * w / 10 + 5, y), Pos2i(6 * w / 10, h - 5), True
    )
    ui.initdistValue = gui.create_text(
        guiMan, "initdistEditBox", Pos2i(x + 9 * w / 10 + 10, y), Pos2i(w / 10, h), str(initdist)
    )
    ui.initdistScroll.setMax(2 * ROWS - 3)
    ui.initdistScroll.setLargeStep(2)
    ui.initdistScroll.setSmallStep(1)
    ui.initdistScroll.setPos(initdist)
    #    ui.initdistScroll.enabled = False
    #    ui.initdistValue.visible = False
    #    ui.initdistLabel.visible = False
    #    ui.initdistScroll.visible = False
    ui.initdistScroll.enabled = True
    ui.initdistValue.visible = True
    ui.initdistLabel.visible = True
    ui.initdistScroll.visible = True
    getMod().set_initdist(INITIAL_DIST)
    ui.initdistScroll.OnScrollBarChange = initdist_adjusted(ui)

    # START/RESET AND PAUSE/CONTINUE AGENT BUTTONS
    x, y = 5, 1 * control_height + 5
    w, h = (window_width - 15) / 2, control_height - 5
    ui.startAgentButton = gui.create_button(guiMan, "startAgentButton", Pos2i(x, y), Pos2i(w, h), "")
    ui.pauseAgentButton = gui.create_button(guiMan, "pauseAgentButton", Pos2i(x + w + 5, y), Pos2i(w, h), "")
    ui.startAgentButton.text = "Start"
    ui.pauseAgentButton.text = "Pause"
    ui.pauseAgentButton.enabled = False
    ui.startAgentButton.OnMouseLeftClick = startAgent(ui)
    ui.pauseAgentButton.OnMouseLeftClick = pauseAgent(ui)

    # HELP BUTTON
    w, h = (window_width - 20) / 3, control_height - 5
    x, y = 5, 0 * control_height + 5
    ui.helpButton = gui.create_button(guiMan, "helpButton", Pos2i(x, y), Pos2i(w, h), "")
    ui.helpButton.text = "Help"
    ui.helpButton.OnMouseLeftClick = openWiki("MazeMod")

    # NEW MAZE BUTTON
    x = 10 + w
    ui.newMazeButton = gui.create_button(guiMan, "newMazeButton", Pos2i(x, y), Pos2i(w, h), "")
    ui.newMazeButton.text = "New Maze"
    ui.newMazeButton.OnMouseLeftClick = lambda: getMod().generate_new_maze()

    # EXIT BUTTON
    x = 15 + w * 2
    ui.exitButton = gui.create_button(guiMan, "exitButton", Pos2i(x, y), Pos2i(w, h), "")
    ui.exitButton.text = "Exit"
    ui.exitButton.OnMouseLeftClick = lambda: switchToHub()

    # SPEEDUP SLIDER
    x, y = 5, 4 * control_height + 5
    w, h = window_width - 20, control_height - 5
    ui.speedupLabel = gui.create_text(guiMan, "speedupLabel", Pos2i(x, y), Pos2i(3 * w / 10, h), "Speedup:")
    ui.speedupScroll = gui.create_scroll_bar(
        guiMan, "speedupScroll", Pos2i(x + 5 + 3 * w / 10, y), Pos2i(3 * w / 5, h - 5), True
    )
    ui.speedupValue = gui.create_text(guiMan, "speedupEditBox", Pos2i(x + 10 + 9 * w / 10, y), Pos2i(w / 10, h), str(0))
    ui.speedupScroll.setMax(100)
    ui.speedupScroll.setLargeStep(10)
    ui.speedupScroll.setSmallStep(1)
    ui.speedupScroll.setPos(0)
    getMod().set_speedup(0)
    ui.speedupScroll.OnScrollBarChange = speedup_adjusted(ui)

    # THE WINDOW THAT HOLDS ALL THE CONTROLS ABOVE
    ui.agentWindow = gui.create_window(
        guiMan, "agentWindow", Pos2i(10, 10), Pos2i(window_width, 6 * control_height + 30), "Agent"
    )
    ui.agentWindow.addChild(ui.agentBoxLabel)
    ui.agentWindow.addChild(ui.agentComboBox)
    ui.agentWindow.addChild(ui.newMazeButton)
    ui.agentWindow.addChild(ui.exitButton)
    ui.agentWindow.addChild(ui.startAgentButton)
    ui.agentWindow.addChild(ui.pauseAgentButton)
    ui.agentWindow.addChild(ui.helpButton)
    ui.agentWindow.addChild(ui.epsilonLabel)
    ui.agentWindow.addChild(ui.epsilonScroll)
    ui.agentWindow.addChild(ui.epsilonValue)
    ui.agentWindow.addChild(ui.initdistLabel)
    ui.agentWindow.addChild(ui.initdistScroll)
    ui.agentWindow.addChild(ui.initdistValue)
    ui.agentWindow.addChild(ui.speedupLabel)
    ui.agentWindow.addChild(ui.speedupScroll)
    ui.agentWindow.addChild(ui.speedupValue)
Exemplo n.º 10
0
def show_context_menu():
    global modify_object_id
    global object_ids

    if len(modify_object_id) > 0:
        return

    guiMan.setTransparency(1.0)

    sim_context = OpenNero.getSimContext()

    # find the screen position at which to open the context menu
    cursor = sim_context.getMousePosition()
    location = sim_context.getClickedPosition(cursor.x, cursor.y)
    selected_object_id = sim_context.getClickedEntityId(cursor.x, cursor.y)

    if selected_object_id not in object_ids and abs(location.z) > 10: return

    print "location:", location

    contextMenu = gui.create_context_menu(guiMan, 'context', cursor)

    def add_wall():
        obj_id = common.addObject(
            "data/shapes/cube/Cube.xml",
            OpenNero.Vector3f(location.x, location.y, constants.HEIGHT + constants.OFFSET),
            OpenNero.Vector3f(0, 0, 90),
            scale=OpenNero.Vector3f(5, 30, constants.HEIGHT*2),
            type=1)
        object_ids[obj_id] = set(['rotate', 'move', 'scale', 'remove'])

    def rotate_object():
        modify_object_id['rot'] = selected_object_id

    def scale_object():
        modify_object_id['scale'] = selected_object_id

    def move_object():
        modify_object_id['move'] = selected_object_id

    def remove_flag():
        module.getMod().remove_flag()

    def place_flag():
        module.getMod().change_flag([location.x, location.y, 0])

    def place_basic_turret():
        obj_id = module.getMod().place_basic_turret([location.x, location.y, 0])
        object_ids[obj_id] = set(['move', 'remove'])

    def set_spawn_1():
        module.getMod().set_spawn(location.x, location.y, constants.OBJECT_TYPE_TEAM_0)

    def set_spawn_2():
        module.getMod().set_spawn(location.x, location.y, constants.OBJECT_TYPE_TEAM_1)

    def remove_wall():
        common.removeObject(selected_object_id)

    if selected_object_id in object_ids:
        operations = object_ids[selected_object_id]

        if 'rotate' in operations:
            rotateButton = gui.create_button(guiMan, 'rotate', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
            rotateButton.OnMouseLeftClick = lambda: rotate_object()
            contextMenu.addItem('Rotate Object', rotateButton)

        if 'scale' in operations:
            scaleButton = gui.create_button(guiMan, 'scale', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
            scaleButton.OnMouseLeftClick = lambda: scale_object()
            contextMenu.addItem('Scale Object', scaleButton)

        if 'move' in operations:
            moveButton = gui.create_button(guiMan, 'move', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
            moveButton.OnMouseLeftClick = lambda: move_object()
            contextMenu.addItem('Move Object', moveButton)

        if 'remove' in operations:
            removeButton = gui.create_button(guiMan, 'remove', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
            removeButton.OnMouseLeftClick = lambda: remove_wall()
            contextMenu.addItem('Remove Object', removeButton)

    else:
        wallButton = gui.create_button(guiMan, 'wall', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        wallButton.OnMouseLeftClick = lambda: add_wall()
        contextMenu.addItem('Add wall', wallButton)

        rmFlagButton = gui.create_button(guiMan, 'flag', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        rmFlagButton.OnMouseLeftClick = lambda: remove_flag()
        contextMenu.addItem('Remove Flag', rmFlagButton)

        flagButton = gui.create_button(guiMan, 'flag', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        flagButton.OnMouseLeftClick = lambda: place_flag()
        contextMenu.addItem('Place Flag', flagButton)

        turretButton = gui.create_button(guiMan, 'b_turret', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        turretButton.OnMouseLeftClick = lambda: place_basic_turret()
        contextMenu.addItem('Place Basic Turret', turretButton)

        spawn1Button = gui.create_button(guiMan, 'blue spawn', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        spawn1Button.OnMouseLeftClick = lambda: set_spawn_1()
        contextMenu.addItem('Set Blue Spawn Location', spawn1Button)

        spawn2Button = gui.create_button(guiMan, 'red spawn', OpenNero.Pos2i(0, 0), OpenNero.Pos2i(0, 0), '')
        spawn2Button.OnMouseLeftClick = lambda: set_spawn_2()
        contextMenu.addItem('Set Red Spawn Location', spawn2Button)