Added some rudimentary UI related stuff: ui.png with the first 32x32 section being a hotbar item; uiDraw(), which draws hotbar_count(value to be controlled by amount of items w/ slots the player has (e.g., belt, slotted glove, etc.)) amount of hotbar item images at partial translucency. Also added hitting 'i' to switch to/draw the inventoryContext - at the moment, it does nothing more than cause an SDL_Rect to be drawn and switch to inventoryContext (which does nothing in itself).
parent
639d4b9fcb
commit
0c24fedfb2
14
context.c
14
context.c
|
@ -88,6 +88,10 @@ void walkContext(int key_press) {
|
|||
current_context = &lookContext;
|
||||
interfacePrint("Look where?");
|
||||
break;
|
||||
case 'i':
|
||||
current_context = &inventoryContext;
|
||||
interfacePrint("You check out your sack.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,3 +153,13 @@ void activateContext(int key_press) {
|
|||
}
|
||||
current_context = &walkContext;
|
||||
}
|
||||
|
||||
void inventoryContext(int key_press) {
|
||||
switch (key_press) {
|
||||
case KEY_ESC:
|
||||
case 'q':
|
||||
interfacePrint("That's enough of that...");
|
||||
current_context = &walkContext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,5 @@ void consoleContext(int key_press);
|
|||
void walkContext(int key_press);
|
||||
void lookContext(int key_press);
|
||||
void activateContext(int key_press);
|
||||
void inventoryContext(int key_press);
|
||||
#endif
|
||||
|
|
|
@ -225,11 +225,11 @@ int interfaceInit() {
|
|||
if (interfaceVideoSet())
|
||||
return ERROR;
|
||||
// FIXME: this should be handled differently, but we need to set the window width/height to the surface's reported width/height, as some window managers will resize the SDL window.
|
||||
SDL_Delay(100);
|
||||
video_width = (SDL_GetVideoSurface())->w;
|
||||
video_height = (SDL_GetVideoSurface())->h;
|
||||
if (interfaceVideoSet())
|
||||
return ERROR;
|
||||
|
||||
SDL_WM_SetCaption(NAME, NULL);
|
||||
|
||||
consoleAddCommand("quit", interfaceQuit);
|
||||
|
@ -240,6 +240,7 @@ int interfaceInit() {
|
|||
/* tile specific stuff */
|
||||
/* load our surfaces from memory */
|
||||
font_spritesheet = IMG_Load_RW(SDL_RWFromMem(&font_images, font_images_length), 1);
|
||||
ui_spritesheet = IMG_Load_RW(SDL_RWFromMem(&ui_images, ui_images_length), 1);
|
||||
player_spritesheet = IMG_Load_RW(SDL_RWFromMem(&player_images, player_images_length), 1);
|
||||
npc_spritesheet = IMG_Load_RW(SDL_RWFromMem(&npc_images, npc_images_length), 1);
|
||||
wall_spritesheet = IMG_Load_RW(SDL_RWFromMem(&wall_images, wall_images_length), 1);
|
||||
|
@ -328,6 +329,22 @@ void cameraDraw() {
|
|||
interfaceDrawString(test, screen->w-strlen(test)*g_tile_width, 0);
|
||||
}
|
||||
|
||||
void uiDraw() {
|
||||
int hotbar_count = 4;
|
||||
// TODO: move the next line to a uiSetAlpha function (so user can customize).
|
||||
// TODO: create a Surface in interfaceInit() and simply blit that here.
|
||||
SDL_SetAlpha(ui_spritesheet, SDL_SRCALPHA, 200);
|
||||
SDL_Rect hotbar_item_rect = { 0, 0, 32, 32 };
|
||||
int hotbar_width = hotbar_count*32;
|
||||
int hotbar_height = 32;
|
||||
int i = 0;
|
||||
while (i < hotbar_count) {
|
||||
SDL_Rect hotbar_target_rect = {(screen->w/2 - hotbar_width/2)+i*32, screen->h-hotbar_height, (screen->w/2 - hotbar_width/2)+32+i*32, screen->h};
|
||||
SDL_BlitSurface(ui_spritesheet, &hotbar_item_rect, screen, &hotbar_target_rect);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int interfaceLoop() {
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch(event.type) {
|
||||
|
@ -398,12 +415,24 @@ void interfaceDraw() {
|
|||
// TODO: instead of redrawing whole screen, redraw last positions of tiles
|
||||
//SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
cameraDraw(); // draw our current view
|
||||
uiDraw();
|
||||
if (current_context == &consoleContext) {
|
||||
interfaceDrawConsole();
|
||||
} else if (current_context == &inventoryContext) {
|
||||
interfaceDrawInventory();
|
||||
}
|
||||
SDL_Flip(screen); // redraw!
|
||||
}
|
||||
|
||||
void interfaceDrawInventory() {
|
||||
SDL_Surface *new_surface = SDL_CreateRGBSurface(screen->flags, (screen->w/6), screen->h/2, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
|
||||
SDL_Rect render_area = { screen->w-(screen->w/6), screen->h/8, screen->w/6, screen->h/2 };
|
||||
SDL_FillRect(new_surface, NULL, SDL_MapRGB(new_surface->format, 196, 164, 64));
|
||||
SDL_SetAlpha(new_surface, SDL_SRCALPHA, 128);
|
||||
SDL_BlitSurface(new_surface, NULL, screen, &render_area);
|
||||
SDL_FreeSurface(new_surface);
|
||||
}
|
||||
|
||||
void interfaceDrawConsole() {
|
||||
int line;
|
||||
struct ConsoleEntry *entry;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
SDL_Surface* screen;
|
||||
SDL_Surface* font_spritesheet;
|
||||
SDL_Surface* ui_spritesheet;
|
||||
SDL_Surface* player_spritesheet;
|
||||
SDL_Surface* npc_spritesheet;
|
||||
SDL_Surface* shadow_spritesheet;
|
||||
|
@ -38,6 +39,8 @@ float g_tile_height;
|
|||
|
||||
void interfaceSetScale(float scale_x, float scale_y);
|
||||
|
||||
void uiDraw();
|
||||
|
||||
void interfaceDrawString(const char *string, int start_x, int start_y);
|
||||
void interfaceDrawChar(char ch, int start_x, int start_y);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ int main(int argc, char **argv) {
|
|||
fprintf(tiles_h, "#define TILE_WIDTH 16\n#define TILE_HEIGHT 32\n");
|
||||
|
||||
convert("tiles/font.png", "font_images");
|
||||
convert("tiles/ui.png", "ui_images");
|
||||
convert("tiles/players.png", "player_images");
|
||||
convert("tiles/npcs.png", "npc_images");
|
||||
convert("tiles/walls.png", "wall_images");
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -6,6 +6,9 @@
|
|||
extern unsigned char font_images[];
|
||||
extern unsigned int font_images_length;
|
||||
|
||||
extern unsigned char ui_images[];
|
||||
extern unsigned int ui_images_length;
|
||||
|
||||
extern unsigned char player_images[];
|
||||
extern unsigned int player_images_length;
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue