Пример #1
0
def handle_input():
	global EXIT_MENU
	
	if QUIT:
		return False
	
	if settings.TICK_MODE in ['normal', 'strategy']:
		if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
			if ui_dialog.get_active_dialog():
				ui_dialog.delete(ui_dialog.get_active_dialog())
			
			elif EXIT_MENU:
				return False
			
			elif ui_menu.get_active_menu():
				_menu = ui_menu.get_active_menu()

				ui_menu.delete(_menu)

				if ui_panel.ACTIVE_MENU == _menu:
					ui_panel.close()
			else:
				EXIT_MENU = ui_menu.create((constants.WINDOW_WIDTH / 2) - 2, 18, title='Menu')
				
				ui_menu.add_selectable(EXIT_MENU, 'Quit', lambda: _quit())

		if settings.TICK_MODE == 'strategy':
			ui_squad_control.handle_keyboard_input()

	if controls.get_input_char_pressed('k'):
		display.screenshot('screenshot-%s.bmp' % time.time())

	return True
Пример #2
0
def handle_input():
    global EXIT_MENU

    if QUIT:
        return False

    if settings.TICK_MODE in ['normal', 'strategy']:
        if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
            if ui_dialog.get_active_dialog():
                ui_dialog.delete(ui_dialog.get_active_dialog())

            elif EXIT_MENU:
                return False

            elif ui_menu.get_active_menu():
                _menu = ui_menu.get_active_menu()

                ui_menu.delete(_menu)

                if ui_panel.ACTIVE_MENU == _menu:
                    ui_panel.close()
            else:
                EXIT_MENU = ui_menu.create((constants.WINDOW_WIDTH / 2) - 2,
                                           18,
                                           title='Menu')

                ui_menu.add_selectable(EXIT_MENU, 'Quit', lambda: _quit())

        if settings.TICK_MODE == 'strategy':
            ui_squad_control.handle_keyboard_input()

    if controls.get_input_char_pressed('k'):
        display.screenshot('screenshot-%s.bmp' % time.time())

    return True
Пример #3
0
def handle_mouse_pressed(x, y, button):
	if ui_menu.get_active_menu() or ui_menu.DELAY:
		return
	
	_x = x+camera.X
	_y = y+camera.Y
	
	if button == 1:
		if handle_squad_member_select(_x, _y):
			return
		
		if handle_fire_order(_x, _y):
			return
		
		if handle_movement_order(_x, _y):
			return
Пример #4
0
def handle_mouse_pressed(x, y, button):
    if ui_menu.get_active_menu() or ui_menu.DELAY:
        return

    _x = x + camera.X
    _y = y + camera.Y

    if button == 1:
        if handle_squad_member_select(_x, _y):
            return

        if handle_fire_order(_x, _y):
            return

        if handle_movement_order(_x, _y):
            return
Пример #5
0
def handle_mouse_movement(x, y):
	global WALK_PATH, WALK_DEST
	
	if ui_menu.get_active_menu() or ui_menu.DELAY or not is_squad_member_selected():
		return
	
	_x = x+camera.X
	_y = y+camera.Y
	
	if (_x, _y) in zones.get_active_solids({}, ignore_calling_entity=True, no_life=True):
		return
	
	_s_x, _s_y = movement.get_position(get_selected_squad_member())
	
	if (_x, _y) == WALK_DEST or (_x, _y) == (_s_x, _s_y):
		return
	
	WALK_PATH = pathfinding.astar((_s_x, _s_y), (_x, _y), zones.get_active_astar_map(), zones.get_active_weight_map())
	WALK_DEST = (_x, _y)
Пример #6
0
def handle_mouse_movement(x, y):
    global WALK_PATH, WALK_DEST

    if ui_menu.get_active_menu(
    ) or ui_menu.DELAY or not is_squad_member_selected():
        return

    _x = x + camera.X
    _y = y + camera.Y

    if (_x, _y) in zones.get_active_solids({},
                                           ignore_calling_entity=True,
                                           no_life=True):
        return

    _s_x, _s_y = movement.get_position(get_selected_squad_member())

    if (_x, _y) == WALK_DEST or (_x, _y) == (_s_x, _s_y):
        return

    WALK_PATH = pathfinding.astar((_s_x, _s_y), (_x, _y),
                                  zones.get_active_astar_map(),
                                  zones.get_active_weight_map())
    WALK_DEST = (_x, _y)
Пример #7
0
def handle_mouse_pressed(entity, x, y, button):
	global DRAGGING_NODE, LAST_CLICKED_POS, SELECTING_TARGET_CALLBACK
	
	if ui_menu.get_active_menu() or ui_menu.DELAY:
		return
	
	if timers.has_timer_with_name(entity, 'passout'):
		return
	
	_x = x+camera.X
	_y = y+camera.Y
	
	if button == 1:
		if DRAGGING_NODE:
			DRAGGING_NODE = None
		
		elif not (_x, _y) in zones.get_active_solids(entity):
			if not DRAGGING_NODE:
				for entity_id in [t for t in entity['ai']['visible_life'] if entity['ai']['life_memory'][t]['can_see']]:
					if entity['_id'] == entity_id:
						continue
					
					_entity = entities.get_entity(entity_id)
					_tx, _ty = movement.get_position(_entity)
					
					if (_x, _y) == (_tx, _ty):
						if SELECTING_TARGET_CALLBACK:
							SELECTING_TARGET_CALLBACK(entity, entity_id)
							SELECTING_TARGET_CALLBACK = None
						else:
							LAST_CLICKED_POS = (_x, _y)
					
							create_life_interact_menu(entity, entity_id)
						
						return
				
				else:
					for entity_id in entities.get_entity_group('contexts'):
						_entity = entities.get_entity(entity_id)
						
						if not _entity['callback']:
							continue
						
						if (_entity['tile']['x'], _entity['tile']['y']) == (_x, _y):
							_entity['callback'](x+2, y-3)
							
							return
					
					else:
						for entity_id in list(entity['ai']['targets'] - entity['ai']['visible_life']):
							_tx, _ty = entity['ai']['life_memory'][entity_id]['last_seen_at']
							
							if (_tx, _ty-2) == (_x, _y):
								ui_dialog.create(x + 2, y - 3, '%s - Last seen <time>' % entities.get_entity(entity_id)['stats']['name'])
								
								return
							
						else:
							for entity_id in entities.get_entity_group('items'):
								_item = entities.get_entity(entity_id)
								
								if _item['stats']['owner']:
									continue
								
								if (_x, _y) == movement.get_position(_item):
									create_item_menu(entity, _item, _x, _y)
									
									return
							
							create_walk_node(entity, _x, _y, clear=True)
							
							return
			
			for node in entity['node_grid']['nodes'].values():
				if (_x, _y) == (node['node']['x'], node['node']['y']):
					DRAGGING_NODE = node
					entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 0))
					
					break
				
				if (_x, _y) in node['node']['path']:
					if not (_x, _y) in node['node']['busy_pos']:
						LAST_CLICKED_POS = (_x, _y)
						
						create_action_menu(entity, LAST_CLICKED_POS[0], LAST_CLICKED_POS[1], on_path=True)
					
					else:
						LAST_CLICKED_POS = None
					
					return
	
	elif button == 2:
		if DRAGGING_NODE:
			entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 255))
			
			DRAGGING_NODE = None
		
		else:
			for node in entity['node_grid']['nodes'].values():
				if (_x, _y) == (node['node']['x'], node['node']['y']):
					entity['node_grid']['path'].remove(node['node']['_id'])
					entities.delete_entity(node['node'])
					redraw_path(entity)
					
					del entity['node_grid']['nodes'][node['node']['_id']]
					
					if not entity['node_grid']['nodes']:
						clear_path(entity)
					
					break
			else:
				create_walk_node(entity, _x, _y)
Пример #8
0
def handle_mouse_pressed(entity, x, y, button):
    global DRAGGING_NODE, LAST_CLICKED_POS, SELECTING_TARGET_CALLBACK

    if ui_menu.get_active_menu() or ui_menu.DELAY:
        return

    if timers.has_timer_with_name(entity, 'passout'):
        return

    _x = x + camera.X
    _y = y + camera.Y

    if button == 1:
        if DRAGGING_NODE:
            DRAGGING_NODE = None

        elif not (_x, _y) in zones.get_active_solids(entity):
            if not DRAGGING_NODE:
                for entity_id in [
                        t for t in entity['ai']['visible_life']
                        if entity['ai']['life_memory'][t]['can_see']
                ]:
                    if entity['_id'] == entity_id:
                        continue

                    _entity = entities.get_entity(entity_id)
                    _tx, _ty = movement.get_position(_entity)

                    if (_x, _y) == (_tx, _ty):
                        if SELECTING_TARGET_CALLBACK:
                            SELECTING_TARGET_CALLBACK(entity, entity_id)
                            SELECTING_TARGET_CALLBACK = None
                        else:
                            LAST_CLICKED_POS = (_x, _y)

                            create_life_interact_menu(entity, entity_id)

                        return

                else:
                    for entity_id in entities.get_entity_group('contexts'):
                        _entity = entities.get_entity(entity_id)

                        if not _entity['callback']:
                            continue

                        if (_entity['tile']['x'],
                                _entity['tile']['y']) == (_x, _y):
                            _entity['callback'](x + 2, y - 3)

                            return

                    else:
                        for entity_id in list(entity['ai']['targets'] -
                                              entity['ai']['visible_life']):
                            _tx, _ty = entity['ai']['life_memory'][entity_id][
                                'last_seen_at']

                            if (_tx, _ty - 2) == (_x, _y):
                                ui_dialog.create(
                                    x + 2, y - 3, '%s - Last seen <time>' %
                                    entities.get_entity(
                                        entity_id)['stats']['name'])

                                return

                        else:
                            for entity_id in entities.get_entity_group(
                                    'items'):
                                _item = entities.get_entity(entity_id)

                                if _item['stats']['owner']:
                                    continue

                                if (_x, _y) == movement.get_position(_item):
                                    create_item_menu(entity, _item, _x, _y)

                                    return

                            create_walk_node(entity, _x, _y, clear=True)

                            return

            for node in entity['node_grid']['nodes'].values():
                if (_x, _y) == (node['node']['x'], node['node']['y']):
                    DRAGGING_NODE = node
                    entities.trigger_event(DRAGGING_NODE['node'],
                                           'set_fore_color',
                                           color=(255, 255, 0))

                    break

                if (_x, _y) in node['node']['path']:
                    if not (_x, _y) in node['node']['busy_pos']:
                        LAST_CLICKED_POS = (_x, _y)

                        create_action_menu(entity,
                                           LAST_CLICKED_POS[0],
                                           LAST_CLICKED_POS[1],
                                           on_path=True)

                    else:
                        LAST_CLICKED_POS = None

                    return

    elif button == 2:
        if DRAGGING_NODE:
            entities.trigger_event(DRAGGING_NODE['node'],
                                   'set_fore_color',
                                   color=(255, 255, 255))

            DRAGGING_NODE = None

        else:
            for node in entity['node_grid']['nodes'].values():
                if (_x, _y) == (node['node']['x'], node['node']['y']):
                    entity['node_grid']['path'].remove(node['node']['_id'])
                    entities.delete_entity(node['node'])
                    redraw_path(entity)

                    del entity['node_grid']['nodes'][node['node']['_id']]

                    if not entity['node_grid']['nodes']:
                        clear_path(entity)

                    break
            else:
                create_walk_node(entity, _x, _y)