You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
7.5KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * Upgrades tab GUI.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "u_common.h"
  14. #include "w_world.h"
  15. cstr upgrcateg[] = {
  16. [UC_Body] = LANG "CAT_BODY",
  17. [UC_Weap] = LANG "CAT_WEAP",
  18. [UC_Extr] = LANG "CAT_EXTR",
  19. [UC_Down] = LANG "CAT_DOWN",
  20. };
  21. static void GUIUpgradesList(struct gui_state *g, struct player *p) {
  22. if(G_Button(g, .x = 90, 213, Pre(btnprev)))
  23. if(CBIState(g)->upgrfilter-- <= 0)
  24. CBIState(g)->upgrfilter = UC_MAX;
  25. if(G_Button(g, .x = 90 + gui_p.btnprev.w, 213, Pre(btnnext)))
  26. if(CBIState(g)->upgrfilter++ >= UC_MAX)
  27. CBIState(g)->upgrfilter = 0;
  28. i32 numbtns = 0;
  29. i32 filter = CBIState(g)->upgrfilter - 1;
  30. char filter_name[16];
  31. if(filter != -1) {
  32. LanguageVC(filter_name, upgrcateg[filter]);
  33. for_upgrade(upgr)
  34. if(upgr->info->category == filter)
  35. numbtns++;
  36. } else {
  37. LanguageVC(filter_name, LANG "CAT_ALL");
  38. for_upgrade(upgr)
  39. numbtns++;
  40. numbtns += UC_MAX;
  41. }
  42. PrintTextFmt(LC(LANG "CAT_FILTER"), filter_name);
  43. PrintText(s_smallfnt, g->defcr, 15,1, 215,1);
  44. G_ScrBeg(g, &CBIState(g)->upgrscr, 15, 36, gui_p.btnlist.w, 178, gui_p.btnlist.h * numbtns);
  45. i32 curcategory = -1;
  46. i32 y = -gui_p.btnlist.h;
  47. for_upgrade(upgr) {
  48. if(filter != -1) {
  49. if(upgr->info->category != filter) continue;
  50. } else if(upgr->info->category != curcategory) {
  51. curcategory = upgr->info->category;
  52. y += gui_p.btnlist.h;
  53. PrintTextChS(LC(upgrcateg[curcategory]));
  54. PrintText(s_lmidfont, g->defcr, g->ox + 40,4, y + g->oy + 1,1);
  55. }
  56. y += gui_p.btnlist.h;
  57. if(G_ScrOcc(g, &CBIState(g)->upgrscr, y, gui_p.btnlist.h))
  58. continue;
  59. cstr color;
  60. if(!get_bit(upgr->flags, _ug_owned) && !P_Shop_CanBuy(p, &upgr->info->shopdef, upgr)) {
  61. color = "u";
  62. } else {
  63. switch(upgr->info->key) {
  64. case UPGR_TorgueMode: color = "g"; break;
  65. case UPGR_DarkCannon: color = "m"; break;
  66. default: color = nil; break;
  67. }
  68. }
  69. struct gui_pre_btn const *pre;
  70. /**/ if(get_bit(upgr->flags, _ug_active)) pre = &gui_p.btnlistactivated;
  71. else if(get_bit(upgr->flags, _ug_owned )) pre = &gui_p.btnlistactive;
  72. else pre = &gui_p.btnlistsel;
  73. char *name = LanguageC(LANG "UPGRADE_TITLE_%S", upgr->info->name);
  74. i32 *upgrsel = &CBIState(g)->upgrsel;
  75. if(G_Button_HId(g, _i, name, 0, y, _i == *upgrsel, .color = color, .preset = pre))
  76. *upgrsel = _i;
  77. for(i32 i = 0; i < 4; i++) {
  78. StrAry(gfxs,
  79. s":UI:Group1", s":UI:Group2", s":UI:Group3", s":UI:Group4");
  80. if(get_bit(upgr->agroups, i)) {
  81. PrintSprite(gfxs[i], g->ox + pre->w - 9,1, g->oy + y + 1,1);
  82. }
  83. }
  84. }
  85. G_ScrEnd(g, &CBIState(g)->upgrscr);
  86. }
  87. static void GUIUpgradeRequirements(struct gui_state *g, struct player *p, struct upgrade *upgr) {
  88. i32 y = 0;
  89. #define Req(name) { \
  90. ACS_BeginPrint(); \
  91. PrintChrSt(LC(LANG name)); \
  92. ACS_PrintChar(' '); \
  93. PrintChrSt(LC(LANG "REQUIRED")); \
  94. PrintText(s_smallfnt, CR_RED, 111,1, 200 + y,2); \
  95. y -= 10; \
  96. }
  97. if(RequiresButDontHave_AI) Req("CBI_ArmorInter");
  98. if(RequiresButDontHave_WMD) Req("CBI_WeapnInter");
  99. if(RequiresButDontHave_WRD) Req("CBI_WeapnInte2");
  100. if(RequiresButDontHave_RDI) Req("CBI_RDistInter");
  101. if(RequiresButDontHave_RA) Req("CBI_ReactArmor");
  102. #undef Req
  103. /* Performance rating */
  104. if(upgr->info->perf && p->pclass != pcl_cybermage) {
  105. bool over = upgr->info->perf + p->cbi.pruse > cbiperf;
  106. if(get_bit(upgr->flags, _ug_active))
  107. PrintTextFmt(LC(LANG "SHOP_DISABLE_SAVES"), upgr->info->perf);
  108. else if(over)
  109. PrintTextFmt(LC(LANG "SHOP_CANT_ACTIVATE"), upgr->info->perf);
  110. else
  111. PrintTextFmt(LC(LANG "SHOP_ACTIVATE_USES"), upgr->info->perf);
  112. PrintText(s_smallfnt, g->defcr, 111,1, 200 + y,2);
  113. y -= 10;
  114. }
  115. /* Score multiplier */
  116. if(upgr->info->scoreadd != 0) {
  117. char cr;
  118. cstr op;
  119. bool chk;
  120. if(get_bit(upgr->flags, _ug_active)) {
  121. chk = upgr->info->scoreadd > 0;
  122. op = LC(LANG "SHOP_MUL_DISABLE");
  123. } else {
  124. chk = upgr->info->scoreadd < 0;
  125. op = LC(LANG "SHOP_MUL_ENABLE");
  126. }
  127. i32 perc = fastabs(ceilk(100.0 * upgr->info->scoreadd));
  128. if(chk) {cr = 'a'; perc = 100 - perc;}
  129. else {cr = 'n'; perc = 100 + perc;}
  130. PrintTextFmt(op, cr, perc);
  131. PrintText(s_smallfnt, g->defcr, 111,1, 200 + y,2);
  132. y -= 10;
  133. }
  134. }
  135. static void GUIUpgradeDescription(struct gui_state *g, struct player *p, struct upgrade *upgr) {
  136. Str(free, sLANG "FREE");
  137. SetClipW(111, 30, 190, 170, 184);
  138. /* Cost */
  139. cstr mark;
  140. str cost;
  141. switch(upgr->info->key) {
  142. case UPGR_lolsords: mark = "\Cjfolds"; break;
  143. case UPGR_TorgueMode: mark = "\Cd$"; break;
  144. default: mark = "\Cnscr"; break;
  145. }
  146. if(upgr->info->cost) cost = StrParam("%s%s", scoresep(P_Shop_Cost(p, &upgr->info->shopdef)), mark);
  147. else cost = L(free);
  148. PrintText_str(cost, s_smallfnt, g->defcr, 111,1, 30,1);
  149. /* Category */
  150. PrintTextChS(LC(upgrcateg[upgr->info->category]));
  151. PrintText(s_smallfnt, g->defcr, 111,1, 40,1);
  152. /* Effect */
  153. ifauto(str, effect, LanguageNull(LANG "UPGRADE_EFFEC_%S", upgr->info->name))
  154. PrintTextFmt("%s %S", LC(LANG "EFFECT"), effect);
  155. static i32 const crs[] = {
  156. CR_RED, CR_ORANGE, CR_YELLOW, CR_GREEN, CR_BLUE, CR_PURPLE, CR_DARKRED
  157. };
  158. i32 cr = g->defcr;
  159. if(upgr->info->key == UPGR_UNCEUNCE)
  160. cr = crs[ACS_Timer() / 4 % countof(crs)];
  161. PrintText(s_smallfnt, cr, 111,1, 50,1);
  162. ClearClip();
  163. }
  164. static void GUIUpgradeButtons(struct gui_state *g, struct player *p, struct upgrade *upgr) {
  165. Str(autogroups, sLANG "AUTOGROUPS");
  166. /* Buy */
  167. if(G_Button(g, LC(LANG "BUY"), 111, 205, !P_Shop_CanBuy(p, &upgr->info->shopdef, upgr), .fill = {&CBIState(g)->buyfill, p->getCVarI(sc_gui_buyfiller)}))
  168. P_Upg_Buy(p, upgr, false);
  169. /* Activate */
  170. if(G_Button(g, get_bit(upgr->flags, _ug_active) ? LC(LANG "DEACTIVATE") : LC(LANG "ACTIVATE"), 111 + gui_p.btndef.w + 2, 205, !P_Upg_CanActivate(p, upgr)))
  171. P_Upg_Toggle(p, upgr);
  172. /* Groups */
  173. PrintText_str(L(autogroups), s_smallfnt, g->defcr, 255,0, 205,0);
  174. for(i32 i = 0; i < 4; i++) {
  175. static i32 const crs[] = {CR_BRICK, CR_GREEN, CR_LIGHTBLUE, CR_GOLD};
  176. ACS_BeginPrint();
  177. ACS_PrintChar('1' + i);
  178. PrintText(s_lmidfont, crs[i], 220 + i * 20,2, 215,1);
  179. if(G_ChkBox_HId(g, i, get_bit(upgr->agroups, i), 221 + i * 20, 211)) {
  180. tog_bit(upgr->agroups, i);
  181. P_Data_Save(p);
  182. }
  183. }
  184. }
  185. void P_CBI_TabUpgrades(struct gui_state *g, struct player *p) {
  186. GUIUpgradesList(g, p);
  187. if(CBIState(g)->upgrsel == UPGR_MAX) {
  188. for_upgrade(upgr) {
  189. if(get_bit(upgr->flags, _ug_available)) {
  190. CBIState(g)->upgrsel = _i;
  191. break;
  192. }
  193. }
  194. }
  195. struct upgrade *upgr = &p->upgrades[CBIState(g)->upgrsel];
  196. GUIUpgradeDescription (g, p, upgr);
  197. GUIUpgradeButtons (g, p, upgr);
  198. GUIUpgradeRequirements(g, p, upgr);
  199. }
  200. /* EOF */