@@ -3,6 +3,7 @@ local gui_notes = reqscript('gui/notes')
33local utils = require (' utils' )
44local guidm = require (' gui.dwarfmode' )
55local overlay = require (' plugins.overlay' )
6+ local notes_textures = reqscript (' notes' ).textures
67
78config = {
89 target = ' gui/notes' ,
@@ -43,6 +44,7 @@ local function arrange_gui_notes(options)
4344 gui_notes .main ()
4445
4546 local gui_notes = gui_notes .view
47+ gui_notes .enable_selector_blink = false
4648
4749 gui_notes :updateLayout ()
4850 gui_notes :onRender ()
@@ -238,7 +240,6 @@ function test.edit_note()
238240 note_manager .subviews .name :setText (' updated green note 2' )
239241 note_manager .subviews .comment :setText (' updated comment 2' )
240242 local screen = dfhack .gui .getCurViewscreen (true )
241- printall (screen .widgets )
242243 gui .simulateInput (dfhack .gui .getCurViewscreen (true ), ' CUSTOM_CTRL_ENTER' )
243244
244245 local note_list = gui_notes .subviews .note_list :getChoices ()
@@ -281,3 +282,68 @@ function test.delete_note()
281282
282283 cleanup (gui_notes )
283284end
285+
286+ function test .create_new_note ()
287+ local notes = {
288+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
289+ }
290+
291+ local gui_notes , gui_notes_window = arrange_gui_notes ({ notes = notes })
292+
293+ local note_list = gui_notes .subviews .note_list :getChoices ()
294+ expect .eq (# note_list , 1 )
295+
296+ gui .simulateInput (dfhack .gui .getCurViewscreen (true ), ' CUSTOM_CTRL_N' )
297+
298+ local viewport = guidm .Viewport .get ()
299+
300+ local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
301+ local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
302+
303+ local pos = {x = half_x , y = half_y , z = viewport .z }
304+ local screen_pos = viewport :tileToScreen (pos )
305+ df .global .cursor = pos
306+
307+ -- should not be a test function to map screen tile to mouse pos?
308+ df .global .gps .precise_mouse_x = screen_pos .x * df .global .gps .viewport_zoom_factor / 4
309+ df .global .gps .precise_mouse_y = screen_pos .y * df .global .gps .viewport_zoom_factor / 4
310+
311+ df .global .gps .mouse_x = screen_pos .x
312+ df .global .gps .mouse_y = screen_pos .y
313+
314+ gui_notes :render (gui .Painter .new ())
315+
316+ local pen = dfhack .screen .readTile (screen_pos .x , screen_pos .y , true )
317+
318+ if dfhack .screen .inGraphicsMode () then
319+ local pin_textpos = dfhack .textures .getTexposByHandle (
320+ notes_textures .green_pin [1 ]
321+ )
322+ expect .eq (pen and pen .tile , pin_textpos )
323+ else
324+ expect .eq (pen and pen .ch , string.byte (' X' ))
325+ end
326+
327+ gui .simulateInput (dfhack .gui .getCurViewscreen (true ), ' _MOUSE_L' )
328+
329+ local note_manager = gui_notes_window .note_manager
330+
331+ expect .ne (note_manager , nil )
332+ expect .eq (note_manager .visible , true )
333+
334+ note_manager .subviews .name :setText (' note 2' )
335+ note_manager .subviews .comment :setText (' new note' )
336+
337+ gui .simulateInput (dfhack .gui .getCurViewscreen (true ), ' CUSTOM_CTRL_ENTER' )
338+
339+ local note_list = gui_notes .subviews .note_list :getChoices ()
340+ expect .eq (# note_list , 2 )
341+
342+ local gui_note = note_list [2 ]
343+ expect .eq (gui_note .text , ' note 2' )
344+ expect .eq (gui_note .point .comment , ' new note' )
345+ expect .table_eq (gui_note .point .pos , pos )
346+
347+ cleanup (gui_notes )
348+ end
349+
0 commit comments