mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 11:24:46 +08:00
[Party Room] 房间类型相关
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
||||
|
||||
import 'party_room_home_ui_model.dart';
|
||||
|
||||
@ -11,8 +12,113 @@ class PartyRoomHomeUI extends BaseUI<PartyRoomHomeUIModel> {
|
||||
child: Text("${model.pingServerMessage}"),
|
||||
);
|
||||
}
|
||||
return Center(
|
||||
child: Text("PartyRoom"),
|
||||
if (model.roomTypes == null) return makeLoading(context);
|
||||
return Column(
|
||||
children: [
|
||||
makeHeader(context, model),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget makeHeader(BuildContext context, PartyRoomHomeUIModel model) {
|
||||
final subTypes = model.getCurRoomSubTypes();
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 24, right: 24, top: 16, bottom: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text("房间类型:"),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: ComboBox<RoomType>(
|
||||
value: model.selectedRoomType,
|
||||
items: [
|
||||
for (final t in model.roomTypes!.entries)
|
||||
ComboBoxItem(
|
||||
value: t.value,
|
||||
child: Text(t.value.name),
|
||||
)
|
||||
],
|
||||
onChanged: model.onChangeRoomType)),
|
||||
if (subTypes != null) ...[
|
||||
const SizedBox(width: 24),
|
||||
const Text("子类型:"),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: ComboBox<RoomSubtype>(
|
||||
value: model.selectedRoomSubType,
|
||||
items: [
|
||||
for (final t in subTypes.entries)
|
||||
ComboBoxItem(
|
||||
value: t.value,
|
||||
child: Text(t.value.name),
|
||||
)
|
||||
],
|
||||
onChanged: model.onChangeRoomSubType)),
|
||||
],
|
||||
const SizedBox(width: 24),
|
||||
const Text("房间状态:"),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: ComboBox<RoomStatus>(
|
||||
value: model.selectedStatus,
|
||||
items: [
|
||||
for (final t in model.roomStatus.entries)
|
||||
ComboBoxItem(
|
||||
value: t.key,
|
||||
child: Text(t.value),
|
||||
)
|
||||
],
|
||||
onChanged: model.onChangeRoomStatus)),
|
||||
const SizedBox(width: 24),
|
||||
const Text("排序:"),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: ComboBox<RoomSortType>(
|
||||
value: model.selectedSortType,
|
||||
items: [
|
||||
for (final t in model.roomSorts.entries)
|
||||
ComboBoxItem(
|
||||
value: t.key,
|
||||
child: Text(t.value),
|
||||
)
|
||||
],
|
||||
onChanged: model.onChangeRoomSort)),
|
||||
const Spacer(),
|
||||
Button(
|
||||
onPressed: () {},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(6),
|
||||
child: Icon(FluentIcons.refresh),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Button(
|
||||
onPressed: () {},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(3),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(FluentIcons.add),
|
||||
SizedBox(width: 6),
|
||||
Text("创建房间")
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 6,
|
||||
),
|
||||
Text(
|
||||
model.selectedRoomType?.desc ?? "",
|
||||
style: TextStyle(fontSize: 13, color: Colors.white.withOpacity(.4)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,37 @@
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
||||
import 'package:starcitizen_doctor/grpc/party_room_server.dart';
|
||||
|
||||
class PartyRoomHomeUIModel extends BaseUIModel {
|
||||
String? pingServerMessage;
|
||||
|
||||
Map<String?, RoomType>? roomTypes;
|
||||
|
||||
RoomType? selectedRoomType;
|
||||
|
||||
RoomSubtype? selectedRoomSubType;
|
||||
|
||||
final roomStatus = <RoomStatus, String>{
|
||||
RoomStatus.All: "全部",
|
||||
RoomStatus.Open: "开启中",
|
||||
RoomStatus.Full: "已满员",
|
||||
RoomStatus.Closed: "已封闭",
|
||||
RoomStatus.WillOffline: "房主离线",
|
||||
RoomStatus.Offline: "已离线",
|
||||
};
|
||||
|
||||
RoomStatus selectedStatus = RoomStatus.All;
|
||||
|
||||
final roomSorts = <RoomSortType, String>{
|
||||
RoomSortType.Default: "默认",
|
||||
RoomSortType.MostPlayerNumber: "最多玩家",
|
||||
RoomSortType.MinimumPlayerNumber: "最少玩家",
|
||||
RoomSortType.RecentlyCreated: "最近创建",
|
||||
RoomSortType.OldestCreated: "最久创建",
|
||||
};
|
||||
|
||||
RoomSortType selectedSortType = RoomSortType.Default;
|
||||
|
||||
@override
|
||||
Future loadData() async {
|
||||
if (pingServerMessage != "") {
|
||||
@ -11,6 +39,7 @@ class PartyRoomHomeUIModel extends BaseUIModel {
|
||||
notifyListeners();
|
||||
}
|
||||
await _pingServer();
|
||||
await _loadTypes();
|
||||
}
|
||||
|
||||
_pingServer() async {
|
||||
@ -26,4 +55,53 @@ class PartyRoomHomeUIModel extends BaseUIModel {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_loadTypes() async {
|
||||
final r = await handleError(() => PartyRoomGrpcServer.getRoomTypes());
|
||||
if (r == null) return;
|
||||
selectedRoomType =
|
||||
RoomType(id: null, name: "全部", desc: "查看所有类型的房间,寻找一起玩的伙伴。");
|
||||
selectedRoomSubType = RoomSubtype(id: "all", name: "全部");
|
||||
roomTypes = {null: selectedRoomType!};
|
||||
for (var element in r.roomTypes) {
|
||||
roomTypes![element.id] = element;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<String, RoomSubtype>? getCurRoomSubTypes() {
|
||||
if (selectedRoomType?.subTypes == null) return null;
|
||||
Map<String, RoomSubtype> types = {};
|
||||
for (var element in selectedRoomType!.subTypes) {
|
||||
types[element.id] = element;
|
||||
}
|
||||
if (types.isEmpty) return null;
|
||||
final allSubType = RoomSubtype(id: "all", name: "全部");
|
||||
selectedRoomSubType ??= allSubType;
|
||||
return {"all": allSubType}..addAll(types);
|
||||
}
|
||||
|
||||
void onChangeRoomType(RoomType? value) {
|
||||
selectedRoomType = value;
|
||||
selectedRoomSubType = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void onChangeRoomStatus(RoomStatus? value) {
|
||||
if (value == null) return;
|
||||
selectedStatus = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void onChangeRoomSort(RoomSortType? value) {
|
||||
if (value == null) return;
|
||||
selectedSortType = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void onChangeRoomSubType(RoomSubtype? value) {
|
||||
if (value == null) return;
|
||||
selectedRoomSubType = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user