Исходник MusicPlayerUI upgrade | Expensive 3.1

Начинающий
Статус
Оффлайн
Регистрация
12 Дек 2022
Сообщения
116
Реакции[?]
0
Поинты[?]
0

Перед прочтением основного контента ниже, пожалуйста, обратите внимание на обновление внутри секции Майна на нашем форуме. У нас появились:

  • бесплатные читы для Майнкрафт — любое использование на свой страх и риск;
  • маркетплейс Майнкрафт — абсолютно любая коммерция, связанная с игрой, за исключением продажи читов (аккаунты, предоставления услуг, поиск кодеров читов и так далее);
  • приватные читы для Minecraft — в этом разделе только платные хаки для игры, покупайте группу "Продавец" и выставляйте на продажу свой софт;
  • обсуждения и гайды — всё тот же раздел с вопросами, но теперь модернизированный: поиск нужных хаков, пати с игроками-читерами и другая полезная информация.

Спасибо!

крч вот ориг тема (noad)
я сделал скролл и картинки
Пожалуйста, авторизуйтесь для просмотра ссылки.

Пожалуйста, авторизуйтесь для просмотра ссылки.

шрифт регать в Fonts.java (im/expensive/utils/render/font) вот так:
добавляем в public static Font вконце test1488
и в public static void register() { добавляем перед "}":
test1488 = new Font("nurik.png", "nurik.json");

MusicPlayerUI (не функция).java:
package im.expensive.ui.musicplayer;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;
import javax.sound.sampled.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayerUI extends Screen implements IMinecraft {
    private List<File> musicFiles = new ArrayList<>();

    private File musicDirectory = new File("assets/skins/0/music");

    private String message = "Папка с музыкой пуста =(";

    final ResourceLocation folder = new ResourceLocation("expensive/images/musicplayer/folder.png");

    final ResourceLocation play = new ResourceLocation("expensive/images/musicplayer/play.png");

    final ResourceLocation pause = new ResourceLocation("expensive/images/musicplayer/pause.png");

    final ResourceLocation repeat = new ResourceLocation("expensive/images/musicplayer/repeat.png");

    final ResourceLocation yes = new ResourceLocation("expensive/images/musicplayer/yes.png");

    private int selectedMusicIndex = -1;
    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;
    private int scrollOffset = 0;
    private int maxVisibleItems = 10;
    private float itemHeight = 25f;
    float iconSizeX = 10;
    float iconSizeY = 10;

    private enum Category {
        LOCAL
    }

    private Category currentCategory = Category.LOCAL;

    public MusicPlayerUI(ITextComponent titleIn) {

        super(titleIn);

    }

    @Override
    protected void init() {

        super.init();

        loadMusicFiles();
    }

    private void loadMusicFiles() {
        musicFiles.clear();

        try {

            if (currentCategory == Category.LOCAL) {

                if (musicDirectory.exists() && musicDirectory.isDirectory()) {

                    File[] files = musicDirectory.listFiles((dir, name) -> name.endsWith(".wav"));

                    if (files != null) {

                        for (File file : files) {

                            musicFiles.add(file);

                        }

                    }

                }

                if (!musicDirectory.exists()) {

                    musicDirectory.mkdir();

                }

                if (musicFiles.isEmpty()) {

                    message = "Папка с музыкой пуста =(\n";

                }

            }

        } catch (Exception e) {

            e.printStackTrace();

            message = "Произошла ошибка при загрузке треков.";

            musicFiles.clear();

        }

    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);

        int windowWidth = mc.getMainWindow().getScaledWidth();
        int windowHeight = mc.getMainWindow().getScaledHeight();
        float width = 400;
        float height = 400;
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;

        DisplayUtils.drawShadow(x, y, width, height, 10, ColorUtils.rgba(17, 17, 17, 128));

        DisplayUtils.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtils.rgba(17, 17, 17, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f, y + 10, ColorUtils.rgb(255, 255, 255), 12);

        //drawCategoryButton(matrixStack, x + 20, y + 10, "Локальный", currentCategory == Category.LOCAL);

        float openFolderX = x + width - 65 + 1;

        float openFolderY = y + 8;//10;

        float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

        //DisplayUtils.drawRoundedRect(openFolderX, openFolderY, folderTextWidth + 10, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        DisplayUtils.drawRoundedRect(openFolderX + 35, openFolderY, 20, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        //Fonts.montserrat.drawText(matrixStack, "Папка", openFolderX + 5, openFolderY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(folder, openFolderX + 40, openFolderY + 5, 10f, 10f, ColorUtils.rgb(255, 255, 255));

        if (musicFiles.isEmpty()) {

            String message2 = "чтобы добавить музыку, поместите её в папку";

            String message3 = "assets/skins/0/music в формате .wav";

            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message2, x + width / 2f, y + height / 2f - 17.5f, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message3, x + width / 2f, y + height / 2f - 5, ColorUtils.rgb(255, 0, 0), 12);

        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 60, width + 300, height - 10);
            float listX = x + 20;
            float listY = y + 40;

            int visibleItems = 10;

            int maxScroll = Math.max(0, musicFiles.size() - visibleItems);

            int scrollOffset1 = Math.max(0, Math.min(scrollOffset, maxScroll));

            int startIndex = Math.max(0, scrollOffset1);

            int endIndex = Math.min(musicFiles.size(), startIndex + visibleItems);

            for (int i = startIndex; i < endIndex; i++) {

                File music = musicFiles.get(i);

                int yOffset = (int) (listY + (i - startIndex) * 25);

                boolean hovered = MathUtil.isHovered(mouseX, mouseY, listX, listY + (i) * 25, width - 40, 25);

                if (hovered) {
                    DisplayUtils.drawRoundedRect(listX, listY + i * 25, width - 40, 25, 3, ColorUtils.rgba(30, 30, 30, 255));
                }
                String songName = trimSongName(music.getName().replaceAll("\\.wav", ""), width - 80);

                Fonts.montserrat.drawText(matrixStack, songName, listX + 5, listY + (i - startIndex) * itemHeight + 5, ColorUtils.rgb(255, 255, 255), 10);

                if (selectedMusicIndex == i) {

                    DisplayUtils.drawImage(yes, listX + width - 65, listY + (i - startIndex) * itemHeight + 1, 20, 20, ColorUtils.rgb(0, 255, 0));

                    //Fonts.montserrat.drawText(matrixStack, "Выбрано", listX + width - 100, listY + i * 25 + 5, ColorUtils.rgb(0, 255, 0), 10);
                }
            }
            Scissor.unset();
            Scissor.pop();

            renderPlayerPanel(matrixStack, x, y, width, height);
        }

        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

    private void drawCategoryButton(MatrixStack matrixStack, float x, float y, String label, boolean selected) {
        int buttonColor = selected ? ColorUtils.rgba(60, 60, 60, 255) : ColorUtils.rgba(30, 30, 30, 255);

        //DisplayUtils.drawRoundedRect(x, y, 90, 20, 5, buttonColor);

        DisplayUtils.drawRoundedRect(x, y, Fonts.montserrat.getWidth(label, 10) + 22.5f, 20, 5, buttonColor);

        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtils.rgb(255, 255, 255), 10);
    }

    private String trimSongName(String name, float maxWidth) {

        float textWidth = Fonts.montserrat.getWidth(name, 10);

        if (textWidth > maxWidth) {

            while (textWidth > maxWidth && name.length() > 3) {

                name = name.substring(0, name.length() - 1);

                textWidth = Fonts.montserrat.getWidth(name + "...", 10);

            }

            name += "...";

        }

        return name;

    }

    private void renderPlayerPanel(MatrixStack matrixStack, float x, float y, float width, float height) {
        float panelHeight = 100;
        float panelY = y + height - panelHeight - 10;
        if (selectedMusicIndex != -1) {
            DisplayUtils.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtils.rgba(30, 30, 30, 255));
            renderPlayer(matrixStack, x + 10, panelY, width - 20, panelHeight);
        }
    }

    private void renderPlayer(MatrixStack matrixStack, float x, float y, float width, float height) {
        String songName = trimSongName(musicFiles.get(selectedMusicIndex).getName().replaceAll("\\.wav", ""), width - 80);
        Fonts.montserrat.drawText(matrixStack, songName, x + 10, y + 35, ColorUtils.rgb(255, 255, 255), 12);
        float buttonSize = 20;
        float buttonSpacing = 10;
        float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

        float prevButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, isPlaying ? "| |" : ">", playPauseButtonX + buttonSize / 2f, playPauseButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(isPlaying ? pause : play, playPauseButtonX + buttonSize / 2f - 5, playPauseButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));
       
        float nextButtonX = x + width / 2f + buttonSpacing + 5;

        float nextButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, ">", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
       
        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

        float repeatButtonY = nextButtonY;

        int repeatButtonColor = isRepeat ? ColorUtils.rgba(0, 0, 255, 255) : ColorUtils.rgba(60, 60, 60, 255);

        DisplayUtils.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);

        DisplayUtils.drawImage(repeat, repeatButtonX + buttonSize / 2f - 5, repeatButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, "R", repeatButtonX + buttonSize / 2f, repeatButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 55;

        float volumeSliderY = y + height / 2f - 4 + 10;

        float volumeSliderWidth = width / 4f - 15;

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtils.rgba(0, 255, 0, 255));
       
        float timeSliderX = x + 10;

        float timeSliderY = y + height - 20;

        float timeSliderWidth = width - 20;

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtils.rgba(0, 255, 0, 255));
       
        float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

        DisplayUtils.drawRoundedRect(closeButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.test1488.drawCenteredText(matrixStack, "U", closeButtonX + buttonSize / 2f - 1, repeatButtonY + 6f, ColorUtils.rgb(255, 255, 255), 10);
    }

    public float getCurrentPlaybackPosition() {

        if (clip != null) {

            return clip.getMicrosecondPosition() / (float) clip.getMicrosecondLength();

        }

        return 0;

    }

    public String getCurrentSongName() {

        if (selectedMusicIndex != -1 && selectedMusicIndex < musicFiles.size()) {

            return musicFiles.get(selectedMusicIndex).getName().replace(".wav", "");

        }

        return "";

    }

    @Override

    public boolean mouseClicked(double mouseX, double mouseY, int button) {

        if (button == 0) {

            float windowWidth = mc.getMainWindow().getScaledWidth();

            float windowHeight = mc.getMainWindow().getScaledHeight();
           
            float width = 400;

            float height = 400;

            float x = windowWidth / 2f - width / 2f;

            float y = windowHeight / 2f - height / 2f;

            float panelHeight = 100;

            float panelY = y + height - panelHeight - 10;

            float buttonSize = 20;

            float buttonSpacing = 10;

            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, prevButtonX, prevButtonY, buttonSize, buttonSize)) {

                selectPreviousMusic();

                return true;

            }
           
            float playPauseButtonX = x + width / 2f - buttonSize / 2f;

            float playPauseButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, playPauseButtonX, playPauseButtonY, buttonSize, buttonSize)) {

                togglePlayPause();

                return true;

            }
           
            float nextButtonX = x + width / 2f + buttonSpacing + 5;

            float nextButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {

                selectNextMusic();

                return true;

            }

            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

            float repeatButtonY = nextButtonY;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {

                isRepeat = !isRepeat;

                return true;

            }

            float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 53;

            float volumeSliderY = panelY + panelHeight / 2f - 5 + 10;

            float volumeSliderWidth = width / 4f - 15;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {

                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);

                setVolume(volume);

                return true;

            }

            float timeSliderX = x + 8;

            float timeSliderY = panelY + panelHeight - 20;

            float timeSliderWidth = width - 20;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {

                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));

                return true;

            }

            float openFolderX = x + width - 30          + 1.5f;

            float openFolderY = y + 8;//10;

            float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

            //if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX - folderTextWidth, openFolderY, buttonSize + folderTextWidth, buttonSize)) {

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, 20, 20)) {

                openMusicFolder();

                return true;

            }

            float listY = y + 40;

            for (int i = 0; i < musicFiles.size(); i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + i * 25, width - 40, 25) && scrollOffset == 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }
            float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, closeButtonX, prevButtonY, buttonSize, buttonSize)) {

                clip.stop();

                clip.close();

                clip = null;

                selectedMusicIndex = -1;

                return true;

            }
            int startIndex = scrollOffset;

            int endIndex = Math.min(startIndex + maxVisibleItems, musicFiles.size());
            for (int i = startIndex; i < endIndex; i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + (i - startIndex) * itemHeight, width - 40, itemHeight) && scrollOffset > 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }

        }
        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {

        int maxOffset = musicFiles.size() - maxVisibleItems;

        if (maxOffset > 0) {

            scrollOffset = (int) MathUtil.clamp(scrollOffset - (int) delta, 0, maxOffset);

        }

        handleMouseWheel((int) delta);

        return super.mouseScrolled(mouseX, mouseY, delta);

    }

    public void handleMouseWheel(int delta) {
        scrollOffset -= delta * 3;
        scrollOffset = Math.max(0, Math.min(scrollOffset, Math.max(0, musicFiles.size() - 10)));

    }

    private void selectPreviousMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex > 0) {

            selectedMusicIndex--;

        } else {

            selectedMusicIndex = musicFiles.size() - 1;

        }

        playSelectedMusic();

    }

    private void selectNextMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex < musicFiles.size() - 1) {

            selectedMusicIndex++;

        } else {

            selectedMusicIndex = 0;

        }

        playSelectedMusic();

    }

    private void togglePlayPause() {

        if (clip == null) return;

        if (isPlaying) {

            clip.stop();

            isPlaying = false;

        } else {

            clip.setFramePosition(clip.getFramePosition());

            clip.start();

            isPlaying = true;

        }

    }

    private void openMusicFolder() {

        try {

            Runtime.getRuntime().exec("explorer " + musicDirectory.getAbsolutePath());

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    private void setVolume(float volume) {

        if (clip != null && clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {

            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

            float dB = (float) (Math.log(volume) / Math.log(10) * 20);

            gainControl.setValue(dB);

        }

    }

    private void seek(float position) {

        if (clip != null) {

            clip.setMicrosecondPosition((long) (clip.getMicrosecondLength() * position));

        }

    }

    public boolean isVisible() {

        return this.minecraft.currentScreen == this;

    }

    public boolean isPlaying() {

        return isPlaying;

    }

    private void playSelectedMusic() {

        if (selectedMusicIndex == -1 || musicFiles.isEmpty()) return;



        if (clip != null && clip.isOpen()) {

            clip.stop();

            clip.close();

        }

        File music = musicFiles.get(selectedMusicIndex);

        try {

            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(music);

            clip = AudioSystem.getClip();

            clip.open(audioInputStream);

            setVolume(volume);

            isPlaying = true;

            clip.addLineListener(event -> {

                if (event.getType() == LineEvent.Type.STOP && isPlaying) {

                    if (clip.getMicrosecondPosition() >= clip.getMicrosecondLength()) {

                        if (isRepeat) {

                            clip.setFramePosition(0);

                            clip.start();

                        } else {
                            selectNextMusic();
                        }

                    }

                }

            });
            clip.start();

        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }

}
 
Начинающий
Статус
Оффлайн
Регистрация
10 Фев 2024
Сообщения
166
Реакции[?]
2
Поинты[?]
2K
крч вот ориг тема (noad)
я сделал скролл и картинки
Пожалуйста, авторизуйтесь для просмотра ссылки.

Пожалуйста, авторизуйтесь для просмотра ссылки.

шрифт регать в Fonts.java (im/expensive/utils/render/font) вот так:
добавляем в public static Font вконце test1488
и в public static void register() { добавляем перед "}":
test1488 = new Font("nurik.png", "nurik.json");

MusicPlayerUI (не функция).java:
package im.expensive.ui.musicplayer;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;
import javax.sound.sampled.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayerUI extends Screen implements IMinecraft {
    private List<File> musicFiles = new ArrayList<>();

    private File musicDirectory = new File("assets/skins/0/music");

    private String message = "Папка с музыкой пуста =(";

    final ResourceLocation folder = new ResourceLocation("expensive/images/musicplayer/folder.png");

    final ResourceLocation play = new ResourceLocation("expensive/images/musicplayer/play.png");

    final ResourceLocation pause = new ResourceLocation("expensive/images/musicplayer/pause.png");

    final ResourceLocation repeat = new ResourceLocation("expensive/images/musicplayer/repeat.png");

    final ResourceLocation yes = new ResourceLocation("expensive/images/musicplayer/yes.png");

    private int selectedMusicIndex = -1;
    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;
    private int scrollOffset = 0;
    private int maxVisibleItems = 10;
    private float itemHeight = 25f;
    float iconSizeX = 10;
    float iconSizeY = 10;

    private enum Category {
        LOCAL
    }

    private Category currentCategory = Category.LOCAL;

    public MusicPlayerUI(ITextComponent titleIn) {

        super(titleIn);

    }

    @Override
    protected void init() {

        super.init();

        loadMusicFiles();
    }

    private void loadMusicFiles() {
        musicFiles.clear();

        try {

            if (currentCategory == Category.LOCAL) {

                if (musicDirectory.exists() && musicDirectory.isDirectory()) {

                    File[] files = musicDirectory.listFiles((dir, name) -> name.endsWith(".wav"));

                    if (files != null) {

                        for (File file : files) {

                            musicFiles.add(file);

                        }

                    }

                }

                if (!musicDirectory.exists()) {

                    musicDirectory.mkdir();

                }

                if (musicFiles.isEmpty()) {

                    message = "Папка с музыкой пуста =(\n";

                }

            }

        } catch (Exception e) {

            e.printStackTrace();

            message = "Произошла ошибка при загрузке треков.";

            musicFiles.clear();

        }

    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);

        int windowWidth = mc.getMainWindow().getScaledWidth();
        int windowHeight = mc.getMainWindow().getScaledHeight();
        float width = 400;
        float height = 400;
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;

        DisplayUtils.drawShadow(x, y, width, height, 10, ColorUtils.rgba(17, 17, 17, 128));

        DisplayUtils.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtils.rgba(17, 17, 17, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f, y + 10, ColorUtils.rgb(255, 255, 255), 12);

        //drawCategoryButton(matrixStack, x + 20, y + 10, "Локальный", currentCategory == Category.LOCAL);

        float openFolderX = x + width - 65 + 1;

        float openFolderY = y + 8;//10;

        float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

        //DisplayUtils.drawRoundedRect(openFolderX, openFolderY, folderTextWidth + 10, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        DisplayUtils.drawRoundedRect(openFolderX + 35, openFolderY, 20, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        //Fonts.montserrat.drawText(matrixStack, "Папка", openFolderX + 5, openFolderY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(folder, openFolderX + 40, openFolderY + 5, 10f, 10f, ColorUtils.rgb(255, 255, 255));

        if (musicFiles.isEmpty()) {

            String message2 = "чтобы добавить музыку, поместите её в папку";

            String message3 = "assets/skins/0/music в формате .wav";

            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message2, x + width / 2f, y + height / 2f - 17.5f, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message3, x + width / 2f, y + height / 2f - 5, ColorUtils.rgb(255, 0, 0), 12);

        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 60, width + 300, height - 10);
            float listX = x + 20;
            float listY = y + 40;

            int visibleItems = 10;

            int maxScroll = Math.max(0, musicFiles.size() - visibleItems);

            int scrollOffset1 = Math.max(0, Math.min(scrollOffset, maxScroll));

            int startIndex = Math.max(0, scrollOffset1);

            int endIndex = Math.min(musicFiles.size(), startIndex + visibleItems);

            for (int i = startIndex; i < endIndex; i++) {

                File music = musicFiles.get(i);

                int yOffset = (int) (listY + (i - startIndex) * 25);

                boolean hovered = MathUtil.isHovered(mouseX, mouseY, listX, listY + (i) * 25, width - 40, 25);

                if (hovered) {
                    DisplayUtils.drawRoundedRect(listX, listY + i * 25, width - 40, 25, 3, ColorUtils.rgba(30, 30, 30, 255));
                }
                String songName = trimSongName(music.getName().replaceAll("\\.wav", ""), width - 80);

                Fonts.montserrat.drawText(matrixStack, songName, listX + 5, listY + (i - startIndex) * itemHeight + 5, ColorUtils.rgb(255, 255, 255), 10);

                if (selectedMusicIndex == i) {

                    DisplayUtils.drawImage(yes, listX + width - 65, listY + (i - startIndex) * itemHeight + 1, 20, 20, ColorUtils.rgb(0, 255, 0));

                    //Fonts.montserrat.drawText(matrixStack, "Выбрано", listX + width - 100, listY + i * 25 + 5, ColorUtils.rgb(0, 255, 0), 10);
                }
            }
            Scissor.unset();
            Scissor.pop();

            renderPlayerPanel(matrixStack, x, y, width, height);
        }

        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

    private void drawCategoryButton(MatrixStack matrixStack, float x, float y, String label, boolean selected) {
        int buttonColor = selected ? ColorUtils.rgba(60, 60, 60, 255) : ColorUtils.rgba(30, 30, 30, 255);

        //DisplayUtils.drawRoundedRect(x, y, 90, 20, 5, buttonColor);

        DisplayUtils.drawRoundedRect(x, y, Fonts.montserrat.getWidth(label, 10) + 22.5f, 20, 5, buttonColor);

        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtils.rgb(255, 255, 255), 10);
    }

    private String trimSongName(String name, float maxWidth) {

        float textWidth = Fonts.montserrat.getWidth(name, 10);

        if (textWidth > maxWidth) {

            while (textWidth > maxWidth && name.length() > 3) {

                name = name.substring(0, name.length() - 1);

                textWidth = Fonts.montserrat.getWidth(name + "...", 10);

            }

            name += "...";

        }

        return name;

    }

    private void renderPlayerPanel(MatrixStack matrixStack, float x, float y, float width, float height) {
        float panelHeight = 100;
        float panelY = y + height - panelHeight - 10;
        if (selectedMusicIndex != -1) {
            DisplayUtils.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtils.rgba(30, 30, 30, 255));
            renderPlayer(matrixStack, x + 10, panelY, width - 20, panelHeight);
        }
    }

    private void renderPlayer(MatrixStack matrixStack, float x, float y, float width, float height) {
        String songName = trimSongName(musicFiles.get(selectedMusicIndex).getName().replaceAll("\\.wav", ""), width - 80);
        Fonts.montserrat.drawText(matrixStack, songName, x + 10, y + 35, ColorUtils.rgb(255, 255, 255), 12);
        float buttonSize = 20;
        float buttonSpacing = 10;
        float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

        float prevButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, isPlaying ? "| |" : ">", playPauseButtonX + buttonSize / 2f, playPauseButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(isPlaying ? pause : play, playPauseButtonX + buttonSize / 2f - 5, playPauseButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));
      
        float nextButtonX = x + width / 2f + buttonSpacing + 5;

        float nextButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, ">", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
      
        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

        float repeatButtonY = nextButtonY;

        int repeatButtonColor = isRepeat ? ColorUtils.rgba(0, 0, 255, 255) : ColorUtils.rgba(60, 60, 60, 255);

        DisplayUtils.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);

        DisplayUtils.drawImage(repeat, repeatButtonX + buttonSize / 2f - 5, repeatButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, "R", repeatButtonX + buttonSize / 2f, repeatButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 55;

        float volumeSliderY = y + height / 2f - 4 + 10;

        float volumeSliderWidth = width / 4f - 15;

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtils.rgba(0, 255, 0, 255));
      
        float timeSliderX = x + 10;

        float timeSliderY = y + height - 20;

        float timeSliderWidth = width - 20;

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtils.rgba(0, 255, 0, 255));
      
        float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

        DisplayUtils.drawRoundedRect(closeButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.test1488.drawCenteredText(matrixStack, "U", closeButtonX + buttonSize / 2f - 1, repeatButtonY + 6f, ColorUtils.rgb(255, 255, 255), 10);
    }

    public float getCurrentPlaybackPosition() {

        if (clip != null) {

            return clip.getMicrosecondPosition() / (float) clip.getMicrosecondLength();

        }

        return 0;

    }

    public String getCurrentSongName() {

        if (selectedMusicIndex != -1 && selectedMusicIndex < musicFiles.size()) {

            return musicFiles.get(selectedMusicIndex).getName().replace(".wav", "");

        }

        return "";

    }

    @Override

    public boolean mouseClicked(double mouseX, double mouseY, int button) {

        if (button == 0) {

            float windowWidth = mc.getMainWindow().getScaledWidth();

            float windowHeight = mc.getMainWindow().getScaledHeight();
          
            float width = 400;

            float height = 400;

            float x = windowWidth / 2f - width / 2f;

            float y = windowHeight / 2f - height / 2f;

            float panelHeight = 100;

            float panelY = y + height - panelHeight - 10;

            float buttonSize = 20;

            float buttonSpacing = 10;

            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, prevButtonX, prevButtonY, buttonSize, buttonSize)) {

                selectPreviousMusic();

                return true;

            }
          
            float playPauseButtonX = x + width / 2f - buttonSize / 2f;

            float playPauseButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, playPauseButtonX, playPauseButtonY, buttonSize, buttonSize)) {

                togglePlayPause();

                return true;

            }
          
            float nextButtonX = x + width / 2f + buttonSpacing + 5;

            float nextButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {

                selectNextMusic();

                return true;

            }

            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

            float repeatButtonY = nextButtonY;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {

                isRepeat = !isRepeat;

                return true;

            }

            float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 53;

            float volumeSliderY = panelY + panelHeight / 2f - 5 + 10;

            float volumeSliderWidth = width / 4f - 15;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {

                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);

                setVolume(volume);

                return true;

            }

            float timeSliderX = x + 8;

            float timeSliderY = panelY + panelHeight - 20;

            float timeSliderWidth = width - 20;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {

                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));

                return true;

            }

            float openFolderX = x + width - 30          + 1.5f;

            float openFolderY = y + 8;//10;

            float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

            //if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX - folderTextWidth, openFolderY, buttonSize + folderTextWidth, buttonSize)) {

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, 20, 20)) {

                openMusicFolder();

                return true;

            }

            float listY = y + 40;

            for (int i = 0; i < musicFiles.size(); i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + i * 25, width - 40, 25) && scrollOffset == 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }
            float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, closeButtonX, prevButtonY, buttonSize, buttonSize)) {

                clip.stop();

                clip.close();

                clip = null;

                selectedMusicIndex = -1;

                return true;

            }
            int startIndex = scrollOffset;

            int endIndex = Math.min(startIndex + maxVisibleItems, musicFiles.size());
            for (int i = startIndex; i < endIndex; i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + (i - startIndex) * itemHeight, width - 40, itemHeight) && scrollOffset > 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }

        }
        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {

        int maxOffset = musicFiles.size() - maxVisibleItems;

        if (maxOffset > 0) {

            scrollOffset = (int) MathUtil.clamp(scrollOffset - (int) delta, 0, maxOffset);

        }

        handleMouseWheel((int) delta);

        return super.mouseScrolled(mouseX, mouseY, delta);

    }

    public void handleMouseWheel(int delta) {
        scrollOffset -= delta * 3;
        scrollOffset = Math.max(0, Math.min(scrollOffset, Math.max(0, musicFiles.size() - 10)));

    }

    private void selectPreviousMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex > 0) {

            selectedMusicIndex--;

        } else {

            selectedMusicIndex = musicFiles.size() - 1;

        }

        playSelectedMusic();

    }

    private void selectNextMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex < musicFiles.size() - 1) {

            selectedMusicIndex++;

        } else {

            selectedMusicIndex = 0;

        }

        playSelectedMusic();

    }

    private void togglePlayPause() {

        if (clip == null) return;

        if (isPlaying) {

            clip.stop();

            isPlaying = false;

        } else {

            clip.setFramePosition(clip.getFramePosition());

            clip.start();

            isPlaying = true;

        }

    }

    private void openMusicFolder() {

        try {

            Runtime.getRuntime().exec("explorer " + musicDirectory.getAbsolutePath());

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    private void setVolume(float volume) {

        if (clip != null && clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {

            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

            float dB = (float) (Math.log(volume) / Math.log(10) * 20);

            gainControl.setValue(dB);

        }

    }

    private void seek(float position) {

        if (clip != null) {

            clip.setMicrosecondPosition((long) (clip.getMicrosecondLength() * position));

        }

    }

    public boolean isVisible() {

        return this.minecraft.currentScreen == this;

    }

    public boolean isPlaying() {

        return isPlaying;

    }

    private void playSelectedMusic() {

        if (selectedMusicIndex == -1 || musicFiles.isEmpty()) return;



        if (clip != null && clip.isOpen()) {

            clip.stop();

            clip.close();

        }

        File music = musicFiles.get(selectedMusicIndex);

        try {

            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(music);

            clip = AudioSystem.getClip();

            clip.open(audioInputStream);

            setVolume(volume);

            isPlaying = true;

            clip.addLineListener(event -> {

                if (event.getType() == LineEvent.Type.STOP && isPlaying) {

                    if (clip.getMicrosecondPosition() >= clip.getMicrosecondLength()) {

                        if (isRepeat) {

                            clip.setFramePosition(0);

                            clip.start();

                        } else {
                            selectNextMusic();
                        }

                    }

                }

            });
            clip.start();

        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }

}
ss?
 
Начинающий
Статус
Оффлайн
Регистрация
6 Дек 2023
Сообщения
213
Реакции[?]
1
Поинты[?]
1K
крч вот ориг тема (noad)
я сделал скролл и картинки
Пожалуйста, авторизуйтесь для просмотра ссылки.

Пожалуйста, авторизуйтесь для просмотра ссылки.

шрифт регать в Fonts.java (im/expensive/utils/render/font) вот так:
добавляем в public static Font вконце test1488
и в public static void register() { добавляем перед "}":
test1488 = new Font("nurik.png", "nurik.json");

MusicPlayerUI (не функция).java:
package im.expensive.ui.musicplayer;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;
import javax.sound.sampled.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayerUI extends Screen implements IMinecraft {
    private List<File> musicFiles = new ArrayList<>();

    private File musicDirectory = new File("assets/skins/0/music");

    private String message = "Папка с музыкой пуста =(";

    final ResourceLocation folder = new ResourceLocation("expensive/images/musicplayer/folder.png");

    final ResourceLocation play = new ResourceLocation("expensive/images/musicplayer/play.png");

    final ResourceLocation pause = new ResourceLocation("expensive/images/musicplayer/pause.png");

    final ResourceLocation repeat = new ResourceLocation("expensive/images/musicplayer/repeat.png");

    final ResourceLocation yes = new ResourceLocation("expensive/images/musicplayer/yes.png");

    private int selectedMusicIndex = -1;
    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;
    private int scrollOffset = 0;
    private int maxVisibleItems = 10;
    private float itemHeight = 25f;
    float iconSizeX = 10;
    float iconSizeY = 10;

    private enum Category {
        LOCAL
    }

    private Category currentCategory = Category.LOCAL;

    public MusicPlayerUI(ITextComponent titleIn) {

        super(titleIn);

    }

    @Override
    protected void init() {

        super.init();

        loadMusicFiles();
    }

    private void loadMusicFiles() {
        musicFiles.clear();

        try {

            if (currentCategory == Category.LOCAL) {

                if (musicDirectory.exists() && musicDirectory.isDirectory()) {

                    File[] files = musicDirectory.listFiles((dir, name) -> name.endsWith(".wav"));

                    if (files != null) {

                        for (File file : files) {

                            musicFiles.add(file);

                        }

                    }

                }

                if (!musicDirectory.exists()) {

                    musicDirectory.mkdir();

                }

                if (musicFiles.isEmpty()) {

                    message = "Папка с музыкой пуста =(\n";

                }

            }

        } catch (Exception e) {

            e.printStackTrace();

            message = "Произошла ошибка при загрузке треков.";

            musicFiles.clear();

        }

    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);

        int windowWidth = mc.getMainWindow().getScaledWidth();
        int windowHeight = mc.getMainWindow().getScaledHeight();
        float width = 400;
        float height = 400;
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;

        DisplayUtils.drawShadow(x, y, width, height, 10, ColorUtils.rgba(17, 17, 17, 128));

        DisplayUtils.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtils.rgba(17, 17, 17, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f, y + 10, ColorUtils.rgb(255, 255, 255), 12);

        //drawCategoryButton(matrixStack, x + 20, y + 10, "Локальный", currentCategory == Category.LOCAL);

        float openFolderX = x + width - 65 + 1;

        float openFolderY = y + 8;//10;

        float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

        //DisplayUtils.drawRoundedRect(openFolderX, openFolderY, folderTextWidth + 10, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        DisplayUtils.drawRoundedRect(openFolderX + 35, openFolderY, 20, 20, 5, ColorUtils.rgba(30, 30, 30, 255));

        //Fonts.montserrat.drawText(matrixStack, "Папка", openFolderX + 5, openFolderY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(folder, openFolderX + 40, openFolderY + 5, 10f, 10f, ColorUtils.rgb(255, 255, 255));

        if (musicFiles.isEmpty()) {

            String message2 = "чтобы добавить музыку, поместите её в папку";

            String message3 = "assets/skins/0/music в формате .wav";

            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message2, x + width / 2f, y + height / 2f - 17.5f, ColorUtils.rgb(255, 0, 0), 12);

            Fonts.montserrat.drawCenteredText(matrixStack, message3, x + width / 2f, y + height / 2f - 5, ColorUtils.rgb(255, 0, 0), 12);

        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 60, width + 300, height - 10);
            float listX = x + 20;
            float listY = y + 40;

            int visibleItems = 10;

            int maxScroll = Math.max(0, musicFiles.size() - visibleItems);

            int scrollOffset1 = Math.max(0, Math.min(scrollOffset, maxScroll));

            int startIndex = Math.max(0, scrollOffset1);

            int endIndex = Math.min(musicFiles.size(), startIndex + visibleItems);

            for (int i = startIndex; i < endIndex; i++) {

                File music = musicFiles.get(i);

                int yOffset = (int) (listY + (i - startIndex) * 25);

                boolean hovered = MathUtil.isHovered(mouseX, mouseY, listX, listY + (i) * 25, width - 40, 25);

                if (hovered) {
                    DisplayUtils.drawRoundedRect(listX, listY + i * 25, width - 40, 25, 3, ColorUtils.rgba(30, 30, 30, 255));
                }
                String songName = trimSongName(music.getName().replaceAll("\\.wav", ""), width - 80);

                Fonts.montserrat.drawText(matrixStack, songName, listX + 5, listY + (i - startIndex) * itemHeight + 5, ColorUtils.rgb(255, 255, 255), 10);

                if (selectedMusicIndex == i) {

                    DisplayUtils.drawImage(yes, listX + width - 65, listY + (i - startIndex) * itemHeight + 1, 20, 20, ColorUtils.rgb(0, 255, 0));

                    //Fonts.montserrat.drawText(matrixStack, "Выбрано", listX + width - 100, listY + i * 25 + 5, ColorUtils.rgb(0, 255, 0), 10);
                }
            }
            Scissor.unset();
            Scissor.pop();

            renderPlayerPanel(matrixStack, x, y, width, height);
        }

        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

    private void drawCategoryButton(MatrixStack matrixStack, float x, float y, String label, boolean selected) {
        int buttonColor = selected ? ColorUtils.rgba(60, 60, 60, 255) : ColorUtils.rgba(30, 30, 30, 255);

        //DisplayUtils.drawRoundedRect(x, y, 90, 20, 5, buttonColor);

        DisplayUtils.drawRoundedRect(x, y, Fonts.montserrat.getWidth(label, 10) + 22.5f, 20, 5, buttonColor);

        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtils.rgb(255, 255, 255), 10);
    }

    private String trimSongName(String name, float maxWidth) {

        float textWidth = Fonts.montserrat.getWidth(name, 10);

        if (textWidth > maxWidth) {

            while (textWidth > maxWidth && name.length() > 3) {

                name = name.substring(0, name.length() - 1);

                textWidth = Fonts.montserrat.getWidth(name + "...", 10);

            }

            name += "...";

        }

        return name;

    }

    private void renderPlayerPanel(MatrixStack matrixStack, float x, float y, float width, float height) {
        float panelHeight = 100;
        float panelY = y + height - panelHeight - 10;
        if (selectedMusicIndex != -1) {
            DisplayUtils.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtils.rgba(30, 30, 30, 255));
            renderPlayer(matrixStack, x + 10, panelY, width - 20, panelHeight);
        }
    }

    private void renderPlayer(MatrixStack matrixStack, float x, float y, float width, float height) {
        String songName = trimSongName(musicFiles.get(selectedMusicIndex).getName().replaceAll("\\.wav", ""), width - 80);
        Fonts.montserrat.drawText(matrixStack, songName, x + 10, y + 35, ColorUtils.rgb(255, 255, 255), 12);
        float buttonSize = 20;
        float buttonSpacing = 10;
        float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

        float prevButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, isPlaying ? "| |" : ">", playPauseButtonX + buttonSize / 2f, playPauseButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        DisplayUtils.drawImage(isPlaying ? pause : play, playPauseButtonX + buttonSize / 2f - 5, playPauseButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));
      
        float nextButtonX = x + width / 2f + buttonSpacing + 5;

        float nextButtonY = y + height / 2f - buttonSize / 2f + 10;

        DisplayUtils.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, ">", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);
      
        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

        float repeatButtonY = nextButtonY;

        int repeatButtonColor = isRepeat ? ColorUtils.rgba(0, 0, 255, 255) : ColorUtils.rgba(60, 60, 60, 255);

        DisplayUtils.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);

        DisplayUtils.drawImage(repeat, repeatButtonX + buttonSize / 2f - 5, repeatButtonY + 5, 10, 10, ColorUtils.rgb(255, 255, 255));

        //Fonts.montserrat.drawCenteredText(matrixStack, "R", repeatButtonX + buttonSize / 2f, repeatButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 55;

        float volumeSliderY = y + height / 2f - 4 + 10;

        float volumeSliderWidth = width / 4f - 15;

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtils.rgba(0, 255, 0, 255));
      
        float timeSliderX = x + 10;

        float timeSliderY = y + height - 20;

        float timeSliderWidth = width - 20;

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtils.rgba(60, 60, 60, 255));

        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtils.rgba(0, 255, 0, 255));
      
        float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

        DisplayUtils.drawRoundedRect(closeButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));

        Fonts.test1488.drawCenteredText(matrixStack, "U", closeButtonX + buttonSize / 2f - 1, repeatButtonY + 6f, ColorUtils.rgb(255, 255, 255), 10);
    }

    public float getCurrentPlaybackPosition() {

        if (clip != null) {

            return clip.getMicrosecondPosition() / (float) clip.getMicrosecondLength();

        }

        return 0;

    }

    public String getCurrentSongName() {

        if (selectedMusicIndex != -1 && selectedMusicIndex < musicFiles.size()) {

            return musicFiles.get(selectedMusicIndex).getName().replace(".wav", "");

        }

        return "";

    }

    @Override

    public boolean mouseClicked(double mouseX, double mouseY, int button) {

        if (button == 0) {

            float windowWidth = mc.getMainWindow().getScaledWidth();

            float windowHeight = mc.getMainWindow().getScaledHeight();
          
            float width = 400;

            float height = 400;

            float x = windowWidth / 2f - width / 2f;

            float y = windowHeight / 2f - height / 2f;

            float panelHeight = 100;

            float panelY = y + height - panelHeight - 10;

            float buttonSize = 20;

            float buttonSpacing = 10;

            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;

            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, prevButtonX, prevButtonY, buttonSize, buttonSize)) {

                selectPreviousMusic();

                return true;

            }
          
            float playPauseButtonX = x + width / 2f - buttonSize / 2f;

            float playPauseButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, playPauseButtonX, playPauseButtonY, buttonSize, buttonSize)) {

                togglePlayPause();

                return true;

            }
          
            float nextButtonX = x + width / 2f + buttonSpacing + 5;

            float nextButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {

                selectNextMusic();

                return true;

            }

            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;

            float repeatButtonY = nextButtonY;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {

                isRepeat = !isRepeat;

                return true;

            }

            float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 53;

            float volumeSliderY = panelY + panelHeight / 2f - 5 + 10;

            float volumeSliderWidth = width / 4f - 15;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {

                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);

                setVolume(volume);

                return true;

            }

            float timeSliderX = x + 8;

            float timeSliderY = panelY + panelHeight - 20;

            float timeSliderWidth = width - 20;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {

                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));

                return true;

            }

            float openFolderX = x + width - 30          + 1.5f;

            float openFolderY = y + 8;//10;

            float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);

            //if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX - folderTextWidth, openFolderY, buttonSize + folderTextWidth, buttonSize)) {

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, 20, 20)) {

                openMusicFolder();

                return true;

            }

            float listY = y + 40;

            for (int i = 0; i < musicFiles.size(); i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + i * 25, width - 40, 25) && scrollOffset == 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }
            float closeButtonX = x + width / 2f - buttonSize / 2f - 60;

            if (MathUtil.isHovered((float) mouseX, (float) mouseY, closeButtonX, prevButtonY, buttonSize, buttonSize)) {

                clip.stop();

                clip.close();

                clip = null;

                selectedMusicIndex = -1;

                return true;

            }
            int startIndex = scrollOffset;

            int endIndex = Math.min(startIndex + maxVisibleItems, musicFiles.size());
            for (int i = startIndex; i < endIndex; i++) {

                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + (i - startIndex) * itemHeight, width - 40, itemHeight) && scrollOffset > 0) {

                    selectedMusicIndex = i;

                    playSelectedMusic();

                    return true;

                }

            }

        }
        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {

        int maxOffset = musicFiles.size() - maxVisibleItems;

        if (maxOffset > 0) {

            scrollOffset = (int) MathUtil.clamp(scrollOffset - (int) delta, 0, maxOffset);

        }

        handleMouseWheel((int) delta);

        return super.mouseScrolled(mouseX, mouseY, delta);

    }

    public void handleMouseWheel(int delta) {
        scrollOffset -= delta * 3;
        scrollOffset = Math.max(0, Math.min(scrollOffset, Math.max(0, musicFiles.size() - 10)));

    }

    private void selectPreviousMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex > 0) {

            selectedMusicIndex--;

        } else {

            selectedMusicIndex = musicFiles.size() - 1;

        }

        playSelectedMusic();

    }

    private void selectNextMusic() {

        if (musicFiles.isEmpty()) return;



        if (selectedMusicIndex < musicFiles.size() - 1) {

            selectedMusicIndex++;

        } else {

            selectedMusicIndex = 0;

        }

        playSelectedMusic();

    }

    private void togglePlayPause() {

        if (clip == null) return;

        if (isPlaying) {

            clip.stop();

            isPlaying = false;

        } else {

            clip.setFramePosition(clip.getFramePosition());

            clip.start();

            isPlaying = true;

        }

    }

    private void openMusicFolder() {

        try {

            Runtime.getRuntime().exec("explorer " + musicDirectory.getAbsolutePath());

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    private void setVolume(float volume) {

        if (clip != null && clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {

            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

            float dB = (float) (Math.log(volume) / Math.log(10) * 20);

            gainControl.setValue(dB);

        }

    }

    private void seek(float position) {

        if (clip != null) {

            clip.setMicrosecondPosition((long) (clip.getMicrosecondLength() * position));

        }

    }

    public boolean isVisible() {

        return this.minecraft.currentScreen == this;

    }

    public boolean isPlaying() {

        return isPlaying;

    }

    private void playSelectedMusic() {

        if (selectedMusicIndex == -1 || musicFiles.isEmpty()) return;



        if (clip != null && clip.isOpen()) {

            clip.stop();

            clip.close();

        }

        File music = musicFiles.get(selectedMusicIndex);

        try {

            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(music);

            clip = AudioSystem.getClip();

            clip.open(audioInputStream);

            setVolume(volume);

            isPlaying = true;

            clip.addLineListener(event -> {

                if (event.getType() == LineEvent.Type.STOP && isPlaying) {

                    if (clip.getMicrosecondPosition() >= clip.getMicrosecondLength()) {

                        if (isRepeat) {

                            clip.setFramePosition(0);

                            clip.start();

                        } else {
                            selectNextMusic();
                        }

                    }

                }

            });
            clip.start();

        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }

}
я думал ты фулл сольешь, я, к слову так и не смог скролл вставить нормальный xd
 
Забаненный
Статус
Оффлайн
Регистрация
5 Май 2024
Сообщения
44
Реакции[?]
0
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
дайте шрифы и иконки
 
Сверху Снизу