aboutsummaryrefslogtreecommitdiff
path: root/pixel-client
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client')
-rw-r--r--pixel-client/assets/misc.ini2
-rw-r--r--pixel-client/assets/textures/clouds.ta128
-rw-r--r--pixel-client/src/game.rs12
-rw-r--r--pixel-client/src/main.rs43
-rw-r--r--pixel-client/src/menu.rs89
-rw-r--r--pixel-client/src/render/font.rs5
-rw-r--r--pixel-client/src/render/misc.rs2
-rw-r--r--pixel-client/src/render/mod.rs9
-rw-r--r--pixel-client/src/render/sprite.rs10
-rw-r--r--pixel-client/src/ui.rs169
10 files changed, 444 insertions, 25 deletions
diff --git a/pixel-client/assets/misc.ini b/pixel-client/assets/misc.ini
index 59bd9132..19a4ba2f 100644
--- a/pixel-client/assets/misc.ini
+++ b/pixel-client/assets/misc.ini
@@ -13,3 +13,5 @@ conveyor-arrow=ew:conveyor_arrow_left
conveyor-arrow=we:conveyor_arrow_left~hflip
icon=pot_back,steak_in_pot~x4~y11,pot_front
+
+clouds=clouds
diff --git a/pixel-client/assets/textures/clouds.ta b/pixel-client/assets/textures/clouds.ta
new file mode 100644
index 00000000..f5b59c2b
--- /dev/null
+++ b/pixel-client/assets/textures/clouds.ta
@@ -0,0 +1,128 @@
+][[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[?[[[[[[[[[]]]]]]]]]]]]{{{{{{{{{]{{]]][[[[[[]]]{]]]]]]]]]]]]]]]]]}}}]]]]]]
+]][[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[????[[[[[[[[[]]]]]]]]]]{{}}}{{{{{{{{]]][[[[]]{{{]]]]]]]]]][[[[]]]}}}]]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[??????[[[[[[[[[]]]]]]]]{{}}}}}}{{{{{{{]]][[]]{{{{]]]]]]]]][[[[[[[]]]}}]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[?????????????[[]]]]]]]{{{}}}}}}}{{{{{{]]]]]{{{{{{]]][[[[[[[[[[[[[[[[]]]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[?[[??????????????[[]]]]]]{{{}}}}}}}}{{{{{{{]{{{{{{{]]][[[[[[[[[[[[[[[[[[]]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[]]]]]][[[[[[[[[[[[??????????????????[]]]]]]{{{}}}}{{{{{{{{{{{{{{{{{{]]][[[[[[[[[[[[[[[[[[[[]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[]]]]]]][[[[[[[[[[[[[????????????????[]]]]]]]{}}}}{{{{{{{{{{{{{{{{{{{]][[[[[[[[[[[[[[[[[[[[[]]]]]
+]]]]]]]]]]]]]]]]]]]]]]]]]]][[[]]]]]]]]]]][[[[[[[[[[[???????????????[[]]]]]]]]}}}{{{{{{{{{{{{{{{{{{{]]][[[[[[[[[[[[????????[[]]]]
+]]]]]]]]]]}]]]]{]]]]]]]]]]]]]]]]]]]{]{{]][[[[[[[[[[[[??????????????[]]]]]]]]]{}}{{{{{{{{{{{{{{{{{{]]][[[[[[[[[[[[?????????[[]]]]
+]]]]]]]]]]}}}}}{{{{{]]]]]]]]]]]]]]{{}{{{][[[[[[[[[[[??????????????[]]]]]]]]]{{}}{{{{{{{{{{{{{{{{{]]]][[[[[[[[[[???????????[[[[[[
+??]]]]}}}}}}}}}}{{{{{]]]]]]]]]]]]]{{}}}{][[[[[[[[[[[????????????[[[[]]]]{{{{{{}}}{{{{{{{{{{]]]]]]]]]][[[[[[[[[[???????????[[[[[[
+????]]}}}}}}}}}}{{{{{{]]]]]]]]]{{{{{{}}{][[[[[[[[[[[????????????[[[[[[[{{{{{{}}}}}{{{{{{{{]]]]]]]]]]]][[[[[[?[[???????????[[[[[?
+?????]]}}}}}}}}}}{{{{{{]]]]]]]{{{{{{{{{{][[[[[[[[[[[????????????[[[[[[[{{}}}}}}}}}}{{{{{]]]]]]]]]]]][[[[[[????????????????[[[???
+??????]]}}}}}}}}}}{{{{{]]]]]]{{{{{{{{{{]][[[[[[[[[[[[???????????[[[[[[[{{}}}}}}{{{{{{{{]]]]]]]]][[[[[[[?????????????????????????
+???????]]}}}}}}}}{{{{]]]]]]]{{{{{{{{{{]]]][[[[[[[[[[[[[[[[[??[[[[[[[[[{{{}}}}}{{{{{{]]]]]]]]]]]][[[[[???????????????????????????
+????????]]}}}}}}{{{]]]]]]]]]{{{{{{{{{{]]]]][[[[[[[[[[[[[[[[[[[[[[[[[[{{{{{}}}}{]]]]]]]]]]]]]]]][[[[[????????????????????????????
+?????????]]{}}}}{{]]]]]]]]]]{{{{{{{{]]]]]]][[[[[[[[[[[[[[[[[[[[[[{{{{{{{{{}}}}{]]]]]]]]]]]]]]][[[[[?????????????????????????????
+?????????]]{}}}}{{]]]]]]]]]]]{{{{{{]]]]]]]]]][[[[[[[[[[[[[[[[[[]]]]{{{{{{{{}}}{]]]]]]]]]]]]]][[[[[??????????????????????????????
+?????????]]]{}}}{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[]]]]]]]{{{{{{{{]]]]]]]]]]]]]]][[[[???????????????????????????????
+?????????]]]{{}}{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[]]][[[]]]]]]]]{{{]]]]]]][]]]]]]]]]]][[[????????????????????????????????
+????????]]]]{{{{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[]]]]][[[]]]]]]]{{]]]]]]]][[]]]]]]]]]][[[????????????????????????????????
+????????]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[]]{]][[[[]]]]]{{{]][[]][[[[[]]]]]]]]][[[????????????????????????????????
+????????]]][[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]{{]]]]][[]]{]][[[[[]]]{{{]]][[[[[[[[[]]]]]]]]]][[????????????????????????????????
+?????????[[[[[[[]][[[]]]]]]]]]]]]]]]{]]]]]{{{{{{{{]]]][[[]{]][[[[]]]{{}{{]]][[[[[[[[]]]]]]]]]][[[???????????????????????????????
+??????????[[[[[[[[[[]]]]]]]]]]]]]]]{{{{]{{{{{{{{{{{]]][[[]]]][[[]]]{{{}}{]]]]][[[[[]]]]]{]]]]]][[[[??[??????????????????????????
+???[[[[[[??[[[[[[[[[]]]]{{]]]{{{]]{{{{{{{{{{{{{{{{{]][[[[]]]][[]]]]{{}}}{]]]]]]]]]]]]]{{{{{{{{{[[[[[[[[[[???????????????????????
+??[[[[[[[??[[[[[[[[[]]]{{{{{{{{{{{{{{{{{{{{{{{{{{{]][[[[[[][[[[]]]{{{}}}{]]]]]]]]]]]]]{{{{{{{{{{[[[[[[[[[[[[????????????????????
+?[[[[[[[[??[[[[[[[[]]]{{{{{{{{{{{{{{{{{{{{{{{{{{]]]][[[[[[[[[[]]]{{{}}}{]]]]]]]]]]]]]]]{{{{{{{{{{[[[[[[[[[[[[[[[[???????????????
+??[[[[[[???[[[[[[[[]]]{{{{{{{{{{{{{{{{{{{{{{{{{]]]]]][[[[[]]]]]]]{{{}}{]]]]]]]]]]]]]]]]]{{{{{{{{{{{{[[[[[[[[[[[[[[[?????????????
+??????????]]][[[[[[]]]{{{{{{{{{{{{{{{{{{{{{{{{{]]]]]]][[[]]]]]]]]]{{{{]]]]]]]]]]]]]]]]]]{{{{{{{{{{{{{[[[[[[[[[[[[[[[????????????
+??]]]]]]]]]]]]][[[]]]]{{{{{{{{{}}}{{{{{{{{{{{{]]]]]]]]][]]]]]]]]]]{{]]]]]]]]]]]]]]]]]]]]{{{{{{{{{{{{{[[[[[[[[[[[[[[[????????????
+]]]]{{{{]]]]]]]][[]]]]]{{{{{{{{}}}}}{{{{{{{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]{{{{{{{{}}{{{{{{{{{[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[[[[[[[[[]]]]]]]]]]]]]]]]]
+]]]]]][[[[[[[[[[[????????[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]{{]]]]{{{{{{{{{{{{]]]]]]]]]][[[[[[[[[[[???[[[[[[[[[[[[[]]]]]]]][[[[[[[]]
+]]]]][[[[[[[[[[[[??????????[[????[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]{{{{{{{{{{{]]]][[[[[[[[[[[[[[[[??????[[[[[[[[[[[]]]][[[[[[[[[[[[[
+]]]][[[[[[[[[[[[[[????????????????[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]{{{{{{{{{{{][[[[[[[[[[[[[[[[[????????[[[[[[[[[[[[[[[[[[[[[[[[[[[
+]]][[[[[[[[[[[[[[??????????????????[[[[[[[[]]]]]]]]]]]]]]]]]]]{]]{{{{{{{{{{[[[[[[[[[[[[[??[[?????????[[[[[[[[[[[[[[[[[[[[[[[[[[[
+[]][[[[[[??????[[???????????????????[[[[[[[]]]]]]]]]]]]]]]]]]]{{{{{{{{{{{{{[[[[[[[[[[[[??????????????[[[[[[[[[[[[[[[[[[[[[[[[[[[
+[[][[[[[????????????????????????????[[[[[[[[]]]]]]]]]]]]]]]]]]]{{{{{{{{{{{{[[[[[[[[[[[???????????????[[[[[[[[[[[[[[[[[[[[[[[[[[[
+[[]][[[[??????????????????????????[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]{{{{{{{{{{[[[[[[[[[[[[???????????????[[[[[[[[[[[[[[[[[[[[[[[[[[[
+[[]][[[[??????????????????????????[[[[[[[[[]]]]]][[[[]]]]]]]]]]]{{{{{]{{{{[[[[[[[[[[[[???????????????[[[[[[[[[[[[[[[[[[[[{{[[[[[
+[]][[[[[??????????????????????????[[[[[[[[[]]]][[[[[[[]]]]]]]]]]]]]]]]{{{{[[[[[[[[[[[???????????????[[[[[[[[[[[[[[[[[[[{{{{{{{[[
+[[[[[[[[??????????????????????????[[[[[[[[[]]]][[[[[[[[]]]]]]]]]]]]]]]]]]{[[[[[[[[[[[??????????????[[[[[[[[[[[[[[[[[[[[{{{{{{{[[
+[[[[[[[???[?????????????????????[[[[?????[[[]][[[[[[[[[]]]]]]]]]]]]]]]]]]][[[[[[[[[[[?????????????[[[[[[[[[[[[[[[[[[[[[[{{{{{{[[
+[[[[[[???[[[???????????????????[[[?????????[[][[[[[[[[[]]]]]]]]]]]]]]]]]]][[[[[[[[[[[?????????????[[[[[[[[[[[[[[[[[[[[[[[{{{{{{[
+[[[[[[???[[[[???????????[[????[[[???????????[]][[[[[[[[[]]]]]]]]]]]]]]]]]][[[[[[[[[[[[?????????????[[[[[[[[[[[[[[[[[[[[[[[{{{{{[
+[[[[[[[[[[[[[[?????????[[[??????????????????[[][[[[[[[[[]]]]]]]]]]]]]]]]]][[[[[[[[[[[[??????????????[[[[[[[[[[[[[[[[[[[[[[[{{{{[
+[[[[[[[[[[[[[[[?????????????????????????????[[][[[[[[[[[][[]]]]]]]]]]]]]]][[[[[[[[[[[[?????[[???[[?[[[[[[[[[[[[[[[[[[[[[[[[{{{{[
+[[[[[[[[[[[[[[[[???????????????????????????[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]][[[[[[[[[[[[????[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{{{{[
+]][[[[[[[[[[[[[[[[[[[[[[?????????????????[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]{][[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{{{{[
+]][[[[[[[[[[[[[[[[[[[[[[????????????[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]{{]][[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{{{{{{
+{]][[[[[[[[[[[[[[[[[[[[[[????????[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]{}}{{][[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{{{}{{
+{{]]][[[[[[[[[[[[[[[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]]]]]][[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]{{{{{{]]]]{{{{]]]]]]]]]]]][[[[[]]]{}}}}{]]{{{{{{{{{{{{{{
+{{{]]]]]]]]]]]]]]]][[[]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]{{{{{{{{{{{{{{{]]]]]]]]]]]]][[]]]]]{{}}{{]{{{{{{{{{{{{{{{
+{{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]{{{{{{{{{{{{{{{]]]]]]]]]]]]]]]]]]]]]{{{{]{{{{{{{{{{{{{{{{
+{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]{{{{{{{{{{{{]]]]]]]]]]]]]]]]]]]]]]]]]]]]]{{{{{{]{{{{{{{{{
+]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]{{{{{{{{{{{]]]]]]]]][[[]]]]]]]]]]]]]]]]{{{{{]]]]]{{{{{{{
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs
index cc1645d9..af387b95 100644
--- a/pixel-client/src/game.rs
+++ b/pixel-client/src/game.rs
@@ -24,6 +24,7 @@ use crate::{
AtlasLayout, Renderer,
},
tilemap::Tilemap,
+ State,
};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
@@ -106,7 +107,12 @@ impl Game {
}
}
- pub fn tick(&mut self, dt: f32, keyboard: &KeyboardState, layout: &AtlasLayout) {
+ pub fn tick(
+ &mut self,
+ dt: f32,
+ keyboard: &KeyboardState,
+ layout: &AtlasLayout,
+ ) -> Option<Box<State>> {
self.network.poll();
// TODO perf
@@ -192,7 +198,9 @@ impl Game {
self.items_removed.retain_mut(|i| {
i.tick(0., dt);
i.alive > 0.01
- })
+ });
+
+ None
}
pub fn packet_in(&mut self, packet: PacketC, layout: &AtlasLayout) {
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index 8c140fc5..05e19194 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -22,11 +22,7 @@ use hurrycurry_protocol::glam::Vec2;
use menu::Menu;
use network::Network;
use render::Renderer;
-use sdl2::{
- event::Event,
- keyboard::{KeyboardState, Keycode},
- pixels::Color,
-};
+use sdl2::{event::Event, keyboard::KeyboardState, mouse::MouseState, pixels::Color};
use std::time::{Duration, Instant};
pub mod game;
@@ -35,6 +31,7 @@ pub mod menu;
pub mod network;
pub mod render;
pub mod tilemap;
+pub mod ui;
#[derive(Debug, Parser)]
pub struct Args {
@@ -52,9 +49,10 @@ pub enum Action {
},
}
-enum State {
+pub enum State {
Ingame(Box<Game>),
Menu(Menu),
+ Quit,
}
fn main() {
@@ -105,18 +103,25 @@ fn main() {
renderer.size = Vec2::new(width as f32, height as f32);
let keyboard = KeyboardState::new(&events);
+ let mouse = MouseState::new(&events);
+
let dt = last_tick.elapsed().min(Duration::from_secs_f32(1. / 30.));
- match &mut state {
+ let next = match &mut state {
State::Ingame(x) => x.tick(dt.as_secs_f32(), &keyboard, renderer.atlas_layout()),
- State::Menu(x) => x.tick(dt.as_secs_f32(), &keyboard, renderer.atlas_layout()),
+ State::Menu(x) => x.tick(dt.as_secs_f32(), &keyboard, &mouse, renderer.atlas_layout()),
+ State::Quit => break,
+ };
+ if let Some(next) = next {
+ state = *next;
}
last_tick += dt;
- renderer.ui_scale = Vec2::new(5., 5.);
+ renderer.set_ui_view(4.);
match &mut state {
State::Ingame(x) => x.draw(&mut renderer),
State::Menu(x) => x.draw(&mut renderer),
+ State::Quit => (),
}
canvas.set_draw_color(Color::BLACK);
@@ -126,11 +131,23 @@ fn main() {
for event in events.poll_iter() {
match event {
- Event::Quit { .. }
- | Event::KeyDown {
- keycode: Option::Some(Keycode::Escape),
+ Event::Quit { .. } => break 'mainloop,
+ Event::KeyUp {
+ keycode: Some(keycode),
+ ..
+ } => match &mut state {
+ State::Ingame(_) => (),
+ State::Menu(menu) => menu.keyboard_event(keycode, false),
+ _ => (),
+ },
+ Event::KeyDown {
+ keycode: Some(keycode),
..
- } => break 'mainloop,
+ } => match &mut state {
+ State::Ingame(_) => (),
+ State::Menu(menu) => menu.keyboard_event(keycode, true),
+ _ => (),
+ },
_ => {}
}
}
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs
index 22a0244a..9ebe525e 100644
--- a/pixel-client/src/menu.rs
+++ b/pixel-client/src/menu.rs
@@ -1,17 +1,27 @@
use crate::{
- render::{AtlasLayout, Renderer},
+ game::Game,
+ network::Network,
+ render::{sprite::SpriteDraw, AtlasLayout, Renderer},
tilemap::Tilemap,
+ ui::UiState,
+ State,
};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
TileIndex,
};
use rand::{random, seq::IndexedRandom, thread_rng};
-use sdl2::keyboard::KeyboardState;
+use sdl2::{
+ keyboard::{KeyboardState, Keycode},
+ mouse::MouseState,
+};
-#[derive(Debug)]
pub struct Menu {
map: Tilemap,
+ fade_in: f32,
+ ui_state: UiState,
+ background: Vec2,
+ next_state: Option<Box<State>>,
}
impl Menu {
@@ -44,15 +54,80 @@ impl Menu {
}
}
- Self { map }
+ Self {
+ map,
+ fade_in: 0.,
+ ui_state: UiState::default(),
+ background: Vec2::ZERO,
+ next_state: None,
+ }
+ }
+ pub fn tick(
+ &mut self,
+ dt: f32,
+ keyboard: &KeyboardState,
+ mouse: &MouseState,
+ _layout: &AtlasLayout,
+ ) -> Option<Box<State>> {
+ self.fade_in = (self.fade_in + dt).min(1.);
+ self.background += Vec2::new(2., 3.) * dt;
+ self.ui_state.update(keyboard, mouse, dt);
+
+ self.next_state.take()
}
- pub fn tick(&mut self, _dt: f32, _keyboard: &KeyboardState, _layout: &AtlasLayout) {}
- pub fn draw(&self, ctx: &mut Renderer) {
+ pub fn keyboard_event(&mut self, keycode: Keycode, down: bool) {
+ self.ui_state.keyboard_event(keycode, down);
+ }
+ pub fn draw(&mut self, ctx: &mut Renderer) {
ctx.set_world_view(
ctx.size / ctx.get_world_scale() * Vec2::new(0.8, 0.2),
ctx.size.max_element() / 32. / 15.,
);
+
+ for x in -1..=2 {
+ for y in -1..=2 {
+ ctx.draw_ui(SpriteDraw::underlay(
+ ctx.misc_textures.clouds,
+ Vec2::new(x as f32, y as f32) * 256. + self.background,
+ Vec2::ONE * 256.,
+ None,
+ ));
+ }
+ }
+ ctx.draw_ui(SpriteDraw::underlay(
+ ctx.misc_textures.solid,
+ Vec2::ZERO,
+ ctx.ui_size,
+ Some([0, 0, 0, 50]),
+ ));
+
self.map.draw(ctx);
- ctx.draw_text(Vec2::new(1., 1.), "Hello world!");
+
+ let mut request_join = false;
+ self.ui_state.draw(ctx, |ui| {
+ if ui.button(80., "Join") {
+ request_join = true
+ }
+ if ui.button(80., "Settings") {
+ eprintln!("settings button")
+ }
+ if ui.button(80., "Quit") {
+ self.next_state = Some(Box::new(State::Quit));
+ }
+ ui.fill();
+ });
+ if request_join {
+ self.next_state = Some(Box::new(State::Ingame(Box::new(Game::new(
+ Network::connect("ws://127.0.0.1").unwrap(),
+ ctx.atlas_layout(),
+ )))))
+ }
+
+ ctx.draw_ui(SpriteDraw::overlay(
+ ctx.misc_textures.solid,
+ Vec2::ZERO,
+ ctx.ui_size,
+ Some([0, 0, 0, 255 - (self.fade_in * 255.) as u8]),
+ ));
}
}
diff --git a/pixel-client/src/render/font.rs b/pixel-client/src/render/font.rs
index ff4abade..38ebe711 100644
--- a/pixel-client/src/render/font.rs
+++ b/pixel-client/src/render/font.rs
@@ -25,8 +25,9 @@ impl FontTextures {
}
impl<'a> Renderer<'a> {
- pub fn draw_text(&mut self, position: Vec2, text: &str) {
+ pub fn draw_text(&mut self, position: Vec2, text: &str) -> Vec2 {
let mut cursor = position;
+ let mut line_height = 0f32;
for c in text.chars() {
if (c as u32) < 128 {
let r = self.font_textures.glyphs[c as usize];
@@ -37,7 +38,9 @@ impl<'a> Renderer<'a> {
None,
));
cursor.x += r.width() as f32;
+ line_height = line_height.max(r.height() as f32)
}
}
+ (cursor - position.y) + Vec2::Y * line_height
}
}
diff --git a/pixel-client/src/render/misc.rs b/pixel-client/src/render/misc.rs
index 05cde8e4..2197b89c 100644
--- a/pixel-client/src/render/misc.rs
+++ b/pixel-client/src/render/misc.rs
@@ -24,6 +24,7 @@ pub struct MiscTextures {
pub customer: Sprite,
pub interact_target: Sprite,
pub solid: Rect,
+ pub clouds: Rect,
}
impl MiscTextures {
@@ -37,6 +38,7 @@ impl MiscTextures {
10.,
),
solid: *layout.get("solid+a").unwrap(),
+ clouds: *layout.get("clouds+a").unwrap(),
}
}
}
diff --git a/pixel-client/src/render/mod.rs b/pixel-client/src/render/mod.rs
index 9b3132f9..74c282f3 100644
--- a/pixel-client/src/render/mod.rs
+++ b/pixel-client/src/render/mod.rs
@@ -21,6 +21,7 @@ pub mod sprite;
use font::FontTextures;
use hurrycurry_protocol::glam::Vec2;
+use misc::MiscTextures;
use sdl2::{
pixels::PixelFormatEnum,
rect::{FRect, Rect},
@@ -34,8 +35,10 @@ pub struct Renderer<'a> {
metadata: AtlasLayout,
font_textures: FontTextures,
+ pub misc_textures: MiscTextures,
pub size: Vec2,
+ pub ui_size: Vec2,
texture: Texture<'a>,
world_scale: Vec2,
@@ -109,6 +112,8 @@ impl<'a> Renderer<'a> {
Self {
ui_scale: Vec2::ZERO,
+ ui_size: Vec2::ZERO,
+ misc_textures: MiscTextures::init(&atlas_layout),
texture,
font_textures: FontTextures::init(&atlas_layout),
size: Vec2::ONE,
@@ -123,6 +128,10 @@ impl<'a> Renderer<'a> {
self.world_offset = offset;
self.world_scale = Vec2::new(32., 24.) * scale;
}
+ pub fn set_ui_view(&mut self, scale: f32) {
+ self.ui_scale = Vec2::splat(scale);
+ self.ui_size = self.size / self.ui_scale;
+ }
pub fn get_world_scale(&self) -> Vec2 {
self.world_scale
}
diff --git a/pixel-client/src/render/sprite.rs b/pixel-client/src/render/sprite.rs
index 084e277e..292a99ab 100644
--- a/pixel-client/src/render/sprite.rs
+++ b/pixel-client/src/render/sprite.rs
@@ -65,14 +65,20 @@ pub struct SpriteDraw {
}
impl SpriteDraw {
- pub fn overlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ pub fn screen(src: Rect, z_order: i32, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
Self {
dst: FRect::new(pos.x, pos.y, size.x, size.y),
src,
tint: tint.unwrap_or([0xff; 4]),
- z_order: i32::MAX,
+ z_order,
}
}
+ pub fn overlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ SpriteDraw::screen(src, i32::MAX, pos, size, tint)
+ }
+ pub fn underlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ SpriteDraw::screen(src, i32::MIN, pos, size, tint)
+ }
pub fn alpha(mut self, alpha: f32) -> Self {
self.tint[3] = (alpha.clamp(0., 1.) * 255.) as u8;
self
diff --git a/pixel-client/src/ui.rs b/pixel-client/src/ui.rs
new file mode 100644
index 00000000..802c8e2f
--- /dev/null
+++ b/pixel-client/src/ui.rs
@@ -0,0 +1,169 @@
+use crate::render::{sprite::SpriteDraw, Renderer};
+use hurrycurry_protocol::glam::{IVec2, Vec2};
+use sdl2::{
+ keyboard::{KeyboardState, Keycode, Scancode},
+ mouse::MouseState,
+};
+
+#[derive(Default)]
+pub struct FocusDevice {
+ focus: usize,
+ pressing: Option<usize>,
+ interact_just_pressed: bool,
+ interact_just_released: bool,
+ interact_down: bool,
+}
+
+#[derive(Default)]
+pub struct UiState {
+ mouse_position: Vec2,
+ ui_scale: Vec2,
+
+ keyboard_focus: FocusDevice,
+ mouse_focus: FocusDevice,
+}
+
+pub struct Ui<'a, 'b> {
+ cursor: Vec2,
+ size: Vec2,
+ cross_height: f32,
+ index: usize,
+ direction_horizontal: bool,
+ renderer: &'a mut Renderer<'b>,
+ state: &'a mut UiState,
+}
+
+impl UiState {
+ pub fn update(&mut self, keyboard: &KeyboardState, mouse: &MouseState, _dt: f32) {
+ self.mouse_position = IVec2::new(mouse.x(), mouse.y()).as_vec2() / self.ui_scale;
+
+ self.mouse_focus.update(mouse.left());
+ self.keyboard_focus
+ .update(keyboard.is_scancode_pressed(Scancode::Space));
+ }
+ pub fn keyboard_event(&mut self, keycode: Keycode, down: bool) {
+ if down {
+ match keycode {
+ Keycode::DOWN => self.keyboard_focus.focus += 1,
+ Keycode::UP if self.keyboard_focus.focus > 0 => self.keyboard_focus.focus -= 1,
+ _ => (),
+ }
+ }
+ }
+
+ pub fn draw(&mut self, renderer: &mut Renderer, ui: impl FnOnce(&mut Ui)) {
+ self.ui_scale = renderer.ui_scale;
+ self.mouse_focus.focus = usize::MAX;
+ let mut u = Ui {
+ cursor: Vec2::ZERO,
+ direction_horizontal: false,
+ size: renderer.ui_size,
+ renderer,
+ state: self,
+ cross_height: 0.,
+ index: 0,
+ };
+ ui(&mut u);
+
+ if self.mouse_focus.interact_just_released {
+ self.mouse_focus.pressing = None;
+ }
+ if self.keyboard_focus.interact_just_released {
+ self.keyboard_focus.pressing = None;
+ }
+ }
+}
+
+impl FocusDevice {
+ pub fn update(&mut self, interact: bool) {
+ self.interact_just_pressed = interact && !self.interact_down;
+ self.interact_just_released = !interact && self.interact_down;
+ self.interact_down = interact;
+ }
+ pub fn element(&mut self, index: usize) -> (bool, bool, bool) {
+ let focus = self.focus == index;
+ if focus && self.interact_just_pressed {
+ self.pressing = Some(index)
+ };
+ let pressing = self.pressing == Some(index);
+ let released = self.interact_just_released && pressing && focus;
+ (focus, pressing, released)
+ }
+}
+
+impl<'a, 'b> Ui<'a, 'b> {
+ pub fn text(&mut self, text: &str) {
+ let margin = Vec2::splat(2.);
+ let size = margin + self.renderer.draw_text(self.cursor + margin, text) + margin;
+ self.advance(size);
+ }
+ pub fn button(&mut self, w: f32, label: &str) -> bool {
+ let c = self.cursor;
+ let margin = Vec2::splat(4.);
+ let text_size = self.renderer.draw_text(self.cursor + margin, label);
+ let size = margin + Vec2::new(w, text_size.y) + margin;
+
+ self.index += 1;
+
+ let mouse_rel = self.state.mouse_position - c;
+ if mouse_rel.x >= 0. && mouse_rel.y >= 0. && mouse_rel.x < size.x && mouse_rel.y < size.y {
+ self.state.mouse_focus.focus = self.index;
+ }
+
+ let (focus, pressing, released) = {
+ let (mfocus, mpressing, mreleased) = self.state.mouse_focus.element(self.index);
+ let (kfocus, kpressing, kreleased) = self.state.keyboard_focus.element(self.index);
+ (
+ mfocus || kfocus,
+ mpressing || kpressing,
+ mreleased || kreleased,
+ )
+ };
+
+ let l = if pressing {
+ 100
+ } else if focus {
+ 50
+ } else {
+ 30
+ };
+ self.renderer.draw_ui(SpriteDraw::screen(
+ self.renderer.misc_textures.solid,
+ i32::MAX - 1,
+ c,
+ size,
+ Some([l, l, l, 200]),
+ ));
+
+ self.advance(size);
+ released
+ }
+
+ pub fn fill(&mut self) {
+ self.renderer.draw_ui(SpriteDraw::screen(
+ self.renderer.misc_textures.solid,
+ i32::MAX - 1,
+ self.cursor,
+ self.get_remaining(),
+ Some([30, 30, 30, 200]),
+ ));
+ }
+
+ pub fn get_remaining(&self) -> Vec2 {
+ if self.direction_horizontal {
+ Vec2::new(self.size.x - self.cursor.x, self.cross_height)
+ } else {
+ Vec2::new(self.cross_height, self.size.y - self.cursor.y)
+ }
+ }
+
+ pub fn advance(&mut self, size: Vec2) {
+ if self.direction_horizontal {
+ self.cursor.x += size.x;
+ self.cross_height = self.cross_height.max(size.y);
+ } else {
+ self.cursor.y += size.y;
+ self.cross_height = self.cross_height.max(size.x);
+ }
+ }
+}