naev 0.12.5
news.c File Reference

Handles news generation. More...

#include "news.h"
#include "array.h"
#include "faction.h"
#include "log.h"
#include "nstring.h"
#include "ntime.h"
#include "nxml.h"
#include "toolkit.h"
Include dependency graph for news.c:

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
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 26 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 311 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 202 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 94 of file news.c.

◆ news_cmp()

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

Definition at line 67 of file news.c.

◆ news_exit()

void news_exit ( void )

Kills the old news thread.

Definition at line 139 of file news.c.

◆ news_focusLose()

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

Called when it's de-focused.

Definition at line 323 of file news.c.

◆ news_free()

void news_free ( news_t * n)

Definition at line 179 of file news.c.

◆ news_get()

news_t * news_get ( int id)

gets the article with id ID, else NULL

Definition at line 169 of file news.c.

◆ news_init()

int news_init ( void )

Initiate news linked list with a stack.

Definition at line 123 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 487 of file news.c.

◆ news_mouse()

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 343 of file news.c.

◆ news_parseArticle()

int news_parseArticle ( xmlNodePtr parent)
static

Parses articles.

Parameters
parentParent node to parse.
Returns
0 on success.

Definition at line 516 of file news.c.

◆ news_render()

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 393 of file news.c.

◆ news_rm()

void news_rm ( int id)

Definition at line 187 of file news.c.

◆ news_saveArticles()

int news_saveArticles ( xmlTextWriterPtr writer)

Definition at line 446 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 273 of file news.c.

Variable Documentation

◆ buf

char buf[NEWS_MAX_LENGTH]
static

News line buffer.

Definition at line 37 of file news.c.

◆ largestID

int largestID
static

Save/load

Definition at line 52 of file news.c.

◆ len

int len
static

Definition at line 38 of file news.c.

◆ news_drag

int news_drag = 0
static

Is dragging news?

Definition at line 41 of file news.c.

◆ news_font

glFont* news_font = &gl_defFont
static

Font to use.

Definition at line 43 of file news.c.

◆ news_lines

char** news_lines = NULL
static

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

Definition at line 44 of file news.c.

◆ news_list

news_t* news_list = NULL

Linked list containing all articles

Definition at line 31 of file news.c.

◆ news_pos

double news_pos = 0.
static

Position of the news feed.

Definition at line 42 of file news.c.

◆ news_restores

glFontRestore* news_restores
static
Initial value:
=
NULL

Array (array.h) of restorations.

Definition at line 45 of file news.c.

◆ news_tick

unsigned int news_tick = 0
static

Last news tick.

Definition at line 40 of file news.c.

◆ next_id

int next_id = 0
static

next number to use as ID

Definition at line 32 of file news.c.

◆ textlength

double textlength = 0.
static

Definition at line 47 of file news.c.