コード例 #1
0
ファイル: RngIndexer.cs プロジェクト: sticks-stuff/STROOP
        public static int GetRngIndexDiff(ushort rngValue1, ushort rngValue2)
        {
            int index1 = GetRngIndex(rngValue1);
            int index2 = GetRngIndex(rngValue2);

            return(MoreMath.NonNegativeModulus(index2 - index1, RNG_COUNT));
        }
コード例 #2
0
        public static void InitializeThreeDimensionController(
            CoordinateSystem coordinateSystem,
            bool allowRelativeOptions,
            GroupBox groupbox,
            Button buttonSquareLeft,
            Button buttonSquareRight,
            Button buttonSquareUp,
            Button buttonSquareDown,
            Button buttonSquareUpLeft,
            Button buttonSquareDownLeft,
            Button buttonSquareUpRight,
            Button buttonSquareDownRight,
            Button buttonLineUp,
            Button buttonLineDown,
            TextBox textboxSquare,
            TextBox textboxLine,
            CheckBox checkbox,
            Action <float, float, float, bool> actionMove)
        {
            Action <int, int> actionSquare = (int hSign, int vSign) =>
            {
                float value;
                if (!float.TryParse(textboxSquare.Text, out value))
                {
                    return;
                }
                actionMove(hSign * value, vSign * value, 0, checkbox?.Checked ?? false);
            };

            Action <int> actionLine = (int nSign) =>
            {
                float value;
                if (!float.TryParse(textboxLine.Text, out value))
                {
                    return;
                }
                actionMove(0, 0, nSign * value, checkbox?.Checked ?? false);
            };

            Action setEulerNames = () =>
            {
                buttonSquareLeft.Text      = "X-";
                buttonSquareRight.Text     = "X+";
                buttonSquareUp.Text        = "Z-";
                buttonSquareDown.Text      = "Z+";
                buttonSquareUpLeft.Text    = "X-Z-";
                buttonSquareDownLeft.Text  = "X-Z+";
                buttonSquareUpRight.Text   = "X+Z-";
                buttonSquareDownRight.Text = "X+Z+";
                buttonLineUp.Text          = "Y+";
                buttonLineDown.Text        = "Y-";
            };

            Action setRelativeNames = () =>
            {
                buttonSquareLeft.Text      = "L";
                buttonSquareRight.Text     = "R";
                buttonSquareUp.Text        = "F";
                buttonSquareDown.Text      = "B";
                buttonSquareUpLeft.Text    = "FL";
                buttonSquareDownLeft.Text  = "BL";
                buttonSquareUpRight.Text   = "FR";
                buttonSquareDownRight.Text = "BR";
                buttonLineUp.Text          = "U";
                buttonLineDown.Text        = "D";
            };

            Action actionCheckedChanged = () =>
            {
                if (checkbox.Checked)
                {
                    setRelativeNames();
                }
                else
                {
                    setEulerNames();
                }
            };

            buttonSquareLeft.Click      += (sender, e) => actionSquare(-1, 0);
            buttonSquareRight.Click     += (sender, e) => actionSquare(1, 0);
            buttonSquareUp.Click        += (sender, e) => actionSquare(0, 1);
            buttonSquareDown.Click      += (sender, e) => actionSquare(0, -1);
            buttonSquareUpLeft.Click    += (sender, e) => actionSquare(-1, 1);
            buttonSquareDownLeft.Click  += (sender, e) => actionSquare(-1, -1);
            buttonSquareUpRight.Click   += (sender, e) => actionSquare(1, 1);
            buttonSquareDownRight.Click += (sender, e) => actionSquare(1, -1);
            buttonLineUp.Click          += (sender, e) => actionLine(1);
            buttonLineDown.Click        += (sender, e) => actionLine(-1);
            if (coordinateSystem == CoordinateSystem.Euler && allowRelativeOptions)
            {
                checkbox.CheckedChanged += (sender, e) => actionCheckedChanged();
            }

            // Implement ToolStripMenu

            List <Button> buttonList = new List <Button>()
            {
                buttonSquareUp,
                buttonSquareUpRight,
                buttonSquareRight,
                buttonSquareDownRight,
                buttonSquareDown,
                buttonSquareDownLeft,
                buttonSquareLeft,
                buttonSquareUpLeft,
            };

            List <Point> positionList = buttonList.ConvertAll(
                button => new Point(button.Location.X, button.Location.Y));

            ToolStripMenuItem itemLeft      = new ToolStripMenuItem("Face Left (X-) (49152)");
            ToolStripMenuItem itemRight     = new ToolStripMenuItem("Face Right (X+) (16384)");
            ToolStripMenuItem itemUp        = new ToolStripMenuItem("Face Up (Z-) (32768)");
            ToolStripMenuItem itemDown      = new ToolStripMenuItem("Face Down (Z+) (0)");
            ToolStripMenuItem itemUpLeft    = new ToolStripMenuItem("Face Up-Left (X-Z-) (40960)");
            ToolStripMenuItem itemDownLeft  = new ToolStripMenuItem("Face Down-Left (X-Z+) (57344)");
            ToolStripMenuItem itemUpRight   = new ToolStripMenuItem("Face Up-Right (X+Z-) (24576)");
            ToolStripMenuItem itemDownRight = new ToolStripMenuItem("Face Down-Right (X+Z+) (8192)");
            ToolStripMenuItem itemInverted  = new ToolStripMenuItem("Inverted");
            int lastDirection = 0;

            List <ToolStripMenuItem> itemList =
                new List <ToolStripMenuItem>()
            {
                itemUp,
                itemUpRight,
                itemRight,
                itemDownRight,
                itemDown,
                itemDownLeft,
                itemLeft,
                itemUpLeft,
            };

            Action <int, bool> SetFacingDirection = (int direction, bool inverted) =>
            {
                for (int i = 0; i < itemList.Count; i++)
                {
                    itemList[i].Checked = i == direction;
                }
                lastDirection = direction;

                for (int i = 0; i < buttonList.Count; i++)
                {
                    int    sign          = inverted ? -1 : 1;
                    int    positionIndex = MoreMath.NonNegativeModulus(i * sign, buttonList.Count);
                    int    buttonIndex   = MoreMath.NonNegativeModulus(direction + i, buttonList.Count);
                    Point  point         = positionList[positionIndex];
                    Button button        = buttonList[buttonIndex];
                    button.Location = point;
                }
            };

            itemLeft.Click      += (sender, e) => SetFacingDirection(6, itemInverted.Checked);
            itemRight.Click     += (sender, e) => SetFacingDirection(2, itemInverted.Checked);
            itemUp.Click        += (sender, e) => SetFacingDirection(0, itemInverted.Checked);
            itemDown.Click      += (sender, e) => SetFacingDirection(4, itemInverted.Checked);
            itemUpLeft.Click    += (sender, e) => SetFacingDirection(7, itemInverted.Checked);
            itemDownLeft.Click  += (sender, e) => SetFacingDirection(5, itemInverted.Checked);
            itemUpRight.Click   += (sender, e) => SetFacingDirection(1, itemInverted.Checked);
            itemDownRight.Click += (sender, e) => SetFacingDirection(3, itemInverted.Checked);
            itemInverted.Click  += (sender, e) =>
            {
                itemInverted.Checked = !itemInverted.Checked;
                SetFacingDirection(lastDirection, itemInverted.Checked);
            };

            ToolStripMenuItem itemPopOut = new ToolStripMenuItem("Pop Out");

            itemPopOut.Click += (sender, e) =>
            {
                VariableTripletControllerForm form = new VariableTripletControllerForm();
                TabPage parentTab  = GetTab(groupbox);
                Form    parentForm = GetForm(groupbox);
                string  text       = parentTab != null ? parentTab.Text + " " + groupbox.Text : parentForm.Text;
                form.Initialize(text, coordinateSystem, allowRelativeOptions, actionMove);
                form.ShowForm();
            };

            ContextMenuStrip contextMenuStrip = new ContextMenuStrip();

            contextMenuStrip.Items.Add(itemLeft);
            contextMenuStrip.Items.Add(itemRight);
            contextMenuStrip.Items.Add(itemUp);
            contextMenuStrip.Items.Add(itemDown);
            contextMenuStrip.Items.Add(itemUpLeft);
            contextMenuStrip.Items.Add(itemDownLeft);
            contextMenuStrip.Items.Add(itemUpRight);
            contextMenuStrip.Items.Add(itemDownRight);
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(itemInverted);
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(itemPopOut);
            groupbox.ContextMenuStrip = contextMenuStrip;

            AddInversionContextMenuStrip(buttonLineUp, buttonLineDown);

            itemUp.Checked = true;
        }
コード例 #3
0
ファイル: RngIndexer.cs プロジェクト: sticks-stuff/STROOP
 public static ushort GetRngValue(int index)
 {
     index = MoreMath.NonNegativeModulus(index, RNG_COUNT);
     return(IndexToRNGDictionary[index]);
 }