Skip to content

Commit

Permalink
Tilemap editor grid size and drawing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Jan 21, 2024
1 parent bf2c618 commit 8ac8da6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
35 changes: 14 additions & 21 deletions creator/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,17 @@ impl TheTrait for Editor {
{
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value));
}
} else if id.name == "Region Item" {
}
else if id.name == "Region Item" {
for r in &mut self.project.regions {
if r.id == id.uuid {
if let Some(text) = value.to_string() {
r.name = text;
}
}
}
} else if id.name == "Character Name Edit" {
}
else if id.name == "Character Name Edit" {
if let Some(list_id) = self
.sidebar
.get_selected_in_list_layout(ui, "Character List")
Expand All @@ -579,45 +581,36 @@ impl TheTrait for Editor {
}
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value));
}
} else if id.name == "Character Item" {
}
else if id.name == "Character Item" {
if let Some(character) = self.project.characters.get_mut(&id.uuid) {
if let Some(text) = value.to_string() {
character.name = text;
}
}
} else if id.name == "Item Name Edit" {
}
else if id.name == "Item Name Edit" {
if let Some(list_id) =
self.sidebar.get_selected_in_list_layout(ui, "Item List")
{
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value));
}
} else if id.name == "Item Item" {
}
else if id.name == "Item Item" {
if let Some(item) = self.project.items.get_mut(&id.uuid) {
if let Some(text) = value.to_string() {
item.name = text;
}
}
} else if id.name == "Tilemap Name Edit" {
if let Some(list_id) =
self.sidebar.get_selected_in_list_layout(ui, "Tilemap List")
{
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value));
}
} else if id.name == "Tilemap Item" {
for t in &mut self.project.tilemaps {
if t.id == id.uuid {
if let Some(text) = value.to_string() {
t.name = text;
}
}
}
} else if id.name == "Code Name Edit" {
}
else if id.name == "Code Name Edit" {
if let Some(list_id) =
self.sidebar.get_selected_in_list_layout(ui, "Code List")
{
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value));
}
} else if id.name == "Code Item" {
}
else if id.name == "Code Item" {
if let Some(code) = self.project.codes.get_mut(&id.uuid) {
if let Some(text) = value.to_string() {
code.name = text;
Expand Down
50 changes: 47 additions & 3 deletions creator/src/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,50 @@ impl Sidebar {
}
}
}
} else if id.name == "Tilemap Filter Edit" || id.name == "Tilemap Filter Role" {
}
// Rename the tilemap item
else if id.name == "Tilemap Name Edit" {
if let Some(list_id) =
self.get_selected_in_list_layout(ui, "Tilemap List")
{
ctx.ui.send(TheEvent::SetValue(list_id.uuid, value.clone()));
}
}
// Rename the tilemap in the project, triggered by the above action.
else if id.name == "Tilemap Item" {
for t in &mut project.tilemaps {
if t.id == id.uuid {
if let Some(text) = value.to_string() {
t.name = text;
}
}
}
}
// Change the size of the tilemap grid
else if id.name == "Tilemap Grid Edit" {
if let Some(tilemap_uuid) = &self.curr_tilemap_uuid {
if let Some(tilemap) = project.get_tilemap(*tilemap_uuid) {
if let Some(size) = value.to_i32() {
tilemap.grid_size = size;
self.apply_tilemap(ui, ctx, Some(tilemap));
}
}
}
}
else if id.name == "Tilemap Filter Edit" || id.name == "Tilemap Filter Role" {
if let Some(id) = self.curr_tilemap_uuid {
self.show_filtered_tiles(ui, ctx, project.get_tilemap(id).as_deref())
}
} else if id.name == "Tilemap Editor Zoom" {
}
else if id.name == "Tilemap Editor Zoom" {
if let Some(v) = value.to_f32() {
if let Some(layout) = ui.get_rgba_layout("Tilemap Editor") {
layout.set_zoom(v);
layout.relayout(ctx);
}
}
} else if id.name == "Region Content Filter Edit"
}
else if id.name == "Region Content Filter Edit"
|| id.name == "Region Content Dropdown"
{
self.apply_region(ui, ctx, project.get_region(&server_ctx.curr_region), server);
Expand Down Expand Up @@ -513,7 +545,9 @@ impl Sidebar {
ctx.ui
.send_widget_state_changed(&id, TheWidgetState::Selected);

server_ctx.curr_region = region.id;
project.regions.push(region);
server.set_project(project.clone());
}
} else if id.name == "Region Remove" {
if let Some(list_layout) = ui.get_list_layout("Region List") {
Expand Down Expand Up @@ -1427,6 +1461,16 @@ impl Sidebar {
widget.set_disabled(true);
}
}

if let Some(layout) = ui.get_rgba_layout("Tilemap Editor") {
if let Some(rgba) = layout.rgba_view_mut().as_rgba_view() {
if let Some(tilemap) = tilemap {
//rgba.set_zoom(tilemap.zoom);
rgba.set_grid(Some(tilemap.grid_size));
}
}
}

self.show_filtered_tiles(ui, ctx, tilemap);
}

Expand Down
17 changes: 0 additions & 17 deletions creator/src/tileeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,4 @@ impl TileEditor {
}
}
}

/*
/// Redraws the region (if the current one is the same as the one passed here from Undo).
pub fn redraw_region(&mut self, region: &Region, ui: &mut TheUI, ctx: &mut TheContext) {
if self.curr_region_uuid != region.id {
return;
}
if let Some(rgba_layout) = ui.canvas.get_layout(Some(&"Region Editor".into()), None) {
if let Some(rgba_layout) = rgba_layout.as_rgba_layout() {
if let Some(rgba_view) = rgba_layout.rgba_view_mut().as_rgba_view() {
self.tiledrawer
.draw_region(rgba_view.buffer_mut(), region, &0, ctx);
}
rgba_layout.rgba_view_mut().set_needs_redraw(true);
}
}
}*/
}
13 changes: 7 additions & 6 deletions shared/src/server/region_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ impl RegionInstance {
// }

let sum = (delta + character.move_delta).clamp(0.0, 1.0);
//let d = smoothstep(0.0, 1.0, sum);//.clamp(0.0, 1.0);
let d = if sum < 0.5 {
2.0 * sum * sum
} else {
1.0 - (-2.0 * sum + 2.0).powi(2) / 2.0
};
// let d = smoothstep(0.0, 1.0, sum);//.clamp(0.0, 1.0);
let d = sum;
// let d = if sum < 0.5 {
// 2.0 * sum * sum
// } else {
// 1.0 - (-2.0 * sum + 2.0).powi(2) / 2.0
// };
let x = start.x * (1.0 - d) + end.x * d;
let y = start.y * (1.0 - d) + end.y * d;
character.move_delta = sum;
Expand Down

0 comments on commit 8ac8da6

Please sign in to comment.