Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

Commit 6491657

Browse files
committed
set door as hidden + handle change of active element properly
1 parent a7a533d commit 6491657

5 files changed

Lines changed: 59 additions & 7 deletions

File tree

src/door.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,30 @@ impl Door {
6060
b: 1.0,
6161
});
6262

63-
vec![Box::new(Line {
64-
color: color,
65-
from: world_pos - (self.width / 2.0) * tangent,
66-
to: world_pos + (self.width / 2.0) * tangent,
67-
width: 20.0,
68-
})]
63+
// TODO: better door visuals
64+
if self.hidden {
65+
vec![
66+
Box::new(Line {
67+
color: color,
68+
from: world_pos - (self.width / 2.0) * tangent,
69+
to: world_pos + (self.width / 2.0) * tangent,
70+
width: 10.0,
71+
}),
72+
Box::new(Line {
73+
color: color,
74+
from: world_pos - (self.width / 4.0) * tangent,
75+
to: world_pos + (self.width / 4.0) * tangent,
76+
width: 20.0,
77+
}),
78+
]
79+
} else {
80+
vec![Box::new(Line {
81+
color: color,
82+
from: world_pos - (self.width / 2.0) * tangent,
83+
to: world_pos + (self.width / 2.0) * tangent,
84+
width: 20.0,
85+
})]
86+
}
6987
}
7088

7189
pub(crate) fn contains_point(&self, wall: &Wall, pos: Vec2<f64>) -> bool {

src/state/commands.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum StateCommand {
2222
ChangeDoorName(DoorId, String),
2323
ChangeDoorNotes(DoorId, String),
2424
ChangeDoorLeadsTo(DoorId, Option<ChamberId>),
25+
ChangeDoorHidden(DoorId, bool),
2526
DeleteDoor(DoorId),
2627
}
2728

@@ -141,6 +142,10 @@ impl StateCommand {
141142
state.dungeon.door_mut(*door_id).unwrap().leads_to = *chamber_id;
142143
vec![StateEvent::DoorModified(*door_id)]
143144
}
145+
StateCommand::ChangeDoorHidden(door_id, hidden) => {
146+
state.dungeon.door_mut(*door_id).unwrap().hidden = *hidden;
147+
vec![StateEvent::DoorModified(*door_id)]
148+
}
144149
StateCommand::DeleteDoor(door_id) => {
145150
state.dungeon.remove_door(*door_id);
146151
let mut events = vec![StateEvent::DoorDeleted(*door_id)];

src/storage.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ fn line_to_command(l: &String) -> Option<StateCommand> {
119119
},
120120
))
121121
}
122+
"ChangeDoorHidden" => {
123+
let v: Value = serde_json::from_str(data).unwrap();
124+
Some(StateCommand::ChangeDoorHidden(
125+
v["door_id"].as_u64().unwrap() as ChamberId,
126+
v["hidden"].as_bool().unwrap(),
127+
))
128+
}
122129
"DeleteDoor" => {
123130
let v: Value = serde_json::from_str(data).unwrap();
124131
Some(StateCommand::DeleteDoor(
@@ -179,6 +186,7 @@ pub fn save_to_file(save_file: String, cmds: &Vec<StateCommand>) {
179186
StateCommand::ChangeDoorName(_, _) => "ChangeDoorName".to_owned(),
180187
StateCommand::ChangeDoorNotes(_, _) => "ChangeDoorNotes".to_owned(),
181188
StateCommand::ChangeDoorLeadsTo(_, _) => "ChangeDoorLeadsTo".to_owned(),
189+
StateCommand::ChangeDoorHidden(_, _) => "ChangeDoorHidden".to_owned(),
182190
StateCommand::DeleteDoor(_) => "DeleteDoor".to_owned(),
183191
};
184192
let data = match cmd {
@@ -230,6 +238,10 @@ pub fn save_to_file(save_file: String, cmds: &Vec<StateCommand>) {
230238
"door_id": door_id,
231239
"chamber_id": chamber_id,
232240
}),
241+
StateCommand::ChangeDoorHidden(door_id, hidden) => json!({
242+
"door_id": door_id,
243+
"hidden": hidden,
244+
}),
233245
StateCommand::DeleteDoor(door_id) => json!({ "door_id": door_id }),
234246
};
235247
data_str += format!("{} >> {}\n", name, data).as_str();

src/view/chamber_edit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct ChamberEdit {
1212
pub widget: Box,
1313
name_input: Entry,
1414
notes_input: TextView,
15+
hidden_input: CheckButton,
1516
}
1617

1718
impl ChamberEdit {
@@ -78,6 +79,7 @@ impl ChamberEdit {
7879
widget: b,
7980
name_input: name_i,
8081
notes_input: notes_i,
82+
hidden_input: hidden_i,
8183
}));
8284

8385
control.borrow_mut().subscribe_any(re.clone());
@@ -98,6 +100,7 @@ impl StateEventSubscriber for ChamberEdit {
98100
let chamber = state.dungeon.chamber_mut(chamber_id).unwrap();
99101
self.name_input.set_text(&chamber.name);
100102
self.notes_input.buffer().set_text(&chamber.notes);
103+
self.hidden_input.set_active(chamber.hidden);
101104
self.widget.set_visible(true);
102105
}
103106
StateEvent::Reset => self.widget.set_visible(false),

src/view/door_edit.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cell::RefCell;
22
use std::rc::Rc;
33

44
use gtk::glib::clone;
5-
use gtk::{gio, glib, DropDown, Expression, ListItem, SignalListItemFactory};
5+
use gtk::{gio, glib, CheckButton, DropDown, Expression, ListItem, SignalListItemFactory};
66
use gtk::{prelude::*, Label, TextView};
77
use gtk::{Box, Entry};
88

@@ -18,6 +18,7 @@ pub struct DoorEdit {
1818
name_input: Entry,
1919
notes_input: TextView,
2020
leads_to_input: DropDown,
21+
hidden_input: CheckButton,
2122
chambers_model: gio::ListStore,
2223
}
2324

@@ -29,6 +30,7 @@ impl DoorEdit {
2930
.left_margin(10)
3031
.right_margin(10)
3132
.build();
33+
let hidden_i = CheckButton::builder().label("Hidden").build();
3234

3335
let chamber_vec: Vec<ChamberObject> =
3436
vec![ChamberObject::new(None, "-- No Chamber --".to_owned())];
@@ -115,6 +117,15 @@ impl DoorEdit {
115117
}
116118
}));
117119

120+
hidden_i.connect_toggled(
121+
clone!(@strong control => move |w| if let Ok(mut control) = control.try_borrow_mut() {
122+
match control.state.active_door_id {
123+
None => (),
124+
Some(door_id) => control.apply(StateCommand::ChangeDoorHidden(door_id, w.is_active())),
125+
}
126+
}),
127+
);
128+
118129
let b = Box::builder()
119130
.orientation(gtk::Orientation::Vertical)
120131
.build();
@@ -123,6 +134,7 @@ impl DoorEdit {
123134
b.append(&part_of_label);
124135
b.append(&Label::new(Some("Name")));
125136
b.append(&name_i);
137+
b.append(&hidden_i);
126138
b.append(&Label::new(Some("Notes")));
127139
b.append(&notes_i);
128140
b.append(&Label::new(Some("Leads to Chamber:")));
@@ -136,6 +148,7 @@ impl DoorEdit {
136148
name_input: name_i,
137149
notes_input: notes_i,
138150
leads_to_input: leads_to_i,
151+
hidden_input: hidden_i,
139152
chambers_model: model,
140153
}));
141154

@@ -177,6 +190,7 @@ impl StateEventSubscriber for DoorEdit {
177190
self.notes_input.buffer().set_text(&door.notes);
178191
self.leads_to_input
179192
.set_selected(self.chamber_object_pos(door.leads_to));
193+
self.hidden_input.set_active(door.hidden);
180194
self.widget.set_visible(true);
181195
}
182196
StateEvent::Reset => self.widget.set_visible(false),

0 commit comments

Comments
 (0)