Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,104 changes: 590 additions & 514 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pomme-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ rayon = "1.10"
fontdue = "0.9.3"
simdnbt = "0.10"
discord-rich-presence = "1.1"
arboard = "3"
12 changes: 6 additions & 6 deletions pomme-client/src/ui/menu/auth_screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl MainMenu {
};

if input.escape {
self.screen = Screen::Main;
self.set_screen(Screen::Main);
return empty_result(2.0);
}

Expand Down Expand Up @@ -81,7 +81,7 @@ impl MainMenu {
true,
) && input.clicked
{
self.screen = Screen::Auth { pending };
self.set_screen(Screen::Auth { pending });
auth::spawn_auth(
&self.rt,
Arc::clone(&self.auth_status),
Expand All @@ -103,7 +103,7 @@ impl MainMenu {
true,
) && input.clicked
{
self.screen = Screen::Main;
self.set_screen(Screen::Main);
}

MainMenuResult {
Expand All @@ -116,7 +116,7 @@ impl MainMenu {
}

pub(super) fn cancel_auth(&mut self) {
self.screen = Screen::Main;
self.set_screen(Screen::Main);
*self.auth_status.lock() = AuthStatus::Idle;
}

Expand Down Expand Up @@ -225,9 +225,9 @@ impl MainMenu {
}

match pending {
AuthPending::None | AuthPending::Singleplayer => self.screen = Screen::Main,
AuthPending::None | AuthPending::Singleplayer => self.set_screen(Screen::Main),
AuthPending::Multiplayer => {
self.screen = Screen::ServerList;
self.set_screen(Screen::ServerList);
self.scroll_offset = 0.0;
self.selected_server = None;
}
Expand Down
62 changes: 49 additions & 13 deletions pomme-client/src/ui/menu/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub(super) fn push_text_field(
gs: f32,
text: &str,
focused: bool,
all_selected: bool,
cursor_blink: &Instant,
text_width_fn: &dyn Fn(&str, f32) -> f32,
) {
Expand All @@ -132,27 +133,62 @@ pub(super) fn push_text_field(
});

let pad = 4.0 * gs;
let text_y = y + (h - fs) / 2.0;
let inner_w = w - pad * 2.0;

let (visible_text, text_w) = fit_text_end(text, fs, inner_w, text_width_fn);

elements.push(MenuElement::ScissorPush {
x: x + pad,
y,
w: inner_w,
h,
});

if focused && all_selected && !visible_text.is_empty() {
elements.push(MenuElement::Rect {
x: x + pad,
y: text_y,
w: text_w,
h: fs,
corner_radius: 0.0,
color: [0.3, 0.5, 0.9, 0.6],
});
}

elements.push(MenuElement::Text {
x: x + pad,
y: y + (h - fs) / 2.0,
text: text.into(),
y: text_y,
text: visible_text.into(),
scale: fs,
color: WHITE,
centered: false,
});

if focused {
let text_w = text_width_fn(text, fs);
common::push_cursor_blink(
elements,
cursor_blink,
x + pad,
y + (h - fs) / 2.0,
gs,
fs,
text_w,
);
if focused && !all_selected {
common::push_cursor_blink(elements, cursor_blink, x + pad, text_y, gs, fs, text_w);
}

elements.push(MenuElement::ScissorPop);
}

fn fit_text_end<'a>(
text: &'a str,
fs: f32,
max_w: f32,
text_width_fn: &dyn Fn(&str, f32) -> f32,
) -> (&'a str, f32) {
let full_w = text_width_fn(text, fs);
if full_w <= max_w {
return (text, full_w);
}
for (i, _) in text.char_indices() {
let w = text_width_fn(&text[i..], fs);
if w <= max_w {
return (&text[i..], w);
}
}
("", 0.0)
}

#[allow(clippy::too_many_arguments)]
Expand Down
8 changes: 4 additions & 4 deletions pomme-client/src/ui/menu/main_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl MainMenu {
match def.id {
0 => {}
1 => {
self.screen = Screen::ServerList;
self.set_screen(Screen::ServerList);
self.scroll_offset = 0.0;
self.selected_server = None;
}
Expand All @@ -238,7 +238,7 @@ impl MainMenu {
0 => AuthPending::Singleplayer,
_ => AuthPending::Multiplayer,
};
self.screen = Screen::AuthPrompt { pending };
self.set_screen(Screen::AuthPrompt { pending });
}
}
}
Expand Down Expand Up @@ -287,9 +287,9 @@ impl MainMenu {
any_clicked = true;
match icon {
ICON_USER if self.auth_account.is_none() => {
self.screen = Screen::AuthPrompt {
self.set_screen(Screen::AuthPrompt {
pending: AuthPending::None,
};
});
}
ICON_LINK => {
self.links_open = !self.links_open;
Expand Down
25 changes: 23 additions & 2 deletions pomme-client/src/ui/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ pub struct MenuInput {
pub escape: bool,
pub tab: bool,
pub f5: bool,
pub select_all: bool,
pub copy: bool,
pub cut: bool,
pub undo: bool,
pub scroll_delta: f32,
}

Expand Down Expand Up @@ -243,6 +247,10 @@ pub struct MainMenu {
transition: Option<ThemeTransition>,
scroll_offset: f32,
focused_field: Option<u8>,
field_all_selected: bool,
last_field_click_time: Instant,
last_field_click: Option<u8>,
field_undo_stack: Vec<(u8, String)>,
cursor_blink: Instant,
last_click_time: Instant,
last_click_index: Option<usize>,
Expand Down Expand Up @@ -306,6 +314,10 @@ impl MainMenu {
transition: None,
scroll_offset: 0.0,
focused_field: None,
field_all_selected: false,
last_field_click_time: Instant::now(),
last_field_click: None,
field_undo_stack: Vec::new(),
cursor_blink: Instant::now(),
last_click_time: Instant::now(),
last_click_index: None,
Expand Down Expand Up @@ -342,6 +354,15 @@ impl MainMenu {
}
}

fn set_screen(&mut self, screen: Screen) {
self.screen = screen;
self.focused_field = None;
self.field_all_selected = false;
self.last_field_click = None;
self.field_undo_stack.clear();
self.cursor_blink = Instant::now();
}

fn save_settings(&self) {
save_settings(
&self.settings_dir,
Expand All @@ -365,7 +386,7 @@ impl MainMenu {
}

pub fn open_options(&mut self) {
self.screen = Screen::Options;
self.set_screen(Screen::Options);
}

pub fn is_options_screen(&self) -> bool {
Expand Down Expand Up @@ -451,7 +472,7 @@ impl MainMenu {
}

pub fn show_disconnect(&mut self, reason: String) {
self.screen = Screen::Disconnected(reason);
self.set_screen(Screen::Disconnected(reason));
}

pub fn build(
Expand Down
35 changes: 19 additions & 16 deletions pomme-client/src/ui/menu/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl MainMenu {
tooltips: &[(&str, &str)],
) -> MainMenuResult {
if input.escape {
self.screen = back.clone_screen();
self.set_screen(back.clone_screen());
return empty_result(2.0);
}

Expand Down Expand Up @@ -563,7 +563,10 @@ impl MainMenu {
if matches!(target, Screen::OptionsResourcePacks) {
self.rescan_packs = true;
}
self.screen = target.clone_screen();
self.set_screen(target.clone_screen());
if matches!(self.screen, Screen::OptionsResourcePacks) {
self.focused_field = Some(0);
}
}
if label.starts_with("GUI Scale:") {
let max = crate::ui::hud::max_gui_scale(sw, sh);
Expand Down Expand Up @@ -676,7 +679,7 @@ impl MainMenu {
);
any_hovered |= h;
if clicked && h {
self.screen = back;
self.set_screen(back);
}

MainMenuResult {
Expand All @@ -699,10 +702,12 @@ impl MainMenu {

if input.escape {
self.pack_search.clear();
self.screen = Screen::Options;
self.set_screen(Screen::Options);
return empty_result(2.0);
}

self.handle_text_input(input, 1);

let gs = crate::ui::hud::gui_scale(sw, sh, self.gui_scale_setting);
let fs = common::FONT_SIZE * gs;
let btn_h = common::BTN_H * gs;
Expand Down Expand Up @@ -749,16 +754,10 @@ impl MainMenu {
});
header_y += fs + pad;

for ch in &input.typed_chars {
self.pack_search.push(*ch);
}
if input.backspace {
self.pack_search.pop();
}

let field_x = cx - list_w / 2.0;
push_text_field(
&mut elements,
cx - list_w / 2.0,
field_x,
header_y,
list_w,
field_h,
Expand All @@ -769,10 +768,14 @@ impl MainMenu {
} else {
&self.pack_search
},
true,
self.focused_field == Some(0),
self.focused_field == Some(0) && self.field_all_selected,
&self.cursor_blink,
text_width_fn,
);
if clicked && common::hit_test(cursor, [field_x, header_y, list_w, field_h]) {
self.on_field_click(0);
}
header_y += field_h + pad;

let content_top = header_y;
Expand Down Expand Up @@ -971,7 +974,7 @@ impl MainMenu {
any_hovered |= h;
if clicked && h {
self.pack_search.clear();
self.screen = Screen::Options;
self.set_screen(Screen::Options);
}

MainMenuResult {
Expand All @@ -992,7 +995,7 @@ impl MainMenu {
back: Screen,
) -> MainMenuResult {
if input.escape {
self.screen = back.clone_screen();
self.set_screen(back.clone_screen());
return empty_result(2.0);
}

Expand Down Expand Up @@ -1079,7 +1082,7 @@ impl MainMenu {
);
any_hovered |= h;
if input.clicked && h {
self.screen = back;
self.set_screen(back);
}

MainMenuResult {
Expand Down
Loading
Loading