scenes
This commit is contained in:
parent
b3924e53d2
commit
9dd2e6acd6
5 changed files with 68 additions and 11 deletions
|
|
@ -9,7 +9,9 @@ double gl_cam_z;
|
|||
int gl_scene = AF_SCENE_MAIN;
|
||||
|
||||
gl_scene_t gl_scenes[] = {
|
||||
{gl_main_init, gl_main_draw}};
|
||||
{gl_main_changed, gl_main_init, gl_main_draw}, /**/
|
||||
{gl_connecting_changed, gl_connecting_init, gl_connecting_draw} /**/
|
||||
};
|
||||
|
||||
void gl_resize(int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#include <af_common.h>
|
||||
|
||||
static double rad;
|
||||
|
||||
void gl_main_changed(void) {
|
||||
rad = 0;
|
||||
}
|
||||
|
||||
void gl_main_init(void) {
|
||||
gl_cam_x = 0;
|
||||
gl_cam_y = 0;
|
||||
|
|
@ -10,14 +16,13 @@ void gl_main_init(void) {
|
|||
}
|
||||
|
||||
void gl_main_draw(void) {
|
||||
int i;
|
||||
static double r = 0;
|
||||
int i;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glPushMatrix();
|
||||
glRotatef(r, 1, 0, 0);
|
||||
glRotatef(r, 0, 1, 0);
|
||||
glRotatef(r, 0, 0, 1);
|
||||
glRotatef(rad, 1, 0, 0);
|
||||
glRotatef(rad, 0, 1, 0);
|
||||
glRotatef(rad, 0, 0, 1);
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(i = 0; i < 8; i++) {
|
||||
double r = i * 90 / 180.0 * M_PI;
|
||||
|
|
@ -31,5 +36,5 @@ void gl_main_draw(void) {
|
|||
glPopMatrix();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
r += 60.0 / (1000.0 / AF_WAIT_MS);
|
||||
rad += 60.0 / (1000.0 / AF_WAIT_MS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ static void resize(MwWidget handle, void* user, void* client) {
|
|||
}
|
||||
|
||||
static void tick(MwWidget handle, void* user, void* client) {
|
||||
net_poll();
|
||||
|
||||
gl_render();
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
|
|
@ -34,6 +36,7 @@ static void* gl_load(const char* name) {
|
|||
void scene_change(int scene) {
|
||||
gl_scene = scene;
|
||||
|
||||
gl_scenes[gl_scene].changed();
|
||||
ui_scene();
|
||||
}
|
||||
|
||||
|
|
|
|||
40
client/ui.c
40
client/ui.c
|
|
@ -17,8 +17,17 @@ void ui_notice_destroy(MwWidget widget) {
|
|||
}
|
||||
|
||||
static void ui_login_join(MwWidget handle, void* user, void* client) {
|
||||
char* username = MwStringDuplicate(MwGetText(MwGetVoid(user, "VusernameEntry"), MwNtext));
|
||||
char* hostname = MwStringDuplicate(MwGetText(MwGetVoid(user, "VhostnameEntry"), MwNtext));
|
||||
int port = atoi(MwGetText(MwGetVoid(user, "VportEntry"), MwNtext));
|
||||
|
||||
MwLLDestroyPixmap(MwGetVoid(user, MwNpixmap));
|
||||
ui_notice_destroy(user);
|
||||
|
||||
net_connect(username, hostname, port);
|
||||
|
||||
free(username);
|
||||
free(hostname);
|
||||
}
|
||||
|
||||
static void ui_login(void) {
|
||||
|
|
@ -37,6 +46,7 @@ static void ui_login(void) {
|
|||
MwNfixedSize, 100,
|
||||
NULL);
|
||||
MwWidget entrybox[3];
|
||||
MwWidget entryinput[3];
|
||||
MwLLPixmap px = MwLoadImage(wnd, DATAROOTDIR "/assaultfish/logo.png");
|
||||
const char* labels[3] = {
|
||||
"Username",
|
||||
|
|
@ -64,9 +74,9 @@ static void ui_login(void) {
|
|||
MwNtext, labels[i],
|
||||
MwNalignment, MwALIGNMENT_END,
|
||||
NULL);
|
||||
MwVaCreateWidget(MwEntryClass, "entry", entrybox[i], 0, 0, 0, 0,
|
||||
MwNtext, entries[i],
|
||||
NULL);
|
||||
entryinput[i] = MwVaCreateWidget(MwEntryClass, "entry", entrybox[i], 0, 0, 0, 0,
|
||||
MwNtext, entries[i],
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwVaApply(icon,
|
||||
|
|
@ -75,11 +85,35 @@ static void ui_login(void) {
|
|||
|
||||
MwVaApply(wnd,
|
||||
MwNpixmap, px,
|
||||
"VusernameEntry", entryinput[0],
|
||||
"VhostnameEntry", entryinput[1],
|
||||
"VportEntry", entryinput[2],
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(join, MwNactivateHandler, ui_login_join, wnd);
|
||||
}
|
||||
|
||||
static void ui_message_ok(MwWidget handle, void* user, void* client) {
|
||||
MwDispatchUserHandler(user, MwNactivateHandler, NULL);
|
||||
|
||||
ui_notice_destroy(user);
|
||||
}
|
||||
|
||||
MwWidget ui_message(const char* message) {
|
||||
MwWidget wnd = ui_notice(0, 0);
|
||||
int bw = MwDefaultBorderWidth(wnd);
|
||||
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", wnd, bw, (MwGetInteger(wnd, MwNheight) - 24) / 2, MwGetInteger(wnd, MwNwidth) - bw * 2, 24,
|
||||
MwNtext, message,
|
||||
NULL);
|
||||
MwWidget ok = MwVaCreateWidget(MwButtonClass, "ok", wnd, MwGetInteger(wnd, MwNwidth) - bw - 10 - 96, MwGetInteger(wnd, MwNheight) - bw - 10 - 24, 96, 24,
|
||||
MwNtext, "OK",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(ok, MwNactivateHandler, ui_message_ok, wnd);
|
||||
|
||||
return wnd;
|
||||
}
|
||||
|
||||
void ui_scene(void) {
|
||||
if(gl_scene == AF_SCENE_MAIN) {
|
||||
ui_login();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
#define AF_WAIT_MS 15
|
||||
|
||||
enum AF_SCENES {
|
||||
AF_SCENE_MAIN = 0
|
||||
AF_SCENE_MAIN = 0,
|
||||
AF_SCENE_CONNECTING
|
||||
};
|
||||
|
||||
/* main.c */
|
||||
|
|
@ -20,6 +21,7 @@ void scene_change(int scene);
|
|||
|
||||
/* gl.c */
|
||||
typedef struct gl_scene {
|
||||
void (*changed)(void);
|
||||
void (*init)(void);
|
||||
void (*draw)(void);
|
||||
} gl_scene_t;
|
||||
|
|
@ -43,13 +45,24 @@ int gl_font_width(const char* text);
|
|||
int gl_font_height(const char* text);
|
||||
|
||||
/* gl_main.c */
|
||||
void gl_main_changed(void);
|
||||
void gl_main_init(void);
|
||||
void gl_main_draw(void);
|
||||
|
||||
/* gl_connecting.c */
|
||||
void gl_connecting_changed(void);
|
||||
void gl_connecting_init(void);
|
||||
void gl_connecting_draw(void);
|
||||
|
||||
/* net.c */
|
||||
void net_connect(const char* username, const char* hostname, int port);
|
||||
void net_poll(void);
|
||||
|
||||
/* ui.c */
|
||||
MwWidget ui_notice(int width, int height);
|
||||
void ui_notice_destroy(MwWidget widget);
|
||||
void ui_init(void);
|
||||
void ui_scene(void);
|
||||
MwWidget ui_message(const char* message);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue