added being able to create a host on the game server now need to work on joining that game
This commit is contained in:
114
options.c
114
options.c
@@ -2,14 +2,124 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <mydebug.h>
|
||||
#include <game.h>
|
||||
#include <input.h>
|
||||
#include <deck.h>
|
||||
#include <main.h>
|
||||
#include <options.h>
|
||||
|
||||
void show_options(){
|
||||
running = 0;
|
||||
#define SPACING 20
|
||||
|
||||
struct options_ctx
|
||||
{
|
||||
int selected_opt;
|
||||
char option_strings[NUM_OPTIONS][MAX_NAMESZ];
|
||||
TTF_Font* font;
|
||||
SDL_Surface *gameplay_surface, *video_surface, *audio_surface,
|
||||
*mainmenu_surface, *exit_surface;
|
||||
SDL_Texture *gameplay_tex, *video_tex, *audio_tex, *mainmenu_tex, *exit_tex;
|
||||
SDL_Rect options_rects[NUM_OPTIONS];
|
||||
SDL_Rect options_boxs[NUM_OPTIONS];
|
||||
SDL_Texture *string_texs[NUM_OPTIONS];
|
||||
};
|
||||
|
||||
struct options_ctx opt;
|
||||
|
||||
int get_sel_opt()
|
||||
{
|
||||
return opt.selected_opt;
|
||||
}
|
||||
|
||||
void set_sel_opt(int i)
|
||||
{
|
||||
opt.selected_opt = i;
|
||||
return;
|
||||
}
|
||||
|
||||
void init_options()
|
||||
{
|
||||
int i;
|
||||
|
||||
opt.selected_opt = GP_OPT_SEL;
|
||||
|
||||
strcpy(opt.option_strings[0], "GAMEPLAY");
|
||||
strcpy(opt.option_strings[1], "VIDEO");
|
||||
strcpy(opt.option_strings[2], "AUDIO");
|
||||
strcpy(opt.option_strings[3], "MAIN MENU");
|
||||
strcpy(opt.option_strings[4], "EXIT GAME");
|
||||
|
||||
opt.font = TTF_OpenFont("assets/font.ttf", 24);
|
||||
|
||||
opt.gameplay_surface = TTF_RenderText_Solid(opt.font, opt.option_strings[0], white);
|
||||
opt.gameplay_tex = SDL_CreateTextureFromSurface(renderer, opt.gameplay_surface);
|
||||
opt.video_surface = TTF_RenderText_Solid(opt.font, opt.option_strings[1], white);
|
||||
opt.video_tex = SDL_CreateTextureFromSurface(renderer, opt.video_surface);
|
||||
opt.audio_surface = TTF_RenderText_Solid(opt.font, opt.option_strings[2], white);
|
||||
opt.audio_tex = SDL_CreateTextureFromSurface(renderer, opt.audio_surface);
|
||||
opt.mainmenu_surface = TTF_RenderText_Solid(opt.font, opt.option_strings[3], white);
|
||||
opt.mainmenu_tex = SDL_CreateTextureFromSurface(renderer, opt.mainmenu_surface);
|
||||
opt.exit_surface = TTF_RenderText_Solid(opt.font, opt.option_strings[4], white);
|
||||
opt.exit_tex = SDL_CreateTextureFromSurface(renderer, opt.exit_surface);
|
||||
|
||||
opt.string_texs[0] = opt.gameplay_tex;
|
||||
opt.string_texs[1] = opt.video_tex;
|
||||
opt.string_texs[2] = opt.audio_tex;
|
||||
opt.string_texs[3] = opt.mainmenu_tex;
|
||||
opt.string_texs[4] = opt.exit_tex;
|
||||
|
||||
|
||||
opt.options_boxs[0].w = (DEF_WINDOW_WIDTH >> 2) + (DEF_WINDOW_WIDTH >> 3) ;
|
||||
opt.options_boxs[0].x = (DEF_WINDOW_WIDTH >> 1) - (opt.options_boxs[0].w >> 1);
|
||||
opt.options_boxs[0].y = SPACING << 3;
|
||||
opt.options_boxs[0].h = (DEF_WINDOW_HEIGHT >> 3);
|
||||
|
||||
opt.options_rects[0].w = ((opt.options_boxs[0].w - (SPACING << 1)) / 9) * strlen(opt.option_strings[0]);
|
||||
opt.options_rects[0].h = opt.options_boxs[0].h - (SPACING << 1);
|
||||
opt.options_rects[0].y = opt.options_boxs[0].y + SPACING;
|
||||
opt.options_rects[0].x = opt.options_boxs[0].x + SPACING;
|
||||
|
||||
for(i = 1; i < NUM_OPTIONS; ++i)
|
||||
{
|
||||
opt.options_boxs[i].w = opt.options_boxs[0].w;
|
||||
opt.options_boxs[i].x = opt.options_boxs[0].x;
|
||||
opt.options_boxs[i].h = opt.options_boxs[0].h;
|
||||
opt.options_boxs[i].y = opt.options_boxs[i-1].y + SPACING + opt.options_boxs[i].h;
|
||||
|
||||
opt.options_rects[i].w = ((opt.options_boxs[0].w - (SPACING << 1)) / 9) * strlen(opt.option_strings[i]);
|
||||
opt.options_rects[i].h = opt.options_rects[0].h;
|
||||
opt.options_rects[i].y = opt.options_boxs[i].y + SPACING;
|
||||
opt.options_rects[i].x = opt.options_boxs[i].x + SPACING;
|
||||
}
|
||||
|
||||
PRINT_M(INIT OPTIONS)
|
||||
return;
|
||||
}
|
||||
|
||||
void opt_render_selected()
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 32, 64, 32, 255);
|
||||
SDL_RenderFillRect(renderer, &opt.options_boxs[opt.selected_opt]);
|
||||
SDL_RenderCopy(renderer, opt.string_texs[opt.selected_opt], NULL, &opt.options_rects[opt.selected_opt]);
|
||||
}
|
||||
void render_options()
|
||||
{
|
||||
int i;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
//render grey boxs for options
|
||||
SDL_SetRenderDrawColor(renderer, 64, 64, 64, 255);
|
||||
for(i = 0; i < NUM_OPTIONS; i++)
|
||||
{
|
||||
SDL_RenderFillRect(renderer, &opt.options_boxs[i]);
|
||||
SDL_RenderCopy(renderer, opt.string_texs[i], NULL, &opt.options_rects[i]);
|
||||
}
|
||||
opt_render_selected();
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user