=== Overview ===
[xuni.git] / src / test / game.c
blob682cdca1933f8c10088ad37a677805c3f5d55a2a
1 /*! \file game.c
3 */
5 #include "SDL_image.h"
6 #include "SDL_rotozoom.h"
8 #include "game.h"
9 #include "menu.h" /* for paint_menu_fps() */
11 #include "graphics.h"
12 #include "gui.h"
13 #include "loop.h"
14 #include "menu.h"
16 #include "widget/widgets.h"
18 #include "main.h"
20 #include "loadso.h"
22 enum wid_t {
23 WID_MENU,
24 WID_MENU_BACK,
25 WID_MENU_QUIT,
26 WIDS
29 void init_game(void *vdata, struct xuni_t *xuni,
30 struct widget_t *panel, struct resource_t *settings) {
32 /*struct game_data_t *data = vdata;*/
33 struct widget_t *temppanel;
35 init_wid(xuni->gui->widget, xuni->gui->widget,
36 PANEL_GAME, "game");
37 init_wid(xuni->gui->widget, xuni->gui->widget,
38 PANEL_GAME_MENU, "game menu");
40 init_wid(xuni->gui->widget, panel, WID_MENU, "game/menu");
41 init_wid(xuni->gui->widget, panel, WID_MENU_BACK, "game menu/back");
42 init_wid(xuni->gui->widget, panel, WID_MENU_QUIT, "game menu/quit");
44 /*add_widget_accelerator(panel,
45 widget_nameid_access(panel, WID_MENU), SDLK_F10, KMOD_NONE);*/
47 temppanel = widget_nameid_access(xuni->gui->widget, PANEL_GAME_MENU);
48 add_widget_accelerator(xuni, temppanel,
49 widget_nameid_access(panel, WID_MENU_BACK), SDLK_ESCAPE, KMOD_NONE);
50 /*add_widget_accelerator(temppanel,
51 widget_nameid_access(panel, WID_MENU_BACK), SDLK_F10, KMOD_NONE);*/
54 void start_game(void *vdata, struct xuni_t *xuni) {
55 /*struct game_data_t *data = vdata;*/
56 struct widget_t *cursor;
57 struct widget_t *panel
58 = widget_nameid_access(xuni->gui->widget, PANEL_GAME);
60 set_caption("Explore the Universe");
62 cursor = widget_nameid_access(xuni->theme->current, THEME_DEFAULT_CURSOR);
64 if(cursor && cursor->p.image->image && panel->p.panel->frameupdate) {
65 show_cursor(0);
69 int game_event(void *vdata, struct xuni_t *xuni, panel_type_t *mode,
70 SDL_Event *event) {
72 switch(event->type) {
73 case SDL_KEYDOWN:
74 switch(event->key.keysym.sym) {
75 case SDLK_ESCAPE:
76 /* there is currently no widget for this */
77 if(*mode == PANEL_GAME) {
78 *mode = PANEL_MAIN_MENU;
81 break;
82 default: break;
84 break;
85 case SDL_QUIT:
86 *mode = PANEL_MAIN_MENU;
87 break;
88 default:
89 break;
92 return 0;
95 void paint_game(void *vdata, panel_type_t mode, struct xuni_t *xuni) {
96 /*struct game_data_t *data = vdata;*/
97 struct widget_t *panel
98 = widget_nameid_access(xuni->gui->widget, PANEL_GAME);
100 clear_screen(xuni->smode->screen);
102 widget_event(xuni, widget_nameid_access(xuni->gui->widget, PANEL_GAME),
103 WIDGET_EVENT_PAINT);
105 if(mode == PANEL_GAME_MENU) {
106 widget_event(xuni, widget_nameid_access(xuni->gui->widget,
107 PANEL_GAME_MENU), WIDGET_EVENT_PAINT);
110 paint_menu_fps(xuni, THEME_FONT_MONO);
112 if(panel->p.panel->frameupdate) {
113 paint_cursor(xuni->smode,
114 widget_nameid_access(xuni->theme->current, THEME_DEFAULT_CURSOR));
117 update_screen(xuni);
120 int game_perform_click(struct widget_t *widget, panel_type_t *mode,
121 void *vdata, struct xuni_t *xuni) {
123 /*struct game_data_t *data = vdata;*/
125 switch(widget->id) {
126 case WID_MENU:
127 *mode = PANEL_GAME_MENU;
129 clear_gui(xuni, PANEL_GAME_MENU, 0);
130 break;
131 case WID_MENU_BACK:
132 *mode = PANEL_GAME;
134 clear_gui(xuni, PANEL_GAME, 0);
135 break;
136 case WID_MENU_QUIT:
137 *mode = PANEL_MAIN_MENU;
138 break;
141 return 0; /* ignored */
144 void free_game(void *vdata, struct xuni_t *xuni) {