Skip to content

Commit

Permalink
Added tooltips, help menu item and link to github repo
Browse files Browse the repository at this point in the history
- Pressing CTRL button while hovering over a label shows a tooltip
  • Loading branch information
waicool20 committed Jan 5, 2017
1 parent 5042ebe commit 674bb6d
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 165 deletions.
12 changes: 7 additions & 5 deletions src/main/kotlin/com/waicool20/kaga/Kaga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package com.waicool20.kaga
import com.waicool20.kaga.config.KagaConfig
import com.waicool20.kaga.config.KancolleAutoProfile
import com.waicool20.kaga.handlers.KeyboardIncrementHandler
import com.waicool20.kaga.handlers.MouseIncrementHandler
import com.waicool20.kaga.handlers.ToolTipHandler
import com.waicool20.kaga.views.ConsoleView
import com.waicool20.kaga.views.PathChooserView
import javafx.application.Application
import javafx.application.Platform
import javafx.fxml.FXMLLoader
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.input.KeyEvent
import javafx.scene.input.KeyEvent.KEY_PRESSED
import javafx.scene.input.MouseEvent.MOUSE_PRESSED
import javafx.scene.input.MouseEvent.MOUSE_RELEASED
import javafx.scene.input.KeyEvent.KEY_RELEASED
import javafx.scene.input.MouseEvent.*
import javafx.stage.Modality
import javafx.stage.Stage
import tornadofx.FX
Expand Down Expand Up @@ -66,10 +69,9 @@ class Kaga : Application() {
show()
minHeight = height + 25
minWidth = width + 25
}
with(scene) {
addEventFilter(KeyEvent.ANY, ToolTipHandler(this))
addEventFilter(KEY_PRESSED, KeyboardIncrementHandler())
val handler = com.waicool20.kaga.handlers.MouseIncrementHandler(1000L, 40)
val handler = MouseIncrementHandler(1000L, 40)
addEventFilter(MOUSE_PRESSED, handler)
addEventFilter(MOUSE_RELEASED, handler)
}
Expand Down
74 changes: 74 additions & 0 deletions src/main/kotlin/com/waicool20/kaga/handlers/ToolTipHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.waicool20.kaga.handlers

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.waicool20.kaga.Kaga
import com.waicool20.kaga.util.getParentTabPane
import javafx.event.EventHandler
import javafx.scene.Node
import javafx.scene.control.Tooltip
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseEvent
import javafx.stage.Stage

class LabelTip(val id: String, val description: String)

class ToolTipHandler(stage: Stage) : EventHandler<KeyEvent> {
val tooltips: List<LabelTip> = run {
val stream = Kaga::class.java.classLoader.getResourceAsStream("tooltips.json")
val mapper = jacksonObjectMapper()
mapper.readValue<List<LabelTip>>(stream, mapper.typeFactory.constructCollectionType(List::class.java, LabelTip::class.java))
}
private var showingTooltip = Tooltip()
private var nodeUnderMouse: Node? = null
private var mouseX = 0.0
private var mouseY = 0.0

private var isCtrlPressed = false

init {
stage.addEventFilter(MouseEvent.MOUSE_MOVED, { event ->
mouseX = event.screenX
mouseY = event.screenY
val node = event.target
if (node is Node) {
if (nodeUnderMouse == node) return@addEventFilter
nodeUnderMouse = node
if (isCtrlPressed) {
showingTooltip.hide()
updateTooltip()
}
} else {
nodeUnderMouse = null
}
})
}

override fun handle(event: KeyEvent?) {
if (event == null || event.code != KeyCode.CONTROL) return
isCtrlPressed = event.isControlDown
showingTooltip.hide()
if (event.eventType == KeyEvent.KEY_PRESSED) {
updateTooltip()
}
}

private fun updateTooltip() {
if (nodeUnderMouse == null) return
with(nodeUnderMouse!!) {
val tab = getParentTabPane()?.selectionModel?.selectedItem
val labeltip = if (tab == null) {
tooltips.find { it.id == nodeUnderMouse?.parent?.id }
} else {
tooltips.find { it.id == "${tab.text}-${nodeUnderMouse?.parent?.id}" }
}
if (labeltip != null) {
showingTooltip = Tooltip(labeltip.description)
showingTooltip.isWrapText = true
showingTooltip.maxWidth = 500.0
val bounds = localToScene(boundsInLocal)
showingTooltip.show(nodeUnderMouse, bounds.maxX + scene.window.x, bounds.minY + scene.window.y)
}
}
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/com/waicool20/kaga/util/FXUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.waicool20.kaga.util
import com.sun.javafx.scene.control.skin.TableHeaderRow
import javafx.beans.property.ReadOnlyObjectProperty
import javafx.collections.ListChangeListener
import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.control.*
Expand Down Expand Up @@ -58,6 +59,18 @@ fun TableView<*>.disableHeaderMoving() {
fun TableColumn<*, *>.setWidthRatio(tableView: TableView<*>, ratio: Double) =
this.prefWidthProperty().bind(tableView.widthProperty().subtract(20).multiply(ratio))

fun Node.getParentTabPane(): TabPane? {
var parentNode = parent
while (parentNode != null) {
if (parentNode is TabPane) {
return parentNode
} else {
parentNode = parentNode.parent
}
}
return null
}

class DeselectableCellFactory<T> : Callback<ListView<T>, ListCell<T>> {
override fun call(viewList: ListView<T>): ListCell<T> {
val cell = object : ListCell<T>() {
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/com/waicool20/kaga/views/KagaView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import com.waicool20.kaga.views.tabs.quests.QuestsTabView
import com.waicool20.kaga.views.tabs.sortie.SortieTabView
import javafx.application.Platform
import javafx.fxml.FXML
import javafx.scene.control.Alert
import javafx.scene.control.Button
import javafx.scene.control.ComboBox
import javafx.scene.control.Label
import tornadofx.bind
import java.awt.Desktop
import java.net.URI
import java.nio.file.Files
import java.nio.file.Paths
import java.util.regex.Pattern
import java.util.stream.Collectors


class KagaView {
private var kancolleAutoProcess: Process? = null
private var streamGobbler: StreamGobbler? = null
Expand Down Expand Up @@ -127,6 +131,24 @@ class KagaView {
}
}

@FXML private fun openHowto() {
with(Alert(Alert.AlertType.INFORMATION)) {
title = "KAGA - How do I use KAGA?"
headerText = null
contentText = "Try pressing the CTRL button while hovering over the label of an option to show a tooltip"
showAndWait()
}
}

@FXML private fun openRepo() {
if (Desktop.isDesktopSupported()) {
Thread({
Desktop.getDesktop().browse(URI("https://github.com/waicool20/KAGA"))
}).start()
Kaga.ROOT_STAGE.toBack()
}
}

@FXML private fun openConsole() = Kaga.CONSOLE_STAGE.show()

@FXML private fun quit() = System.exit(0)
Expand Down
186 changes: 186 additions & 0 deletions src/main/resources/tooltips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
[
{
"id": "startStopButton",
"description": "This button starts and stops kancolle auto and brings the console to front if it's open."
},
{
"id": "profileLabel",
"description": "The profile that is currently loaded.\n\nTIP: To rename a profile, delete it first then change the name and save"
},
{
"id": "General-programLabel",
"description": "The program/window name of your Kancolle container. Eg. Google Chrome, Firefox, KanColleViewer!, KanColleTool Viewer, Electronic Observer, etc..."
},
{
"id": "General-recoveryMethodLabel",
"description": "Which built-in recovery method to use when you get cat bombed."
},
{
"id": "General-basicRecoveryLabel",
"description": "Check this box if your viewer sometimes throws a popup that must be cleared (DMM popup, KC3Kai navigation warning popup due to KC3Kai updates, etc). Setting this to True will try hitting the Esc key to clear the popup before re-initializing kancolle-auto from the beginning. Unfortunately does not work if the game is mid-sortie/combat."
},
{
"id": "General-paranoiaLabel",
"description": "Specifies the desired # of menus to randomly walk through. The number of sidesteps range from 0 to the Paranoia value. Setting this value to at least 1 is recommended (0 to 1 sidesteps)."
},
{
"id": "General-sleepCycleLabel",
"description": "How often kancolle-auto should run its loop, specified in full seconds. A lower value will make kancolle-auto be quicker to respond to timers, while a higher value will make it slower, but perhaps guard against bot-detection."
},
{
"id": "General-sleepModifierLabel",
"description": "If you have a slow computer/network connection, you may encounter frequent FindFailed errors. Increase this value by whole numbers (seconds) to increase the length of all sleep/wait timers to avoid this."
},
{
"id": "General-sikuliScriptJarLabel",
"description": "Path to the sikuli script Jar"
},
{
"id": "General-kancolleAutoRootLabel",
"description": "Path to kancolle auto root directory"
},
{
"id": "Scheduling-enableSleepButton",
"description": "Check this box if you want kancolle-auto to automatically sleep/pause at set times. Highly recommended that you check this box if you run kancolle-auto for a long period of time."
},
{
"id": "Scheduling-startTimeLabel",
"description": "Define around when you would like scheduled sleep to start. (Based on computer local time)"
},
{
"id": "Scheduling-sleepLengthLabel",
"description": "How long you want the sleep to last, in hours. Anywhere between 0 to 10 minutes are added randomly to the actual timer."
},
{
"id": "Scheduling-enableAutoStopButton",
"description": "Set to True if you want kancolle-auto to automatically stop and exit after a set number of hours, expeditions, sorties, or PvPs. You will have to manually restart kancolle-auto after this."
},
{
"id": "Scheduling-modeLabel",
"description": "Define what you want to base the stop count on."
},
{
"id": "Scheduling-countLabel",
"description": "Define how many of the above kancolle-auto should perform before automatically stopping."
},
{
"id": "Sortie-enableButton",
"description": "Check this box if you want to enable sorties."
},
{
"id": "Sortie-fleetCompLabel",
"description": "Specify which saved fleet composition should be used for sorties, with the first saved fleet being 1.\n\nNOTE: this value is only relevant if both PvP and Combat modules are enabled with different fleets assigned to them!"
},
{
"id": "Sortie-combinedFleetCheckBox",
"description": "Specify whether the map you're running utilizes Combined Fleets or not. Only relevant for Events. Will automatically handle FCFs and the extra ships needing repairs + resupplies. This also turns off PvP and Fleet 2's Expedition, regardless of what you input above."
},
{
"id": "Sortie-areaLabel",
"description": "The area you want the fleet to sortie to."
},
{
"id": "Sortie-nodesLabel",
"description": "Maximum number of combat nodes to run. Resource/hazard nodes do not count."
},
{
"id": "Sortie-nodeSelectsLabel",
"description": "If the map you are sortieing to involves node selections, use this to point at the image generated for that specific node. For example, if you want to always head to node K on E-3 of Winter 2016, set this to '_node_E-3-K' to reference the '_node_E-3-K.png' image included. For other maps, please generate this image yourself (a 70px x 70px image of the node during node selection, with the desired node being in the center of the image)."
},
{
"id": "Sortie-formationsLabel",
"description": "Formations to use at each combat node. If the number of formations you've specified does not match the number of nodes you specified, the script will default to line ahead for the remaining nodes."
},
{
"id": "Sortie-nightBattlesLabel",
"description": "Whether or not to engage in night battle at each combat node. If the number of night battle options you've specified does not match the number of nodes you specified, the script will default to Yes for the remaining nodes."
},
{
"id": "Sortie-retreatLimitLabel",
"description": "Specifies the damage level (of any ship) in which to retreat from a sortie."
},
{
"id": "Sortie-repairLimitLabel",
"description": "Specifies the damage level (of any ship) to repair before sortieing again. The script will not sortie if any ships are at in this damage level"
},
{
"id": "Sortie-repairTimeLimitLabel",
"description": "Set the repair time limit for repairs. kancolle-auto will automatically use a bucket to repair a ship if its repair time is above this # of hours. If you want to never use buckets, set this to '9900'. A limit of '9500' and below will allow the repair script to use a bucket if the OCR cannot properly read the timer, so adjust this accordingly. If you always want to use buckets, set it to '0'."
},
{
"id": "Sortie-checksLabel",
"description": "Several options that are checked before and after sortieing"
},
{
"id": "Sortie-checkFatigueCheckBox",
"description": "Whether or not to consider fatigue/morale before sorties. If the ships have an unhappy face (morale of 29 or below) the script will wait for a set amount of time for morale to recover."
},
{
"id": "Sortie-checkPortCheckBox",
"description": "Whether or not to sortie when the port (ship slots) is full. Check this box if you do not want sorties to occur when your port is full. Port checking is automatically done when sortieing to Event maps, since sortieing is prohibited when you do not have 5 free ship slots."
},
{
"id": "Sortie-medalStopCheckBox",
"description": "Set this to True if you want kancolle-auto to stop sortieing to the specified map once the medal has been obtained. Only applicable to the monthly EOs (1-5, 2-5, 3-5, 4-5, 5-5)."
},
{
"id": "Sortie-lastNodePushLabel",
"description": "Set whether or not to 'push' past the max number of defined combat nodes, REGARDLESS OF THE STATE OF YOUR FLEET. Only do this if the last node is a resource/non-combat node, like the end of 1-6, and only if your path is 100% fixed!\n\nWARNING: YOU MAY LOSE SHIPS WITH THIS SET TO TRUE. PLEASE STUDY THE MAP YOU ARE SORTIEING TO AND MAKE AN EDUCATED DECISION"
},
{
"id": "PvP-enableButton",
"description": "Check this box if you want to enable pvp."
},
{
"id": "PvP-fleetCompLabel",
"description": "Specify which saved fleet composition should be used for pvp, with the first saved fleet being 1.\n\nNOTE: this value is only relevant if both PvP and Combat modules are enabled with different fleets assigned to them!"
},
{
"id": "Expeditions-enableButton",
"description": "Check this box if you want to enable expeditions"
},
{
"id": "Expeditions-fleet2Label",
"description": "The expedition fleet 2 should go on. If this Fleet hasn't been unlocked or you don't want it to run an expedition, set it to off-duty"
},
{
"id": "Expeditions-fleet3Label",
"description": "The expedition fleet 3 should go on. If this Fleet hasn't been unlocked or you don't want it to run an expedition, set it to off-duty"
},
{
"id": "Expeditions-fleet4Label",
"description": "The expedition fleet 4 should go on. If this Fleet hasn't been unlocked or you don't want it to run an expedition, set it to off-duty"
},
{
"id": "Quests-enableButton",
"description": "Check this box if you want kancolle auto to manage quests"
},
{
"id": "Quests-questsLabel",
"description": "Quests to check for, only the shown quests are supported. Kancolle-auto will ignore quests if they are not completable as specified by your config (if PvP is disabled, PvP quests will not be activated, and so on)."
},
{
"id": "Quests-checkScheduleLabel",
"description": "How often should quests be checked? Settings this to 1 will make quests be checked after every expedition and sortie."
},
{
"id": "Misc-enableSubSwitchButton",
"description": "Check this box if you want kancolle auto to find submarines under repair to switch out so kancolle-auto can continue sorties. Useful for maps where submarines are used to tank hits, such as 2-3 (Orel) or 3-2-A."
},
{
"id": "Misc-enableLbasButton",
"description": "Check this box if you want to enable LBAS"
},
{
"id": "Misc-group1CheckBox",
"description": "Check this box to enable group 1 LBAS Support, then configure the node image names for each of the above enabled air support groups. Groups with node targets should have two nodes assigned to them. You'll have to generate these images yourself (or wait for the program to be updated on Github). Active groups with no node images are assumed to be air defense groups, and will be resupplied each sortie, but not assigned nodes on the map"
},
{
"id": "Misc-group2CheckBox",
"description": "Check this box to enable group 2 LBAS Support, then configure the node image names for each of the above enabled air support groups. Groups with node targets should have two nodes assigned to them. You'll have to generate these images yourself (or wait for the program to be updated on Github). Active groups with no node images are assumed to be air defense groups, and will be resupplied each sortie, but not assigned nodes on the map"
},
{
"id": "Misc-group3CheckBox",
"description": "Check this box to enable group 3 LBAS Support, then configure the node image names for each of the above enabled air support groups. Groups with node targets should have two nodes assigned to them. You'll have to generate these images yourself (or wait for the program to be updated on Github). Active groups with no node images are assumed to be air defense groups, and will be resupplied each sortie, but not assigned nodes on the map"
}
]
7 changes: 6 additions & 1 deletion src/main/resources/views/kaga.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<KeyCodeCombination alt="UP" code="D" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#openHowto" text="How do I use KAGA?">
<accelerator>
<KeyCodeCombination alt="UP" code="F1" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<MenuItem mnemonicParsing="false" onAction="#openRepo" text="Github Repository" />
</items>
</Menu>
</menus>
Expand All @@ -59,7 +64,7 @@
<children>
<HBox alignment="CENTER_LEFT" spacing="4.0" GridPane.valignment="TOP">
<children>
<Label text="Profile:" />
<Label fx:id="profileLabel" text="Profile:" />
<ComboBox fx:id="profileNameComboBox" editable="true" onAction="#onSelectProfile" onShowing="#showProfiles" prefHeight="28.0" prefWidth="200.0" />
<Button mnemonicParsing="false" onAction="#onSaveButton" text="Save" />
<Button mnemonicParsing="false" onAction="#onDeleteButton" text="Delete" />
Expand Down
Loading

0 comments on commit 674bb6d

Please sign in to comment.