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/>.
20 import iv
.nanovg
.oui
.blendish
;
28 // ////////////////////////////////////////////////////////////////////////// //
29 __gshared Galaxy universe
;
32 // ////////////////////////////////////////////////////////////////////////// //
33 final class PlanetInfoBillboard
{
36 float[] lineH
; // line height
44 float[3] mtblW
= 0; // market widthes
46 float billH
= 0, billW
= 0;
50 this (NVGContext avg
, ref Galaxy
.Planet p
) {
53 scope(exit
) vg
= null;
54 vg
.fontFaceId(galmapFont
);
55 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Baseline
);
56 vg
.fontSize(fGalMapSize
);
57 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
61 void draw (NVGContext avg
, float mx
=10, float my
=10) {
62 if (avg
is null) return;
64 scope(exit
) vg
= null;
67 scope(exit
) vg
.restore
;
69 auto obfn
= bndGetFont();
70 scope(exit
) bndSetFont(obfn
);
76 vg
.fontFaceId(uiFont
);
77 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
81 adv
= vg
.textBounds(0, 0, "Woo", b
[]);
82 { import std
.stdio
; writeln("adv=", adv
, "; b=", b
[]); }
85 bndSetFont(galmapFont
);
86 vg
.fontFaceId(galmapFont
);
87 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Baseline
);
88 vg
.fontSize(fGalMapSize
);
90 vg
.bndMenuBackground(mx
, my
, billW
+8, billH
+8, BND_CORNER_NONE
);
94 foreach (immutable idx
; 0..lines
.length
) {
96 vg
.fillColor(nvgRGBA(255, 255, 255));
97 vg
.textAlign(NVGAlign
.Right|NVGAlign
.Top
);
99 vg
.text(x
, y
, lines
[idx
][0]);
101 vg
.fillColor(nvgRGBA(255, 255, 0));
102 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
103 vg
.text(x
, y
, lines
[idx
][1]);
107 vg
.fillColor(nvgRGBA(255, 127, 0));
108 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
110 vg
.text(mx
+4, y
, pdsc
);
113 vg
.fillColor(nvgRGBA(255, 255, 255));
114 foreach (immutable idx
; 0..market
.length
) {
116 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
117 vg
.text(x
, y
, market
[idx
][0]);
118 x
+= mtblW
[0]+8+mtblW
[1];
119 vg
.textAlign(NVGAlign
.Right|NVGAlign
.Top
);
120 vg
.text(x
, y
, market
[idx
][1]);
122 vg
.text(x
, y
, market
[idx
][2]);
123 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Top
);
125 vg
.text(x
, y
, Galaxy
.good(idx
).unitName
);
132 void putf(A
...) (string label
, string fmt
, in A args
) {
133 import std
.algorithm
: max
;
134 import std
.string
: format
;
135 auto s
= format(fmt
, args
);
137 lines
[$-1][0] = label
;
141 vg
.textBounds(0, 0, label
, b
[]);
142 float hh
= b
[3]-b
[1];
143 float ww
= b
[2]-b
[0];
144 ltblW
[0] = max(ltblW
[0], ww
);
146 vg
.textBounds(0, 0, s
, b
[]);
147 hh
= max(hh
, b
[3]-b
[1]);
149 ltblW
[1] = max(ltblW
[1], ww
);
153 billW
= max(billW
, ltblW
[0]+4+ltblW
[1]);
156 void putd (string dsc
) {
157 import std
.algorithm
: max
;
160 vg
.textBounds(0, 0, dsc
, b
[]);
161 float hh
= b
[3]-b
[1];
162 float ww
= b
[2]-b
[0];
166 billW
= max(billW
, ww
);
169 void putm(T
: ulong) (in ref Galaxy
.Planet p
, T idx
) {
170 import std
.algorithm
: max
;
171 import std
.string
: format
;
172 if (idx
< 0 || idx
> Galaxy
.Goods
.max
) return;
173 auto good
= Galaxy
.good(idx
);
175 market
[$-1][0] = good
.name
;
176 market
[$-1][1] = "%s.%s".format(p
.price
[idx
]/10, p
.price
[idx
]%10);
177 market
[$-1][2] = "%s".format(p
.quantity
[idx
]);
179 float hh
= 0, wt
= 8*2;
180 foreach (immutable n
, string s
; market
[$-1]) {
181 vg
.textBounds(0, 0, s
, b
[]);
182 hh
= max(hh
, b
[3]-b
[1]);
183 mtblW
[n
] = max(mtblW
[n
], b
[2]-b
[0]);
186 vg
.textBounds(0, 0, "kg", b
[]);
187 hh
= max(hh
, b
[3]-b
[1]);
191 billW
= max(billW
, wt
);
194 void buildPlanetData (ref Galaxy
.Planet p
) {
195 putf("System:", "%s", p
.name
);
196 putf("Position:", "(%s,%s)", p
.x
, p
.y
);
197 putf("Economy:", "%s", p
.economyName
);
198 putf("Government:", "%s", p
.govName
);
199 putf("Tech Level:", "%s", p
.techlev
+1);
200 putf("Turnover:", "%s", p
.productivity
);
201 putf("Radius:", "%s", p
.radius
);
202 putf("Population:", "%s.%s Billion", p
.population
/10, p
.population
%10);
205 foreach (immutable idx
; 0..Galaxy
.Goods
.max
+1) putm(p
, idx
);
209 a
= vg
.textBounds(0, 0, "m", b
[]);
210 writeln(a
, " : ", b
[]);
211 a
= vg
.textBounds(0, 0, "o", b
[]);
212 writeln(a
, " : ", b
[]);
213 a
= vg
.textBounds(0, 0, "mo", b
[]);
214 writeln(a
, " : ", b
[]);
215 debug(nanovg_fons_kern_test
) NVGKTT(vg
);
221 // ////////////////////////////////////////////////////////////////////////// //
222 __gshared
ulong lastGalSeed
= 0;
223 __gshared
ubyte lastPlanetNum
= 0;
224 __gshared PlanetInfoBillboard planetBill
;
227 void drawGalaxy (NVGContext vg
) {
228 if (vg
is null) return;
230 if (planetBill
is null || lastGalSeed
!= universe
.galSeed || lastPlanetNum
!= universe
.currPlanet
.number
) {
231 lastGalSeed
= universe
.galSeed
;
232 lastPlanetNum
= universe
.currPlanet
.number
;
234 planetBill
= new PlanetInfoBillboard(vg
, universe
.currPlanet
);
238 scope(exit
) vg
.restore
;
241 vg
.fontFaceId(uiFont
);
242 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Baseline
);
243 vg
.fontSize(fsizeUI
);
245 //vg.beginFrame(GWidth, GHeight, 1);
246 //vg.scissor(0, 0, GWidth, GHeight);
247 //vg.resetTransform();
249 //vg.translate((GWidth-256*2-8)/2, (GHeight-256*2-8)/2);
251 float mx
= (GWidth
-256*2-8)/2.0;
252 float my
= (GHeight
-256*2-8)/1.0-8;
254 vg
.bndMenuBackground(mx
, my
, 256*2+8, 256*2+8, BND_CORNER_NONE
);
257 vg
.fillColor(nvgRGBA(255, 255, 255));
258 foreach (const ref p
; universe
.planets
) {
259 vg
.circle(mx
+p
.x
*2+4, my
+p
.y
*2+4, 1);
264 vg
.strokeColor(nvgRGBA(255, 255, 0));
265 vg
.circle(mx
+universe
.currPlanet
.x
*2+4, my
+universe
.currPlanet
.y
*2+4, 4);