Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1.  
  2. #include "KartingMusic.as";
  3. Random rnd();
  4.  
  5. const string stereo = "StereoPlayer.png";
  6.  
  7. const f32 HUD_X = getScreenWidth()/2;
  8. const f32 HUD_Y = getScreenHeight();
  9.  
  10. bool showing;
  11. bool mouse_over_showbutton;
  12. bool mouse_over_nextbutton;
  13. bool mouse_over_stopplaybutton;
  14. bool mouse_over_backbutton;
  15. Vec2f buttonframesize = Vec2f(16,16);
  16.  
  17. Vec2f topleft = Vec2f(24, HUD_Y-96);
  18. Vec2f nextbuttonpos = topleft + Vec2f(204, 63);
  19. //Vec2f letterpos;
  20.  
  21. SColor showbuttoncolor;
  22. SColor nextbuttoncolor;
  23.  
  24. void onInit(CRules@ this)
  25. {
  26. //onRestart(this);
  27. }
  28.  
  29. //void onRestart( CRules@ this )
  30. //{
  31. // CPlayer@ player = getLocalPlayer();
  32. // if (player is null) return;
  33. // CMixer@ mixer = getMixer();
  34. // if (mixer is null) return;
  35. //
  36. // if (mixer.getPlayingCount() == 0)
  37. // {
  38. // rnd.Reset(player.getNetworkID()+getGameTime());
  39. // s8 num = rnd.NextRanged(7);
  40. // this.set_s8("track", num);
  41. // this.SyncToPlayer("track", player);
  42. // this.set_string("musictrack" ,TrackNames[num]);
  43. // this.set_u16("tracktimer", getGameTime());
  44. // mixer.StopAll();
  45. // mixer.FadeInRandom(num , 25.0f);
  46. // }
  47. //}
  48.  
  49. void onTick(CRules@ this)
  50. {
  51. //if (!getNet().isClient()) return;
  52. CPlayer@ player = getLocalPlayer();
  53. if (player is null) return;
  54. CMixer@ mixer = getMixer();
  55. if (mixer is null) return;
  56. CControls@ controls = getControls();
  57. if (controls is null) return;
  58.  
  59. if (mixer.getPlayingCount() == 0)
  60. {
  61. rnd.Reset(player.getNetworkID()+getGameTime());
  62. s8 num = rnd.NextRanged(7);
  63. this.set_s8("track", num);
  64. this.SyncToPlayer("track", player);
  65. this.set_string("musictrack" ,TrackNames[num]);
  66. this.set_u16("tracktimer", getGameTime());
  67. mixer.StopAll();
  68. mixer.FadeInRandom(num , 25.0f);
  69. }
  70.  
  71. const bool keyAction1 = (controls.isKeyJustPressed(controls.getActionKeyKey(AK_ACTION1)));
  72. Vec2f mousePos = controls.getMouseScreenPos();
  73.  
  74. Vec2f showbuttonpos = topleft + Vec2f(224, 27);
  75.  
  76. mouse_over_showbutton = (mousePos.x > showbuttonpos.x && mousePos.x < showbuttonpos.x+32 && mousePos.y > showbuttonpos.y-24 && mousePos.y < showbuttonpos.y);
  77. mouse_over_nextbutton = (mousePos.x > nextbuttonpos.x-48 && mousePos.x < nextbuttonpos.x+24 && mousePos.y > nextbuttonpos.y && mousePos.y < nextbuttonpos.y+24);
  78.  
  79. showbuttoncolor = mouse_over_showbutton ? SColor(255, 145, 145, 255) : color_white;
  80. nextbuttoncolor = mouse_over_nextbutton ? SColor(255, 145, 145, 255) : color_white;
  81.  
  82. if (showing && mouse_over_showbutton && keyAction1)
  83. {
  84. showing = false;
  85. Sound::Play("select.ogg");
  86. }
  87. else if (!showing && mouse_over_showbutton && keyAction1)
  88. {
  89. showing = true;
  90. Sound::Play("select.ogg");
  91. }
  92. else if (showing && mouse_over_nextbutton && keyAction1)
  93. {
  94. s8 currenttrack = this.get_s8("track");
  95. if (currenttrack == 7)
  96. currenttrack = 0;
  97. else
  98. currenttrack++;
  99.  
  100. this.set_s8("track", currenttrack);
  101. this.SyncToPlayer("track", player);
  102. this.set_string("musictrack" , TrackNames[currenttrack]);
  103. this.set_u16("tracktimer", getGameTime());
  104. mixer.StopAll();
  105. mixer.FadeInRandom(currenttrack , 0.5f);
  106. Sound::Play("select.ogg");
  107.  
  108. offset = 0;
  109. substr_letters = 0;
  110. timer = 50;
  111. }
  112.  
  113. s32 gametime = getGameTime();
  114.  
  115. topleft.y = showing ? HUD_Y-96 : HUD_Y-24;
  116. }
  117.  
  118. f32 offset = 0;
  119. u8 substr_letters = 0;
  120. f32 timer = 0;
  121. string song_name = "";
  122.  
  123. void onRender(CRules@ this)
  124. {
  125. CPlayer@ player = getLocalPlayer();
  126. if (player is null) return;
  127.  
  128.  
  129. GUI::DrawIcon(stereo, 0, Vec2f(128, 48), topleft , 1.0f); // background
  130.  
  131. Vec2f showbuttonpos = topleft + Vec2f(224, showing ? 27 : -2);
  132. GUI::DrawIcon(stereo, 24, buttonframesize, showbuttonpos, 1.0f, showing ? -1.0: 1.0f, showbuttoncolor); // up down button
  133.  
  134. if (showing)
  135. {
  136. GUI::DrawIcon(stereo, 25, buttonframesize, topleft + Vec2f(58, 63), 1.0f, color_white); // back button
  137. GUI::DrawIcon(stereo, 26, buttonframesize, topleft + Vec2f(114, 63), 1.0f, color_white); // stop/play button
  138. GUI::DrawIcon(stereo, 25, buttonframesize, topleft + Vec2f(198, 63), -1.0f, 1.0f, nextbuttoncolor); // next button
  139.  
  140. GUI::SetFont("hud");
  141.  
  142. //float time = (getGameTime()*2.0f);
  143. //f32 tracktimer = this.get_u16("tracktimer");
  144. //string track = this.get_string("musictrack");
  145.  
  146. //GUI::DrawText(track, topleft+Vec2f(25, 18)*2, color_white);
  147. //GUI::DrawText(track, topleft+Vec2f(25, 18)*2, topleft+Vec2f(103, 27)*2, color_white, false, false);
  148.  
  149. string track = this.get_string("musictrack");
  150. Vec2f dim;
  151. GUI::GetTextDimensions(track, dim);
  152. if(dim.x > 150)
  153. {
  154. string final_string = track.substr(substr_letters, track.size()-substr_letters);
  155. GUI::GetTextDimensions(final_string, dim);
  156. if(dim.x + offset > 150 && timer == 0)
  157. {
  158. offset -= getRenderApproximateCorrectionFactor()/3.0f;
  159. while(dim.x + offset > 150)
  160. {
  161. final_string = final_string.substr(0, final_string.size()-1);
  162. GUI::GetTextDimensions(final_string, dim);
  163. }
  164. song_name = final_string;
  165. }
  166. else
  167. {
  168. timer += getRenderApproximateCorrectionFactor()/3.0f;
  169. if(timer < 35)
  170. {
  171. song_name = final_string;
  172. }
  173. else if (timer < 70)
  174. {
  175. final_string = track;
  176. GUI::GetTextDimensions(final_string, dim);
  177. while(dim.x > 150)
  178. {
  179. final_string = final_string.substr(0, final_string.size()-1);
  180. GUI::GetTextDimensions(final_string, dim);
  181. }
  182. song_name = final_string;
  183. }
  184. else
  185. {
  186. substr_letters = 0;
  187. timer = 0;
  188. }
  189. }
  190. }
  191. else
  192. {
  193. offset = 0;
  194. substr_letters = 0;
  195. song_name = track;
  196. }
  197.  
  198. GUI::DrawText(song_name, topleft+Vec2f(25+offset, 18)*2, color_white);
  199.  
  200. if(offset < 0)
  201. {
  202. string char_to_remove = song_name.substr(0, 1);
  203. Vec2f dim2;
  204. GUI::GetTextDimensions(char_to_remove, dim2);
  205. offset += dim2.x/2.0f;
  206. substr_letters++;
  207. }
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement