コード例 #1
0
 private static void showErrorMessageInMainThread(Form form, string message)
 {
     form.Invoke(new Action(() =>
     {
         MessageBoxUtils.showError(message);
     }));
 }
コード例 #2
0
        private bool verifyNoteCoordinates(string message, params TextBox[] textBoxes)
        {
            int index = 0;

            foreach (TextBox textBox in textBoxes)
            {
                string[] texts = textBox.Text.Split(',');
                if (texts.Length != 2)
                {
                    MessageBoxUtils.showError(message);
                    return(false);
                }
                texts[0] = texts[0].Trim();
                texts[1] = texts[1].Trim();

                int xCoordinate = Convert.ToInt32(texts[0]);
                int yCoordinate = Convert.ToInt32(texts[1]);

                if (!VerifyUtils.verifyRange(32, 512, xCoordinate) || !VerifyUtils.verifyRange(32, 384, yCoordinate))
                {
                    MessageBoxUtils.showError(message + " Detected coordinates: \"" + xCoordinate + ", " + yCoordinate + "\"");
                    return(false);
                }

                switch (index)
                {
                case 0:
                    fillArray(donPosition, xCoordinate, yCoordinate);
                    break;

                case 1:
                    fillArray(katPosition, xCoordinate, yCoordinate);
                    break;

                case 2:
                    fillArray(donFinisherPosition, xCoordinate, yCoordinate);
                    break;

                case 3:
                    fillArray(katFinisherPosition, xCoordinate, yCoordinate);
                    break;
                }
                index++;
            }
            return(true);
        }
コード例 #3
0
 public static TimingPoint ParseLine(Beatmap beatmap, string line)
 {
     string[] splitted = line.Trim().Split(',');
     if (splitted.Length == 8)
     {
         double pointValue = Convert.ToDouble(splitted[1]);
         int    kiaiValue  = Convert.ToInt32(splitted[7]);
         return(new TimingPoint(beatmap, Convert.ToDouble(splitted[0]),
                                pointValue, Convert.ToInt32(splitted[2]), Convert.ToInt32(splitted[3]),
                                Convert.ToInt32(splitted[4]), Convert.ToInt32(splitted[5]), splitted[6] == "0",
                                ((kiaiValue & KIAI_BIT) == KIAI_BIT), ((kiaiValue & OMIT_BIT) == OMIT_BIT)));
     }
     else
     {
         MessageBoxUtils.showError("A timing object always has to have 8 fields. Input: " + line.Trim());
         return(null);
     }
 }
コード例 #4
0
        public static TimingPoint GetClosestInheritedPoint(List <TimingPoint> points, double offset)
        {
            int i = GetClosestPointIndex(points, offset);

            if (i >= 0)
            {
                if (points[i].IsInherited)
                {
                    return(points[i]);
                }
                else
                {
                    // This condition might be true because the index has found the
                    // timing point but at the same time there can be another inherited
                    // point which should be the next element in this list.
                    // Check for that first.
                    if (i < points.Count - 1 && points[i + 1].Offset == offset &&
                        points[i].IsInherited)
                    {
                        return(points[i + 1]);
                    }
                    else
                    {
                        // It means there is no inherited point after this red point. Get that red point
                        // and return it as an inherited one by changing the values.
                        TimingPoint inheritedDummy = new TimingPoint(points[i])
                        {
                            PointValue  = -100d,
                            IsInherited = true
                        };
                        return(inheritedDummy);
                    }
                }
            }
            else
            {
                // There is no active any points before this offset even though we return a dummy
                // even if there is no points.
                MessageBoxUtils.showError("No timing points have been found, notes could not be processed.");
                return(null);
            }
        }
コード例 #5
0
        public static TimingPoint GetClosestTimingPoint(IList <TimingPoint> points, double offset)
        {
            int i = GetClosestPointIndex(points, offset);

            if (i >= 0)
            {
                if (!points[i].IsInherited)
                {
                    return(points[i]);
                }
                else
                {
                    // The search might have been found the inherited point
                    // instead of the timing point. Loop until the closest timing point
                    // has been found. If index becomes 0, throw an error.
                    for (; i >= 0; i--)
                    {
                        if (points[i].Offset <= offset && !points[i].IsInherited)
                        {
                            return(points[i]);
                        }
                    }

                    // At this point, it is time to throw the error.
                    MessageBoxUtils.showError("Somehow an inherited point has been found but there were no " +
                                              "timing points to take reference for.");
                    return(null);
                }
            }
            else
            {
                // There is no active any points before this offset even though we return a dummy
                // even if there is no points.
                MessageBoxUtils.showError("No timing points have been found, notes could not be processed.");
                return(null);
            }
        }
コード例 #6
0
        // Checks the values and sets them on the fly.
        //
        private bool checkValues()
        {
            bool check = true;

            // Check the SV increase mode first.
            check = VerifyUtils.verifyRange("You need to select a SV increase mode.",
                                            0, increaseModeComboBox.Items.Count, increaseModeComboBox.SelectedIndex) &&

                    // Check the necessary textboxes afterwards.
                    VerifyUtils.verifyTextBoxes("You need to fill necessary fields.",
                                                increaseModeComboBox.SelectedIndex != 0 ? increaseMultiplierTextBox : null,
                                                firstTimeTextBox,
                                                lastTimeTextBox,
                                                firstSvTextBox,
                                                lastSvTextBox) &&

                    // Check if grid snap is entered if "Put points by note snaps"
                    // is not enabled.
                    (putPointsByNotesCheckBox.Checked || VerifyUtils.verifyTextBoxes(
                         "You need to fill the \"Grid Snap\" value if you don\'t check\n" +
                         "\"Put points by note snaps\" checkbox."));

            // If anything was wrong here, don't check the rest.
            if (!check)
            {
                return(false);
            }

            // Set the sv increase mode.
            SvIncreaseMode = increaseModeComboBox.SelectedIndex;

            // Starting from here, check the values themselves.
            // Start with the extracted times.
            check = VerifyUtils.verifyOffsetFormat("First entered time format is wrong.",
                                                   firstTimeTextBox.Text, out FirstOffset);

            if (!check)
            {
                return(false);
            }

            // Check the last time text box if time mode checkbox is checked.
            // Otherwise, try to parse the integer as count.
            if (activateTimeModeCheckBox.Checked)
            {
                check = VerifyUtils.verifyOffsetFormat("Last entered time format is wrong.",
                                                       lastTimeTextBox.Text, out LastOffset);

                if (!check)
                {
                    return(false);
                }
                else if (LastOffset <= FirstOffset)
                {
                    MessageBoxUtils.showError("You cannot use the last time point before the first time point.");
                    return(false);
                }
            }
            else
            {
                check = VerifyUtils.verifyRangeFromString("Count text is wrong, value must be higher than 0.", lastTimeTextBox.Text,
                                                          0, int.MaxValue, out Count);

                if (!check)
                {
                    return(false);
                }
            }

            check = ParseUtils.GetDouble(firstSvTextBox.Text, out FirstSv);
            if (!check)
            {
                MessageBoxUtils.showError("Entered first SV value is wrong.");
                return(false);
            }

            check = ParseUtils.GetDouble(lastSvTextBox.Text, out LastSv);
            if (!check)
            {
                MessageBoxUtils.showError("Entered last SV value is wrong.");
                return(false);
            }

            if (SvIncreaseMode != 0)
            {
                check = VerifyUtils.verifyRangeFromString("Sv increase multiplier text is wrong, value must be higher than 0.", increaseMultiplierTextBox.Text,
                                                          0, int.MaxValue, out SvIncreaseMultiplier);

                if (!check)
                {
                    return(false);
                }
            }

            // If "Put points by notes" is not checked,
            // the grid snap value has to be defined.
            // Check that there.
            if (putPointsByNotesCheckBox.Checked)
            {
                GridSnap         = 0;
                PutPointsByNotes = true;
                check            = true;
            }
            else
            {
                check = VerifyUtils.verifyGridSnap("Grid snap value is wrong. Example: 1/4",
                                                   gridSnapTextBox.Text, out GridSnap);

                if (!check)
                {
                    return(false);
                }
            }

            // Check the target BPM and SV offset here. These fields are optional,
            // so accept blank text, but if it cannot parse, warn the user.
            check = VerifyUtils.verifyRangeFromString("Target BPM is wrong, example: 200.\nThis field is optional, so you can keep it blank.",
                                                      targetBpmTextBox.Text, 0, double.MaxValue, out TargetBpm, true);

            if (!check)
            {
                return(false);
            }

            check = VerifyUtils.verifyRangeFromString("SV offset is wrong, it should be between -10 and 0.\nThis field is optional, so you can keep it blank.",
                                                      svOffsetTextBox.Text, -10, 0, out SvOffset, true);

            // Finally, return true or false if checks are done.
            return(check);
        }
コード例 #7
0
        public static HitObject ParseLine(Beatmap beatmap, string line)
        {
            string[] elements = line.Trim().Split(',');
            int      type     = Convert.ToInt32(elements[3]);

            // If elements have 5 size, it is a normal hit object. Parse it as required.
            if ((type & CIRCLE) != 0)
            {
                // Do a type check first.
                if (elements.Length == 6)
                {
                    return(new HitCircle(beatmap, Convert.ToInt32(elements[0]),
                                         Convert.ToInt32(elements[1]), Convert.ToDouble(elements[2]), 0d,
                                         Convert.ToInt32(elements[3]), Convert.ToInt32(elements[4]),
                                         elements[5]));
                }
                else
                {
                    MessageBoxUtils.showError("Type and element information does not match as a circle for line: " +
                                              line + ", aborting note processing.");
                    return(null);
                }
            }
            // If elements have the size of 11, it is a slider. Parse it as required.
            else if ((type & SLIDER) != 0)
            {
                // Always check the length first.
                if (elements.Length < 8)
                {
                    MessageBoxUtils.showError("Type and element information does not match as a slider for line: " +
                                              line + ", aborting note processing.");
                    return(null);
                }
                else
                {
                    // This requires some additional processing.
                    double      offset = Convert.ToDouble(elements[2]);
                    TimingPoint point  = SearchUtils.GetClosestTimingPoint(beatmap.TimingPoints, offset);
                    if (point != null)
                    {
                        // We found the timing point, now it is time to construct the object.
                        double   pixelLength     = Convert.ToDouble(elements[7]);
                        double   duration        = pixelLength / (100.0 * beatmap.SliderMultiplier) * point.PointValue;
                        string[] hitsoundStrings = elements.Length >= 9 && !string.IsNullOrWhiteSpace(elements[8]) ?
                                                   elements[8].Split('|') : new string[0];
                        string extras = (elements.Length >= 10 ? elements[9] : "") +
                                        (elements.Length >= 11 ? "," + elements[10] : "");
                        List <int> edgeHitsounds = new List <int>();
                        for (int i = 0; i < hitsoundStrings.Length; i++)
                        {
                            edgeHitsounds.Add(Convert.ToInt32(hitsoundStrings[i]));
                        }
                        return(new HitSlider(beatmap, Convert.ToInt32(elements[0]),
                                             Convert.ToInt32(elements[1]), Convert.ToDouble(elements[2]),
                                             duration, type, Convert.ToInt32(elements[4]),
                                             string.Join(",", elements[5], elements[6], elements[7]),
                                             edgeHitsounds, extras));
                    }
                    else
                    {
                        MessageBoxUtils.showError("Slider cannot be parsed, there was no relative timing point found at offset " +
                                                  offset.ToString() + ", aborting note processing.");
                        return(null);
                    }
                }
            }
            else if ((type & SPINNER) != 0)
            {
                if (elements.Length == 7)
                {
                    double duration = Convert.ToDouble(elements[5]) - Convert.ToDouble(elements[2]);
                    return(new HitSpinner(beatmap, Convert.ToInt32(elements[0]), Convert.ToInt32(elements[1]),
                                          Convert.ToDouble(elements[2]), duration, type, Convert.ToInt32(elements[4]),
                                          elements[6]));
                }
                else
                {
                    MessageBoxUtils.showError("Type and element information does not match as a spinner for line: " +
                                              line + ", aborting note processing.");
                    return(null);
                }
            }
            else if ((type & MANIA_NOTE) != 0)
            {
                MessageBoxUtils.showError("Mania is not supported yet.");
                return(null);
            }
            else
            {
                MessageBoxUtils.showError("Unsupported element data found for line: " + line + ", aborting note " +
                                          "processing.");
                return(null);
            }
        }
コード例 #8
0
        private void load(string beatmapPath, bool addFirstState)
        {
            // Set the beatmap path.
            FilePath   = beatmapPath;
            FileName   = Path.GetFileName(beatmapPath);
            FolderPath = Path.GetDirectoryName(beatmapPath);

            // Read the file content (always extract the empty lines)
            List <string> lines = File.ReadAllLines(beatmapPath).ToList();

            for (int i = 0; i < lines.Count; i++)
            {
                if (string.IsNullOrEmpty(lines[i]))
                {
                    lines.RemoveAt(i--);
                }
            }

            // Parse the file content line by line.
            int index = 0;

            if (lines[index].StartsWith("osu file format"))
            {
                FileFormat = lines[index];
            }
            index = 1;

            // From now on, map every value in itself.
            int    dotIndex;
            string line;

            string[] splitted;
            for (; index < lines.Count; index++)
            {
                line = lines[index];
                if (IsSection(line))
                {
                    // Reached a section. If it is "[Events]", break from this loop.
                    // The rest should be handled differently.
                    if (line.Trim() == "[Events]")
                    {
                        // The next sequence needs to be addressed into
                        // the events string.
                        index++;
                        for (; index < lines.Count; index++)
                        {
                            if (IsSection(lines[index]))
                            {
                                break;
                            }
                            Events += lines[index] + Environment.NewLine;
                        }
                    }
                    // If we reach timing points, then break.
                    if (lines[index].Trim() == "[TimingPoints]")
                    {
                        index++;
                        break;
                    }
                    // Otherwise, go on.
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    dotIndex = line.IndexOf(":");
                    if (dotIndex >= 0)
                    {
                        splitted = line.Split(':');
                        if (splitted.Length == 2)
                        {
                            AssignValueByKey(splitted[0], splitted[1].TrimStart());
                        }
                    }
                }
            }

            // Timing points case.
            TimingPoint point;

            for (; !IsSection(lines[index]) && index < lines.Count; index++)
            {
                point = TimingPoint.ParseLine(this, lines[index]);
                TimingPoints.Add(point);
                if (TimingPoints[TimingPoints.Count - 1] == null)
                {
                    MessageBoxUtils.showError("Process aborted.");
                    return;
                }
            }

            // If there are any bookmarks, after timing points, add them.
            if (!string.IsNullOrWhiteSpace(bookmarksString))
            {
                string[] bookmarksSplitted = bookmarksString.Trim().Split(',');
                foreach (string offset in bookmarksSplitted)
                {
                    Bookmarks.Add(new Bookmark(this, Convert.ToInt32(offset)));
                }
            }

            // Check if beatmap has the property "colors". If it does,
            // just add it and skip to the hit objects.
            if (lines[index] == "[Colours]")
            {
                // Welp, beatmap has colors. Add them to the colors.
                index++;
                for (; !IsSection(lines[index]) && index < lines.Count; index++)
                {
                    Colours += lines[index] + Environment.NewLine;
                }
            }

            // It will break after finding a section, so raise index again.
            index++;

            // Hit objects case.
            for (; index < lines.Count; index++)
            {
                HitObjects.Add(HitObject.ParseLine(this, lines[index]));
                if (HitObjects[HitObjects.Count - 1] == null)
                {
                    MessageBoxUtils.showError("Process aborted.");
                    return;
                }
            }
            if (addFirstState)
            {
                addSavedState("First load", this);
            }
        }
コード例 #9
0
 private static void showErrorMessage(string message)
 {
     MessageBoxUtils.showError(message);
 }