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

Feature table hint #11

Merged
merged 9 commits into from
Oct 29, 2023
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Copy button is active only when all required components present (aspects, paper,

### Functional
Nice to have
- "Info" element (question mark icon?) which explains how to use the table
- A way to switch (in-game?) to old UI in case a fallback needed
- Configurable bonus aspect particle (change size/turn off)
- Batch aspect combination in one packet (see PacketAspectCombinationToServer)
Expand Down Expand Up @@ -105,6 +104,21 @@ which causes aspect caching of this mod to miss it.
**Probable Cause**: Mod X creates its aspects on `FMLLoadCompleteEvent` or later
which causes aspect caching of this mod to miss it.

**Solutions**:
1. Move aspect creation of mod X earlier (e.g. FMLInitializeEvent).
This would be a preferred solution since aspects should be created early if possible.
2. Drop `AspectTree` initialization in `elan.tweaks.thaumcraft.research.frontend.integration.proxies.ClientSingletonInitializer`
(two lines, one creating the tree and second one printing).
This will cause caching on first UI opening.
This is not crucial, but somewhat reduces UX, since it will cause a small delay

## Known issues

### Aspect from mod X is not showing up in the aspect pools.

**Probable Cause**: Mod X creates its aspects on `FMLLoadCompleteEvent` or later
which causes aspect caching of this mod to miss it.

**Solutions**:
1. Move aspect creation of mod X earlier (e.g. FMLInitializeEvent).
This would be a preferred solution since aspects should be created early if possible.
Expand Down
Binary file modified doc/example-gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface UIContext {

fun drawTooltip(uiPosition: VectorXY = Vector2D.ZERO, vararg text: String)
fun drawTooltipCentered(uiCenterPosition: VectorXY = Vector2D.ZERO, vararg text: String)
fun drawTooltipVerticallyCentered(uiCenterPosition: VectorXY = Vector2D.ZERO, vararg text: String)

fun drawOrb(uiPosition: VectorXY, color: Int)
fun drawOrb(uiPosition: VectorXY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ object TooltipRenderer {
fontRenderer: FontRenderer
) {
val textScale = lines.textScale(fontRenderer)
val xOffset = Vector2D(textScale.width / 2, y = textScale.height / 2)
fontRenderer.draw(lines, textScale, origin = center - xOffset, subTipColorColorHex)
val offset = Vector2D(textScale.width / 2, y = textScale.height / 2)
fontRenderer.draw(lines, textScale, origin = center - offset, subTipColorColorHex)
}

fun drawVerticallyCentered(
lines: Array<out String>,
center: VectorXY,
subTipColorColorHex: String,
fontRenderer: FontRenderer
) {
val textScale = lines.textScale(fontRenderer)
val offset = Vector2D(x = 0, y = textScale.height / 2)
fontRenderer.draw(lines, textScale, origin = center - offset, subTipColorColorHex)
}

fun draw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class TableUIContext(
TooltipRenderer.TextColors.LIGHT_BLUE,
fontRenderer)
}
override fun drawTooltipVerticallyCentered(uiCenterPosition: VectorXY, vararg text: String) {
TooltipRenderer.drawVerticallyCentered(
text, center = screenOrigin + uiCenterPosition, TooltipRenderer.TextColors.LIGHT_BLUE, fontRenderer
)
}

override fun drawOrb(uiPosition: VectorXY, color: Int) {
OrbParticle.draw(screenOrigin + uiPosition, color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.R
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.ResearchTableInventoryTexture.AspectPools
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.ResearchTableInventoryTexture.CopyButton
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.ResearchTableInventoryTexture.ResearchArea
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.ResearchTableInventoryTexture.UsageHint
import net.minecraft.entity.player.EntityPlayer
import thaumcraft.api.aspects.Aspect
import thaumcraft.common.tiles.TileResearchTable
Expand All @@ -39,6 +40,7 @@ object ResearchTableGuiFactory {
researchArea() +
copyButton() +
palletComponents() +
UsageHintUIComponent(UsageHint.uiBounds, UsageHint.onMouseOverBounds, researcher) +
ScribeToolsNotificationUIComponent(research, ResearchArea.centerOrigin) +
AspectDragAndDropUIComponent(pallet) +
KnowledgeNotificationUIComponent()) { screenOrigin, fontRenderer ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package elan.tweaks.thaumcraft.research.frontend.integration.table.gui.component

import elan.tweaks.common.gui.component.BackgroundUIComponent
import elan.tweaks.common.gui.component.MouseOverUIComponent
import elan.tweaks.common.gui.component.UIContext
import elan.tweaks.common.gui.dto.Rectangle
import elan.tweaks.common.gui.dto.VectorXY
import elan.tweaks.thaumcraft.research.frontend.domain.ports.provided.ResearcherKnowledgePort
import elan.tweaks.thaumcraft.research.frontend.domain.ports.provided.ResearcherKnowledgePort.Knowledge
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.layout.UsageHintLayout
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.UsageHintResearchExpertiseTexture
import elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures.UsageHintTexture
import net.minecraft.util.StatCollector

class UsageHintUIComponent(
private val uiBounds: Rectangle,
private val onMouseOverBounds: Rectangle,
private val researcher: ResearcherKnowledgePort
): BackgroundUIComponent, MouseOverUIComponent {

override fun onDrawBackground(uiMousePosition: VectorXY, partialTicks: Float, context: UIContext){
if(researcher.hasDiscovered(Knowledge.ResearchExpertise)) {
context.drawBlending(UsageHintResearchExpertiseTexture, uiBounds.origin)
} else {
context.drawBlending(UsageHintTexture, uiBounds.origin)
}
}

override fun onMouseOver(uiMousePosition: VectorXY, partialTicks: Float, context: UIContext) {
if (uiMousePosition in onMouseOverBounds) drawHint(uiMousePosition, context)
}

private fun drawHint(uiMousePosition: VectorXY, context: UIContext) {
val hintHeaderLine = StatCollector.translateToLocal("researchtable.usagehint.header")
val hintDescriptionLine = StatCollector.translateToLocal("researchtable.usagehint.description")

if(researcher.hasDiscovered(Knowledge.ResearchExpertise)) {
val hintResearchExpertise =
StatCollector.translateToLocal("researchtable.usagehint.research_expertise")
context.drawTooltipVerticallyCentered(
uiCenterPosition = uiMousePosition + UsageHintLayout.textBoxOffset,
hintHeaderLine, hintDescriptionLine, hintResearchExpertise
)
} else {
context.drawTooltipVerticallyCentered(
uiCenterPosition = uiMousePosition + UsageHintLayout.textBoxOffset,
hintHeaderLine, hintDescriptionLine
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package elan.tweaks.thaumcraft.research.frontend.integration.table.gui.layout

import elan.tweaks.common.gui.dto.Vector2D

object UsageHintLayout {
val textBoxOffset = Vector2D(12, 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ object ResearchTableInventoryTexture :
private const val SIZE_PIXEL = 18
const val SIZE_WITH_SHADOW_PIXELS = SIZE_PIXEL + SHADOW_PIXELS
private val uiOrigin = Vector2D(x = 207, y = 6)
val bounds = Rectangle(origin = uiOrigin, scale = Scale(SIZE_PIXEL, SIZE_PIXEL))
val bounds = Rectangle(
origin = uiOrigin,
scale = Scale.cube(SIZE_PIXEL)
)
val requirementsUiOrigin = ResearchArea.bounds.origin + Vector2D(x = 6, y = 4)
}

object UsageHint {
private const val SHADOW_PIXELS = 6
private const val SIZE_PIXEL = 18
const val SIZE_WITH_SHADOW_PIXELS = SIZE_PIXEL + SHADOW_PIXELS
private val uiOrigin = Vector2D(x = 111, y = 6)
val uiBounds = Rectangle(
origin = uiOrigin,
scale = Scale.cube(SIZE_WITH_SHADOW_PIXELS)
)
private val onMouseOverOrigin = Vector2D(x = 114, y = 10)
val onMouseOverBounds = Rectangle(
origin = onMouseOverOrigin,
scale = Scale.cube(SIZE_PIXEL)
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures

import elan.tweaks.common.gui.dto.Scale
import elan.tweaks.common.gui.dto.UV
import elan.tweaks.common.gui.textures.ThaumcraftTextureInstance

object UsageHintResearchExpertiseTexture : ThaumcraftTextureInstance(
"research/table/research-table.png",
textureScale = Scale(width = 342, height = 245),
uv = UV(76, 220),
uvScale = Scale.cube(ResearchTableInventoryTexture.UsageHint.SIZE_WITH_SHADOW_PIXELS)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package elan.tweaks.thaumcraft.research.frontend.integration.table.gui.textures

import elan.tweaks.common.gui.dto.Scale
import elan.tweaks.common.gui.dto.UV
import elan.tweaks.common.gui.textures.ThaumcraftTextureInstance

object UsageHintTexture : ThaumcraftTextureInstance(
"research/table/research-table.png",
textureScale = Scale(width = 342, height = 245),
uv = UV(51, 220),
uvScale = Scale.cube(ResearchTableInventoryTexture.UsageHint.SIZE_WITH_SHADOW_PIXELS)
)
7 changes: 6 additions & 1 deletion src/main/resources/assets/thaumcraft/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ tc.research_page.RESEARCH.6=<IMG>thaumcraft:textures/research/table/research-tab
tc.research_page.RESEARCH.7=the thaumometer beforehand then you might have a significant number of primal and compound aspects listed here.<BR>You can now start combining aspects into more complex compound aspects by simply dragging and dropping or by right clicking while dragging one aspect over the other. If successful you should see what was gained in the bottom right and it should appear in areas §l3§r.<BR>The component aspects are consumed even if the combination did not result in valid compound aspect.
tc.research_page.RESEARCH.8=§l §n(3) Primary Research§r<IMG>thaumcraft:textures/research/table/research-table-tutorial-filled.png:0:0:256:200:.50</IMG>You need to be carrying a set of scribing tools and paper for this step.<BR>If you open your Thaumonomicon you will see all the knowledge have and also all the knowledge that you are now able to pursue.<BR>Flashing square or round icons represent primary researches.
tc.research_page.RESEARCH.9=If you can read their title (instead of seeing strange runes) you are simply able to click on them. Paper and ink will be consumed from your inventory and you will gain a research note. You can now take this research note to the table to start researching it by placing it in slot §l2§r.<BR>Section §l4§r will now display a sheet of paper covered in hexagonal tiles with aspect icons around the outer edge. If you see question mark icons it means you do not know that aspect yet and you will need to learn it first.<LINE>
tc.research_page.RESEARCH.10=To complete your research you simply need to connect and activate all the aspects. You do this by writing an aspect to a hex adjacent to it that is either composed of the target aspect, or can be combined with another aspect to form the target aspect. To write an aspect simply drag and drop or right click while dragging over hex.<IMG>thaumcraft:textures/misc/research3.png:0:0:150:80:.65</IMG>Placing an aspect consumes one research point. If you make a mistake you can click on the aspect to remove it, but you will not regain the research point.
tc.research_page.RESEARCH.10=To complete your research you simply need to connect and activate all the aspects. You do this by writing an aspect to a hex adjacent to it that is either composed of the target aspect, or can be combined with another aspect to form the target aspect. To write an aspect simply drag and drop or right click while dragging over hex.<IMG>thaumcraft:textures/misc/research3.png:0:0:150:80:.65</IMG>Placing an aspect consumes one research point. If you make a mistake you can click on the aspect to remove it, but you will not regain the research point.

# Hint button on the table
researchtable.usagehint.header=How to use
researchtable.usagehint.description=Drag & drop or drag & right-click aspects to draw and combine
researchtable.usagehint.research_expertise=Hold ctrl while combining to make up to 10 aspects. Works with research mastery.

# In case notes get corrupted
tc.research.notes.corrupted.line.1=Notes corrupted!
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.