diff --git a/src/main/java/com/wsf/mathapp/view/ResultView.java b/src/main/java/com/wsf/mathapp/view/ResultView.java index 5276044..d4af0db 100644 --- a/src/main/java/com/wsf/mathapp/view/ResultView.java +++ b/src/main/java/com/wsf/mathapp/view/ResultView.java @@ -23,7 +23,7 @@ public class ResultView { public ResultView(SceneManager sceneManager) { this.sceneManager = sceneManager; - this.currentUsername = "用户"; // 默认用户名 + this.currentUsername = sceneManager.getCurrentUserName(); createScene(); } @@ -47,62 +47,9 @@ public class ResultView { HBox userInfoBar = new HBox(10); userInfoBar.setAlignment(Pos.CENTER_LEFT); userInfoBar.setPadding(new Insets(0, 0, 20, 0)); - - // 创建默认头像(使用系统图标或文本) - ImageView avatar = createDefaultAvatar(); - - // 用户名标签 - Label usernameLabel = new Label(currentUsername); - usernameLabel.setFont(Font.font(16)); - usernameLabel.setStyle("-fx-text-fill: #333;"); - - // 添加间隔,让用户信息靠左,其他内容居中 - Region spacer = new Region(); - HBox.setHgrow(spacer, Priority.ALWAYS); - - userInfoBar.getChildren().addAll(avatar, usernameLabel, spacer); - return userInfoBar; } - private ImageView createDefaultAvatar() { - // 尝试加载默认头像图片,如果失败则使用文本头像 - ImageView avatar = new ImageView(); - avatar.setFitWidth(40); - avatar.setFitHeight(40); - - try { - // 尝试加载默认头像图片 - Image defaultAvatar = new Image( - Objects.requireNonNull(getClass().getResourceAsStream("/images/default-avatar.png"))); - avatar.setImage(defaultAvatar); - } catch (Exception e) { - // 如果图片加载失败,创建一个圆形文本头像 - avatar.setImage(createTextAvatar()); - } - - // 设置头像样式 - avatar.setStyle( - "-fx-background-color: #4CAF50; " + - "-fx-background-radius: 20; " + - "-fx-border-radius: 20; " + - "-fx-border-color: #ddd; " + - "-fx-border-width: 2;" - ); - - return avatar; - } - - private Image createTextAvatar() { - // 创建一个简单的文本头像(使用首字母) - String firstLetter = !currentUsername.isEmpty() ? - currentUsername.substring(0, 1).toUpperCase() : "U"; - - // 这里可以创建一个包含文本的图像,但为了简单起见,我们使用CSS样式 - // 在实际项目中,你可以使用Canvas绘制或预加载图片 - return null; // 返回null,我们将使用CSS样式 - } - private VBox createResultContent() { VBox resultContent = new VBox(30); resultContent.setPadding(new Insets(20)); @@ -154,29 +101,6 @@ public class ResultView { updateScoreDisplay(); } - public void setCurrentUsername(String username) { - this.currentUsername = username != null ? username : "用户"; - updateUserInfo(); - } - - private void updateUserInfo() { - if (scene != null) { - VBox mainContainer = (VBox) scene.getRoot(); - HBox userInfoBar = (HBox) mainContainer.getChildren().get(0); - - // 更新用户名标签 - Label usernameLabel = (Label) userInfoBar.getChildren().get(1); - usernameLabel.setText(currentUsername); - - // 更新头像(如果需要显示首字母) - updateAvatar(); - } - } - - private void updateAvatar() { - // 如果需要根据用户名更新头像样式,可以在这里实现 - // 例如根据用户名首字母设置不同的背景颜色 - } private void updateScoreDisplay() { if (scene != null) { @@ -208,4 +132,5 @@ public class ResultView { public Scene getScene() { return scene; } + } \ No newline at end of file