Skip to content

Commit

Permalink
add landscape support
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 committed Jan 15, 2019
1 parent 8710e90 commit 4a8399c
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 103 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Please view [README_EN](https://github.com/boyan01/flutter-tetris/blob/master/RE

![效果预览](./_preview/game_gif.gif)

支持横屏模式

![横屏](./_preview/screen_land.jpg)


## 其他
Expand Down
4 changes: 4 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Inspired by [vue-tetris](https://github.com/Binaryify/vue-tetris).

![preview](./_preview/game_gif.gif)

support landscape

![land](./_preview/screen_land.jpg)

## Other

MIT License
Binary file added _preview/screen_land.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 6 additions & 60 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:tetris/gamer/gamer.dart';
import 'package:tetris/generated/i18n.dart';
import 'package:tetris/income/donation_dialog.dart';
import 'package:tetris/panel/controller.dart';
import 'package:tetris/panel/screen.dart';
import 'package:tetris/panel/page_portrait.dart';

void main() {
_disableDebugPrint();
Expand Down Expand Up @@ -51,65 +49,13 @@ class MyApp extends StatelessWidget {

const SCREEN_BORDER_WIDTH = 3.0;

const BACKGROUND_COLOR = const Color(0xffefcc19);

class _HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final screenW = size.width * 0.8;

return SizedBox.expand(
child: Container(
color: Color(0xffefcc19),
child: Padding(
padding: MediaQuery.of(context).padding,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Spacer(),
FlatButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => DonationDialog());
},
child: Text(S.of(context).reward))
],
),
Spacer(),
Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: const Color(0xFF987f0f),
width: SCREEN_BORDER_WIDTH),
left: BorderSide(
color: const Color(0xFF987f0f),
width: SCREEN_BORDER_WIDTH),
right: BorderSide(
color: const Color(0xFFfae36c),
width: SCREEN_BORDER_WIDTH),
bottom: BorderSide(
color: const Color(0xFFfae36c),
width: SCREEN_BORDER_WIDTH),
),
),
child: Container(
decoration:
BoxDecoration(border: Border.all(color: Colors.black54)),
child: Container(
padding: const EdgeInsets.all(3),
color: SCREEN_BACKGROUND,
child: Screen(width: screenW),
),
),
),
Spacer(flex: 2),
GameController(),
],
),
),
),
);
return MediaQuery.of(context).orientation == Orientation.landscape
? PageLand()
: PagePortrait();
}
}
8 changes: 5 additions & 3 deletions lib/material/briks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class Brik extends StatelessWidget {

@override
Widget build(BuildContext context) {
final width = BrikSize.of(context).size.width;
return SizedBox.fromSize(
size: BrikSize.of(context).size,
child: Container(
margin: EdgeInsets.all(1),
padding: EdgeInsets.all(2),
decoration: BoxDecoration(border: Border.all(width: 2, color: color)),
margin: EdgeInsets.all(0.05 * width),
padding: EdgeInsets.all(0.1 * width),
decoration:
BoxDecoration(border: Border.all(width: 0.10 * width, color: color)),
child: Container(
color: color,
),
Expand Down
89 changes: 52 additions & 37 deletions lib/panel/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class GameController extends StatelessWidget {
height: 200,
child: Row(
children: <Widget>[
Expanded(child: _LeftController()),
Expanded(child: _DirectionController()),
Expanded(child: LeftController()),
Expanded(child: DirectionController()),
],
),
);
Expand All @@ -27,10 +27,11 @@ const Size _SYSTEM_BUTTON_SIZE = const Size(28, 28);

const double _DIRECTION_SPACE = 10;

class _DirectionController extends StatelessWidget {
class DirectionController extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
return SizedBox.fromSize(
size: _DIRECTION_BUTTON_SIZE * 2 * 1.41,
child: Transform.rotate(
angle: math.pi / 4,
child: Column(
Expand Down Expand Up @@ -80,45 +81,59 @@ class _DirectionController extends StatelessWidget {
}
}

class _LeftController extends StatelessWidget {
class SystemButtonGroup extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_SystemButton(
color: const Color(0xFF2dc421),
label: S.of(context).sounds,
onTap: () {
Game.of(context).soundSwitch();
},
),
_SystemButton(
color: const Color(0xFF2dc421),
label: S.of(context).pause_resume,
onTap: () {
Game.of(context).pauseOrResume();
},
),
_SystemButton(
color: Colors.red,
label: S.of(context).reset,
onTap: () {
Game.of(context).reset();
})
],
_SystemButton(
color: const Color(0xFF2dc421),
label: S.of(context).sounds,
onTap: () {
Game.of(context).soundSwitch();
},
),
_SystemButton(
color: const Color(0xFF2dc421),
label: S.of(context).pause_resume,
onTap: () {
Game.of(context).pauseOrResume();
},
),
_SystemButton(
color: Colors.red,
label: S.of(context).reset,
onTap: () {
Game.of(context).reset();
})
],
);
}
}

class DropButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return _Button(
enableLongPress: false,
size: Size(90, 90),
onTap: () {
Game.of(context).drop();
});
}
}

class LeftController extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SystemButtonGroup(),
Expanded(
child: Center(
child: _Button(
enableLongPress: false,
size: Size(90, 90),
onTap: () {
Game.of(context).drop();
},
),
child: DropButton(),
),
)
],
Expand Down
57 changes: 57 additions & 0 deletions lib/panel/page_land.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
part of 'page_portrait.dart';

class PageLand extends StatelessWidget {
@override
Widget build(BuildContext context) {
var height = MediaQuery.of(context).size.height;
height -= MediaQuery.of(context).viewInsets.vertical;
return SizedBox.expand(
child: Container(
color: BACKGROUND_COLOR,
child: Padding(
padding: MediaQuery.of(context).padding,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Spacer(),
SystemButtonGroup(),
Spacer(),
Padding(
padding: const EdgeInsets.only(left: 40, bottom: 40),
child: DropButton(),
)
],
),
),
_ScreenDecoration(child: Screen.fromHeight(height * 0.8)),
Expanded(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Spacer(),
FlatButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => DonationDialog());
},
child: Text(S.of(context).reward))
],
),
Spacer(),
DirectionController(),
],
),
),
],
),
),
),
);
}
}
77 changes: 77 additions & 0 deletions lib/panel/page_portrait.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'package:flutter/material.dart';
import 'package:tetris/generated/i18n.dart';
import 'package:tetris/income/donation_dialog.dart';
import 'package:tetris/main.dart';
import 'package:tetris/panel/controller.dart';
import 'package:tetris/panel/screen.dart';

part 'page_land.dart';

class PagePortrait extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final screenW = size.width * 0.8;

return SizedBox.expand(
child: Container(
color: BACKGROUND_COLOR,
child: Padding(
padding: MediaQuery.of(context).padding,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Spacer(),
FlatButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => DonationDialog());
},
child: Text(S.of(context).reward))
],
),
Spacer(),
_ScreenDecoration(child: Screen(width: screenW)),
Spacer(flex: 2),
GameController(),
],
),
),
),
);
}
}

class _ScreenDecoration extends StatelessWidget {
final Widget child;

const _ScreenDecoration({Key key, @required this.child}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: const Color(0xFF987f0f), width: SCREEN_BORDER_WIDTH),
left: BorderSide(
color: const Color(0xFF987f0f), width: SCREEN_BORDER_WIDTH),
right: BorderSide(
color: const Color(0xFFfae36c), width: SCREEN_BORDER_WIDTH),
bottom: BorderSide(
color: const Color(0xFFfae36c), width: SCREEN_BORDER_WIDTH),
),
),
child: Container(
decoration: BoxDecoration(border: Border.all(color: Colors.black54)),
child: Container(
padding: const EdgeInsets.all(3),
color: SCREEN_BACKGROUND,
child: child,
),
),
);
}
}
1 change: 1 addition & 0 deletions lib/panel/player_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PlayerPanel extends StatelessWidget {

@override
Widget build(BuildContext context) {
debugPrint("size : $size");
return SizedBox.fromSize(
size: size,
child: Container(
Expand Down
Loading

0 comments on commit 4a8399c

Please sign in to comment.