Пример #1
0
        private async void GridTroopsOrders_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (e.RowIndex >= 0)
                {
                    var troopsOrderName = GridTroopsOrders.Rows[e.RowIndex].Cells[1].Value.ToString();

                    var troopsOrder = _plemionaToolLocalData.TroopsOrders.Single(ta => ta.Name == troopsOrderName);

                    SetReady(false);

                    try
                    {
                        _ownTroops = await Task.Run(() =>
                        {
                            return(_plemionaFeaturesDiagnostics.GetTroops());
                        });
                    }
                    catch (BotCheckException)
                    {
                        MessageBox.Show("Bot check detected, order stopped.", "Bot check", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    catch (FeatureException fe)
                    {
                        MessageBox.Show(fe.PlemionaErrorMessage, $"{(fe.PlemionaError ? "Plemiona" : "Unexpected")} Error", MessageBoxButtons.OK, fe.PlemionaError ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
                        return;
                    }
                    finally
                    {
                        SetReady(true);
                    }

                    using (var frmTroopsOrder = new FrmTroopsOrder(_plemionaToolLocalData.TroopsOrders.Select(tt => tt.Name), _plemionaToolLocalData.TroopsTemplates, _ownTroops, troopsOrder))
                    {
                        var dialogResult = frmTroopsOrder.ShowDialog();

                        if (dialogResult == DialogResult.OK)
                        {
                            if (frmTroopsOrder.Deletetion)
                            {
                                _plemionaToolLocalData.TroopsOrders.Remove(troopsOrder);
                                GridTroopsOrders.Rows.RemoveAt(e.RowIndex);
                                FixGridNumbers(GridTroopsOrders);
                            }
                            else
                            {
                                GridTroopsOrders.Rows[e.RowIndex].Cells[1].Value = troopsOrder.Name;
                                GridTroopsOrders.Rows[e.RowIndex].Cells[2].Value = string.Join("..", troopsOrder.VillagesCoordinates.Select(vc => $"{vc.X}|{vc.Y}"));
                                GridTroopsOrders.Rows[e.RowIndex].Cells[3].Value = troopsOrder.ExecutionDate.ToLongDateString();
                                GridTroopsOrders.Rows[e.RowIndex].Cells[4].Value = troopsOrder.Everyday;
                            }

                            _plemionaToolLocalDataService.Save(_plemionaToolLocalData);
                        }
                    }
                }
            }
        }
Пример #2
0
        private async void BtnAddTroopsOrder_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (!_featureIsBeingExecuted)
                {
                    SetReady(false);

                    _ownTroops = await Task.Run(() =>
                    {
                        return(_plemionaFeaturesDiagnostics.GetTroops());
                    });

                    SetReady(true);
                }

                using (var frmTroopsOrder = new FrmTroopsOrder(_plemionaToolLocalData.TroopsOrders.Select(tt => tt.Name), _plemionaToolLocalData.TroopsTemplates, _ownTroops))
                {
                    var dialogResult = frmTroopsOrder.ShowDialog();

                    if (dialogResult == DialogResult.OK)
                    {
                        var troopsOrder = frmTroopsOrder.TroopsOrder;

                        _plemionaToolLocalData.TroopsOrders.Add(troopsOrder);

                        GridTroopsOrders.Rows.Add(GridTroopsOrders.RowCount + 1, troopsOrder.Name, string.Join("..", troopsOrder.VillagesCoordinates.Select(vc => $"{vc.X}|{vc.Y}")), troopsOrder.ExecutionDate, troopsOrder.Everyday);
                    }
                }
            }
        }