Skip to content

Commit

Permalink
Add INI setting for scaling the reticle
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Dec 4, 2018
1 parent 9e94db5 commit f798829
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions _work/data/Scripts/Content/GFA/_intern/const.d
Expand Up @@ -64,6 +64,7 @@ const int GFA_MAX_DIST = 5000; // Distance for shoo
var int GFA_AimRayInterval; // Perform trace ray every x ms (change in ini-file)
var int GFA_AimRayPrevCalcTime; // Time of last trace ray calculation
var int GFA_NoAimNoFocus; // Remove focus when not aiming (change in ini-file)
var int GFA_ScaleReticleWithResolution; // Scale reticle relative to the screen resolution (ini)

const int GFA_RETICLE_MIN_SIZE = 200; // Smallest reticle size in virtual coordinates
const int GFA_RETICLE_MAX_SIZE = 400; // Biggest reticle size in virtual coordinates
Expand Down
8 changes: 8 additions & 0 deletions _work/data/Scripts/Content/GFA/_intern/init.d
Expand Up @@ -157,6 +157,11 @@ func void GFA_InitFeatureFreeAiming() {
MEM_SetGothOpt("GFA", "showFocusWhenNotAiming", "0");
};

if (!MEM_GothOptExists("GFA", "scaleReticleWithResolution")) {
// Add INI-entry, if not set (disable by default)
MEM_SetGothOpt("GFA", "scaleReticleWithResolution", "0");
};

if (GOTHIC_BASE_VERSION == 2) {
if (GFA_Flags & GFA_RANGED) {
if (!MEM_GothOptExists("GFA", "overwriteControlSchemeRanged")) {
Expand Down Expand Up @@ -328,6 +333,9 @@ func void GFA_InitAlways() {
// Remove focus when not aiming: Prevent using bow/spell as enemy detector
GFA_NoAimNoFocus = !STR_ToInt(MEM_GetGothOpt("GFA", "showFocusWhenNotAiming"));

// Scale the reticle relative to the screen resolution
GFA_ScaleReticleWithResolution = STR_ToInt(MEM_GetGothOpt("GFA", "scaleReticleWithResolution"));

// Reset/reinitialize free aiming settings every time to prevent crashes
if (GFA_Flags & GFA_RANGED) || (GFA_Flags & GFA_SPELLS) {
// On level change, Gothic does not maintain the focus instances (see Focus.d), nor does it reinitialize them.
Expand Down
17 changes: 13 additions & 4 deletions _work/data/Scripts/Content/GFA/_intern/reticle.d
Expand Up @@ -57,7 +57,11 @@ func void GFA_InsertReticle(var int reticlePtr) {
if (!GFA_RETICLE_PTR) {
// Create reticle if it does not exist
Print_GetScreenSize(); // Necessary for Print_ToRatio
GFA_RETICLE_PTR = ViewPtr_CreateCenter(PS_VMax/2, PS_VMax/2, size, Print_ToRatio(size, PS_Y));
if (GFA_ScaleReticleWithResolution) {
GFA_RETICLE_PTR = ViewPtr_CreateCenter(PS_VMax/2, PS_VMax/2, size, Print_ToRatio(size, PS_Y));
} else {
GFA_RETICLE_PTR = ViewPtr_CreateCenterPxl(Print_Screen[PS_X]/2, Print_Screen[PS_Y]/2, size/6, size/6);
};
ViewPtr_SetTexture(GFA_RETICLE_PTR, reticle.texture);
ViewPtr_SetColor(GFA_RETICLE_PTR, reticle.color);
ViewPtr_Open(GFA_RETICLE_PTR);
Expand All @@ -78,9 +82,14 @@ func void GFA_InsertReticle(var int reticlePtr) {
// Update its size and re-position it to center
Print_GetScreenSize(); // Necessary for Print_ToRatio
var int centerX; centerX = Print_Screen[PS_X]/2;
var int sizey; sizey = Print_ToRatio(size, PS_Y);
ViewPtr_Resize(GFA_RETICLE_PTR, size, sizey);
ViewPtr_MoveTo(GFA_RETICLE_PTR, PS_VMax/2-size/2, PS_VMax/2-sizey/2);
if (GFA_ScaleReticleWithResolution) {
var int sizey; sizey = Print_ToRatio(size, PS_Y);
ViewPtr_Resize(GFA_RETICLE_PTR, size, sizey);
ViewPtr_MoveTo(GFA_RETICLE_PTR, PS_VMax/2-size/2, PS_VMax/2-sizey/2);
} else {
ViewPtr_ResizePxl(GFA_RETICLE_PTR, size/6, size/6);
ViewPtr_MoveToPxl(GFA_RETICLE_PTR, Print_Screen[PS_X]/2-size/6/2, Print_Screen[PS_Y]/2-size/6/2);
};
};

if (!crsHr.isOpen) {
Expand Down
9 changes: 7 additions & 2 deletions _work/data/Scripts/Content/GFA/config/criticalHit.d
Expand Up @@ -150,8 +150,13 @@ func void GFA_GetCriticalHit(var C_Npc target, var string bone, var C_Item weapo
if (!GFA_HITMARKER) {
// Create it (if it does not exist) in the center of the screen
Print_GetScreenSize(); // Necessary for Print_ToRatio
GFA_HITMARKER = ViewPtr_CreateCenter(PS_VMax/2, PS_VMax/2, // Coordinates. Dimensions below
GFA_RETICLE_MAX_SIZE, Print_ToRatio(GFA_RETICLE_MAX_SIZE, PS_Y));
if (GFA_ScaleReticleWithResolution) {
GFA_HITMARKER = ViewPtr_CreateCenter(PS_VMax/2, PS_VMax/2,
GFA_RETICLE_MAX_SIZE, Print_ToRatio(GFA_RETICLE_MAX_SIZE, PS_Y));
} else {
GFA_HITMARKER = ViewPtr_CreateCenterPxl(Print_Screen[PS_X]/2, Print_Screen[PS_Y]/2,
GFA_RETICLE_MAX_SIZE/6, GFA_RETICLE_MAX_SIZE/6);
};

// Get 7th frame of animated texture as static texture
ViewPtr_SetTexture(GFA_HITMARKER, GFA_AnimateReticleByPercent(RETICLE_TRI_IN, 100, 7));
Expand Down

0 comments on commit f798829

Please sign in to comment.