Merge pull request #2414 from mahirsn/fix/sign-editor-update
🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed at this head; a re-review was asked, with no new objection since. Proven in wave 5's union run (cg20 union C 5900ab38793aa602315091ab4873615e93dda57d (main b6f18dc8f + 57 PRs) Mac mini 122/122 delta harness).
This commit is contained in:
@@ -3291,6 +3291,15 @@ impl Game<'_> {
|
|||||||
|
|
||||||
fn tick_remote_level(&mut self) -> Result<()> {
|
fn tick_remote_level(&mut self) -> Result<()> {
|
||||||
self.ticks += 1;
|
self.ticks += 1;
|
||||||
|
// AbstractSignEditScreen.tick: the editor closes once its sign is removed.
|
||||||
|
if let Some(edit) = &self.sign_edit
|
||||||
|
&& !matches!(
|
||||||
|
self.world.block_entities.get(&edit.pos),
|
||||||
|
Some(BlockEntity::Sign(_))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
self.close_sign_editor();
|
||||||
|
}
|
||||||
self.track_experience_display();
|
self.track_experience_display();
|
||||||
// Leaving a slot clears its bundle's selection here and on the server.
|
// Leaving a slot clears its bundle's selection here and on the server.
|
||||||
self.tick_bundle_hover();
|
self.tick_bundle_hover();
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ pub(super) struct SignEditor {
|
|||||||
pub line: usize,
|
pub line: usize,
|
||||||
/// The line being edited (`AbstractSignEditScreen`'s text field).
|
/// The line being edited (`AbstractSignEditScreen`'s text field).
|
||||||
edit: EditBox,
|
edit: EditBox,
|
||||||
|
/// `AbstractSignEditScreen.messages`: the side's lines as edited, sent
|
||||||
|
/// when the editor closes, even if the sign is gone by then.
|
||||||
|
lines: [String; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign_box() -> EditBox {
|
fn sign_box() -> EditBox {
|
||||||
@@ -185,11 +188,19 @@ impl Game<'_> {
|
|||||||
}
|
}
|
||||||
/// `SignBlock.openTextEdit` for the front side after placement.
|
/// `SignBlock.openTextEdit` for the front side after placement.
|
||||||
pub(super) fn open_sign_editor(&mut self, pos: (i32, i32, i32), front: bool) {
|
pub(super) fn open_sign_editor(&mut self, pos: (i32, i32, i32), front: bool) {
|
||||||
|
// Minecraft.setScreen: the editor already open is removed first.
|
||||||
|
self.close_sign_editor();
|
||||||
|
let lines = match self.world.block_entities.get(&pos) {
|
||||||
|
Some(BlockEntity::Sign(sign)) if front => sign.front.lines.clone(),
|
||||||
|
Some(BlockEntity::Sign(sign)) => sign.back.lines.clone(),
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
self.sign_edit = Some(SignEditor {
|
self.sign_edit = Some(SignEditor {
|
||||||
pos,
|
pos,
|
||||||
front,
|
front,
|
||||||
line: 0,
|
line: 0,
|
||||||
edit: sign_box(),
|
edit: sign_box(),
|
||||||
|
lines,
|
||||||
});
|
});
|
||||||
self.sign_load();
|
self.sign_load();
|
||||||
self.keys.clear();
|
self.keys.clear();
|
||||||
@@ -202,14 +213,11 @@ impl Game<'_> {
|
|||||||
pub(super) fn close_sign_editor(&mut self) {
|
pub(super) fn close_sign_editor(&mut self) {
|
||||||
if let Some(edit) = self.sign_edit.take() {
|
if let Some(edit) = self.sign_edit.take() {
|
||||||
if self.remote.is_some() {
|
if self.remote.is_some() {
|
||||||
if let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get(&edit.pos) {
|
self.send(S::SignUpdate(play::SignUpdate {
|
||||||
let side = if edit.front { &sign.front } else { &sign.back };
|
pos: [edit.pos.0, edit.pos.1, edit.pos.2],
|
||||||
self.send(S::SignUpdate(play::SignUpdate {
|
lines: edit.lines,
|
||||||
pos: [edit.pos.0, edit.pos.1, edit.pos.2],
|
front: edit.front,
|
||||||
lines: side.lines.clone(),
|
}));
|
||||||
front: edit.front,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
self.mark_block_entity_updated(edit.pos);
|
self.mark_block_entity_updated(edit.pos);
|
||||||
}
|
}
|
||||||
@@ -358,7 +366,8 @@ impl Game<'_> {
|
|||||||
edit.edit.set_value(&text);
|
edit.edit.set_value(&text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// The box's text onto the sign, when it still fits the line.
|
/// The box's text onto the editor's lines and the sign
|
||||||
|
/// (`AbstractSignEditScreen.setMessage`), when it still fits the line.
|
||||||
fn sign_write(&mut self) {
|
fn sign_write(&mut self) {
|
||||||
let Some(edit) = self.sign_edit.as_ref() else {
|
let Some(edit) = self.sign_edit.as_ref() else {
|
||||||
return;
|
return;
|
||||||
@@ -367,6 +376,9 @@ impl Game<'_> {
|
|||||||
if !self.sign_fits(&value) {
|
if !self.sign_fits(&value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if let Some(edit) = self.sign_edit.as_mut() {
|
||||||
|
edit.lines[line].clone_from(&value);
|
||||||
|
}
|
||||||
let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get_mut(&pos) else {
|
let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get_mut(&pos) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -147,10 +147,10 @@ fn component_text(tag: &Tag) -> String {
|
|||||||
_ => s,
|
_ => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tag::Compound(_) => match tag.get("text") {
|
// Component.getString: translations and key binds resolved.
|
||||||
Some(Tag::String(t)) => t.to_string_lossy(),
|
Tag::Compound(_) => {
|
||||||
_ => String::new(),
|
crate::scoreboard::comp_text(&crate::scoreboard::tag_to_json(tag)).plain()
|
||||||
},
|
}
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user