diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 375c94ba..8f422fe6 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -65,6 +65,16 @@ #define ENCOUNTER_FLAG_ICON_SP (0x8) // use special encounter icon #define ENCOUNTER_FLAG_FADEOUT (0x10) // fade out the screen on encounter (Note: you yourself should restore the fade screen when entering the encounter) +//Valid window types for get_window_attribute +#define WINTYPE_INVENTORY (0) // any inventory window +#define WINTYPE_DIALOG (1) +#define WINTYPE_PIPBOY (2) +#define WINTYPE_WORLDMAP (3) +#define WINTYPE_MAINIFACE (4) // the interface bar +#define WINTYPE_CHARACTER (5) +#define WINTYPE_SKILLDEX (6) +#define WINTYPE_ESCMENU (7) // escape menu + //The attack types returned by get_attack_type #define ATKTYPE_LWEP1 (0) #define ATKTYPE_LWEP2 (1) @@ -243,6 +253,8 @@ #define get_current_inven_size(obj) sfall_func1("get_current_inven_size", obj) #define get_cursor_mode sfall_func0("get_cursor_mode") #define get_flags(obj) sfall_func1("get_flags", obj) +#define get_interface_xpos(winType) sfall_func2("get_window_attribute", winType, 0) +#define get_interface_ypos(winType) sfall_func2("get_window_attribute", winType, 1) #define get_inven_ap_cost sfall_func0("get_inven_ap_cost") #define get_map_enter_position sfall_func0("get_map_enter_position") #define get_metarule_table sfall_func0("get_metarule_table") diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index c48aa919..f1d0eb2d 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -600,7 +600,7 @@ optional arguments: - the radius is limited to 50 hexes > int sfall_func2("tile_by_position", int x, int y) -- returns the tile number at the x, y position relative to the top-left corner of the screen +- returns the tile number at the x, y position relative to the top-left corner of the game screen - if the position is outside of the range of tiles, it will return -1 > string sfall_func2("string_to_case", string text, int toCase) @@ -608,6 +608,11 @@ optional arguments: - toCase: 0 - lowercase, 1 - uppercase - NOTE: this function works only for English letters of A-Z/a-z +int sfall_func2("get_window_attribute", int winType, int attrType) +- returns the attribute of the specified interface window by the attrType argument +- winType: the type number of the interface window (see WINTYPE_* constants in sfall.h) +- attrType: 0 - X position, 1 - Y position (relative to the top-left corner of the game screen) + ------------------------ ------ MORE INFO ------- ------------------------ diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index 0fdf8a84..252b8fc7 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -1447,6 +1447,50 @@ long __fastcall GetTopWindowID(long xPos, long yPos) { return win->wID; } +enum WinNameType { + WINTYPE_Inventory = 0, // any inventory window + WINTYPE_Dialog = 1, + WINTYPE_PipBoy = 2, + WINTYPE_WorldMap = 3, + WINTYPE_MainIface = 4, // the interface bar + WINTYPE_Character = 5, + WINTYPE_Skilldex = 6, + WINTYPE_EscMenu = 7, // escape menu +}; + +WINinfo* GetUIWindow(long winType) { + long winID = -1; + switch (winType) { + case WINTYPE_Inventory: + winID = *ptr_i_wid; + break; + case WINTYPE_Dialog: + winID = *(DWORD*)_dialogueBackWindow; + break; + case WINTYPE_PipBoy: + winID = *ptr_pip_win; + break; + case WINTYPE_WorldMap: + winID = *(DWORD*)_wmBkWin; + break; + case WINTYPE_MainIface: + winID = *ptr_interfaceWindow; + break; + case WINTYPE_Character: + winID = *ptr_edit_win; + break; + case WINTYPE_Skilldex: + winID = *(DWORD*)_skldxwin; + break; + case WINTYPE_EscMenu: + winID = *(DWORD*)_optnwin; + break; + default: + return (WINinfo*)-1; + } + return (winID != -1) ? GNWFind(winID) : nullptr; +} + // Returns an array of objects within the specified radius from the source tile void GetObjectsTileRadius(std::vector &objs, long sourceTile, long radius, long elev, long type = -1) { for (long tile = 0; tile < 40000; tile++) { diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index 4193ea8a..1087f78c 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -1291,6 +1291,8 @@ long GetScriptLocalVars(long sid); long __fastcall GetTopWindowID(long xPos, long yPos); +WINinfo* GetUIWindow(long winType); + void GetObjectsTileRadius(std::vector &objs, long sourceTile, long radius, long elev, long type); // Print text to surface diff --git a/sfall/ScriptOps/InterfaceOp.hpp b/sfall/ScriptOps/InterfaceOp.hpp index 0580b681..de05782d 100644 --- a/sfall/ScriptOps/InterfaceOp.hpp +++ b/sfall/ScriptOps/InterfaceOp.hpp @@ -706,3 +706,33 @@ static void sf_unwield_slot() { } if (update) IntfaceUpdateItems(0, -1, -1); } + +void sf_get_window_attribute() { + const ScriptValue &winArg = opHandler.arg(0), + &attrArg = opHandler.arg(1); + + if (winArg.isInt() && attrArg.isInt()) { + WINinfo* win = GetUIWindow(winArg.rawValue()); + if (win == nullptr) { + opHandler.printOpcodeError("get_window_attribute() - failed to get the interface window."); + return; + } + if ((long)win == -1) { + opHandler.printOpcodeError("get_window_attribute() - invalid window type number."); + return; + } + long pos = 0; + switch (attrArg.rawValue()) { + case 0 : // x + pos = win->wRect.left; + break; + case 1 : // y + pos = win->wRect.top; + break; + } + opHandler.setReturn(pos); + } else { + OpcodeInvalidArgs("get_window_attribute"); + opHandler.setReturn(0); + } +} diff --git a/sfall/ScriptOps/MetaruleOp.hpp b/sfall/ScriptOps/MetaruleOp.hpp index 77f26121..f55c07f6 100644 --- a/sfall/ScriptOps/MetaruleOp.hpp +++ b/sfall/ScriptOps/MetaruleOp.hpp @@ -141,6 +141,7 @@ static const SfallMetarule metaruleArray[] = { {"get_outline", sf_get_outline, 1, 1}, {"get_sfall_arg_at", sf_get_sfall_arg_at, 1, 1}, {"get_text_width", sf_get_text_width, 1, 1}, + {"get_window_attribute", sf_get_window_attribute, 2, 2}, {"hide_window", sf_hide_window, 0, 1}, {"intface_hide", sf_intface_hide, 0, 0}, {"intface_is_hidden", sf_intface_is_hidden, 0, 0},