Skip to content

Commit

Permalink
Started Rusterix integration
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Jan 5, 2025
1 parent e83a3cf commit 2fe5fb4
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 131 deletions.
192 changes: 121 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

270 changes: 232 additions & 38 deletions creator/src/mapeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,44 +219,7 @@ impl MapEditor {
match event {
TheEvent::Custom(id, value) => {
if id.name == "Map Selection Changed" {
// We handle only the tilepicker
if server_ctx.curr_map_tool_helper == MapToolHelper::TilePicker {
let mut floor_icon_id: Option<Uuid> = None;
//let mut wall_icon_id: Option<Uuid> = None;
//let mut ceiling_icon_id: Option<Uuid> = None;

//if server_ctx.curr_map_tool_type == MapToolType::Sector {
if let Some(map) = project.get_map_mut(server_ctx) {
// if let Some(rc) =
// server_ctx.get_texture_for_mode(server_ctx.curr_texture_mode, map)
// {
// }

if map.selected_sectors.len() == 1 {
if let Some(sector) = map.find_sector(map.selected_sectors[0]) {
if let Some(tile_id) = sector.floor_texture {
floor_icon_id = Some(tile_id);
}
}
}
}
//}

if let Some(icon_view) = ui.get_icon_view("Ground Icon") {
if let Some(floor_icon_id) = floor_icon_id {
if let Some(tile) =
TILEDRAWER.lock().unwrap().tiles.get(&floor_icon_id)
{
icon_view.set_rgba_tile(tile.clone());
}
} else {
let buffer = TheRGBABuffer::new(TheDim::sized(48, 48));
if let Some(icon_view) = ui.get_icon_view("Ground Icon") {
icon_view.set_rgba_tile(TheRGBATile::buffer(buffer));
}
}
}
}
self.apply_map_settings(ui, ctx, project, server, server_ctx);
} else if id.name == "Cursor Pos Changed" {
if let Some(text) = ui.get_text("Cursor Position") {
if let Some(v) = value.to_vec2f() {
Expand Down Expand Up @@ -624,6 +587,89 @@ impl MapEditor {
server.update_region(region);
}
}
} else if id.name == "linedefWallHeight" {
if let Some(value) = value.to_f32() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
for linedef_id in &region.map.selected_linedefs.clone() {
let prev = region.map.clone();
if let Some(linedef) = region.map.find_linedef_mut(*linedef_id) {
if linedef.wall_height != value {
linedef.wall_height = value;
let undo_atom = RegionUndoAtom::MapEdit(
Box::new(prev),
Box::new(region.map.clone()),
);
UNDOMANAGER.lock().unwrap().add_region_undo(
&server_ctx.curr_region,
undo_atom,
ctx,
);
}
}
}
}
}
} else if id.name == "linedefName" {
if let Some(value) = value.to_string() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
for linedef_id in &region.map.selected_linedefs.clone() {
let prev = region.map.clone();
if let Some(linedef) = region.map.find_linedef_mut(*linedef_id) {
linedef.name = value.to_string();
let undo_atom = RegionUndoAtom::MapEdit(
Box::new(prev),
Box::new(region.map.clone()),
);
UNDOMANAGER.lock().unwrap().add_region_undo(
&server_ctx.curr_region,
undo_atom,
ctx,
);
}
}
}
}
} else if id.name == "sectorWallHeight" {
if let Some(value) = value.to_f32() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
let mut linedef_ids = Vec::new();
for sector_id in &region.map.selected_sectors {
if let Some(sector) = region.map.find_sector(*sector_id) {
linedef_ids.extend(&sector.linedefs);
}
}

for linedef_id in linedef_ids {
if let Some(linedef) = region.map.find_linedef_mut(linedef_id) {
linedef.wall_height = value;
}
}
}
}
redraw = true;
} else if id.name == "sectorName" {
if let Some(value) = value.to_string() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
for sector_id in &region.map.selected_sectors.clone() {
let prev = region.map.clone();
if let Some(sector) = region.map.find_sector_mut(*sector_id) {
if sector.name != value.clone() {
sector.name = value.clone();
let undo_atom = RegionUndoAtom::MapEdit(
Box::new(prev),
Box::new(region.map.clone()),
);
UNDOMANAGER.lock().unwrap().add_region_undo(
&server_ctx.curr_region,
undo_atom,
ctx,
);
}
}
}
}
}
redraw = true;
}
}
TheEvent::StateChanged(id, _state) => {
Expand Down Expand Up @@ -914,6 +960,154 @@ impl MapEditor {
redraw
}

/// Applies the icons for the tilepicker and sets the node settings for the map selection.
fn apply_map_settings(
&mut self,
ui: &mut TheUI,
ctx: &mut TheContext,
project: &mut Project,
_server: &mut Server,
server_ctx: &mut ServerContext,
) {
// Apply Tile Picker based Icons
if server_ctx.curr_map_tool_helper == MapToolHelper::TilePicker {
let mut floor_icon_id: Option<Uuid> = None;
//let mut wall_icon_id: Option<Uuid> = None;
//let mut ceiling_icon_id: Option<Uuid> = None;

//if server_ctx.curr_map_tool_type == MapToolType::Sector {
if let Some(map) = project.get_map(server_ctx) {
// if let Some(rc) =
// server_ctx.get_texture_for_mode(server_ctx.curr_texture_mode, map)
// {
// }

if map.selected_sectors.len() == 1 {
if let Some(sector) = map.find_sector(map.selected_sectors[0]) {
if let Some(tile_id) = sector.floor_texture {
floor_icon_id = Some(tile_id);
}
}
}
}
//}

if let Some(icon_view) = ui.get_icon_view("Ground Icon") {
if let Some(floor_icon_id) = floor_icon_id {
if let Some(tile) = TILEDRAWER.lock().unwrap().tiles.get(&floor_icon_id) {
icon_view.set_rgba_tile(tile.clone());
}
} else {
let buffer = TheRGBABuffer::new(TheDim::sized(48, 48));
if let Some(icon_view) = ui.get_icon_view("Ground Icon") {
icon_view.set_rgba_tile(TheRGBATile::buffer(buffer));
}
}
}
}

// Create Node Settings if necessary
if let Some(layout) = ui.get_text_layout("Node Settings") {
layout.clear();
}

if let Some(map) = project.get_map(server_ctx) {
if server_ctx.curr_map_tool_type == MapToolType::Linedef
&& map.selected_linedefs.len() == 1
{
self.create_linedef_settings(map, map.selected_linedefs[0], ui, ctx);
} else if server_ctx.curr_map_tool_type == MapToolType::Sector
&& map.selected_sectors.len() == 1
{
self.create_sector_settings(map, map.selected_sectors[0], ui, ctx);
}
}
}

fn create_linedef_settings(
&self,
map: &Map,
linedef_id: u32,
ui: &mut TheUI,
ctx: &mut TheContext,
) {
let mut nodeui = TheNodeUI::default();

if let Some(linedef) = map.find_linedef(linedef_id) {
let item = TheNodeUIItem::Text(
"linedefName".into(),
"Name".into(),
"Set the name of the wall".into(),
linedef.name.clone(),
None,
false,
);
nodeui.add_item(item);
let item = TheNodeUIItem::FloatEditSlider(
"linedefWallHeight".into(),
"Wall Height".into(),
"Set the height for the wall.".into(),
linedef.wall_height,
0.0..=4.0,
false,
);
nodeui.add_item(item);
}

if let Some(layout) = ui.get_text_layout("Node Settings") {
nodeui.apply_to_text_layout(layout);
// layout.relayout(ctx);
ctx.ui.relayout = true;

ctx.ui.send(TheEvent::Custom(
TheId::named("Show Node Settings"),
TheValue::Text("Linedef Settings".to_string()),
));
}
}

fn create_sector_settings(
&self,
map: &Map,
sector_id: u32,
ui: &mut TheUI,
ctx: &mut TheContext,
) {
let mut nodeui = TheNodeUI::default();

if let Some(sector) = map.find_sector(sector_id) {
let item = TheNodeUIItem::Text(
"sectorName".into(),
"Name".into(),
"Set the name of the sector".into(),
sector.name.clone(),
None,
false,
);
nodeui.add_item(item);
let item = TheNodeUIItem::FloatEditSlider(
"sectorWallHeight".into(),
"Wall Height".into(),
"Set the height for all walls of the sector.".into(),
2.0,
0.0..=4.0,
false,
);
nodeui.add_item(item);
}

if let Some(layout) = ui.get_text_layout("Node Settings") {
nodeui.apply_to_text_layout(layout);
// layout.relayout(ctx);
ctx.ui.relayout = true;

ctx.ui.send(TheEvent::Custom(
TheId::named("Show Node Settings"),
TheValue::Text("Sector Settings".to_string()),
));
}
}

/*
fn set_icon_previews(
&mut self,
Expand Down
11 changes: 6 additions & 5 deletions creator/src/tools/linedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Tool for LinedefTool {
ui: &mut TheUI,
ctx: &mut TheContext,
project: &mut Project,
server: &mut Server,
server: &mut shared::server::Server,
_client: &mut Client,
server_ctx: &mut ServerContext,
) -> bool {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl Tool for LinedefTool {
ui: &mut TheUI,
ctx: &mut TheContext,
map: &mut Map,
_server: &mut Server,
_server: &mut shared::server::Server,
_client: &mut Client,
server_ctx: &mut ServerContext,
) -> Option<RegionUndoAtom> {
Expand Down Expand Up @@ -554,7 +554,7 @@ impl Tool for LinedefTool {
ui: &mut TheUI,
ctx: &mut TheContext,
project: &mut Project,
_server: &mut Server,
_server: &mut shared::server::Server,
_client: &mut Client,
server_ctx: &mut ServerContext,
) -> bool {
Expand All @@ -574,8 +574,9 @@ impl Tool for LinedefTool {
if let Some(code) = value.to_string() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
for linedef_id in &region.map.selected_linedefs.clone() {
/*
let mut mapscript = MapScript::new();
let result = mapscript.transform(
let result = mapscript.compile(
code.clone(),
Some(region.map.clone()),
Some(*linedef_id),
Expand All @@ -591,7 +592,7 @@ impl Tool for LinedefTool {
));
}
}
}
}*/
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion creator/src/tools/sector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ impl Tool for SectorTool {
if let Some(code) = value.to_string() {
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
for sector_id in &region.map.selected_sectors.clone() {
/*
let mut mapscript = rusterix::MapScript::new();
let result = mapscript.transform(
code.clone(),
Expand All @@ -457,7 +458,7 @@ impl Tool for SectorTool {
));
}
}
}
}*/
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion creator/src/undo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum UndoManagerContext {
Palette,
}

#[derive(PartialEq, Clone, Debug)]
#[derive(Clone, Debug)]
pub struct UndoManager {
pub context: UndoManagerContext,

Expand Down
Loading

0 comments on commit 2fe5fb4

Please sign in to comment.