Skip to content

Commit

Permalink
Merge pull request #390 from Ariemeth/reposition_unit_in_group
Browse files Browse the repository at this point in the history
Add ability to move units up and down in the group lists
  • Loading branch information
Ariemeth authored Apr 28, 2024
2 parents 339c8e0 + 98e2eb8 commit 6ead0e3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
24 changes: 24 additions & 0 deletions lib/models/combatGroups/group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ class Group extends ChangeNotifier {
notifyListeners();
}

bool moveUnitUpInList(Unit unit) {
final index = _units.indexOf(unit);
if (index <= 0) {
return false;
}

_units.removeAt(index);
_units.insert(index - 1, unit);
notifyListeners();
return true;
}

bool moveUnitDownInList(Unit unit) {
final index = _units.indexOf(unit);
if (index < 0 || index >= _units.length - 1) {
return false;
}

_units.removeAt(index);
_units.insert(index + 1, unit);
notifyListeners();
return true;
}

List<Unit> allUnits() {
return _units.toList();
}
Expand Down
52 changes: 48 additions & 4 deletions lib/screens/roster/combatGroup/combat_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:gearforce/screens/upgrades/unit_upgrade_button.dart';
import 'package:gearforce/widgets/unit_text_cell.dart';

const double _sectionheight = 320;
const double _movementIconCellWidth = 36;

class CombatGroupWidget extends StatefulWidget {
CombatGroupWidget(this.roster, {required this.name});
Expand Down Expand Up @@ -129,10 +130,18 @@ class _CombatGroupWidgetState extends State<CombatGroupWidget> {

List<DataColumn> _generateTableHeading() {
return <DataColumn>[
DataColumn(
label: Container(
width: _movementIconCellWidth,
child: UnitTextCell.columnTitle(
'',
),
),
),
DataColumn(
label: Container(
alignment: Alignment.centerLeft,
width: 160,
width: 180,
child: UnitTextCell.columnTitle(
"Model",
textAlignment: TextAlign.left,
Expand Down Expand Up @@ -166,7 +175,7 @@ class _CombatGroupWidgetState extends State<CombatGroupWidget> {
),
DataColumn(
label: Container(
width: 92,
width: 60,
child: UnitTextCell.columnTitle(
'Rank',
),
Expand All @@ -182,9 +191,9 @@ class _CombatGroupWidgetState extends State<CombatGroupWidget> {
),
DataColumn(
label: Container(
width: 65,
width: 40,
child: UnitTextCell.columnTitle(
'Veteran',
'Vet',
),
),
),
Expand Down Expand Up @@ -217,6 +226,40 @@ class _CombatGroupWidgetState extends State<CombatGroupWidget> {
for (var i = 0; i < units.length; i++) {
var unit = units[i];
final canBeCommand = ruleSet.canBeCommand(unit);
var movementCell = DataCell(Column(
children: [
SizedBox(
width: _movementIconCellWidth,
height: 24.0,
child: IconButton(
onPressed: unit == units.firstOrNull
? null
: () => group.moveUnitUpInList(unit),
icon: const Icon(
size: 15.0,
Icons.arrow_upward,
color: Colors.blueAccent,
),
splashRadius: 20.0,
),
),
SizedBox(
width: _movementIconCellWidth,
height: 24.0,
child: IconButton(
onPressed: unit == units.lastOrNull
? null
: () => group.moveUnitDownInList(unit),
icon: const Icon(
size: 15.0,
Icons.arrow_downward,
color: Colors.blueAccent,
),
splashRadius: 20.0,
),
),
],
));
var nameCell = DataCell(
UnitTextCell.content(
unit.name,
Expand Down Expand Up @@ -345,6 +388,7 @@ class _CombatGroupWidgetState extends State<CombatGroupWidget> {
);

var dataRow = DataRow(cells: [
movementCell,
nameCell,
tvCell,
actionCell,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/roster/roster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:url_launcher/url_launcher_string.dart';
const double _leftPanelWidth = 670.0;
const double _titleHeight = 40.0;
const double _menuTitleHeight = 50.0;
const String _version = '1.5.0';
const String _version = '1.6.0';
const String _bugEmailAddress = '[email protected]';
const String _dp9URL = 'https://www.dp9.com/';
const String _sourceCodeURL = 'https://github.com/Ariemeth/gearforce-flutter';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 1.5.0
version: 1.6.0
environment:
sdk: ">=3.0.0"

Expand Down

0 comments on commit 6ead0e3

Please sign in to comment.