|
98 | 98 | #define PLANET_LIST_COLONY_X 88 |
99 | 99 | #define PLANET_LIST_OUTPOST_X 18 |
100 | 100 |
|
| 101 | +#define COLONY_ARCHIVE "colsum.lbx" |
| 102 | +#define ASSET_COLONYLIST_BG 0 |
| 103 | +#define ASSET_COLONYLIST_RETURN_BUTTON 1 |
| 104 | + |
| 105 | +#define COLONY_LIST_ROWS 10 |
| 106 | +#define COLONY_LIST_FIRST_ROW 39 |
| 107 | +#define COLONY_LIST_ROW_HEIGHT 26 |
| 108 | +#define COLONY_LIST_ROW_DIST 5 |
| 109 | +#define COLONY_LIST_ROW_LEFT_PADDING 55 |
| 110 | +#define COLONY_LIST_ROW_BOTTOM_PADDING 5 |
| 111 | + |
101 | 112 | static const uint8_t starmapHighlightColors[(MAX_PLAYERS + 1) * 3] { |
102 | 113 | RGB(0xfc0000), RGB(0xd4c418), RGB(0x209c1c), RGB(0xc8c8c8), |
103 | 114 | RGB(0x305ca0), RGB(0xa47050), RGB(0x8c6098), RGB(0xd0680c), |
@@ -1411,7 +1422,9 @@ void GalaxyView::clickGameMenu(int x, int y, int arg) { |
1411 | 1422 | new MainMenuWindow(this, _game); |
1412 | 1423 | } |
1413 | 1424 |
|
1414 | | -void GalaxyView::clickColoniesButton(int x, int y, int arg) STUB(this) |
| 1425 | +void GalaxyView::clickColoniesButton(int x, int y, int arg) { |
| 1426 | + gui_stack->push(new ColoniesListView(_game, _activePlayer)); |
| 1427 | +} |
1415 | 1428 |
|
1416 | 1429 | void GalaxyView::clickPlanetsButton(int x, int y, int arg) { |
1417 | 1430 | gui_stack->push(new PlanetsListView(_game, _activePlayer)); |
@@ -2050,6 +2063,8 @@ void PlanetsListView::highlightSlot(int x, int y, int arg) { |
2050 | 2063 | unsigned pid, sy, w, h, offset = _scroll->position(); |
2051 | 2064 | const Planet *ptr; |
2052 | 2065 |
|
| 2066 | + printf("Highlight: %d, %d, %d\n", x, y, arg); |
| 2067 | + |
2053 | 2068 | if (arg >= 0 && arg < PLANET_LIST_ROWS && offset + arg < _planetCount) { |
2054 | 2069 | _curslot = arg; |
2055 | 2070 | pid = _planets[offset + arg]; |
@@ -2198,6 +2213,95 @@ void PlanetsListView::clickReturn(int x, int y, int arg) { |
2198 | 2213 | exitView(); |
2199 | 2214 | } |
2200 | 2215 |
|
| 2216 | +ColoniesListView::ColoniesListView(GameState *game, int activePlayer) : |
| 2217 | + _game(game), _scroll(NULL) { |
| 2218 | + |
| 2219 | + _bg = gameAssets->getImage(COLONY_ARCHIVE, ASSET_COLONYLIST_BG); |
| 2220 | + |
| 2221 | + initWidgets(); |
| 2222 | +} |
| 2223 | + |
| 2224 | +void ColoniesListView::initWidgets(void) { |
| 2225 | + unsigned i; |
| 2226 | + const uint8_t *pal = _bg->palette(); |
| 2227 | + Widget *w = NULL; |
| 2228 | + |
| 2229 | + for (i = 0; i < COLONY_LIST_ROWS; i++) { |
| 2230 | + w = createWidget(10, |
| 2231 | + COLONY_LIST_FIRST_ROW + i * (COLONY_LIST_ROW_HEIGHT + COLONY_LIST_ROW_BOTTOM_PADDING), |
| 2232 | + 398, |
| 2233 | + COLONY_LIST_ROW_HEIGHT); |
| 2234 | + w->setMouseOverCallback(GuiMethod(*this, |
| 2235 | + &ColoniesListView::highlightSlot, i)); |
| 2236 | + w->setMouseMoveCallback(GuiMethod(*this, |
| 2237 | + &ColoniesListView::highlightSlot, i)); |
| 2238 | + w->setMouseOutCallback(GuiMethod(*this, |
| 2239 | + &ColoniesListView::highlightSlot, -1)); |
| 2240 | + } |
| 2241 | + |
| 2242 | + w = createWidget(531, 445, 156, 25); |
| 2243 | + w->setMouseUpCallback(MBUTTON_LEFT, |
| 2244 | + GuiMethod(*this, &ColoniesListView::clickReturn)); |
| 2245 | + w->setClickSprite(MBUTTON_LEFT, COLONY_ARCHIVE, |
| 2246 | + ASSET_COLONYLIST_RETURN_BUTTON, pal, 1); |
| 2247 | + w->setMouseUpCallback(MBUTTON_RIGHT, |
| 2248 | + GuiMethod(*this, &ColoniesListView::showHelp, |
| 2249 | + HELP_RETURN_BUTTON)); |
| 2250 | +} |
| 2251 | + |
| 2252 | +void ColoniesListView::highlightSlot(int x, int y, int arg) { |
| 2253 | + if (arg >= 0 && arg < COLONY_LIST_ROWS && arg < _game->_colonyCount) { |
| 2254 | + _curslot = arg; |
| 2255 | + } else { |
| 2256 | + _curslot = -1; |
| 2257 | + } |
| 2258 | +} |
| 2259 | + |
| 2260 | +void ColoniesListView::redraw(unsigned curtick) { |
| 2261 | + Font *fnt; |
| 2262 | + // unsigned i, offset = _scroll->position(); |
| 2263 | + unsigned i, j, y, color; |
| 2264 | + int owner; |
| 2265 | + StringBuffer buf; |
| 2266 | + const Planet *planet_ptr; |
| 2267 | + const Star *star_ptr; |
| 2268 | + |
| 2269 | + fnt = gameFonts->getFont(FONTSIZE_SMALL); |
| 2270 | + |
| 2271 | + clearScreen(); |
| 2272 | + _bg->draw(0, 0); |
| 2273 | + |
| 2274 | + unsigned offset = 0; // FIXME: This should come from the scrollbar |
| 2275 | + int colony_row = 0; |
| 2276 | + for (i = 0; i < _game->_planetCount; i++) { |
| 2277 | + y = COLONY_LIST_FIRST_ROW + COLONY_LIST_ROW_DIST + colony_row * (COLONY_LIST_ROW_HEIGHT + COLONY_LIST_ROW_BOTTOM_PADDING); |
| 2278 | + planet_ptr = _game->_planets + offset + i; |
| 2279 | + if (planet_ptr->colony < 0) continue; |
| 2280 | + |
| 2281 | + star_ptr = &_game->_starSystems[planet_ptr->star]; |
| 2282 | + if (_curslot == colony_row) { |
| 2283 | + color = FONT_COLOR_COLONY_LIST_BRIGHT; |
| 2284 | + } else { |
| 2285 | + color = FONT_COLOR_COLONY_LIST; |
| 2286 | + } |
| 2287 | + buf.printf("%s %s", star_ptr->name, |
| 2288 | + romanNumbers[star_ptr->planetSeq(planet_ptr->orbit)]); |
| 2289 | + fnt->centerText(COLONY_LIST_ROW_LEFT_PADDING, y, color, buf.c_str()); |
| 2290 | + colony_row++; |
| 2291 | + } |
| 2292 | + |
| 2293 | + redrawWidgets(0, 0, curtick); |
| 2294 | + redrawWindows(curtick); |
| 2295 | +} |
| 2296 | + |
| 2297 | +void ColoniesListView::clickReturn(int x, int y, int arg) { |
| 2298 | + exitView(); |
| 2299 | +} |
| 2300 | + |
| 2301 | +void ColoniesListView::showHelp(int x, int y, int arg) { |
| 2302 | + new MessageBoxWindow(this, arg, _bg->palette()); |
| 2303 | +} |
| 2304 | + |
2201 | 2305 | MainMenuWindow::MainMenuWindow(GuiView *parent, GameState *game) : |
2202 | 2306 | GuiWindow(parent, WINDOW_MODAL), _game(game) { |
2203 | 2307 |
|
|
0 commit comments