From 6298d5d643a30d733eab994041f16ac89498ab94 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Mon, 19 Aug 2024 01:36:12 -0700 Subject: [PATCH] Update dependencies --- .vscode/bevy.code-snippets | 2 +- Cargo.lock | 309 +++++++++++++++++----------- Cargo.toml | 6 +- src/core/theme.rs | 20 +- src/game/actor/attack/input.rs | 23 ++- src/game/actor/movement/input.rs | 18 +- src/game/card.rs | 10 +- src/screen/playing.rs | 11 +- src/screen/playing/level_up_menu.rs | 40 ++-- src/ui.rs | 6 +- src/ui/font.rs | 9 +- src/ui/tooltip.rs | 236 +++------------------ 12 files changed, 299 insertions(+), 391 deletions(-) diff --git a/.vscode/bevy.code-snippets b/.vscode/bevy.code-snippets index 973d436..174b1f9 100644 --- a/.vscode/bevy.code-snippets +++ b/.vscode/bevy.code-snippets @@ -46,4 +46,4 @@ ], "description": "Define a Resource" } -} \ No newline at end of file +} diff --git a/Cargo.lock b/Cargo.lock index 40107dd..2b753d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,9 +212,9 @@ checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" dependencies = [ "serde", ] @@ -317,9 +317,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "avian2d" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757274b827f77c3853fd36c4229ebeda55746fc297244bcd1104e561dab34326" +checksum = "63b586289578913c009ad13cf138e5b676b23df78894c299a9db14fdecee92e3" dependencies = [ "avian_derive", "bevy", @@ -342,7 +342,7 @@ checksum = "b4adeeecb6d4628d3ca11836ce9af8309f9552d4bd3e3f6e4368440d8163260c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -363,9 +363,9 @@ dependencies = [ [[package]] name = "bevy-inspector-egui" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8d77dbe53c8840aa74b66ea19dac6675d0a1752c989610cbded909d03967bec" +checksum = "8b66b51a66c0be92604c13cd490509d77676c05406f4f4b046672aaffdcc925f" dependencies = [ "bevy-inspector-egui-derive", "bevy_app", @@ -396,13 +396,13 @@ dependencies = [ [[package]] name = "bevy-inspector-egui-derive" -version = "0.25.0" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161d93f4b3a9246a87485e30ccf4cc927f204a14f26df42da977e383f0a0ec5d" +checksum = "791acfac11e3d5a750952c5201dc0d414b88431260118b46949bf6b159c5a19c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -496,7 +496,7 @@ source = "git+https://github.com/benfrankel/bevy_asset_loader.git?branch=direct- dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -508,7 +508,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -587,7 +587,7 @@ checksum = "8675f337f374b2b8ae90539982b947d171f9adb302d00c032b823bd5231f8978" dependencies = [ "bevy_macro_utils", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -673,13 +673,14 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] name = "bevy_editor_pls" version = "0.9.0" -source = "git+https://github.com/zhaop/bevy_editor_pls?branch=bevy-0.14#78aa34ce109ecd924928bbd54b04dcd7286ebfea" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02242646d9efb114c156b11ade613bc47339133422c261435eca8c07c36f6dd7" dependencies = [ "bevy", "bevy_editor_pls_core", @@ -691,7 +692,8 @@ dependencies = [ [[package]] name = "bevy_editor_pls_core" version = "0.9.0" -source = "git+https://github.com/zhaop/bevy_editor_pls?branch=bevy-0.14#78aa34ce109ecd924928bbd54b04dcd7286ebfea" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c405936c0efb9279ce9a0689cd40df87fd94b85d9723530a8f88d2f98627eb9" dependencies = [ "bevy", "bevy-inspector-egui", @@ -702,7 +704,8 @@ dependencies = [ [[package]] name = "bevy_editor_pls_default_windows" version = "0.9.0" -source = "git+https://github.com/zhaop/bevy_editor_pls?branch=bevy-0.14#78aa34ce109ecd924928bbd54b04dcd7286ebfea" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c81d69f24cc6b61f0f62f997c491365a1c0956b6276530e4fec12c5839c8fff4" dependencies = [ "bevy", "bevy-inspector-egui", @@ -767,7 +770,7 @@ checksum = "3fc779559aa23b81da2b14fba90586755d225983c5b6d3154658e42fc088de7f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -817,7 +820,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -927,7 +930,7 @@ checksum = "7ec4a585ec2a6dedd4f4143c07219d120ae142121929f0d83e68d82a452cdc9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", "toml_edit 0.22.20", ] @@ -956,9 +959,9 @@ dependencies = [ [[package]] name = "bevy_mod_debugdump" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9651b4fb528d1c4800a8da0a5819ebeffb32933654d13e0aa5b6a738146b7f15" +checksum = "30f0eab3099d7d474b25a95a6a2a945e6089d75e099af5a571fe896f7c1a455b" dependencies = [ "bevy_app", "bevy_color", @@ -1111,7 +1114,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", "uuid", ] @@ -1173,7 +1176,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1245,7 +1248,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1378,7 +1381,7 @@ checksum = "36a1e91b4294cad2d08620ac062509395d4f65247b636946d6497eaeccf4dbfd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1444,7 +1447,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1510,6 +1513,7 @@ dependencies = [ "leafwing-input-manager", "log", "pyri_state", + "pyri_tooltip", "rand", "ron", "serde", @@ -1566,22 +1570,22 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.3" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" +checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1630,12 +1634,13 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.7" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" dependencies = [ "jobserver", "libc", + "shlex", ] [[package]] @@ -1828,9 +1833,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-graphics" @@ -1979,7 +1984,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -1990,7 +1995,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2015,7 +2020,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2064,6 +2069,24 @@ dependencies = [ "proc-macro-error", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "dyn-eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2d035d21af5cde1a6f5c7b444a5bf963520a9f142e5d06931178433d7d5388" + +[[package]] +name = "dyn-hash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a650a461c6a8ff1ef205ed9a2ad56579309853fecefc2423f73dced342f92258" + [[package]] name = "ecolor" version = "0.28.1" @@ -2141,7 +2164,7 @@ checksum = "fd31dbbd9743684d339f907a87fe212cb7b51d75b9e8e74181fe363199ee9b47" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2162,7 +2185,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2183,7 +2206,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2295,14 +2318,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.23" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +checksum = "bf401df4a4e3872c4fe8151134cf483738e74b67fc934d6532c882b3d24a4550" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", - "windows-sys 0.52.0", + "libredox 0.1.3", + "windows-sys 0.59.0", ] [[package]] @@ -2351,7 +2374,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2759,9 +2782,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", "hashbrown", @@ -2884,9 +2907,9 @@ checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -2973,7 +2996,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -2990,27 +3013,32 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leafwing-input-manager" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebb7f3227809906ca7ccc981aedf7805b5edb422b4265290cc749316c0faba4" +checksum = "10cfa701709bb37011dd09965a76ff981f6284ed5b8ac0e5089dcd311efeff49" dependencies = [ "bevy", "derive_more", + "dyn-clone", + "dyn-eq", + "dyn-hash", "itertools 0.13.0", "leafwing_input_manager_macros", + "once_cell", "serde", + "serde_flexitos", ] [[package]] name = "leafwing_input_manager_macros" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d065e4f0771d9cc597e76d648da18476ad01fd50cd60ee585ee500f9cd8d696" +checksum = "61ff6f0b220de1c284422f6af6a529acfaa5dab76ee86d6167eb2ee34502290c" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -3021,9 +3049,9 @@ checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" @@ -3062,6 +3090,17 @@ dependencies = [ "redox_syscall 0.4.1", ] +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", + "redox_syscall 0.5.3", +] + [[package]] name = "libudev-sys" version = "0.1.4" @@ -3282,7 +3321,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -3450,7 +3489,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -3500,7 +3539,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -3761,7 +3800,7 @@ version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166" dependencies = [ - "libredox", + "libredox 0.0.2", ] [[package]] @@ -3899,7 +3938,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -3910,9 +3949,9 @@ checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "piper" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1d5c74c9876f070d3e8fd503d748c7d974c3e48da8f41350fa5222ef9b4391" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" dependencies = [ "atomic-waker", "fastrand", @@ -3940,9 +3979,9 @@ dependencies = [ [[package]] name = "polling" -version = "3.7.2" +version = "3.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" dependencies = [ "cfg-if", "concurrent-queue", @@ -3950,7 +3989,7 @@ dependencies = [ "pin-project-lite", "rustix", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4042,7 +4081,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -4070,7 +4109,30 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", +] + +[[package]] +name = "pyri_tooltip" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5ef71c24beb1dfda4cb3a6f520be4a0e97e5406526239c072c848f56189cb5c" +dependencies = [ + "bevy_app", + "bevy_color", + "bevy_core", + "bevy_ecs", + "bevy_hierarchy", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_sprite", + "bevy_text", + "bevy_time", + "bevy_transform", + "bevy_ui", + "bevy_window", + "tiny_bail", ] [[package]] @@ -4373,22 +4435,32 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", +] + +[[package]] +name = "serde_flexitos" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a95e8972debc2acae5fa208fd4ec9ba96ace41d2bdd4e715ad4082b822e955" +dependencies = [ + "erased-serde", + "serde", ] [[package]] @@ -4488,9 +4560,9 @@ dependencies = [ [[package]] name = "spade" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "766195f983f4098dc3bf37fb66bd609f6e6258c4b8db684d05252b2c694cdbcd" +checksum = "9bd14cf9e23b5241e1b1289ed3b9afc7746c95ead8df52d9254f5ed2d40c561b" dependencies = [ "hashbrown", "num-traits", @@ -4538,7 +4610,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -4631,9 +4703,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -4699,7 +4771,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -4750,9 +4822,9 @@ dependencies = [ [[package]] name = "tiny_bail" -version = "0.1.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58b188988b0bd734f9ff002b39db10a25f97ed4b1bec958c538bb62a07030076" +checksum = "75814a573fb24985a87a518968108d687b1d6f8136434d8e580e4ded5eef8aaa" dependencies = [ "tracing", ] @@ -4820,7 +4892,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -4957,9 +5029,9 @@ dependencies = [ [[package]] name = "ttf-parser" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8686b91785aff82828ed725225925b33b4fde44c4bb15876e5f7c832724c420a" +checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a" [[package]] name = "twox-hash" @@ -4973,9 +5045,9 @@ dependencies = [ [[package]] name = "typeid" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "059d83cc991e7a42fc37bd50941885db0888e34209f8cfd9aab07ddec03bc9cf" +checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e" [[package]] name = "typenum" @@ -5080,34 +5152,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -5117,9 +5190,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5127,22 +5200,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wayland-backend" @@ -5255,9 +5328,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", @@ -5412,9 +5485,9 @@ dependencies = [ [[package]] name = "wide" -version = "0.7.26" +version = "0.7.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901e8597c777fa042e9e245bd56c0dc4418c5db3f845b6ff94fbac732c6a0692" +checksum = "b828f995bf1e9622031f8009f8481a85406ce1f4d4588ff746d872043e855690" dependencies = [ "bytemuck", "safe_arch", @@ -5529,7 +5602,7 @@ checksum = "942ac266be9249c84ca862f0a164a39533dc2f6f33dc98ec89c8da99b82ea0bd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -5540,7 +5613,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -5551,7 +5624,7 @@ checksum = "da33557140a288fae4e1d5f8873aaf9eb6613a9cf82c3e070223ff177f598b60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -5562,7 +5635,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] [[package]] @@ -5809,9 +5882,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" -version = "0.30.4" +version = "0.30.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4225ddd8ab67b8b59a2fee4b34889ebf13c0460c1c3fa297c58e21eb87801b33" +checksum = "0be9e76a1f1077e04a411f0b989cbd3c93339e1771cb41e71ac4aee95bfd2c67" dependencies = [ "ahash", "android-activity", @@ -5911,9 +5984,9 @@ checksum = "ec107c4503ea0b4a98ef47356329af139c0a4f7750e621cf2973cd3385ebcb3d" [[package]] name = "xcursor" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d491ee231a51ae64a5b762114c3ac2104b967aadba1de45c86ca42cf051513b7" +checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" [[package]] name = "xi-unicode" @@ -5942,9 +6015,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" [[package]] name = "xml-rs" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" +checksum = "539a77ee7c0de333dcc6da69b177380a0b81e0dacfa4f7344c465a36871ee601" [[package]] name = "zerocopy" @@ -5964,5 +6037,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.75", ] diff --git a/Cargo.toml b/Cargo.toml index 29c06c5..a6a814e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ bevy_tweening = "0.11" interpolation = "0.3" iyes_progress = "0.12" lazy-regex = { version = "3", features = ["lite"] } -leafwing-input-manager = "0.14" +leafwing-input-manager = "0.15" log = { version = "0.4", features = [ "max_level_debug", "release_max_level_warn", @@ -59,12 +59,13 @@ pyri_state = { version = "0.2", default-features = false, features = [ "bevy_state", "entity_scope", ] } +pyri_tooltip = "0.1" rand = { version = "0.8", features = ["small_rng"] } ron = "0.8" serde = "1" strum = { version = "0.26", features = ["derive"] } tap = "1" -tiny_bail = "0.1" +tiny_bail = "0.3" tracing = { version = "0.1", features = [ "max_level_debug", "release_max_level_warn", @@ -73,7 +74,6 @@ tracing = { version = "0.1", features = [ [patch.crates-io] # TODO: Workaround for https://github.com/NiklasEi/bevy_asset_loader/issues/219. bevy_asset_loader = { git = "https://github.com/benfrankel/bevy_asset_loader.git", branch = "direct-depend" } -bevy_editor_pls = { git = "https://github.com/zhaop/bevy_editor_pls", branch = "bevy-0.14" } [features] default = ["native_dev"] diff --git a/src/core/theme.rs b/src/core/theme.rs index 924fc64..7214d1a 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -88,16 +88,6 @@ pub struct ThemeColorFor( #[reflect(ignore)] PhantomData, ); -fn apply_theme_color_for( - theme: ConfigRef, - mut color_query: Query<(&ThemeColorFor, &mut C)>, -) { - let palette = &r!(theme.get()).colors; - for (theme_color, mut color) in &mut color_query { - *color.color_mut() = palette[theme_color.0]; - } -} - impl Configure for ThemeColorFor { fn configure(app: &mut App) { app.register_type::(); @@ -108,6 +98,16 @@ impl Configure for ThemeColorFor { } } +fn apply_theme_color_for( + theme: ConfigRef, + mut color_query: Query<(&ThemeColorFor, &mut C)>, +) { + let palette = &r!(theme.get()).colors; + for (theme_color, mut color) in &mut color_query { + *color.color_mut() = palette[theme_color.0]; + } +} + #[derive(Component, Reflect, Default)] #[reflect(Component)] pub struct ThemeColorForText(pub Vec); diff --git a/src/game/actor/attack/input.rs b/src/game/actor/attack/input.rs index 18a3f4e..cba4686 100644 --- a/src/game/actor/attack/input.rs +++ b/src/game/actor/attack/input.rs @@ -11,12 +11,21 @@ pub(super) fn plugin(app: &mut App) { app.configure::(); } -#[derive(Actionlike, Eq, PartialEq, Hash, Copy, Clone, Reflect)] +#[derive(Eq, PartialEq, Hash, Copy, Clone, Reflect, Debug)] enum AttackAction { Aim, Fire, } +impl Actionlike for AttackAction { + fn input_control_kind(&self) -> InputControlKind { + match self { + Self::Aim => InputControlKind::DualAxis, + Self::Fire => InputControlKind::Button, + } + } +} + impl Configure for AttackAction { fn configure(app: &mut App) { app.add_plugins(InputManagerPlugin::::default()); @@ -33,7 +42,8 @@ fn record_attack_action( mut action_query: Query<(&ActionState, &mut AttackController)>, ) { for (action, mut controller) in &mut action_query { - controller.aim += cq!(action.axis_pair(&AttackAction::Aim)) + controller.aim += action + .axis_pair(&AttackAction::Aim) .xy() .clamp_length_max(1.0); controller.fire |= action.just_pressed(&AttackAction::Fire); @@ -43,10 +53,9 @@ fn record_attack_action( pub fn attack_action(mut entity: EntityWorldMut) { entity.insert(InputManagerBundle::with_map( InputMap::default() - .insert(AttackAction::Aim, DualAxis::right_stick()) - .insert(AttackAction::Aim, VirtualDPad::arrow_keys()) - .insert(AttackAction::Fire, GamepadButtonType::East) - .insert(AttackAction::Fire, VirtualDPad::arrow_keys()) - .build(), + .with_dual_axis(AttackAction::Aim, GamepadStick::RIGHT) + .with_dual_axis(AttackAction::Aim, KeyboardVirtualDPad::ARROW_KEYS) + .with(AttackAction::Fire, GamepadButtonType::East) + .with(AttackAction::Fire, MouseButton::Left), )); } diff --git a/src/game/actor/movement/input.rs b/src/game/actor/movement/input.rs index b127910..d67945c 100644 --- a/src/game/actor/movement/input.rs +++ b/src/game/actor/movement/input.rs @@ -11,11 +11,19 @@ pub(super) fn plugin(app: &mut App) { app.configure::(); } -#[derive(Actionlike, Eq, PartialEq, Hash, Copy, Clone, Reflect)] +#[derive(Eq, PartialEq, Hash, Copy, Clone, Reflect, Debug)] enum MovementAction { Move, } +impl Actionlike for MovementAction { + fn input_control_kind(&self) -> InputControlKind { + match self { + Self::Move => InputControlKind::DualAxis, + } + } +} + impl Configure for MovementAction { fn configure(app: &mut App) { app.add_plugins(InputManagerPlugin::::default()); @@ -32,7 +40,8 @@ fn record_movement_action( mut action_query: Query<(&ActionState, &mut MovementController)>, ) { for (action, mut controller) in &mut action_query { - controller.0 += cq!(action.axis_pair(&MovementAction::Move)) + controller.0 += action + .axis_pair(&MovementAction::Move) .xy() .clamp_length_max(1.0); } @@ -41,8 +50,7 @@ fn record_movement_action( pub fn movement_action(mut entity: EntityWorldMut) { entity.insert(InputManagerBundle::with_map( InputMap::default() - .insert(MovementAction::Move, DualAxis::left_stick()) - .insert(MovementAction::Move, VirtualDPad::wasd()) - .build(), + .with_dual_axis(MovementAction::Move, GamepadStick::LEFT) + .with_dual_axis(MovementAction::Move, KeyboardVirtualDPad::WASD), )); } diff --git a/src/game/card.rs b/src/game/card.rs index 36840b8..7bc5529 100644 --- a/src/game/card.rs +++ b/src/game/card.rs @@ -230,7 +230,7 @@ pub fn card(key: impl Into, active: Option) -> impl EntityCommand let name = format!("Card(\"{}\")", card.name); let height = config.card_height; let border_width = height / 18.0; - let tooltip_text = format!("{}\n\n{}", card.name, card.description); + let tooltip_text = format!("[b]{}\n\n[r]{}", card.name, card.description); world .entity_mut(entity) @@ -246,12 +246,8 @@ pub fn card(key: impl Into, active: Option) -> impl EntityCommand }, ThemeColor::CardBorder.target::(), Interaction::default(), - Tooltip { - text: tooltip_text, - self_anchor: Anchor::TopCenter, - tooltip_anchor: Anchor::BottomCenter, - offset: Vec2::ZERO, - }, + Tooltip::fixed(Anchor::TopCenter, parse_rich(tooltip_text)) + .with_justify(JustifyText::Center), )) .with_children(|children| { children.spawn_with(background).with_children(|children| { diff --git a/src/screen/playing.rs b/src/screen/playing.rs index 44ce395..469020a 100644 --- a/src/screen/playing.rs +++ b/src/screen/playing.rs @@ -127,7 +127,7 @@ impl Configure for PlayingAssets { } } -#[derive(Actionlike, Reflect, Clone, Hash, PartialEq, Eq)] +#[derive(Actionlike, Reflect, Clone, Hash, PartialEq, Eq, Debug)] pub enum PlayingAction { TogglePause, } @@ -137,11 +137,10 @@ impl Configure for PlayingAction { app.init_resource::>(); app.insert_resource( InputMap::default() - .insert(Self::TogglePause, GamepadButtonType::Start) - .insert(Self::TogglePause, KeyCode::Escape) - .insert(Self::TogglePause, KeyCode::Tab) - .insert(Self::TogglePause, KeyCode::KeyP) - .build(), + .with(Self::TogglePause, GamepadButtonType::Start) + .with(Self::TogglePause, KeyCode::Escape) + .with(Self::TogglePause, KeyCode::Tab) + .with(Self::TogglePause, KeyCode::KeyP), ); app.add_plugins(InputManagerPlugin::::default()); app.add_systems( diff --git a/src/screen/playing/level_up_menu.rs b/src/screen/playing/level_up_menu.rs index dee0acf..db68dc6 100644 --- a/src/screen/playing/level_up_menu.rs +++ b/src/screen/playing/level_up_menu.rs @@ -359,7 +359,7 @@ fn ready_button(mut entity: EntityWorldMut) { )); } -#[derive(Actionlike, Reflect, Clone, Hash, PartialEq, Eq)] +#[derive(Actionlike, Eq, PartialEq, Hash, Copy, Clone, Reflect, Debug)] pub enum LevelUpMenuAction { SelectLeft, SelectRight, @@ -373,24 +373,26 @@ impl Configure for LevelUpMenuAction { app.init_resource::>(); app.insert_resource( InputMap::default() - .insert(Self::SelectLeft, GamepadButtonType::DPadLeft) - .insert(Self::SelectLeft, GamepadButtonType::LeftTrigger) - .insert(Self::SelectLeft, KeyCode::KeyA) - .insert(Self::SelectLeft, KeyCode::ArrowLeft) - .insert(Self::SelectRight, GamepadButtonType::DPadRight) - .insert(Self::SelectRight, GamepadButtonType::RightTrigger) - .insert(Self::SelectRight, KeyCode::KeyD) - .insert(Self::SelectRight, KeyCode::ArrowRight) - .insert(Self::SwapLeft, GamepadButtonType::LeftTrigger2) - .insert_modified(Self::SwapLeft, Modifier::Shift, KeyCode::KeyA) - .insert_modified(Self::SwapLeft, Modifier::Shift, KeyCode::ArrowLeft) - .insert(Self::SwapRight, GamepadButtonType::RightTrigger2) - .insert_modified(Self::SwapRight, Modifier::Shift, KeyCode::KeyD) - .insert_modified(Self::SwapRight, Modifier::Shift, KeyCode::ArrowRight) - .insert(Self::Discard, GamepadButtonType::West) - .insert(Self::Discard, KeyCode::Backspace) - .insert(Self::Discard, KeyCode::Delete) - .build(), + .with(Self::SelectLeft, GamepadButtonType::DPadLeft) + .with(Self::SelectLeft, GamepadButtonType::LeftTrigger) + .with(Self::SelectLeft, KeyCode::KeyA) + .with(Self::SelectLeft, KeyCode::ArrowLeft) + .with(Self::SelectRight, GamepadButtonType::DPadRight) + .with(Self::SelectRight, GamepadButtonType::RightTrigger) + .with(Self::SelectRight, KeyCode::KeyD) + .with(Self::SelectRight, KeyCode::ArrowRight) + .with(Self::SwapLeft, GamepadButtonType::LeftTrigger2) + .with(Self::SwapLeft, ModifierKey::Shift.with(KeyCode::KeyA)) + .with(Self::SwapLeft, ModifierKey::Shift.with(KeyCode::ArrowLeft)) + .with(Self::SwapRight, GamepadButtonType::RightTrigger2) + .with(Self::SwapRight, ModifierKey::Shift.with(KeyCode::KeyD)) + .with( + Self::SwapRight, + ModifierKey::Shift.with(KeyCode::ArrowRight), + ) + .with(Self::Discard, GamepadButtonType::West) + .with(Self::Discard, KeyCode::Backspace) + .with(Self::Discard, KeyCode::Delete), ); app.add_plugins(InputManagerPlugin::::default()); // TODO: It'd be better to disable the action outside of `PlayingMenu::LevelUp`, but diff --git a/src/ui.rs b/src/ui.rs index 502e4ac..0aca915 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,6 +1,6 @@ //! Custom UI tools. -#![allow(dead_code, unused_imports)] +#![allow(dead_code)] pub mod div; pub mod font; @@ -8,8 +8,10 @@ pub mod interaction; pub mod tooltip; pub mod widget; +#[allow(unused_imports)] pub mod prelude { pub use bevy::ui::Val::*; + pub use pyri_tooltip::prelude::*; pub use super::div::StyleExtDiv as _; pub use super::font::parse_rich; @@ -21,7 +23,6 @@ pub mod prelude { pub use super::interaction::InteractionSfx; pub use super::interaction::InteractionTable; pub use super::interaction::IsDisabled; - pub use super::tooltip::Tooltip; pub use super::widget; pub use super::UiRoot; pub use crate::core::theme::ThemeColor; @@ -30,7 +31,6 @@ pub mod prelude { } use bevy::prelude::*; -use bevy::ui::Val::*; use bevy_mod_picking::prelude::*; use pyri_state::prelude::*; diff --git a/src/ui/font.rs b/src/ui/font.rs index 5f22028..81468d7 100644 --- a/src/ui/font.rs +++ b/src/ui/font.rs @@ -78,8 +78,8 @@ fn apply_dynamic_font_size( window_query: Query<&Window>, mut text_query: Query<(&DynamicFontSize, &Node, &mut Text)>, ) { - let window = r!(window_query.get(window_root.primary)); - let viewport_size = Vec2::new(window.resolution.width(), window.resolution.height()); + let window = rq!(window_query.get(window_root.primary)); + let viewport_size = window.resolution.size(); for (font_size, node, mut text) in &mut text_query { // Compute font size. @@ -101,7 +101,7 @@ fn apply_dynamic_font_size( } /// Parses a "rich text" string with tags `"[r]"`, `"[b]"`, and `"[t]"`. -pub fn parse_rich(text: &str) -> Vec { +pub fn parse_rich(text: impl AsRef) -> Vec { let styles = HashMap::from([ ( "r", @@ -137,10 +137,11 @@ pub fn parse_rich(text: &str) -> Vec { /// - If `styles["tag"]` is not found, `"[tag]"` will be interpreted as literal text. /// - Tags cannot be escaped. To allow literal `"[tag]"`, don't use `"tag"` as a key. pub fn parse_rich_custom( - text: &str, + text: impl AsRef, styles: &HashMap<&str, TextStyle>, start_tag: &str, ) -> Vec { + let text = text.as_ref(); let mut sections = vec![]; let mut lo = 0; diff --git a/src/ui/tooltip.rs b/src/ui/tooltip.rs index f5c9c97..386677b 100644 --- a/src/ui/tooltip.rs +++ b/src/ui/tooltip.rs @@ -1,216 +1,36 @@ -use bevy::ecs::entity::Entities; use bevy::prelude::*; -use bevy::sprite::Anchor; -use crate::core::window::WindowRoot; -use crate::core::PostTransformSet; -use crate::core::UpdateSet; use crate::ui::prelude::*; -use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { - app.configure::<(TooltipRoot, Tooltip, TooltipHover)>(); -} - -#[derive(Resource, Reflect)] -#[reflect(Resource)] -pub struct TooltipRoot { - pub container: Entity, - pub text: Entity, -} - -impl Configure for TooltipRoot { - fn configure(app: &mut App) { - app.register_type::(); - app.init_resource::(); - } -} - -impl FromWorld for TooltipRoot { - fn from_world(world: &mut World) -> Self { - let container = world - .spawn(( - Name::new("Tooltip"), - NodeBundle { - style: Style { - position_type: PositionType::Absolute, - max_width: Vw(40.0), - padding: UiRect::all(Px(8.0)), - ..default() - }, - visibility: Visibility::Hidden, - z_index: ZIndex::Global(999), + let container = app + .world_mut() + .spawn(( + Name::new("PrimaryTooltip"), + NodeBundle { + style: Style { + position_type: PositionType::Absolute, + max_width: Vw(40.0), + padding: UiRect::all(Px(8.0)), ..default() }, - ThemeColor::Popup.target::(), - Selection::default(), - )) - .id(); - - Self { - container, - text: world - .spawn(( - Name::new("TooltipText"), - TextBundle::from_section( - "", - TextStyle { - font: FONT_HANDLE, - ..default() - }, - ) - .with_text_justify(JustifyText::Center), - // TODO: Adjustable font sizes in ThemeConfig - DynamicFontSize::new(Px(16.0)), - ThemeColorForText(vec![ThemeColor::BodyText]), - )) - .set_parent(container) - .id(), - } - } -} - -#[derive(Component, Reflect)] -#[reflect(Component)] -pub struct Tooltip { - pub text: String, - pub self_anchor: Anchor, - pub tooltip_anchor: Anchor, - // TODO: Val? - pub offset: Vec2, -} - -impl Configure for Tooltip { - fn configure(app: &mut App) { - app.register_type::(); - app.add_systems( - Update, - ( - update_tooltip_selection, - update_tooltip_visibility, - update_tooltip_text, - ) - .in_set(UpdateSet::SyncLate) - .run_if(on_event::()), - ); - app.add_systems( - PostUpdate, - update_tooltip_position - .in_set(PostTransformSet::Blend) - .run_if(on_event::()), - ); - } -} - -fn update_tooltip_selection( - mut events: EventReader, - tooltip_root: Res, - mut tooltip_query: Query<&mut Selection>, -) { - let event = r!(events.read().last()); - let mut selection = r!(tooltip_query.get_mut(tooltip_root.container)); - - selection.0 = event.0.unwrap_or(Entity::PLACEHOLDER); -} - -fn update_tooltip_visibility( - mut events: EventReader, - tooltip_root: Res, - mut tooltip_query: Query<&mut Visibility>, -) { - let event = r!(events.read().last()); - let mut visibility = r!(tooltip_query.get_mut(tooltip_root.container)); - - *visibility = match event.0 { - Some(_) => Visibility::Inherited, - None => Visibility::Hidden, - }; -} - -fn update_tooltip_text( - mut events: EventReader, - selected_query: Query<&Tooltip>, - tooltip_root: Res, - mut tooltip_query: Query<&mut Text>, -) { - let event = r!(events.read().last()); - let entity = rq!(event.0); - let tooltip = r!(selected_query.get(entity)); - let mut text = r!(tooltip_query.get_mut(tooltip_root.text)); - - text.sections[0].value.clone_from(&tooltip.text); -} - -fn update_tooltip_position( - mut events: EventReader, - selected_query: Query<(&Tooltip, &GlobalTransform, &Node)>, - tooltip_root: Res, - mut tooltip_query: Query<(&mut Style, &mut Transform, &GlobalTransform, &Node)>, -) { - let event = r!(events.read().last()); - let entity = rq!(event.0); - let (tooltip, selected_gt, selected_node) = r!(selected_query.get(entity)); - let (mut style, mut transform, gt, node) = r!(tooltip_query.get_mut(tooltip_root.container)); - - // Convert `self_anchor` to a window-space offset. - let self_rect = selected_node.logical_rect(selected_gt); - let self_anchor = self_rect.size() * tooltip.self_anchor.as_vec(); - - // Convert `tooltip_anchor` to a window-space offset. - let tooltip_rect = node.logical_rect(gt); - let tooltip_anchor = tooltip_rect.size() * tooltip.tooltip_anchor.as_vec(); - - // Calculate the combined anchor (adjusted by bonus offset). - let anchor = tooltip_anchor - self_anchor + tooltip.offset; - - // Convert to absolute position. - let center = self_rect.center() + anchor; - let top_left = center - tooltip_rect.half_size(); - style.top = Px(top_left.y); - style.left = Px(top_left.x); - - // This system has to run after `UiSystem::Layout` so that its size is calculated - // from the updated text. However, that means that `Style` positioning will be - // delayed by 1 frame. As a workaround, update the `Transform` directly as well. - transform.translation.x = center.x; - transform.translation.y = center.y; -} - -/// A buffered event sent when an entity with tooltip is hovered. -#[derive(Event)] -struct TooltipHover(Option); - -impl Configure for TooltipHover { - fn configure(app: &mut App) { - app.add_event::(); - app.add_systems(Update, detect_tooltip_hover.in_set(UpdateSet::RecordInput)); - } -} - -fn detect_tooltip_hover( - mut events: EventWriter, - tooltip_root: Res, - tooltip_query: Query<&Selection>, - interaction_query: Query< - (Entity, &Interaction), - (With, With, With), - >, -) { - let selection = r!(tooltip_query.get(tooltip_root.container)); - - // TODO: Sorting by ZIndex would be nice, but not necessary. - for (entity, interaction) in &interaction_query { - if matches!(interaction, Interaction::None) { - continue; - } - - // Hovering something new: Update tooltip. - if selection.0 != entity { - events.send(TooltipHover(Some(entity))); - } - return; - } - - // Not hovering anything: Hide tooltip. - events.send(TooltipHover(None)); + visibility: Visibility::Hidden, + z_index: ZIndex::Global(999), + ..default() + }, + ThemeColor::Popup.target::(), + )) + .id(); + let text = app + .world_mut() + .spawn(( + Name::new("Text"), + TextBundle::default(), + DynamicFontSize::new(Px(16.0)), + ThemeColorForText(vec![ThemeColor::BodyText]), + )) + .set_parent(container) + .id(); + + app.add_plugins(TooltipPlugin { container, text }); }