Skip to content

Commit

Permalink
Improve new/edit note modal design
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-obrebski committed Sep 4, 2024
1 parent 7a7c6eb commit 46bbd78
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local waypoints = df.global.plotinfo.waypoints
local map_points = df.global.plotinfo.waypoints.points

function NotesOverlay:init()
self.notes = {}
self.visible_notes = {}
self.note_manager = nil
self.last_click_pos = {}
self:reloadVisibleNotes()
Expand All @@ -40,6 +40,9 @@ function NotesOverlay:onInput(keys)
local top_most_screen = dfhack.gui.getDFViewscreen(true)
if dfhack.gui.matchFocusString('dwarfmode/Default', top_most_screen) then
local pos = dfhack.gui.getMousePos()
if pos == nil then
return false
end

local note = self:clickedNote(pos)
if note ~= nil then
Expand All @@ -59,7 +62,7 @@ function NotesOverlay:clickedNote(click_pos)

local last_note_on_pos = nil
local first_note_on_pos = nil
for _, note in ipairs(self.notes) do
for _, note in ipairs(self.visible_notes) do
if same_xyz(note.point.pos, click_pos) then
if (last_note_on_pos and pos_curr_note
and last_note_on_pos.point.id == pos_curr_note.point.id
Expand Down Expand Up @@ -108,7 +111,7 @@ function NotesOverlay:onRenderFrame(dc)
local texpos = dfhack.textures.getTexposByHandle(green_pin[1])
dc:pen({fg=COLOR_BLACK, bg=COLOR_LIGHTCYAN, tile=texpos})

for _, note in pairs(self.notes) do
for _, note in pairs(self.visible_notes) do
dc
:seek(note.screen_pos.x, note.screen_pos.y)
:char('N')
Expand All @@ -118,7 +121,7 @@ function NotesOverlay:onRenderFrame(dc)
end

function NotesOverlay:reloadVisibleNotes()
self.notes = {}
self.visible_notes = {}

local viewport = guidm.Viewport.get()
self.viewport_pos = {
Expand All @@ -130,7 +133,7 @@ function NotesOverlay:reloadVisibleNotes()
for _, map_point in ipairs(map_points) do
if viewport:isVisible(map_point.pos) then
local screen_pos = viewport:tileToScreen(map_point.pos)
table.insert(self.notes, {
table.insert(self.visible_notes, {
point=map_point,
screen_pos=screen_pos
})
Expand Down Expand Up @@ -182,11 +185,13 @@ function NoteManager:init()
widgets.Panel{
view_id='buttons',
frame={b=0,h=2},
autoarrange_subviews=true,
frame_inset={l=1,r=1},
-- autoarrange_subviews=true,
subviews={
widgets.HotkeyLabel{
view_id='Save',
frame={h=1},
frame={l=0,t=0,h=1},
auto_width=true,
label='Save',
key='CUSTOM_ALT_S',
visible=edit_mode,
Expand All @@ -195,7 +200,8 @@ function NoteManager:init()
},
widgets.HotkeyLabel{
view_id='Create',
frame={h=1},
frame={l=0,t=0,h=1},
auto_width=true,
label='Create',
key='CUSTOM_ALT_S',
visible=not edit_mode,
Expand All @@ -204,7 +210,8 @@ function NoteManager:init()
},
widgets.HotkeyLabel{
view_id='delete',
frame={h=1},
frame={r=0,t=0,h=1},
auto_width=true,
label='Delete',
key='CUSTOM_ALT_D',
visible=edit_mode,
Expand All @@ -220,7 +227,7 @@ end
function NoteManager:createNote()
local cursor_pos = guidm.getCursorPos()
if cursor_pos == nil then
print('Enable keyboard cursor to add a note.')
dfhack.printerr('Enable keyboard cursor to add a note.')
return
end

Expand Down

0 comments on commit 46bbd78

Please sign in to comment.