Maraiah/source/tycho/editor.rs

109 lines
2.3 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
//! state and human interactions with it, but is otherwise not permitted to
//! directly edit it.
use maraiah::{durandal::image::*,
marathon::map,
rozinante::{color::*, draw::*}};
impl MapEditor
2019-03-24 17:04:49 -07:00
{
/// Creates a closed map editor.
#[inline]
pub const fn new_closed() -> Self
{
MapEditor::Closed
}
2019-03-24 17:04:49 -07:00
/// Creates a new empty map.
#[inline]
pub fn new_opened() -> Self
2019-03-24 17:04:49 -07:00
{
MapEditor::Opened(MapEditorState::default())
2019-03-24 17:04:49 -07:00
}
/// Draws the screen for this editor state.
pub fn draw<D, I>(&self, d: &D, im: &I)
2019-03-24 17:04:49 -07:00
where D: DrawArea<NativeImage = I>,
I: CacheImage
{
match self {
MapEditor::Closed => {
d.clear(Color16::new(0, 0, 0));
2019-03-24 17:04:49 -07:00
d.image((d.w() / 2 - im.w() / 2, d.h() / 2 - im.h() / 2), im);
2019-03-24 17:04:49 -07:00
let text = "Map Required To Proceed";
d.rect(Rect{x: 0, y: 0, w: d.w(), h: 18}, CR_DARK_RED);
d.text((4, 14), text, CR_RED);
2019-03-24 17:04:49 -07:00
let text = "CAS.qterm//CyberAcme Systems Inc.";
d.rect(Rect{x: 0, y: d.h() - 18, w: d.w(), h: 18}, CR_DARK_RED);
d.text((4, d.h() - 4), text, CR_RED);
}
MapEditor::Opened(_st) => {
d.clear(Color16::new(0, 0, 0));
}
}
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 02:32:25 -07:00
impl Default for Tool
2019-03-24 17:04:49 -07:00
{
2019-03-27 02:32:25 -07:00
fn default() -> Tool {Tool::Points}
2019-03-24 17:04:49 -07:00
}
2019-03-27 02:32:25 -07:00
/// Copyable map state.
#[derive(Clone, Default)]
pub struct MapEditorStateBlock
2019-03-24 17:04:49 -07:00
{
info: map::Minf,
}
/// The state of an opened map editor.
2019-03-27 02:32:25 -07:00
#[derive(Default)]
pub struct MapEditorState
{
edit_stack: Vec<MapEditorStateBlock>,
tool: Tool,
}
/// An entire map editor, which may be opened or closed.
pub enum MapEditor
{
Closed,
Opened(MapEditorState),
}
2019-03-27 02:32:25 -07:00
/// A tool in the map editor.
pub enum Tool
{
Points,
Lines,
Polygons,
}
2019-03-24 17:04:49 -07:00
// EOF