Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_ui_wrappers.c File Reference
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sf_ui_wrappers.h"
#include "sf_wrappers.h"
#include "sf_hooks.h"
#include "hooks/sf_menu_hook.h"
#include "hooks/sf_console_hook.h"
#include "hooks/sf_vanilla_fix_hook.h"
#include "../registry/sf_mod_registry.h"
#include "../registry/sf_error_registry.h"
Include dependency graph for sf_ui_wrappers.c:

Go to the source code of this file.

Macros

#define MOD_LIST_ROWS   11
 Number of mod rows the left panel can show at once.
#define MOD_ROW_X   108
#define MOD_ROW_Y_START   40
#define MOD_ROW_PITCH   44
#define MOD_ROW_WIDTH   227
#define MOD_ROW_HEIGHT   36
#define MOD_NAV_Y   540
#define MOD_INFO_PANEL_WIDTH   443
#define MOD_INFO_TITLE_Y   34
#define MOD_INFO_TITLE_H   34
#define MOD_INFO_AUTHOR_Y   62
#define MOD_INFO_AUTHOR_H   28
#define MOD_INFO_TYPE_Y   98
#define MOD_INFO_TYPE_H   28
#define MOD_INFO_DESC_Y   136
#define MOD_INFO_DESC_H   248
#define MOD_INFO_ERROR_Y   396
#define MOD_INFO_ERROR_H   200
#define MOD_GLYPH_WIDTH   8
 Approximate pixel width of one glyph in the info panel fonts.
#define MOD_TITLE_RGB   0.85f, 0.64f, 0.12f
#define MOD_AUTHOR_RGB   0.75f, 0.75f, 0.75f
#define MOD_TYPE_RGB   0.45f, 0.72f, 0.95f
#define MOD_ERROR_RGB   1.0f, 0.0f, 0.0f
#define MOD_INFO_WRAP   50

Functions

void wrap_text (const char *input, char *output, size_t max_width)
 Wraps text to a character width, inserting newlines.
void __thiscall SFStringConstructor (SF_String *_this)
 Zero-initializes an SF_String (no allocation). Moved here from sf_vanilla_fix_hook.c; exposed as uiAPI.SFStringConstructor.
SF_String *__thiscall SFStringConstructor_char (SF_String *_this, const char *char_string)
 Constructs an SF_String from a null-terminated char string. Moved here from sf_vanilla_fix_hook.c; exposed as uiAPI.SFStringConstructor_char.
void __thiscall updateLabelText (CMnuLabel *label, const char *text)
void reset_mod_list_screen ()
 Drops every cached mod list pointer, this will ensure we don't crash after a map load.
int calculate_total_unique_mods ()
int calculate_total_pages (int total_unique_mods, int mods_per_page)
int normalize_page_index (int page, int total_pages)
void prepare_mod_title (SFMod *parent_mod, char *mod_title, size_t buffer_size)
void prepare_mod_author (SFMod *parent_mod, char *mod_author, size_t buffer_size)
void prepare_mod_description (SFMod *parent_mod, char *mod_description, size_t description_buffer_size, char *wrapped_description, size_t wrapped_buffer_size)
void prepare_mod_page_info (int page, int total_pages, char *mod_page_info, size_t buffer_size)
void prepare_mod_error_info (SFMod *parent_mod, char *mod_error_info, size_t error_buffer_size, char *wrapped_error_info, size_t wrapped_buffer_size)
void set_centred_label_text (CMnuLabel *label, const char *text, int panel_width, int y, int height)
 Repositions a label so its text block sits centred, then sets the text.
void apply_label_colour (CMnuLabel *label, float red, float green, float blue)
 Sets both colour slots of a label. (normal and on hover).
void show_mod_details (int mod_index)
 Renders one mod into the right hand info panel.
void refresh_mod_list_page (int page)
 Points the visible rows at the mods on the given page.
void __thiscall on_mod_selected (CMnuSmpButton *button)
 Left panel row callback.
void build_mod_list_panel (CMnuContainer *list_panel)
 Creates the clickable mod rows, the paging arrows and the counter.
void build_mod_info_panel (CMnuContainer *info_panel)
 Creates the right hand panel's labels.
void __fastcall close_mod_list_callback (CMnuSmpButton *button, int32_t *cui_menu_ptr_maybe)
CMnuContainer *__thiscall createContainer (uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *background_msb, const char *border_msb, float alpha)
void add_close_button (CMnuContainer *mod_list)
void __thiscall show_mod_list (CMnuSmpButton *button)
CMnuSmpButton *__thiscall attachNewButton (CMnuContainer *parent, char *button_mesh_default, char *button_mesh_pressed, char *button_initial_load_mesh, char *button_mesh_disabled, char *label_char, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height, int button_index, uint32_t callback_func_ptr)
SFModcreateModInfo (const char *mod_id, const char *mod_version, const char *mod_author, const char *mod_description)
CMnuLabel *__thiscall attachMeshedLabel (CMnuLabel *new_label, CMnuContainer *parent, char *mesh_char, char *label_char, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height)
CMnuLabel *__thiscall attachLabel (CMnuLabel *label_ptr, CMnuContainer *parent, char *label_chars, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height)

Variables

CMnuContainermod_list
CMnuContainermod_container
CMnuContainermod_info_page
CMnuLabelmod_list_title
CMnuSmpButtonleft_nav
CMnuSmpButtonright_nav

Macro Definition Documentation

◆ MOD_AUTHOR_RGB

#define MOD_AUTHOR_RGB   0.75f, 0.75f, 0.75f

Definition at line 153 of file sf_ui_wrappers.c.

◆ MOD_ERROR_RGB

#define MOD_ERROR_RGB   1.0f, 0.0f, 0.0f

Definition at line 155 of file sf_ui_wrappers.c.

◆ MOD_GLYPH_WIDTH

#define MOD_GLYPH_WIDTH   8

Approximate pixel width of one glyph in the info panel fonts.

Used to centre a text block by measurement - label flags are undocumented. So labels are simply positioned so the widest line sits centred in the panel. this is all just an approximation.

Definition at line 149 of file sf_ui_wrappers.c.

◆ MOD_INFO_AUTHOR_H

#define MOD_INFO_AUTHOR_H   28

Definition at line 134 of file sf_ui_wrappers.c.

◆ MOD_INFO_AUTHOR_Y

#define MOD_INFO_AUTHOR_Y   62

Definition at line 133 of file sf_ui_wrappers.c.

◆ MOD_INFO_DESC_H

#define MOD_INFO_DESC_H   248

Definition at line 138 of file sf_ui_wrappers.c.

◆ MOD_INFO_DESC_Y

#define MOD_INFO_DESC_Y   136

Definition at line 137 of file sf_ui_wrappers.c.

◆ MOD_INFO_ERROR_H

#define MOD_INFO_ERROR_H   200

Definition at line 140 of file sf_ui_wrappers.c.

◆ MOD_INFO_ERROR_Y

#define MOD_INFO_ERROR_Y   396

Definition at line 139 of file sf_ui_wrappers.c.

◆ MOD_INFO_PANEL_WIDTH

#define MOD_INFO_PANEL_WIDTH   443

Definition at line 130 of file sf_ui_wrappers.c.

◆ MOD_INFO_TITLE_H

#define MOD_INFO_TITLE_H   34

Definition at line 132 of file sf_ui_wrappers.c.

◆ MOD_INFO_TITLE_Y

#define MOD_INFO_TITLE_Y   34

Definition at line 131 of file sf_ui_wrappers.c.

◆ MOD_INFO_TYPE_H

#define MOD_INFO_TYPE_H   28

Definition at line 136 of file sf_ui_wrappers.c.

◆ MOD_INFO_TYPE_Y

#define MOD_INFO_TYPE_Y   98

Definition at line 135 of file sf_ui_wrappers.c.

◆ MOD_INFO_WRAP

#define MOD_INFO_WRAP   50

Definition at line 223 of file sf_ui_wrappers.c.

◆ MOD_LIST_ROWS

#define MOD_LIST_ROWS   11

Number of mod rows the left panel can show at once.

Definition at line 121 of file sf_ui_wrappers.c.

◆ MOD_NAV_Y

#define MOD_NAV_Y   540

Definition at line 128 of file sf_ui_wrappers.c.

◆ MOD_ROW_HEIGHT

#define MOD_ROW_HEIGHT   36

Definition at line 127 of file sf_ui_wrappers.c.

◆ MOD_ROW_PITCH

#define MOD_ROW_PITCH   44

Definition at line 125 of file sf_ui_wrappers.c.

◆ MOD_ROW_WIDTH

#define MOD_ROW_WIDTH   227

Definition at line 126 of file sf_ui_wrappers.c.

◆ MOD_ROW_X

#define MOD_ROW_X   108

Definition at line 123 of file sf_ui_wrappers.c.

◆ MOD_ROW_Y_START

#define MOD_ROW_Y_START   40

Definition at line 124 of file sf_ui_wrappers.c.

◆ MOD_TITLE_RGB

#define MOD_TITLE_RGB   0.85f, 0.64f, 0.12f

Info panel label colours, as red, green, blue argument triples.

Definition at line 152 of file sf_ui_wrappers.c.

◆ MOD_TYPE_RGB

#define MOD_TYPE_RGB   0.45f, 0.72f, 0.95f

Definition at line 154 of file sf_ui_wrappers.c.

Function Documentation

◆ add_close_button()

void add_close_button ( CMnuContainer * mod_list)

Definition at line 581 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_label_colour()

void apply_label_colour ( CMnuLabel * label,
float red,
float green,
float blue )

Sets both colour slots of a label. (normal and on hover).

Sets a label's normal and highlight colours in one call.

Sets both colour slots of a label. (normal and on hover).

Definition at line 293 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ attachLabel()

CMnuLabel *__thiscall attachLabel ( CMnuLabel * label_ptr,
CMnuContainer * parent,
char * label_chars,
uint8_t font_index,
uint16_t x_pos,
uint16_t y_pos,
uint16_t width,
uint16_t height )

Definition at line 876 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attachMeshedLabel()

CMnuLabel *__thiscall attachMeshedLabel ( CMnuLabel * new_label,
CMnuContainer * parent,
char * mesh_char,
char * label_char,
uint8_t font_index,
uint16_t x_pos,
uint16_t y_pos,
uint16_t width,
uint16_t height )

Definition at line 833 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attachNewButton()

CMnuSmpButton *__thiscall attachNewButton ( CMnuContainer * parent,
char * button_mesh_default,
char * button_mesh_pressed,
char * button_initial_load_mesh,
char * button_mesh_disabled,
char * label_char,
uint8_t font_index,
uint16_t x_pos,
uint16_t y_pos,
uint16_t width,
uint16_t height,
int button_index,
uint32_t callback_func_ptr )

Definition at line 692 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_mod_info_panel()

void build_mod_info_panel ( CMnuContainer * info_panel)

Creates the right hand panel's labels.

Definition at line 489 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_mod_list_panel()

void build_mod_list_panel ( CMnuContainer * list_panel)

Creates the clickable mod rows, the paging arrows and the counter.

Definition at line 442 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_total_pages()

int calculate_total_pages ( int total_unique_mods,
int mods_per_page )

Definition at line 199 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ calculate_total_unique_mods()

int calculate_total_unique_mods ( )

Definition at line 194 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_mod_list_callback()

void __fastcall close_mod_list_callback ( CMnuSmpButton * button,
int32_t * cui_menu_ptr_maybe )

Definition at line 525 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ createContainer()

CMnuContainer *__thiscall createContainer ( uint16_t x,
uint16_t y,
uint16_t width,
uint16_t height,
const char * background_msb,
const char * border_msb,
float alpha )

Definition at line 537 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createModInfo()

SFMod * createModInfo ( const char * mod_id,
const char * mod_version,
const char * mod_author,
const char * mod_description )

Definition at line 781 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalize_page_index()

int normalize_page_index ( int page,
int total_pages )

Definition at line 205 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ on_mod_selected()

void __thiscall on_mod_selected ( CMnuSmpButton * button)

Left panel row callback.

Definition at line 398 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_mod_author()

void prepare_mod_author ( SFMod * parent_mod,
char * mod_author,
size_t buffer_size )

Definition at line 217 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ prepare_mod_description()

void prepare_mod_description ( SFMod * parent_mod,
char * mod_description,
size_t description_buffer_size,
char * wrapped_description,
size_t wrapped_buffer_size )

Definition at line 225 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_mod_error_info()

void prepare_mod_error_info ( SFMod * parent_mod,
char * mod_error_info,
size_t error_buffer_size,
char * wrapped_error_info,
size_t wrapped_buffer_size )

Definition at line 240 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_mod_page_info()

void prepare_mod_page_info ( int page,
int total_pages,
char * mod_page_info,
size_t buffer_size )

Definition at line 234 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ prepare_mod_title()

void prepare_mod_title ( SFMod * parent_mod,
char * mod_title,
size_t buffer_size )

Definition at line 210 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ refresh_mod_list_page()

void refresh_mod_list_page ( int page)

Points the visible rows at the mods on the given page.

Definition at line 362 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_mod_list_screen()

void reset_mod_list_screen ( )

Drops every cached mod list pointer, this will ensure we don't crash after a map load.

Forgets the cached mod list screen so the next open rebuilds it.

Drops every cached mod list pointer, this will ensure we don't crash after a map load.

Must be called every time the main menu is constructed - the engine destroys the menu's control tree (and our containers with it) when a game loads.

Definition at line 166 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ set_centred_label_text()

void set_centred_label_text ( CMnuLabel * label,
const char * text,
int panel_width,
int y,
int height )

Repositions a label so its text block sits centred, then sets the text.

Repositions a label so its widest line sits centred in panel_width, then sets its text. Used by the mod list and custom campaign detail panels.

Repositions a label so its text block sits centred, then sets the text.

Definition at line 280 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ SFStringConstructor()

void __thiscall SFStringConstructor ( SF_String * _this)

Zero-initializes an SF_String (no allocation). Moved here from sf_vanilla_fix_hook.c; exposed as uiAPI.SFStringConstructor.

Definition at line 56 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ SFStringConstructor_char()

SF_String *__thiscall SFStringConstructor_char ( SF_String * _this,
const char * char_string )

Constructs an SF_String from a null-terminated char string. Moved here from sf_vanilla_fix_hook.c; exposed as uiAPI.SFStringConstructor_char.

Note
Relies on uiAPI.SFStringSetLength, which is registered at the very top of initialize_data_hooks() before any code path that can call this.

Definition at line 70 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_mod_details()

void show_mod_details ( int mod_index)

Renders one mod into the right hand info panel.

The labels are created once per menu session by build_mod_info_panel();

Definition at line 324 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_mod_list()

void __thiscall show_mod_list ( CMnuSmpButton * button)

Definition at line 606 of file sf_ui_wrappers.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateLabelText()

void __thiscall updateLabelText ( CMnuLabel * label,
const char * text )

Helper function to update label text using SF_String

Parameters
labelThe label to update
textNew text to set

Definition at line 94 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

◆ wrap_text()

void wrap_text ( const char * input,
char * output,
size_t max_width )

Wraps text to a character width, inserting newlines.

Definition at line 16 of file sf_ui_wrappers.c.

Here is the caller graph for this function:

Variable Documentation

◆ left_nav

CMnuSmpButton* left_nav

Definition at line 113 of file sf_ui_wrappers.c.

◆ mod_container

CMnuContainer* mod_container

Definition at line 109 of file sf_ui_wrappers.c.

◆ mod_info_page

CMnuContainer* mod_info_page

Definition at line 110 of file sf_ui_wrappers.c.

◆ mod_list

CMnuContainer* mod_list

Definition at line 108 of file sf_ui_wrappers.c.

◆ mod_list_title

CMnuLabel* mod_list_title

Definition at line 112 of file sf_ui_wrappers.c.

◆ right_nav

CMnuSmpButton* right_nav

Definition at line 114 of file sf_ui_wrappers.c.