Added "get_window_attribute" script function (#276)

This commit is contained in:
NovaRain
2020-01-22 21:13:22 +08:00
parent 56f2ea46c2
commit d387e009ee
7 changed files with 89 additions and 1 deletions
+12
View File
@@ -84,6 +84,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)
@@ -277,6 +287,8 @@
#define get_flags(obj) sfall_func1("get_flags", obj)
#define get_ini_section(file, sect) sfall_func2("get_ini_section", file, sect)
#define get_ini_sections(file) sfall_func1("get_ini_sections", file)
#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")
+6 -1
View File
@@ -694,7 +694,7 @@ optional argument:
- 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)
@@ -705,6 +705,11 @@ optional argument:
> void sfall_func3("set_terrain_name", int x, int y, string name)
- overrides the terrain type name for the sub-tile on the world map by the specified coordinates
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 -------
------------------------
+44
View File
@@ -195,6 +195,50 @@ long __fastcall GetTopWindowID(long xPos, long yPos) {
return win->wID;
}
enum WinNameType {
Inventory = 0, // any inventory window
Dialog = 1,
PipBoy = 2,
WorldMap = 3,
MainIface = 4, // the interface bar
Character = 5,
Skilldex = 6,
EscMenu = 7, // escape menu
};
fo::Window* GetWindow(long winType) {
long winID = -1;
switch (winType) {
case WinNameType::Inventory:
winID = fo::var::i_wid;
break;
case WinNameType::Dialog:
winID = *(DWORD*)FO_VAR_dialogueBackWindow;
break;
case WinNameType::PipBoy:
winID = fo::var::pip_win;
break;
case WinNameType::WorldMap:
winID = *(DWORD*)FO_VAR_wmBkWin;
break;
case WinNameType::MainIface:
winID = fo::var::interfaceWindow;
break;
case WinNameType::Character:
winID = fo::var::edit_win;
break;
case WinNameType::Skilldex:
winID = *(DWORD*)FO_VAR_skldxwin;
break;
case WinNameType::EscMenu:
winID = *(DWORD*)FO_VAR_optnwin;
break;
default:
return (fo::Window*)-1;
}
return (winID != -1) ? fo::func::GNW_find(winID) : nullptr;
}
// Returns an array of objects within the specified radius from the source tile
void GetObjectsTileRadius(std::vector<fo::GameObject*> &objs, long sourceTile, long radius, long elev, long type = -1) {
for (long tile = 0; tile < 40000; tile++) {
+2
View File
@@ -78,6 +78,8 @@ long GetScriptLocalVars(long sid);
long __fastcall GetTopWindowID(long xPos, long yPos);
fo::Window* GetWindow(long winType);
void GetObjectsTileRadius(std::vector<fo::GameObject*> &objs, long sourceTile, long radius, long elev, long type);
long wmGetCurrentTerrainType();
@@ -541,5 +541,27 @@ void sf_unwield_slot(OpcodeContext& ctx) {
if (update) fo::func::intface_update_items(0, -1, -1);
}
void sf_get_window_attribute(OpcodeContext& ctx) {
fo::Window* win = fo::GetWindow(ctx.arg(0).rawValue());
if (win == nullptr) {
ctx.printOpcodeError("%s() - failed to get the interface window.", ctx.getMetaruleName());
return;
}
if ((long)win == -1) {
ctx.printOpcodeError("%s() - invalid window type number.", ctx.getMetaruleName());
return;
}
long pos = 0;
switch (ctx.arg(1).rawValue()) {
case 0 : // x
pos = win->wRect.left;
break;
case 1 : // y
pos = win->wRect.top;
break;
}
ctx.setReturn(pos);
}
}
}
@@ -111,5 +111,7 @@ void sf_draw_image_scaled(OpcodeContext&);
void sf_unwield_slot(OpcodeContext&);
void sf_get_window_attribute(OpcodeContext&);
}
}
@@ -92,6 +92,7 @@ static const SfallMetarule metarules[] = {
{"get_sfall_arg_at", sf_get_sfall_arg_at, 1, 1, 0, {ARG_INT}},
{"get_string_pointer", sf_get_string_pointer, 1, 1, 0, {ARG_STRING}},
{"get_text_width", sf_get_text_width, 1, 1, 0, {ARG_STRING}},
{"get_window_attribute", sf_get_window_attribute, 2, 2, 0, {ARG_INT, ARG_INT}},
{"has_fake_perk_npc", sf_has_fake_perk_npc, 2, 2, 0, {ARG_OBJECT, ARG_STRING}},
{"has_fake_trait_npc", sf_has_fake_trait_npc, 2, 2, 0, {ARG_OBJECT, ARG_STRING}},
{"hide_window", sf_hide_window, 0, 1, -1, {ARG_STRING}},