Maraiah/source/rozinante/editor.rs

91 lines
2.1 KiB
Rust
Raw Normal View History

2019-03-24 17:04:49 -07:00
//! Main map editor module.
//!
//! The entry point is responsible for maintaining the lifetime of the editor
2019-03-27 14:02:15 -07:00
//! and human interactions with it, but is otherwise not permitted to directly
//! edit it.
2019-03-24 17:04:49 -07:00
2019-03-27 11:07:33 -07:00
pub mod block;
pub mod state;
use crate::durandal::image::*;
use super::{color, draw::*};
2019-03-24 17:04:49 -07:00
impl MapEditor
2019-03-24 17:04:49 -07:00
{
/// Opens the editor with a new empty map.
#[inline]
pub fn open_new(&mut self)
2019-03-24 17:04:49 -07:00
{
2019-03-27 14:02:15 -07:00
*self = MapEditor::Opened(state::OpenMap::default());
2019-03-24 17:04:49 -07:00
}
/// Draws the screen for this editor state.
2019-03-27 04:56:30 -07:00
pub fn draw<D, I>(&self, d: &mut D, im: &I)
2019-03-24 17:04:49 -07:00
where D: DrawArea<NativeImage = I>,
I: CacheImage
{
2019-03-27 04:56:30 -07:00
let dw = d.w();
let dh = d.h();
let iw = im.w();
let ih = im.h();
match self {
MapEditor::Closed => {
let tx_top = "Map Required To Proceed";
let tx_bot = "CAS.qterm//CyberAcme Systems Inc.";
d.clear(Color16::new(0, 0, 0));
2019-03-24 17:04:49 -07:00
d.image((dw / 2 - iw / 2, dh / 2 - ih / 2), im);
2019-03-24 17:04:49 -07:00
2019-03-27 11:07:33 -07:00
d.rect(Rect{x: 0, y: 0, w: dw, h: 18}, color::DARK_RED);
d.text((4, 14), tx_top, color::RED);
2019-03-24 17:04:49 -07:00
2019-03-27 11:07:33 -07:00
d.rect(Rect{x: 0, y: dh - 18, w: dw, h: 18}, color::DARK_RED);
d.text((4, dh - 4), tx_bot, color::RED);
}
2019-03-27 04:56:30 -07:00
MapEditor::Opened(st) => {
2019-03-27 14:02:15 -07:00
let text = &format!("tool: {:?}", st.tool);
d.clear(Color16::new(0, 0, 0));
2019-03-27 14:02:15 -07:00
d.text((dw/2, dh/2), text, color::RED);
}
}
2019-03-24 17:04:49 -07:00
}
2019-03-27 02:32:25 -07:00
/// Returns `true` if `self` is closed.
#[inline]
pub fn is_closed(&self) -> bool
2019-03-27 02:32:25 -07:00
{
match self {
MapEditor::Closed => true,
MapEditor::Opened(_) => false,
}
}
/// Returns `true` if `self` is opened.
#[inline]
pub fn is_opened(&self) -> bool
{
match self {
MapEditor::Closed => false,
MapEditor::Opened(_) => true,
}
2019-03-27 02:32:25 -07:00
}
2019-03-24 17:04:49 -07:00
}
2019-03-27 11:07:33 -07:00
impl Default for MapEditor
2019-03-24 17:04:49 -07:00
{
2019-03-27 11:07:33 -07:00
#[inline]
2019-03-27 14:02:15 -07:00
fn default() -> Self {MapEditor::Closed}
2019-03-27 02:32:25 -07:00
}
/// An entire map editor, which may be opened or closed.
pub enum MapEditor
{
Closed,
2019-03-27 14:02:15 -07:00
Opened(state::OpenMap),
2019-03-27 02:32:25 -07:00
}
2019-03-24 17:04:49 -07:00
// EOF