Starsector API
Loading...
Searching...
No Matches
CodexCustomEntryExample.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.codex;
2
3import java.util.List;
4
5import java.awt.Color;
6
7import org.lwjgl.opengl.GL11;
8
9import com.fs.starfarer.api.campaign.CustomUIPanelPlugin;
10import com.fs.starfarer.api.input.InputEventAPI;
11import com.fs.starfarer.api.ui.CustomPanelAPI;
12import com.fs.starfarer.api.ui.PositionAPI;
13import com.fs.starfarer.api.ui.TooltipMakerAPI;
14import com.fs.starfarer.api.ui.UIPanelAPI;
15import com.fs.starfarer.api.util.Misc;
16
18
21 protected UIPanelAPI box;
23
24 public CodexCustomEntryExample(String id, String title, String icon) {
25 super(id, title, icon);
26 }
27
28 @Override
29 public void createTitleForList(TooltipMakerAPI info, float width, ListMode mode) {
30 super.createTitleForList(info, width, mode);
31 }
32
33 @Override
34 public boolean hasCustomDetailPanel() {
35 return true;
36 }
37
38 @Override
40 return this;
41 }
42
43 @Override
44 public void destroyCustomDetail() {
45 panel = null;
46 relatedEntries = null;
47 box = null;
48 codex = null;
49 }
50
51 @Override
53 this.panel = panel;
54 this.relatedEntries = relatedEntries;
55 this.codex = codex;
56
57 Color color = Misc.getBasePlayerColor();
58 Color dark = Misc.getDarkPlayerColor();
59 Color h = Misc.getHighlightColor();
60 Color g = Misc.getGrayColor();
61 float opad = 10f;
62 float pad = 3f;
63 float small = 5f;
64
65 float width = panel.getPosition().getWidth();
66
67 float initPad = 0f;
68
69 float horzBoxPad = 30f;
70
71 // the right width for a tooltip wrapped in a box to fit next to relatedEntries
72 // 290 is the width of the related entries widget, but it may be null
73 float tw = width - 290f - opad - horzBoxPad + 10f;
74
75 TooltipMakerAPI text = panel.createUIElement(tw, 0, false);
77
78 String design = "Cicero";
79 if (design != null && !design.toLowerCase().equals("common")) {
80 text.setParaFontDefault();
81 Misc.addDesignTypePara(text, design, initPad);
83 initPad = opad;
84 }
85
86 text.addPara("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt "
87 + "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
88 + "ullamco laboris nisi ut aliquip ex ea commodo consequat.", initPad);
89
90 // add a bunch of paragraphs so that it requires a scroller
91 for (int i = 0; i < 10; i++) {
92 text.addPara("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat "
93 + "nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia "
94 + "deserunt mollit anim id est laborum.", opad);
95 }
96
98
100 panel.addComponent(box).inTL(0f, 0f);
101 if (relatedEntries != null) {
103 }
104
105 float height = box.getPosition().getHeight();
106 if (relatedEntries != null) {
107 height = Math.max(height, relatedEntries.getPosition().getHeight());
108 }
109 panel.getPosition().setSize(width, height);
110 }
111
112 @Override
113 public void positionChanged(PositionAPI position) {
114
115 }
116
117 @Override
118 public void renderBelow(float alphaMult) {
119 // just rendering something to show how one might do it
121 float x = p.getX();
122 float y = p.getY();
123 float w = p.getWidth();
124 float h = p.getHeight();
125 Color color = Misc.getDarkPlayerColor();
126 GL11.glDisable(GL11.GL_TEXTURE_2D);
127 GL11.glEnable(GL11.GL_BLEND);
128 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
129 Misc.renderQuad(x, y - 110f, w, 100f, color, alphaMult);
130 }
131
132 @Override
133 public void render(float alphaMult) {
134
135 }
136
137 @Override
138 public void advance(float amount) {
139
140 }
141
142 @Override
143 public void processInput(List<InputEventAPI> events) {
144
145 }
146
147 @Override
148 public void buttonPressed(Object buttonId) {
149
150 }
151
152
153
154}
void createCustomDetail(CustomPanelAPI panel, UIPanelAPI relatedEntries, CodexDialogAPI codex)
void createTitleForList(TooltipMakerAPI info, float width, ListMode mode)
static void renderQuad(float x, float y, float width, float height, Color color, float alphaMult)
Definition Misc.java:1842
static Color getBasePlayerColor()
Definition Misc.java:833
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
static LabelAPI addDesignTypePara(TooltipMakerAPI tooltip, String design, float pad)
Definition Misc.java:4946
static Color getDarkPlayerColor()
Definition Misc.java:836
TooltipMakerAPI createUIElement(float width, float height, boolean withScroller)
void updateUIElementSizeAndMakeItProcessInput(TooltipMakerAPI element)
UIPanelAPI wrapTooltipWithBox(TooltipMakerAPI tooltip)
PositionAPI inTL(float xPad, float yPad)
PositionAPI setSize(float width, float height)
PositionAPI inTR(float xPad, float yPad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
PositionAPI addComponent(UIComponentAPI custom)