1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import iv
.nanovega
.blendish
;
29 // ////////////////////////////////////////////////////////////////////////// //
30 __gshared Galaxy universe
;
33 // ////////////////////////////////////////////////////////////////////////// //
34 final class PlanetInfoBillboard
{
37 float[] lineH
; // line height
45 float[3] mtblW
= 0; // market widthes
47 float billH
= 0, billW
= 0;
51 this (NVGContext avg
, ref Galaxy
.Planet p
) {
54 scope(exit
) vg
= null;
55 vg
.fontFaceId(galmapFont
);
56 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Baseline
);
57 vg
.fontSize(fGalMapSize
);
58 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
62 void draw (NVGContext avg
, float mx
=10, float my
=10) {
63 if (avg
is null) return;
65 scope(exit
) vg
= null;
68 scope(exit
) vg
.restore
;
70 auto obfn
= bndGetFont();
71 scope(exit
) bndSetFont(obfn
);
77 vg
.fontFaceId(uiFont
);
78 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
82 adv
= vg
.textBounds(0, 0, "Woo", b
[]);
83 conwriteln("adv=", adv
, "; b=", b
[]);
86 bndSetFont(galmapFont
);
87 vg
.fontFaceId(galmapFont
);
88 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Baseline
);
89 vg
.fontSize(fGalMapSize
);
91 vg
.bndMenuBackground(mx
, my
, billW
+8, billH
+8, BND_CORNER_NONE
);
95 foreach (immutable idx
; 0..lines
.length
) {
97 vg
.fillColor(nvgRGBA(255, 255, 255));
98 vg
.textAlign(NVGTextAlign
.H
.Right
, NVGTextAlign
.V
.Top
);
100 vg
.text(x
, y
, lines
[idx
][0]);
102 vg
.fillColor(nvgRGBA(255, 255, 0));
103 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
104 vg
.text(x
, y
, lines
[idx
][1]);
108 vg
.fillColor(nvgRGBA(255, 127, 0));
109 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
111 vg
.text(mx
+4, y
, pdsc
);
114 vg
.fillColor(nvgRGBA(255, 255, 255));
115 foreach (immutable idx
; 0..market
.length
) {
117 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
118 vg
.text(x
, y
, market
[idx
][0]);
119 x
+= mtblW
[0]+8+mtblW
[1];
120 vg
.textAlign(NVGTextAlign
.H
.Right
, NVGTextAlign
.V
.Top
);
121 vg
.text(x
, y
, market
[idx
][1]);
123 vg
.text(x
, y
, market
[idx
][2]);
124 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Top
);
126 vg
.text(x
, y
, Galaxy
.good(idx
).unitName
);
133 void putf(A
...) (string label
, string fmt
, in A args
) {
134 import std
.algorithm
: max
;
135 import std
.string
: format
;
136 auto s
= format(fmt
, args
);
138 lines
[$-1][0] = label
;
142 vg
.textBounds(0, 0, label
, b
[]);
143 float hh
= b
[3]-b
[1];
144 float ww
= b
[2]-b
[0];
145 ltblW
[0] = max(ltblW
[0], ww
);
147 vg
.textBounds(0, 0, s
, b
[]);
148 hh
= max(hh
, b
[3]-b
[1]);
150 ltblW
[1] = max(ltblW
[1], ww
);
154 billW
= max(billW
, ltblW
[0]+4+ltblW
[1]);
157 void putd (string dsc
) {
158 import std
.algorithm
: max
;
161 vg
.textBounds(0, 0, dsc
, b
[]);
162 float hh
= b
[3]-b
[1];
163 float ww
= b
[2]-b
[0];
167 billW
= max(billW
, ww
);
170 void putm(T
: ulong) (in ref Galaxy
.Planet p
, T idx
) {
171 import std
.algorithm
: max
;
172 import std
.string
: format
;
173 if (idx
< 0 || idx
> Galaxy
.Goods
.max
) return;
174 auto good
= Galaxy
.good(idx
);
176 market
[$-1][0] = good
.name
;
177 market
[$-1][1] = "%s.%s".format(p
.price
[idx
]/10, p
.price
[idx
]%10);
178 market
[$-1][2] = "%s".format(p
.quantity
[idx
]);
180 float hh
= 0, wt
= 8*2;
181 foreach (immutable n
, string s
; market
[$-1]) {
182 vg
.textBounds(0, 0, s
, b
[]);
183 hh
= max(hh
, b
[3]-b
[1]);
184 mtblW
[n
] = max(mtblW
[n
], b
[2]-b
[0]);
187 vg
.textBounds(0, 0, "kg", b
[]);
188 hh
= max(hh
, b
[3]-b
[1]);
192 billW
= max(billW
, wt
);
195 void buildPlanetData (ref Galaxy
.Planet p
) {
196 putf("System:", "%s", p
.name
);
197 putf("Position:", "(%s,%s)", p
.x
, p
.y
);
198 putf("Economy:", "%s", p
.economyName
);
199 putf("Government:", "%s", p
.govName
);
200 putf("Tech Level:", "%s", p
.techlev
+1);
201 putf("Turnover:", "%s", p
.productivity
);
202 putf("Radius:", "%s", p
.radius
);
203 putf("Population:", "%s.%s Billion", p
.population
/10, p
.population
%10);
206 foreach (immutable idx
; 0..Galaxy
.Goods
.max
+1) putm(p
, idx
);
210 a
= vg
.textBounds(0, 0, "m", b
[]);
211 conwriteln(a
, " : ", b
[]);
212 a
= vg
.textBounds(0, 0, "o", b
[]);
213 conwriteln(a
, " : ", b
[]);
214 a
= vg
.textBounds(0, 0, "mo", b
[]);
215 conwriteln(a
, " : ", b
[]);
216 debug(nanovg_fons_kern_test
) NVGKTT(vg
);
222 // ////////////////////////////////////////////////////////////////////////// //
223 __gshared
ulong lastGalSeed
= 0;
224 __gshared
ubyte lastPlanetNum
= 0;
225 __gshared PlanetInfoBillboard planetBill
;
228 void drawGalaxy (NVGContext vg
) {
229 if (vg
is null) return;
231 if (planetBill
is null || lastGalSeed
!= universe
.galSeed || lastPlanetNum
!= universe
.currPlanet
.number
) {
232 lastGalSeed
= universe
.galSeed
;
233 lastPlanetNum
= universe
.currPlanet
.number
;
235 planetBill
= new PlanetInfoBillboard(vg
, universe
.currPlanet
);
239 scope(exit
) vg
.restore
;
242 vg
.fontFaceId(uiFont
);
243 vg
.textAlign(NVGTextAlign
.H
.Left
, NVGTextAlign
.V
.Baseline
);
244 vg
.fontSize(fsizeUI
);
246 //vg.beginFrame(GWidth, GHeight, 1);
247 //vg.scissor(0, 0, GWidth, GHeight);
248 //vg.resetTransform();
250 //vg.translate((GWidth-256*2-8)/2, (GHeight-256*2-8)/2);
252 float mx
= (GWidth
-256*2-8)/2.0;
253 float my
= (GHeight
-256*2-8)/1.0-8;
255 vg
.bndMenuBackground(mx
, my
, 256*2+8, 256*2+8, BND_CORNER_NONE
);
258 vg
.fillColor(nvgRGBA(255, 255, 255));
259 foreach (const ref p
; universe
.planets
) {
260 vg
.circle(mx
+p
.x
*2+4, my
+p
.y
*2+4, 1);
265 vg
.strokeColor(nvgRGBA(255, 255, 0));
266 vg
.circle(mx
+universe
.currPlanet
.x
*2+4, my
+universe
.currPlanet
.y
*2+4, 4);