Skip to content

Commit

Permalink
Merge pull request #1287 from wiktor-obrebski/feat/notes
Browse files Browse the repository at this point in the history
`notes` script
  • Loading branch information
myk002 authored Sep 6, 2024
2 parents f99a7fd + cc223f1 commit 22675fc
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Template for new versions:
- `embark-anyone`: allows you to embark as any civilization, including dead and non-dwarven ones
- `idle-crafting`: allow dwarves to independently satisfy their need to craft objects
- `gui/family-affairs`: (reinstated) inspect or meddle with pregnancies, marriages, or lover relationships
- `notes`: Manage map-specific notes

## New Features
- `caravan`: DFHack dialogs for trade screens (both ``Bring goods to depot`` and the ``Trade`` barter screen) can now filter by item origins (foreign vs. fort-made) and can filter bins by whether they have a mix of ethically acceptable and unacceptable items in them
Expand Down
42 changes: 42 additions & 0 deletions docs/notes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
notes
=====

.. dfhack-tool::
:summary: Manage map-specific notes.
:tags: fort interface map

The `notes` tool enables players to annotate specific tiles
on the Dwarf Fortress game map with customizable notes.

Each note is displayed as a green pin on the map and includes a one-line title and a detailed comment.

It can be used to e.g.:
- marking plans for future constructions
- explaining mechanisms or traps
- noting historical events

Usage
-----

::

notes add

Add new note in the current position of the keyboard cursor.

Creating a Note
---------------
1. Use the keyboard cursor to select the desired map tile where you want to place a note.
2. Execute ``notes add`` via the DFHack console.
3. In the pop-up dialog, fill in the note's title and detailed comment.
4. Press :kbd:`Alt` + :kbd:`S` to create the note.

Editing or Deleting a Note
--------------------------
- Click on the green pin representing the note directly on the map.
- A dialog will appear, offering options to edit the title or comment, or to delete the note entirely.

Managing Notes Visibility
-------------------------
- Access the `gui/control-panel` / ``UI Overlays`` tab.
- Toggle the ``notes.map-notes`` overlay to show or hide the notes on the map.
1 change: 1 addition & 0 deletions gui/journal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function JournalWindow:init()
on_text_change=self:callback('onTextChange'),
on_cursor_change=self:callback('onCursorChange'),
},
widgets.HelpButton{command="gui/journal", frame={r=0,t=1}},
widgets.Panel{
frame={l=0,r=0,b=1,h=1},
frame_inset={l=1,r=1,t=0, w=100},
Expand Down
4 changes: 2 additions & 2 deletions internal/journal/table_of_contents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ function TableOfContents:init()

local function can_prev()
local toc = self.subviews.table_of_contents
return #toc:getChoices() > 0 and toc:getSelected() > 1
return #toc:getChoices() > 0
end
local function can_next()
local toc = self.subviews.table_of_contents
local num_choices = #toc:getChoices()
return num_choices > 0 and toc:getSelected() < num_choices
return num_choices > 0
end

self:addviews{
Expand Down
59 changes: 40 additions & 19 deletions internal/journal/text_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ TextEditor.ATTRS{
select_pen = COLOR_CYAN,
on_text_change = DEFAULT_NIL,
on_cursor_change = DEFAULT_NIL,
one_line_mode = false,
debug = false
}

Expand All @@ -104,27 +105,28 @@ function TextEditor:init()
TextEditorView{
view_id='text_area',
frame={l=0,r=3,t=0},
text = self.init_text,
text=self.init_text,

text_pen = self.text_pen,
ignore_keys = self.ignore_keys,
select_pen = self.select_pen,
debug = self.debug,
text_pen=self.text_pen,
ignore_keys=self.ignore_keys,
select_pen=self.select_pen,
debug=self.debug,
one_line_mode=self.one_line_mode,

on_text_change = function (val)
on_text_change=function (val)
self:updateLayout()
if self.on_text_change then
self.on_text_change(val)
end
end,
on_cursor_change = self:callback('onCursorChange')
on_cursor_change=self:callback('onCursorChange')
},
widgets.Scrollbar{
view_id='scrollbar',
frame={r=0,t=1},
on_scroll=self:callback('onScrollbar')
},
widgets.HelpButton{command="gui/journal", frame={r=0,t=0}}
on_scroll=self:callback('onScrollbar'),
visible=not self.one_line_mode
}
}
self:setFocus(true)
end
Expand Down Expand Up @@ -169,14 +171,14 @@ function TextEditor:setCursor(cursor_offset)
end

function TextEditor:getPreferredFocusState()
return true
return self.parent_view.focus
end

function TextEditor:postUpdateLayout()
self:updateScrollbar(self.render_start_line_y)

if self.subviews.text_area.cursor == nil then
local cursor = self.init_cursor or #self.text + 1
local cursor = self.init_cursor or #self.init_text + 1
self.subviews.text_area:setCursor(cursor)
self:scrollToCursor(cursor)
end
Expand Down Expand Up @@ -234,6 +236,10 @@ function TextEditor:onInput(keys)
return self.subviews.scrollbar:onInput(keys)
end

if keys._MOUSE_L and self:getMousePos() then
self:setFocus(true)
end

return TextEditor.super.onInput(self, keys)
end

Expand All @@ -248,6 +254,7 @@ TextEditorView.ATTRS{
on_cursor_change = DEFAULT_NIL,
enable_cursor_blink = true,
debug = false,
one_line_mode = false,
history_size = 10,
}

Expand All @@ -270,6 +277,8 @@ function TextEditorView:init()
bold=true
})

self.text = self:normalizeText(self.text)

self.wrapped_text = wrapped_text.WrappedText{
text=self.text,
wrap_width=256
Expand All @@ -278,6 +287,14 @@ function TextEditorView:init()
self.history = TextEditorHistory{history_size=self.history_size}
end

function TextEditorView:normalizeText(text)
if self.one_line_mode then
return text:gsub("\r?\n", "")
end

return text
end

function TextEditorView:setRenderStartLineY(render_start_line_y)
self.render_start_line_y = render_start_line_y
end
Expand Down Expand Up @@ -407,7 +424,7 @@ end

function TextEditorView:setText(text)
local changed = self.text ~= text
self.text = text
self.text = self:normalizeText(text)

self:recomputeLines()

Expand Down Expand Up @@ -629,6 +646,8 @@ function TextEditorView:onInput(keys)
self:paste()
self.history:store(HISTORY_ENTRY.OTHER, self.text, self.cursor)
return true
else
return TextEditor.super.onInput(self, keys)
end
end

Expand Down Expand Up @@ -777,12 +796,14 @@ end
function TextEditorView:onTextManipulationInput(keys)
if keys.SELECT then
-- handle enter
self.history:store(
HISTORY_ENTRY.WHITESPACE_BLOCK,
self.text,
self.cursor
)
self:insert(NEWLINE)
if not self.one_line_mode then
self.history:store(
HISTORY_ENTRY.WHITESPACE_BLOCK,
self.text,
self.cursor
)
self:insert(NEWLINE)
end

return true

Expand Down
Loading

0 comments on commit 22675fc

Please sign in to comment.