コード例 #1
0
 /// <summary>
 /// Adds the given event to the event list.
 /// The event does not need to have all parameters set yet.
 /// keepCurrentLevel indicates whether the event should stay at its level
 /// and other events should change if necessary. If it is false, the event will
 /// be added at its last possible position, i.e. after any conflicting event.
 /// </summary>
 public void AddAuthoredEvent(EventStub authoredEvent)
 {
     CalculateLevel(authoredEvent);
     //registers the object selector's listeners to update the event stub when the involved objects change
     for (int i = 0; i < authoredEvent.NrOfNeededRoles; i++)
     {
         authoredEvent.GetSelectorForIndex(i).OnObjectChanged += (SmartObject o, SmartObject n) => 
             UpdateAuthoredEvent(authoredEvent);
         authoredEvent.GetSelectorForIndex(i).OnObjectChanged += (SmartObject o, SmartObject n) =>
         {
             if (o != null && o != n)
             {
                 if (!authoredEvent.InvolvedObjects.Contains(o))
                     GetInvolvedInEvents(o).Remove(authoredEvent);
                 if (!authoredEvent.Participants.Contains(o))
                     GetParticipatingEvents(o).Remove(authoredEvent);
                 CalculateLevel(o);
             }
         };
     }
     UpdateAuthoredEvent(authoredEvent);
     allEvents.Add(authoredEvent);
     dependencies.Add(authoredEvent.ID, new List<EventID>());
 }
コード例 #2
0
 /// <summary>
 /// Removes the given event. Note that the event may not be predecessor
 /// of any other event, or the behavior is not defined.
 /// </summary>
 public void RemoveEvent(EventStub authoredEvent)
 {
     //Setting all to null actually makes cleanup easier, as all event handlers will be informed
     //that the old object was removed from the event
     for (int i = 0; i < authoredEvent.NrOfNeededRoles; i++)
     {
         authoredEvent.GetSelectorForIndex(i).TrySet(null);
     }
     //removes the event from any list/dictionary where it could be contained
     allEvents.Remove(authoredEvent);
     levelsForEvents.Remove(authoredEvent);
     //it is possible that the removed event is in a middle level, this makes sure that the predecessors are changed correctly,
     //i.e. any event that has a predecessor connection through the removed event, now has a direct connection
     foreach (EventStub evnt in allEvents.Where((EventStub e) => e.Predecessors.Contains(authoredEvent)))
     {
         evnt.RemovePredecessor(authoredEvent);
         foreach (EventStub e in authoredEvent.Predecessors)
         {
             evnt.AddPredecessor(e);
         }
         CalculateLevelRecursively(evnt);
     }
     dependencies.Remove(authoredEvent.ID);
 }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: fgeraci/CS195-Core
 /// <summary>
 /// Logic for adding an event that is used both in AddEmptyEvent and AddFinishedEvent.
 /// If addToManager is true, adds the event to the AuthoredEventManager.W
 /// </summary>
 private void AddEvent(EventStub currentEvent, bool addToManager)
 {
     if (addToManager)
     {
         AuthoredEventManager.Instance.AddAuthoredEvent(currentEvent);
     }
     for (int i = 0; i < currentEvent.NrOfNeededRoles; i++)
     {
         currentEvent.GetSelectorForIndex(i).OnObjectChanged += 
             ((SmartObject o, SmartObject n) => UpdateEventParticipants(currentEvent, o, n));
     }
     connectors.Add(currentEvent, new HashSet<ParticipantConnector>());
     rectangleForEvent[currentEvent] = new ContentRectangle<EventStub>(currentEvent, false, new Rect(0, 0, 0, 0), true, EventStubContent);
     rectangleForEvent[currentEvent].Style = rectangleForEvent[currentEvent].GetContent().image == null ? GUI.skin.button : GUI.skin.GetStyle("ImageBackground");
     rectangleForEvent[currentEvent].onRightClick = this.onEventRightClick;
     rectangleForEvent[currentEvent].onLeftClick = this.onEventLeftClick;
     rectangleForEvent[currentEvent].onMouseOver = this.onEventMouseOver;
     rectangleForEvent[currentEvent].onMouseOut = this.onEventMouseOut;
     rectangleForEvent[currentEvent].RegisterLeftClickAction(StartDragEvent);
     for (int i = 0; i < currentEvent.NrOfNeededRoles; i++)
     {
         connectors[currentEvent].Add(new ParticipantConnector(i, currentEvent, this));
     }
     CalculateEventAndObjectPositions();
 }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: fgeraci/CS195-Core
    /// <summary>
    /// Adds a new menu when right clicking an event, which offers some options
    /// for the given event.
    /// </summary>
    private void AddEventContextMenu(EventStub evnt)
    {
        contextMenu = new ActionBar(false);

        contextMenuArea = new Rect(
            Event.current.mousePosition.x + scrollPosition.x,
            Mathf.Min(Event.current.mousePosition.y + scrollPosition.y - parent.HEIGHT_BARS, height - 140 + scrollPosition.y),
            250, 125);

        //Close the context menu on cancel
        contextMenu.AddButton("Cancel", () => contextMenu = null);
        //Clear the event's parameters on Clear Params
        contextMenu.AddButton("Clear Params", () =>
        {
            for (int i = 0; i < evnt.NrOfNeededRoles; i++)
            {
                evnt.GetSelectorForIndex(i).TrySet(null);
            }
            contextMenu = null;
        });
        //Remove the event from the manager and GUI
        contextMenu.AddButton("Remove", () =>
        {
            RemoveEvent(evnt);
            CalculateEventAndObjectPositions();
            contextMenu = null;
        });
        //Fill in missing parameters
        contextMenu.AddButton("Fill In", () =>
        {
            FillIn(evnt);
            contextMenu = null;
        });
        //Fill in missing parameters after selecting rules
        contextMenu.AddButton("Fill In With", () =>
        {
            CreateFillInWithContextMenU(contextMenu);
        });
        //Highlight the event
        contextMenu.AddButton("Highlight", () =>
        {
			SetEventColor(evnt, Color.cyan);
            contextMenu = null;
        });
        //Configure the camera for the event
        contextMenu.AddButton("Camera", () =>
        {
            SelectCameraArguments(evnt);
            contextMenu = null;
        });
    }
コード例 #5
0
ファイル: MainWindow.cs プロジェクト: fgeraci/CS195-Core
 public ParticipantConnector(int index, EventStub eventStub, MainWindow window)
 {
     this.index = index;
     this.eventStub = eventStub;
     this.window = window;
     this.selector = eventStub.GetSelectorForIndex(index);
     this.compatibleSmartObjects = new List<ContentRectangle<SmartObject>>();
     this.leftOffset = CalculateLeftOffset();
 }
コード例 #6
0
ファイル: Texturizer.cs プロジェクト: fgeraci/CS195-Core
 /// <summary>
 /// Creates a new Texturizer for the given event.
 /// </summary>
 /// <param name="evnt">Event to create a Texturizer for.</param>
 public Texturizer(EventStub evnt)
 {
     this.Event = evnt;
     Material mat = Resources.Load<Material>(
         EventFolderName(evnt) + "/Mat");
     TextAsset offsetsFile = Resources.Load<TextAsset>(
         EventFolderName(evnt) + "/Offsets");
     //only if we have a material and an offsets file can we create a texture.
     if (mat != null && offsetsFile != null)
     {
         //set up the camera at a fixed 16:9 aspect ratio
         camera = new GameObject().AddComponent<Camera>();
         camera.transform.position = new Vector3(0, -100, 0 + zOffset);
         camera.backgroundColor = Color.black;
         camera.aspect = 16.0f / 9.0f;
         camera.orthographic = true;
         //create a render texture to which the camera renders
         currentTex = new RenderTexture(800, 450, 24);
         currentTex.Create();
         camera.targetTexture = currentTex;
         //create a single cube to hold the event image's material
         imageCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
         imageCube.transform.localScale = new Vector3(IMG_CUBE_WIDTH, IMG_CUBE_HEIGHT, 0.01f);
         imageCube.transform.position = new Vector3(0, -100, 0.7f + zOffset);
         imageCube.transform.Rotate(Vector3.forward, 180.0f);
         imageCube.GetComponent<MeshRenderer>().material = mat;
         emptySlotMat = Resources.Load<Material>("EventThumbnails/ObjMat_Default/Mat_Empty");
         defaultSlotMat = Resources.Load<Material>("EventThumbnails/ObjMat_Default/Mat_Default");
         //create param cubes at the correct offset
         offsets = LitJson.JsonMapper.ToObject<ImageOffsets>(offsetsFile.text);
         if (offsets.Offsets.Length < evnt.NrOfNeededRoles)
         {
             //do nothing, else we crash as we don't have enough offsets
         }
         else
         {
             //use the offsets to place the param cubes at the correct position
             for (int i = 0; i < evnt.NrOfNeededRoles; i++)
             {
                 int index = i;
                 evnt.GetSelectorForIndex(i).OnObjectChanged +=
                     (SmartObject o, SmartObject n) => SetCube(index);
                 paramCubes.Add(CreateParamCube(offsets.Offsets[i]));
                 SetCube(i);
             }
         }
     }
     this.hasTexture = mat != null && offsetsFile != null && offsets.Offsets.Length >= evnt.NrOfNeededRoles;
     zOffset += 1.0f;
 }
コード例 #7
0
 /// <summary>
 /// Executed when the mouse is released after dragging of an Event started.
 /// </summary>
 private void OnEventDragEnd()
 {
     if (eventDragRectangle.Position.Overlaps(new Rect(0, HEIGHT_BARS, width - 2 * WIDTH_SIDEBAR, height - HEIGHT_BARS)))
     {
         EventStub toAdd = new EventStub(eventDragRectangle.containedObject);
         mainWindow.AddEmptyEvent(toAdd);
         for (int i = 0; i < toAdd.NrOfNeededRoles; i++)
         {
             toAdd.GetSelectorForIndex(i).OnObjectChanged += 
                 (SmartObject o, SmartObject n) => CheckForWaypoint(o);
         }
     }
     eventDragRectangle = null;
     draggingEvent = false;
 }