public virtual void StartMusic(TuneDef parmDef = null) { if (state == State.off) { state = State.on; } //Establish duration //Cthulhu.Utility.DebugReport("Cur Time:" + Time.time.ToString()); duration = Time.time + currentTuneDef.durationTime; //Cthulhu.Utility.DebugReport(currentTuneDef.ToString() + " Fin Time:" + duration.ToString()); //Clear old song this.playingSong = null; //Put on new song SoundInfo soundInfo = SoundInfo.InMap(this, MaintenanceType.None); SoundDef soundDef = currentTuneDef as SoundDef; if (parmDef != null) { soundDef = parmDef as SoundDef; } this.playingSong = SoundStarter.TrySpawnSustainer(soundDef, soundInfo); }
/// <summary> /// Handles the upcoming track. /// </summary> /// <param name="def"></param> /// <returns></returns> private bool TryResolveNextTrack(out TuneDef def) { def = null; if (playlist.Count == 0) { if (!TryCreatePlaylist()) { Log.Error("Unable to create playlist!"); return(false); } } TuneDef result = null; for (int i = 0; i < 999; i++) { if (playlist.TryRandomElement <TuneDef>(out result)) { if (result == CurrentTune) { continue; } break; } } if (result != null) { def = result; return(true); } return(false); }
// ============= PLAYLIST CONTROLS ================= // private void SwitchTracks() { //Let's declare some variables. TuneDef curTune; TuneDef nextTune; //Let's pick out the next tune. TuneDef resolvedNextTune = null; if (!TryResolveNextTrack(out resolvedNextTune)) { Log.Error("Could not resolve next track."); return; } NextTune = resolvedNextTune; //Let's seal up the current variables in nice clean envelope. curTune = CurrentTune; nextTune = NextTune; //Stop the music. StopMusic(); //Let's switch tracks. PreviousTune = curTune; CurrentTune = nextTune; //Start the music. StartMusic(); }
// ===================== Pawn Actions ===================== //Pawn-activated music event public virtual void PlayMusic(Pawn activator) { //No one there? We can't start without an audience. if (activator == null || this == null) { return; } //If there is no tuneDef set to play, then let's randomly select one from the library. if (currentTuneDef == null) { currentTuneDef = tuneScape.TuneDefCache.Where(x => !x.instrumentOnly).RandomElement <TuneDef>(); } //We're off? Let's change that. if (state == State.off) { state = State.on; StartMusic(); } }
public TuneDef GetCache(TuneDef tune) { TuneDef result; if (TuneDefCache == null) { TuneDefCache = new List <TuneDef>(); } foreach (TuneDef current in TuneDefCache) { if (current == tune) { result = current; return(result); } } TuneDefCache.Add(tune); result = tune; return(result); }
public TuneDef GetCache(TuneDef tune) { TuneDef result; if (TuneDefCache == null) { TuneDefCache = new List <TuneDef>(); } foreach (var current in TuneDefCache) { if (current != tune) { continue; } result = current; return(result); } TuneDefCache.Add(tune); result = tune; return(result); }
/// <summary> /// All the menu options for the Gramophone. /// </summary> /// <param name="myPawn"></param> /// <returns></returns> public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn) { if (!myPawn.CanReserve(this, 16)) { FloatMenuOption item = new FloatMenuOption("CannotUseReserved".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null); return(new List <FloatMenuOption> { item }); } if (!myPawn.CanReach(this, PathEndMode.InteractionCell, Danger.Some, false, TraverseMode.ByPawn)) { FloatMenuOption item2 = new FloatMenuOption("CannotUseNoPath".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null); return(new List <FloatMenuOption> { item2 }); } if (!myPawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { FloatMenuOption item3 = new FloatMenuOption("CannotUseReason".Translate(new object[] { "IncapableOfCapacity".Translate(new object[] { PawnCapacityDefOf.Manipulation.label }) }), null, MenuOptionPriority.Default, null, null, 0f, null); return(new List <FloatMenuOption> { item3 }); } List <FloatMenuOption> list = new List <FloatMenuOption>(); IntVec3 vec = myPawn.Position; Building t2 = null; if (IsOn() == true) { Action action0 = delegate { Job job = null; if (ListenBuildingUtility.TryFindBestListenCell(this, myPawn, true, out vec, out t2)) { job = new Job(DefDatabase <JobDef> .GetNamed("ListenToGramophone"), this, vec, t2); } else if (ListenBuildingUtility.TryFindBestListenCell(this, myPawn, false, out vec, out t2)) { job = new Job(DefDatabase <JobDef> .GetNamed("ListenToGramophone"), this, vec, t2); } if (job != null) { job.targetB = vec; job.targetC = t2; if (myPawn.jobs.TryTakeOrderedJob(job)) { //Lala } } }; list.Add(new FloatMenuOption("Listen to " + this.Label, action0, MenuOptionPriority.Default, null, null, 0f, null)); Action action0a = delegate { Job job = new Job(DefDatabase <JobDef> .GetNamed("TurnOffGramophone"), this); job.targetA = this; if (myPawn.jobs.TryTakeOrderedJob(job)) { //Lala } }; list.Add(new FloatMenuOption("Turn off " + this.Label, action0a, MenuOptionPriority.Default, null, null, 0f, null)); } if (tuneScape != null) { var tuneDefs = tuneScape.TuneDefCache.Where(x => !x.instrumentOnly); if (tuneDefs.Any()) { foreach (TuneDef def in tuneDefs) { Action actionDef = delegate { Job job = new Job(DefDatabase <JobDef> .GetNamed("PlayGramophone"), this); job.targetA = this; currentTuneDef = def; if (myPawn.jobs.TryTakeOrderedJob(job)) { //Lala } }; list.Add(new FloatMenuOption("Play " + def.LabelCap, actionDef, MenuOptionPriority.Default, null, null, 0f, null)); } } } return(list); }