示例#1
0
 // Save a BO file
 public static void SaveBO(BuildOrder bo)
 {
     using (StreamWriter file = new StreamWriter(string.Concat(DirectoryPath(), bo.ToPath())))
     {
         file.Write(bo.ToFormat());
     }
 }
示例#2
0
        /*
         * Saving the BO
         * Does not save it if informations are missing or incorrect
         */
        private void Saving(object sender, RoutedEventArgs e)
        {
            if (actionsBOPreview.Items.Count < 1)
            {
                feedbackTextBlock.Text = "You need at least one action";
                return;
            }

            try
            {
                List <Action> castedList = actionsBOPreview.Items.OfType <Action>().ToList();

                Dictionary <string, string> metaDatas = new Dictionary <string, string>();
                metaDatas.Add("type", typeBox.Text);
                metaDatas.Add("matchup", matchupBox.Text);
                metaDatas.Add("author", authorBox.Text);
                metaDatas.Add("description", boCommentBox.Text);

                BuildOrder.CreateAndSaveBO(nameBox.Text, castedList, metaDatas);
                feedbackTextBlock.Text = "BO successfully added";
            }
            catch (Exception ex)
            {
                feedbackTextBlock.Text = ex.Message;
            }
        }
示例#3
0
        private void UpdateSelection(object sender, SelectionChangedEventArgs e)
        {
            if (GetSelectedBO() == null)
            {
                playButton.IsEnabled   = false;
                deleteButton.IsEnabled = false;
                modifyButton.IsEnabled = false;
                copyButton.IsEnabled   = false;
                return;
            }
            playButton.IsEnabled   = true;
            deleteButton.IsEnabled = true;
            modifyButton.IsEnabled = true;
            copyButton.IsEnabled   = true;

            // BO preview
            selectedBOPreview.Items.Clear();

            BuildOrder preview = GetSelectedBO();

            boNamePreview.Content = preview.Name;
            foreach (var meta in preview.MetaDataToString)
            {
                selectedBOPreview.Items.Add(meta);
            }
            List <Action> actions = preview.ListOfAction;

            foreach (Action action in actions)
            {
                selectedBOPreview.Items.Add(action.ToString());
            }
        }
示例#4
0
        public Select()
        {
            InitializeComponent();
            var boList = BuildOrder.ReadAllBO();

            // Global list
            foreach (var bo in boList)
            {
                if (bo != null)
                {
                    this.allList.Items.Add(bo);
                }
            }

            // RaceList
            foreach (var bo in boList)
            {
                if (bo != null)
                {
                    if (bo.IsTerran())
                    {
                        terranList.Items.Add(bo);
                    }
                    if (bo.IsZerg())
                    {
                        zergList.Items.Add(bo);
                    }
                    if (bo.IsProtoss())
                    {
                        protossList.Items.Add(bo);
                    }
                }
            }
        }
        public PlayMenu(BuildOrder bo)
        {
            InitializeComponent();

            reader = new BuildOrderReader(bo, this, timerLabel, titleLabel, previousLabel, actualLabel, nextLabel);

            Console.WriteLine("Starting Global Key listener...");
            KListener.KeyDown += new RawKeyEventHandler(GlobalKeyPressed);
            KListener.KeyUp   += new RawKeyEventHandler(GlobalKeyUnpressed);


            /*
             * Process[] processlist = Process.GetProcesses();
             * Process sp = null;
             * foreach (Process process in processlist)
             * {
             *  //Console.WriteLine("Process: {0} ID: {1}", process.ProcessName, process.Id);
             *  if (process.ProcessName == "SC2_x64")
             *  {
             *      sp = process;
             *      Console.WriteLine(process.ProcessName);
             *  }
             *  if (process.Id == 7888)
             *  {
             *      Console.WriteLine(process.StartTime);
             *      Console.WriteLine("Process: {0} ID: {1}", process.ProcessName, process.Id);
             *  }
             * } */
        }
        public BuildOrderReader(BuildOrder bo, Page page, TextBlock timerLabel, Label titleLabel, Label previousLabel, Label currentLabel, Label nextLabel)
        {
            this.bo         = bo;
            this.timerLabel = timerLabel;
            this.page       = page;

            // Initialize labels and actions lists
            labels = new List <Label>
            {
                previousLabel,
                currentLabel,
                nextLabel
            };

            actionsOnLabels = new List <Action>
            {
                PreviousAction,
                CurrentAction,
                NextAction
            };
            titleLabel.Content = bo.Name;

            //Initialise list
            listOfActions = bo.ListOfAction;
            NextAction    = listOfActions[0];
            listOfActions.Remove(NextAction);

            // Time setup
        }
示例#7
0
        // create a object BO from it string format
        // Return null if bad format
        public static BuildOrder CreateBOFromString(string boStr, string name = "")
        {
            string[] lines = Regex.Split(boStr, "(?:\r\n)");

            bool actionLines = false;
            Dictionary <string, string> metaData = new Dictionary <string, string>();

            foreach (var item in allowedDatas)
            {
                metaData.Add(item, "");
            }

            List <Action> actionList = new List <Action>();

            foreach (var line in lines)
            {
                // Match these tags without a specific order
                var splitedLine = Regex.Split(line, @"^(?=.*(Name|Type|Description|Matchup|Author).*\:(.*))(?:.*|\r)", RegexOptions.IgnoreCase);

                // Check if the line is a action line
                if (Action.regexActionParser.IsMatch(line))
                {
                    actionLines = true;
                }

                if (!actionLines)
                {
                    if (splitedLine.Count() > 1)
                    {
                        var meta = splitedLine[1].ToLower();
                        if (meta == "name")
                        {
                            name = splitedLine[2];
                        }
                        else if (metaData.Keys.Contains(meta))
                        {
                            metaData[meta] = splitedLine[2];
                        }
                    }
                }
                else
                {
                    var action = Action.ReadActionLine(line);
                    if (action != null)
                    {
                        actionList.Add(action);
                    }
                    ;
                }
            }
            BuildOrder bo = new BuildOrder(name, actionList, metaData);

            return(bo);
        }
示例#8
0
        // Remove a BO from the file system
        internal static void DeleteBO(BuildOrder selectedItem)
        {
            string directory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + folderName;
            string path      = string.Concat(directory, selectedItem.ToPath());

            if (!File.Exists(path))
            {
                Console.WriteLine("Error deleting BuildOrder. File not found. Maybe the name of the file is not the name of the BO.");
            }
            File.Delete(path);
        }
示例#9
0
        private void CopyClipboardClic(object sender, RoutedEventArgs e)
        {
            BuildOrder selectedBo = GetSelectedBO();

            if (selectedBo == null)
            {
                // TODO Write a error message on a label
                return;
            }

            Clipboard.SetText(selectedBo.ToFormat());
            // TODO confirmation message in a label
        }
示例#10
0
        // Fill boxes with the bo informations
        private void FillBoxes(BuildOrder bo)
        {
            nameBox.Text      = bo.Name;
            matchupBox.Text   = bo.MetaDatas["matchup"];
            authorBox.Text    = bo.MetaDatas["author"];
            boCommentBox.Text = bo.MetaDatas["description"];
            typeBox.Text      = bo.MetaDatas["type"];
            actionsBOPreview.Items.Clear();

            foreach (var action in bo.ListOfAction)
            {
                actionsBOPreview.Items.Add(action);
            }
        }
示例#11
0
        private void DeleteSelected(object sender, RoutedEventArgs e)
        {
            BuildOrder selectedItem = GetSelectedBO();

            if (selectedItem != null)
            {
                BuildOrder.DeleteBO(selectedItem);

                // Remove element from lists
                allList.Items.Remove(selectedItem);
                terranList.Items.Remove(selectedItem);
                protossList.Items.Remove(selectedItem);
                zergList.Items.Remove(selectedItem);
                selectedBOPreview.Items.Clear();
            }
        }
示例#12
0
        // Import a .bo file
        private void ImportFileClick(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "Build order file (*.bo)|*.bo|All files (*.*)|*.*";
                dialog.ShowDialog();

                // TODO replay ???????
                BuildOrder bo = BuildOrder.ReadBO(dialog.FileName);
                FillBoxes(bo);

                feedbackTextBlock.Text = "Sucessfully import bo";
            }
            catch (Exception)
            {
                feedbackTextBlock.Text = "File is not build order";
            }
        }
示例#13
0
        // Import some types of bo using clipboard
        private void importClipboardClick(object sender, RoutedEventArgs e)
        {
            try
            {
                string     clipBoardText = Clipboard.GetText();
                BuildOrder bo;

                if (SALT.saltMatch.IsMatch(clipBoardText))
                {
                    bo = BuildOrder.CreateBOFromSALT(new SALT(clipBoardText));
                }
                else
                {
                    bo = BuildOrder.CreateBOFromString(clipBoardText);
                }
                FillBoxes(bo);
                feedbackTextBlock.Text = "Sucessfully import bo";
            }
            catch (Exception ex)
            {
                feedbackTextBlock.Text = "There is no build order in Clipboard";
            }
        }
示例#14
0
 public BuildOrderMenu(BuildOrder bo)
 {
     InitializeComponent();
     FillBoxes(bo);
 }
示例#15
0
        //Create a custom BO from the BuildOrderMenu
        public static void CreateAndSaveBO(string name, IEnumerable <Action> actionList, Dictionary <string, string> metaDatas)
        {
            BuildOrder bo = new BuildOrder(name, actionList, metaDatas);

            SaveBO(bo);
        }