tooltips for UI elements only. don't need the OSD fullscreen now.

This commit is contained in:
Dustin Carlino 2020-02-20 11:24:50 -08:00
parent 775a4d4035
commit 2a747ef46b
7 changed files with 9 additions and 27 deletions

View File

@ -1,4 +1,4 @@
use crate::{ScreenDims, ScreenPt, ScreenRectangle, Text, UserInput};
use crate::{ScreenDims, ScreenPt, ScreenRectangle, UserInput};
use abstutil::Timer;
use geom::{Bounds, Pt2D};
use serde_derive::{Deserialize, Serialize};
@ -33,8 +33,6 @@ pub struct Canvas {
// Kind of just ezgui state awkwardly stuck here...
pub(crate) lctrl_held: bool,
// This should be mutually exclusive among all buttons and things in map-space.
pub(crate) button_tooltip: Option<Text>,
}
impl Canvas {
@ -61,7 +59,6 @@ impl Canvas {
covered_areas: RefCell::new(Vec::new()),
lctrl_held: false,
button_tooltip: None,
}
}

View File

@ -208,7 +208,7 @@ impl<'a> GfxCtx<'a> {
let dims = txt_batch.get_dims();
// TODO Maybe also consider the cursor as a valid center
let pt = dims.top_left_for_corner(
ScreenPt::new(self.canvas.cursor_x, self.canvas.cursor_y),
ScreenPt::new(self.canvas.cursor_x, self.canvas.cursor_y + 20.0),
&self.canvas,
);
let mut batch = GeomBatch::new();
@ -259,10 +259,6 @@ impl<'a> GfxCtx<'a> {
self.prerender.upload(batch)
}
pub fn button_tooltip(&self) -> Option<Text> {
self.canvas.button_tooltip.clone()
}
// Delegation to assets
pub fn default_line_height(&self) -> f64 {
self.prerender.assets.default_line_height

View File

@ -50,8 +50,6 @@ impl<G: GUI> State<G> {
// Update some ezgui state that's stashed in Canvas for sad reasons.
{
self.canvas.button_tooltip = None;
if let Event::WindowResized(width, height) = input.event {
prerender.inner.window_resized(width, height);
self.canvas.window_width = width;

View File

@ -46,11 +46,12 @@ impl Button {
draw_hovered: ctx.upload(hovered),
hotkey,
tooltip: if let Some(key) = hotkey {
let mut txt = Text::from(Line(key.describe()).fg(text::HOTKEY_COLOR));
let mut txt =
Text::from(Line(key.describe()).fg(text::HOTKEY_COLOR).size(20)).with_bg();
txt.append(Line(format!(" - {}", tooltip)));
txt
} else {
Text::from(Line(tooltip))
Text::from(Line(tooltip).size(20)).with_bg()
},
hitbox,
@ -80,18 +81,15 @@ impl Button {
}
if self.hovering && ctx.normal_left_click() {
self.clicked = true;
self.hovering = false;
}
if let Some(hotkey) = self.hotkey {
if ctx.input.new_was_pressed(hotkey) {
self.clicked = true;
self.hovering = false;
}
}
if self.hovering {
// TODO Should we assert this is None?
ctx.canvas.button_tooltip = Some(self.tooltip.clone());
}
}
pub(crate) fn clicked(&mut self) -> bool {
@ -106,6 +104,7 @@ impl Button {
pub(crate) fn draw(&self, g: &mut GfxCtx) {
if self.hovering {
g.redraw_at(self.top_left, &self.draw_hovered);
g.draw_mouse_tooltip(self.tooltip.clone());
} else {
g.redraw_at(self.top_left, &self.draw_normal);
}

View File

@ -220,8 +220,6 @@ impl CommonState {
pub fn draw_osd(g: &mut GfxCtx, ui: &UI, id: &Option<ID>) {
let osd = if let Some(id) = id {
CommonState::default_osd(id.clone(), ui)
} else if let Some(button) = g.button_tooltip() {
button
} else {
Text::from(Line("..."))
};

View File

@ -1,4 +1,3 @@
use crate::common::CommonState;
use crate::options::Options;
use crate::pregame::TitleScreen;
use crate::render::DrawOptions;
@ -269,7 +268,7 @@ impl State for WizardState {
DrawBaselayer::PreviousState
}
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
fn draw(&self, g: &mut GfxCtx, _: &UI) {
// TODO This shouldn't get greyed out, but I think the weird z-ordering of screen-space
// right now is messing this up.
if let Some(ref d) = self.also_draw {
@ -279,8 +278,6 @@ impl State for WizardState {
State::grey_out_map(g);
self.wizard.draw(g);
// Still want to show hotkeys
CommonState::draw_osd(g, ui, &None);
}
}

View File

@ -1,5 +1,4 @@
use crate::colors;
use crate::common::CommonState;
use crate::game::{DrawBaselayer, State, Transition};
use crate::ui::UI;
use ezgui::{
@ -157,7 +156,5 @@ impl State for ManagedGUIState {
}
self.composite.draw(g);
// Still want to show hotkeys
CommonState::draw_osd(g, ui, &None);
}
}