Skip to content

Commit

Permalink
Icon chooser widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ontheheavens committed Feb 4, 2024
1 parent 4380292 commit e135136
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 95 deletions.
19 changes: 9 additions & 10 deletions data/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
"fleetjour_intel": {

"fleet_journal": "graphics/fleetjour/icons/intel/fleet_journal.png",

"entry_cache": "graphics/fleetjour/icons/intel/entry_cache.png",
"entry_debris": "graphics/fleetjour/icons/intel/entry_debris.png",
"entry_derelict": "graphics/fleetjour/icons/intel/entry_derelict.png",
"entry_entity": "graphics/fleetjour/icons/intel/entry_entity.png",
"entry_exclamation": "graphics/fleetjour/icons/intel/entry_exclamation.png",
"entry_station": "graphics/fleetjour/icons/intel/entry_station.png",
"entry_stellar_body": "graphics/fleetjour/icons/intel/entry_stellar_body.png",
"entry_probe": "graphics/fleetjour/icons/intel/entry_probe.png",
"entry_cryosleeper": "graphics/fleetjour/icons/intel/entry_cryosleeper.png"
"entry_cache": "graphics/fleetjour/icons/intel/entry_cache.png",
"entry_debris": "graphics/fleetjour/icons/intel/entry_debris.png",
"entry_derelict": "graphics/fleetjour/icons/intel/entry_derelict.png",
"entry_entity": "graphics/fleetjour/icons/intel/entry_entity.png",
"entry_exclamation": "graphics/fleetjour/icons/intel/entry_exclamation.png",
"entry_station": "graphics/fleetjour/icons/intel/entry_station.png",
"entry_stellar_body": "graphics/fleetjour/icons/intel/entry_stellar_body.png",
"entry_probe": "graphics/fleetjour/icons/intel/entry_probe.png",
"entry_cryosleeper": "graphics/fleetjour/icons/intel/entry_cryosleeper.png"

}

Expand Down
2 changes: 1 addition & 1 deletion fleet_journal_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# WARNING: careless usage of this feature can lead to issues with your game.
# Use at your own discretion and under your own responsibility.

"enable_manage_entries_button": false,
"enable_manage_entries_button": true,

####### Auto-Logging Options #######

Expand Down
Binary file added images/Auto-Logs and Icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified jars/fleet_journal.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/kotlin/fleetjour/scripts/EntryWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class EntryWriter: BaseIntelPlugin() {

var customTitleSet: Boolean = false

var selectedIconIndex: Int = 0

var tagsState: HashMap<WriterPanelAssembly.EntityDisplayTags, Boolean> = hashMapOf(
Pair(WriterPanelAssembly.EntityDisplayTags.PLANETS, true),
Pair(WriterPanelAssembly.EntityDisplayTags.SALVAGE, true),
Expand Down Expand Up @@ -112,6 +114,8 @@ class EntryWriter: BaseIntelPlugin() {
contents.add(paragraph.content)
}
val newEntry = JournalEntry(Common.findTargetEntity(this), title, brief, contents)
val iconID = assembly.icons[this.selectedIconIndex]
newEntry.icon = iconID
Global.getSector().intelManager.addIntel(newEntry)
this.draftParagraphs.clear()
this.selectedParagraphIndex = 0
Expand All @@ -132,6 +136,10 @@ class EntryWriter: BaseIntelPlugin() {
this.draftParagraphs.clear()
this.selectedParagraphIndex = 0

val entryIcon = entry.icon

this.selectedIconIndex = assembly.icons.entries.find {it.value == entryIcon}?.key?:0

for (paragraph in entry.contents) {
addParagraph(paragraph)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package fleetjour.scripts.interaction.entrymanager

import com.fs.starfarer.api.ui.IntelUIAPI
import fleetjour.scripts.interaction.entrymanager.panel.PanelConstants
import fleetjour.scripts.EntryWriter
import fleetjour.scripts.interaction.entrymanager.panel.EntryManagerConstants
import fleetjour.scripts.interaction.shared.AbstractPanelDialog

/**
* @author Ontheheavens
* @since 16.02.2023
*/

class EntryManagerDialog(ui: IntelUIAPI) : AbstractPanelDialog(ui) {
class EntryManagerDialog(ui: IntelUIAPI, private val journal: EntryWriter) : AbstractPanelDialog(ui) {

override fun showCustomDialog() {
dialog.showCustomVisualDialog(
PanelConstants.PANEL_WIDTH,
PanelConstants.PANEL_HEIGHT, EntryManagerDelegate(EntryManagerPlugin(ui), this.dialog)
EntryManagerConstants.PANEL_WIDTH,
EntryManagerConstants.PANEL_HEIGHT, EntryManagerDelegate(EntryManagerPlugin(ui, journal), this.dialog)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate.DialogCallbacks
import com.fs.starfarer.api.campaign.InteractionDialogAPI
import com.fs.starfarer.api.ui.CustomPanelAPI
import com.fs.starfarer.api.ui.IntelUIAPI
import fleetjour.scripts.EntryWriter
import fleetjour.scripts.interaction.entrymanager.panel.EntryPanelAssembly
import fleetjour.scripts.interaction.entrymanager.panel.EntryPanelOverseer
import fleetjour.scripts.interaction.shared.AbstractPanelPlugin
Expand All @@ -13,15 +14,15 @@ import fleetjour.scripts.interaction.shared.AbstractPanelPlugin
* @since 16.02.2023
*/

class EntryManagerPlugin(ui: IntelUIAPI) : AbstractPanelPlugin(ui) {
class EntryManagerPlugin(ui: IntelUIAPI, private val journal: EntryWriter) : AbstractPanelPlugin(ui) {

override fun assemblePanel(
panel: CustomPanelAPI,
callbacks: DialogCallbacks,
dialog: InteractionDialogAPI,
ui: IntelUIAPI
) {
EntryPanelOverseer.initialize(panel, callbacks, dialog, ui, this)
EntryPanelOverseer.initialize(panel, callbacks, dialog, ui, this, journal)
EntryPanelAssembly.assemble(panel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object EntriesSection {
parentPanelInstance?.removeComponent(listPanelInstance)
}
val sectionContainer = parentPanelInstance?.createCustomPanel(
PanelConstants.CONTENT_WIDTH,
EntryManagerConstants.CONTENT_WIDTH,
sectionHeight, EntryPanelOverseer.plugin
)
val list = createEntriesList(sectionContainer, sectionHeight)
Expand Down Expand Up @@ -86,7 +86,7 @@ object EntriesSection {

private fun createEntriesList(section: CustomPanelAPI?, height: Float): TooltipMakerAPI? {
section?: return null
val listContainer = section.createUIElement(PanelConstants.ENTRIES_LIST_WIDTH, height, true)
val listContainer = section.createUIElement(EntryManagerConstants.ENTRIES_LIST_WIDTH, height, true)
val allEntries = retrieveFilteredEntries()
if (allEntries.size == 0) return listContainer
showedEntries = linkedMapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ package fleetjour.scripts.interaction.entrymanager.panel
* @since 17.02.2023
*/

object PanelConstants {
object EntryManagerConstants {

const val RIGHTSIDE_BUTTONS_WIDTH = 180f
const val ENTRIES_LIST_WIDTH = 380f

const val PANEL_CONTENT_OFFSET = 8f
const val MANAGE_SECTION_HEIGHT = 150f

const val PANEL_HEIGHT = 640f
const val PANEL_WIDTH = ENTRIES_LIST_WIDTH + RIGHTSIDE_BUTTONS_WIDTH + (PANEL_CONTENT_OFFSET * 2) + 20f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.fs.starfarer.api.impl.campaign.ids.Tags
import com.fs.starfarer.api.ui.*
import com.fs.starfarer.api.util.Misc
import fleetjour.scripts.EntryWriter
import fleetjour.scripts.interaction.shared.ButtonListener
import fleetjour.scripts.interaction.shared.InteractiveButton

/**
* @author Ontheheavens
Expand Down Expand Up @@ -65,7 +67,7 @@ object EntryPanelAssembly {
headerInstance = header
val footer = Footer.create(panel)
val contentHeightOffset = header!!.position.height + footer!!.position.height
val contentHeight = PanelConstants.PANEL_HEIGHT - ((PanelConstants.PANEL_CONTENT_OFFSET * 2)
val contentHeight = EntryManagerConstants.PANEL_HEIGHT - ((EntryManagerConstants.PANEL_CONTENT_OFFSET * 2)
+ contentHeightOffset + 23f)
val entriesSection = EntriesSection.create(panel, contentHeight)
val sortingSection = createSortingPanel(panel, contentHeight - 91f)
Expand All @@ -86,7 +88,7 @@ object EntryPanelAssembly {
}

private fun createSortingPanel(panel: CustomPanelAPI, height: Float): CustomPanelAPI {
val width = PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f
val width = EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f
val sortingPanel = panel.createCustomPanel(width, height, EntryPanelOverseer.plugin)
val backgroundContainer = sortingPanel.createUIElement(width, height, false)
backgroundContainer.setForceProcessInput(false)
Expand All @@ -107,7 +109,7 @@ object EntryPanelAssembly {
)
tagButton.isChecked = tag.value
buttonsContainer.addSpacer(3f)
val buttonWrapper = object : InteractiveButton(tagButton, Type.TAG) {
val buttonWrapper = object : InteractiveButton(tagButton) {
var state: Boolean = tagButton.isChecked
override fun applyEffect() {
SORTING_TAGS[tag.key] = state
Expand Down Expand Up @@ -135,15 +137,15 @@ object EntryPanelAssembly {
val boxColor = Misc.scaleColorOnly(baseBoxColor, 0.9f)
sidebarBoxContainer.addAreaCheckbox("", null, Misc.getBasePlayerColor(), boxColor,
Misc.getBasePlayerColor(), 186f, height, 0f)
val offsetX = PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 2f
val offsetX = EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 2f
sidebarBoxContainer.prev.position.setXAlignOffset(-offsetX)
sidebarBoxContainer.prev.position.setYAlignOffset(-9f)
sidebarFrame.addImageWithText(2f)
return sidebarFrame.prev
}

private fun createControlSection(parentPanel: CustomPanelAPI): CustomPanelAPI {
val width = PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f
val width = EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f
val panel = parentPanel.createCustomPanel(width, 20f, EntryPanelOverseer.plugin)
val buttonsContainer = panel.createUIElement(width - 8f, 20f, false)
buttonsContainer.addSpacer(8f)
Expand All @@ -156,24 +158,24 @@ object EntryPanelAssembly {
hideButtonText = "Show entry"
}
val hideButtonInstance = buttonsContainer.addButton(hideButtonText, null, colorBase, colorDark,
Alignment.MID, CutStyle.ALL, PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
Alignment.MID, CutStyle.ALL, EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
hideButtonInstance.isEnabled = false
val hideButtonWrapper = object : InteractiveButton(hideButtonInstance, Type.STANDARD) {
val hideButtonWrapper = object : InteractiveButton(hideButtonInstance) {
override fun applyEffect() {
EntriesSection.changeEntryVisibility()
}
}
ButtonListener.getIndex()?.add(hideButtonWrapper)
buttonsContainer.addSpacer(8f)
val deleteButtonInstance = buttonsContainer.addButton("Delete entry", null, colorBase, colorDark,
Alignment.MID, CutStyle.ALL, PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
Alignment.MID, CutStyle.ALL, EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
if (!EntriesSection.showedEntries.containsKey(EntriesSection.selectedEntry) ||
EntriesSection.showedEntries.size == 0 ||
EntriesSection.selectedEntry == null ||
EntriesSection.selectedEntry is EntryWriter) {
deleteButtonInstance.isEnabled = false
}
val deleteButtonWrapper = object : InteractiveButton(deleteButtonInstance, Type.STANDARD) {
val deleteButtonWrapper = object : InteractiveButton(deleteButtonInstance) {
override fun applyEffect() {
if (EntriesSection.selectedEntry == null) return
if (EntriesSection.selectedEntry is EntryWriter) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package fleetjour.scripts.interaction.entrymanager.panel

import com.fs.starfarer.api.Global
import com.fs.starfarer.api.campaign.CoreUITabId
import com.fs.starfarer.api.campaign.CustomUIPanelPlugin
import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate.DialogCallbacks
import com.fs.starfarer.api.campaign.InteractionDialogAPI
import com.fs.starfarer.api.ui.CustomPanelAPI
import com.fs.starfarer.api.ui.IntelUIAPI
import fleetjour.scripts.EntryWriter
import fleetjour.scripts.interaction.shared.ButtonListener

/**
* @author Ontheheavens
Expand All @@ -18,13 +22,16 @@ object EntryPanelOverseer {
private var dialog: InteractionDialogAPI? = null
var plugin: CustomUIPanelPlugin? = null
private var intelUI: IntelUIAPI? = null
private var journal: EntryWriter? = null

fun initialize(panel: CustomPanelAPI, callbacks: DialogCallbacks,
dialog: InteractionDialogAPI, ui: IntelUIAPI, plugin: CustomUIPanelPlugin) {
dialog: InteractionDialogAPI, ui: IntelUIAPI,
plugin: CustomUIPanelPlugin, journal: EntryWriter) {
EntryPanelOverseer.panel = panel
EntryPanelOverseer.callbacks = callbacks
EntryPanelOverseer.dialog = dialog
EntryPanelOverseer.plugin = plugin
EntryPanelOverseer.journal = journal
intelUI = ui
}

Expand All @@ -46,8 +53,9 @@ object EntryPanelOverseer {
ButtonListener.clearIndex()
// Dismissing dialog itself means exit from initialization dialog too.
dialog?.dismiss()
intelUI?.updateIntelList()
intelUI?.updateIntelList(true)
intelUI?.recreateIntelUI()
Global.getSector().campaignUI.showCoreUITab(CoreUITabId.INTEL, journal)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package fleetjour.scripts.interaction.entrymanager.panel

import com.fs.starfarer.api.ui.*
import com.fs.starfarer.api.util.Misc
import fleetjour.scripts.interaction.entrymanager.panel.PanelConstants.PANEL_CONTENT_OFFSET
import fleetjour.scripts.interaction.entrymanager.panel.EntryManagerConstants.PANEL_CONTENT_OFFSET
import fleetjour.scripts.interaction.shared.ButtonListener
import fleetjour.scripts.interaction.shared.InteractiveButton
import fleetjour.scripts.panel.Common

/**
Expand All @@ -13,11 +15,11 @@ import fleetjour.scripts.panel.Common
object Footer {

fun create(panel: CustomPanelAPI): TooltipMakerAPI? {
val contentWidth = PanelConstants.CONTENT_WIDTH
val contentWidth = EntryManagerConstants.CONTENT_WIDTH
val footer = panel.createUIElement(contentWidth, 10f, false)
footer.setForceProcessInput(true)
val footerLine: ButtonAPI = Common.addLine(footer, contentWidth -
(PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 21f))
(EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 21f))
footerLine.position.setYAlignOffset(17f)
footerLine.position.setXAlignOffset(-4f)
createExitButton(footer)
Expand All @@ -29,10 +31,10 @@ object Footer {
footer.setButtonFontVictor14()
val exitButtonInstance = footer.addButton("DISMISS", null, Misc.getBasePlayerColor(),
Misc.getDarkPlayerColor(), Alignment.MID, CutStyle.TL_BR,
PanelConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
EntryManagerConstants.RIGHTSIDE_BUTTONS_WIDTH + 6f, 25f, 2f)
val offset: Float = PANEL_CONTENT_OFFSET
exitButtonInstance.position.inBR(offset, offset)
val buttonWrapper = object : InteractiveButton(exitButtonInstance, Type.STANDARD) {
val buttonWrapper = object : InteractiveButton(exitButtonInstance) {
override fun applyEffect() {
EntryPanelOverseer.dismissPanel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.fs.starfarer.api.ui.*
object Header {

fun create(panel: CustomPanelAPI): TooltipMakerAPI? {
val header = panel.createUIElement(PanelConstants.CONTENT_WIDTH - 4f, 18f, false)
val header = panel.createUIElement(EntryManagerConstants.CONTENT_WIDTH - 4f, 18f, false)
header.addSectionHeading("Manage entries", Alignment.MID, 2f)
panel.addUIElement(header).inTMid(PanelConstants.PANEL_CONTENT_OFFSET + 2f)
panel.addUIElement(header).inTMid(EntryManagerConstants.PANEL_CONTENT_OFFSET + 2f)
return header
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import com.fs.starfarer.api.ui.CustomPanelAPI
import com.fs.starfarer.api.ui.TooltipMakerAPI
import com.fs.starfarer.api.ui.UIComponentAPI
import com.fs.starfarer.api.util.Misc
import fleetjour.scripts.interaction.shared.ButtonListener
import fleetjour.scripts.interaction.shared.GroupButton
import fleetjour.scripts.interaction.shared.InteractiveButton
import java.awt.Color

/**
Expand All @@ -29,7 +32,7 @@ class IntelEntry(val plugin: IntelInfoPlugin) {
}

fun createEntry(section: CustomPanelAPI, entry: IntelInfoPlugin): Pair<CustomPanelAPI, Float> {
val width = PanelConstants.ENTRIES_LIST_WIDTH
val width = EntryManagerConstants.ENTRIES_LIST_WIDTH
val entryContainer = section.createCustomPanel(width, 20f, EntryPanelOverseer.plugin)
val entryTooltip = entryContainer.createUIElement(width - 8f, 20f, false)
val dummy = entryTooltip.beginImageWithText(Global.getSettings().getSpriteName("intel",
Expand Down Expand Up @@ -60,47 +63,17 @@ class IntelEntry(val plugin: IntelInfoPlugin) {
}

private fun createButton(selectEntryButton: ButtonAPI): InteractiveButton {
val buttonWrapper = object : InteractiveButton(selectEntryButton, Type.ENTRY) {
private var checkedLastFrame = false
private var othersUnchecked = false
private var checkedAtCreation = false
val buttonWrapper = object : GroupButton(selectEntryButton, Type.ENTRY) {

override fun applyEffect() {
if (EntriesSection.selectedEntry == this@IntelEntry.plugin) return
EntriesSection.selectedEntry = this@IntelEntry.plugin
this.instance.highlight()
this.instance.isEnabled = false
this.instance.setButtonDisabledPressedSound("ui_button_pressed")
EntryPanelAssembly.controlButtonsRedrawQueued = true
}
fun affectOthersInGroup() {
for (button in ButtonListener.getIndex()!!) {
if (button.type !== this.type) continue
if (button === this) continue
button.instance.isChecked = false
button.instance.isEnabled = true
button.instance.unhighlight()
}
}
override fun check() {
val instance: ButtonAPI = this.instance
if (!instance.isChecked) {
checkedLastFrame = false
othersUnchecked = false
return
}
if (!othersUnchecked) {
affectOthersInGroup()
othersUnchecked = true
}
if (checkedAtCreation) {
checkedAtCreation = false
checkedLastFrame = true
return
}
if (!checkedLastFrame) {
applyEffect()
checkedLastFrame = true
}

override fun getGroupButtons(): Set<InteractiveButton> {
return ButtonListener.getIndex()!!
}
}
return buttonWrapper
Expand Down
Loading

0 comments on commit e135136

Please sign in to comment.