Added "interface_art_draw" script function

Added an argument to "intface_redraw" function to redraw all interfaces.
This commit is contained in:
NovaRain
2020-09-26 22:17:59 +08:00
parent 52f42af913
commit 75b275159f
13 changed files with 130 additions and 23 deletions
+7 -2
View File
@@ -70,6 +70,7 @@
#define WINTYPE_CHARACTER (5)
#define WINTYPE_SKILLDEX (6)
#define WINTYPE_ESCMENU (7) // escape menu
#define WINTYPE_AUTOMAP (8)
//Valid flags for force_encounter_with_flags
#define ENCOUNTER_FLAG_NO_CAR (0x1)
@@ -268,8 +269,8 @@
#define critter_inven_obj2(obj, type) sfall_func2("critter_inven_obj2", obj, type)
#define dialog_obj sfall_func0("dialog_obj")
#define display_stats sfall_func0("display_stats")
#define draw_image(pathFile, frame, x, y, noTrans) sfall_func5("draw_image", pathFile, frame, x, y, noTrans)
#define draw_image_scaled(pathFile, frame, x, y, w, h) sfall_func6("draw_image_scaled", pathFile, frame, x, y, w, h)
#define draw_image(artFile, frame, x, y, noTrans) sfall_func5("draw_image", artFile, frame, x, y, noTrans)
#define draw_image_scaled(artFile, frame, x, y, w, h) sfall_func6("draw_image_scaled", artFile, frame, x, y, w, h)
#define exec_map_update_scripts sfall_func0("exec_map_update_scripts")
#define floor2(value) sfall_func1("floor2", value)
#define get_current_inven_size(obj) sfall_func1("get_current_inven_size", obj)
@@ -289,6 +290,10 @@
#define get_sfall_arg_at(argNum) sfall_func1("get_sfall_arg_at", argNum)
#define get_text_width(text) sfall_func1("get_text_width", text)
#define hide_window(winName) sfall_func1("hide_window", winName)
#define interface_art_draw(winID, artFile, x, y) sfall_func4("interface_art_draw", winID, artFile, x, y)
#define interface_art_draw_frame(wID, art, x, y, frame) sfall_func5("interface_art_draw", wID, art, x, y, frame)
#define interface_art_draw_ex(wID, art, x, y, frm, prm) sfall_func6("interface_art_draw", wID, art, x, y, frm, prm)
#define interface_redraw_all sfall_func1("intface_redraw", 1)
#define intface_hide sfall_func0("intface_hide")
#define intface_is_hidden sfall_func0("intface_is_hidden")
#define intface_is_shown(winType) sfall_func1("get_window_attribute", winType)
+24 -9
View File
@@ -341,7 +341,7 @@ Some utility/math functions are available:
- returns first object blocking given tile using given blocking function or 0 if tile is clear
> array tile_get_objs(int tileNum, int elevation)
- returns array of all objects at given tile
- returns an array of all objects at given tile
- it will include any hidden, dead or system objects (like cursor), so make sure to check properly when iterating
> array party_member_list(int includeHidden)
@@ -387,8 +387,9 @@ Some utility/math functions are available:
- works just like vanilla critter_inven_obj, but correctly reports item in player's inactive hand slot
> void sfall_func0("intface_redraw")
- redraws main game interface
- useful after direct changes to current player weapons or stats to reflect changes
> void sfall_func1("intface_redraw", bool eachWin)
- redraws main game interface, useful to reflect changes after directly changing current player weapons or stats
- eachWin: pass True to redraw all interface windows
> void sfall_func0("intface_hide")
- hides main interface
@@ -534,15 +535,15 @@ Some utility/math functions are available:
- there is also a unique ID number range for the player and party members from 18000 to 83535
- to assign a new ID number generated by the engine to the object (i.e. unassign a unique ID), call the function with two arguments and pass -1 for the flag argument
> void sfall_func5("draw_image", string/int pathFile/artId, int frame, int x, int y, bool noTransparent)
> void sfall_func6("draw_image_scaled", string/int pathFile/artId, int frame, int x, int y, int width, int height)
> void sfall_func5("draw_image", string/int artFile/artId, int frame, int x, int y, bool noTransparent)
> void sfall_func6("draw_image_scaled", string/int artFile/artId, int frame, int x, int y, int width, int height)
- displays the specified PCX or FRM image in the active window created by vanilla CreateWin or sfall's create_win script function
- pathFile/artId: path to the PCX/FRM file (e.g. "art\\inven\\5mmap.frm"), or its FRM ID number (e.g. 0x7000026, see specification of the FID format)
- artFile/artId: path to the PCX/FRM file (e.g. "art\\inven\\5mmap.frm"), or its FRM ID number (e.g. 0x7000026, see specification of the FID format)
optional arguments:
- frame: frame number, the first frame starts from zero
- x/y: offset relative to the top-left corner of the window
- width/height: image size, used to scale the image when displaying it. Pass -1 to either width or height to keep the aspect ratio when scaling
- noTransparent: pass true to display an image without transparent background
- width/height: the new width/height to scale the image to. Pass -1 to either width or height to keep the aspect ratio when scaling
- noTransparent: pass True to display an image without transparent background
- NOTE: to omit optional arguments starting from the right, call the functions with different sfall_funcX (e.g. sfall_func4("draw_image", pathFile, frame, x, y))
- if draw_image_scaled is called without x/y/width/height arguments, the image will be scaled to fit the window without transparent background
@@ -637,7 +638,7 @@ optional arguments:
- message: the text in the dialog box. Use the \n control character to move text to a new line (example: "Hello\nWorld!")
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/2: 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)
- 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)
@@ -646,6 +647,20 @@ optional arguments:
- 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)
- 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
- artFile/artId: path to the PCX/FRM file (e.g. "art\\inven\\5mmap.frm"), or its FRM ID number (e.g. 0x7000026, see specification of the FID format)
- x/y: offset relative to the top-left corner of the window
optional arguments:
- frame: frame number, the first frame starts from zero
- param: an array which specifies additional parameters:
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
------------------------
------ MORE INFO -------
------------------------
+11 -2
View File
@@ -580,8 +580,12 @@ void __stdcall SetArray(DWORD id, DWORD key, DWORD keyType, DWORD val, DWORD val
}
int __stdcall LenArray(DWORD id) {
if (arrays.find(id) == arrays.end()) return -1;
return arrays[id].size();
array_itr it = arrays.find(id);
return (it != arrays.end()) ? it->second.size() : -1;
}
bool __stdcall ArrayExist(DWORD id) {
return (arrays.find(id) != arrays.end());
}
template <class T>
@@ -791,3 +795,8 @@ long __stdcall StackArray(DWORD key, DWORD keyType, DWORD val, DWORD valType) {
SetArray(id, key, keyType, val, valType, 0);
return 0;
}
sArrayVar* __stdcall GetRawArray(DWORD id) {
array_itr it = arrays.find(id);
return (it != arrays.end()) ? &it->second : nullptr;
}
+4
View File
@@ -182,6 +182,8 @@ void __stdcall SetArray(DWORD id, DWORD key, DWORD keyType, DWORD val, DWORD val
// number of elements in list or pairs in map
int __stdcall LenArray(DWORD id);
bool __stdcall ArrayExist(DWORD id);
// change array size (only works with list)
void __stdcall ResizeArray(DWORD id, int newlen);
@@ -199,3 +201,5 @@ void __stdcall SaveArray(DWORD key, DWORD keyType, DWORD id);
// special function that powers array expressions
long __stdcall StackArray(DWORD key, DWORD keyType, DWORD val, DWORD valType);
sArrayVar* __stdcall GetRawArray(DWORD id);
+2 -2
View File
@@ -1608,9 +1608,9 @@ void RedrawObject(TGameObj* obj) {
}
// Redraws all interface windows
void RefreshGNW() {
void RefreshGNW(size_t from) {
*(DWORD*)_doing_refresh_all = 1;
for (size_t i = 0; i < *ptr_num_windows; i++) {
for (size_t i = from; i < *ptr_num_windows; i++) {
GNWWinRefresh(ptr_window[i], ptr_scr_size, 0);
}
*(DWORD*)_doing_refresh_all = 0;
+1 -1
View File
@@ -1333,6 +1333,6 @@ DWORD __stdcall GetMaxCharWidth();
void RedrawObject(TGameObj* obj);
// Redraws all interface windows
void RefreshGNW();
void RefreshGNW(size_t from);
UNLSTDfrm *LoadUnlistedFrm(char *frmName, unsigned int folderRef);
+1 -1
View File
@@ -42,7 +42,7 @@ WRAP_WATCOM_FFUNC4(void, RegisterObjectCall, register_object_call_, long*, targe
WRAP_WATCOM_FFUNC3(long, ScrGetLocalVar, scr_get_local_var_, long, sid, long, varId, long*, value)
WRAP_WATCOM_FFUNC3(long, ScrSetLocalVar, scr_set_local_var_, long, sid, long, varId, long, value)
WRAP_WATCOM_FFUNC3(long, TileNumInDirection, tile_num_in_direction_, long, tile, long, rotation, long, distance)
//WRAP_WATCOM_FFUNC8(void, TransCscale, trans_cscale_, void*, fromBuff, long, width, long, height, long, pitch, void*, toBuff, long, toWidth, long, toHeight, long, toPitch)
WRAP_WATCOM_FFUNC8(void, TransCscale, trans_cscale_, void*, fromBuff, long, width, long, height, long, pitch, void*, toBuff, long, toWidth, long, toHeight, long, toPitch)
WRAP_WATCOM_FFUNC3(const char*, InterpretGetString, interpretGetString_, TProgram*, scriptPtr, DWORD, dataType, DWORD, strId)
+1 -1
View File
@@ -896,7 +896,7 @@ public:
if (d3d9Device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) {
ResetDevice(false);
DeviceLost = false;
RefreshGNW();
RefreshGNW(0);
}
return !DeviceLost;
}
+1 -1
View File
@@ -44,7 +44,7 @@ WINinfo* Interface_GetWindow(long winType) {
long winID = 0;
switch (winType) {
case WINTYPE_Inventory:
if (GetLoopFlags() & INVENTORY) winID = *ptr_i_wid;
if (GetLoopFlags() & (INVENTORY | INTFACEUSE | INTFACELOOT | BARTER)) winID = *ptr_i_wid;
break;
case WINTYPE_Dialog:
if (GetLoopFlags() & DIALOG) winID = *ptr_dialogueBackWindow;
+1 -1
View File
@@ -217,7 +217,7 @@ static void StopMovie() {
aviPlayState = AVISTATE_Stop;
Gfx_SetMovieTexture(false);
movieInterface.pControl->Stop();
if (*(DWORD*)_subtitles == 0) RefreshGNW(); // Note: it is only necessary when in the game
if (*(DWORD*)_subtitles == 0) RefreshGNW(0); // Note: it is only necessary when in the game
}
DWORD FreeMovie(sDSTexture* movie) {
+1
View File
@@ -857,6 +857,7 @@ static const SfallOpcodeMetadata opcodeMetaArray[] = {
{mf_draw_image_scaled, "draw_image_scaled", {DATATYPE_MASK_INT | DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
{mf_get_window_attribute, "get_window_attribute", {DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
{mf_hide_window, "hide_window", {DATATYPE_MASK_STR}},
{mf_interface_art_draw, "interface_art_draw", {DATATYPE_MASK_INT, DATATYPE_MASK_INT | DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
{mf_inventory_redraw, "inventory_redraw", {DATATYPE_MASK_INT}},
{mf_message_box, "message_box", {DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
{mf_remove_timer_event, "remove_timer_event", {DATATYPE_MASK_INT}},
+74 -2
View File
@@ -340,7 +340,12 @@ static void __declspec(naked) op_is_iface_tag_active() {
}
static void mf_intface_redraw() {
IntfaceRedraw();
DWORD flag = (opHandler.numArgs() > 0) ? opHandler.arg(0).rawValue() : 0;
if (flag == 0) {
IntfaceRedraw();
} else {
RefreshGNW(1); // redraw all interfaces
}
}
static void mf_intface_show() {
@@ -531,7 +536,7 @@ static long GetArtFIDFile(long fid, const char* &file) {
file = ArtGetName(_fid); // .frm
if (_fid >> 24 == OBJ_TYPE_CRITTER) {
direction = (fid >> 28);
if (direction && !DbAccess(file)) {
if (direction > 0 && !DbAccess(file)) {
file = ArtGetName(fid); // .fr#
}
}
@@ -681,6 +686,73 @@ exit:
opHandler.setReturn(result);
}
static void mf_interface_art_draw() {
long result = -1;
WINinfo* interfaceWin = Interface_GetWindow(opHandler.arg(0).rawValue() & 0xFF);
if (interfaceWin && (int)interfaceWin != -1) {
const char* file = nullptr;
bool useShift = false;
long direction = -1, w = -1, h = -1;
if (opHandler.arg(1).isInt()) { // art id
long fid = opHandler.arg(1).rawValue();
if (fid == -1) {
result = -1;
goto exit;
}
useShift = (((fid & 0xF000000) >> 24) == OBJ_TYPE_CRITTER);
direction = GetArtFIDFile(fid, file);
} else {
file = opHandler.arg(1).strValue(); // path to frm/pcx file
}
if (opHandler.numArgs() > 5) { // array params
sArrayVar* sArray = GetRawArray(opHandler.arg(5).rawValue());
if (sArray) {
if (direction < 0) direction = sArray->val[0].intVal;
int size = sArray->size();
if (size > 1) w = sArray->val[1].intVal;
if (size > 2) h = sArray->val[2].intVal;
}
}
long frame = (opHandler.numArgs() > 4) ? opHandler.arg(4).rawValue() : 0;
FrmFrameData* framePtr;
FrmFile* frmPtr = LoadArtFile(file, frame, direction, framePtr);
if (frmPtr == nullptr) {
opHandler.printOpcodeError("interface_art_draw() - cannot open the file: %s", file);
result = -1;
goto exit;
}
int x = opHandler.arg(2).rawValue();
int y = opHandler.arg(3).rawValue();
if (useShift && direction >= 0) {
x += frmPtr->xshift[direction];
y += frmPtr->yshift[direction];
}
if (x < 0) x = 0;
if (y < 0) y = 0;
int width = (w >= 0) ? w : framePtr->width;
int height = (h >= 0) ? h : framePtr->height;
TransCscale(framePtr->data, framePtr->width, framePtr->height, framePtr->width,
interfaceWin->surface + (y * interfaceWin->width) + x, width, height, interfaceWin->width
);
if (!(opHandler.arg(0).rawValue() & 0x10000)) {
GNWWinRefresh(interfaceWin, &interfaceWin->rect, 0);
}
MemFree(frmPtr);
result = 1;
} else {
opHandler.printOpcodeError("interface_art_draw() - the game interface window is not created or invalid value for the interface.");
}
exit:
opHandler.setReturn(result);
}
static void mf_unwield_slot() {
InvenType slot = static_cast<InvenType>(opHandler.arg(1).rawValue());
if (slot < INVEN_TYPE_WORN || slot > INVEN_TYPE_LEFT_HAND) {
+2 -1
View File
@@ -142,9 +142,10 @@ static const SfallMetarule metaruleArray[] = {
{"get_text_width", mf_get_text_width, 1, 1},
{"get_window_attribute", mf_get_window_attribute, 1, 2},
{"hide_window", mf_hide_window, 0, 1},
{"interface_art_draw", mf_interface_art_draw, 4, 6},
{"intface_hide", mf_intface_hide, 0, 0},
{"intface_is_hidden", mf_intface_is_hidden, 0, 0},
{"intface_redraw", mf_intface_redraw, 0, 0},
{"intface_redraw", mf_intface_redraw, 0, 1},
{"intface_show", mf_intface_show, 0, 0},
{"inventory_redraw", mf_inventory_redraw, 0, 1},
{"item_weight", mf_item_weight, 1, 1},