npcs and tutorial stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index 14df0dcc3606919c3003696fe3989aa81d57c705..fd59f3eb047cf652cdca82f3e0c065ac34e34f79 100644 (file)
@@ -1,21 +1,23 @@
-#ifndef ENT_SKATESHOP_C
-#define ENT_SKATESHOP_C
-
-#define VG_GAME
-#include "vg/vg.h"
 #include "vg/vg_steam_ugc.h"
 #include "vg/vg_msg.h"
+#include "vg/vg_tex.h"
+#include "vg/vg_image.h"
+#include "vg/vg_loader.h"
 #include "ent_skateshop.h"
 #include "world.h"
 #include "player.h"
 #include "gui.h"
 #include "menu.h"
-#include "highscores.h"
 #include "steam.h"
 #include "addon.h"
 #include "save.h"
 #include "network.h"
 
+struct global_skateshop global_skateshop = 
+{
+   .render={.reg_id=0xffffffff,.world_reg=0xffffffff}
+};
+
 /*
  * Checks string equality but does a hash check first
  */
@@ -64,8 +66,7 @@ static void skateshop_async_preview_imageload( void *data, u32 len ){
          global_skateshop.tex_preview;
    }
    else {
-      skaterift.rt_textures[k_skaterift_rt_workshop_preview] =
-         global_skateshop.tex_preview_err;
+      skaterift.rt_textures[k_skaterift_rt_workshop_preview] = vg.tex_missing;
    }
 
    SDL_AtomicLock( &addon_system.sl_cache_using_resources );
@@ -150,7 +151,8 @@ static void skateshop_op_board_scan(void){
 }
 
 /* TODO: migrate to addon.c */
-static void skateshop_autostart_loading(void){
+void skateshop_autostart_loading(void)
+{
    if( !vg_loader_availible() ) return;
 
    SDL_AtomicLock( &addon_system.sl_cache_using_resources );
@@ -193,19 +195,16 @@ static void skateshop_init_async(void *_data,u32 size){
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
 
-   skaterift.rt_textures[ k_skaterift_rt_workshop_preview ] =
-      global_skateshop.tex_preview_err;
-
-   skaterift.rt_textures[ k_skaterift_rt_server_status ] =
-      global_skateshop.tex_preview_err;
+   skaterift.rt_textures[ k_skaterift_rt_workshop_preview ] = vg.tex_missing;
+   skaterift.rt_textures[ k_skaterift_rt_server_status ] = vg.tex_missing;
    render_server_status_gui();
 }
 
 /*
  * VG event init
  */
-static void skateshop_init(void){
-   vg_tex2d_replace_with_error( &global_skateshop.tex_preview_err );
+void skateshop_init(void)
+{
    vg_async_call( skateshop_init_async, NULL, 0 );
 }
 
@@ -224,17 +223,23 @@ static void skateshop_server_helper_update(void){
    vg_strnull( &text, global_skateshop.helper_toggle->text, 
                sizeof(global_skateshop.helper_toggle->text) );
 
-   if( network_client.user_intent == k_server_intent_online )
-      vg_strcat( &text, "Disconnect" );
-   else
-      vg_strcat( &text, "Go Online" );
+   if( skaterift.demo_mode ){
+      vg_strcat( &text, "Not availible in demo" );
+   }
+   else {
+      if( network_client.user_intent == k_server_intent_online )
+         vg_strcat( &text, "Disconnect" );
+      else
+         vg_strcat( &text, "Go Online" );
+   }
 }
 
 /*
  * VG event preupdate 
  */
 void temp_update_playermodel(void);
-static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
+void ent_skateshop_preupdate( ent_skateshop *shop, int active )
+{
    if( !active ) return;
 
    /* input filter */
@@ -312,7 +317,8 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
          localplayer.board_view_slot = cache_id;
          network_send_item( k_netmsg_playeritem_board );
 
-         world_entity_unfocus();
+         world_entity_exit_modal();
+         world_entity_clear_focus();
          gui_helper_clear();
          skaterift_autosave(1);
          return;
@@ -359,7 +365,8 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
 
       if( button_down( k_srbind_maccept ) ){
          network_send_item( k_netmsg_playeritem_player );
-         world_entity_unfocus();
+         world_entity_exit_modal();
+         world_entity_clear_focus();
          gui_helper_clear();
       }
    }
@@ -415,7 +422,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
    else if( shop->type == k_skateshop_type_server ){
       f64 delta = vg.time_real - network_client.last_intent_change;
 
-      if( delta > 5.0 ){
+      if( (delta > 5.0) && (!skaterift.demo_mode) ){
          global_skateshop.helper_pick->greyed = 0;
          if( button_down( k_srbind_maccept ) ){
             network_client.user_intent = !network_client.user_intent;
@@ -432,17 +439,20 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
       vg_fatal_error( "Unknown store (%u)\n", shop->type );
    }
 
-   if( button_down( k_srbind_mback ) ){
+   if( button_down( k_srbind_mback ) )
+   {
       if( shop->type == k_skateshop_type_charshop )
          network_send_item( k_netmsg_playeritem_player );
 
-      world_entity_unfocus();
+      world_entity_exit_modal();
+      world_entity_clear_focus();
       gui_helper_clear();
       return;
    }
 }
 
-static void skateshop_world_preupdate( world_instance *world ){
+void skateshop_world_preupdate( world_instance *world )
+{
    for( u32 i=0; i<mdl_arrcount(&world->ent_skateshop); i++ ){
       ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i );
 
@@ -713,7 +723,8 @@ none:;
 /*
  * World: render event
  */
-static void skateshop_render( ent_skateshop *shop ){
+void skateshop_render( ent_skateshop *shop )
+{
    if( shop->type == k_skateshop_type_boardshop )
       skateshop_render_boardshop( shop );
    else if( shop->type == k_skateshop_type_charshop )
@@ -726,7 +737,8 @@ static void skateshop_render( ent_skateshop *shop ){
       vg_fatal_error( "Unknown store (%u)\n", shop->type );
 }
 
-static void skateshop_render_nonfocused( world_instance *world, camera *cam ){
+void skateshop_render_nonfocused( world_instance *world, vg_camera *cam )
+{
    for( u32 j=0; j<mdl_arrcount( &world->ent_skateshop ); j ++ ){
       ent_skateshop *shop = mdl_arritm(&world->ent_skateshop, j );
 
@@ -780,7 +792,8 @@ static void ent_skateshop_helpers_pickable( const char *acceptance ){
 /*
  * Entity logic: entrance event
  */
-static void ent_skateshop_call( world_instance *world, ent_call *call ){
+void ent_skateshop_call( world_instance *world, ent_call *call )
+{
    u32 index = mdl_entity_id_id( call->id );
    ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
    vg_info( "skateshop_call\n" );
@@ -793,7 +806,8 @@ static void ent_skateshop_call( world_instance *world, ent_call *call ){
       
       vg_info( "Entering skateshop\n" );
 
-      world_entity_focus( call->id );
+      world_entity_set_focus( call->id );
+      world_entity_focus_modal();
       gui_helper_clear();
       
       if( shop->type == k_skateshop_type_boardshop ){
@@ -812,9 +826,9 @@ static void ent_skateshop_call( world_instance *world, ent_call *call ){
          vg_str text;
          global_skateshop.helper_pick = gui_new_helper(
                      input_button_list[k_srbind_maccept], &text);
+         if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
+            vg_strcat( &text, "exit" );
          skateshop_server_helper_update();
       }
    }
 }
-
-#endif /* ENT_SKATESHOP_C */