Ejemplo n.º 1
0
        private void UpdateFusionRowDisplay(
            DataGridViewRow currentFusionRow, Domain.Demon demon1, Domain.Demon demon2, Domain.Demon demon3)
        {
            currentFusionRow.Cells[DGV_DEMONFUSION_COL_ID].Style = GlobalObjects.GetDefaultDgvcStyle(DGV_FUSIONS_FONT_SIZE);

            currentFusionRow.Cells[DGV_DEMONFUSION_COL_LEVEL1].ReadOnly                    =
                currentFusionRow.Cells[DGV_DEMONFUSION_COL_RACE1].ReadOnly                 =
                    currentFusionRow.Cells[DGV_DEMONFUSION_COL_NAME1].ReadOnly             =
                        currentFusionRow.Cells[DGV_DEMONFUSION_COL_LEVEL2].ReadOnly        =
                            currentFusionRow.Cells[DGV_DEMONFUSION_COL_RACE2].ReadOnly     =
                                currentFusionRow.Cells[DGV_DEMONFUSION_COL_NAME2].ReadOnly = true;

            currentFusionRow.Cells[DGV_DEMONFUSION_COL_LEVEL1].Style        =
                currentFusionRow.Cells[DGV_DEMONFUSION_COL_RACE1].Style     =
                    currentFusionRow.Cells[DGV_DEMONFUSION_COL_NAME1].Style = GlobalObjects.GetDefaultDgvcStyle
                                                                                  (fontSize: DGV_FUSIONS_FONT_SIZE, enabled: false, inParty: demon1.IsInParty);

            currentFusionRow.Cells[DGV_DEMONFUSION_COL_LEVEL2].Style        =
                currentFusionRow.Cells[DGV_DEMONFUSION_COL_RACE2].Style     =
                    currentFusionRow.Cells[DGV_DEMONFUSION_COL_NAME2].Style = GlobalObjects.GetDefaultDgvcStyle
                                                                                  (fontSize: DGV_FUSIONS_FONT_SIZE, enabled: false, inParty: demon2.IsInParty);

            currentFusionRow.Cells[DGV_DEMONFUSION_COL_LEVEL3].Style        =
                currentFusionRow.Cells[DGV_DEMONFUSION_COL_RACE3].Style     =
                    currentFusionRow.Cells[DGV_DEMONFUSION_COL_NAME3].Style = GlobalObjects.GetDefaultDgvcStyle(
                        fontSize: DGV_FUSIONS_FONT_SIZE,
                        enabled: demon3 == null,
                        inParty: demon3 == null ? false : demon3.IsInParty);
        }
Ejemplo n.º 2
0
        private void UpdateDemonsGrid()
        {
            var allDemons = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons).OrderBy(y => y.Level).ThenBy(y => y.Name);

            foreach (Domain.Demon oneDemon in allDemons)
            {
                var demonRow = new Object[6];

                demonRow[DGV_DEMON_COL_ID]      = oneDemon.Id;
                demonRow[DGV_DEMON_COL_FUSE]    = oneDemon.IsFused;
                demonRow[DGV_DEMON_COL_INPARTY] = oneDemon.IsInParty;
                demonRow[DGV_DEMON_COL_LEVEL]   = oneDemon.Level;
                demonRow[DGV_DEMON_COL_RACE]    = oneDemon.Race.Name;
                demonRow[DGV_DEMON_COL_NAME]    = oneDemon.Name;

                this.dgvDemons.Rows.Add(demonRow);
            }

            foreach (DataGridViewRow dr in this.dgvDemons.Rows)
            {
                dr.Cells[DGV_DEMON_COL_INPARTY].Style  =
                    dr.Cells[DGV_DEMON_COL_FUSE].Style =
                        GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: true);

                dr.Cells[DGV_DEMON_COL_LEVEL].Style        =
                    dr.Cells[DGV_DEMON_COL_RACE].Style     =
                        dr.Cells[DGV_DEMON_COL_NAME].Style =
                            GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: true);

                dr.Cells[DGV_DEMON_COL_INPARTY].ReadOnly  =
                    dr.Cells[DGV_DEMON_COL_FUSE].ReadOnly = false;
            }
        }
Ejemplo n.º 3
0
        private Domain.Demon GetDemonFromDataGridViewRow(DataGridViewRow dgvr, bool canInsertRace)
        {
            Domain.Demon returnDemon = null;

            if (!String.IsNullOrEmpty(dgvr.Cells[(int)MyDataGridColumns.colId3].Value.ToString()))
            {
                // Selecting / updating demon
                MessageBox.Show("UPDATING fusions is not implemented. Please refresh window to reload data.");
                returnDemon = null;
            }
            else if (((FusionObject)dgvr.Cells[(int)MyDataGridColumns.colFusionObject].Value).FusionIsImpossible)
            {
                MessageBox.Show("UPDATING fusions from impossible to possible is not implemented. " +
                                "Please refresh window to reload data.");
                returnDemon = null;
            }
            else
            {
                // Inserting new demon
                object nameValue = dgvr.Cells[(int)MyDataGridColumns.colName3].Value;

                if (nameValue != null)
                {
                    returnDemon = GetDemonFromDataGridViewRowDemonColumn(dgvr);
                }
                else
                {
                    object idValue    = dgvr.Cells[(int)MyDataGridColumns.colId3].Value;
                    object levelValue = dgvr.Cells[(int)MyDataGridColumns.colLevel3].Value;
                    object raceValue  = dgvr.Cells[(int)MyDataGridColumns.colRace3].Value;

                    if (levelValue != null && nameValue != null && raceValue != null)
                    {
                        var actualDemonRace = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>().
                                              Where(x => x.Name == raceValue.ToString()).FirstOrDefault();
                        if (actualDemonRace == null && canInsertRace)
                        {
                            actualDemonRace = GlobalObjects.InsertRaceMaybe(raceValue.ToString());
                        }

                        if (actualDemonRace != null)
                        {
                            returnDemon       = new Domain.Demon();
                            returnDemon.Level = Convert.ToInt32(levelValue.ToString());
                            returnDemon.Name  = (string)nameValue;
                            returnDemon.Race  = actualDemonRace;
                        }
                    }
                }
            }

            return(returnDemon);
        }
Ejemplo n.º 4
0
        private void AddOneColumn(Domain.Race oneRace)
        {
            string raceName  = (oneRace == null ? "" : oneRace.Name);
            var    oneColumn = new DataGridViewTextBoxColumn()
            {
                HeaderText       = raceName,
                Name             = "col" + raceName,
                Width            = 60,
                ReadOnly         = (oneRace == null),
                DefaultCellStyle = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE)
            };

            this.dgvFusions.Columns.Add(oneColumn);
        }
Ejemplo n.º 5
0
        private void InitializeColumnsAndStuff()
        {
            this.colId = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Id", Name = "colId", Width = 40, ReadOnly = true
            };
            this.colInParty = new DataGridViewCheckBoxColumn {
                HeaderText = "InParty", Name = "colInParty", Width = 50
            };
            this.colLevel = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Level", Name = "colLevel", Width = 80, ReadOnly = true
            };
            this.colRace = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Race", Name = "colRace", Width = 120, ReadOnly = true
            };
            this.colName = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Name", Name = "colName", Width = 240
            };

            this.dgvDemons.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.None;
            this.dgvDemons.AllowUserToResizeRows     = false;
            this.dgvDemons.RowTemplate.Height        = 40;
            this.dgvDemons.RowTemplate.MinimumHeight = 40;
            this.dgvDemons.AllowUserToAddRows        = true;

            this.colLevel.DefaultCellStyle        =
                this.colRace.DefaultCellStyle     =
                    this.colName.DefaultCellStyle =
                        GlobalObjects.GetDefaultDgvcStyle(16);

            this.colId.DefaultCellStyle =
                GlobalObjects.GetDefaultDgvcStyle(16, false);

            this.dgvDemons.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                this.colId,
                this.colInParty,
                this.colLevel,
                this.colRace,
                this.colName
            });

            // for the eventual combobox
            // var racesList = new List<FeatherItem>();
            // _game.Races.ToList().ForEach(x => racesList.Add(new FeatherItem(x.Name, x)));
            // this.colRace.DataSource = racesList;
        }
Ejemplo n.º 6
0
        private void SaveChanges(bool exiting = false)
        {
            using (var transaction = _dbSession.BeginTransaction())
            {
                foreach (var oneFusionRace in GlobalObjects.CurrentGame.FusionRaces)
                {
                    _dbSession.Save(oneFusionRace);
                }
                foreach (var oneFusionDemon in GlobalObjects.CurrentGame.FusionDemons)
                {
                    _dbSession.Save(oneFusionDemon);
                }
                _changesWereDone = false;
                transaction.Commit();
            }
            if (!exiting)
            {
                var currentGame = GlobalObjects.CurrentGame;
                currentGame.demonsById = currentGame.Races.SelectMany(x => x.Demons)
                                         .ToDictionary(d => d.Id);
                UpdateDemonFusionsGrid();
                RecalculateFusionRowIndexes();

                foreach (DataGridViewRow dr in dgvDemons.Rows)
                {
                    dr.Cells[DGV_DEMON_COL_INPARTY].Style  =
                        dr.Cells[DGV_DEMON_COL_FUSE].Style =
                            GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: true);

                    dr.Cells[DGV_DEMON_COL_LEVEL].Style        =
                        dr.Cells[DGV_DEMON_COL_RACE].Style     =
                            dr.Cells[DGV_DEMON_COL_NAME].Style =
                                GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: true);

                    dr.Cells[DGV_DEMON_COL_INPARTY].ReadOnly  =
                        dr.Cells[DGV_DEMON_COL_FUSE].ReadOnly = false;
                }
            }
            MessageBox.Show("Saved.");
        }
Ejemplo n.º 7
0
        private Domain.Demon GetDemonFromDataGridViewRow(DataGridViewRow dgvr, bool canInsertRace)
        {
            Domain.Demon returnDemon = null;

            if (dgvr.Cells[(int)MyDataGridColumns.columnObject].Value != null)
            {
                // Selecting / updating demon
                returnDemon = (Domain.Demon)dgvr.Cells[(int)MyDataGridColumns.columnObject].Value;
            }
            else
            {
                // Inserting new demon
                object idValue    = dgvr.Cells[(int)MyDataGridColumns.columnId].Value;
                object levelValue = dgvr.Cells[(int)MyDataGridColumns.columnLevel].Value;
                object nameValue  = dgvr.Cells[(int)MyDataGridColumns.columnName].Value;
                object raceValue  = dgvr.Cells[(int)MyDataGridColumns.columnRace].Value;

                if (levelValue != null && nameValue != null && raceValue != null)
                {
                    var actualDemonRace = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>().
                                          Where(x => x.Name == raceValue.ToString()).FirstOrDefault();
                    if (actualDemonRace == null && canInsertRace)
                    {
                        actualDemonRace = GlobalObjects.InsertRaceMaybe(raceValue.ToString());
                    }

                    if (actualDemonRace != null)
                    {
                        returnDemon       = new Domain.Demon();
                        returnDemon.Level = Convert.ToInt32(levelValue.ToString());
                        returnDemon.Name  = (string)nameValue;
                        returnDemon.Race  = actualDemonRace;
                    }
                }
            }

            return(returnDemon);
        }
Ejemplo n.º 8
0
        private void InitializeColumnsAndStuff()
        {
            List <DataGridViewColumn> listOfColumns = new List <DataGridViewColumn>();

            this.colFusionObject = new DataGridViewTextBoxColumn()
            {
                HeaderText = "FusionObject",
                Name       = "colFusionObject",
                Visible    = false,
                Tag        = MyDataGridColumns.colFusionObject
            };
            listOfColumns.Add(colFusionObject);

            this.colId1 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Id1",
                Name       = "colId1",
                Visible    = false,
                Tag        = MyDataGridColumns.colId1
            };
            this.colLevel1 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Level1",
                Name       = "colLevel1",
                Width      = 45,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colLevel1
            };
            this.colRaceObject1 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "RaceObject1",
                Name       = "colRaceObject1",
                Visible    = false,
                Tag        = MyDataGridColumns.colRaceObject1
            };
            this.colRace1 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Race1",
                Name       = "colRace1",
                Width      = 90,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colRace1
            };
            this.colName1 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Name1",
                Name       = "colName1",
                Width      = 180,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colName1
            };
            listOfColumns.AddRange(new DataGridViewColumn[] {
                colId1, colLevel1, colRaceObject1, colRace1, colName1
            });


            this.colId2 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Id2",
                Name       = "colId2",
                Visible    = false,
                Tag        = MyDataGridColumns.colId2
            };
            this.colLevel2 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Level2",
                Name       = "colLevel2",
                Width      = 45,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colLevel2
            };
            this.colRaceObject2 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "RaceObject2",
                Name       = "colRaceObject2",
                Visible    = false,
                Tag        = MyDataGridColumns.colRaceObject2
            };
            this.colRace2 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Race2",
                Name       = "colRace2",
                Width      = 90,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colRace2
            };
            this.colName2 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Name2",
                Name       = "colName2",
                Width      = 180,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.colName2
            };
            listOfColumns.AddRange(new DataGridViewColumn[] {
                colId2, colLevel2, colRaceObject2, colRace2, colName2
            });


            this.colId3 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Id3",
                Name       = "colId3",
                Visible    = false,
                Tag        = MyDataGridColumns.colId3
            };
            this.colLevel3 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Level3",
                Name       = "colLevel3",
                Width      = 45,
                ReadOnly   = false,
                Tag        = MyDataGridColumns.colLevel3
            };
            this.colRace3 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Race3",
                Name       = "colRace3",
                Width      = 90,
                ReadOnly   = false,
                Tag        = MyDataGridColumns.colRace3
            };
            this.colName3 = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Name3",
                Name       = "colName3",
                Width      = 180,
                ReadOnly   = false,
                Tag        = MyDataGridColumns.colName3
            };
            listOfColumns.AddRange(new DataGridViewColumn[] { colId3, colLevel3, colRace3, colName3 });

            this.dgvPartyFusions.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.None;
            this.dgvPartyFusions.AllowUserToResizeRows     = false;
            this.dgvPartyFusions.RowTemplate.Height        = 40;
            this.dgvPartyFusions.RowTemplate.MinimumHeight = 40;
            this.dgvPartyFusions.AllowUserToAddRows        = false;

            this.colLevel1.DefaultCellStyle                = this.colLevel2.DefaultCellStyle =
                this.colLevel3.DefaultCellStyle            = this.colRace1.DefaultCellStyle =
                    this.colRace2.DefaultCellStyle         = this.colRace3.DefaultCellStyle =
                        this.colName1.DefaultCellStyle     = this.colName2.DefaultCellStyle =
                            this.colName3.DefaultCellStyle = GlobalObjects.GetDefaultDgvcStyle(16);

            foreach (MyDataGridColumns oneColumnType in Enum.GetValues(typeof(MyDataGridColumns)))
            {
                foreach (DataGridViewColumn oneColumnToAdd in listOfColumns)
                {
                    if (((MyDataGridColumns)oneColumnToAdd.Tag) == oneColumnType)
                    {
                        this.dgvPartyFusions.Columns.Add(oneColumnToAdd);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvFusions.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvFusions.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of fusions.");

                var currentGameRaces   = game.Races.ToList();
                var currentGameRaceIds = currentGameRaces.Select(x => x.Id).ToList();
                var allFusions         =
                    _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                    .Where(x => currentGameRaceIds.Contains(x.IdRace1))
                    .OrderBy(y => y.IdRace1)
                    .ThenBy(z => z.IdRace2).ToList();

                AddOneColumn(null);
                foreach (var oneRace in currentGameRaces)
                {
                    AddOneColumn(oneRace);
                }

                // first row
                object[] oneRow = new object[currentGameRaces.Count + 1];
                oneRow[0] = " ";
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    oneRow[i + 1] = currentGameRaces[i].Name;
                }

                // race tag on every cell of the first row except the first one
                this.dgvFusions.Rows.Add(oneRow);
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    this.dgvFusions.Rows[0].Cells[i + 1].Tag = currentGameRaces[i];
                }

                // following rows
                DataGridViewRow oneDgvr;
                foreach (var oneRace in currentGameRaces)
                {
                    oneDgvr = new DataGridViewRow();
                    oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                    {
                        Value = oneRace.Name,
                        Tag   = oneRace
                    });
                    foreach (var anotherRace in currentGameRaces)
                    {
                        int?idRaceResult =
                            allFusions.Where(x =>
                                             x.IdRace1 == oneRace.Id &&
                                             x.IdRace2 == anotherRace.Id)
                            .Select(y => y.IdRace3).FirstOrDefault();
                        if (idRaceResult == null)
                        {
                            idRaceResult =
                                allFusions.Where(x =>
                                                 x.IdRace2 == oneRace.Id &&
                                                 x.IdRace1 == anotherRace.Id)
                                .Select(y => y.IdRace3).FirstOrDefault();
                        }
                        Domain.Race raceResult =
                            (idRaceResult == null ? null :
                             _dbSession.Get <Domain.Race>(idRaceResult.GetValueOrDefault()));

                        oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                        {
                            Value = (raceResult == null ? null : raceResult.Name),
                            Tag   = raceResult
                        });
                    }
                    this.dgvFusions.Rows.Add(oneDgvr);
                }

                foreach (DataGridViewCell oneCell in this.dgvFusions.Rows[0].Cells)
                {
                    oneCell.ReadOnly = true;
                    oneCell.Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                foreach (DataGridViewRow aRow in this.dgvFusions.Rows)
                {
                    aRow.Cells[0].ReadOnly = true;
                    aRow.Cells[0].Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                AddHandlers();
                _logger.Info("Adding complete.");

                SetFormats();
            }
            _logger.CloseSection(location);
        }
Ejemplo n.º 10
0
        private void dgvFusions_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            List <Domain.Fusion> allFusions;

            if (_cellChanged)
            {
                string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;
                _logger.OpenSection(location);

                _logger.Info("Called with row index " + e.RowIndex + ", column index = " + e.ColumnIndex);
                Domain.Race race1      = this.dgvFusions.Rows[0].Cells[e.ColumnIndex].Tag as Domain.Race;
                Domain.Race race2      = this.dgvFusions.Rows[e.RowIndex].Cells[0].Tag as Domain.Race;
                var         resultCell = this.dgvFusions.Rows[e.RowIndex].Cells[e.ColumnIndex];

                Domain.Race race3 = null;

                if (resultCell.Value != null)
                {
                    race3 = GlobalObjects.CurrentGame.Races.
                            Where(x => x.Name == resultCell.Value.ToString()).FirstOrDefault();

                    if (race3 == null && resultCell.ToString() == GlobalObjects.ImpossibleToFuseRace.Name)
                    {
                        race3 = GlobalObjects.ImpossibleToFuseRace;
                    }

                    if (race3 == null)
                    {
                        race3 = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>()
                                .Where(x => x.Name == resultCell.Value.ToString()).FirstOrDefault();
                        if (race3 == null)
                        {
                            race3 = GlobalObjects.InsertRaceMaybe(resultCell.ToString());
                        }
                    }
                }

                if (race3 == null && resultCell.Value != null)
                {
                    _logger.Info("Insertion cancelled.");
                }
                else
                {
                    using (var transaction = _dbSession.BeginTransaction())
                    {
                        var currentFusion =
                            _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                            .Where(x => x.IdRace1 == race2.Id && x.IdRace2 == race1.Id)
                            .FirstOrDefault();
                        if (currentFusion == null)
                        {
                            currentFusion = _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                                            .Where(x => x.IdRace1 == race1.Id && x.IdRace2 == race2.Id)
                                            .FirstOrDefault();
                        }

                        if (currentFusion != null)
                        {
                            _logger.Info("Got fusion " + currentFusion.ToString());
                            if (race3 != null)
                            {
                                _logger.Info("Result of fusion will now be " + race3.ToString());
                                currentFusion.IdRace3 = race3.Id;
                                _logger.Info("Saving fusion " + currentFusion.ToString());
                                _dbSession.Update(currentFusion);
                                _logger.Info("Saved.");
                            }
                            else
                            {
                                _logger.Info("Fusion will be deleted from database.");
                                _dbSession.Delete(currentFusion);
                                _logger.Info("Deleted.");
                            }
                        }
                        else
                        {
                            currentFusion = new Domain.Fusion(race1, race2, race3);
                            _logger.Info("Creating new fusion " + currentFusion.ToString());
                            _dbSession.Save(currentFusion);
                            _logger.Info("Created.");
                        }

                        transaction.Commit();
                        _logger.Info("Fusion saved.");
                    }
                }

                _logger.CloseSection(location);
            }
        }
Ejemplo n.º 11
0
        private void dgvDemons_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (_cellDemonChanged)
            {
                string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;
                _logger.OpenSection(location);

                _logger.Info("Called with row index " + e.RowIndex + ", column index = " + e.ColumnIndex);
                var currentRow = this.dgvDemons.Rows[e.RowIndex];

                if (!_addingDemon)
                {
                    var id = currentRow.Cells[DGV_DEMON_COL_ID].Value.ToString();
                    id = id + id;
                }
                else
                {
                    var raceName  = this.dgvDemons.Rows[this.dgvDemons.Rows.Count - 2].Cells[DGV_DEMON_COL_RACE].Value.ToString();
                    var demonRace = GlobalObjects.CurrentGame.Races.Where(x => x.Name == raceName).FirstOrDefault();

                    if (demonRace == null)
                    {
                        MessageBox.Show("Race '" + raceName + "' does not exist.");
                        RemoveHandlers();
                        this.dgvDemons.Rows.RemoveAt(this.dgvDemons.Rows.Count - 2);
                        AddHandlers();
                        return;
                    }

                    var demonName   = this.dgvDemons.Rows[this.dgvDemons.Rows.Count - 2].Cells[DGV_DEMON_COL_NAME].Value.ToString();
                    var demonExists = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons)
                                      .Where(x => x.Name == demonName).FirstOrDefault() != null;

                    if (demonExists)
                    {
                        MessageBox.Show("This demon already exists.");
                        RemoveHandlers();
                        this.dgvRaces.Rows.RemoveAt(this.dgvRaces.Rows.Count - 2);
                        AddHandlers();
                        return;
                    }

                    int demonLevel = -1;
                    if (!Int32.TryParse(
                            this.dgvDemons.Rows[this.dgvDemons.Rows.Count - 2].Cells[DGV_DEMON_COL_LEVEL].Value.ToString(), out demonLevel))
                    {
                        MessageBox.Show("Invalid level.");
                        RemoveHandlers();
                        this.dgvRaces.Rows.RemoveAt(this.dgvRaces.Rows.Count - 2);
                        AddHandlers();
                        return;
                    }

                    try
                    {
                        using (var transaction = _dbSession.BeginTransaction())
                        {
                            if (!_changesWereDone)
                            {
                                foreach (DataGridViewRow dr in dgvDemons.Rows)
                                {
                                    dr.Cells[DGV_DEMON_COL_INPARTY].Style  =
                                        dr.Cells[DGV_DEMON_COL_FUSE].Style =
                                            GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: false);

                                    dr.Cells[DGV_DEMON_COL_LEVEL].Style        =
                                        dr.Cells[DGV_DEMON_COL_RACE].Style     =
                                            dr.Cells[DGV_DEMON_COL_NAME].Style =
                                                GlobalObjects.GetDefaultDgvcStyle(fontSize: DGV_DEMONS_FONT_SIZE, enabled: true);

                                    dr.Cells[DGV_DEMON_COL_INPARTY].ReadOnly  =
                                        dr.Cells[DGV_DEMON_COL_FUSE].ReadOnly = false;
                                }
                            }
                            _changesWereDone = true;

                            var allDemonsSoFar = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons).ToList();
                            var fgg            = allDemonsSoFar.Count();

                            var newDemon = new Domain.Demon(demonLevel, demonName, demonRace);
                            _dbSession.Save(newDemon);
                            demonRace.Demons.Add(newDemon);

                            foreach (Domain.Demon oneDemon in allDemonsSoFar)
                            {
                                var fusionRaceObject = GlobalObjects.CurrentGame.FusionRaces.Where
                                                           (x =>
                                                           (x.IdRace1 == oneDemon.Race.Id && x.IdRace2 == newDemon.Race.Id) ||
                                                           (x.IdRace2 == oneDemon.Race.Id && x.IdRace1 == newDemon.Race.Id))
                                                       .FirstOrDefault();

                                var resultDemon = fusionRaceObject == null ? null :
                                                  FindDemonFromFusion(oneDemon, newDemon, fusionRaceObject).Item1;

                                var newFusion = newDemon.Level > oneDemon.Level ?
                                                new Domain.FusionDemon(GlobalObjects.CurrentGame.Id, oneDemon, newDemon, resultDemon) :
                                                new Domain.FusionDemon(GlobalObjects.CurrentGame.Id, newDemon, oneDemon, resultDemon);
                                GlobalObjects.CurrentGame.FusionDemons.Add(newFusion);
                            }

                            // Update fusions where the new demon might be the result of a previously unknown fusion
                            // e.g. fusion says Gouki 7+ unknown, then add Gouki 12 Kushi-mitama
                            var demonFusionsToUpdate = GlobalObjects.CurrentGame.FusionDemons.Where
                                                           (x => /*x.Demon3 == null && fgg: doit considérer le cas où quelqu'un insère
                                                                  * le level 23 Gouki avant le level 12 Gouki, et là les fusions
                                                                  * 5+6 pointent vers le level 23*/x.Race3 != null && x.Race3.Id == newDemon.Race.Id);
                            foreach (Domain.FusionDemon fusionToUpdate in demonFusionsToUpdate)
                            {
                                if (newDemon.Level >= fusionToUpdate.Level3)
                                {
                                    var fusionRaceObject = GlobalObjects.CurrentGame.FusionRaces.Where
                                                               (x =>
                                                               (x.IdRace1 == fusionToUpdate.Demon1.Race.Id && x.IdRace2 == fusionToUpdate.Demon2.Race.Id) ||
                                                               (x.IdRace2 == fusionToUpdate.Demon1.Race.Id && x.IdRace1 == fusionToUpdate.Demon2.Race.Id))
                                                           .FirstOrDefault();
                                    var demonFusionTuple = FindDemonFromFusion(fusionToUpdate.Demon1, fusionToUpdate.Demon2, fusionRaceObject);

                                    if (demonFusionTuple.Item1 == null)
                                    {
                                        fusionToUpdate.Demon3 = newDemon;
                                    }
                                    else if (fusionToUpdate.Demon3 != null &&
                                             demonFusionTuple.Item1 != null &&
                                             demonFusionTuple.Item1.Id != fusionToUpdate.Demon3.Id)
                                    {
                                        fusionToUpdate.Demon3 = newDemon;
                                    }
                                }
                            }

                            RemoveHandlers();
                            this.dgvDemons.Rows[this.dgvDemons.Rows.Count - 2].Cells[DGV_DEMON_COL_ID].Value = newDemon.Id;
                            AddHandlers();
                            transaction.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                        throw;
                    }

                    _addingDemon = false;
                }
            }

            if (_demonFusionStatusChanged)
            {
                var currentGame = GlobalObjects.CurrentGame;

                var currentRow = dgvDemons.Rows[dgvDemons.SelectedCells[0].RowIndex];

                var selectedDemonId = Convert.ToInt32(currentRow.Cells[DGV_DEMON_COL_ID].Value);
                var useInFusions    = (bool)(currentRow.Cells[DGV_DEMON_COL_FUSE].Value);
                var fggcell         = currentRow.Cells[DGV_DEMON_COL_INPARTY];

                var inParty = (bool?)(currentRow.Cells[DGV_DEMON_COL_INPARTY].Value) ?? false;

                var selectedDemon = currentGame.demonsById[selectedDemonId];

                try
                {
                    using (var transaction = _dbSession.BeginTransaction())
                    {
                        selectedDemon.IsFused   = useInFusions;
                        selectedDemon.IsInParty = inParty;
                        _dbSession.Save(selectedDemon);
                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                    throw;
                }

                var affectedFusions = currentGame.FusionDemons.Where(
                    x => x.Demon1.Id == selectedDemonId || x.Demon2.Id == selectedDemonId ||
                    (x.Demon3 != null && x.Demon3.Id == selectedDemonId)).ToList();

                foreach (Domain.FusionDemon oneFusion in affectedFusions)
                {
                    var currentFusionRow = this.dgvFusions.Rows[DataGridFusionRowIndexesPerFusionId[oneFusion.Id]];
                    currentFusionRow.Visible = oneFusion.Demon1.IsFused && oneFusion.Demon2.IsFused;
                    UpdateFusionRowDisplay(currentFusionRow, oneFusion.Demon1, oneFusion.Demon2, oneFusion.Demon3);
                }
                _demonFusionStatusChanged = false;
            }
        }
Ejemplo n.º 12
0
        private void InitializeColumnsAndStuff()
        {
            List <DataGridViewColumn> listOfColumns = new List <DataGridViewColumn>();

            this.colInParty = new DataGridViewCheckBoxColumn {
                HeaderText = "Party",
                Name       = "colInParty",
                Width      = 40,
                Tag        = MyDataGridColumns.columnInParty
            };
            listOfColumns.Add(colInParty);

            this.colUseInFusions = new DataGridViewCheckBoxColumn {
                HeaderText = "Fuse",
                Name       = "colUseInFusions",
                Width      = 40,
                Tag        = MyDataGridColumns.columnUseInFusions
            };
            listOfColumns.Add(colUseInFusions);

            this.colObject = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Object",
                Name       = "colObject",
                Visible    = false,
                Tag        = MyDataGridColumns.columnObject
            };
            listOfColumns.Add(colObject);

            this.colId = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Id",
                Name       = "colId",
                Width      = 45,
                ReadOnly   = true,
                Tag        = MyDataGridColumns.columnId
            };
            listOfColumns.Add(colId);

            this.colLevel = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Level",
                Name       = "colLevel",
                Width      = 55,
                Tag        = MyDataGridColumns.columnLevel
            };
            listOfColumns.Add(colLevel);

            this.colRace = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Race",
                Name       = "colRace",
                Width      = 85,
                Tag        = MyDataGridColumns.columnRace
            };
            listOfColumns.Add(colRace);

            this.colName = new DataGridViewTextBoxColumn()
            {
                HeaderText = "Name",
                Name       = "colName",
                Width      = 250,
                Tag        = MyDataGridColumns.columnName
            };
            listOfColumns.Add(colName);

            this.dgvDemons.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.None;
            this.dgvDemons.AllowUserToResizeRows     = false;
            this.dgvDemons.RowTemplate.Height        = 40;
            this.dgvDemons.RowTemplate.MinimumHeight = 40;

            this.colLevel.DefaultCellStyle        =
                this.colRace.DefaultCellStyle     =
                    this.colName.DefaultCellStyle =
                        GlobalObjects.GetDefaultDgvcStyle(16);

            this.colId.DefaultCellStyle =
                GlobalObjects.GetDefaultDgvcStyle(16, false);

            foreach (MyDataGridColumns oneColumnType in Enum.GetValues(typeof(MyDataGridColumns)))
            {
                foreach (DataGridViewColumn oneColumnToAdd in listOfColumns)
                {
                    if (((MyDataGridColumns)oneColumnToAdd.Tag) == oneColumnType)
                    {
                        this.dgvDemons.Columns.Add(oneColumnToAdd);
                    }
                }
            }

            // for the eventual combobox
            // var racesList = new List<FeatherItem>();
            // _game.Races.ToList().ForEach(x => racesList.Add(new FeatherItem(x.Name, x)));
            // this.colRace.DataSource = racesList;
        }