001package com.fs.starfarer.api.impl.campaign.intel; 002 003import java.awt.Color; 004import java.util.ArrayList; 005import java.util.List; 006 007import com.fs.starfarer.api.ui.LabelAPI; 008import com.fs.starfarer.api.ui.TooltipMakerAPI; 009import com.fs.starfarer.api.util.Misc; 010 011/** 012 * For campaign messages that show up in the lower-left corner, but are not tied to an actual 013 * piece of intel. E.G. "fleet member finished repairs" or "got a monthly income report". 014 * 015 * 016 * 017 * @author Alex Mosolov 018 * 019 * Copyright 2018 Fractal Softworks, LLC 020 */ 021public class MessageIntel extends BaseIntelPlugin { 022 023 public static class MessageLineData { 024 protected String text; 025 protected Color color; 026 protected String [] highlights; 027 protected Color [] colors; 028 public MessageLineData(String text) { 029 this(text, null, null, (Color [])null); 030 } 031 public MessageLineData(String text, Color color) { 032 this(text, color, null, (Color [])null); 033 } 034 public MessageLineData(String text, Color color, String [] highlights, Color ... colors) { 035 this.text = text; 036 this.color = color; 037 this.highlights = highlights; 038 this.colors = colors; 039 } 040 } 041 042// protected String text; 043// protected Color color; 044// protected String [] highlights; 045// protected Color [] colors; 046// 047// protected String text2; 048// protected Color color2; 049// protected String [] highlights2; 050// protected Color [] colors2; 051 052 protected List<MessageLineData> lines = new ArrayList<MessageLineData>(); 053 protected String icon; 054 protected String sound; 055 protected String extra; 056 057 public MessageIntel() { 058 059 } 060 061 public MessageIntel(String text) { 062 this(text, null, null, (Color [])null); 063 } 064 public MessageIntel(String text, Color color) { 065 this(text, color, null, (Color [])null); 066 } 067 public MessageIntel(String text, Color color, String [] highlights, Color ... colors) { 068 addLine(text, color, highlights, colors); 069 } 070 071 public void addLine(String text) { 072 addLine(text, null, null, (Color []) null); 073 } 074 public void addLine(String text, Color color) { 075 addLine(text, color, null, (Color []) null); 076 } 077 public void addLine(String text, Color color, String [] highlights, Color ... colors) { 078 MessageLineData line = new MessageLineData(text, color, highlights, colors); 079 lines.add(line); 080 } 081 082 public void clearLines() { 083 lines.clear(); 084 } 085 086 @Override 087 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) { 088 float pad = 3f; 089 boolean first = true; 090 for (MessageLineData line : lines) { 091 Color c = line.color; 092 if (c == null) { 093 c = Misc.getTextColor(); 094// if (first) { 095// c = Misc.getTextColor(); 096// } else { 097// c = Misc.getGrayColor(); 098// } 099 } 100 101 float currPad = pad; 102 if (first) { 103 currPad = 0f; 104 } 105 106 if (line.highlights != null) { 107 LabelAPI label = info.addPara(line.text, currPad, c, c, line.highlights); 108 label.setHighlight(line.highlights); 109 label.setHighlightColors(line.colors); 110 } else { 111 info.addPara(line.text, c, currPad); 112 } 113 114 115 if (!first) pad = 0f; 116 first = false; 117 } 118 119 } 120 121 public String getIcon() { 122 return icon; 123 } 124 125 public void setIcon(String icon) { 126 this.icon = icon; 127 } 128 129 public String getSound() { 130 return sound; 131 } 132 133 public void setSound(String sound) { 134 this.sound = sound; 135 } 136 137 @Override 138 public String getCommMessageSound() { 139 if (sound != null) { 140 return sound; 141 } 142 return getSoundMinorMessage(); 143 } 144 145 public String getExtra() { 146 return extra; 147 } 148 149 public void setExtra(String extra) { 150 this.extra = extra; 151 } 152 153} 154 155 156 157 158 159 160 161