Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "KartingMusic.as";
- Random rnd();
- const string stereo = "StereoPlayer.png";
- const f32 HUD_X = getScreenWidth()/2;
- const f32 HUD_Y = getScreenHeight();
- bool showing;
- bool mouse_over_showbutton;
- bool mouse_over_nextbutton;
- bool mouse_over_stopplaybutton;
- bool mouse_over_backbutton;
- Vec2f buttonframesize = Vec2f(16,16);
- Vec2f topleft = Vec2f(24, HUD_Y-96);
- Vec2f nextbuttonpos = topleft + Vec2f(204, 63);
- //Vec2f letterpos;
- SColor showbuttoncolor;
- SColor nextbuttoncolor;
- void onInit(CRules@ this)
- {
- //onRestart(this);
- }
- //void onRestart( CRules@ this )
- //{
- // CPlayer@ player = getLocalPlayer();
- // if (player is null) return;
- // CMixer@ mixer = getMixer();
- // if (mixer is null) return;
- //
- // if (mixer.getPlayingCount() == 0)
- // {
- // rnd.Reset(player.getNetworkID()+getGameTime());
- // s8 num = rnd.NextRanged(7);
- // this.set_s8("track", num);
- // this.SyncToPlayer("track", player);
- // this.set_string("musictrack" ,TrackNames[num]);
- // this.set_u16("tracktimer", getGameTime());
- // mixer.StopAll();
- // mixer.FadeInRandom(num , 25.0f);
- // }
- //}
- void onTick(CRules@ this)
- {
- //if (!getNet().isClient()) return;
- CPlayer@ player = getLocalPlayer();
- if (player is null) return;
- CMixer@ mixer = getMixer();
- if (mixer is null) return;
- CControls@ controls = getControls();
- if (controls is null) return;
- if (mixer.getPlayingCount() == 0)
- {
- rnd.Reset(player.getNetworkID()+getGameTime());
- s8 num = rnd.NextRanged(7);
- this.set_s8("track", num);
- this.SyncToPlayer("track", player);
- this.set_string("musictrack" ,TrackNames[num]);
- this.set_u16("tracktimer", getGameTime());
- mixer.StopAll();
- mixer.FadeInRandom(num , 25.0f);
- }
- const bool keyAction1 = (controls.isKeyJustPressed(controls.getActionKeyKey(AK_ACTION1)));
- Vec2f mousePos = controls.getMouseScreenPos();
- Vec2f showbuttonpos = topleft + Vec2f(224, 27);
- mouse_over_showbutton = (mousePos.x > showbuttonpos.x && mousePos.x < showbuttonpos.x+32 && mousePos.y > showbuttonpos.y-24 && mousePos.y < showbuttonpos.y);
- mouse_over_nextbutton = (mousePos.x > nextbuttonpos.x-48 && mousePos.x < nextbuttonpos.x+24 && mousePos.y > nextbuttonpos.y && mousePos.y < nextbuttonpos.y+24);
- showbuttoncolor = mouse_over_showbutton ? SColor(255, 145, 145, 255) : color_white;
- nextbuttoncolor = mouse_over_nextbutton ? SColor(255, 145, 145, 255) : color_white;
- if (showing && mouse_over_showbutton && keyAction1)
- {
- showing = false;
- Sound::Play("select.ogg");
- }
- else if (!showing && mouse_over_showbutton && keyAction1)
- {
- showing = true;
- Sound::Play("select.ogg");
- }
- else if (showing && mouse_over_nextbutton && keyAction1)
- {
- s8 currenttrack = this.get_s8("track");
- if (currenttrack == 7)
- currenttrack = 0;
- else
- currenttrack++;
- this.set_s8("track", currenttrack);
- this.SyncToPlayer("track", player);
- this.set_string("musictrack" , TrackNames[currenttrack]);
- this.set_u16("tracktimer", getGameTime());
- mixer.StopAll();
- mixer.FadeInRandom(currenttrack , 0.5f);
- Sound::Play("select.ogg");
- offset = 0;
- substr_letters = 0;
- timer = 50;
- }
- s32 gametime = getGameTime();
- topleft.y = showing ? HUD_Y-96 : HUD_Y-24;
- }
- f32 offset = 0;
- u8 substr_letters = 0;
- f32 timer = 0;
- string song_name = "";
- void onRender(CRules@ this)
- {
- CPlayer@ player = getLocalPlayer();
- if (player is null) return;
- GUI::DrawIcon(stereo, 0, Vec2f(128, 48), topleft , 1.0f); // background
- Vec2f showbuttonpos = topleft + Vec2f(224, showing ? 27 : -2);
- GUI::DrawIcon(stereo, 24, buttonframesize, showbuttonpos, 1.0f, showing ? -1.0: 1.0f, showbuttoncolor); // up down button
- if (showing)
- {
- GUI::DrawIcon(stereo, 25, buttonframesize, topleft + Vec2f(58, 63), 1.0f, color_white); // back button
- GUI::DrawIcon(stereo, 26, buttonframesize, topleft + Vec2f(114, 63), 1.0f, color_white); // stop/play button
- GUI::DrawIcon(stereo, 25, buttonframesize, topleft + Vec2f(198, 63), -1.0f, 1.0f, nextbuttoncolor); // next button
- GUI::SetFont("hud");
- //float time = (getGameTime()*2.0f);
- //f32 tracktimer = this.get_u16("tracktimer");
- //string track = this.get_string("musictrack");
- //GUI::DrawText(track, topleft+Vec2f(25, 18)*2, color_white);
- //GUI::DrawText(track, topleft+Vec2f(25, 18)*2, topleft+Vec2f(103, 27)*2, color_white, false, false);
- string track = this.get_string("musictrack");
- Vec2f dim;
- GUI::GetTextDimensions(track, dim);
- if(dim.x > 150)
- {
- string final_string = track.substr(substr_letters, track.size()-substr_letters);
- GUI::GetTextDimensions(final_string, dim);
- if(dim.x + offset > 150 && timer == 0)
- {
- offset -= getRenderApproximateCorrectionFactor()/3.0f;
- while(dim.x + offset > 150)
- {
- final_string = final_string.substr(0, final_string.size()-1);
- GUI::GetTextDimensions(final_string, dim);
- }
- song_name = final_string;
- }
- else
- {
- timer += getRenderApproximateCorrectionFactor()/3.0f;
- if(timer < 35)
- {
- song_name = final_string;
- }
- else if (timer < 70)
- {
- final_string = track;
- GUI::GetTextDimensions(final_string, dim);
- while(dim.x > 150)
- {
- final_string = final_string.substr(0, final_string.size()-1);
- GUI::GetTextDimensions(final_string, dim);
- }
- song_name = final_string;
- }
- else
- {
- substr_letters = 0;
- timer = 0;
- }
- }
- }
- else
- {
- offset = 0;
- substr_letters = 0;
- song_name = track;
- }
- GUI::DrawText(song_name, topleft+Vec2f(25+offset, 18)*2, color_white);
- if(offset < 0)
- {
- string char_to_remove = song_name.substr(0, 1);
- Vec2f dim2;
- GUI::GetTextDimensions(char_to_remove, dim2);
- offset += dim2.x/2.0f;
- substr_letters++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement