Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task notes #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/main/java/net/reldo/taskstracker/HtmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static String wrapWithWrappingParagraph(String text, int width)
return "<p width=\"" + width + "\">" + text + "</p>";
}

public static String wrapWithItalics(String text)
{
return "<i>" + text + "</i>";
}

public static String wrapWithBold(String text)
{
return "<b>" + text + "</b>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public class ConfigTaskSave
@Expose public final long tracked;
@Expose public final Integer structId;
@Expose public final long ignored;
@Expose public final String note;

public ConfigTaskSave(TaskFromStruct task)
{
completed = task.getCompletedOn();
tracked = task.getTrackedOn();
ignored = task.getIgnoredOn();
structId = task.getStructId();
note = task.getNote();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TaskFromStruct
private StructComposition _struct;
private final Map<String, String> _stringParams = new HashMap<>();
private final Map<String, Integer> _intParams = new HashMap<>();
@Getter @Setter
private String note;

public TaskFromStruct(TaskType taskType, TaskDefinition taskDefinition)
{
Expand Down Expand Up @@ -148,11 +150,13 @@ public void setIgnored(boolean state)
public void loadConfigSave(ConfigTaskSave loadedData)
{
setDates(loadedData.completed, loadedData.ignored, loadedData.tracked);
setNote(loadedData.note);
}

public void loadReldoSave(ReldoTaskSave loadedData)
{
setMostRecentDates(loadedData.getCompleted(), loadedData.getIgnored(), loadedData.getTodo());
setNote(loadedData.getNotes());
}

private void setDates(long completedOn, long ignoredOn, long trackedOn)
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/net/reldo/taskstracker/panel/TaskPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
Expand Down Expand Up @@ -109,7 +111,7 @@ public String getTaskTooltip()
}

String wikiNotes = task.getTaskDefinition().getWikiNotes();
if (wikiNotes != null)
if (wikiNotes != null && !wikiNotes.isEmpty())
{
tooltipText.append(HtmlUtil.HTML_LINE_BREAK).append(wikiNotes).append(HtmlUtil.HTML_LINE_BREAK);
}
Expand All @@ -128,6 +130,13 @@ public String getTaskTooltip()
tooltipText.append(HtmlUtil.HTML_LINE_BREAK).append("Players Completed: ").append(completionPercent).append('%');
}

String userNotes = task.getNote();
if (userNotes != null && !userNotes.isEmpty())
{
tooltipText.append(HtmlUtil.HTML_LINE_BREAK).append(HtmlUtil.HTML_LINE_BREAK);
tooltipText.append(HtmlUtil.wrapWithItalics(userNotes)).append(HtmlUtil.HTML_LINE_BREAK);
}

return HtmlUtil.wrapWithHtml(
HtmlUtil.wrapWithWrappingParagraph(tooltipText.toString(), 200)
);
Expand Down Expand Up @@ -246,22 +255,38 @@ public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JPopupMenu menu = createWikiPopupMenu();
JPopupMenu menu = createTaskPopupMenu();
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
}

public JPopupMenu createWikiPopupMenu()
public JPopupMenu createTaskPopupMenu()
{
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem editNoteItem = new JMenuItem("Edit Note");
editNoteItem.addActionListener(e -> editTaskNote());
popupMenu.add(editNoteItem);
JMenuItem openWikiItem = new JMenuItem("Wiki");
openWikiItem.addActionListener(e -> openRuneScapeWiki());
popupMenu.add(openWikiItem);
return popupMenu;
}

private void editTaskNote()
{
JOptionPane optionPane = new JOptionPane("Enter the notes to associate with this task (empty removes note):", JOptionPane.INFORMATION_MESSAGE);
optionPane.setInputValue(task.getNote());
optionPane.setWantsInput(true);
JDialog inputDialog = optionPane.createDialog(this, "Set tasks note");
inputDialog.setAlwaysOnTop(true);
inputDialog.setVisible(true);
String note = optionPane.getInputValue().toString();
task.setNote(note);
plugin.saveCurrentTaskTypeData();
}

private void openRuneScapeWiki()
{
String wikiUrl = String.format("https://oldschool.runescape.wiki/%s", URLEncoder.encode(task.getName().replace(' ', '_'), StandardCharsets.UTF_8));
Expand Down