//the descriptor doesn't have an icon prefab so for its popup display, clone the existing one that's in the icon container
    public RectTransform setPopupIcon(GameRuleDesignComponentDescriptor descriptor)
    {
        int i = popupDescriptors.IndexOf(descriptor);
        if (i == -1)
            throw new System.Exception("Bug: popup not expecting to clone icon for descriptor " + descriptor);

        RectTransform iconToPlace = (RectTransform)(GameObject.Instantiate(popupIcons[i].gameObject).transform);
        placeIcon(iconToPlace);
        iconToPlace.gameObject.SetActive(true);
        return iconToPlace;
    }
Beispiel #2
0
 //if this is an event target then its icon may need to be substituted for its opponent
 public RectTransform getIconMaybeOpponent(GameRuleDesignComponentDescriptor d)
 {
     //it's an event target or an event source, if it's a target go and get the right icon for it
     if (d is GameRuleDesignComponentEventParticipantDescriptor) {
         List<GameObject> iconList = new List<GameObject>();
         //this is part of an event-happened condition
         if (parent.parent.descriptor == GameRuleDesigner.instance.gameRuleEventHappenedConditionDurationDescriptor) {
             //it's just the source, construct normally
             if (parent.subComponents[0] == this)
                 return GameRuleDesignPopup.instantiateIcon(d.displayIcon);
             //it's the target, go grab the icon
             else
                 GameRuleSourceSelector.selectorIdentifier(
                     ((GameRuleDesignComponentEventParticipantDescriptor)d).typeDescribed, true).addIcons(iconList);
         //this is the target of an until-condition duration
         } else if (parent.parent.parent.descriptor == GameRuleDesigner.instance.gameRuleActionUntilConditionDurationDescriptor) {
             GameRuleSourceSelector.selectorIdentifier(
                 ((GameRuleDesignComponentEventParticipantDescriptor)d).typeDescribed,
                 ((GameRuleDesignComponentSelectorDescriptor)parent.parent.descriptor).selectorDescribed).addIcons(iconList);
         //this should never happen
         } else
             throw new System.Exception("Bug: event participant part of " + parent.descriptor);
         return GameRuleDesignPopup.instantiateIcon(iconList[0]);
     //it's normal
     } else
         return GameRuleDesignPopup.instantiateIcon(d.displayIcon);
 }
Beispiel #3
0
    public void assignDescriptor(GameRuleDesignComponentDescriptor newDescriptor)
    {
        //if there's no change then don't change anything
        if (newDescriptor == descriptor)
            return;

        //if we're replacing a descriptor we need to get rid of everything it had
        bool hadOldDescriptor = descriptor != null;
        if (hadOldDescriptor)
            destroyComponent(false);
        descriptor = newDescriptor;

        //if the descriptor is part of a popup then it will manage the icon
        if (componentPopup != null)
            componentIcon = componentPopup.setPopupIcon(newDescriptor);
        //most components that are not part of a popup have an icon that represents it
        else if (newDescriptor.displayIcon != null) {
            componentIcon = getIconMaybeOpponent(newDescriptor);
            componentIcon.SetParent(GameRuleDesigner.instance.iconContainerTransform);
            componentIcon.localScale = new Vector3(1.0f, 1.0f);
        }

        //if it's got subcomponents, each one of them needs a popup
        //we also need to pick a default for each one
        //each event type has its own list that it will use
        if (newDescriptor is GameRuleDesignComponentEventTypeDescriptor) {
            GameRuleEventType eventType = ((GameRuleDesignComponentEventTypeDescriptor)newDescriptor).eventTypeDescribed;
            //event-happened conditions and until-conditions both have event types
            //based on which one this is, the structure of the subcomponents is different
            //if we're in a regular event-happened condition, we have a source type and target type
            if (parent.descriptor == GameRuleDesigner.instance.gameRuleEventHappenedConditionDurationDescriptor) {
                //if we had an old descriptor, we want to check if the source type changed
                System.Type oldSourceType;
                if (hadOldDescriptor)
                    oldSourceType = ((GameRuleDesignComponentEventParticipantDescriptor)(subComponents[0].descriptor)).typeDescribed;
                //otherwise, we need to initialize the subcomponents array
                else {
                    oldSourceType = null;
                    subComponents = new GameRuleDesignComponent[2];
                }
                //constructing the component auto-assigns the target descriptor
                (subComponents[0] = new GameRuleDesignComponent(this)).assignPopup(GameRuleDesigner.instance.potentialSourcesForEventMap[eventType], null);
                if (hadOldDescriptor) {
                    System.Type newSourceType = ((GameRuleDesignComponentEventParticipantDescriptor)(subComponents[0].descriptor)).typeDescribed;
                    //the source type switched, we need to refresh the effect action's subcomponents
                    if (oldSourceType != newSourceType) {
                        GameRuleDesigner.instance.gameRuleActionComponent.destroyComponent(false);
                        GameRuleDesigner.instance.gameRuleActionComponent.assignEffectActionSelector(newSourceType);
                    }
                }
            //if we're in an until-condition duration, our parent is the source type and our only subcomponent is the target type
            } else if (parent.parent.descriptor == GameRuleDesigner.instance.gameRuleActionUntilConditionDurationDescriptor) {
                if (!hadOldDescriptor)
                    subComponents = new GameRuleDesignComponent[1];
                subComponents[0] = new GameRuleDesignComponent(this, GameRuleDesigner.instance.potentialTargetsForEventSourceMap
                    [eventType]
                    //the source of the until-condition trigger is the target of a selector on the source of the original condition
                    [((GameRuleDesignComponentSelectorDescriptor)(parent.descriptor)).selectorDescribed.targetType()]);
            } else
                throw new System.Exception("Bug: event type changed with parent " + parent.descriptor);
        //this is the source or the target of an event-happened-condition, which could be the condition or an until-condition duration
        //if it's the condition, we need to change other stuff
        } else if (newDescriptor is GameRuleDesignComponentEventParticipantDescriptor) {
            //we changed the general condition source
            //we need to update the target type and possibly also an action type
            if (parent.parent.descriptor == GameRuleDesigner.instance.gameRuleEventHappenedConditionDurationDescriptor &&
                parent.subComponents[0] == this) {
                System.Type sourceType = ((GameRuleDesignComponentEventParticipantDescriptor)newDescriptor).typeDescribed;
                //if the source changed from an old one then we need to update the action
                //if this is the first time then the action gets set elsewhere
                if (hadOldDescriptor) {
                    parent.subComponents[1].destroyComponent(true);
                    GameRuleDesigner.instance.gameRuleActionComponent.destroyComponent(false);
                    GameRuleDesigner.instance.gameRuleActionComponent.assignEffectActionSelector(sourceType);
                }
                parent.subComponents[1] = new GameRuleDesignComponent(parent, GameRuleDesigner.instance.potentialTargetsForEventSourceMap
                    [((GameRuleDesignComponentEventTypeDescriptor)(parent.descriptor)).eventTypeDescribed]
                    [sourceType]);
            }
        //when we assign an until-condition, we need to pick the source type and it will pick the event type which will pick the target type
        } else if (descriptor == GameRuleDesigner.instance.gameRuleActionUntilConditionDurationDescriptor) {
            subComponents = new GameRuleDesignComponent[] {
                new GameRuleDesignComponent(this, GameRuleDesigner.instance.sourceSelectorMap[
                    ((GameRuleDesignComponentEventParticipantDescriptor)(GameRuleDesigner.instance.gameRuleConditionComponent.subComponents[0].subComponents[0].descriptor)).typeDescribed])
            };
        //we changed a selector descriptor, this is an effect action, until-condition duration, or a zone source
        } else if (newDescriptor is GameRuleDesignComponentSelectorDescriptor) {
            System.Type parentType = ((GameRuleDesignComponentClassDescriptor)(parent.descriptor)).typeDescribed;
            //when we change the selector for an effect action, we need to update the possible effects
            if (parentType == typeof(GameRuleEffectAction)) {
                if (hadOldDescriptor)
                    parent.subComponents[1].destroyComponent(true);
                parent.subComponents[1] = new GameRuleDesignComponent(parent, GameRuleDesigner.instance.sourceEffectMap[
                    ((GameRuleDesignComponentSelectorDescriptor)(newDescriptor)).selectorDescribed.targetType()]);
            //we changed the source of an until-condition, we need to refresh the event type
            } else if (parentType == typeof(GameRuleActionUntilConditionDuration)) {
                subComponents = new GameRuleDesignComponent[] {
                    new GameRuleDesignComponent(this, GameRuleDesigner.instance.potentialEventsForSourceMap[
                        ((GameRuleDesignComponentSelectorDescriptor)(descriptor)).selectorDescribed.targetType()])
                };
            }
        //the rest of the descriptors build their subcomponents normally
        } else if (newDescriptor.subComponents != null) {
            subComponents = new GameRuleDesignComponent[newDescriptor.subComponents.Length];
            for (int i = 0; i < subComponents.Length; i++) {
                //the component will build itself from the popup types list
                subComponents[i] = new GameRuleDesignComponent(this, newDescriptor.subComponents[i]);
            }

            //a few components need to send changes to other components
            //zone type was changed, assign the right metarule
            if (newDescriptor is GameRuleDesignComponentZoneTypeDescriptor) {
                GameRuleRequiredObjectType zoneType = ((GameRuleDesignComponentZoneTypeDescriptor)newDescriptor).zoneTypeDescribed;
                GameRuleDesigner.instance.gameRuleActionComponent.assignMetaRuleSubComponent(zoneType);
            //the condition changed, update the action with the corresponding descriptor
            } else if (this == GameRuleDesigner.instance.gameRuleConditionComponent) {
                if (hadOldDescriptor)
                    GameRuleDesigner.instance.gameRuleActionComponent.complementComponent(this);
            }
        } else
            subComponents = null;

        //save the component that actually gets displayed to render this component
        if (componentPopup != null)
            componentDisplayed = (RectTransform)(componentPopup.transform);
        else if (componentIcon != null)
            componentDisplayed = componentIcon;
        else
            componentDisplayed = null;
    }
Beispiel #4
0
 public GameRuleDesignComponent(GameRuleDesignComponent p, GameRuleDesignComponentDescriptor d)
 {
     parent = p;
     assignDescriptor(d);
 }