Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 46 additions & 38 deletions gui/notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local overlay = require 'plugins.overlay'
local utils = require 'utils'

local note_manager = reqscript('internal/notes/note_manager')
local notes_textures = reqscript('notes').textures

local map_points = df.global.plotinfo.waypoints.points

Expand All @@ -17,13 +18,6 @@ local RESIZE_MIN = {w=65, h=30}
local NOTE_SEARCH_BATCH_SIZE = 25
local OVERLAY_NAME = 'notes.map_notes'

local green_pin = dfhack.textures.loadTileset(
'hack/data/art/note_green_pin_map.png',
32,
32,
true
)

NotesWindow = defclass(NotesWindow, widgets.Window)
NotesWindow.ATTRS {
frame_title='DF Notes',
Expand All @@ -38,46 +32,51 @@ function NotesWindow:init()
self.note_manager = nil
self.curr_search_phrase = nil

self:addviews{
local left_panel_content = {
widgets.Panel{
view_id='note_list_panel',
frame={l=0, w=NOTE_LIST_RESIZE_MIN.w, t=0, b=1},
visible=true,
frame_inset={l=1,t=1,b=1,r=1},
autoarrange_subviews=true,
frame={l=0,h=3},
frame_style=gui.FRAME_INTERIOR,
subviews={
widgets.TextArea{
widgets.EditField{
view_id='search',
frame={l=0,h=3},
frame_style=gui.FRAME_INTERIOR,
one_line_mode=true,
on_text_change=self:callback('loadFilteredNotes'),
on_change=self:callback('loadFilteredNotes'),
on_submit=function()
self.subviews.note_list:submit()
end
},
widgets.List{
view_id='note_list',
frame={l=0,b=2},
frame_inset={t=1},
row_height=1,
on_select=function (ind, note)
self:loadNote(note)
end,
on_submit=function (ind, note)
self:loadNote(note)
dfhack.gui.pauseRecenter(note.point.pos)
end
},
},
}
},
widgets.List{
view_id='note_list',
frame={l=0,b=2},
frame_inset={t=1},
row_height=1,
on_select=function (ind, note)
self:loadNote(note)
end,
on_submit=function (ind, note)
self:loadNote(note)
dfhack.gui.pauseRecenter(note.point.pos)
end
},
}

self:addviews{
widgets.Panel{
view_id='note_list_panel',
frame={l=0, w=NOTE_LIST_RESIZE_MIN.w, t=0, b=1},
visible=true,
frame_inset={l=1,t=1,b=1,r=1},
autoarrange_subviews=true,
subviews=left_panel_content,
},
widgets.HotkeyLabel{
view_id='create',
frame={l=1,b=1,h=1},
auto_width=true,
label='New note',
key='CUSTOM_CTRL_N',
visible=edit_mode,
visible=true,
on_activate=function()
if self.on_note_add then
self:on_note_add()
Expand Down Expand Up @@ -248,6 +247,7 @@ NotesScreen = defclass(NotesScreen, gui.ZScreen)
NotesScreen.ATTRS {
focus_path='gui/notes',
pass_movement_keys=true,
enable_selector_blink = true,
}

function NotesScreen:init()
Expand Down Expand Up @@ -278,7 +278,7 @@ function NotesScreen:onInput(keys)
if (keys.SELECT or keys._MOUSE_L) then
self.adding_note_pos = dfhack.gui.getMousePos()

local manager = note_manager.NoteManager{
local note_manager = note_manager.NoteManager{
note=nil,
on_update=function()
dfhack.run_command_silent('overlay trigger notes.map_notes')
Expand All @@ -289,7 +289,8 @@ function NotesScreen:onInput(keys)
self:stopNoteAdd()
end
}:show()
manager:setNotePos(self.adding_note_pos)
note_manager:setNotePos(self.adding_note_pos)
self.subviews.notes_window.note_manager = note_manager

return true
elseif (keys.LEAVESCREEN or keys._MOUSE_R)then
Expand All @@ -304,7 +305,7 @@ end
function NotesScreen:onRenderFrame(dc, rect)
NotesScreen.super.onRenderFrame(self, dc, rect)

if not dfhack.screen.inGraphicsMode() and not gui.blink_visible(500) then
if self.enable_selector_blink and not gui.blink_visible(500) then
return
end

Expand All @@ -316,7 +317,9 @@ function NotesScreen:onRenderFrame(dc, rect)

local function get_overlay_pen(pos)
if same_xy(curr_pos, pos) then
local texpos = dfhack.textures.getTexposByHandle(green_pin[1])
local texpos = dfhack.textures.getTexposByHandle(
notes_textures.green_pin[1]
)
return dfhack.pen.parse{
ch='X',
fg=COLOR_BLUE,
Expand Down Expand Up @@ -345,10 +348,15 @@ function NotesScreen:onDismiss()
if self.should_disable_overlay then
overlay.overlay_command({'disable', 'notes.map_notes'})
end

if self.subviews.notes_window.note_manager then
self.subviews.notes_window.note_manager:dismiss()
end

view = nil
end

function main(options)
function main()
if not dfhack.isMapLoaded() or not dfhack.world.isFortressMode() then
qerror('notes requires a fortress map to be loaded')
end
Expand Down
9 changes: 4 additions & 5 deletions internal/notes/note_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function NoteManager:init()
frame={t=1,h=3},
frame_style=gui.FRAME_INTERIOR,
init_text=self.note and self.note.point.name or '',
-- init_cursor=self.note and #self.note.point.name + 1 or 1,
one_line_mode=true
},
widgets.HotkeyLabel {
Expand Down Expand Up @@ -97,11 +96,11 @@ function NoteManager:init()
end

function NoteManager:setNotePos(note_pos)
self.notes_pos = note_pos
self.note_pos = note_pos
end

function NoteManager:createNote()
local cursor_pos = self.notes_pos or guidm.getCursorPos()
local cursor_pos = self.note_pos or guidm.getCursorPos()
if cursor_pos == nil then
dfhack.printerr('Enable keyboard cursor to add a note.')
return
Expand Down Expand Up @@ -150,8 +149,8 @@ function NoteManager:saveNote()

self.note.point.name = name
self.note.point.comment = comment
if self.notes_pos then
self.note.pos=self.notes_pos
if self.note_pos then
self.note.pos=self.note_pos
end

if self.on_update then
Expand Down
16 changes: 9 additions & 7 deletions notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ local overlay = require('plugins.overlay')
local guidm = require('gui.dwarfmode')
local note_manager = reqscript('internal/notes/note_manager')

local green_pin = dfhack.textures.loadTileset(
'hack/data/art/note_green_pin_map.png',
32,
32,
true
)
textures = {
green_pin = dfhack.textures.loadTileset(
'hack/data/art/note_green_pin_map.png',
32,
32,
true
)
}

NotesOverlay = defclass(NotesOverlay, overlay.OverlayWidget)
NotesOverlay.ATTRS{
Expand Down Expand Up @@ -113,7 +115,7 @@ function NotesOverlay:onRenderFrame(dc)

dc:map(true)

local texpos = dfhack.textures.getTexposByHandle(green_pin[1])
local texpos = dfhack.textures.getTexposByHandle(textures.green_pin[1])
dc:pen({fg=COLOR_BLACK, bg=COLOR_LIGHTCYAN, tile=texpos})

for _, note in pairs(self.visible_notes) do
Expand Down
2 changes: 0 additions & 2 deletions test/gui/journal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ config = {
mode = 'fortress'
}

local df_major_version = tonumber(dfhack.getCompiledDFVersion():match('%d+'))

local function simulate_input_keys(...)
local keys = {...}
for _,key in ipairs(keys) do
Expand Down
Loading
Loading