From 0758980bbbe05722f3e9db23ccebefe1d31f043c Mon Sep 17 00:00:00 2001 From: C J Silverio Date: Tue, 9 Jan 2024 20:58:35 -0800 Subject: [PATCH] Goodbye ucs2 and byte-slice-cast I woke up in the middle of the night last night aware that this code was useless. --- Cargo.lock | 23 ----------------------- Cargo.toml | 2 -- src/controller/strings.rs | 14 +------------- src/renderer/ui_renderer.cpp | 20 ++++++++++++-------- 4 files changed, 13 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4715f432..814c6273 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,12 +62,6 @@ dependencies = [ "virtue", ] -[[package]] -name = "bit_field" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" - [[package]] name = "bitflags" version = "1.3.2" @@ -80,12 +74,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -[[package]] -name = "byte-slice-cast" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" - [[package]] name = "bytemuck" version = "1.14.0" @@ -792,7 +780,6 @@ name = "soulsy" version = "0.16.2" dependencies = [ "bincode", - "byte-slice-cast", "chardet", "cxx", "cxx-build", @@ -811,7 +798,6 @@ dependencies = [ "strum", "textcode", "toml", - "ucs2", ] [[package]] @@ -1007,15 +993,6 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" -[[package]] -name = "ucs2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad643914094137d475641b6bab89462505316ec2ce70907ad20102d28a79ab8" -dependencies = [ - "bit_field", -] - [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index 51398bd5..117c60b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ crate-type = ["staticlib"] [dependencies] bincode = "2.0.0-rc.3" -byte-slice-cast = "1.2.2" chardet = "0.2.4" cxx = { version = "1.0.111", features = ["c++20"] } enumset = "1.1.3" @@ -30,7 +29,6 @@ strfmt = "0.2.4" strum = { version = "0.25.0", features = ["derive"] } textcode = "0.2.2" toml = "0.8.6" -ucs2 = "0.3.2" [build-dependencies] cxx-build = "1.0.111" diff --git a/src/controller/strings.rs b/src/controller/strings.rs index c5eb28b0..ca3d8db3 100644 --- a/src/controller/strings.rs +++ b/src/controller/strings.rs @@ -1,6 +1,4 @@ //! Character encoding shenanigans. Bethesda is very bad at utf-8, I am told. - -use byte_slice_cast::AsSliceOf; use cxx::CxxVector; use textcode::{iso8859_15, iso8859_9}; @@ -48,17 +46,7 @@ pub fn convert_to_utf8(bytes: Vec) -> String { iso8859_15::decode(bytes.as_slice(), &mut dst); dst } - _ => { - let Ok(widebytes) = bytes.as_slice_of::() else { - return String::from_utf8_lossy(bytes.as_slice()).to_string(); - }; - let mut utf8bytes: Vec = vec![0; widebytes.len()]; - let Ok(_c) = ucs2::decode(widebytes, &mut utf8bytes) else { - return String::from_utf8_lossy(bytes.as_slice()).to_string(); - }; - String::from_utf8(utf8bytes.clone()) - .unwrap_or_else(|_| String::from_utf8_lossy(utf8bytes.as_slice()).to_string()) - } + _ => String::from_utf8_lossy(&bytes).to_string(), } } diff --git a/src/renderer/ui_renderer.cpp b/src/renderer/ui_renderer.cpp index 14a0d5c7..12125fa7 100644 --- a/src/renderer/ui_renderer.cpp +++ b/src/renderer/ui_renderer.cpp @@ -542,6 +542,7 @@ namespace ui auto entry_name = std::string(entry->name()); const auto hotkey = settings->hotkey_for(slotLayout.element); const auto slot_center = ImVec2(slotLayout.center.x, slotLayout.center.y); + const bool skipItem = entry_name.empty() && entry->icon_key().empty(); const auto slotbg = std::string(slotLayout.bg_image); if (slotLayout.bg_color.a > 0 && ui_renderer::lazyLoadHudImage(slotbg)) @@ -552,7 +553,7 @@ namespace ui } // now draw the icon over the background... - if (slotLayout.icon_color.a > 0) + if (slotLayout.icon_color.a > 0 && !skipItem) { const auto iconColor = colorizeIcons ? entry->color() : slotLayout.icon_color; auto iconkey = std::string(entry->icon_key()); @@ -570,15 +571,18 @@ namespace ui } // Loop through the text elements of this slot. - for (auto label : slotLayout.text) + if (!skipItem) { - if (label.color.a == 0) { continue; } - const auto textPos = ImVec2(label.anchor.x, label.anchor.y); - auto entrytxt = std::string(entry->fmtstr(label.contents)); - // Let's try a wrap width here. This is going to be wrong, but we'll experiment. - if (!entrytxt.empty()) + for (auto label : slotLayout.text) { - drawText(entrytxt, textPos, label.font_size, label.color, label.alignment, label.wrap_width); + if (label.color.a == 0) { continue; } + const auto textPos = ImVec2(label.anchor.x, label.anchor.y); + auto entrytxt = std::string(entry->fmtstr(label.contents)); + // Let's try a wrap width here. This is going to be wrong, but we'll experiment. + if (!entrytxt.empty()) + { + drawText(entrytxt, textPos, label.font_size, label.color, label.alignment, label.wrap_width); + } } }