tycho: add model/view test code

master
an 2019-06-13 21:10:33 -04:00
parent dafa691002
commit 68b4939a15
19 changed files with 347 additions and 52 deletions

View File

@ -24,10 +24,13 @@ add_library(
$ENV{OUT_DIR}/bindings.h
cc_headers/mapprops.h
cc_headers/menu.h
cc_headers/project.h
cc_headers/tycho.h
cc_source/main.cc
cc_source/mapprops.cc
cc_source/menu.cc
cc_source/projectmodel.cc
cc_source/projectview.cc
resources/resources.qrc
ui/about.ui
ui/mapprops.ui

View File

@ -1,7 +1,7 @@
[package]
name = "maraiah-tycho"
version = "0.1.0"
authors = ["Alison Watson <marrub@greyserv.net>"]
authors = ["Alison Watson <marrub@greyserv.net>", "Tae Matous"]
description = "Tycho map editor."
edition = "2018"
build = "build.rs"

View File

@ -10,7 +10,7 @@
"type": "Object",
"functions": {
"open": {
"return": "void",
"return": "bool",
"mut": true,
"arguments": [{
"name": "fname",

View File

@ -13,9 +13,15 @@ fn main()
generate_bindings(&config).unwrap();
let dst = cmake::Config::new(".").build();
let mut config = cmake::Config::new(".");
println!("cargo:rustc-link-search=native={}/lib", dst.display());
if cfg!(debug_assertions) {
config.cxxflag("-DTYCHO_DEBUG_PRINT");
}
let destination = config.build();
println!("cargo:rustc-link-search=native={}/lib", destination.display());
println!("cargo:rustc-link-lib=dylib=maraiah-tycho-hermes");
}

View File

@ -2,6 +2,8 @@
#include <QDialog>
class ProjectModel;
namespace Ui
{
class MapProps;
@ -12,10 +14,12 @@ class MapProps : public QDialog
Q_OBJECT
public:
explicit MapProps(QWidget *parent = nullptr);
explicit MapProps(QSharedPointer<ProjectModel> proj,
QWidget *parent = nullptr);
~MapProps();
private:
QSharedPointer<ProjectModel> proj;
QSharedPointer<Ui::MapProps> ui;
};

View File

@ -3,7 +3,8 @@
#include <QMainWindow>
#include <vector>
class Project;
class ProjectView;
class QMdiSubWindow;
namespace Ui
{
@ -23,10 +24,14 @@ public slots:
void mapOpen();
void openAbout();
void openMapProperties();
void updateActions();
private:
ProjectView *activeProject() const;
QMdiSubWindow *activeSubWindow() const;
void addProject(ProjectView *proj);
QSharedPointer<Ui::Menu> ui;
std::vector<QSharedPointer<Project>> projects;
};
// EOF

View File

@ -0,0 +1,41 @@
#pragma once
#include "bindings.h"
#include <QWidget>
namespace Ui
{
class ProjectView;
}
class ProjectModel : public QObject
{
Q_OBJECT
public:
explicit ProjectModel();
~ProjectModel();
bool open(QString fname);
private:
Project data;
};
class ProjectView : public QWidget
{
Q_OBJECT
public:
explicit ProjectView(QWidget *parent = nullptr);
~ProjectView();
QSharedPointer<ProjectModel> model();
private:
QSharedPointer<Ui::ProjectView> ui;
QSharedPointer<ProjectModel> proj;
};
// EOF

View File

@ -12,4 +12,12 @@
#define dbgPrintFunc() dbgPrint("%s", __func__)
constexpr std::uint32_t fourCC(std::uint8_t a,
std::uint8_t b,
std::uint8_t c,
std::uint8_t d)
{
return (a << 24) | (b << 16) | (c << 8) | d;
}
// EOF

View File

@ -4,9 +4,10 @@
#include <QDialogButtonBox>
MapProps::MapProps(QWidget *parent) :
MapProps::MapProps(QSharedPointer<ProjectModel> _proj, QWidget *parent) :
QDialog(parent),
ui(new Ui::MapProps)
ui(new Ui::MapProps),
proj(_proj)
{
ui->setupUi(this);

View File

@ -1,11 +1,12 @@
#include "tycho.h"
#include "mapprops.h"
#include "menu.h"
#include "project.h"
#include "../ui/ui_menu.h"
#include "../ui/ui_about.h"
#include "bindings.h"
#include <QFileDialog>
#include <QMdiSubWindow>
#include <iostream>
Menu::Menu(QWidget *parent) :
@ -23,7 +24,9 @@ Menu::~Menu()
void Menu::mapNew()
{
auto proj = projects.emplace_back(new Project);
QScopedPointer view{new ProjectView};
addProject(view.take());
}
void Menu::mapOpen()
@ -35,8 +38,11 @@ void Menu::mapOpen()
QString(),
tr("Marathon Map files (*.scen *.sceA Map)"));
auto proj = projects.emplace_back(new Project);
proj->open(fname);
QScopedPointer view{new ProjectView};
if(view->model()->open(fname)) {
addProject(view.take());
}
}
void Menu::openAbout()
@ -46,16 +52,44 @@ void Menu::openAbout()
about.setupUi(&dlg);
about.labelVer->setText(tr(TYCHO_VERSION));
about.labelAuthors->setText(tr(TYCHO_AUTHORS));
about.labelAuthors->setText(tr(TYCHO_AUTHORS).replace(':', '\n'));
dlg.exec();
}
void Menu::openMapProperties()
{
MapProps props{this};
auto view = activeProject();
props.exec();
if(view) {
MapProps props{view->model(), view};
props.exec();
}
}
void Menu::updateActions()
{
auto view = activeProject();
bool active = view != nullptr;
ui->actionMapProps->setEnabled(active);
}
ProjectView *Menu::activeProject() const
{
auto win = activeSubWindow();
return win ? qobject_cast<ProjectView *>(win->widget()) : nullptr;
}
QMdiSubWindow *Menu::activeSubWindow() const
{
return ui->mdiArea->activeSubWindow();
}
void Menu::addProject(ProjectView *view)
{
auto win = ui->mdiArea->addSubWindow(view);
win->showMaximized();
}
// EOF

View File

@ -0,0 +1,19 @@
#include "tycho.h"
#include "project.h"
ProjectModel::ProjectModel() :
data()
{
}
ProjectModel::~ProjectModel()
{
dbgPrintFunc();
}
bool ProjectModel::open(QString fname)
{
return data.open(fname);
}
// EOF

View File

@ -0,0 +1,24 @@
#include "tycho.h"
#include "project.h"
#include "../ui/ui_projectview.h"
ProjectView::ProjectView(QWidget *parent) :
QWidget(parent),
ui(new Ui::ProjectView),
proj(new ProjectModel)
{
ui->setupUi(this);
dbgPrintFunc();
}
ProjectView::~ProjectView()
{
dbgPrintFunc();
}
QSharedPointer<ProjectModel> ProjectView::model()
{
return proj;
}
// EOF

View File

@ -1,4 +1,4 @@
use maraiah::durandal::{err::*, ffi};
use maraiah::{err::*, ffi};
mod qimpl;
mod qintr;

View File

@ -1,35 +1,5 @@
use crate::qintr::*;
mod project;
pub struct Project
{
emit: ProjectEmitter,
}
impl Drop for Project
{
fn drop(&mut self)
{
eprintln!("drop Project");
}
}
impl ProjectTrait for Project
{
fn new(emit: ProjectEmitter) -> Project
{
eprintln!("new Project");
Project{emit}
}
fn emit(&mut self) -> &mut ProjectEmitter
{
&mut self.emit
}
fn open(&mut self, fname: String)
{
println!("opening project: {}", fname);
}
}
pub use self::project::*;
// EOF

View File

@ -0,0 +1,59 @@
use crate::qintr::*;
use std::{cell::RefCell, fs};
use memmap::Mmap;
use maraiah::map;
pub struct Project
{
emit: ProjectEmitter,
wad: RefCell<Option<map::Wad>>,
}
impl Drop for Project
{
fn drop(&mut self)
{
if cfg!(debug_assertions) {
eprintln!("drop Project");
}
}
}
impl ProjectTrait for Project
{
fn new(emit: ProjectEmitter) -> Project
{
if cfg!(debug_assertions) {
eprintln!("new Project");
}
Project{emit, wad: RefCell::new(None)}
}
fn emit(&mut self) -> &mut ProjectEmitter
{
&mut self.emit
}
fn open(&mut self, path: String) -> bool
{
if cfg!(debug_assertions) {
eprintln!("opening project: {}", &path);
}
let fp = fs::File::open(path);
let fp = if let Ok(fp) = fp {fp} else {return false;};
let mm = unsafe {Mmap::map(&fp)};
let mm = if let Ok(mm) = mm {mm} else {return false;};
if let Ok(wad) = map::read(&mm) {
self.wad.replace(Some(wad));
return true;
}
false
}
}
// EOF

View File

@ -1,7 +1,7 @@
#![allow(unused_imports)]
#![allow(dead_code)]
use maraiah::durandal::ffi as libc;
use maraiah::ffi as libc;
include!(concat!(env!("OUT_DIR"), "/src/qintr.rs"));

View File

@ -12,8 +12,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>468</width>
<height>598</height>
<width>466</width>
<height>594</height>
</rect>
</property>
<property name="windowTitle">
@ -71,6 +71,31 @@ Because of this, the texture sets are named after the liquids primarily.</string
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Water</string>
</property>
</item>
<item>
<property name="text">
<string>Lava</string>
</property>
</item>
<item>
<property name="text">
<string>Sewage</string>
</property>
</item>
<item>
<property name="text">
<string>Jjaro</string>
</property>
</item>
<item>
<property name="text">
<string>Pfhor</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
@ -91,6 +116,26 @@ Because of this, the texture sets are named after the liquids primarily.</string
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Lh'owon Day</string>
</property>
</item>
<item>
<property name="text">
<string>Lh'owon Night</string>
</property>
</item>
<item>
<property name="text">
<string>Moon</string>
</property>
</item>
<item>
<property name="text">
<string>Space</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0">
@ -451,5 +496,21 @@ Some of them also set the &quot;failure&quot; terminal state when the objective
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_24</sender>
<signal>toggled(bool)</signal>
<receiver>comboBox_2</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>361</x>
<y>465</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>131</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -105,6 +105,9 @@
</property>
</action>
<action name="actionMapProps">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-properties">
<normaloff>.</normaloff>.</iconset>
@ -223,11 +226,28 @@
</hint>
</hints>
</connection>
<connection>
<sender>mdiArea</sender>
<signal>subWindowActivated(QMdiSubWindow*)</signal>
<receiver>Menu</receiver>
<slot>updateActions()</slot>
<hints>
<hint type="sourcelabel">
<x>399</x>
<y>301</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>openMapProperties()</slot>
<slot>mapNew()</slot>
<slot>mapOpen()</slot>
<slot>openAbout()</slot>
<slot>updateActions()</slot>
</slots>
</ui>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectView</class>
<widget class="QWidget" name="ProjectView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Project</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>gay</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>