public override void Draw(SpriteBatch spriteBatch) { bool useAlt = UseAlternateTexture(); int selectedMusic = tMusicPlayer.AllMusic[tMusicPlayer.MusicPlayerUI.DisplayBox].music; int firstBox = tMusicPlayer.MusicPlayerUI.musicData[0].music; int lastBox = tMusicPlayer.MusicPlayerUI.musicData[tMusicPlayer.MusicPlayerUI.musicData.Count - 1].music; bool firstOrLast = (Id == "prev" && selectedMusic == firstBox) || (Id == "next" && selectedMusic == lastBox); int indexPrev = tMusicPlayer.MusicPlayerUI.FindPrevIndex(); int indexNext = tMusicPlayer.MusicPlayerUI.FindNextIndex(); bool firstOrLastUnavail = (Id == "prev" && (indexPrev == -1 || tMusicPlayer.MusicPlayerUI.listening)) || (Id == "next" && (indexNext == -1 || tMusicPlayer.MusicPlayerUI.listening)); MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>(); bool recordUnavail = Id == "record" && modplayer.musicBoxesStored <= 0; bool activeListen = (Id == "next" || Id == "prev" || Id == "play") && tMusicPlayer.MusicPlayerUI.listening; bool musicAtZero = Id != "expand" && Id != "view" && Main.musicVolume <= 0f; bool clearModDisabled = Id == "clearfiltermod" && tMusicPlayer.MusicPlayerUI.FilterMod == ""; bool cannotPlayListMusic = Id.Contains("altplay") && !tMusicPlayer.MusicPlayerUI.canPlay.Contains(Convert.ToInt32(Id.Substring(Id.IndexOf("_") + 1))); bool disabled = firstOrLast | firstOrLastUnavail | recordUnavail | activeListen | musicAtZero | clearModDisabled | cannotPlayListMusic; Rectangle push = new Rectangle(useAlt ? (src.X + src.Width + 2) : src.X, (IsMouseHovering && !disabled) ? (src.Y + src.Height + 2) : src.Y, src.Width, src.Height); CalculatedStyle innerDimensions = GetInnerDimensions(); spriteBatch.Draw(texture, innerDimensions.ToRectangle(), push, disabled ? new Color(60, 60, 60, 60) : Color.White); if (ContainsPoint(Main.MouseScreen) && !PlayerInput.IgnoreMouseInterface) { Main.LocalPlayer.mouseInterface = true; if (tMusicPlayer.tMPConfig.EnableMoreTooltips && Main.SmartCursorEnabled && !disabled) { Main.hoverItemName = SetHoverItemName(Id); } } }
public override void Click(UIMouseEvent evt) { Player player = Main.LocalPlayer; MusicPlayerPlayer modplayer = player.GetModPlayer <MusicPlayerPlayer>(); if (IsMouseHovering && modplayer.musicBoxesStored > 0) { if (Main.mouseItem.IsAir) { Main.mouseItem.SetDefaults(itemID); modplayer.musicBoxesStored--; } while (modplayer.musicBoxesStored > 0) { player.QuickSpawnItem(itemID, 1); modplayer.musicBoxesStored--; } } }
protected override void DrawSelf(SpriteBatch spriteBatch) { CalculatedStyle dimensions = GetDimensions(); Rectangle rectangle = dimensions.ToRectangle(); MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>(); if (ContainsPoint(Main.MouseScreen) && !PlayerInput.IgnoreMouseInterface) { Main.LocalPlayer.mouseInterface = true; if (tMusicPlayer.tMPConfig.EnableMoreTooltips && Main.SmartCursorEnabled) { Main.hoverItemName = "Stored music boxes record songs while recording is enabled\n" + $"Up to {tMusicPlayer.tMPConfig.MaxStorage} music boxes can be held at once\n" + "Right click to take out one music box\nLeft click to take all of them out"; } } base.DrawSelf(spriteBatch); Vector2 pos = new Vector2(rectangle.X + Width.Pixels * 0.75f, rectangle.Y + Height.Pixels * 0.75f); Utils.DrawBorderString(spriteBatch, modplayer.musicBoxesStored.ToString(), pos, Color.White, 0.85f); }
public override void Draw(SpriteBatch spriteBatch) { bool isSelectionSlot = Id.Contains("SelectionSlot"); bool isDisplaySlot = Id == "DisplaySlot"; bool isEntrySlot = Id == "EntrySlot"; float oldScale = Main.inventoryScale; Main.inventoryScale = scale; CalculatedStyle dimensions = GetDimensions(); Rectangle rectangle = dimensions.ToRectangle(); MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>(); if (isDisplaySlot) { if (tMusicPlayer.MusicPlayerUI.listening) { int index = tMusicPlayer.AllMusic.FindIndex((MusicData musicRef) => musicRef.music == Main.curMusic); tMusicPlayer.MusicPlayerUI.ListenDisplay = index; if (index != -1) { itemID = tMusicPlayer.AllMusic[index].musicbox; } } if (!tMusicPlayer.MusicPlayerUI.listening || tMusicPlayer.MusicPlayerUI.ListenDisplay == -1) { tMusicPlayer.MusicPlayerUI.ListenDisplay = -1; itemID = tMusicPlayer.AllMusic[tMusicPlayer.MusicPlayerUI.DisplayBox].musicbox; } } if (!isEntrySlot) { bool HasMusicBox = modplayer.MusicBoxList.Any(item => item.Type == itemID); musicBox.SetDefaults(HasMusicBox ? itemID : 0); } else { if (!musicBox.IsAir) { if (musicBox.type != ItemID.MusicBox) { modplayer.MusicBoxList.Add(new ItemDefinition(musicBox.type)); tMusicPlayer.MusicPlayerUI.canPlay.Add(musicBox.type); tMusicPlayer.SendDebugText($"Added [c/{Utils.Hex3(Color.DarkSeaGreen)}:{musicBox.Name}] [ID#{refItem}]", Colors.RarityGreen); } else if (modplayer.musicBoxesStored < 5) { modplayer.musicBoxesStored++; } musicBox.TurnToAir(); } } if (ContainsPoint(Main.MouseScreen) && !PlayerInput.IgnoreMouseInterface) { Main.LocalPlayer.mouseInterface = true; if (isSelectionSlot && (Main.mouseItem.type == refItem || Main.mouseItem.IsAir) && !Main.mouseRight) { if (Main.mouseLeft) { Main.playerInventory = true; } ItemSlot.Handle(ref musicBox, context); } else if (isEntrySlot) { int mouseType = Main.mouseItem.type; if (mouseType != 0) { bool ValidEntryBox = modplayer.MusicBoxList.All(x => x.Type != mouseType) && tMusicPlayer.AllMusic.Any(y => y.musicbox == mouseType); bool isUnrecordedAndNotMax = mouseType == 576 && modplayer.musicBoxesStored < 5; if (ValidEntryBox | isUnrecordedAndNotMax) { ItemSlot.Handle(ref musicBox, context); } } else { ItemSlot.Handle(ref musicBox, context); } if (tMusicPlayer.tMPConfig.EnableMoreTooltips && Main.SmartCursorEnabled) { Main.hoverItemName = "Insert a music box you do not already own!"; } } } Texture2D backup = Main.inventoryBack2Texture; Main.inventoryBack2Texture = (isEntrySlot ? Main.inventoryBack7Texture : Main.inventoryBack3Texture); ItemSlot.Draw(spriteBatch, ref musicBox, context, Utils.TopLeft(rectangle)); Main.inventoryBack2Texture = backup; Main.inventoryScale = oldScale; if (isSelectionSlot) { int index = tMusicPlayer.AllMusic.FindIndex(x => x.musicbox == refItem); int musicID = tMusicPlayer.AllMusic[index].music; if (musicBox.type == refItem) { if (modplayer.MusicBoxList.All(x => x.Type != refItem)) { modplayer.MusicBoxList.Add(new ItemDefinition(refItem)); tMusicPlayer.MusicPlayerUI.canPlay.Add(musicID); tMusicPlayer.SendDebugText($"Added [c/{Utils.Hex3(Color.DarkSeaGreen)}:{musicBox.Name}] [ID#{refItem}]", Colors.RarityGreen); } if (IsMouseHovering && Main.mouseRight && Id.Contains("Grid")) { tMusicPlayer.MusicPlayerUI.ListenDisplay = -1; tMusicPlayer.MusicPlayerUI.listening = false; tMusicPlayer.MusicPlayerUI.DisplayBox = index; tMusicPlayer.MusicPlayerUI.playingMusic = musicID; } } else if (musicBox.IsAir && ContainsPoint(Main.MouseScreen) && modplayer.MusicBoxList.Any(x => x.Type == refItem)) { modplayer.MusicBoxList.RemoveAll(x => x.Type == refItem); tMusicPlayer.MusicPlayerUI.canPlay.Remove(musicID); // = tMusicPlayer.tMPConfig.EnableAllMusicBoxes; tMusicPlayer.SendDebugText($"Removed Music Box [ID#{refItem}]", Color.IndianRed); if (!tMusicPlayer.MusicPlayerUI.canPlay.Contains(musicID)) { int next = tMusicPlayer.MusicPlayerUI.FindNextIndex(); int prev = tMusicPlayer.MusicPlayerUI.FindPrevIndex(); if (next != -1) { tMusicPlayer.MusicPlayerUI.DisplayBox = next; } else if (prev != -1) { tMusicPlayer.MusicPlayerUI.DisplayBox = prev; } else { tMusicPlayer.MusicPlayerUI.playingMusic = -1; tMusicPlayer.MusicPlayerUI.listening = true; } } } } if (musicBox.IsAir) { int type; if (isDisplaySlot) { if (tMusicPlayer.MusicPlayerUI.listening && Main.musicVolume > 0f && tMusicPlayer.MusicPlayerUI.ListenDisplay != -1) { type = tMusicPlayer.AllMusic[tMusicPlayer.MusicPlayerUI.ListenDisplay].musicbox; } else { if (tMusicPlayer.MusicPlayerUI.DisplayBox == -1) { return; } type = tMusicPlayer.AllMusic[tMusicPlayer.MusicPlayerUI.DisplayBox].musicbox; } } else { type = refItem; } if (type > 0) { float x2 = (rectangle.X + rectangle.Width / 2) - Main.itemTexture[type].Width * scale / 2f; float y2 = (rectangle.Y + rectangle.Height / 2) - Main.itemTexture[type].Height * scale / 2f; spriteBatch.Draw(Main.itemTexture[type], new Vector2(x2, y2), Main.itemTexture[type].Bounds, new Color(75, 75, 75, 75), 0f, Vector2.Zero, scale, 0, 0f); } } return; }
internal void OrganizeSelection(SortBy sortBy, ProgressBy progressBy, string filterMod, bool initializing = false) { int displayMusicID = tMusicPlayer.AllMusic[DisplayBox].music; if (sortBy == SortBy.ID) { musicData = musicData.OrderBy(x => x.music).ToList(); } if (sortBy == SortBy.Name) { musicData = musicData.OrderBy(x => x.name).ToList(); } DisplayBox = tMusicPlayer.AllMusic.FindIndex(x => x.music == displayMusicID); SelectionList.Clear(); if (!viewMode) { // Current view mode is GRID ItemSlotRow newRow = new ItemSlotRow(0, 400, 50); int col = 0; int row = 0; for (int i = 0; i < musicData.Count; i++) { // Filter checks do not happen when initializing // Include all music boxes if FilterMod is left empty // Otherwise find music boxes with the same mod name as the selected filter mod // If Availability isn't 'None' check if the box is obtained or not if (!initializing) { MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>(); bool CheckFilterMod = filterMod != "" && (musicData[i].mod != filterMod); bool CheckObtained = progressBy == ProgressBy.Obtained && modplayer.MusicBoxList.All(x => x.Type != musicData[i].musicbox); bool CheckUnobtained = progressBy == ProgressBy.Unobtained && modplayer.MusicBoxList.Any(x => x.Type == musicData[i].musicbox); if (CheckFilterMod || CheckObtained || CheckUnobtained) { continue; } } SelectionSlots[i] = new MusicBoxSlot(musicData[i].musicbox, 0.85f); SelectionSlots[i].Left.Pixels = 20f + (SelectionSlots[i].Width.Pixels + 10f) * col; SelectionSlots[i].Top.Pixels = (newRow.Height.Pixels / 2f) - (SelectionSlots[i].Height.Pixels / 2f); SelectionSlots[i].Id = $"SelectionSlotGrid_{i}"; newRow.Append(SelectionSlots[i]); col++; if (col == 5) { row++; col = 0; SelectionList.Add(newRow); newRow = new ItemSlotRow(row, 400, 50); } } if (col != 0) { // Add the last row if we did not complete it SelectionList.Add(newRow); } } else { // Current view mode is LIST ItemSlotRow newRow; for (int i = 0; i < musicData.Count; i++) { // Include all music boxes if FilterMod is left empty // Otherwise find music boxes with the same mod name as the selected filter mod // If Availability isn't 'None' check if the box is obtained or not if (!initializing) { MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>(); bool CheckFilterMod = filterMod != "" && (musicData[i].mod != filterMod); bool CheckObtained = progressBy == ProgressBy.Obtained && modplayer.MusicBoxList.All(x => x.Type != musicData[i].musicbox); bool CheckUnobtained = progressBy == ProgressBy.Unobtained && modplayer.MusicBoxList.Any(x => x.Type == musicData[i].musicbox); if (CheckFilterMod || CheckObtained || CheckUnobtained) { continue; } } newRow = new ItemSlotRow(i, panelTextures[2].Bounds.Width, panelTextures[2].Bounds.Height); // Item Slot SelectionSlots[i] = new MusicBoxSlot(musicData[i].musicbox, 0.85f); SelectionSlots[i].Left.Pixels = 20f; SelectionSlots[i].Top.Pixels = (newRow.Height.Pixels / 2f) - (SelectionSlots[i].Height.Pixels / 2f); SelectionSlots[i].Id = $"SelectionSlotList_{i}"; newRow.Append(SelectionSlots[i]); // Play button HoverButton playSong = new HoverButton(buttonTextures, new Rectangle(24, 0, 22, 22)) { Id = $"altplay_{musicData[i].music}", }; playSong.Width.Pixels = 22f; playSong.Height.Pixels = 22f; playSong.Left.Pixels = SelectionSlots[i].Left.Pixels + SelectionSlots[i].Width.Pixels + 8f; playSong.Top.Pixels = (newRow.Height.Pixels / 2f) - (playSong.Height.Pixels / 2f); playSong.OnClick += (a, b) => ListViewPlaySong(playSong.Id); newRow.Append(playSong); // Song name and mod UIText songName = new UIText(musicData[i].name, 0.85f); songName.Left.Pixels = playSong.Left.Pixels + playSong.Width.Pixels + 8f; songName.Top.Pixels = (newRow.Height.Pixels / 2f) - 15f; newRow.Append(songName); UIText songMod = new UIText(musicData[i].mod, 0.85f); songMod.Left.Pixels = playSong.Left.Pixels + playSong.Width.Pixels + 8f; songMod.Top.Pixels = (newRow.Height.Pixels / 2f) + 4f; newRow.Append(songMod); SelectionList.Add(newRow); } } SelectionList.SetScrollbar(selectionScrollBar); }
public override void Update(GameTime gameTime) { // This code mimics the "Music Box Recording" process. // Check if we have music boxes at the ready, if the player is in record mode and music is currently playing. // If all of those apply, we also go a rand check which will trigger the "recording" code. Player player = Main.LocalPlayer; MusicPlayerPlayer modplayer = player.GetModPlayer <MusicPlayerPlayer>(); if (modplayer.musicBoxesStored > 0 && tMusicPlayer.MusicPlayerUI.recording && Main.curMusic > 0 && Main.rand.Next(2700) == 0) { int index = tMusicPlayer.AllMusic.FindIndex(x => x.music == Main.curMusic); // Make sure curMusic is a music box. if (index != -1) { int musicBoxType = tMusicPlayer.AllMusic[index].musicbox; Main.PlaySound(SoundLoader.customSoundType, player.position, ModLoader.GetMod("tMusicPlayer").GetSoundSlot(SoundType.Custom, "Sounds/Custom/recorded")); // TODO: [1.4] Proper PlaySound if (modplayer.MusicBoxList.All(x => x.Type != musicBoxType)) { // If we don't have it in our music player, automatically add it in. modplayer.MusicBoxList.Add(new ItemDefinition(musicBoxType)); } else { // If we do have it already, spawn the item. player.QuickSpawnItem(musicBoxType); } tMusicPlayer.SendDebugText($"Music Box ({tMusicPlayer.AllMusic[index].name}) obtained!", Color.BlanchedAlmond); // Automatically turn recording off and reduce the amount of stored music boxes by 1. tMusicPlayer.MusicPlayerUI.recording = false; modplayer.musicBoxesStored--; } } base.Update(gameTime); if (Main.gameMenu) { playingMusic = -1; ListenDisplay = -1; listening = false; } if (tMusicPlayer.HidePlayerHotkey.JustPressed) { mpToggleVisibility = !mpToggleVisibility; if (mpToggleVisibility) { if (tMusicPlayer.tMPConfig.StartWithSmall != tMusicPlayer.MusicPlayerUI.smallPanel) { tMusicPlayer.MusicPlayerUI.SwapPanelSize(); } } } if (tMusicPlayer.PlayStopHotkey.JustPressed) { ToggleButton(MusicMode.Play); } if (tMusicPlayer.PrevSongHotkey.JustPressed) { ChangeDisplay(false, false); } if (tMusicPlayer.NextSongHotkey.JustPressed) { ChangeDisplay(true, false); } this.AddOrRemoveChild(MusicPlayerPanel, mpToggleVisibility); this.AddOrRemoveChild(musicEntryPanel, selectionVisible); this.AddOrRemoveChild(selectionPanel, selectionVisible); // Update positions of UIElements that are not parented by the main SelectionPanel musicEntryPanel.Left.Pixels = selectionPanel.Left.Pixels - musicEntryPanel.Width.Pixels + 10f; musicEntryPanel.Top.Pixels = selectionPanel.Top.Pixels + 10f; musicEntryPanel.Recalculate(); if (!listening && canPlay.Count == 0) { ToggleButton(MusicMode.Listen); } if (modplayer.musicBoxesStored <= 0) { recording = false; } if (!selectionVisible) { searchBar.currentString = ""; OrganizeSelection(sortType, availabililty, FilterMod); } }