コード例 #1
0
 public SituationCreationCommand(
     IVerb verb,
     global::Recipe recipe,
     SituationState situationState,
     DraggableToken sourceToken = null) : base(verb, recipe, situationState, sourceToken)
 {
 }
コード例 #2
0
 Vector2 GetGridSize(DraggableToken token)
 {
     if (token is ElementStackToken)
     {
         return(new Vector2(ElementGridSizeX, ElementGridSizeY));
     }
     else
     {
         return(new Vector2(SituationGridSizeX, SituationGridSizeY));
     }
 }
コード例 #3
0
        // This runs after a token is dropped (on the table or anywhere else)
        static void Postfix(DraggableToken __instance)
        {
            // Check that we're over the tabletop background. If we're over another element, it looks better to not snap.
            if (!(__instance.TokenContainer is TabletopTokenContainer))
            {
                return;
            }

            float x = __instance.RectTransform.position.x;
            float y = __instance.RectTransform.position.y;

            Utility.Snap(ref x, ref y);
            __instance.RectTransform.position = new Vector3(x, y, __instance.RectTransform.position.z);
        }
コード例 #4
0
        // This runs as a token is being dragged
        static void Postfix(DraggableToken __instance, PointerEventData eventData)
        {
            // Check that we're over the tabletop background. If we're over another element, it looks better to not snap.
            if (eventData.pointerCurrentRaycast.gameObject.GetComponent <TabletopBackground>() == null)
            {
                return;
            }

            float x = __instance.RectTransform.position.x;
            float y = __instance.RectTransform.position.y;

            Utility.Snap(ref x, ref y);
            __instance.RectTransform.position = new Vector3(x, y, __instance.RectTransform.position.z);
        }
コード例 #5
0
        object OnCall(string typeName, string methodName, object thisObj, object[] args, IntPtr[] refArgs, int[] refIdxMatch)
        {
            bool snapToGrid = !Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightControl);

            if (typeName == "Assets.TabletopUi.Scripts.Infrastructure.Choreographer" && methodName == "GetFreePosWithDebug")
            {
                if (snapToGrid)
                {
                    Choreographer choreo = (Choreographer)thisObj;
                    MethodInfo    getFreeTokenPositionMethod = choreo.GetType().GetMethod("GetFreeTokenPosition", BindingFlags.NonPublic | BindingFlags.Instance);
                    Vector2       pos      = (Vector2)getFreeTokenPositionMethod.Invoke(choreo, args);
                    Vector2       gridSize = GetGridSize((DraggableToken)args[0]);
                    pos.x = gridSize.x * (Mathf.Round(pos.x / gridSize.x));
                    pos.y = gridSize.y * (Mathf.Round(pos.y / gridSize.y));
                    return(pos);
                }
            }

            if (typeName == "Assets.CS.TabletopUI.DraggableToken" && methodName == "DelayedEndDrag")
            {
                if (snapToGrid)
                {
                    DraggableToken token    = (DraggableToken)thisObj;
                    Vector3        pos      = token.RectTransform.localPosition;
                    Vector2        gridSize = GetGridSize(token);
                    pos.x = gridSize.x * (Mathf.Round(pos.x / gridSize.x));
                    pos.y = gridSize.y * (Mathf.Round(pos.y / gridSize.y));
                    token.RectTransform.localPosition = pos;
                }
            }

            if (typeName == "Assets.TabletopUi.Scripts.Infrastructure.HotkeyWatcher" && methodName == "WatchForGameplayHotkeys")
            {
                if (Input.GetKeyDown(KeyCode.A))
                {
                    TabletopTokenContainer ttc = Registry.Retrieve <TabletopManager>()._tabletop;
                    foreach (DraggableToken token in ttc.GetTokens())
                    {
                        Vector3 pos      = token.transform.localPosition;
                        Vector2 gridSize = GetGridSize(token);
                        pos.x = gridSize.x * (Mathf.Round(pos.x / gridSize.x));
                        pos.y = gridSize.y * (Mathf.Round(pos.y / gridSize.y));
                        token.RectTransform.localPosition = pos;
                    }
                }
            }

            return(null);
        }