Skip to content

Commit

Permalink
Cleaning up hud module including removing use of global ui scale value.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbroad committed Oct 23, 2017
1 parent fc247be commit 63b41c8
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 142 deletions.
2 changes: 1 addition & 1 deletion consolewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int display_console_handler (window_info *win)
//if they want it filtered, then more work can be done until it works properly
//((text_field*)((widget_find(console_root_win, console_out_id))->widget_info))->chan_nr = current_filter;

draw_hud_interface ();
draw_hud_interface (win);
set_font (0); // switch to fixed
}

Expand Down
1 change: 1 addition & 0 deletions elconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "filter.h"
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_statsbar_window.h"
#include "hud_indicators.h"
#include "hud_misc_window.h"
Expand Down
34 changes: 33 additions & 1 deletion gamewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,38 @@ void return_to_gamewin_common(void)
show_window (quickspell_win);
}

static void draw_ingame_interface(window_info *win)
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
#ifdef OLD_CLOSE_BAG
// watch for closing a bag
if(ground_items_win >= 0)
{
int old_view= view_ground_items;

view_ground_items= get_show_window(ground_items_win);
// watch for telling the server we need to close the bag
if(old_view && !view_ground_items)
{
unsigned char protocol_name;

protocol_name= S_CLOSE_BAG;
my_tcp_send(my_socket,&protocol_name,1);
}
}
#endif //OLD_CLOSE_BAG

draw_hud_interface(win);
display_spells_we_have();

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}


static int display_game_handler (window_info *win)
{
static int main_count = 0;
Expand Down Expand Up @@ -1391,7 +1423,7 @@ static int display_game_handler (window_info *win)
anything_under_the_mouse (0, UNDER_MOUSE_NO_CHANGE);
CHECK_GL_ERRORS ();

draw_ingame_interface ();
draw_ingame_interface (win);

CHECK_GL_ERRORS ();

Expand Down
66 changes: 25 additions & 41 deletions hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#endif
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_indicators.h"
#include "hud_misc_window.h"
#include "hud_quickbar_window.h"
Expand All @@ -23,6 +24,7 @@
#include "mapwin.h"
#include "minimap.h"
#include "missiles.h"
#include "new_character.h"
#include "questlog.h"
#include "spells.h"
#include "storage.h"
Expand All @@ -31,17 +33,14 @@
#include "trade.h"
#include "user_menus.h"

#define UI_SCALED_VALUE(BASE) ((int)(0.5 + ((BASE) * get_global_scale())))

int hud_x= 64;
int hud_y= 48;
int hud_text;
int show_help_text=1;
int always_enlarge_text=1;
Uint32 exp_lev[200];
hud_interface last_interface = HUD_INTERFACE_NEW_CHAR; //Current interface (game or new character)

static void init_hud_frame(void);
static hud_interface last_interface = HUD_INTERFACE_NEW_CHAR; //Current interface (game or new character)


/* called on client exit to free resources */
Expand Down Expand Up @@ -77,15 +76,14 @@ void init_hud_interface (hud_interface type)
if (type == HUD_INTERFACE_LAST)
type = last_interface;

init_hud_frame ();
if(type == HUD_INTERFACE_GAME)
init_misc_display (type);

if (type == HUD_INTERFACE_NEW_CHAR)
{
hud_x = UI_SCALED_VALUE(270);
resize_root_window();
init_icon_window (NEW_CHARACTER_ICONS);
if (newchar_root_win >= 0 && newchar_root_win < windows_list.num_windows)
{
hud_x = (int)(0.5 + windows_list.window[newchar_root_win].current_scale * 270);
resize_root_window();
init_icon_window (NEW_CHARACTER_ICONS);
}
}
else
{
Expand All @@ -94,6 +92,7 @@ void init_hud_interface (hud_interface type)
resize_root_window();
init_icon_window (MAIN_WINDOW_ICONS);
init_stats_display ();
init_misc_display ();
init_quickbar ();
init_quickspell ();
init_hud_indicators ();
Expand Down Expand Up @@ -127,48 +126,33 @@ void hide_hud_windows (void)
hide_hud_indicators_window();
}

// draw everything related to the hud
void draw_hud_interface(void)
void draw_hud_interface(window_info *win)
{
glColor3f(1.0f, 1.0f, 1.0f);
draw_hud_frame();
}

// hud frame section
static float vertical_bar_u_start = (float)192/256;
static float vertical_bar_u_end = 1.0f;
static float vertical_bar_v_end = 0.0f;
static float vertical_bar_v_start = 0.0f;
const float vertical_bar_u_start = (float)192/256;
const float vertical_bar_u_end = 1.0f;
const float vertical_bar_v_start = 0.0f;
const float horizontal_bar_u_start = (float)144/256;
const float horizontal_bar_u_end = (float)191/256;
const float horizontal_bar_v_end = 0.0f;
const float logo_u_start = (float)64/256;
const float logo_v_start = (float)128/256;
const float logo_u_end = (float)127/256;
const float logo_v_end = (float)191/256;
float vertical_bar_v_end = (float)window_height/256;
float horizontal_bar_v_start = (float)(window_width-hud_x)/256;

static float horizontal_bar_u_start = (float)144/256;
static float horizontal_bar_u_end = (float)191/256;
static float horizontal_bar_v_start = 0.0f;
static float horizontal_bar_v_end = 0.0f;

static void init_hud_frame(void)
{
vertical_bar_v_end = (float)window_height/256;
horizontal_bar_v_start = (float)(window_width-hud_x)/256;
}

static float logo_u_start = (float)64/256;
static float logo_v_start = (float)128/256;
static float logo_u_end = (float)127/256;
static float logo_v_end = (float)191/256;

void draw_hud_frame(void)
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
glColor3f(1.0f, 1.0f, 1.0f);
bind_texture(hud_text);
glBegin(GL_QUADS);
draw_2d_thing_r(horizontal_bar_u_start, horizontal_bar_v_start, horizontal_bar_u_end, horizontal_bar_v_end,0,window_height,window_width, window_height-hud_y);
if(last_interface == HUD_INTERFACE_GAME)
{
draw_2d_thing(vertical_bar_u_start, vertical_bar_v_start, vertical_bar_u_end, vertical_bar_v_end,window_width-hud_x, 0, window_width, window_height);
//draw the logo
draw_2d_thing(logo_u_start, logo_v_start, logo_u_end, logo_v_end,window_width-hud_x, 0, window_width, UI_SCALED_VALUE(64));
draw_2d_thing(logo_u_start, logo_v_start, logo_u_end, logo_v_end,window_width-hud_x, 0, window_width, (int)(0.5 + win->current_scale * 64));
}
glEnd();
#ifdef OPENGL_TRACE
Expand Down
15 changes: 3 additions & 12 deletions hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define __HUD_H

#include <SDL_types.h>
#include "elwindows.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -80,21 +81,11 @@ void hide_hud_windows (void);
* \ingroup display_2d
* \brief Draws the hud interface related items.
*
* Draws the hud related items by setting the background color before calling \ref draw_hud_frame.
* Draws the hud interface related items.
*
* \callgraph
*/
void draw_hud_interface(void);

/*!
* \ingroup display_2d
* \brief Draws the hud frame.
*
* Draws the hud frame, by setting the texture, then draws the horizontal and vertical bar of the hud and finally the EL logo.
*
* \callgraph
*/
void draw_hud_frame(void);
void draw_hud_interface(window_info *win);

/*!
* \ingroup windows
Expand Down
22 changes: 2 additions & 20 deletions hud_misc_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static int calc_statbar_start_y(int base_y_start, int win_y_len)
/* if the number of stats displayed has changed, resize other hud elements */
if (last_display != num_disp_stat)
{
init_misc_display(HUD_INTERFACE_LAST);
init_misc_display();
init_quickbar();
init_quickspell();
}
Expand Down Expand Up @@ -596,10 +596,8 @@ static int ui_scale_misc_handler(window_info *win)
}


void init_misc_display(hud_interface type)
void init_misc_display(void)
{
int i;

//create the misc window
if(misc_win < 0)
{
Expand Down Expand Up @@ -629,21 +627,5 @@ void init_misc_display(hud_interface type)
cm_add_window(cm_hud_id, misc_win);
cm_set_pre_show_handler(cm_hud_id, context_hud_pre_show_handler);
}

ui_scale_misc_handler(&windows_list.window[misc_win]);

cm_grey_line(cm_hud_id, CMH_STATS, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_STATBARS, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_FPS, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_INDICATORS, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_MINIMAP, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_RANGSTATS, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_QUICKBM, (type == HUD_INTERFACE_NEW_CHAR));
cm_grey_line(cm_hud_id, CMH_LOCATION, (type == HUD_INTERFACE_NEW_CHAR));

for (i=0; i<MAX_WATCH_STATS; i++)
{
if (watch_this_stats[i] > 0)
statsinfo[watch_this_stats[i]-1].is_selected = 1;
}
}
4 changes: 1 addition & 3 deletions hud_misc_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
extern "C" {
#endif

#include "hud.h"

extern int misc_win;
extern int view_analog_clock;
extern int view_digital_clock;
Expand All @@ -16,7 +14,7 @@ extern int show_stats_in_hud;
extern int show_statbars_in_hud;
extern int copy_next_LOCATE_ME;

void init_misc_display(hud_interface type);
void init_misc_display(void);

#ifdef __cplusplus
} // extern "C"
Expand Down
1 change: 1 addition & 0 deletions hud_quickbar_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "elwindows.h"
#include "font.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_misc_window.h"
#include "hud_quickbar_window.h"
#include "interface.h"
Expand Down
35 changes: 34 additions & 1 deletion hud_statsbar_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
int stats_bar_win= -1;
int show_action_bar = 0;
int max_food_level = 45;
int watch_this_stats[MAX_WATCH_STATS]={NUM_WATCH_STAT -1, 0, 0, 0, 0}; // default to only watching overall

#define MAX_WATCH_STATS 5 /*!< max number of stats watchable in hud */

static int max_disp_stats=1;
static int exp_bar_text_len = 0;
Expand All @@ -39,6 +40,7 @@ static int player_statsbar_bar_height = 8;
static int stats_bar_len;
static int health_bar_start_x;
static struct { int d; int h; Uint32 dt; Uint32 ht; } my_last_health = { 0, 0, 0, 0 };
static int watch_this_stats[MAX_WATCH_STATS]={NUM_WATCH_STAT -1, 0, 0, 0, 0}; // default to only watching overall

#define UI_SCALED_VALUE(BASE) ((int)(0.5 + ((BASE) * get_global_scale())))

Expand Down Expand Up @@ -479,6 +481,7 @@ static int mouseover_stats_bar_handler(window_info *win, int mx, int my)
// the stats display
void init_stats_display(void)
{
int i;
int num_exp = get_num_statsbar_exp();
int actual_num_exp = 0;
int stats_height = get_player_statsbar_active_height();
Expand Down Expand Up @@ -557,6 +560,12 @@ void init_stats_display(void)
cm_set_pre_show_handler(cm_id,cm_statsbar_pre_show_handler);
}
reset_statsbar_exp_cm_regions();

for (i=0; i<MAX_WATCH_STATS; i++)
{
if (watch_this_stats[i] > 0)
statsinfo[watch_this_stats[i]-1].is_selected = 1;
}
}


Expand Down Expand Up @@ -639,3 +648,27 @@ void set_last_heal(int quantity)
my_last_health.h = quantity;
my_last_health.ht = SDL_GetTicks();
}


void set_statsbar_watched_stats(int *cfg_watch_this_stats)
{
int i;
#if MAX_WATCH_STATS != 5
#error You cannot just go around changing MAX_WATCH_STATS as its used by the el.cfg file so change init.h too.
#endif
for(i=0;i<MAX_WATCH_STATS;i++)
{
watch_this_stats[i] = cfg_watch_this_stats[i];
if (watch_this_stats[i]<0 || watch_this_stats[i]>=NUM_WATCH_STAT)
watch_this_stats[i]=0;
}
if(watch_this_stats[0]<1 || watch_this_stats[0]>=NUM_WATCH_STAT)
watch_this_stats[0]=NUM_WATCH_STAT-1;
}

void get_statsbar_watched_stats(int *cfg_watch_this_stats)
{
int i;
for(i=0;i<MAX_WATCH_STATS;i++)
cfg_watch_this_stats[i]=watch_this_stats[i];
}
Loading

0 comments on commit 63b41c8

Please sign in to comment.