Skip to content

Commit

Permalink
fix compatibility with gzdoom 3.x ( revert to old menu system, remove…
Browse files Browse the repository at this point in the history
… unsupported MENUDEF features )
  • Loading branch information
RicardoLuis0 committed Aug 23, 2021
1 parent e5fdcfa commit ff5e523
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 123 deletions.
6 changes: 1 addition & 5 deletions MENUDEF
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ OptionMenu "AimAssistControls" {
StaticText ""
}

AddOptionMenu "CustomizeControls" after "ChatControlsMenu" {
AddOptionMenu "CustomizeControls" {
Submenu "Aim Assist Mod","AimAssistControls"
}

Expand Down Expand Up @@ -169,7 +169,3 @@ AddOptionMenu "OptionsMenu"{
StaticText ""
}

AddOptionMenu "OptionsMenuSimple"{
Submenu "Aim Assist Options", "AimAssistOptions"
StaticText ""
}
1 change: 1 addition & 0 deletions zscript/Menu.zs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "zscript/menu/CVarControl.zs"
#include "zscript/menu/ReverseSlider.zs"
#include "zscript/menu/ReverseCheckSlider.zs"
#include "zscript/menu/CheckSlider.zs"
#include "zscript/menu/CheckVal.zs"
125 changes: 42 additions & 83 deletions zscript/Menu/CheckSlider.zs
Original file line number Diff line number Diff line change
@@ -1,110 +1,69 @@
class OptionMenuCheckSliderBase : OptionMenuSliderBase {

double mMin, mMax, mStep;
int mShowValue;
int mDrawX;
int mSliderShort;
CVar mGrayCheck;

OptionMenuCheckSliderBase Init(String label, double min, double max, double step, int showval, Name command = 'none', CVar graycheck = NULL) {
Super.Init(label, min, max, step, showval, command, graycheck);
mMin = min;
mMax = max;
mStep = step;
mShowValue = showval;
mDrawX = 0;
mSliderShort = 0;
mGrayCheck = graycheck;
return self;
}

virtual double GetSliderTextValue() {
return GetSliderValue();
}
class OptionMenuItemCheckSlider : OptionMenuItemSlider{
protected CVar check;

override bool isGrayed(void) {
return mGrayCheck != NULL && !mGrayCheck.GetInt();
}

override bool Selectable(void) {
return !isGrayed();
}

private void DrawSliderElement (int color, int x, int y, String str, bool grayed = false) {
int overlay = grayed? Color(96, 48, 0, 0) : 0;
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 16 * CleanXfac_1, DTA_CellY, 16 * CleanYfac_1, DTA_ColorOverlay, overlay);
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null) {
Super.Init(label, command, min, max, step, showval);
check=check_var;
return self;
}

protected void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent, bool grayed = false) {
protected void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent)
{
bool grayed=isGrayed();
Color slidercolor=grayed?Font.FindFontColor("DarkGray"):Font.FindFontColor(gameinfo.mSliderColor);
String formater = String.format("%%.%df", fracdigits); // The format function cannot do the '%.*f' syntax.
String textbuf;
double range;
int maxlen = 0;
int right = x + (12*16 + 4) * CleanXfac_1; // length of slider. This uses the old ConFont and
int cy = y + CleanYFac;
int right = x + (12*8 + 4) * CleanXfac_1;
int cy = y + (OptionMenuSettings.mLinespacing-8)*CleanYfac_1;

range = max - min;
double ccur = clamp(cur, min, max) - min;

if (fracdigits >= 0) {
if (fracdigits >= 0)
{
textbuf = String.format(formater, max);
maxlen = Menu.OptionWidth(textbuf) * CleanXfac_1;
maxlen = SmallFont.StringWidth(textbuf) * CleanXfac_1;
}

mSliderShort = right + maxlen > screen.GetWidth();

if (!mSliderShort) {
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12", grayed);
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 78) / range)) * 2 * CleanXfac_1), cy, "\x13", grayed);
} else {
if (!mSliderShort)
{
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12");
Menu.DrawConText(slidercolor, x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "\x13");
}
else
{
// On 320x200 we need a shorter slider
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12", grayed);
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 38) / range)) * 2 * CleanXfac_1), cy, "\x13", grayed);
right -= 5*8*CleanXfac;
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12");
Menu.DrawConText(slidercolor, x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "\x13");
right -= 5*8*CleanXfac_1;
}

if (fracdigits >= 0 && right + maxlen <= screen.GetWidth()) {
textbuf = String.format(formater, GetSliderTextValue());
drawText(right, y, Font.CR_DARKGRAY, textbuf, grayed);
if (fracdigits >= 0 && right + maxlen <= screen.GetWidth())
{
textbuf = String.format(formater, cur);
screen.DrawText(SmallFont, Font.CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true);
}
}

override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) {
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, isGrayed());
mDrawX = indent + CursorSpace();
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent, isGrayed());
return indent;
}

}
class OptionMenuItemCheckSlider : OptionMenuCheckSliderBase {

CVar mCVar;

OptionMenuItemCheckSlider Init(String label, Name command, double min, double max, double step, int showval = 1, CVar graycheck = NULL)
{
Super.Init(label, min, max, step, showval, command, graycheck);
mCVar =CVar.FindCVar(command);
return self;
}

override double GetSliderValue()
//=============================================================================
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
{
if (mCVar != null)
{
return mCVar.GetFloat();
}
else
{
return 0;
}
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
mDrawX = indent + CursorSpace();
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
return indent;
}

override void SetSliderValue(double val)
{
if (mCVar != null)
{
mCVar.SetFloat(val);
}
virtual bool isGrayed() {
return check != null && !check.GetInt();
}

override bool Selectable() {
return !isGrayed();
}
}
}
17 changes: 8 additions & 9 deletions zscript/Menu/CheckVal.zs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@

class OptionMenuItemCheckValSlider : OptionMenuItemCheckSlider {
class OptionMenuItemCheckValSlider : OptionMenuItemCheckSlider{
int val;
bool not;

OptionMenuItemCheckValSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null,int check_val=0,bool check_not=true) {
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null,int check_val=0,bool check_not=true) {
Super.Init(label, command, min, max, step, showval,check_var);
val=check_val;
not=check_not;
return self;
}

override bool isGrayed() {
return mGrayCheck != null && not?!(mGrayCheck.GetInt()==val):((mGrayCheck.GetInt()==val));
return check != null && not?!(check.GetInt()==val):((check.GetInt()==val));
}
}

class OptionMenuItemReverseCheckValSlider : OptionMenuItemReverseSlider {
class OptionMenuItemReverseCheckValSlider : OptionMenuItemReverseCheckSlider{
int val;
bool not;

OptionMenuItemReverseCheckValSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null,int check_val=0,bool check_not=true) {
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null,int check_val=0,bool check_not=true) {
Super.Init(label, command, min, max, step, showval,check_var);
val=check_val;
not=check_not;
return self;
}

override bool isGrayed() {
return mGrayCheck != null && not?!(mGrayCheck.GetInt()==val):((mGrayCheck.GetInt()==val));
return check != null && not?!(check.GetInt()==val):((check.GetInt()==val));
}
}

Expand All @@ -36,7 +35,7 @@ class OptionMenuItemCheckValOption:OptionMenuItemOption{
int val;
bool not;

OptionMenuItemCheckValOption Init(String label, Name command, Name values, int center = 0, CVar check_var = null,int check_val=0,bool check_not=true){
OptionMenuItemOption Init(String label, Name command, Name values, int center = 0, CVar check_var = null,int check_val=0,bool check_not=true){
Super.Init(label, command, values, null, center);
check=check_var;
val=check_val;
Expand All @@ -47,4 +46,4 @@ class OptionMenuItemCheckValOption:OptionMenuItemOption{
override bool isGrayed() {
return check != null && not?!(check.GetInt()==val):((check.GetInt()==val));
}
}
}
103 changes: 103 additions & 0 deletions zscript/Menu/ReverseCheckSlider.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class OptionMenuItemReverseCheckSlider : OptionMenuItemReverseSlider{
protected CVar check;

OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1,CVar check_var=null) {
Super.Init(label, command, min, max, step, showval);
check=check_var;
return self;
}

protected void DrawReverseSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent) {
bool grayed=isGrayed();
Color slidercolor=grayed?Font.FindFontColor("DarkGray"):Font.FindFontColor(gameinfo.mSliderColor);

String formater = String.format("%%.%df", fracdigits); // The format function cannot do the '%.*f' syntax.
String textbuf;
double range;
int maxlen = 0;
int right = x + (12*8 + 4) * CleanXfac_1;
int cy = y + (OptionMenuSettings.mLinespacing-8)*CleanYfac_1;

range = max - min;
double ccur = (max-min)-(clamp(cur, min, max) - min);
if (fracdigits >= 0) {
textbuf = String.format(formater, max);
maxlen = SmallFont.StringWidth(textbuf) * CleanXfac_1;
}

mSliderShort = right + maxlen > screen.GetWidth();

if (!mSliderShort) {
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12");
Menu.DrawConText(slidercolor, x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "\x13");
}else{
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12");
Menu.DrawConText(slidercolor, x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "\x13");
right -= 5*8*CleanXfac_1;
}

if (fracdigits >= 0 && right + maxlen <= screen.GetWidth()) {
textbuf = String.format(formater, cur);
screen.DrawText(SmallFont, Font.CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true);
}
}


override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) {
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
mDrawX = indent + CursorSpace();
DrawReverseSlider(mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
return indent;
}

override bool MenuEvent (int mkey, bool fromcontroller) {
double value = GetSliderValue();
if (mkey == Menu.MKEY_Right) {
value -= mStep;
}else if (mkey == Menu.MKEY_Left) {
value += mStep;
}else{
return OptionMenuItem.MenuEvent(mkey, fromcontroller);
}
if (value ~== 0) value = 0; // This is to prevent formatting anomalies with very small values
SetSliderValue(clamp(value, mMin, mMax));
Menu.MenuSound("menu/change");
return true;
}

override bool MouseEvent(int type, int x, int y) {
let lm = OptionMenu(Menu.GetCurrentMenu());
if (type != Menu.MOUSE_Click) {
if (!lm.CheckFocus(self)) return false;
}
if (type == Menu.MOUSE_Release) {
lm.ReleaseFocus();
}

int slide_left = mDrawX+8*CleanXfac_1;
int slide_right = slide_left + (10*8*CleanXfac_1 >> mSliderShort); // 12 char cells with 8 pixels each.

if (type == Menu.MOUSE_Click) {
if (x < slide_left || x >= slide_right) return true;
}

x = clamp(x, slide_left, slide_right);
double v = mMax - ((x - slide_left) * (mMax - mMin)) / (slide_right - slide_left);
if (v != GetSliderValue()) {
SetSliderValue(v);
//Menu.MenuSound("menu/change");
}
if (type == Menu.MOUSE_Click) {
lm.SetFocus(self);
}
return true;
}

virtual bool isGrayed() {
return check != null && !check.GetInt();
}

override bool Selectable() {
return !isGrayed();
}
}
Loading

0 comments on commit ff5e523

Please sign in to comment.