Exemplo n.º 1
0
        /// <summary>
        /// Right click village context menu on the XPTable
        /// </summary>
        private void TableControl_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (Table.TableModel.Selections.SelectedItems.Length > 1)
                {
                    // Show context menu for multiple villages
                    var vils = new List<Village>();
                    foreach (Row row in Table.TableModel.Selections.SelectedItems)
                    {
                        vils.AddRange(((ITwContextMenu)row).GetVillages());
                    }

                    var menu = new VillagesContextMenu(_map, vils, (villageTypeSetTo) =>
                        {
                            foreach (Row row in Table.TableModel.Selections.SelectedItems)
                            {
                                row.Cells[1].Image = villageTypeSetTo.GetImage(true);
                            }
                        });
                    menu.Show(Table, e.Location);
                }
                else
                {
                    // Display context menu for one village, player or tribe
                    Table.TableModel.Selections.Clear();
                    if (Table.ColumnModel != null)
                    {
                        Table.TableModel.Selections.SelectCells(Table.RowIndexAt(e.Location), 0, Table.RowIndexAt(e.Location), Table.ColumnModel.Columns.Count - 1);
                        if (Table.TableModel.Selections.SelectedItems.Length == 1)
                        {
                            var row = (ITwContextMenu)Table.TableModel.Selections.SelectedItems[0];
                            row.ShowContext(e.Location);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Provide right click context menu
        /// </summary>
        private void GridExVillage_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                var rowCount = GridExVillage.SelectedItems.Count;
                if (rowCount == 1)
                {
                    var row = GridExVillage.CurrentRow;
                    if (row != null && row.RowType == RowType.Record)
                    {
                        var record = row.GetDataRow<PolygonDataSet.VILLAGERow>();

                        var contextMenu = new VillageContextMenu(World.Default.Map, record.Village, () => GridExVillage.Refresh());
                        contextMenu.Show(GridExVillage, e.Location);
                    }
                }
                else if (rowCount > 1)
                {
                    IEnumerable<Village> villages = GridExVillage.SelectedItems.GetDataSetRows<PolygonDataSet.VILLAGERow>().Select(x => x.Village);

                    var contextMenu = new VillagesContextMenu(World.Default.Map, villages.ToArray(), type => GridExVillage.Refresh());
                    contextMenu.Show(GridExVillage, e.Location);
                }
            }
        }