table.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <furi.h>
  3. #include <vector>
  4. #include "objects.h"
  5. #define TABLE_SELECT 0
  6. #define TABLE_ERROR 1
  7. #define TABLE_SETTINGS 2
  8. #define TABLE_INDEX_OFFSET 3
  9. class DataDisplay {
  10. public:
  11. enum Align {
  12. Horizontal,
  13. Vertical
  14. };
  15. DataDisplay(const Vec2& pos, int val, bool disp, Align align)
  16. : p(pos)
  17. , value(val)
  18. , display(disp)
  19. , alignment(align) {
  20. }
  21. Vec2 p;
  22. int value;
  23. bool display;
  24. Align alignment;
  25. virtual void draw(Canvas* canvas) = 0;
  26. };
  27. class Lives : public DataDisplay {
  28. public:
  29. Lives()
  30. : DataDisplay(Vec2(), 3, false, Horizontal) {
  31. }
  32. void draw(Canvas* canvas);
  33. };
  34. class Score : public DataDisplay {
  35. public:
  36. Score()
  37. : DataDisplay(Vec2(64 - 1, 1), 0, false, Horizontal) {
  38. }
  39. void draw(Canvas* canvas);
  40. };
  41. // Defines all of the elements on a pinball table:
  42. // edges, bumpers, flipper locations, scoreboard
  43. //
  44. // Also used for other app "views", like the main menu (table select)
  45. // and the Settings screen.
  46. // TODO: make this better? eh, it works for now...
  47. class Table {
  48. public:
  49. Table()
  50. : game_over(false)
  51. , balls_released(false)
  52. , plunger(nullptr) {
  53. }
  54. ~Table();
  55. std::vector<FixedObject*> objects;
  56. std::vector<Ball> balls; // current state of balls
  57. std::vector<Ball> balls_initial; // original positions, before release
  58. std::vector<Flipper> flippers;
  59. bool game_over;
  60. bool balls_released; // is ball in play?
  61. Lives lives;
  62. Score score;
  63. Plunger* plunger;
  64. void draw(Canvas* canvas);
  65. };
  66. typedef struct {
  67. FuriString* name;
  68. FuriString* filename;
  69. } TableMenuItem;
  70. class TableList {
  71. public:
  72. TableList() = default;
  73. ~TableList();
  74. std::vector<TableMenuItem> menu_items;
  75. int display_size; // how many can fit on screen
  76. int selected;
  77. };
  78. // Read the list tables from the data folder and store in the state
  79. void table_table_list_init(void* ctx);
  80. // Loads the index'th table from the list
  81. bool table_load_table(void* ctx, size_t index);