public ShipGroupData Add()
 {
     int key = ShipGroups.Count > 0 ? ShipGroups.Keys.Max() + 1 : 1;
     var group = new ShipGroupData( key );
     ShipGroups.Add( group );
     return group;
 }
 public ShipGroupData Add()
 {
     int key = GetUniqueID();
     var group = new ShipGroupData( key );
     ShipGroups.Add( group );
     return group;
 }
		public DialogShipGroupColumnFilter( DataGridView target, ShipGroupData group ) {
			InitializeComponent();


			var rows = new LinkedList<DataGridViewRow>();
			var row = new DataGridViewRow();

			row.CreateCells( ColumnView );
			row.SetValues( "(全て)", null, null, "-" );
			row.Cells[ColumnView_Width.Index].ReadOnly = true;
			rows.AddLast( row );

			foreach ( var c in group.ViewColumns.Values.OrderBy( c => c.DisplayIndex ) ) {
				row = new DataGridViewRow();
				row.CreateCells( ColumnView );
				row.SetValues( target.Columns[c.Name].HeaderText, c.Visible, c.AutoSize, c.Width );
				row.Cells[ColumnView_Width.Index].ValueType = typeof( int );
				row.Tag = c.Name;
				rows.AddLast( row );
			}

			ColumnView.Rows.AddRange( rows.ToArray() );


			ScrLkColumnCount.Minimum = 0;
			ScrLkColumnCount.Maximum = group.ViewColumns.Count;
			ScrLkColumnCount.Value = group.ScrollLockColumnCount;
		}
        public ShipGroupData Add()
        {
            int key   = GetUniqueID();
            var group = new ShipGroupData(key);

            ShipGroups.Add(group);
            return(group);
        }
        public ShipGroupData Add()
        {
            int key   = ShipGroups.Count > 0 ? ShipGroups.Keys.Max() + 1 : 1;
            var group = new ShipGroupData(key);

            ShipGroups.Add(group);
            return(group);
        }
		public DialogShipGroupSortOrder( DataGridView target, ShipGroupData group ) {
			InitializeComponent();

			var rows_enabled = new LinkedList<DataGridViewRow>();
			var rows_disabled = new LinkedList<DataGridViewRow>();

			var columns = target.Columns.Cast<DataGridViewColumn>();
			var names = columns.Select( c => c.Name );


			if ( group.SortOrder == null )
				group.SortOrder = new List<KeyValuePair<string, ListSortDirection>>();

			foreach ( var sort in group.SortOrder.Where( s => names.Contains( s.Key ) ) ) {

				var row = new DataGridViewRow();

				row.CreateCells( EnabledView );
				row.SetValues( target.Columns[sort.Key].HeaderText, sort.Value );
				row.Cells[EnabledView_Name.Index].Tag = sort.Key;
				row.Tag = columns.FirstOrDefault( c => c.Name == sort.Key ).DisplayIndex;

				rows_enabled.AddLast( row );
			}

			foreach ( var name in names.Where( n => group.SortOrder.Count( s => n == s.Key ) == 0 ) ) {

				var row = new DataGridViewRow();

				row.CreateCells( DisabledView );
				row.SetValues( target.Columns[name].HeaderText );
				row.Cells[DisabledView_Name.Index].Tag = name;
				row.Tag = columns.FirstOrDefault( c => c.Name == name ).DisplayIndex;

				rows_disabled.AddLast( row );
			}

			EnabledView.Rows.AddRange( rows_enabled.ToArray() );
			DisabledView.Rows.AddRange( rows_disabled.ToArray() );


			AutoSortFlag.Checked = group.AutoSortEnabled;
		}
        /// <summary>
        /// 表示設定を反映します。
        /// </summary>
        private void ApplyViewData( ShipGroupData group )
        {
            IsRowsUpdating = true;

            // いったん解除しないと列入れ替え時にエラーが起きる
            foreach ( DataGridViewColumn column in ShipView.Columns ) {
                column.Frozen = false;
            }

            foreach ( var data in group.ViewColumns.Values.OrderBy( g => g.DisplayIndex ) ) {
                data.ToColumn( ShipView.Columns[data.Name] );
            }

            int count = 0;
            foreach ( var column in ShipView.Columns.Cast<DataGridViewColumn>().OrderBy( c => c.DisplayIndex ) ) {
                column.Frozen = count < group.ScrollLockColumnCount;
                count++;
            }

            IsRowsUpdating = false;
        }
        private void ApplyAutoSort( ShipGroupData group )
        {
            if ( !group.AutoSortEnabled || group.SortOrder == null )
                return;

            // 一番上/最後に実行したほうが優先度が高くなるので逆順で
            for ( int i = group.SortOrder.Count - 1; i >= 0; i-- ) {

                var order = group.SortOrder[i];
                ListSortDirection dir = order.Value;

                if ( ShipView.Columns[order.Key].SortMode != DataGridViewColumnSortMode.NotSortable )
                    ShipView.Sort( ShipView.Columns[order.Key], dir );
            }
        }
 /// <summary>
 /// 現在の表を基に、グループメンバーを更新します。
 /// </summary>
 private void UpdateMembers( ShipGroupData group )
 {
     group.UpdateMembers( ShipView.Rows.Cast<DataGridViewRow>().Select( r => (int)r.Cells[ShipView_ID.Index].Value ) );
 }
        public DialogShipGroupFilter( ShipGroupData group )
        {
            InitializeComponent();

            {
                // 一部の列ヘッダを中央揃えにする
                var headercenter = new DataGridViewCellStyle( ExpressionView_Enabled.HeaderCell.Style );
                headercenter.Alignment = DataGridViewContentAlignment.MiddleCenter;
                ExpressionView_Enabled.HeaderCell.Style =
                ExpressionView_InternalAndOr.HeaderCell.Style =
                ExpressionView_ExternalAndOr.HeaderCell.Style =
                ExpressionView_Inverse.HeaderCell.Style =
                ExpressionView_Up.HeaderCell.Style =
                ExpressionView_Down.HeaderCell.Style =
                ExpressionDetailView_Enabled.HeaderCell.Style =
                ConstFilterView_Up.HeaderCell.Style =
                ConstFilterView_Down.HeaderCell.Style =
                ConstFilterView_Delete.HeaderCell.Style =
                headercenter;
            }

            #region init DataTable
            {
                _dtAndOr = new DataTable();
                _dtAndOr.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( bool ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtAndOr.Rows.Add( true, "And" );
                _dtAndOr.Rows.Add( false, "Or" );
                _dtAndOr.AcceptChanges();

                ExpressionView_InternalAndOr.ValueMember = "Value";
                ExpressionView_InternalAndOr.DisplayMember = "Display";
                ExpressionView_InternalAndOr.DataSource = _dtAndOr;

                ExpressionView_ExternalAndOr.ValueMember = "Value";
                ExpressionView_ExternalAndOr.DisplayMember = "Display";
                ExpressionView_ExternalAndOr.DataSource = _dtAndOr;
            }
            {
                _dtLeftOperand = new DataTable();
                _dtLeftOperand.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( string ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var lont in ExpressionData.LeftOperandNameTable )
                    _dtLeftOperand.Rows.Add( lont.Key, lont.Value );
                _dtLeftOperand.AcceptChanges();

                LeftOperand.ValueMember = "Value";
                LeftOperand.DisplayMember = "Display";
                LeftOperand.DataSource = _dtLeftOperand;
            }
            {
                _dtOperator = new DataTable();
                _dtOperator.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var ont in ExpressionData.OperatorNameTable )
                    _dtOperator.Rows.Add( ont.Key, ont.Value );
                _dtOperator.AcceptChanges();

                Operator.ValueMember = "Value";
                Operator.DisplayMember = "Display";
                Operator.DataSource = _dtOperator;
            }
            {
                _dtOperator_bool = new DataTable();
                _dtOperator_bool.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_bool.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_bool.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_bool.AcceptChanges();
            }
            {
                _dtOperator_number = new DataTable();
                _dtOperator_number.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.LessThan, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.LessThan] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.LessEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.LessEqual] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.GreaterThan, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.GreaterThan] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.GreaterEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.GreaterEqual] );
                _dtOperator_number.AcceptChanges();
            }
            {
                _dtOperator_string = new DataTable();
                _dtOperator_string.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.Contains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Contains] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotContains] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.BeginWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.BeginWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotBeginWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotBeginWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.EndWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.EndWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotEndWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEndWith] );
                _dtOperator_string.AcceptChanges();
            }
            {
                _dtOperator_array = new DataTable();
                _dtOperator_array.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_array.Rows.Add( ExpressionData.ExpressionOperator.ArrayContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.ArrayContains] );
                _dtOperator_array.Rows.Add( ExpressionData.ExpressionOperator.ArrayNotContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.ArrayNotContains] );
                _dtOperator_array.AcceptChanges();
            }
            {
                _dtRightOperand_bool = new DataTable();
                _dtRightOperand_bool.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( bool ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtRightOperand_bool.Rows.Add( true, "○" );
                _dtRightOperand_bool.Rows.Add( false, "×" );
                _dtRightOperand_bool.AcceptChanges();
            }
            {
                _dtRightOperand_shipname = new DataTable();
                _dtRightOperand_shipname.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var s in KCDatabase.Instance.MasterShips.Values.Where( s => !s.IsAbyssalShip ).OrderBy( s => s.NameWithClass ).OrderBy( s => s.NameReading ) )
                    _dtRightOperand_shipname.Rows.Add( s.ShipID, s.Name );
                _dtRightOperand_shipname.AcceptChanges();
            }
            {
                _dtRightOperand_shiptype = new DataTable();
                _dtRightOperand_shiptype.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var st in KCDatabase.Instance.ShipTypes.Values )
                    _dtRightOperand_shiptype.Rows.Add( st.TypeID, st.Name );
                _dtRightOperand_shiptype.AcceptChanges();
            }
            {
                _dtRightOperand_range = new DataTable();
                _dtRightOperand_range.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                for ( int i = 0; i <= 4; i++ )
                    _dtRightOperand_range.Rows.Add( i, Constants.GetRange( i ) );
                _dtRightOperand_range.AcceptChanges();
            }
            {
                _dtRightOperand_speed = new DataTable();
                _dtRightOperand_speed.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtRightOperand_speed.Rows.Add( 0, Constants.GetSpeed( 0 ) );
                _dtRightOperand_speed.Rows.Add( 5, Constants.GetSpeed( 5 ) );
                _dtRightOperand_speed.Rows.Add( 10, Constants.GetSpeed( 10 ) );
                _dtRightOperand_speed.AcceptChanges();
            }
            {
                _dtRightOperand_rarity = new DataTable();
                _dtRightOperand_rarity.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                for ( int i = 1; i <= 8; i++ )
                    _dtRightOperand_rarity.Rows.Add( i, Constants.GetShipRarity( i ) );
                _dtRightOperand_rarity.AcceptChanges();
            }
            {
                _dtRightOperand_equipment = new DataTable();
                _dtRightOperand_equipment.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtRightOperand_equipment.Rows.Add( -1, "(なし)" );
                foreach ( var eq in KCDatabase.Instance.MasterEquipments.Values.Where( eq => !eq.IsAbyssalEquipment ).OrderBy( eq => eq.CategoryType ) )
                    _dtRightOperand_equipment.Rows.Add( eq.EquipmentID, eq.Name );
                _dtRightOperand_equipment.Rows.Add( 0, "(未開放)" );
                _dtRightOperand_equipment.AcceptChanges();
            }

            RightOperand_ComboBox.ValueMember = "Value";
            RightOperand_ComboBox.DisplayMember = "Display";
            RightOperand_ComboBox.DataSource = _dtRightOperand_bool;

            SetExpressionSetter( ExpressionData.LeftOperandNameTable.Keys.First() );

            #endregion

            ConstFilterSelector.SelectedIndex = 0;

            ImportGroupData( group );
        }
        /// <summary>
        /// グループデータをコピーし、UIを初期化します。
        /// </summary>
        /// <param name="group">対象となるグループ。コピーされるためこのインスタンスには変更は適用されません。</param>
        public void ImportGroupData( ShipGroupData group )
        {
            _group = group.Clone();

            UpdateExpressionView();
            UpdateConstFilterView();
        }
        private void FormShipGroup_Load( object sender, EventArgs e )
        {
            ShipGroupManager groups = KCDatabase.Instance.ShipGroup;

            if ( !groups.ShipGroups.ContainsKey( -1 ) ) {
                var master = new ShipGroupData( -1 );
                master.Name = GeneralRes.AllAssignedShips;
                master.ColumnFilter = Enumerable.Repeat<bool>( true, ShipView.Columns.Count ).ToList();
                master.ColumnWidth = ShipView.Columns.OfType<DataGridViewColumn>().Select( c => c.Width ).ToList();

                groups.ShipGroups.Add( master );
            }

            foreach ( var g in groups.ShipGroups.Values ) {
                TabPanel.Controls.Add( CreateTabLabel( g.GroupID ) );
            }

            {
                int columnCount = ShipView.Columns.Count;
                for ( int i = 0; i < columnCount; i++ ) {
                    ShipView.Columns[i].Visible = false;
                }
            }

            ConfigurationChanged();

            APIObserver o = APIObserver.Instance;

            o.APIList["api_port/port"].ResponseReceived += APIUpdated;
            o.APIList["api_get_member/ship2"].ResponseReceived += APIUpdated;
            o.APIList["api_get_member/ship_deck"].ResponseReceived += APIUpdated;

            Utility.Configuration.Instance.ConfigurationChanged += ConfigurationChanged;

            Icon = ResourceManager.ImageToIcon( ResourceManager.Instance.Icons.Images[(int)ResourceManager.IconContent.FormShipGroup] );
        }