summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-08-03 16:37:59 +1000
committerquou <quou@disroot.org>2024-08-03 16:37:59 +1000
commitd5e84753f4201730c6953c3b978fc934f2cacedb (patch)
treecdfbea0f18b51266e354d22e40fc405143a9be7b
parent125be3c1880d9f64580bf9c753dd85c5cbc1cfc4 (diff)
Display the map in the editor
-rw-r--r--editor.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/editor.c b/editor.c
index b59ce32..645f7f7 100644
--- a/editor.c
+++ b/editor.c
@@ -1,9 +1,12 @@
-#include "editor.h"
#include "asset.h"
+#include "editor.h"
#include "gui.h"
#include "map.h"
+#include "plat.h"
#include "render.h"
+#define tile_display_size 32
+
static GUI_Scroll_State map_ss = { 0 };
void draw_map_scrollable(
@@ -12,22 +15,58 @@ void draw_map_scrollable(
const Rect* rect,
const GUI_Scroll_State* ss
) {
- Rect re = { 0, 0, 500, 500 };
- re.x = rect->x - ss->x;
- re.y = rect->y - ss->y;
- (void)g;
- (void)ss;
- ren_texture(r, &re, get_texture(asset_id_floorboards_texture));
+ const Map* m = g->uptr;
+ const Map_Tile* tiles = map_tilesc(m);
+ int x, y;
+ Rect re = { 0 };
+ re.w = tile_display_size;
+ re.h = tile_display_size;
+ for (y = 0; y < m->h; y++) {
+ for (x = 0; x < m->w; x++) {
+ re.x = rect->x + x * tile_display_size - ss->x;
+ re.y = rect->y + y * tile_display_size - ss->y;
+ if (tiles[x + y * m->w])
+ ren_texture(
+ r,
+ &re,
+ get_texture(asset_id_brick_texture)
+ );
+ else
+ ren_rect(
+ r,
+ make_black(),
+ &re
+ );
+ }
+ }
+ x = (g->app->mx - rect->x) / tile_display_size;
+ y = (g->app->my - rect->y) / tile_display_size;
+ if (
+ x >= 0 &&
+ y >= 0 &&
+ x < m->w &&
+ y < m->h
+ ) {
+ re.x = x * tile_display_size + rect->x;
+ re.y = y * tile_display_size + rect->y;
+ ren_rect(
+ r,
+ make_colour(0xffffff, 120),
+ &re
+ );
+ }
}
void edit_map(Editor* e, GUI* g, Map* m) {
Rect b = gui_viewport(g);
Rect t = gui_cut_up(&b, gui_text_height() + 4);
- int mcs[] = { 500, 500 };
+ int mcs[2];
(void)e;
- (void)m;
+ mcs[0] = m->w * tile_display_size;
+ mcs[1] = m->h * tile_display_size;
gui_btn(g, gui_cut_left(&t, gui_text_width("Load", 4) + 4), "Save");
gui_btn(g, gui_cut_left(&t, gui_text_width("Save", 4) + 4), "Load");
+ g->uptr = m;
gui_scrollable(g, b, mcs, &map_ss, draw_map_scrollable);
}