Skip to content

Commit

Permalink
Merge pull request #267 from TruncateGame/main
Browse files Browse the repository at this point in the history
Production Release
  • Loading branch information
bglw authored May 23, 2024
2 parents 7b523c3 + f658754 commit 80da1e9
Show file tree
Hide file tree
Showing 19 changed files with 1,141 additions and 187 deletions.
16 changes: 16 additions & 0 deletions truncate_client/img/tile_order
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ GAME_PIECE_RUBBLE_2_NW
GAME_PIECE_RUBBLE_2_NE
GAME_PIECE_RUBBLE_2_SW
GAME_PIECE_RUBBLE_2_SE
SELECTION_SPINNER_1_NW
SELECTION_SPINNER_1_NE
SELECTION_SPINNER_1_SW
SELECTION_SPINNER_1_SE
SELECTION_SPINNER_2_NW
SELECTION_SPINNER_2_NE
SELECTION_SPINNER_2_SW
SELECTION_SPINNER_2_SE
SELECTION_SPINNER_3_NW
SELECTION_SPINNER_3_NE
SELECTION_SPINNER_3_SW
SELECTION_SPINNER_3_SE
SELECTION_SPINNER_4_NW
SELECTION_SPINNER_4_NE
SELECTION_SPINNER_4_SW
SELECTION_SPINNER_4_SE
DIALOG_NW
DIALOG_N
DIALOG_NE
Expand Down
Binary file modified truncate_client/img/truncate.aseprite
Binary file not shown.
Binary file modified truncate_client/img/truncate_packed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 26 additions & 4 deletions truncate_client/src/lil_bits/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ impl<'a> BoardUI<'a> {
}
}

if square_response.hovered() {
ui.output_mut(|o| {
o.cursor_icon = egui::CursorIcon::PointingHand
});
}

if square_response.clicked() {
if interactions.selected_tile_on_board.is_some() {
interactions.selected_tile_on_board = None;
}

if let Some((tile, _)) =
interactions.selected_tile_in_hand
{
Expand All @@ -165,10 +175,18 @@ impl<'a> BoardUI<'a> {
));

interactions.selected_tile_in_hand = None;
}

if interactions.selected_tile_on_board.is_some() {
interactions.selected_tile_on_board = None;
interactions.selected_square_on_board = None;
} else {
if interactions
.selected_square_on_board
.is_some_and(|(c, _)| c == coord)
{
interactions.selected_square_on_board =
None;
} else {
interactions.selected_square_on_board =
Some((coord, square.clone()));
}
}
}

Expand Down Expand Up @@ -234,6 +252,8 @@ impl<'a> BoardUI<'a> {
interactions.selected_tile_on_board =
Some((coord, *square));
}

interactions.selected_square_on_board = None;
}
let mut is_being_dragged =
ui.memory(|mem| mem.is_being_dragged(tile_id));
Expand All @@ -248,6 +268,8 @@ impl<'a> BoardUI<'a> {
}

if tile_response.drag_started() {
interactions.selected_square_on_board = None;

if let Some(pointer_pos) =
ui.ctx().pointer_interact_pos()
{
Expand Down
43 changes: 16 additions & 27 deletions truncate_client/src/lil_bits/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ use super::BattleUI;
pub struct DictionaryUI {
current_word: String,
is_valid: bool,
focus_in_n_frames: usize,
definitions: HashMap<String, Option<Vec<WordMeaning>>>,
}

impl DictionaryUI {
pub fn new() -> Self {
pub fn new(initial_focus: bool) -> Self {
Self {
current_word: String::new(),
is_valid: false,
focus_in_n_frames: if initial_focus { 2 } else { 0 },
definitions: HashMap::new(),
}
}
Expand Down Expand Up @@ -133,6 +135,15 @@ impl DictionaryUI {
))
.show(&mut input_ui);

if self.focus_in_n_frames > 0 {
if self.focus_in_n_frames == 1 {
input.response.request_focus();
self.focus_in_n_frames = 0;
} else {
self.focus_in_n_frames -= 1;
}
}

if (input.response.gained_focus() || input.response.has_focus())
&& !ui.input(|i| i.pointer.any_down())
{
Expand All @@ -157,6 +168,8 @@ impl DictionaryUI {
}

if !self.current_word.is_empty() {
depot.ui_state.dictionary_showing_definition = true;

let meanings = if self.is_valid {
let loading_meaning = if !self.definitions.contains_key(&self.current_word) {
Some(vec![WordMeaning {
Expand Down Expand Up @@ -201,33 +214,9 @@ impl DictionaryUI {

BattleUI::new(&report, false).render(&mut battle_ui, depot);
} else {
if depot.ui_state.dictionary_focused {
ui.add_space(20.0);

let (dialog_rect, _) = crate::utils::tex::paint_dialog_background(
false,
false,
true,
vec2(input_band_inner.width(), 200.0),
depot.aesthetics.theme.water.lighten().lighten(),
&depot.aesthetics.map_texture,
ui,
);
depot.ui_state.dictionary_showing_definition = false;

let dialog_text = TextHelper::light(
"Use the input above to check whether a word exists in Truncate's dictionary",
32.0,
Some(dialog_rect.shrink(16.0).width()),
ui,
);

dialog_text.paint_within(
dialog_rect,
Align2::CENTER_CENTER,
depot.aesthetics.theme.text,
ui,
);
} else {
if !depot.ui_state.dictionary_focused && self.focus_in_n_frames == 0 {
let text = TextHelper::heavy("Search", 20.0, None, ui);
text.paint_within(
input.response.rect,
Expand Down
2 changes: 2 additions & 0 deletions truncate_client/src/lil_bits/hand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ impl<'a> HandUI<'a> {
if started_interaction {
depot.ui_state.dictionary_open = false;
depot.ui_state.dictionary_focused = false;
depot.interactions.selected_square_on_board = None;
depot.interactions.selected_tile_on_board = None;
}
}
}
1 change: 0 additions & 1 deletion truncate_client/src/regions/active_game/control_strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ impl ActiveGame {
} else {
self.depot.ui_state.dictionary_open = true;
self.depot.ui_state.dictionary_focused = false;
self.dictionary_ui = Some(DictionaryUI::new());
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions truncate_client/src/regions/active_game/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ use eframe::{
emath::Align,
};

use crate::utils::tex::{render_tex_quad, tiles};
use crate::{
lil_bits::DictionaryUI,
utils::tex::{render_tex_quad, tiles},
};

use super::ActiveGame;

impl ActiveGame {
pub fn render_dictionary(&mut self, ui: &mut egui::Ui) -> Option<PlayerMessage> {
let mut msg = None;

// Guard for dictionary being closed (since it can't destroy itself)
if !self.depot.ui_state.dictionary_open {
self.depot.ui_state.dictionary_focused = false;
self.depot.ui_state.dictionary_opened_by_keyboard = false;
self.dictionary_ui = None;
}

if self.depot.ui_state.dictionary_open && self.dictionary_ui.is_none() {
self.dictionary_ui = Some(DictionaryUI::new(
self.depot.ui_state.dictionary_opened_by_keyboard,
));
}

if let Some(dict_ui) = self.dictionary_ui.as_mut() {
let area = egui::Area::new(egui::Id::new("dict_layer"))
.movable(false)
Expand All @@ -29,7 +45,7 @@ impl ActiveGame {
let button_size = 48.0;

area.show(ui.ctx(), |ui| {
if self.depot.ui_state.dictionary_focused {
if self.depot.ui_state.dictionary_showing_definition {
ui.painter().clone().rect_filled(
dict_alloc,
0.0,
Expand All @@ -50,6 +66,7 @@ impl ActiveGame {
// Guard for dictionary being closed (since it can't destroy itself)
if !self.depot.ui_state.dictionary_open {
self.depot.ui_state.dictionary_focused = false;
self.depot.ui_state.dictionary_opened_by_keyboard = false;
self.dictionary_ui = None;
}

Expand Down
10 changes: 9 additions & 1 deletion truncate_client/src/regions/active_game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use hashbrown::HashMap;
use crate::{
lil_bits::{BoardUI, DictionaryUI},
utils::{
control_devices,
depot::{
AestheticDepot, AudioDepot, BoardDepot, GameplayDepot, InteractionDepot, RegionDepot,
TimingDepot, TruncateDepot, UIStateDepot,
Expand Down Expand Up @@ -161,6 +162,13 @@ impl ActiveGame {
self.depot.aesthetics.qs_tick = cur_tick;
}

let kb_msg = control_devices::keyboard::handle_input(
ui.ctx(),
&self.board,
&self.hand,
&mut self.depot,
);

if !self.depot.ui_state.is_touch {
// If we ever receive any touch event,
// irrevocably put Truncate into touch mode.
Expand Down Expand Up @@ -237,7 +245,7 @@ impl ActiveGame {
.or(dict_player_message)
.or(sidebar_player_message);

player_message
kb_msg.or(player_message)
}

pub fn apply_new_state(&mut self, state_message: GameStateMessage) {
Expand Down
Loading

0 comments on commit 80da1e9

Please sign in to comment.