ttt_multi_scene_local.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "../ttt_multi.h"
  2. static void ttt_multi_scene_local_callback(void* context, TttMultiCustomEvent event) {
  3. furi_assert(context);
  4. TttMultiApp* ttt_multi = context;
  5. view_dispatcher_send_custom_event(ttt_multi->view_dispatcher, event);
  6. }
  7. void ttt_multi_scene_local_on_enter(void* context) {
  8. furi_assert(context);
  9. TttMultiApp* ttt_multi = context;
  10. TttMultiGameView* view = ttt_multi->game_view;
  11. ttt_multi_game_view_set_callback(view, ttt_multi_scene_local_callback, ttt_multi);
  12. ttt_multi_game_view_set_local_play(view);
  13. view_dispatcher_switch_to_view(ttt_multi->view_dispatcher, TttMultiViewGame);
  14. }
  15. void ttt_multi_scene_local_on_exit(void* context) {
  16. furi_assert(context);
  17. TttMultiApp* ttt_multi = context;
  18. ttt_multi_game_view_reset(ttt_multi->game_view);
  19. }
  20. bool ttt_multi_scene_local_on_event(void* context, SceneManagerEvent event) {
  21. furi_assert(context);
  22. TttMultiApp* ttt_multi = context;
  23. if(event.type == SceneManagerEventTypeCustom) {
  24. TttMultiCustomEvent custom_event = event.event;
  25. switch(custom_event) {
  26. case TttMultiCustomEventGameMove: {
  27. TttMultiGameMove last_move = {};
  28. ttt_multi_game_view_get_last_move(ttt_multi->game_view, &last_move);
  29. ttt_multi_game_view_move(ttt_multi->game_view, &last_move);
  30. return true;
  31. }
  32. case TttMultiCustomEventGameFinish: {
  33. TttMultiGameResult result = ttt_multi_game_view_get_result(ttt_multi->game_view);
  34. if(result == TttMultiGameResultDraw) {
  35. notification_message(ttt_multi->notifications, &sequence_error);
  36. } else {
  37. notification_message(ttt_multi->notifications, &sequence_success);
  38. }
  39. return true;
  40. }
  41. default:
  42. break;
  43. }
  44. }
  45. return false;
  46. }