This commit is contained in:
Arkitu 2024-09-21 19:31:27 +02:00
parent 287b0d28d8
commit 303e39bd12
5 changed files with 45 additions and 43 deletions

View File

@ -10,7 +10,8 @@ use crate::{state::State, App};
#[derive(Clone, Copy, Zeroable, Pod, Debug)]
pub struct Vertex {
pub pos: [f32; 2],
pub color: [f32; 4]
pub color: [f32; 4],
pub effect: u32, // 0: None, 1: Grayscale, 2: Scaled, 3: Grayscale + Scaled
}
impl Vertex {
const DESC: VertexBufferLayout<'static> = VertexBufferLayout {

View File

@ -12,7 +12,8 @@ struct VertexOutput {
@vertex
fn vs_main(
@location(0) pos: vec2f,
@location(1) color: vec4f
@location(1) color: vec4f,
@location(2) effect: u32
) -> VertexOutput {
var out: VertexOutput;
out.color = color;
@ -23,4 +24,4 @@ fn vs_main(
@fragment
fn fs_main(v: VertexOutput) -> @location(0) vec4f {
return v.color;
}
}

View File

@ -196,9 +196,6 @@ impl State {
for (c, cd) in self.map.voronoi.iter_cells().zip(self.map.cells_data.iter()).filter(|(_,cd)| cd.kind != CellKind::Forest) {
let mut color = cd.color();
if self.ui.kind_selected != Kind::Terrain && self.ui.kind_selected != Kind::None {
color = rgba_to_grayscale(color);
}
if c.site() == self.selected_tile {
color[0] = (color[0]+0.4).clamp(0., 1.);
color[1] = (color[1]+0.4).clamp(0., 1.);
@ -207,7 +204,7 @@ impl State {
let vs = c.iter_vertices().collect::<Vec<_>>();
let i = self.vertices.len() as u32;
for v in vs.iter() {
self.vertices.push(Vertex { pos: [v.x as f32, v.y as f32], color });
self.vertices.push(Vertex { pos: [v.x as f32, v.y as f32], color, effect:2 });
}
for v in 1..(vs.len()-1) as u32 {
self.indices.push(i);
@ -230,7 +227,7 @@ impl State {
let vs = c.iter_vertices().collect::<Vec<_>>();
let i = self.vertices.len() as u32;
for v in vs.iter() {
self.vertices.push(Vertex { pos: [v.x as f32, v.y as f32], color });
self.vertices.push(Vertex { pos: [v.x as f32, v.y as f32], color, effect:2 });
}
for v in 1..(vs.len()-1) as u32 {
self.indices.push(i);
@ -321,4 +318,4 @@ impl State {
self.cells_entities.insert(cid, vec![eid]);
}
}
}
}

View File

@ -63,31 +63,31 @@ impl Entity {
(
[
// back left leg
Vertex { pos: [-0.5, 0.3], color: dark },
Vertex { pos: [-0.4 + (now.sin()*0.1), -0.7 + (now.cos().max(-0.5)*0.1)], color: dark },
Vertex { pos: [-0.25, 0.1], color: dark },
Vertex { pos: [-0.5, 0.3], color: dark, effect:2 },
Vertex { pos: [-0.4 + (now.sin()*0.1), -0.7 + (now.cos().max(-0.5)*0.1)], color: dark, effect:2 },
Vertex { pos: [-0.25, 0.1], color: dark, effect:2 },
// back right leg
Vertex { pos: [-0.5, 0.3], color },
Vertex { pos: [-0.4 + ((now + 1.).sin()*0.1), -0.7 + ((now + 1.).cos().max(-0.5)*0.1)], color },
Vertex { pos: [-0.25, 0.1], color },
Vertex { pos: [-0.5, 0.3], color, effect:2 },
Vertex { pos: [-0.4 + ((now + 1.).sin()*0.1), -0.7 + ((now + 1.).cos().max(-0.5)*0.1)], color, effect:2 },
Vertex { pos: [-0.25, 0.1], color, effect:2 },
// front left leg
Vertex { pos: [0.3, 0.2], color: dark },
Vertex { pos: [0.4 + ((now-1.).sin()*0.1), -0.7 + ((now-1.).cos().max(-0.5)*0.1)], color: dark },
Vertex { pos: [0.5, 0.3], color: dark },
Vertex { pos: [0.3, 0.2], color: dark, effect:2 },
Vertex { pos: [0.4 + ((now-1.).sin()*0.1), -0.7 + ((now-1.).cos().max(-0.5)*0.1)], color: dark, effect:2 },
Vertex { pos: [0.5, 0.3], color: dark, effect:2 },
// front right leg
Vertex { pos: [0.3, 0.2], color },
Vertex { pos: [0.4 + ((now-2.).sin()*0.1), -0.7 + ((now-2.).cos().max(-0.5)*0.1)], color },
Vertex { pos: [0.5, 0.3], color },
Vertex { pos: [0.3, 0.2], color, effect:2 },
Vertex { pos: [0.4 + ((now-2.).sin()*0.1), -0.7 + ((now-2.).cos().max(-0.5)*0.1)], color, effect:2 },
Vertex { pos: [0.5, 0.3], color, effect:2 },
// body
// 3
Vertex { pos: [-0.3, 0.], color },
Vertex { pos: [0.4, -0.1], color },
Vertex { pos: [-0.3, 0.], color, effect:2 },
Vertex { pos: [0.4, -0.1], color, effect:2 },
// 11
Vertex { pos: [0.3, 0.4], color },
Vertex { pos: [0.3, 0.4], color, effect:2 },
],
[
0,1,2,
@ -104,31 +104,31 @@ impl Entity {
(
[
// back left leg
Vertex { pos: [-0.5, 0.3], color: dark },
Vertex { pos: [-0.4, -0.75], color: dark },
Vertex { pos: [-0.25, 0.1], color: dark },
Vertex { pos: [-0.5, 0.3], color: dark, effect:2 },
Vertex { pos: [-0.4, -0.75], color: dark, effect:2 },
Vertex { pos: [-0.25, 0.1], color: dark, effect:2 },
// back right leg
Vertex { pos: [-0.5, 0.3], color },
Vertex { pos: [-0.4, -0.75], color },
Vertex { pos: [-0.25, 0.1], color },
Vertex { pos: [-0.5, 0.3], color, effect:2 },
Vertex { pos: [-0.4, -0.75], color, effect:2 },
Vertex { pos: [-0.25, 0.1], color, effect:2 },
// front left leg
Vertex { pos: [0.3, 0.2], color: dark },
Vertex { pos: [0.4, -0.75], color: dark },
Vertex { pos: [0.5, 0.3], color: dark },
Vertex { pos: [0.3, 0.2], color: dark, effect:2 },
Vertex { pos: [0.4, -0.75], color: dark, effect:2 },
Vertex { pos: [0.5, 0.3], color: dark, effect:2 },
// front right leg
Vertex { pos: [0.3, 0.2], color },
Vertex { pos: [0.4, -0.75], color },
Vertex { pos: [0.5, 0.3], color },
Vertex { pos: [0.3, 0.2], color, effect:2 },
Vertex { pos: [0.4, -0.75], color, effect:2 },
Vertex { pos: [0.5, 0.3], color, effect:2 },
// body
// 3
Vertex { pos: [-0.3, 0.], color },
Vertex { pos: [0.4, -0.1], color },
Vertex { pos: [-0.3, 0.], color, effect:2 },
Vertex { pos: [0.4, -0.1], color, effect:2 },
// 11
Vertex { pos: [0.3, 0.4], color },
Vertex { pos: [0.3, 0.4], color, effect:2 },
],
[
0,1,2,
@ -218,4 +218,4 @@ impl Entity {
None
}
}
}
}

View File

@ -2,6 +2,7 @@ use winit::event::{Touch, TouchPhase, WindowEvent};
use crate::graphics::Vertex;
const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.1;
const SECONDARY_COLOR: [f32; 4] = [255./84., 255./33., 255./32., 1.];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
@ -17,7 +18,7 @@ pub struct UI {
impl UI {
pub fn new() -> Self {
Self {
kind_selected: Kind::None,
kind_selected: Kind::Entities,
touch: None
}
}
@ -64,6 +65,8 @@ impl UI {
}
}
pub fn render(&self, vertices: &mut Vec<Vertex>, indices: &mut Vec<u32>) {
//let vs = [
// Vertex { color: SECONDARY_COLOR, pos: [] }
//];
}
}
}