Maxwan commited on
Commit
83f487c
·
1 Parent(s): d890315

empathy visible

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. flet_app.py +37 -21
.gitignore CHANGED
@@ -1,4 +1,5 @@
1
  .venv
 
2
  playground/
3
  uploaded_files/
4
  __pycache__/
 
1
  .venv
2
+ venv/
3
  playground/
4
  uploaded_files/
5
  __pycache__/
flet_app.py CHANGED
@@ -28,7 +28,6 @@ class ChessModel:
28
  self.board = chess.Board()
29
  self.piece_mapping = self._initialize_piece_mapping()
30
  self.last_move = None
31
- print("ChessModel initialized with a new board.")
32
 
33
  def is_king_empathy_zero_or_below(self) -> bool:
34
  for piece in self.piece_mapping.values():
@@ -486,7 +485,7 @@ class ChessPresenter:
486
  logger.info(f"Selected piece at {chess.SQUARE_NAMES[square]}: {piece}")
487
 
488
  self.current_sprite = piece
489
- # self.view.show_sprite(piece)
490
  elif self.selected_square is not None:
491
  move = chess.Move(self.selected_square, square)
492
  if self.model.is_promotion_move(move):
@@ -499,7 +498,6 @@ class ChessPresenter:
499
  else:
500
  self.pending_move = move
501
  self.view.show_move_argument_dialog()
502
- # self.view.show_sprite(self.current_sprite)
503
  else:
504
  logger.info(f"Invalid move: {move}")
505
 
@@ -589,6 +587,7 @@ class ChessView(ft.Container):
589
  self.es_button = ft.ElevatedButton("ES", on_click=self.set_spanish)
590
  self.piece_speak_velocity_bar = self.speak_velocity_bar()
591
  self.player_speak_velocity_bar = self.speak_velocity_bar()
 
592
 
593
  self.language_selector = ft.Row(
594
  [self.en_button, self.es_button],
@@ -613,10 +612,10 @@ class ChessView(ft.Container):
613
 
614
  self.empathy_bar = ft.ProgressBar(
615
  width=self.board_size,
616
- height=5,
617
  color=ft.colors.BLUE,
618
  bgcolor=ft.colors.GREY_300,
619
- visible=False
620
  )
621
 
622
  self.empathy_text = ft.Text("Empathy", size=14, color=ft.colors.WHITE)
@@ -625,11 +624,12 @@ class ChessView(ft.Container):
625
  content=ft.Column([
626
  self.empathy_text,
627
  self.empathy_bar
628
- ], spacing=1, alignment=ft.MainAxisAlignment.CENTER),
629
  width=self.board_size,
630
- height=50,
631
- visible=False,
632
- padding=10
 
633
  )
634
 
635
  self.countdown = RecordingCountdown(10)
@@ -1043,15 +1043,16 @@ class ChessView(ft.Container):
1043
  def on_square_click(self, row, col):
1044
  square = chess.square(col, 7 - row)
1045
  piece, chess_piece = self.presenter.model.get_piece_at(square)
1046
-
1047
  if self.elimination_mode:
1048
  self.presenter.eliminate_rival_piece(chess.square(col, 7 - row))
1049
 
1050
  if chess_piece and chess_piece.color == self.current_turn:
 
1051
  self.show_empathy_bar(chess_piece.empathy)
1052
  else:
1053
- self.hide_empathy_bar()
1054
- self.hide_sprite_and_dialogue()
1055
 
1056
  self.presenter.on_square_click(row, col)
1057
 
@@ -1070,14 +1071,16 @@ class ChessView(ft.Container):
1070
  self.update()
1071
 
1072
  def show_empathy_bar(self, empathy):
 
1073
  self.empathy_bar.value = empathy
1074
  self.empathy_container.visible = True
1075
- self.empathy_bar.visible = True
1076
  self.update()
1077
 
1078
  def hide_empathy_bar(self):
 
1079
  self.empathy_container.visible = False
1080
- self.empathy_bar.visible = False
1081
  self.update()
1082
 
1083
  def hide_player_transcription(self):
@@ -1237,25 +1240,32 @@ class ChessView(ft.Container):
1237
 
1238
  self.turn_indicator = ft.Text("White's turn", size=20, color=ft.colors.WHITE)
1239
 
1240
- # Empathy bar and turn indicator in a row
1241
- turn_and_empathy_row = ft.Row([self.turn_indicator], alignment=ft.MainAxisAlignment.CENTER, spacing=10)
 
 
 
 
 
 
 
 
 
 
1242
 
1243
  main_layout = ft.Container(
1244
- content=ft.Column([turn_and_empathy_row, ft.Row([ft.Container(ft.Stack([self.chessboard, self.move_argument_dialog]), bgcolor='blue')], alignment=ft.MainAxisAlignment.CENTER)], alignment=ft.CrossAxisAlignment.END, expand=True),
1245
  margin=ft.margin.only(top=20)
1246
  )
1247
 
1248
  self.response_layout = ft.Column(controls=[self.transcription_container, self.sprite_and_dialogue_container], width=600, visible=False)
1249
 
1250
- def temp_function(e):
1251
- self.hide_sprite_and_dialogue()
1252
-
1253
  full_layout = ft.Container(
1254
  ft.Stack([
1255
  ft.Column(controls=[ft.Container(ft.Column(controls=[main_layout])), self.checkmate_dialog, self.eliminate_piece_dialog, self.king_empathy_loss_dialog]),
1256
  ft.Row(controls=[self.response_layout], alignment=ft.MainAxisAlignment.CENTER),
1257
  ]),
1258
- on_click=temp_function
1259
  )
1260
 
1261
  return ft.Column(controls=[full_layout], alignment=ft.MainAxisAlignment.SPACE_BETWEEN) # , self.language_selector
@@ -1313,6 +1323,12 @@ class ChessView(ft.Container):
1313
  # Final update to apply opacity changes
1314
  self.video_stack.update()
1315
 
 
 
 
 
 
 
1316
 
1317
  async def main(page: ft.Page):
1318
  import sys
 
28
  self.board = chess.Board()
29
  self.piece_mapping = self._initialize_piece_mapping()
30
  self.last_move = None
 
31
 
32
  def is_king_empathy_zero_or_below(self) -> bool:
33
  for piece in self.piece_mapping.values():
 
485
  logger.info(f"Selected piece at {chess.SQUARE_NAMES[square]}: {piece}")
486
 
487
  self.current_sprite = piece
488
+ self.view.show_empathy_bar(piece_enum.empathy)
489
  elif self.selected_square is not None:
490
  move = chess.Move(self.selected_square, square)
491
  if self.model.is_promotion_move(move):
 
498
  else:
499
  self.pending_move = move
500
  self.view.show_move_argument_dialog()
 
501
  else:
502
  logger.info(f"Invalid move: {move}")
503
 
 
587
  self.es_button = ft.ElevatedButton("ES", on_click=self.set_spanish)
588
  self.piece_speak_velocity_bar = self.speak_velocity_bar()
589
  self.player_speak_velocity_bar = self.speak_velocity_bar()
590
+ self.empathy_bar_visible = False
591
 
592
  self.language_selector = ft.Row(
593
  [self.en_button, self.es_button],
 
612
 
613
  self.empathy_bar = ft.ProgressBar(
614
  width=self.board_size,
615
+ height=10,
616
  color=ft.colors.BLUE,
617
  bgcolor=ft.colors.GREY_300,
618
+ value=0.5,
619
  )
620
 
621
  self.empathy_text = ft.Text("Empathy", size=14, color=ft.colors.WHITE)
 
624
  content=ft.Column([
625
  self.empathy_text,
626
  self.empathy_bar
627
+ ], spacing=5, alignment=ft.MainAxisAlignment.CENTER),
628
  width=self.board_size,
629
+ padding=10,
630
+ bgcolor=ft.colors.BLACK,
631
+ border_radius=ft.border_radius.all(10),
632
+ visible=False, # Start hidden
633
  )
634
 
635
  self.countdown = RecordingCountdown(10)
 
1043
  def on_square_click(self, row, col):
1044
  square = chess.square(col, 7 - row)
1045
  piece, chess_piece = self.presenter.model.get_piece_at(square)
1046
+
1047
  if self.elimination_mode:
1048
  self.presenter.eliminate_rival_piece(chess.square(col, 7 - row))
1049
 
1050
  if chess_piece and chess_piece.color == self.current_turn:
1051
+ print(f"Valid piece selected: {chess_piece}, empathy: {chess_piece.empathy}")
1052
  self.show_empathy_bar(chess_piece.empathy)
1053
  else:
1054
+ print("No valid piece selected")
1055
+ # Don't hide the empathy bar here
1056
 
1057
  self.presenter.on_square_click(row, col)
1058
 
 
1071
  self.update()
1072
 
1073
  def show_empathy_bar(self, empathy):
1074
+ print(f"Showing empathy bar with value: {empathy}")
1075
  self.empathy_bar.value = empathy
1076
  self.empathy_container.visible = True
1077
+ self.empathy_bar_visible = True
1078
  self.update()
1079
 
1080
  def hide_empathy_bar(self):
1081
+ print("Hiding empathy bar")
1082
  self.empathy_container.visible = False
1083
+ self.empathy_bar_visible = False
1084
  self.update()
1085
 
1086
  def hide_player_transcription(self):
 
1240
 
1241
  self.turn_indicator = ft.Text("White's turn", size=20, color=ft.colors.WHITE)
1242
 
1243
+ # Create separate containers for turn indicator and empathy bar
1244
+ turn_container = ft.Container(
1245
+ content=self.turn_indicator,
1246
+ margin=ft.margin.only(bottom=5)
1247
+ )
1248
+
1249
+ # Place turn container, empathy container, and chessboard in a column
1250
+ board_column = ft.Column([
1251
+ turn_container,
1252
+ self.empathy_container,
1253
+ ft.Container(ft.Stack([self.chessboard, self.move_argument_dialog]), bgcolor='blue')
1254
+ ], alignment=ft.MainAxisAlignment.CENTER, spacing=10) # Added spacing between elements
1255
 
1256
  main_layout = ft.Container(
1257
+ content=board_column,
1258
  margin=ft.margin.only(top=20)
1259
  )
1260
 
1261
  self.response_layout = ft.Column(controls=[self.transcription_container, self.sprite_and_dialogue_container], width=600, visible=False)
1262
 
 
 
 
1263
  full_layout = ft.Container(
1264
  ft.Stack([
1265
  ft.Column(controls=[ft.Container(ft.Column(controls=[main_layout])), self.checkmate_dialog, self.eliminate_piece_dialog, self.king_empathy_loss_dialog]),
1266
  ft.Row(controls=[self.response_layout], alignment=ft.MainAxisAlignment.CENTER),
1267
  ]),
1268
+ on_click=self.on_screen_click # Change this line
1269
  )
1270
 
1271
  return ft.Column(controls=[full_layout], alignment=ft.MainAxisAlignment.SPACE_BETWEEN) # , self.language_selector
 
1323
  # Final update to apply opacity changes
1324
  self.video_stack.update()
1325
 
1326
+ def on_screen_click(self, e):
1327
+ if self.empathy_bar_visible:
1328
+ print("Screen clicked, hiding empathy bar")
1329
+ self.hide_empathy_bar()
1330
+ self.hide_sprite_and_dialogue()
1331
+
1332
 
1333
  async def main(page: ft.Page):
1334
  import sys