2015-09-21 08:08:06 -04:00
|
|
|
|
|
|
|
use std::sync::{Arc, RwLock};
|
2015-09-21 16:11:30 -04:00
|
|
|
use std::f64::consts;
|
2015-09-21 08:08:06 -04:00
|
|
|
use ui;
|
|
|
|
use render;
|
|
|
|
use resources;
|
2018-09-29 23:01:13 -04:00
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
2015-09-21 16:11:30 -04:00
|
|
|
use rand;
|
|
|
|
use rand::Rng;
|
2015-09-21 08:08:06 -04:00
|
|
|
|
|
|
|
pub struct Logo {
|
2016-04-24 07:22:04 -04:00
|
|
|
_shadow: ui::BatchRef,
|
|
|
|
_layer0: ui::BatchRef,
|
2015-09-21 16:11:30 -04:00
|
|
|
|
2016-04-24 07:22:04 -04:00
|
|
|
text: ui::TextRef,
|
2015-10-07 14:36:59 -04:00
|
|
|
text_base_scale: f64,
|
|
|
|
text_orig_x: f64,
|
|
|
|
text_index: isize,
|
|
|
|
text_strings: Vec<String>,
|
2015-09-21 08:08:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Logo {
|
2015-10-07 14:36:59 -04:00
|
|
|
pub fn new(resources: Arc<RwLock<resources::Manager>>,
|
|
|
|
ui_container: &mut ui::Container)
|
|
|
|
-> Logo {
|
2016-03-29 15:53:41 -04:00
|
|
|
let logo_str = {
|
2016-04-24 07:22:04 -04:00
|
|
|
let res = resources.read().unwrap();
|
2016-03-29 15:53:41 -04:00
|
|
|
let mut logo = res.open("steven", "logo/logo.txt").unwrap();
|
|
|
|
let mut logo_str = String::new();
|
|
|
|
logo.read_to_string(&mut logo_str).unwrap();
|
|
|
|
logo_str
|
|
|
|
};
|
2015-10-07 14:36:59 -04:00
|
|
|
|
2016-04-24 07:22:04 -04:00
|
|
|
let shadow_batch = ui::BatchBuilder::new()
|
|
|
|
.position(0.0, 8.0)
|
|
|
|
.size(100.0, 100.0)
|
|
|
|
.alignment(ui::VAttach::Top, ui::HAttach::Center)
|
|
|
|
.create(ui_container);
|
|
|
|
let layer0 = ui::BatchBuilder::new()
|
|
|
|
.position(0.0, 8.0)
|
|
|
|
.size(100.0, 100.0)
|
|
|
|
.draw_index(1)
|
|
|
|
.alignment(ui::VAttach::Top, ui::HAttach::Center)
|
|
|
|
.create(ui_container);
|
2015-10-07 14:36:59 -04:00
|
|
|
|
|
|
|
let mut row = 0;
|
|
|
|
for line in logo_str.lines() {
|
|
|
|
if line.is_empty() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (i, c) in line.chars().enumerate() {
|
|
|
|
if c == ' ' {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let x = i * 4;
|
|
|
|
let y = row * 8;
|
|
|
|
let (r, g, b) = if c == ':' {
|
|
|
|
(255, 255, 255)
|
|
|
|
} else {
|
|
|
|
(170, 170, 170)
|
|
|
|
};
|
2016-04-24 07:22:04 -04:00
|
|
|
ui::ImageBuilder::new()
|
|
|
|
.texture("steven:solid")
|
|
|
|
.position((x + 2) as f64, (y + 4) as f64)
|
|
|
|
.size(4.0, 8.0)
|
|
|
|
.colour((0, 0, 0, 100))
|
|
|
|
.attach(&mut *shadow_batch.borrow_mut());
|
|
|
|
|
|
|
|
|
|
|
|
ui::ImageBuilder::new()
|
|
|
|
.texture("minecraft:blocks/planks_oak")
|
|
|
|
.position(x as f64, y as f64)
|
|
|
|
.size(4.0, 8.0)
|
|
|
|
.texture_coords((
|
|
|
|
(x % 16) as f64 / 16.0, (y % 16) as f64 / 16.0,
|
|
|
|
4.0 / 16.0, 8.0 / 16.0
|
|
|
|
))
|
|
|
|
.colour((r, g, b, 255))
|
|
|
|
.attach(&mut *layer0.borrow_mut());
|
2015-10-07 14:36:59 -04:00
|
|
|
|
|
|
|
let width = (x + 4) as f64;
|
2016-04-24 07:22:04 -04:00
|
|
|
if shadow_batch.borrow().width < width {
|
|
|
|
shadow_batch.borrow_mut().width = width;
|
|
|
|
layer0.borrow_mut().width = width;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
row += 1;
|
|
|
|
}
|
2016-04-24 07:22:04 -04:00
|
|
|
|
|
|
|
shadow_batch.borrow_mut().height = row as f64 * 8.0;
|
|
|
|
layer0.borrow_mut().height = row as f64 * 8.0;
|
|
|
|
|
|
|
|
let mut text_strings = vec![];
|
2015-10-07 14:36:59 -04:00
|
|
|
{
|
2016-04-24 07:22:04 -04:00
|
|
|
let res = resources.read().unwrap();
|
2015-10-07 14:36:59 -04:00
|
|
|
let mut splashes = res.open_all("minecraft", "texts/splashes.txt");
|
|
|
|
for file in &mut splashes {
|
|
|
|
let mut texts = String::new();
|
|
|
|
file.read_to_string(&mut texts).unwrap();
|
|
|
|
for line in texts.lines() {
|
2016-04-24 07:22:04 -04:00
|
|
|
text_strings.push(line.to_owned().replace("\r", ""));
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut r: rand::XorShiftRng = rand::SeedableRng::from_seed([45, 64, 32, 12]);
|
2016-04-24 07:22:04 -04:00
|
|
|
r.shuffle(&mut text_strings[..]);
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
|
2016-04-24 07:22:04 -04:00
|
|
|
let txt = ui::TextBuilder::new()
|
|
|
|
.text("")
|
|
|
|
.position(0.0, -8.0)
|
|
|
|
.colour((255, 255, 0, 255))
|
|
|
|
.rotation(-consts::PI / 8.0)
|
|
|
|
.alignment(ui::VAttach::Bottom, ui::HAttach::Right)
|
|
|
|
.draw_index(1)
|
|
|
|
.create(&mut *layer0.borrow_mut());
|
|
|
|
|
|
|
|
let width = txt.borrow().width;
|
|
|
|
let mut text_base_scale = 300.0 / width;
|
|
|
|
if text_base_scale > 1.0 {
|
|
|
|
text_base_scale = 1.0;
|
|
|
|
}
|
|
|
|
txt.borrow_mut().x = (-width / 2.0) * text_base_scale;
|
|
|
|
let text_orig_x = txt.borrow().x;
|
|
|
|
|
|
|
|
Logo {
|
|
|
|
_shadow: shadow_batch,
|
|
|
|
_layer0: layer0,
|
|
|
|
text: txt,
|
|
|
|
text_base_scale: text_base_scale,
|
|
|
|
text_orig_x: text_orig_x,
|
|
|
|
text_index: -1,
|
|
|
|
text_strings: text_strings,
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-24 07:22:04 -04:00
|
|
|
pub fn tick(&mut self, renderer: &mut render::Renderer) {
|
2018-09-29 23:01:13 -04:00
|
|
|
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
2015-09-21 16:11:30 -04:00
|
|
|
|
2016-03-20 16:17:21 -04:00
|
|
|
// Splash text
|
2018-09-29 23:01:13 -04:00
|
|
|
let text_index = (now.as_secs() / 15) as isize % self.text_strings.len() as isize;
|
2016-04-24 07:22:04 -04:00
|
|
|
let mut text = self.text.borrow_mut();
|
2015-10-07 14:36:59 -04:00
|
|
|
if self.text_index != text_index {
|
|
|
|
self.text_index = text_index;
|
2016-04-24 07:22:04 -04:00
|
|
|
text.text = self.text_strings[text_index as usize].clone();
|
|
|
|
let width = (renderer.ui.size_of_string(&text.text) + 2.0) * text.scale_x;
|
2015-10-07 14:36:59 -04:00
|
|
|
self.text_base_scale = 300.0 / width;
|
|
|
|
if self.text_base_scale > 1.0 {
|
|
|
|
self.text_base_scale = 1.0;
|
|
|
|
}
|
2016-04-24 07:22:04 -04:00
|
|
|
text.x =(-width / 2.0) * self.text_base_scale;
|
|
|
|
self.text_orig_x = text.x;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
|
2018-09-29 23:01:13 -04:00
|
|
|
let timer = now.subsec_nanos() as f64 / 1000000000.0;
|
2015-10-07 14:36:59 -04:00
|
|
|
let mut offset = timer / 0.5;
|
|
|
|
if offset > 1.0 {
|
|
|
|
offset = 2.0 - offset;
|
|
|
|
}
|
|
|
|
offset = ((offset * consts::PI).cos() + 1.0) / 2.0;
|
2016-04-24 07:22:04 -04:00
|
|
|
text.scale_x = (0.7 + (offset / 3.0)) * self.text_base_scale;
|
|
|
|
text.scale_y = (0.7 + (offset / 3.0)) * self.text_base_scale;
|
|
|
|
let scale = text.scale_x;
|
|
|
|
text.x =self.text_orig_x * scale * self.text_base_scale;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
|
|
|
}
|