001package com.fs.starfarer.api.impl.codex; 002 003import java.util.List; 004 005import java.awt.Color; 006 007import org.lwjgl.opengl.GL11; 008 009import com.fs.starfarer.api.campaign.CustomUIPanelPlugin; 010import com.fs.starfarer.api.input.InputEventAPI; 011import com.fs.starfarer.api.ui.CustomPanelAPI; 012import com.fs.starfarer.api.ui.PositionAPI; 013import com.fs.starfarer.api.ui.TooltipMakerAPI; 014import com.fs.starfarer.api.ui.UIPanelAPI; 015import com.fs.starfarer.api.util.Misc; 016 017public class CodexCustomEntryExample extends CodexEntryV2 implements CustomUIPanelPlugin { 018 019 protected CustomPanelAPI panel; 020 protected UIPanelAPI relatedEntries; 021 protected UIPanelAPI box; 022 protected CodexDialogAPI codex; 023 024 public CodexCustomEntryExample(String id, String title, String icon) { 025 super(id, title, icon); 026 } 027 028 @Override 029 public void createTitleForList(TooltipMakerAPI info, float width, ListMode mode) { 030 super.createTitleForList(info, width, mode); 031 } 032 033 @Override 034 public boolean hasCustomDetailPanel() { 035 return true; 036 } 037 038 @Override 039 public CustomUIPanelPlugin getCustomPanelPlugin() { 040 return this; 041 } 042 043 @Override 044 public void destroyCustomDetail() { 045 panel = null; 046 relatedEntries = null; 047 box = null; 048 codex = null; 049 } 050 051 @Override 052 public void createCustomDetail(CustomPanelAPI panel, UIPanelAPI relatedEntries, CodexDialogAPI codex) { 053 this.panel = panel; 054 this.relatedEntries = relatedEntries; 055 this.codex = codex; 056 057 Color color = Misc.getBasePlayerColor(); 058 Color dark = Misc.getDarkPlayerColor(); 059 Color h = Misc.getHighlightColor(); 060 Color g = Misc.getGrayColor(); 061 float opad = 10f; 062 float pad = 3f; 063 float small = 5f; 064 065 float width = panel.getPosition().getWidth(); 066 067 float initPad = 0f; 068 069 float horzBoxPad = 30f; 070 071 // the right width for a tooltip wrapped in a box to fit next to relatedEntries 072 // 290 is the width of the related entries widget, but it may be null 073 float tw = width - 290f - opad - horzBoxPad + 10f; 074 075 TooltipMakerAPI text = panel.createUIElement(tw, 0, false); 076 text.setParaSmallInsignia(); 077 078 String design = "Cicero"; 079 if (design != null && !design.toLowerCase().equals("common")) { 080 text.setParaFontDefault(); 081 Misc.addDesignTypePara(text, design, initPad); 082 text.setParaSmallInsignia(); 083 initPad = opad; 084 } 085 086 text.addPara("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt " 087 + "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation " 088 + "ullamco laboris nisi ut aliquip ex ea commodo consequat.", initPad); 089 090 // add a bunch of paragraphs so that it requires a scroller 091 for (int i = 0; i < 10; i++) { 092 text.addPara("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat " 093 + "nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia " 094 + "deserunt mollit anim id est laborum.", opad); 095 } 096 097 panel.updateUIElementSizeAndMakeItProcessInput(text); 098 099 box = panel.wrapTooltipWithBox(text); 100 panel.addComponent(box).inTL(0f, 0f); 101 if (relatedEntries != null) { 102 panel.addComponent(relatedEntries).inTR(0f, 0f); 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 120 PositionAPI p = relatedEntries.getPosition(); 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}