Geen omschrijving

textbox_mugshots.c 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 <objects.h>
  31. #include <callback.h>
  32. #include <config/core.h>
  33. #include <lcd.h>
  34. #include <debug.h>
  35. #include <game_engine.h>
  36. #include <memory.h>
  37. /* === PROTOTYPES === */
  38. /**
  39. * @brief null callback
  40. * @param self object
  41. */
  42. void mug_cb_null(struct obj_entity *self);
  43. /**
  44. * @brief called when tb is opened to create mugshot
  45. */
  46. void mug_create_on_variable();
  47. /**
  48. * @brief called when tb is closed to delete mugshot
  49. */
  50. void mug_delete();
  51. /* === STRUCTURES === */
  52. typedef struct mug_mugshot {
  53. void *gfx;
  54. void *pal;
  55. } mug_mugshot;
  56. /* === STATIC GLOBALS === */
  57. extern mug_mugshot mugshots[0xFF];
  58. u8 *temp_obj_id1 = (u8*) OBJ_1_TEMP;
  59. u8 *temp_obj_id2 = (u8*) OBJ_2_TEMP;
  60. struct obj_oam_attributes mug_sprite = {0, 0x8000, 0, 0};
  61. struct obj_template mugshot_1_template = {MUGSHOT_1_TAG, MUGSHOT_1_TAG, &mug_sprite, (struct obj_frame **) 0x08231CF0, 0, (struct obj_rotscale_frame **) 0x08231CFC, mug_cb_null};
  62. struct obj_template mugshot_2_template = {MUGSHOT_2_TAG, MUGSHOT_2_TAG, &mug_sprite, (struct obj_frame **) 0x08231CF0, 0, (struct obj_rotscale_frame **) 0x08231CFC, mug_cb_null};
  63. /* === IMPLEMENTATIONS === */
  64. void mug_create_on_variable() {
  65. u16 *mug1_var = var_access(MUGHSOT_1_TABLE);
  66. u16 c_mug1_var = *mug1_var;
  67. u16 mug_id_1 = c_mug1_var & 0x3FFF;
  68. if (mug_id_1 != 0) {
  69. bool h_flip = (c_mug1_var & 0x8000) > 0;
  70. bool v_flip = (c_mug1_var & 0x4000) > 0;
  71. u16 *mug1_x = var_access(MUGSHOT_1_X);
  72. u16 *mug1_y = var_access(MUGSHOT_1_Y);
  73. mug_id_1--;
  74. struct obj_resource gfx_mugshot_1 = {(mugshots[mug_id_1].gfx), 0x1C00, MUGSHOT_1_TAG};
  75. struct obj_resource pal_mugshot_1 = {(mugshots[mug_id_1].pal), MUGSHOT_1_TAG};
  76. obj_gpu_pal_alloc_tag_and_apply(&pal_mugshot_1);
  77. obj_gpu_tile_decompress_alloc_tag_and_upload(&gfx_mugshot_1);
  78. *temp_obj_id1 = (u16) obj_template_instanciate_forward_search(&mugshot_1_template, 0, 100, 1);
  79. if (h_flip)
  80. objects[*temp_obj_id1].final_oam.attr1 |= 0x1000;
  81. if (v_flip)
  82. objects[*temp_obj_id1].final_oam.attr1 |= 0x2000;
  83. objects[*temp_obj_id1].x = *mug1_x;
  84. objects[*temp_obj_id1].y = *mug1_y;
  85. }
  86. u16 *mug2_var = var_access(MUGHSOT_2_TABLE);
  87. u16 c_mug2_var = *mug2_var;
  88. u16 mug_id_2 = c_mug2_var & 0x3FFF;
  89. if (mug_id_2 != 0) {
  90. bool h_flip = (c_mug2_var & 0x8000) > 0;
  91. bool v_flip = (c_mug2_var & 0x4000) > 0;
  92. u16 *mug2_x = var_access(MUGSHOT_2_X);
  93. u16 *mug2_y = var_access(MUGSHOT_2_Y);
  94. mug_id_2--;
  95. struct obj_resource gfx_mugshot_2 = {(mugshots[mug_id_2].gfx), 0x1C00, MUGSHOT_2_TAG};
  96. struct obj_resource pal_mugshot_2 = {(mugshots[mug_id_2].pal), MUGSHOT_2_TAG};
  97. obj_gpu_pal_alloc_tag_and_apply(&pal_mugshot_2);
  98. obj_gpu_tile_decompress_alloc_tag_and_upload(&gfx_mugshot_2);
  99. c_mug2_var = *mug2_var;
  100. *temp_obj_id2 = (u16) obj_template_instanciate_forward_search(&mugshot_2_template, 0, 100, 1);
  101. if (h_flip)
  102. objects[*temp_obj_id2].final_oam.attr1 |= 0x1000;
  103. if (v_flip)
  104. objects[*temp_obj_id2].final_oam.attr1 |= 0x2000;
  105. objects[*temp_obj_id2].x = *mug2_x;
  106. objects[*temp_obj_id2].y = *mug2_y;
  107. }
  108. }
  109. void mug_delete() {
  110. //u16 *mug1_var = var_access(MUGHSOT_1_TABLE);
  111. //u16 *mug2_var = var_access(MUGHSOT_2_TABLE);
  112. if (*temp_obj_id1 != 0) {
  113. gpu_pal_free_by_tag(MUGSHOT_1_TAG);
  114. obj_gpu_tile_free_by_tag(MUGSHOT_1_TAG);
  115. //*mug1_var = 0;
  116. //do reset mugshot var ; set it to old value instead
  117. //*mug1_var = objects[object_id_1].private[0];
  118. obj_delete_and_free_tiles(&(objects[*temp_obj_id1]));
  119. *temp_obj_id1 = 0;
  120. }
  121. //return;
  122. if (*temp_obj_id2 != 0) {
  123. gpu_pal_free_by_tag(MUGSHOT_2_TAG);
  124. obj_gpu_tile_free_by_tag(MUGSHOT_2_TAG);
  125. //*mug2_var = 0;
  126. //do reset mugshot var ; set it to old value instead
  127. //*mug2_var = objects[object_id_2].private[0];
  128. obj_delete_and_free_tiles(&(objects[*temp_obj_id2]));
  129. *temp_obj_id2 = 0;
  130. }
  131. }
  132. void mug_cb_null(struct obj_entity *self) {
  133. return;
  134. }