예제 #1
0
        public static void CopyForCode(List <WatchVariableControl> controls, string dialogString = null)
        {
            if (controls.Count == 0)
            {
                return;
            }
            Func <string, string> varNameFunc;

            if (dialogString != null || KeyboardUtilities.IsCtrlHeld())
            {
                string template = dialogString ?? DialogUtilities.GetStringFromDialog("$");
                if (template == null)
                {
                    return;
                }
                varNameFunc = varName => template.Replace("$", varName);
            }
            else
            {
                varNameFunc = varName => varName;
            }
            List <string> lines = new List <string>();

            foreach (WatchVariableControl watchVar in controls)
            {
                Type   type = watchVar.GetMemoryType();
                string line = string.Format(
                    "{0} {1} = {2}{3};",
                    type != null ? TypeUtilities.TypeToString[type] : "double",
                    varNameFunc(watchVar.VarName.Replace(" ", "")),
                    watchVar.GetValue(false),
                    type == typeof(float) ? "f" : "");
                lines.Add(line);
            }
            if (lines.Count > 0)
            {
                Clipboard.SetText(string.Join("\r\n", lines));
                controls.ForEach(control => control.FlashColor(WatchVariableControl.COPY_COLOR));
            }
        }
예제 #2
0
        public static void AddGraphicsTriangleVerticesToTriangleTab()
        {
            int numVertices = 3;

            if (KeyboardUtilities.IsCtrlHeld())
            {
                numVertices = 4;
            }
            if (KeyboardUtilities.IsNumberHeld())
            {
                numVertices = KeyboardUtilities.GetCurrentlyInputtedNumber().Value;
            }

            uint triangleAddress = Config.TriangleManager.TriangleAddress;

            if (triangleAddress == 0)
            {
                return;
            }
            TriangleDataModel    triangle         = new TriangleDataModel(triangleAddress);
            List <List <short> > triangleVertices = new List <List <short> >()
            {
                new List <short>()
                {
                    triangle.X1, triangle.Y1, triangle.Z1
                },
                new List <short>()
                {
                    triangle.X2, triangle.Y2, triangle.Z2
                },
                new List <short>()
                {
                    triangle.X3, triangle.Y3, triangle.Z3
                },
            };

            int  structSize = numVertices * 0x10;
            uint ramStart   = 0x80000000;

            for (uint baseAddress = ramStart; baseAddress < ramStart + Config.RamSize - structSize; baseAddress += 2)
            {
                List <uint>          addresses = new List <uint>();
                List <string>        names     = new List <string>();
                List <List <short> > vertices  = new List <List <short> >();

                for (int i = 0; i < numVertices; i++)
                {
                    List <short> vertex = new List <short>();
                    for (int j = 0; j < 3; j++)
                    {
                        uint   offset    = (uint)(i * 0x10 + j * 0x02);
                        uint   address   = baseAddress + offset;
                        short  value     = Config.Stream.GetInt16(address);
                        string component = j == 0 ? "x" : j == 1 ? "y" : "z";
                        string name      = "v" + (i + 1) + component;

                        addresses.Add(address);
                        names.Add(name);
                        vertex.Add(value);
                    }
                    vertices.Add(vertex);
                }

                List <List <List <short> > > vertexSubsets = ControlUtilities.GetSubsets(vertices, 3);
                foreach (List <List <short> > vertexSubset in vertexSubsets)
                {
                    if (AreVerticesEqual(triangleVertices, vertexSubset))
                    {
                        List <WatchVariableControlPrecursor> precursors = new List <WatchVariableControlPrecursor>();
                        for (int i = 0; i < addresses.Count; i++)
                        {
                            WatchVariable watchVar = new WatchVariable(
                                memoryTypeName: "short",
                                specialType: null,
                                baseAddressType: BaseAddressTypeEnum.Relative,
                                offsetUS: null,
                                offsetJP: null,
                                offsetPAL: null,
                                offsetDefault: addresses[i],
                                mask: null,
                                shift: null);
                            WatchVariableControlPrecursor precursor = new WatchVariableControlPrecursor(
                                name: names[i],
                                watchVar: watchVar,
                                subclass: WatchVariableSubclass.Number,
                                backgroundColor: null,
                                displayType: null,
                                roundingLimit: null,
                                useHex: null,
                                invertBool: null,
                                isYaw: null,
                                coordinate: null,
                                groupList: new List <VariableGroup>()
                            {
                                VariableGroup.Custom
                            });
                            precursors.Add(precursor);
                        }

                        Config.TriangleManager.AddVariables(
                            precursors.ConvertAll(precursor => precursor.CreateWatchVariableControl()));
                    }
                }
            }
        }