Added "print_text" script function

This commit is contained in:
NovaRain
2020-10-05 14:38:53 +08:00
parent 51dfee26d3
commit ac28d7293b
8 changed files with 77 additions and 11 deletions
+2
View File
@@ -348,6 +348,8 @@
#define obj_under_cursor(onlyCritter, includeDude) sfall_func2("obj_under_cursor", onlyCritter, includeDude)
#define objects_in_radius(tile, radius, elev, type) sfall_func4("objects_in_radius", tile, radius, elev, type)
#define outlined_object sfall_func0("outlined_object")
#define print_text(text, winType, x, y, color) sfall_func5("print_text", text, winType, x, y, color)
#define print_text_width(text, winType, x, y, color, w) sfall_func6("print_text", text, winType, x, y, color, w)
#define real_dude_obj sfall_func0("real_dude_obj")
#define remove_all_timer_events sfall_func0("remove_timer_event")
#define remove_timer_event(fixedParam) sfall_func1("remove_timer_event", fixedParam)
+20 -8
View File
@@ -676,7 +676,7 @@ optional argument:
- displays the specified hidden script window or the one previously hidden with the sfall_func0("hide_window") function
- winName: the window name, assigned to the window by the CreateWin/create_win function
> void sfall_func3("set_window_flag", string/int winName/winID, int flag, bool value)
> void sfall_func3("set_window_flag", string winName/int winID, int flag, bool value)
- changes the specified flag for the created script or game interface window
- winName: the window name, assigned to the window by the CreateWin/create_win function
- winID: the ID number of the interface or script window obtained with the get_window_under_mouse function, or 0 for the current game interface
@@ -734,16 +734,16 @@ optional arguments:
- flags: mode flags (see MSGBOX_* constants in define_extra.h). Pass -1 to skip setting the flags (default flags are NORMAL and YESNO)
- color1/color2: the color index in Fallout palette. color1 sets the text color for the first line, and color2 for all subsequent lines of text (default color is 145)
> int sfall_func1("get_stat_min", stat)
> int sfall_func1("get_stat_max", stat)
> int sfall_func2("get_stat_min", stat, bool who)
> int sfall_func2("get_stat_max", stat, bool who)
> int sfall_func1("get_stat_min", int stat)
> int sfall_func1("get_stat_max", int stat)
> int sfall_func2("get_stat_min", int stat, bool who)
> int sfall_func2("get_stat_max", int stat, bool who)
- returns the maximum or minimum set value of the specified stat (see set_stat_max/min functions)
- who: 0 (false) or omitting the argument - returns the value of the player, 1 (true) - returns the value set for other critters
> int sfall_func4("interface_art_draw", int winType, string/int artFile/artId, int x, int y)
> int sfall_func5("interface_art_draw", int winType, string/int artFile/artId, int x, int y, int frame)
> int sfall_func6("interface_art_draw", int winType, string/int artFile/artId, int x, int y, int frame, array param)
> int sfall_func4("interface_art_draw", int winType, string artFile/int artID, int x, int y)
> int sfall_func5("interface_art_draw", int winType, string artFile/int artID, int x, int y, int frame)
> int sfall_func6("interface_art_draw", int winType, string artFile/int artID, int x, int y, int frame, array param)
- draws the specified PCX or FRM image in the game interface window, returns -1 in case of any error
- winType: the type number of the interface window (see WINTYPE_* constants in sfall.h)
this also takes the value of the flag (0x10000) to prevent immediate redrawing of the interface window
@@ -755,6 +755,18 @@ optional arguments:
index 0 - sprite direction for multi-directional FRM
index 1/index 2 - the new width/height to scale the image to. Pass -1 to use the original width/height
> int sfall_func5("print_text", string text, int winType, int x, int y, int color)
> int sfall_func6("print_text", string text, int winType, int x, int y, int color, int width)
- displays the text in the specified interface window with the current font. Use vanilla SetFont function to set the font
- text: the text to be printed. Use the \n control character to move text to a new line (example: "Hello\nWorld!")
- winType: the type number of the interface window (see WINTYPE_* constants in sfall.h)
- x/y: offset relative to the top-left corner of the window
- color: the color index in Fallout palette. Pass 0 if the text color was previously set by vanilla SetTextColor function
it can also take additional flags (via bwor) for displaying text:
0x0010000 - adds a shadow to the text, the 'textshadow' compiler constant
0x2000000 - fills the background of the text with black color, the 'textnofill' compiler constant (works the other way around)
- width: the maximum width of the text. The text will be wrapped to fit within the specified width
------------------------
------ MORE INFO -------
------------------------
+11 -2
View File
@@ -103,6 +103,10 @@ void dev_printf(...) {}
__asm push arg8 \
WRAP_WATCOM_FCALL7(offs, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
#define WRAP_WATCOM_FCALL9(offs, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
__asm push arg9 \
WRAP_WATCOM_FCALL8(offs, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
// prints message to debug.log file
void __declspec(naked) debug_printf(const char* fmt, ...) {
__asm jmp fo::funcoffs::debug_printf_;
@@ -266,10 +270,10 @@ void __fastcall window_trans_cscale(long i_width, long i_height, long s_width, l
push w_width;
push s_height;
push s_width;
mov ebx, edx; // i_height
mov edx, ecx; // i_width
call fo::funcoffs::windowGetBuffer_;
add eax, xy_shift;
mov ebx, edx; // i_height
mov edx, ecx; // i_width
push eax; // to_buff
mov eax, data;
call fo::funcoffs::trans_cscale_; // *from_buff<eax>, i_width<edx>, i_height<ebx>, i_width2<ecx>, to_buff, width, height, to_width
@@ -481,6 +485,11 @@ long __fastcall get_game_config_string(const char* outValue, const char* section
WRAP_WATCOM_FCALL8(name##_, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
}
#define WRAP_WATCOM_FFUNC9(retType, name, arg1t, arg1, arg2t, arg2, arg3t, arg3, arg4t, arg4, arg5t, arg5, arg6t, arg6, arg7t, arg7, arg8t, arg8, arg9t, arg9) \
retType __fastcall name(arg1t arg1, arg2t arg2, arg3t arg3, arg4t arg4, arg5t arg5, arg6t arg6, arg7t arg7, arg8t arg8, arg9t arg9) { \
WRAP_WATCOM_FCALL9(name##_, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
}
#include "Functions_def.h"
}
+4
View File
@@ -129,6 +129,9 @@ long __fastcall get_game_config_string(const char* outValue, const char* section
#define WRAP_WATCOM_FFUNC8(retType, name, arg1t, arg1, arg2t, arg2, arg3t, arg3, arg4t, arg4, arg5t, arg5, arg6t, arg6, arg7t, arg7, arg8t, arg8) \
retType __fastcall name(arg1t arg1, arg2t arg2, arg3t arg3, arg4t arg4, arg5t arg5, arg6t arg6, arg7t arg7, arg8t arg8);
#define WRAP_WATCOM_FFUNC9(retType, name, arg1t, arg1, arg2t, arg2, arg3t, arg3, arg4t, arg4, arg5t, arg5, arg6t, arg6, arg7t, arg7, arg8t, arg8, arg9t, arg9) \
retType __fastcall name(arg1t arg1, arg2t arg2, arg3t arg3, arg4t arg4, arg5t arg5, arg6t arg6, arg7t arg7, arg8t arg8, arg9t arg9);
#include "Functions_def.h"
#undef WRAP_WATCOM_FUNC0
@@ -148,6 +151,7 @@ long __fastcall get_game_config_string(const char* outValue, const char* section
#undef WRAP_WATCOM_FFUNC6
#undef WRAP_WATCOM_FFUNC7
#undef WRAP_WATCOM_FFUNC8
#undef WRAP_WATCOM_FFUNC9
}
}
+1
View File
@@ -49,6 +49,7 @@ WRAP_WATCOM_FFUNC3(long, scr_set_local_var, long, sid, long, varId, long, value)
WRAP_WATCOM_FFUNC3(long, tile_num_in_direction, long, tile, long, rotation,long, distance)
WRAP_WATCOM_FFUNC8(void, trans_cscale, void*, fromBuff, long, width, long, height, long, pitch, void*, toBuff, long, toWidth, long, toHeight, long, toPitch)
WRAP_WATCOM_FFUNC3(void, win_clip, Window*, window, RectList**, rects, void*, buffer)
WRAP_WATCOM_FFUNC9(long, windowWrapLineWithSpacing, long, winID, const char*, text, long, width, long, height, long, x, long, y, long, color, long, alignment, long, unknown)
WRAP_WATCOM_FFUNC3(const char*, interpretGetString, Program*, scriptPtr, DWORD, dataType, DWORD, strId)
+36 -1
View File
@@ -269,7 +269,7 @@ void mf_intface_redraw(OpcodeContext& ctx) {
if (ctx.arg(0).rawValue() == 0) {
fo::func::intface_redraw();
} else {
fo::func::RefreshGNW(1); // redraw all interfaces
fo::func::RefreshGNW(2); // fake redraw all interfaces (TODO: need a real redraw of interfaces)
}
}
@@ -420,6 +420,7 @@ void mf_hide_window(OpcodeContext& ctx) {
void mf_set_window_flag(OpcodeContext& ctx) {
long bitFlag = ctx.arg(1).rawValue();
switch (bitFlag) {
case fo::WinFlags::DontMoveTop:
case fo::WinFlags::MoveOnTop:
case fo::WinFlags::Hidden:
case fo::WinFlags::Exclusive:
@@ -707,5 +708,39 @@ void mf_get_window_attribute(OpcodeContext& ctx) {
ctx.setReturn(result);
}
void mf_print_text(OpcodeContext& ctx) { // same as vanilla PrintRect
fo::Window* win = Interface::GetWindow(ctx.arg(1).rawValue());
if (win == nullptr || (int)win == -1) {
ctx.printOpcodeError("%s() - the game interface window is not created or invalid value for the interface.", ctx.getMetaruleName());
ctx.setReturn(-1);
return;
}
const char* text = ctx.arg(0).strValue();
long x = ctx.arg(2).rawValue();
long y = ctx.arg(3).rawValue();
long color = ctx.arg(4).rawValue();
long width = ctx.arg(5).rawValue();
int maxHeight = win->height - y;
int maxWidth = win->width - x;
if (width <= 0) {
width = maxWidth;
} else if (width > maxWidth) {
width = maxWidth;
}
color ^= 0x2000000; // fills background with black color if the flag is set
if ((color & 0xFF) == 0) {
__asm call fo::funcoffs::windowGetTextColor_; // set from SetTextColor
__asm mov byte ptr color, al;
}
if (color & 0x10000) { // shadow
fo::func::windowWrapLineWithSpacing(win->wID, text, width, maxHeight, x, y, 0x201000F, 0, 0);
color ^= 0x10000;
}
ctx.setReturn(fo::func::windowWrapLineWithSpacing(win->wID, text, width, maxHeight, x, y, color, 0, 0));
fo::func::GNW_win_refresh(win, &win->rect, 0);
}
}
}
@@ -117,5 +117,7 @@ void mf_unwield_slot(OpcodeContext&);
void mf_get_window_attribute(OpcodeContext&);
void mf_print_text(OpcodeContext& ctx);
}
}
@@ -116,6 +116,7 @@ static const SfallMetarule metarules[] = {
{"obj_under_cursor", mf_obj_under_cursor, 2, 2, 0, {ARG_INT, ARG_INT}},
{"objects_in_radius", mf_objects_in_radius, 3, 4, 0, {ARG_INT, ARG_INT, ARG_INT, ARG_INT}},
{"outlined_object", mf_outlined_object, 0, 0},
{"print_text", mf_print_text, 5, 6, -1, {ARG_STRING, ARG_INT, ARG_INT, ARG_INT, ARG_INT, ARG_INT}},
{"real_dude_obj", mf_real_dude_obj, 0, 0},
{"remove_timer_event", mf_remove_timer_event, 0, 1, -1, {ARG_INT}},
{"set_can_rest_on_map", mf_set_rest_on_map, 3, 3, -1, {ARG_INT, ARG_INT, ARG_INT}},