Skip to content

Commit e211f34

Browse files
committed
Home key toggle
1 parent 29bbaaf commit e211f34

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
egui = "0.17"
11-
egui-hook = { git = "https://github.com/jac3km4/egui-hook", rev = "v0.0.1" }
11+
egui-hook = { git = "https://github.com/jac3km4/egui-hook", rev = "v0.0.2" }
1212
rhai = "1.5"
1313
phf = { version = "0.10", features = ["macros"] }

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## C.R.O.N.Y GUI
22
Small WIP script hook/extender for Elex 2
33

4-
### how to
4+
### how it works
55
This library uses [Rhai](https://rhai.rs) as the scripting language.
6+
A script console can be toggled with the Home key.
67
You can find available game functions [here](https://github.com/jac3km4/crony-gui/tree/master/doc/FUNCTIONS.md).
78

89
### demo

src/host.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::elex::FunctionPtr;
99
pub struct ScriptHost {
1010
pub(crate) cmd: String,
1111
pub(crate) history: String,
12+
is_active: bool,
1213
engine: Engine,
1314
scope: Scope<'static>,
1415
}
@@ -20,6 +21,7 @@ impl Default for ScriptHost {
2021
Self {
2122
cmd: String::new(),
2223
history: String::new(),
24+
is_active: false,
2325
engine,
2426
scope: Scope::new(),
2527
}
@@ -56,6 +58,14 @@ impl ScriptHost {
5658
}
5759
module
5860
}
61+
62+
pub fn toggle(&mut self) {
63+
self.is_active = !self.is_active;
64+
}
65+
66+
pub fn is_active(&self) -> bool {
67+
self.is_active
68+
}
5969
}
6070

6171
pub type CustomHandler = fn(&str, &mut Module, FunctionPtr) -> u64;

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ egui_hook!(ScriptHost, ui);
1111
fn ui(ctx: &Context, app: &mut ScriptHost) {
1212
const DEFAULT_SIZE: Vec2 = Vec2::new(600., 320.);
1313

14+
if ctx.input().key_pressed(Key::Home) {
15+
app.toggle();
16+
}
17+
if !app.is_active() {
18+
return;
19+
}
20+
1421
Window::new("CRONY GUI")
1522
.default_size(DEFAULT_SIZE)
1623
.show(ctx, |ui| {

0 commit comments

Comments
 (0)