fix: button sizes

This commit is contained in:
2023-10-15 02:59:47 +03:00
parent 1eebc88e3c
commit 7fada0c523
4 changed files with 88 additions and 80 deletions

View File

@@ -16,6 +16,7 @@ class MUDAction {
String content;
Automation? parent;
MUDActionTarget target;
MUDAction(
this.content, {
this.target = MUDActionTarget.execute,
@@ -35,6 +36,7 @@ class MUDAction {
case MUDActionTarget.world:
debugPrint('ActionSendTo.world: $content');
store.send(content);
// if (parent == null || !parent!.isRemovedFromBuffer) {
if (parent != null && !parent!.isRemovedFromBuffer) {
store.echoOwn(content);
}
@@ -42,6 +44,7 @@ class MUDAction {
case MUDActionTarget.execute:
debugPrint('ActionSendTo.execute: $content');
store.execute(content);
// if (parent == null || !parent!.isRemovedFromBuffer) {
if (parent != null && !parent!.isRemovedFromBuffer) {
store.echoOwn(content);
}

View File

@@ -20,16 +20,7 @@ class GameButtonSet extends StatelessWidget {
alignment: data.alignment,
child: IconTheme(
data: IconTheme.of(context).copyWith(size: 32),
child: Builder(
builder: (context) {
final containerSize = data.size;
return SizedBox(
width: containerSize.width,
height: containerSize.height,
child: _buildButtonContainer(context),
);
},
),
child: Builder(builder: _buildButtonContainer),
),
);
}
@@ -41,11 +32,13 @@ class GameButtonSet extends StatelessWidget {
crossAxisCount: data.crossAxisCount,
spacing: data.spacing,
count: data.buttons.length,
size: data.size,
alignment: data.alignment,
builder: (context, index) => data.buttons[index] != null
? GameButton(data: data.buttons[index]!)
: Container(),
: const SizedBox(
width: GameButtonData.defaultSize,
height: GameButtonData.defaultSize,
),
);
}
@@ -57,7 +50,6 @@ class GameButtonSet extends StatelessWidget {
required int? crossAxisCount,
required Alignment alignment,
required double spacing,
required Size size,
}) {
final buttonWidgets = List.generate(
count,
@@ -70,17 +62,41 @@ class GameButtonSet extends StatelessWidget {
case GameButtonSetType.row:
return Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: buttonWidgets,
);
case GameButtonSetType.column:
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: buttonWidgets,
);
case GameButtonSetType.grid:
return GridView.count(
crossAxisCount: crossAxisCount ?? 3,
children: buttonWidgets,
final rows = <List<Widget>>[];
final rowCount = (count / crossAxisCount!).ceil();
for (var i = 0; i < rowCount; i++) {
final row = <Widget>[];
for (var j = 0; j < crossAxisCount; j++) {
final index = i * crossAxisCount + j;
if (index < count) {
row.add(buttonWidgets[index]);
} else {
row.add(Container());
}
}
rows.add(row);
}
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: rows
.map((row) => Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: row,
))
.toList(),
);
}
}
@@ -121,8 +137,6 @@ class GameButtonSetData {
buttons: [],
);
Size get size => Size(calculateWidth(), calculateHeight());
List<GameButtonData> get nonEmptyButtons =>
buttons.whereType<GameButtonData>().toList();
@@ -190,52 +204,52 @@ class GameButtonSetData {
group: group ?? this.group,
);
double calculateWidth() {
switch (type) {
case GameButtonSetType.row:
return sumSize(buttons) + (buttons.length - 1) * spacing;
case GameButtonSetType.column:
return maxSize(buttons) + spacing;
case GameButtonSetType.grid:
final colWidths = List.generate(
colCount,
(index) => maxSize(getColumnButtons(index)),
);
return colWidths.fold<double>(0, (sum, width) => sum + width) +
(colCount - 0) * spacing;
}
}
double calculateHeight() {
switch (type) {
case GameButtonSetType.row:
return maxSize(buttons) + spacing;
case GameButtonSetType.column:
return sumSize(buttons) + (buttons.length - 1) * spacing;
case GameButtonSetType.grid:
final rowHeights = List.generate(
rowCount,
(index) => maxSize(getRowButtons(index)),
);
return rowHeights.fold<double>(0, (sum, height) => sum + height) +
(rowCount - 0) * spacing;
}
}
double maxSize(List<GameButtonData?> buttons) {
return buttons.fold<double>(
0,
(sum, button) => max(sum, button?.size ?? GameButtonData.defaultSize),
);
}
double sumSize(List<GameButtonData?> buttons) {
return buttons.fold<double>(
0,
(sum, button) => sum + (button?.size ?? GameButtonData.defaultSize),
);
}
// double calculateWidth() {
// switch (type) {
// case GameButtonSetType.row:
// return sumSize(buttons) + buttons.length * spacing;
// case GameButtonSetType.column:
// return maxSize(buttons) + spacing;
// case GameButtonSetType.grid:
// final colWidths = List.generate(
// colCount,
// (index) => maxSize(getColumnButtons(index)),
// );
//
// return colWidths.fold<double>(
// 0, (sum, width) => sum + width + (spacing / 2));
// }
// }
//
// double calculateHeight() {
// switch (type) {
// case GameButtonSetType.row:
// return maxSize(buttons) + spacing;
// case GameButtonSetType.column:
// return sumSize(buttons) + buttons.length * spacing;
// case GameButtonSetType.grid:
// final rowHeights = List.generate(
// rowCount,
// (index) => maxSize(getRowButtons(index)),
// );
// return rowHeights.fold<double>(
// 0, (sum, height) => sum + height + (spacing / 2));
// }
// }
//
// double maxSize(List<GameButtonData?> buttons) {
// return buttons.fold<double>(
// 0,
// (sum, button) => max(sum, button?.size ?? GameButtonData.defaultSize),
// );
// }
//
// double sumSize(List<GameButtonData?> buttons) {
// return buttons.fold<double>(
// 0,
// (sum, button) => sum + (button?.size ?? GameButtonData.defaultSize),
// );
// }
List<GameButtonData?> getRowButtons(int row) =>
getRowIndices(row).map((index) => buttons[index]).toList(growable: false);

View File

@@ -65,11 +65,9 @@ class LuaBindings {
int gsub(LuaState ls) {
final source = ls.checkString(1)!;
// ls.pop(1);
final find = ls.checkString(2)!;
// ls.pop(1);
final replace = ls.checkString(3)!;
// ls.pop(1);
ls.pop(3);
debugPrint("lua string.gsub $source, $find, $replace");
ls.pushString(source.replaceAll(find, replace));

View File

@@ -29,18 +29,19 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return _buildContainer(
context,
(context, index) {
final theme = Theme.of(context);
final button = data.buttons[index];
final size = button?.size ?? GameButtonData.defaultSize;
final Widget child = button != null
? FakeGameButton(label: button.label)
: const Icon(Icons.add, color: Colors.white);
: SizedBox.square(
dimension: size,
child: const Icon(Icons.add, color: Colors.white),
);
return Container(
height: size,
width: size,
decoration: BoxDecoration(
color: button == null
? theme.dividerColor.withOpacity(0.2)
@@ -52,7 +53,6 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
style: BorderStyle.solid,
),
),
// color: Colors.grey,
child: GameButtonWrapper(
size: size,
isEmpty: button == null,
@@ -280,14 +280,8 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
BuildContext context,
Widget Function(BuildContext context, int index) builder,
) {
final size = Size(
data.size.width + data.spacing * 6,
data.size.height + data.spacing * 10,
);
return Center(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(16),
@@ -298,10 +292,9 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
child: GameButtonSet.buildContainer(
context: context,
type: data.type,
size: data.size,
count: data.buttons.length,
crossAxisCount: data.crossAxisCount,
spacing: data.spacing / 3,
spacing: data.spacing / 4,
alignment: data.alignment,
builder: builder,
),