Refactorings/Fixes related to emoting
This commit is contained in:
parent
d88e8ef9f3
commit
b4eaba09c5
3 changed files with 48 additions and 10 deletions
|
@ -49,7 +49,7 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
}
|
}
|
||||||
div.emote_wrapper {
|
div.emote_wrapper {
|
||||||
grid-row: 3;
|
grid-row: 4;
|
||||||
grid-column: 8;
|
grid-column: 8;
|
||||||
display: grid;
|
display: grid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,14 @@ impl GameState {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_singleplayer_current_side(&self) -> Option<Turn> {
|
||||||
|
if let GameState::SinglePlayer(turn, _) = *self {
|
||||||
|
Some(turn)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameState {
|
impl Default for GameState {
|
||||||
|
|
|
@ -256,13 +256,43 @@ impl Component for EmoteButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
fn update(&mut self, ctx: &Context<Self>, _msg: Self::Message) -> bool {
|
||||||
ctx.link()
|
let (shared, _) = ctx
|
||||||
.get_parent()
|
.link()
|
||||||
.expect("Wrapper should be parent of EmoteButton")
|
.context::<SharedState>(Callback::noop())
|
||||||
.clone()
|
.expect("state to be set");
|
||||||
.downcast::<Wrapper>()
|
let (_window, document) =
|
||||||
.send_message(WrapperMsg::SendEmote(ctx.props().emote));
|
get_window_document().expect("Should be able to get Window and Document");
|
||||||
|
|
||||||
|
if shared.game_state.borrow().is_networked_multiplayer() {
|
||||||
|
ctx.link()
|
||||||
|
.get_parent()
|
||||||
|
.expect("Wrapper should be parent of EmoteButton")
|
||||||
|
.clone()
|
||||||
|
.downcast::<Wrapper>()
|
||||||
|
.send_message(WrapperMsg::SendEmote(ctx.props().emote));
|
||||||
|
} else if let Some(side) = shared.game_state.borrow().get_singleplayer_current_side() {
|
||||||
|
append_to_info_text(
|
||||||
|
&document,
|
||||||
|
"info_text0",
|
||||||
|
&format!(
|
||||||
|
"<b class=\"{}\">{} emoted with <b class=\"emote\">{}</b></b>",
|
||||||
|
side.get_color(),
|
||||||
|
side,
|
||||||
|
ctx.props().emote.get_unicode()
|
||||||
|
),
|
||||||
|
INFO_TEXT_MAX_ITEMS,
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
} else {
|
||||||
|
append_to_info_text(
|
||||||
|
&document,
|
||||||
|
"info_text0",
|
||||||
|
"<b>Cannot use emotes at this time</b>",
|
||||||
|
INFO_TEXT_MAX_ITEMS,
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1508,7 +1538,7 @@ impl Component for Wrapper {
|
||||||
&document,
|
&document,
|
||||||
"info_text0",
|
"info_text0",
|
||||||
&format!(
|
&format!(
|
||||||
"<b class=\"{}\">{} sent <b class=\"emote\">{}</p></b>",
|
"<b class=\"{}\">{} sent <b class=\"emote\">{}</b></b>",
|
||||||
current_side.get_opposite().get_color(),
|
current_side.get_opposite().get_color(),
|
||||||
current_side.get_opposite(),
|
current_side.get_opposite(),
|
||||||
emote_enum.get_unicode()
|
emote_enum.get_unicode()
|
||||||
|
@ -1854,7 +1884,7 @@ impl Component for Wrapper {
|
||||||
&document,
|
&document,
|
||||||
"info_text0",
|
"info_text0",
|
||||||
&format!(
|
&format!(
|
||||||
"<b class=\"{}\">{} sent <b class=\"emote\">{}</p></b>",
|
"<b class=\"{}\">{} sent <b class=\"emote\">{}</b></b>",
|
||||||
current_side.get_color(),
|
current_side.get_color(),
|
||||||
current_side,
|
current_side,
|
||||||
emote.get_unicode()
|
emote.get_unicode()
|
||||||
|
|
Loading…
Reference in a new issue