Nessuna descrizione

textbox_mugshots.c 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file textbox_mugshots.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Display little mugshot icons over the textbox
  27. *
  28. */
  29. /* === INCLUDES === */
  30. #include <pokeagb/pokeagb.h>
  31. #include <config/core.h>
  32. /* === PROTOTYPES === */
  33. /**
  34. * @brief null callback
  35. * @param self object
  36. */
  37. void mug_cb_null(struct Object *self);
  38. /**
  39. * @brief called when tb is opened to create mugshot
  40. */
  41. void mug_create_on_variable();
  42. /**
  43. * @brief called when tb is closed to delete mugshot
  44. */
  45. void mug_delete();
  46. /* === STRUCTURES === */
  47. typedef struct Mugshot {
  48. void *gfx;
  49. void *pal;
  50. } Mugshot;
  51. /* === STATIC GLOBALS === */
  52. extern Mugshot mugshots[0xFF];
  53. u8 *temp_obj_id1 = (u8*) OBJ_1_TEMP;
  54. u8 *temp_obj_id2 = (u8*) OBJ_2_TEMP;
  55. struct OamData mug_sprite = {.size = 3};
  56. struct Template mugshot_1_template = {.tiles_tag = MUGSHOT_1_TAG,
  57. .pal_tag = MUGSHOT_1_TAG,
  58. .oam = &mug_sprite, .graphics = NULL,
  59. .animation=SPRITE_NO_ANIMATION,
  60. .rotscale = SPRITE_NO_ROTSCALE,
  61. .callback=mug_cb_null};
  62. struct Template mugshot_2_template = {.tiles_tag = MUGSHOT_2_TAG,
  63. .pal_tag = MUGSHOT_2_TAG,
  64. .oam = &mug_sprite, .graphics = NULL,
  65. .animation=SPRITE_NO_ANIMATION,
  66. .rotscale = SPRITE_NO_ROTSCALE,
  67. .callback=mug_cb_null};
  68. /* === IMPLEMENTATIONS === */
  69. void mug_create_on_variable() {
  70. u16 *mug1_var = var_access(MUGHSOT_1_TABLE);
  71. u16 c_mug1_var = *mug1_var;
  72. u16 mug_id_1 = c_mug1_var & 0x3FFF;
  73. if (mug_id_1 != 0) {
  74. bool h_flip = (c_mug1_var & 0x8000) > 0;
  75. bool v_flip = (c_mug1_var & 0x4000) > 0;
  76. u16 *mug1_x = var_access(MUGSHOT_1_X);
  77. u16 *mug1_y = var_access(MUGSHOT_1_Y);
  78. mug_id_1--;
  79. struct SpriteTiles gfx_mugshot_1 = {(mugshots[mug_id_1].gfx), 0x1C00, MUGSHOT_1_TAG};
  80. struct SpritePalette pal_mugshot_1 = {(mugshots[mug_id_1].pal), MUGSHOT_1_TAG};
  81. gpu_pal_obj_alloc_tag_and_apply(&pal_mugshot_1);
  82. gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_mugshot_1);
  83. *temp_obj_id1 = (u16) template_instanciate_forward_search(&mugshot_1_template, 0, 100, 1);
  84. if (h_flip)
  85. objects[*temp_obj_id1].final_oam.h_flip = true;
  86. if (v_flip)
  87. objects[*temp_obj_id1].final_oam.v_flip = true;
  88. objects[*temp_obj_id1].pos1.x = *mug1_x;
  89. objects[*temp_obj_id1].pos1.y = *mug1_y;
  90. }
  91. u16 *mug2_var = var_access(MUGHSOT_2_TABLE);
  92. u16 c_mug2_var = *mug2_var;
  93. u16 mug_id_2 = c_mug2_var & 0x3FFF;
  94. if (mug_id_2 != 0) {
  95. bool h_flip = (c_mug2_var & 0x8000) > 0;
  96. bool v_flip = (c_mug2_var & 0x4000) > 0;
  97. u16 *mug2_x = var_access(MUGSHOT_2_X);
  98. u16 *mug2_y = var_access(MUGSHOT_2_Y);
  99. mug_id_2--;
  100. struct SpriteTiles gfx_mugshot_2 = {(mugshots[mug_id_2].gfx), 0x1C00, MUGSHOT_2_TAG};
  101. struct SpritePalette pal_mugshot_2 = {(mugshots[mug_id_2].pal), MUGSHOT_2_TAG};
  102. gpu_pal_obj_alloc_tag_and_apply(&pal_mugshot_2);
  103. gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_mugshot_2);
  104. c_mug2_var = *mug2_var;
  105. *temp_obj_id2 = (u16) template_instanciate_forward_search(&mugshot_2_template, 0, 100, 1);
  106. if (h_flip)
  107. objects[*temp_obj_id2].final_oam.h_flip = true;
  108. if (v_flip)
  109. objects[*temp_obj_id2].final_oam.v_flip = true;
  110. objects[*temp_obj_id2].pos1.x = *mug2_x;
  111. objects[*temp_obj_id2].pos1.y = *mug2_y;
  112. }
  113. }
  114. void mug_delete() {
  115. //u16 *mug1_var = var_access(MUGHSOT_1_TABLE);
  116. //u16 *mug2_var = var_access(MUGHSOT_2_TABLE);
  117. if (*temp_obj_id1 != 0) {
  118. gpu_pal_free_by_tag(MUGSHOT_1_TAG);
  119. gpu_tile_obj_free_by_tag(MUGSHOT_1_TAG);
  120. //*mug1_var = 0;
  121. //do reset mugshot var ; set it to old value instead
  122. //*mug1_var = objects[object_id_1].private[0];
  123. obj_delete_and_free_tiles(&(objects[*temp_obj_id1]));
  124. *temp_obj_id1 = 0;
  125. }
  126. //return;
  127. if (*temp_obj_id2 != 0) {
  128. gpu_pal_free_by_tag(MUGSHOT_2_TAG);
  129. gpu_tile_obj_free_by_tag(MUGSHOT_2_TAG);
  130. //*mug2_var = 0;
  131. //do reset mugshot var ; set it to old value instead
  132. //*mug2_var = objects[object_id_2].private[0];
  133. obj_delete_and_free_tiles(&(objects[*temp_obj_id2]));
  134. *temp_obj_id2 = 0;
  135. }
  136. }
  137. void mug_cb_null(struct Object *self) {
  138. (void)self;
  139. return;
  140. }