diff --git a/assets/db/materials.json b/assets/db/materials.json index 8d4eee3bd..d7cd6e812 100644 --- a/assets/db/materials.json +++ b/assets/db/materials.json @@ -8,7 +8,8 @@ "type": "talents", "days": [ 1, - 4 + 4, + 7 ] }, { @@ -19,7 +20,8 @@ "type": "talents", "days": [ 1, - 4 + 4, + 7 ] }, { @@ -30,7 +32,8 @@ "type": "talents", "days": [ 2, - 5 + 5, + 7 ] }, { @@ -41,7 +44,8 @@ "type": "talents", "days": [ 2, - 5 + 5, + 7 ] }, { @@ -52,7 +56,8 @@ "type": "talents", "days": [ 3, - 6 + 6, + 7 ] }, { @@ -63,7 +68,8 @@ "type": "talents", "days": [ 3, - 6 + 6, + 7 ] }, { @@ -148,7 +154,8 @@ "type": "weaponPrimary", "days": [ 1, - 4 + 4, + 7 ] }, { @@ -159,7 +166,8 @@ "type": "weaponPrimary", "days": [ 1, - 4 + 4, + 7 ] }, { @@ -170,7 +178,8 @@ "type": "weaponPrimary", "days": [ 2, - 5 + 5, + 7 ] }, { @@ -181,7 +190,8 @@ "type": "weaponPrimary", "days": [ 2, - 5 + 5, + 7 ] }, { @@ -192,7 +202,8 @@ "type": "weaponPrimary", "days": [ 3, - 6 + 6, + 7 ] }, { @@ -203,7 +214,8 @@ "type": "weaponPrimary", "days": [ 3, - 6 + 6, + 7 ] } ] diff --git a/lib/bloc/weapon/weapon_bloc.dart b/lib/bloc/weapon/weapon_bloc.dart index dc76c6036..c8790d724 100644 --- a/lib/bloc/weapon/weapon_bloc.dart +++ b/lib/bloc/weapon/weapon_bloc.dart @@ -23,34 +23,43 @@ class WeaponBloc extends Bloc { ) async* { yield const WeaponState.loading(); final s = event.when( - loadWeapon: (name) { + loadFromImg: (img) { + final weapon = _genshinService.getWeaponByImg(img); + final translation = _genshinService.getWeaponTranslation(weapon.name); + return _buildInitialState(weapon, translation); + }, + loadFromName: (name) { final weapon = _genshinService.getWeapon(name); final translation = _genshinService.getWeaponTranslation(name); - return WeaponState.loaded( - name: weapon.name, - weaponType: weapon.type, - fullImage: weapon.fullImagePath, - rarity: weapon.rarity, - atk: weapon.atk, - secondaryStat: weapon.secondaryStat, - secondaryStatValue: weapon.secondaryStatValue, - description: translation.description, - locationType: weapon.location, - ascentionMaterials: weapon.ascentionMaterials, - refinements: weapon.refinements.map( - (e) { - var description = translation.refinement; - for (var i = 0; i < e.values.length; i++) { - description = description.replaceFirst('{{$i}}', '${e.values[i]}'); - } - - return WeaponFileRefinementModel(level: e.level, description: description); - }, - ).toList(), - ); + return _buildInitialState(weapon, translation); }, ); yield s; } + + WeaponState _buildInitialState(WeaponFileModel weapon, TranslationWeaponFile translation) { + return WeaponState.loaded( + name: weapon.name, + weaponType: weapon.type, + fullImage: weapon.fullImagePath, + rarity: weapon.rarity, + atk: weapon.atk, + secondaryStat: weapon.secondaryStat, + secondaryStatValue: weapon.secondaryStatValue, + description: translation.description, + locationType: weapon.location, + ascentionMaterials: weapon.ascentionMaterials, + refinements: weapon.refinements.map( + (e) { + var description = translation.refinement; + for (var i = 0; i < e.values.length; i++) { + description = description.replaceFirst('{{$i}}', '${e.values[i]}'); + } + + return WeaponFileRefinementModel(level: e.level, description: description); + }, + ).toList(), + ); + } } diff --git a/lib/bloc/weapon/weapon_event.dart b/lib/bloc/weapon/weapon_event.dart index 9f41d89d7..973ed46f8 100644 --- a/lib/bloc/weapon/weapon_event.dart +++ b/lib/bloc/weapon/weapon_event.dart @@ -2,7 +2,11 @@ part of 'weapon_bloc.dart'; @freezed abstract class WeaponEvent with _$WeaponEvent { - const factory WeaponEvent.loadWeapon({ + const factory WeaponEvent.loadFromName({ @required String name, - }) = _LoadWeapon; + }) = _LoadWeaponFromName; + + const factory WeaponEvent.loadFromImg({ + @required String image, + }) = _LoadWeaponFromImg; } diff --git a/lib/models/home/today_weapon_ascention_material_model.dart b/lib/models/home/today_weapon_ascention_material_model.dart index 7c7d1084e..b0576668c 100644 --- a/lib/models/home/today_weapon_ascention_material_model.dart +++ b/lib/models/home/today_weapon_ascention_material_model.dart @@ -4,10 +4,11 @@ class TodayWeaponAscentionMaterialModel { final String name; final String image; final List days; - + final List weapons; TodayWeaponAscentionMaterialModel({ @required this.name, @required this.image, @required this.days, + @required this.weapons, }); } diff --git a/lib/services/genshing_service.dart b/lib/services/genshing_service.dart index c359cab89..df3c2bf53 100644 --- a/lib/services/genshing_service.dart +++ b/lib/services/genshing_service.dart @@ -23,6 +23,7 @@ abstract class GenshinService { List getWeaponsForCard(); WeaponCardModel getWeaponForCardByImg(String image); WeaponFileModel getWeapon(String name); + WeaponFileModel getWeaponByImg(String img); List getArtifactsForCard(); ArtifactCardModel getArtifactForCardByImg(String image); @@ -195,6 +196,11 @@ class GenshinServiceImpl implements GenshinService { return _weaponsFile.weapons.firstWhere((element) => element.name == name); } + @override + WeaponFileModel getWeaponByImg(String img) { + return _weaponsFile.weapons.firstWhere((element) => Assets.getWeaponPath(element.image, element.type) == img); + } + @override TranslationWeaponFile getWeaponTranslation(String name) { return _translationFile.weapons.firstWhere((element) => element.key == name); @@ -280,13 +286,23 @@ class GenshinServiceImpl implements GenshinService { final iterable = day == DateTime.sunday ? _materialsFile.weaponPrimary : _materialsFile.weaponPrimary.where((t) => t.days.contains(day)); + return iterable.map((e) { final translation = _translationFile.materials.firstWhere((t) => t.key == e.name); + final weapons = []; + for (final weapon in _weaponsFile.weapons) { + final materialIsBeingUsed = + weapon.ascentionMaterials.expand((m) => m.materials).where((m) => m.image == e.image).isNotEmpty; + if (materialIsBeingUsed) { + weapons.add(weapon.fullImagePath); + } + } return TodayWeaponAscentionMaterialModel( days: e.days, name: translation.name, image: Assets.getMaterialPath(e.image, e.type), + weapons: weapons, ); }).toList(); } diff --git a/lib/ui/pages/map_page.dart b/lib/ui/pages/map_page.dart index 80d852697..363dc9bcc 100644 --- a/lib/ui/pages/map_page.dart +++ b/lib/ui/pages/map_page.dart @@ -16,21 +16,29 @@ class _MapPageState extends State { final flutterWebviewPlugin = FlutterWebviewPlugin(); final String script = ''' - let elements = document.getElementsByClassName("nav-link"); - let total = elements.length; - for (let index = 0; index < total; index++) { - const element = elements[index]; - const text = element.childNodes[0].textContent; - if (text !== "Markers") { - element.remove(); - total--; - index--; + setTimeout(function(){ + let elements = document.getElementsByClassName("nav-link"); + let total = elements.length; + for (let index = 0; index < total; index++) { + const element = elements[index]; + const text = element.childNodes[0].textContent; + if (text !== "Markers") { + element.remove(); + total--; + index--; + } + + if (total === 1) + break; } - if (total === 1) - break; - } - document.getElementsByClassName("fixed-bottom")[0].remove(); + total = document.getElementsByClassName("fixed-bottom").length; + for (let index = 0; index < total; index++) { + if (document.getElementsByClassName("fixed-bottom").length > 0) + document.getElementsByClassName("fixed-bottom")[0].remove(); + } + }, + 800); '''; @override diff --git a/lib/ui/pages/materials_page.dart b/lib/ui/pages/materials_page.dart index 6b4b331c2..95accc3df 100644 --- a/lib/ui/pages/materials_page.dart +++ b/lib/ui/pages/materials_page.dart @@ -8,19 +8,9 @@ import '../widgets/common/loading.dart'; import '../widgets/materials/sliver_character_ascention_materials.dart'; import '../widgets/materials/sliver_weapon_ascention_materials.dart'; -class MaterialsPage extends StatefulWidget { - @override - _MaterialsPageState createState() => _MaterialsPageState(); -} - -class _MaterialsPageState extends State with AutomaticKeepAliveClientMixin { - @override - bool get wantKeepAlive => true; - +class MaterialsPage extends StatelessWidget { @override Widget build(BuildContext context) { - super.build(context); - final theme = Theme.of(context); final s = S.of(context); return BlocBuilder( diff --git a/lib/ui/widgets/common/item_description_detail.dart b/lib/ui/widgets/common/item_description_detail.dart index 1a9a2c0cf..32cef1208 100644 --- a/lib/ui/widgets/common/item_description_detail.dart +++ b/lib/ui/widgets/common/item_description_detail.dart @@ -30,10 +30,18 @@ class ItemDescriptionDetail extends StatelessWidget { offset: Styles.listItemWithIconOffset, child: Tooltip( message: title, - child: Text( - title, - style: theme.textTheme.headline5.copyWith(color: textColor, fontWeight: FontWeight.bold), - overflow: TextOverflow.ellipsis, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + title, + style: theme.textTheme.headline5.copyWith(color: textColor, fontWeight: FontWeight.bold), + overflow: TextOverflow.ellipsis, + ), + Divider(color: textColor, thickness: 2), + ], ), ), ), diff --git a/lib/ui/widgets/home/char_card_ascention_material.dart b/lib/ui/widgets/home/char_card_ascention_material.dart index 2c27aee8c..0fe74c324 100644 --- a/lib/ui/widgets/home/char_card_ascention_material.dart +++ b/lib/ui/widgets/home/char_card_ascention_material.dart @@ -82,7 +82,6 @@ class CharCardAscentionMaterial extends StatelessWidget { child: Text( obtainOn, textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, style: theme.textTheme.subtitle2.copyWith(fontSize: 12), ), ), diff --git a/lib/ui/widgets/home/weapon_card_ascention_material.dart b/lib/ui/widgets/home/weapon_card_ascention_material.dart index 4b809612f..e80fef5d7 100644 --- a/lib/ui/widgets/home/weapon_card_ascention_material.dart +++ b/lib/ui/widgets/home/weapon_card_ascention_material.dart @@ -1,19 +1,24 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../bloc/bloc.dart'; import '../../../common/extensions/i18n_extensions.dart'; import '../../../common/styles.dart'; import '../../../generated/l10n.dart'; +import '../../pages/weapon_page.dart'; class WeaponCardAscentionMaterial extends StatelessWidget { final String name; final String image; final List days; + final List weapons; const WeaponCardAscentionMaterial({ Key key, @required this.name, @required this.image, @required this.days, + @required this.weapons, }) : super(key: key); @override @@ -21,13 +26,13 @@ class WeaponCardAscentionMaterial extends StatelessWidget { final s = S.of(context); final theme = Theme.of(context); final obtainOn = s.translateDays(days); + return Card( margin: Styles.edgeInsetAll10, shape: Styles.cardShape, child: Container( padding: Styles.edgeInsetAll5, child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset(image, width: 120, height: 100), @@ -45,13 +50,39 @@ class WeaponCardAscentionMaterial extends StatelessWidget { child: Text( obtainOn, textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, + overflow: TextOverflow.visible, style: theme.textTheme.subtitle2.copyWith(fontSize: 12), ), ), + SizedBox( + height: 70, + child: ListView.builder( + shrinkWrap: true, + itemCount: weapons.length, + physics: const BouncingScrollPhysics(), + scrollDirection: Axis.horizontal, + itemBuilder: (ctx, index) => Container( + margin: const EdgeInsets.all(3), + child: InkWell( + onTap: () => _gotoWeaponPage(weapons[index], context), + child: CircleAvatar( + radius: 30, + backgroundColor: Colors.transparent, + backgroundImage: AssetImage(weapons[index]), + ), + ), + ), + ), + ), ], ), ), ); } + + Future _gotoWeaponPage(String image, BuildContext context) async { + context.read().add(WeaponEvent.loadFromImg(image: image)); + final route = MaterialPageRoute(builder: (c) => WeaponPage()); + await Navigator.push(context, route); + } } diff --git a/lib/ui/widgets/materials/sliver_weapon_ascention_materials.dart b/lib/ui/widgets/materials/sliver_weapon_ascention_materials.dart index 3b0357b4d..94376e49c 100644 --- a/lib/ui/widgets/materials/sliver_weapon_ascention_materials.dart +++ b/lib/ui/widgets/materials/sliver_weapon_ascention_materials.dart @@ -13,24 +13,78 @@ class SliverWeaponAscentionMaterials extends StatelessWidget { @override Widget build(BuildContext context) { - final isPortrait = MediaQuery.of(context).orientation == Orientation.portrait; - return SliverGrid.count( - // childAspectRatio: 1.15, - crossAxisCount: isPortrait ? 2 : 4, - children: weaponAscMaterials - .map((item) => WeaponCardAscentionMaterial(name: item.name, image: item.image, days: item.days)) - .toList(), + final widgets = []; + + for (var i = 0; i < weaponAscMaterials.length; i++) { + final item = weaponAscMaterials[i]; + final nextIndex = i + 1; + final first = WeaponCardAscentionMaterial( + name: item.name, + image: item.image, + days: item.days, + weapons: item.weapons, + ); + if (nextIndex <= weaponAscMaterials.length - 1) { + final item2 = weaponAscMaterials[nextIndex]; + final second = WeaponCardAscentionMaterial( + name: item2.name, + image: item2.image, + days: item2.days, + weapons: item2.weapons, + ); + widgets.add(_buildRow(first, second)); + + i++; + continue; + } + + widgets.add(_buildRow(first, Container())); + } + return SliverList( + delegate: SliverChildListDelegate(widgets), ); + // final isPortrait = MediaQuery.of(context).orientation == Orientation.portrait; + // return SliverGrid.count( + // // childAspectRatio: 0.5, + // // crossAxisCount: isPortrait ? 2 : 4, + // crossAxisCount: 1, + // children: weaponAscMaterials + // .map((item) => Container( + // constraints: BoxConstraints(minHeight: 250), + // child: WeaponCardAscentionMaterial( + // name: item.name, + // image: item.image, + // days: item.days, + // weapons: item.weapons, + // ), + // )) + // .toList(), + // ); + //TODO: COMMENTED UNTIL https://github.com/letsar/flutter_staggered_grid_view/issues/145 // return SliverStaggeredGrid.countBuilder( // crossAxisCount: 2, // itemBuilder: (ctx, index) { // final item = weaponAscMaterials[index]; - // return WeaponCardAscentionMaterial(name: item.name, image: item.image, days: item.days); + // return WeaponCardAscentionMaterial( + // name: item.name, + // image: item.image, + // days: item.days, + // weapons: item.weapons, + // ); // }, // itemCount: weaponAscMaterials.length, // staggeredTileBuilder: (int index) => const StaggeredTile.fit(1), // ); } + + Widget _buildRow(Widget first, Widget second) { + return Row( + children: [ + Expanded(child: first), + Expanded(child: second), + ], + ); + } } diff --git a/lib/ui/widgets/weapons/weapon_card.dart b/lib/ui/widgets/weapons/weapon_card.dart index 74a67fe11..e886810e2 100644 --- a/lib/ui/widgets/weapons/weapon_card.dart +++ b/lib/ui/widgets/weapons/weapon_card.dart @@ -126,7 +126,7 @@ class WeaponCard extends StatelessWidget { } Future _gotoWeaponPage(BuildContext context) async { - context.read().add(WeaponEvent.loadWeapon(name: name)); + context.read().add(WeaponEvent.loadFromName(name: name)); final route = MaterialPageRoute(builder: (c) => WeaponPage()); await Navigator.push(context, route); }