mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
extend chat::Dialogue to accept Option<pddb_key>
extend ui.dialogue_set() to select existing Dialogue when operating offline
This commit is contained in:
parent
defac5ed7e
commit
62a3bae502
3 changed files with 32 additions and 24 deletions
|
|
@ -5,10 +5,8 @@ pub(crate) const SERVER_NAME_CHAT: &str = "Chat UI";
|
|||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum ChatOp {
|
||||
/// change focus
|
||||
ChangeFocus,
|
||||
///
|
||||
DialogueSet,
|
||||
DialogueSet = 128,
|
||||
///
|
||||
GamChangeFocus,
|
||||
/// a line of text has arrived
|
||||
|
|
@ -42,7 +40,7 @@ pub struct Find {
|
|||
#[derive(Archive, Serialize, Deserialize, Debug)]
|
||||
pub struct Dialogue {
|
||||
pub dict: xous_ipc::String<128>,
|
||||
pub key: xous_ipc::String<128>,
|
||||
pub key: Option<xous_ipc::String<128>>,
|
||||
}
|
||||
|
||||
#[derive(Archive, Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -42,20 +42,18 @@ impl Chat {
|
|||
self.cid
|
||||
}
|
||||
|
||||
pub fn read_only(pddb_dict: &str, pddb_key: &str) -> Self {
|
||||
let chat = Chat::new(None, None, None, None);
|
||||
pub fn read_only(pddb_dict: &str, pddb_key: Option<&str>) -> Self {
|
||||
let chat = Chat::new("_Chat Read_", "unused", None, None, None, None);
|
||||
chat.dialogue_set(pddb_dict, pddb_key).unwrap();
|
||||
chat
|
||||
}
|
||||
|
||||
// set the current Dialogue
|
||||
pub fn dialogue_set(&self, pddb_dict: &str, pddb_key: &str) -> Result<(), Error> {
|
||||
let mut dialogue = api::Dialogue {
|
||||
dict: xous_ipc::String::new(),
|
||||
key: xous_ipc::String::new(),
|
||||
pub fn dialogue_set(&self, pddb_dict: &str, pddb_key: Option<&str>) -> Result<(), Error> {
|
||||
let dialogue = api::Dialogue {
|
||||
dict: xous_ipc::String::from_str(pddb_dict),
|
||||
key: pddb_key.map(|key| xous_ipc::String::from_str(key)),
|
||||
};
|
||||
dialogue.dict.append(pddb_dict).unwrap();
|
||||
dialogue.key.append(pddb_key).unwrap();
|
||||
match Buffer::into_buf(dialogue) {
|
||||
Ok(buf) => buf.send(self.cid, ChatOp::DialogueSet as u32).map(|_| ()),
|
||||
Err(_) => Err(xous::Error::InternalError),
|
||||
|
|
@ -171,13 +169,15 @@ pub fn server(
|
|||
log::debug!("got message {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(ChatOp::DialogueSet) => {
|
||||
log::info!("ChatOp::DialogueSet");
|
||||
let buffer =
|
||||
unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let dialogue = buffer.to_original::<Dialogue, _>().unwrap();
|
||||
ui.dialogue_set(
|
||||
dialogue.dict.as_str().unwrap(),
|
||||
dialogue.key.as_str().unwrap(),
|
||||
);
|
||||
let dialogue_key = match dialogue.key {
|
||||
Some(key) => Some(key.to_string()),
|
||||
None => None,
|
||||
};
|
||||
ui.dialogue_set(dialogue.dict.as_str().unwrap(), dialogue_key.as_deref());
|
||||
}
|
||||
Some(ChatOp::GamChangeFocus) => {
|
||||
xous::msg_scalar_unpack!(msg, new_state_code, _, _, _, {
|
||||
|
|
|
|||
|
|
@ -207,17 +207,27 @@ impl Ui {
|
|||
}
|
||||
|
||||
// set the current Dialogue
|
||||
pub fn dialogue_set(&mut self, pddb_dict: &str, pddb_key: &str) {
|
||||
pub fn dialogue_set(&mut self, pddb_dict: &str, pddb_key: Option<&str>) {
|
||||
self.pddb_dict = Some(pddb_dict.to_string());
|
||||
self.pddb_key = Some(pddb_key.to_string());
|
||||
log::info!("Dialogue set to {}:{}", pddb_dict, pddb_key);
|
||||
self.pddb_key = pddb_key.map(|key| key.to_string());
|
||||
if self.pddb_key.is_none() {
|
||||
self.dialogue_modal();
|
||||
}
|
||||
log::info!("Dialogue set to {:?}:{:?}", self.pddb_dict, self.pddb_key);
|
||||
match self.dialogue_read() {
|
||||
Ok(_) => (),
|
||||
Ok(_) => {
|
||||
log::info!("read dialogue {:?}:{:?}", self.pddb_dict, self.pddb_key);
|
||||
self.redraw().expect("couldn't redraw screen");
|
||||
}
|
||||
Err(_) => {
|
||||
self.dialogue = Some(Dialogue::new(pddb_key));
|
||||
match self.dialogue_save() {
|
||||
Ok(_) => log::info!("Dialogue created {}:{}", pddb_dict, pddb_key),
|
||||
Err(e) => log::warn!("Failed to create Dialogue {}:{}", pddb_dict, pddb_key),
|
||||
if let Some(key) = &self.pddb_key {
|
||||
self.dialogue = Some(Dialogue::new(&key));
|
||||
match self.dialogue_save() {
|
||||
Ok(_) => log::info!("Dialogue created {}:{}", pddb_dict, key),
|
||||
Err(e) => {
|
||||
log::warn!("Failed to create Dialogue {}:{} : {e}", pddb_dict, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue