Skip to content
Snippets Groups Projects
Select Git revision
  • 36b40403bfd67e55fb8555b04e1e37f120c0b104
  • master default protected
  • 61-upgrade-framework-and-dependencies
  • 42-improve-app-metadata
  • 17-improve-and-complete-offline-words-list-and-tips
  • 6-allow-translate-application
  • 9-improve-documentation
  • Release_1.10.0_44 protected
  • Release_1.9.2_43 protected
  • Release_1.9.1_42 protected
  • Release_1.9.0_41 protected
  • Release_1.8.0_40 protected
  • Release_1.7.0_39 protected
  • Release_1.6.0_38 protected
  • Release_1.5.2_37 protected
  • Release_1.5.1_36 protected
  • Release_1.5.0_35 protected
  • Release_1.4.1_34 protected
  • Release_1.4.0_33 protected
  • Release_1.3.2_32 protected
  • Release_1.3.1_31 protected
  • Release_1.3.0_30 protected
  • Release_1.2.18_29 protected
  • Release_1.2.17_28 protected
  • Release_1.2.16_27 protected
  • Release_1.2.15_26 protected
  • Release_1.2.14_25 protected
27 results

game.dart

Blame
  • parameters.dart 4.52 KiB
    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    
    import 'package:jeweled/config/default_game_settings.dart';
    import 'package:jeweled/cubit/game_cubit.dart';
    import 'package:jeweled/cubit/settings_cubit.dart';
    import 'package:jeweled/models/game_settings.dart';
    
    class Parameters extends StatelessWidget {
      const Parameters({super.key});
    
      static const double separatorHeight = 2.0;
      static const double blockMargin = 3.0;
      static const double blockPadding = 2.0;
      static const Color buttonBackgroundColor = Colors.white;
      static const Color buttonBorderColorActive = Colors.blue;
      static const Color buttonBorderColorInactive = Colors.white;
      static const double buttonBorderWidth = 10.0;
      static const double buttonBorderRadius = 8.0;
      static const double buttonPadding = 0.0;
      static const double buttonMargin = 0.0;
    
      @override
      Widget build(BuildContext context) {
        return BlocBuilder<SettingsCubit, SettingsState>(
          builder: (BuildContext context, SettingsState settingsState) {
            final GameCubit gameCubit = BlocProvider.of<GameCubit>(context);
            final SettingsCubit settingsCubit = BlocProvider.of<SettingsCubit>(context);
    
            final List<Widget> lines = [];
    
            DefaultGameSettings.availableParameters.forEach((code) {
              final List<dynamic> availableValues = DefaultGameSettings.getAvailableValues(code);
    
              if (availableValues.length > 1) {
                final List<Widget> parameterButtons = [];
    
                final dynamic currentValue = settingsCubit.getParameterValue(code);
    
                availableValues.forEach((value) {
                  final bool isActive = (value == currentValue);
                  final String imageAsset = code + '_' + value.toString();
    
                  final Widget parameterButton = TextButton(
                    child: Container(
                      margin: EdgeInsets.all(buttonMargin),
                      padding: EdgeInsets.all(buttonPadding),
                      decoration: BoxDecoration(
                        color: buttonBackgroundColor,
                        borderRadius: BorderRadius.circular(buttonBorderRadius),
                        border: Border.all(
                          color: isActive ? buttonBorderColorActive : buttonBorderColorInactive,
                          width: buttonBorderWidth,
                        ),
                      ),
                      child: buildImageWidget(imageAsset),
                    ),
                    onPressed: () => settingsCubit.setParameterValue(code, value),
                  );
    
                  parameterButtons.add(parameterButton);
                });
    
                lines.add(Table(
                  defaultColumnWidth: IntrinsicColumnWidth(),
                  children: [
                    TableRow(
                      children: parameterButtons,
                    ),
                  ],
                ));
    
                lines.add(SizedBox(height: separatorHeight));
              }
            });
    
            return Container(
              child: Column(
                children: [
                  SizedBox(height: separatorHeight),
                  Column(
                    children: lines,
                  ),
                  SizedBox(height: separatorHeight),
                  buildStartNewGameButton(gameCubit, settingsState.settings),
                ],
              ),
            );
          },
        );
      }
    
      static Image buildImageWidget(String imageAssetCode) {
        return Image(
          image: AssetImage('assets/icons/' + imageAssetCode + '.png'),
          fit: BoxFit.fill,
        );
      }
    
      static Container buildImageContainerWidget(String imageAssetCode) {
        return Container(
          child: buildImageWidget(imageAssetCode),
        );
      }
    
      static Column buildDecorationImageWidget() {
        return Column(
          children: [
            TextButton(
              child: buildImageContainerWidget('placeholder'),
              onPressed: () => null,
            ),
          ],
        );
      }
    
      static Container buildStartNewGameButton(GameCubit gameCubit, GameSettings settings) {
        return Container(
          margin: EdgeInsets.all(blockMargin),
          padding: EdgeInsets.all(blockPadding),
          child: Table(
            defaultColumnWidth: IntrinsicColumnWidth(),
            children: [
              TableRow(
                children: [
                  buildDecorationImageWidget(),
                  Column(
                    children: [
                      TextButton(
                        child: buildImageContainerWidget('button_start'),
                        onPressed: () => gameCubit.startNewGame(settings),
                      ),
                    ],
                  ),
                  buildDecorationImageWidget(),
                ],
              ),
            ],
          ),
        );
      }
    }