New icons, new side panel, table no longer shows playlists, as they are selectable seperately

This commit is contained in:
2024-10-09 15:02:24 +03:00
parent 847aa2bb4f
commit 70b92f4ebf
19 changed files with 6712 additions and 703 deletions

View File

@@ -1,6 +1,8 @@
use anyhow::bail;
use egui::Color32;
use crate::manifest::song::SongType;
use super::{State, Window};
@@ -9,19 +11,20 @@ pub struct GuiSongEditor {
song: (String, String),
ed_url: String,
ed_name: String,
ed_type: SongType
}
impl Window for GuiSongEditor {
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
let mut save = false;
let (playlist, song_name) = self.song.clone();
let (playlist_name, song_name) = self.song.clone();
if playlist.is_empty() {
if playlist_name.is_empty() {
return Ok(());
}
let Some(song) = state.manifest.get_song(&playlist, &song_name) else {
let Some(song) = state.manifest.get_song(&playlist_name, &song_name) else {
bail!("Failed to get song (1)");
};
let song = song.clone();
@@ -36,7 +39,7 @@ impl Window for GuiSongEditor {
ui.label("[");
ui.hyperlink_to("link", song.get_url().unwrap());
ui.label("] ");
ui.colored_label(Color32::LIGHT_BLUE, &playlist);
ui.colored_label(Color32::LIGHT_BLUE, &playlist_name);
ui.label(": ");
ui.label(&song_name)
});
@@ -44,6 +47,14 @@ impl Window for GuiSongEditor {
ui.horizontal(|ui| {
ui.label("Type: ");
ui.label(song.get_type().to_string());
egui::ComboBox::from_id_source("song_edit_window_type")
.selected_text(format!("{:?}", self.ed_type))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.ed_type, SongType::Youtube, "Youtube");
ui.selectable_value(&mut self.ed_type, SongType::Spotify, "Spotify");
ui.selectable_value(&mut self.ed_type, SongType::Soundcloud, "Soundcloud");
}
);
});
ui.horizontal(|ui| {
@@ -61,21 +72,23 @@ impl Window for GuiSongEditor {
});
if save {
{
let Some(song) = state.manifest.get_song_mut(&playlist, &song_name) else {
let song = {
let Some(song) = state.manifest.get_song_mut(&playlist_name, &song_name) else {
bail!("Failed to get song (2)");
};
song.get_url_str_mut().clone_from(&self.ed_url);
}
song.get_type_mut().clone_from(&self.ed_type);
song.clone()
};
let Some(playlist) = state.manifest.get_playlist_mut(&playlist) else {
let Some(playlist) = state.manifest.get_playlist_mut(&playlist_name) else {
bail!("Failed to get playlist");
};
playlist.remove_song(&song_name);
playlist.add_song(self.ed_name.clone(), song);
playlist.add_song(self.ed_name.clone(), song.clone());
*open = false;
let _ = state.manifest.save(None);
}
@@ -85,10 +98,11 @@ impl Window for GuiSongEditor {
}
impl GuiSongEditor {
pub fn set_active_song(&mut self, pname: &str, sname: &str, url: &str) {
pub fn set_active_song(&mut self, pname: &str, sname: &str, url: &str, typ: &SongType) {
self.song.0 = pname.to_string();
self.song.1 = sname.to_string();
self.ed_name = sname.to_string();
self.ed_url = url.to_string();
self.ed_type = typ.clone();
}
}