Main menu, loading into game, etc
This commit is contained in:
@@ -47,10 +47,11 @@ texturemap=res/map/texturemap.png
|
||||
entitymap=res/map/entitymap.png
|
||||
|
||||
[UIDefs]
|
||||
tooltip=res/scripts/ui/tooltip.scm
|
||||
main_menu=res/scripts/ui/debug_window.scm
|
||||
tooltip=res/scripts/u_tooltip.scm
|
||||
main_menu=res/scripts/u_main_menu.scm
|
||||
debug_window=res/scripts/u_debug.scm
|
||||
|
||||
# The scripts are loaded and executed after everything above has been
|
||||
# loaded, so that Guile has some stuff to work with.
|
||||
[Scripts]
|
||||
global=res/scripts/global/ui_styles.scm;res/scripts/global/ui_composites.scm
|
||||
# The names of the scripts are ignored.
|
||||
[RunScripts]
|
||||
uistyles=res/scripts/g_styles.scm
|
||||
uielements=res/scripts/g_uielements.scm
|
||||
@@ -40,6 +40,14 @@
|
||||
#:icon-color-hovered '(1.0 1.0 0.0 1.0)
|
||||
#:icon-color-clicked '(1.0 0.0 0.0 1.0)))
|
||||
|
||||
(define style-button
|
||||
(style-new #:background-color '(0.1 0.1 0.1 1.0)
|
||||
#:background-color-hovered '(0.4 0.4 0.4 1.0)
|
||||
#:background-color-clicked '(0.2 0.2 0.2 1.0)
|
||||
#:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE))
|
||||
|
||||
(define style-tooltip
|
||||
(style-new
|
||||
#:text-color COLOR_WHITE
|
||||
@@ -0,0 +1,11 @@
|
||||
(widget-new
|
||||
'flowbox
|
||||
#:style style-container
|
||||
#:layout-padding 8
|
||||
#:layout-spacing 8
|
||||
#:horizontal #t
|
||||
(widget-new 'label #:style style-button #:layout-weight 1 #:h 20 #:text-alignment 'center #:text "New game"
|
||||
#:on-click (lambda (w e) (stateman-switch-state "game")))
|
||||
(widget-new 'label #:style style-button #:layout-weight 1 #:h 20 #:text-alignment 'center #:text "Options")
|
||||
(widget-new 'label #:style style-button #:layout-weight 1 #:h 20 #:text-alignment 'center #:text "Quit game"))
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
#:visible #f
|
||||
#:layout-padding 4
|
||||
#:line-height 20
|
||||
#:style style-tooltip)
|
||||
#:style style-tooltip
|
||||
#:text-alignment 'center)
|
||||
+2
-4
@@ -21,14 +21,11 @@ SDL_AppInit (void **appstate, int argc, char **argv)
|
||||
things. */
|
||||
scm_init_guile ();
|
||||
gvar_guile_register ();
|
||||
stateman_guile_register ();
|
||||
widget_guile_register ();
|
||||
entity_guile_register ();
|
||||
pakman_guile_register ();
|
||||
|
||||
/* TODO: move this somewhere. */
|
||||
scm_c_primitive_load ("res/scripts/global/ui_styles.scm");
|
||||
scm_c_primitive_load ("res/scripts/global/ui_composites.scm");
|
||||
|
||||
/* The basics; game variables, graphics, the state manager, and the
|
||||
pak manager. */
|
||||
gvar_init ();
|
||||
@@ -44,6 +41,7 @@ SDL_AppInit (void **appstate, int argc, char **argv)
|
||||
ui_widget_mesh_init ();
|
||||
|
||||
/* The UI, entity and chunk subsystems. */
|
||||
ent_templates_init ();
|
||||
entman_init ();
|
||||
chunkman_init ();
|
||||
|
||||
|
||||
@@ -124,6 +124,14 @@ pakman_load_pak (const char *path)
|
||||
g_hash_table_insert (pak->textures, g_strdup (*t), GUINT_TO_POINTER (_pm_load_texture (texture)));
|
||||
}
|
||||
|
||||
char **run = g_key_file_get_keys (key_file, "RunScripts", NULL, &err);
|
||||
|
||||
for (char **r = run; *r != NULL; r++)
|
||||
{
|
||||
char *run_path = g_key_file_get_string (key_file, "RunScripts", *r, &err);
|
||||
scm_c_primitive_load (run_path);
|
||||
}
|
||||
|
||||
char **uidefs = g_key_file_get_keys (key_file, "UIDefs", NULL, &err);
|
||||
|
||||
for (char **u = uidefs; *u != NULL; u++)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "state_game.h"
|
||||
|
||||
extern vec3 camera_position;
|
||||
|
||||
static void
|
||||
_on_enter ()
|
||||
{
|
||||
gvar_set ("ui_has_focus", TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_update ()
|
||||
{
|
||||
chunkman_tick (camera_position);
|
||||
entman_tick ();
|
||||
}
|
||||
|
||||
static void
|
||||
_on_render ()
|
||||
{
|
||||
mat4 projection, view;
|
||||
camera_get_projection (gvar_get ("window_width") / gvar_get ("window_height"), projection);
|
||||
camera_get_view (view);
|
||||
|
||||
pakman_all_paks_set_mat4 ("projection", projection);
|
||||
pakman_all_paks_set_mat4 ("view", view);
|
||||
pakman_all_paks_set_float ("time", gvar_get ("last_time"));
|
||||
|
||||
vec4 planes[6];
|
||||
#if FRUSTUM_CULL
|
||||
mat4 view_proj;
|
||||
glm_mat4_mul (projection, view, view_proj);
|
||||
glm_frustum_planes (view_proj, planes);
|
||||
#endif
|
||||
|
||||
chunkman_render (camera_position, planes);
|
||||
entman_render (view, planes);
|
||||
}
|
||||
|
||||
GameState *
|
||||
state_game_new ()
|
||||
{
|
||||
GameState *g = GameState_new ();
|
||||
|
||||
g->on_enter = _on_enter;
|
||||
g->on_update = _on_update;
|
||||
g->on_render = _on_render;
|
||||
|
||||
/* If your GameState uses the UI, always call this. */
|
||||
GameState_register_UIContext_handlers (g);
|
||||
g->ui_context->root = PMUID ("debug_window");
|
||||
|
||||
return g;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "state_common.h"
|
||||
|
||||
#include "../graphics.h"
|
||||
#include "../gvar.h"
|
||||
#include "../camera.h"
|
||||
|
||||
GameState *state_game_new ();
|
||||
@@ -19,8 +19,6 @@ _on_update ()
|
||||
gvar_set ("last_time", now);
|
||||
}
|
||||
|
||||
static void _on_render () { return; }
|
||||
|
||||
GameState *
|
||||
state_global_new ()
|
||||
{
|
||||
@@ -35,7 +33,6 @@ state_global_new ()
|
||||
self->on_enter = _on_enter;
|
||||
self->on_exit = _on_exit;
|
||||
self->on_update = _on_update;
|
||||
self->on_render = _on_render;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -6,37 +6,15 @@ _on_enter ()
|
||||
gvar_set ("ui_has_focus", TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_exit ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
_on_update ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
_on_render ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GameState *
|
||||
state_main_menu_new ()
|
||||
{
|
||||
GameState *g = GameState_new ();
|
||||
|
||||
g->on_enter = _on_enter;
|
||||
g->on_exit = _on_exit;
|
||||
g->on_update = _on_update;
|
||||
g->on_render = _on_render;
|
||||
|
||||
/* If your GameState uses the UI, always call this. */
|
||||
GameState_register_UIContext_handlers (g);
|
||||
|
||||
g->ui_context->root = PMUID ("main_menu");
|
||||
|
||||
return g;
|
||||
|
||||
@@ -11,11 +11,26 @@ stateman_init ()
|
||||
game_states = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
stateman_add_state ("main_menu", state_main_menu_new ());
|
||||
stateman_add_state ("game", state_game_new ());
|
||||
|
||||
global_state = state_global_new ();
|
||||
global_state->on_enter (global_state);
|
||||
}
|
||||
|
||||
static SCM
|
||||
_scm_switch_state (SCM state_val)
|
||||
{
|
||||
char *state = scm_to_utf8_string (state_val);
|
||||
stateman_switch_state (state);
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
|
||||
void
|
||||
stateman_guile_register ()
|
||||
{
|
||||
scm_c_define_gsubr ("stateman-switch-state", 1, 0, 0, _scm_switch_state);
|
||||
}
|
||||
|
||||
void
|
||||
stateman_add_state (const char *name, GameState *state)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
#include "state_global.h"
|
||||
|
||||
#include "state_main_menu.h"
|
||||
#include "state_game.h"
|
||||
|
||||
void stateman_init ();
|
||||
void stateman_guile_register ();
|
||||
static inline void stateman_free () { } /* TODO: implement */
|
||||
void stateman_add_state (const char *name, GameState *state);
|
||||
void stateman_switch_state (const char *name);
|
||||
|
||||
@@ -141,8 +141,6 @@ UIContext_mouse_motion (SDL_Event *event, void *data)
|
||||
like scrollbars. */
|
||||
_call_on_event (self->clicked_widget, event, EVENT_MOUSE_MOVE);
|
||||
|
||||
/* TODO: Later... */
|
||||
|
||||
Widget *tooltip_source = Widget_find_xy_cond (self->root, pos, wcond_tooltip, NULL);
|
||||
|
||||
if (tooltip_source && tooltip_source->tooltip && tooltip_source->tooltip->len > 0)
|
||||
|
||||
Reference in New Issue
Block a user