Skip to content

Commit affc39d

Browse files
committed
Implement the list of user's colonies
1 parent 7554239 commit affc39d

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

src/galaxy.cpp

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@
9898
#define PLANET_LIST_COLONY_X 88
9999
#define PLANET_LIST_OUTPOST_X 18
100100

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+
101112
static const uint8_t starmapHighlightColors[(MAX_PLAYERS + 1) * 3] {
102113
RGB(0xfc0000), RGB(0xd4c418), RGB(0x209c1c), RGB(0xc8c8c8),
103114
RGB(0x305ca0), RGB(0xa47050), RGB(0x8c6098), RGB(0xd0680c),
@@ -1411,7 +1422,9 @@ void GalaxyView::clickGameMenu(int x, int y, int arg) {
14111422
new MainMenuWindow(this, _game);
14121423
}
14131424

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+
}
14151428

14161429
void GalaxyView::clickPlanetsButton(int x, int y, int arg) {
14171430
gui_stack->push(new PlanetsListView(_game, _activePlayer));
@@ -2050,6 +2063,8 @@ void PlanetsListView::highlightSlot(int x, int y, int arg) {
20502063
unsigned pid, sy, w, h, offset = _scroll->position();
20512064
const Planet *ptr;
20522065

2066+
printf("Highlight: %d, %d, %d\n", x, y, arg);
2067+
20532068
if (arg >= 0 && arg < PLANET_LIST_ROWS && offset + arg < _planetCount) {
20542069
_curslot = arg;
20552070
pid = _planets[offset + arg];
@@ -2198,6 +2213,95 @@ void PlanetsListView::clickReturn(int x, int y, int arg) {
21982213
exitView();
21992214
}
22002215

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+
22012305
MainMenuWindow::MainMenuWindow(GuiView *parent, GameState *game) :
22022306
GuiWindow(parent, WINDOW_MODAL), _game(game) {
22032307

src/galaxy.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ class PlanetsListView : public GuiView {
241241
void clickReturn(int x, int y, int arg);
242242
};
243243

244+
class ColoniesListView : public GuiView {
245+
private:
246+
GameState *_game;
247+
ScrollBarWidget *_scroll;
248+
int _curslot;
249+
ImageAsset _bg;
250+
unsigned _colonies[MAX_COLONIES];
251+
252+
void initWidgets(void);
253+
254+
public:
255+
ColoniesListView(GameState *game, int activePlayer);
256+
257+
void highlightSlot(int x, int y, int arg);
258+
void redraw(unsigned curtick);
259+
260+
void showHelp(int x, int y, int arg);
261+
void clickReturn(int x, int y, int arg);
262+
};
263+
244264
class MainMenuWindow : public GuiWindow {
245265
private:
246266
ImageAsset _bg;

src/lang.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
#define HELP_GAMEMENU_SETTINGS 422
128128
#define HELP_GAMEMENU_RETURN 423
129129

130+
#define HELP_RETURN_BUTTON 500
131+
130132
// Main menu
131133
#define HELP_MAINMENU_CONTINUE 645
132134
#define HELP_MAINMENU_LOAD 646

0 commit comments

Comments
 (0)