1
0

guru.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include <precomp.h>
  2. #include <api.h>
  3. #ifdef WASABI_COMPILE_WND
  4. #include <api/wnd/basewnd.h>
  5. #include <tataki/canvas/bltcanvas.h>
  6. #endif
  7. #include <api/script/guru.h>
  8. #include <api/script/script.h>
  9. #include <api/script/vcpu.h>
  10. #ifdef WASABI_COMPILE_SKIN
  11. #include <api/skin/skin.h>
  12. #endif
  13. extern HINSTANCE hInstance;
  14. #ifdef WASABI_COMPILE_WND
  15. Guru::Guru()
  16. {
  17. fcount = 0;
  18. txt=NULL;
  19. code=0;
  20. intinfo=0;
  21. }
  22. Guru::~Guru() {
  23. }
  24. #endif
  25. void Guru::spawn(SystemObject *_script, int code, const wchar_t *pub, int intinfo) {
  26. #ifdef WASABI_COMPILE_WND
  27. script = _script;
  28. if (WASABI_API_PALETTE->getSkinPartIterator() > last_iterator) {
  29. mustquit = 0;
  30. last_iterator = WASABI_API_PALETTE->getSkinPartIterator();
  31. }
  32. else
  33. return;
  34. #ifdef WASABI_COMPILE_SKIN
  35. int oldlock = WASABI_API_SKIN->skin_getLockUI();
  36. WASABI_API_SKIN->skin_setLockUI(0);
  37. #endif
  38. Guru g;
  39. g.setCode(code);
  40. g.setPublicTxt(pub);
  41. g.setIntInfo(intinfo);
  42. g.setStartHidden(1);
  43. g.init(hInstance, INVALIDOSWINDOWHANDLE, TRUE);
  44. RECT r;
  45. Wasabi::Std::getViewport(&r, (POINT*)NULL);
  46. r.left = r.left + ((r.right-r.left-640)/2);
  47. r.right = r.left + 640;
  48. TextInfoCanvas c(&g);
  49. Wasabi::FontInfo fontInfo;
  50. fontInfo.pointSize = WASABI_API_APP->getScaleY(14);
  51. #ifdef WIN32
  52. fontInfo.face = L"Lucida Console";
  53. #else
  54. fontInfo.face = L"Lucida";
  55. #endif
  56. fontInfo.bold = true;
  57. r.bottom = r.top + c.getTextHeight(&fontInfo)* (script != NULL ? 9 : 7);
  58. g.resize(&r);
  59. g.setVisible(1);
  60. g.bringToFront();
  61. MSG msg = {0};
  62. WASABI_API_WND->pushModalWnd(&g);
  63. #ifdef WIN32
  64. HWND old = SetCapture(g.gethWnd());
  65. #endif
  66. while (!mustquit) {
  67. mustquit = !GetMessage(&msg, g.gethWnd(), 0, 0);
  68. #ifdef WIN32
  69. if (!msg.hwnd || !TranslateAccelerator(msg.hwnd, NULL, &msg)) {
  70. #endif
  71. TranslateMessage(&msg);
  72. DispatchMessage(&msg);
  73. #ifdef WIN32
  74. }
  75. #endif
  76. }
  77. WASABI_API_WND->popModalWnd(&g);
  78. #ifdef WIN32
  79. SetCapture(old);
  80. #endif
  81. #else
  82. StringPrintfW t(L"Guru Meditation #%04X.%04X%04X.%d%s%s", code, (intinfo & 0xFFFF), VCPU::VIP & 0xFFFF, VCPU::VSD, pub?" ":"", pub?pub:"");
  83. Std::messageBox(t, L"Guru Meditiation", 16);
  84. #endif
  85. #ifdef WASABI_COMPILE_SKIN
  86. WASABI_API_SKIN->skin_setLockUI(oldlock);
  87. #endif
  88. }
  89. #ifdef WASABI_COMPILE_WND
  90. int Guru::onPaint(Canvas *canvas) {
  91. GURU_PARENT::onPaint(canvas);
  92. PaintBltCanvas paintcanvas;
  93. if (canvas == NULL) {
  94. paintcanvas.beginPaint(this);
  95. canvas = &paintcanvas;
  96. }
  97. RECT r;
  98. getClientRect(&r);
  99. canvas->fillRect(&r, 0);
  100. if (fcount%2==0)
  101. {
  102. int w;
  103. Wasabi::FontInfo fontInfo;
  104. fontInfo.color = RGB(0xFF,0,0);
  105. fontInfo.pointSize = WASABI_API_APP->getScaleY(14);
  106. #ifdef WIN32
  107. fontInfo.face = L"Lucida Console";
  108. #else
  109. fontInfo.face = L"Lucida";
  110. #endif
  111. fontInfo.bold = true;
  112. fontInfo.opaque = false;
  113. w = canvas->getTextHeight(&fontInfo);
  114. RECT s = {40, w*2, 560, w*3};
  115. canvas->textOutCentered(&s, L"Winamp Script Failure. Press the left mouse button to continue.", &fontInfo);
  116. StringPrintfW t(L"Guru Meditation #%04X.%04X%04X.%d%s%s", code, (intinfo & 0xFFFF), VCPU::VIP & 0xFFFF, VCPU::VSD, txt?L" ":L"", txt?txt:L"");
  117. s.top=w*4;
  118. s.bottom=s.top+w;
  119. canvas->textOutCentered(&s, t, &fontInfo);
  120. if (script != NULL) {
  121. s.top=w*6;
  122. s.bottom=s.top+w;
  123. canvas->textOutCentered(&s, script->getFilename(), &fontInfo);
  124. }
  125. RECT z;
  126. z.top = r.top + 5;
  127. z.bottom = r.top + min(10, w-2);
  128. z.left = r.left + 5;
  129. z.right = r.right - 5;
  130. canvas->fillRect(&z, RGB(0xFF,0,0));
  131. z.top = r.top + 5;
  132. z.bottom = r.bottom - 5;;
  133. z.left = r.right - min(10, w-2);
  134. z.right = r.right - 5;
  135. canvas->fillRect(&z, RGB(0xFF,0,0));
  136. z.top = r.bottom - min(10, w-2);
  137. z.bottom = r.bottom - 5;
  138. z.left = r.left + 5;
  139. z.right = r.right - 5;
  140. canvas->fillRect(&z, RGB(0xFF,0,0));
  141. z.top = r.top + 5;
  142. z.bottom = r.bottom - 5;;
  143. z.left = r.left + 5;
  144. z.right = r.left + min(10, w-2);
  145. canvas->fillRect(&z, RGB(0xFF,0,0));
  146. }
  147. return 1;
  148. }
  149. int Guru::onLeftButtonUp(int x, int y) {
  150. mustquit=1;
  151. return GURU_PARENT::onLeftButtonUp(x,y);
  152. }
  153. int Guru::onInit() {
  154. GURU_PARENT::onInit();
  155. setTimer(GURU_TIMERID, 400);
  156. return 1;
  157. }
  158. void Guru::setCode(int c) {
  159. code = c;
  160. }
  161. void Guru::setPublicTxt(const wchar_t *t) {
  162. txt = t;
  163. }
  164. void Guru::setIntInfo(int info) {
  165. intinfo = info;
  166. }
  167. void Guru::timerCallback(int id) {
  168. if (id == GURU_TIMERID) {
  169. fcount++;
  170. if (fcount > 7) {
  171. killTimer(GURU_TIMERID);
  172. }
  173. invalidate();
  174. return;
  175. }
  176. GURU_PARENT::timerCallback(id);
  177. }
  178. int Guru::mustquit = 0;
  179. int Guru::last_iterator = -1;
  180. SystemObject * Guru::script = NULL;
  181. #endif