-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix compatibility with gzdoom 3.x ( revert to old menu system, remove…
… unsupported MENUDEF features )
- Loading branch information
1 parent
e5fdcfa
commit ff5e523
Showing
6 changed files
with
237 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.