naev 0.11.5
news.c File Reference

Handles news generation. More...

#include "news.h"
#include "array.h"
#include "faction.h"
#include "log.h"
#include "nlua.h"
#include "nlua_diff.h"
#include "nlua_faction.h"
#include "nlua_misn.h"
#include "nlua_var.h"
#include "nluadef.h"
#include "nstring.h"
#include "ntime.h"
#include "nxml.h"
#include "nxml_lua.h"
#include "space.h"
#include "toolkit.h"

Go to the source code of this file.

Macros

#define NEWS_MAX_LENGTH   8192
 
#define NEWS_READ(elem, s)
 

Functions

static void news_render (double bx, double by, double w, double h, void *data)
 Renders a news widget.
 
static void news_focusLose (unsigned int wid, const char *wgtname)
 Called when it's de-focused.
 
static int news_mouse (unsigned int wid, const SDL_Event *event, double mx, double my, double w, double h, double rx, double ry, void *data)
 News widget mouse event handler.
 
static int news_parseArticle (xmlNodePtr parent)
 Parses articles.
 
int news_saveArticles (xmlTextWriterPtr writer)
 
int news_loadArticles (xmlNodePtr parent)
 Loads the player's active articles from a save, initilizes news.
 
static void clear_newslines (void)
 
static int news_cmp (const void *p1, const void *p2)
 
int news_add (const char *title, const char *content, const char *faction, const char *tag, ntime_t date, ntime_t date_to_rm, int priority)
 makes a new article and puts it into the list
 
int news_init (void)
 Initiate news linked list with a stack.
 
void news_exit (void)
 Kills the old news thread.
 
news_tnews_get (int id)
 gets the article with id ID, else NULL
 
void news_free (news_t *n)
 
void news_rm (int id)
 
int * generate_news (int faction)
 Generates news from newslist from specific faction AND Generic news.
 
void news_widget (unsigned int wid, int x, int y, int w, int h)
 Creates a news widget.
 

Variables

news_tnews_list = NULL
 
static int next_id = 0
 
static char buf [NEWS_MAX_LENGTH]
 
static int len
 
static unsigned int news_tick = 0
 
static int news_drag = 0
 
static double news_pos = 0.
 
static glFontnews_font = &gl_defFont
 
static char ** news_lines = NULL
 
static glFontRestorenews_restores = NULL
 
static double textlength = 0.
 
static int largestID
 

Detailed Description

Handles news generation.

Definition in file news.c.

Macro Definition Documentation

◆ NEWS_MAX_LENGTH

#define NEWS_MAX_LENGTH   8192

Maximum length to print.

Definition at line 34 of file news.c.

◆ NEWS_READ

#define NEWS_READ ( elem,
s )
Value:
xmlr_attr_strd(node, s, elem); \
if (elem == NULL) { WARN(_("Event is missing '%s', skipping."), s); goto cleanup; }

Function Documentation

◆ clear_newslines()

void clear_newslines ( void )
static

Definition at line 313 of file news.c.

◆ generate_news()

int * generate_news ( int faction)

Generates news from newslist from specific faction AND Generic news.

Parameters
factionthe faction of wanted news
Returns
0 on success

Definition at line 209 of file news.c.

◆ news_add()

int news_add ( const char * title,
const char * content,
const char * faction,
const char * tag,
ntime_t date,
ntime_t date_to_rm,
int priority )

makes a new article and puts it into the list

Parameters
titlethe article title
contentthe article content
factionthe article faction
tagTag to set.
datedate to put
date_to_rmdate to remove the article
priorityPriority to use.
Returns
ID of newly added news.

Definition at line 100 of file news.c.

◆ news_cmp()

static int news_cmp ( const void * p1,
const void * p2 )
static

Definition at line 73 of file news.c.

◆ news_exit()

void news_exit ( void )

Kills the old news thread.

Definition at line 146 of file news.c.

◆ news_focusLose()

static void news_focusLose ( unsigned int wid,
const char * wgtname )
static

Called when it's de-focused.

Definition at line 325 of file news.c.

◆ news_free()

void news_free ( news_t * n)

Definition at line 186 of file news.c.

◆ news_get()

news_t * news_get ( int id)

gets the article with id ID, else NULL

Definition at line 176 of file news.c.

◆ news_init()

int news_init ( void )

Initiate news linked list with a stack.

Definition at line 130 of file news.c.

◆ news_loadArticles()

int news_loadArticles ( xmlNodePtr parent)

Loads the player's active articles from a save, initilizes news.

Parameters
parentNode containing the player's active events.
Returns
0 on success.

Definition at line 488 of file news.c.

◆ news_mouse()

static int news_mouse ( unsigned int wid,
const SDL_Event * event,
double mx,
double my,
double w,
double h,
double rx,
double ry,
void * data )
static

News widget mouse event handler.

Parameters
widWindow receiving the mouse events.
eventMouse event being received.
mxX position of the mouse.
myY position of the mouse.
wWidth of the widget.
hHeight of the widget.
rxRelative X movement (only valid for motion).
ryRelative Y movement (only valid for motion).
dataUnused.

Definition at line 345 of file news.c.

◆ news_parseArticle()

static int news_parseArticle ( xmlNodePtr parent)
static

Parses articles.

Parameters
parentParent node to parse.
Returns
0 on success.

Definition at line 517 of file news.c.

◆ news_render()

static void news_render ( double bx,
double by,
double w,
double h,
void * data )
static

Renders a news widget.

Parameters
bxBase X position to render at.
byBase Y position to render at.
wWidth of the widget.
hHeight of the widget.
dataUnused.

Definition at line 394 of file news.c.

◆ news_rm()

void news_rm ( int id)

Definition at line 194 of file news.c.

◆ news_saveArticles()

int news_saveArticles ( xmlTextWriterPtr writer)

Definition at line 447 of file news.c.

◆ news_widget()

void news_widget ( unsigned int wid,
int x,
int y,
int w,
int h )

Creates a news widget.

Parameters
widWindow to create news widget on.
xX position of the widget to create.
yY position of the widget to create.
wWidth of the widget.
hHeight of the widget.

Definition at line 277 of file news.c.

Variable Documentation

◆ buf

char buf[NEWS_MAX_LENGTH]
static

News line buffer.

Definition at line 45 of file news.c.

◆ largestID

int largestID
static

Save/load

Definition at line 59 of file news.c.

◆ len

int len
static

Definition at line 46 of file news.c.

◆ news_drag

int news_drag = 0
static

Is dragging news?

Definition at line 49 of file news.c.

◆ news_font

glFont* news_font = &gl_defFont
static

Font to use.

Definition at line 51 of file news.c.

◆ news_lines

char** news_lines = NULL
static

Array (array.h) of each line's text.

Definition at line 52 of file news.c.

◆ news_list

news_t* news_list = NULL

Linked list containing all articles

Definition at line 39 of file news.c.

◆ news_pos

double news_pos = 0.
static

Position of the news feed.

Definition at line 50 of file news.c.

◆ news_restores

glFontRestore* news_restores = NULL
static

Array (array.h) of restorations.

Definition at line 53 of file news.c.

◆ news_tick

unsigned int news_tick = 0
static

Last news tick.

Definition at line 48 of file news.c.

◆ next_id

int next_id = 0
static

next number to use as ID

Definition at line 40 of file news.c.

◆ textlength

double textlength = 0.
static

Definition at line 54 of file news.c.