Merge pull request '修复LevelSelectionView文件' (#14) from ybw_branch into develop

develop
ppy4sjqvf 4 months ago
commit d55ede49b2

@ -16,6 +16,10 @@ import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
/**
* .
* .
*/
public class LevelSelectionView {
private Scene scene;
private final SceneManager sceneManager;
@ -25,12 +29,20 @@ public class LevelSelectionView {
private Label usernameLabel;
private Text avatarText;
/**
* .
*
* @param sceneManager .
*/
public LevelSelectionView(SceneManager sceneManager) {
this.sceneManager = sceneManager;
this.currentUsername = sceneManager.getCurrentUserName();
createScene();
}
/**
* .
*/
private void createScene() {
// 创建主容器
VBox mainContainer = new VBox();
@ -47,31 +59,45 @@ public class LevelSelectionView {
scene = new Scene(mainContainer, 450, 550);
}
/**
* .
*
* @return HBox .
*/
private HBox createUserInfoBar() {
HBox userInfoBar = new HBox(15);
userInfoBar.setAlignment(Pos.CENTER_LEFT);
userInfoBar.setPadding(new Insets(0, 0, 30, 0));
userInfoBar.setStyle("-fx-border-color: #e0e0e0; -fx-border-width: 0 0 1 0; -fx-padding: 0 0 15 0;");
userInfoBar.setStyle("-fx-border-color: #e0e0e0; "
+ "-fx-border-width: 0 0 1 0; -fx-padding: 0 0 15 0;");
// 用户名标签
usernameLabel = new Label(currentUsername != null ? currentUsername : "用户");
usernameLabel.setFont(Font.font("Arial", FontWeight.BOLD, 16));
usernameLabel.setStyle("-fx-text-fill: #2c3e50;");
// 间隔
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
// 创建头像容器
VBox avatarContainer = createAvatarContainer();
userInfoBar.getChildren().addAll(avatarContainer, usernameLabel, spacer);
return userInfoBar;
}
// 创建圆形头像容器
/**
* .
*
* @return VBox .
*/
private VBox createAvatarContainer() {
VBox avatarContainer = new VBox();
avatarContainer.setAlignment(Pos.CENTER);
avatarContainer.setPrefSize(50, 50);
// 创建圆形头像背景
Circle avatarCircle = new Circle(22);
avatarCircle.setFill(Color.web("#4CAF50")); // 统一的绿色背景
avatarCircle.setStroke(Color.WHITE);
avatarCircle.setStrokeWidth(2);
// 添加阴影效果
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
// 添加首字母文本
avatarText = new Text(getFirstLetter());
avatarText.setFill(Color.WHITE);
avatarText.setFont(Font.font("Arial", FontWeight.BOLD, 16));
// 创建圆形头像背景
Circle avatarCircle = createAvatarCircle();
// 使用StackPane将文本放在圆形中心
javafx.scene.layout.StackPane avatarStack = new javafx.scene.layout.StackPane();
avatarStack.getChildren().addAll(avatarCircle, avatarText);
@ -79,101 +105,190 @@ public class LevelSelectionView {
avatarStack.setAlignment(Pos.CENTER);
avatarContainer.getChildren().add(avatarStack);
return avatarContainer;
}
// 用户名标签
usernameLabel = new Label(currentUsername != null ? currentUsername : "用户");
usernameLabel.setFont(Font.font("Arial", FontWeight.BOLD, 16));
usernameLabel.setStyle("-fx-text-fill: #2c3e50;");
// 间隔
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
userInfoBar.getChildren().addAll(avatarContainer, usernameLabel, spacer);
/**
* .
*
* @return Circle .
*/
private Circle createAvatarCircle() {
Circle avatarCircle = new Circle(22);
avatarCircle.setFill(Color.web("#4CAF50")); // 统一的绿色背景
avatarCircle.setStroke(Color.WHITE);
avatarCircle.setStrokeWidth(2);
return userInfoBar;
// 添加阴影效果
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
return avatarCircle;
}
/**
* .
*
* @return VBox .
*/
private VBox createSelectionContent() {
VBox selectionContent = new VBox(25);
selectionContent.setPadding(new Insets(30, 20, 20, 20));
selectionContent.setAlignment(Pos.CENTER);
// 创建标题区域
VBox titleSection = createTitleSection();
// 创建级别按钮区域
VBox levelButtonsSection = createLevelButtonsSection();
// 创建返回按钮
Button backButton = createBackButton();
selectionContent.getChildren().addAll(titleSection, levelButtonsSection, backButton);
return selectionContent;
}
/**
* .
*
* @return VBox .
*/
private VBox createTitleSection() {
VBox titleSection = new VBox(5);
titleSection.setAlignment(Pos.CENTER);
Label titleLabel = new Label("选择题目级别");
titleLabel.setFont(Font.font("Arial", FontWeight.BOLD, 26));
titleLabel.setStyle("-fx-text-fill: #2c3e50;");
// 添加副标题
Label subtitleLabel = new Label("请选择适合您的学习级别");
subtitleLabel.setFont(Font.font("Arial", 14));
subtitleLabel.setStyle("-fx-text-fill: #7f8c8d; -fx-padding: 0 0 10 0;");
titleSection.getChildren().addAll(titleLabel, subtitleLabel);
return titleSection;
}
/**
* .
*
* @return VBox .
*/
private VBox createLevelButtonsSection() {
VBox levelButtonsSection = new VBox(15);
levelButtonsSection.setAlignment(Pos.CENTER);
Button primaryButton = createLevelButton("小学题目", "#4CAF50", "#45a049");
Button juniorButton = createLevelButton("初中题目", "#2196F3", "#1976D2");
Button seniorButton = createLevelButton("高中题目", "#9C27B0", "#7B1FA2");
Button backButton = new Button("返回主菜单");
backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;");
backButton.setPrefSize(180, 45);
backButton.setOnMouseEntered(e -> backButton.setStyle("-fx-background-color: #7f8c8d; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;"));
backButton.setOnMouseExited(e -> backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;"));
setupLevelButtonAction(primaryButton, "小学");
setupLevelButtonAction(juniorButton, "初中");
setupLevelButtonAction(seniorButton, "高中");
primaryButton.setOnAction(e -> {
String selectedLevel = "小学";
sceneManager.getQuestionCountView().setLevel(selectedLevel);
sceneManager.showQuestionCountView();
});
juniorButton.setOnAction(e -> {
String selectedLevel = "初中";
sceneManager.getQuestionCountView().setLevel(selectedLevel);
sceneManager.showQuestionCountView();
});
levelButtonsSection.getChildren().addAll(primaryButton, juniorButton, seniorButton);
return levelButtonsSection;
}
seniorButton.setOnAction(e -> {
String selectedLevel = "高中";
sceneManager.getQuestionCountView().setLevel(selectedLevel);
/**
* .
*
* @param button .
* @param level .
*/
private void setupLevelButtonAction(Button button, String level) {
button.setOnAction(e -> {
sceneManager.getQuestionCountView().setLevel(level);
sceneManager.showQuestionCountView();
});
}
backButton.setOnAction(e -> {
sceneManager.showMainMenuView();
});
selectionContent.getChildren().addAll(
titleLabel, subtitleLabel, primaryButton, juniorButton, seniorButton, backButton
);
/**
* .
*
* @return Button .
*/
private Button createBackButton() {
Button backButton = new Button("返回主菜单");
backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: "
+ "white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;");
backButton.setPrefSize(180, 45);
setupButtonHoverEffect(backButton, "#95a5a6", "#7f8c8d");
backButton.setOnAction(e -> sceneManager.showMainMenuView());
return selectionContent;
return backButton;
}
/**
* .
*
* @param text .
* @param color .
* @param hoverColor .
* @return Button .
*/
private Button createLevelButton(String text, String color, String hoverColor) {
Button button = new Button(text);
button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
"-fx-background-color: %s; -fx-text-fill: "
+ "white; -fx-font-size: 16px; -fx-font-weight: bold;-fx-background-radius: 12;"
+ "-fx-padding: 12 30;-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
color
));
button.setPrefSize(220, 60);
button.setOnMouseEntered(e -> button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);",
hoverColor
)));
button.setOnMouseExited(e -> button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
color
)));
setupButtonHoverEffect(button, color, hoverColor);
return button;
}
/**
* .
*
* @param button .
* @param normalColor .
* @param hoverColor .
*/
private void setupButtonHoverEffect(Button button, String normalColor, String hoverColor) {
String normalStyle = String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: %s;"
+ " -fx-background-radius: %s; -fx-padding: %s; -fx-effect: "
+ "dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
normalColor,
button.getStyle().contains("16px") ? "16px" : "14px",
button.getStyle().contains("12") ? "12" : "8",
button.getStyle().contains("12 30") ? "12 30" : "8 20"
);
String hoverStyle = String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: %s;"
+ " -fx-background-radius: %s; -fx-padding: %s; -fx-effect:"
+ " dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);",
hoverColor,
button.getStyle().contains("16px") ? "16px" : "14px",
button.getStyle().contains("12") ? "12" : "8",
button.getStyle().contains("12 30") ? "12 30" : "8 20"
);
button.setOnMouseEntered(e -> button.setStyle(hoverStyle));
button.setOnMouseExited(e -> button.setStyle(normalStyle));
}
/**
* .
*
* @return String "U".
*/
private String getFirstLetter() {
return currentUsername != null && !currentUsername.isEmpty() ?
currentUsername.substring(0, 1).toUpperCase() : "U";
return currentUsername != null && !currentUsername.isEmpty()
? currentUsername.substring(0, 1).toUpperCase() : "U";
}
// 添加更新用户名的方法
/**
* .
*
* @param username .
*/
public void updateUsername(String username) {
this.currentUsername = username;
if (usernameLabel != null) {
@ -184,6 +299,11 @@ public class LevelSelectionView {
}
}
/**
* .
*
* @return Scene .
*/
public Scene getScene() {
return scene;
}

Loading…
Cancel
Save