mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 02:56:09 -04:00
F1 to F35 can consistently be used in menus
This commit is contained in:
parent
e844b866e4
commit
4a07280218
@ -30,6 +30,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 75),
|
||||
};
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) { return true; }
|
||||
|
||||
void GenLevelClick(Game g, Widget w) {
|
||||
game.Gui.SetNewScreen(new GenLevelScreen(game));
|
||||
|
@ -38,14 +38,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
} else if (selectedI >= 0) {
|
||||
FocusKeyDown(key);
|
||||
return true;
|
||||
if (selectedI >= 0) {
|
||||
FocusKeyDown(key); return true;
|
||||
}
|
||||
return widgets[actionI].HandlesKeyDown(key);
|
||||
return widgets[actionI].HandlesKeyDown(key) || base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp(Key key) {
|
||||
@ -66,20 +62,21 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF";
|
||||
bool existed = origHotkey.BaseKey != Key.Unknown;
|
||||
|
||||
InputWidget input;
|
||||
input = MenuInputWidget.Create(game, 500, 30, curHotkey.Text, regularFont, new StringValidator())
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -35);
|
||||
input.ShowCaret = true;
|
||||
|
||||
widgets = new Widget[] {
|
||||
Make(0, -150, "Key: " + curHotkey.BaseKey, 300, titleFont, BaseKeyClick),
|
||||
Make(0, -100, "Modifiers:" + flags, 300, titleFont, ModifiersClick),
|
||||
|
||||
MenuInputWidget.Create(game, 500, 30, curHotkey.Text, regularFont, new StringValidator())
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -35),
|
||||
Make(0, -100, "Modifiers:" + flags, 300, titleFont, ModifiersClick),
|
||||
input,
|
||||
Make(-100, 10, "Input stays open: " + staysOpen, 300, titleFont, LeaveOpenClick),
|
||||
|
||||
Make(0, 80, existed ? "Save changes" : "Add hotkey", 300, titleFont, SaveChangesClick),
|
||||
Make(0, 130, existed ? "Remove hotkey" : "Cancel", 300, titleFont, RemoveHotkeyClick),
|
||||
MakeBack(false, titleFont, SwitchPause),
|
||||
};
|
||||
|
||||
((InputWidget)widgets[actionI]).ShowCaret = true;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
@ -19,17 +19,12 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
}
|
||||
return selected == null ? (key < Key.F1 || key > Key.F35) :
|
||||
selected.HandlesKeyDown(key);
|
||||
if (selected != null && selected.HandlesKeyDown(key)) return true;
|
||||
return base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp(Key key) {
|
||||
return selected == null ? true :
|
||||
selected.HandlesKeyUp(key);
|
||||
return selected == null ? true : selected.HandlesKeyUp(key);
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
@ -138,14 +133,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
public sealed class ClassicGenLevelScreen : MenuScreen {
|
||||
public ClassicGenLevelScreen(Game game) : base(game) { }
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
|
||||
|
@ -110,15 +110,14 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
} else if (curWidget != null) {
|
||||
if (curWidget != null) {
|
||||
int index = IndexOfWidget(curWidget) - 2;
|
||||
game.Input.Keys[binds[index]] = key;
|
||||
curWidget.SetText(ButtonText(index));
|
||||
curWidget = null;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
public override bool HandlesMouseDown(int mouseX, int mouseY, MouseButton button) {
|
||||
|
@ -46,16 +46,13 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
} else if ((key == Key.Enter || key == Key.KeypadEnter) && input != null) {
|
||||
ChangeSetting();
|
||||
return true;
|
||||
if (input != null) {
|
||||
if (input.HandlesKeyDown(key)) return true;
|
||||
if (key == Key.Enter || key == Key.KeypadEnter) {
|
||||
ChangeSetting(); return true;
|
||||
}
|
||||
}
|
||||
if (input == null)
|
||||
return key < Key.F1 || key > Key.F35;
|
||||
return input.HandlesKeyDown(key);
|
||||
return base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp(Key key) {
|
||||
@ -163,7 +160,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
extendedHelp = null;
|
||||
}
|
||||
|
||||
void OnOKButtonClick(Game game, Widget widget) {
|
||||
void OnOKButtonClick(Game game, Widget widget) {
|
||||
ChangeSetting();
|
||||
}
|
||||
|
||||
|
@ -54,14 +54,17 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override bool HandlesMouseMove(int mouseX, int mouseY) {
|
||||
return HandleMouseMove(widgets, mouseX, mouseY) >= 0;
|
||||
}
|
||||
public override bool HandlesMouseScroll(float delta) { return true; }
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
}
|
||||
return key < Key.F1 || key > Key.F35;
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(float delta) { return true; }
|
||||
|
||||
public override bool HandlesKeyPress(char key) { return true; }
|
||||
|
||||
public override bool HandlesKeyDown(Key key) { return true; }
|
||||
|
||||
public override bool HandlesKeyUp(Key key) { return true; }
|
||||
}
|
||||
}
|
@ -58,14 +58,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
ButtonWidget Make(int dir, int y, string text, ClickHandler onClick) {
|
||||
return ButtonWidget.Create(game, 300, text, titleFont, onClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, dir * 160, y);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
}
|
||||
return key < Key.F1 || key > Key.F35;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandlesMouseMove(int mouseX, int mouseY) {
|
||||
int i = HandleMouseMove(widgets, mouseX, mouseY);
|
||||
|
@ -89,12 +89,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, y);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
if (key == Key.Escape)
|
||||
game.Gui.SetNewScreen(null);
|
||||
return key < Key.F1 || key > Key.F35;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
game.Events.HackPermissionsChanged -= CheckHacksAllowed;
|
||||
|
@ -38,11 +38,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
RemoveOverwrites();
|
||||
if (key == Key.Escape) {
|
||||
game.Gui.SetNewScreen(null);
|
||||
return true;
|
||||
}
|
||||
return input.HandlesKeyDown(key);
|
||||
if (input.HandlesKeyDown(key)) return true;
|
||||
return base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp(Key key) {
|
||||
@ -97,9 +94,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
text = Path.Combine(Program.AppDirectory, "maps");
|
||||
text = Path.Combine(text, file);
|
||||
|
||||
if (File.Exists(text) && ((ButtonWidget)widget).OptName == null) {
|
||||
((ButtonWidget)widget).SetText("&cOverwrite existing?");
|
||||
((ButtonWidget)widget).OptName = "O";
|
||||
ButtonWidget btn = (ButtonWidget)widget;
|
||||
if (File.Exists(text) && btn.OptName == null) {
|
||||
btn.SetText("&cOverwrite existing?");
|
||||
btn.OptName = "O";
|
||||
} else {
|
||||
// NOTE: We don't immediately save here, because otherwise the 'saving...'
|
||||
// will not be rendered in time because saving is done on the main thread.
|
||||
|
@ -50,6 +50,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
RedrawText();
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) { return true; }
|
||||
|
||||
protected void CloseOverlay() {
|
||||
Dispose();
|
||||
|
||||
|
@ -65,17 +65,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
#region Input handling
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
bool controlDown = ControlDown();
|
||||
|
||||
if (key == Key.Tab) { TabKey(); return true; }
|
||||
if (key == Key.Up) { UpKey(controlDown); return true; }
|
||||
if (key == Key.Down) { DownKey(controlDown); return true; }
|
||||
|
||||
if (key == Key.Up) { UpKey(); return true; }
|
||||
if (key == Key.Down) { DownKey(); return true; }
|
||||
return base.HandlesKeyDown(key);
|
||||
}
|
||||
|
||||
void UpKey(bool controlDown) {
|
||||
if (controlDown) {
|
||||
void UpKey() {
|
||||
if (ControlDown()) {
|
||||
int pos = caret == -1 ? Text.Length : caret;
|
||||
if (pos < MaxCharsPerLine) return;
|
||||
|
||||
@ -99,8 +96,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
Recreate();
|
||||
}
|
||||
|
||||
void DownKey(bool controlDown) {
|
||||
if (controlDown) {
|
||||
void DownKey() {
|
||||
if (ControlDown()) {
|
||||
if (caret == -1 || caret >= (UsedLines - 1) * MaxCharsPerLine) return;
|
||||
caret += MaxCharsPerLine;
|
||||
UpdateCaret();
|
||||
|
@ -301,15 +301,13 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
bool clipboardDown = ControlDown();
|
||||
|
||||
if (key == Key.Left) LeftKey(clipboardDown);
|
||||
else if (key == Key.Right) RightKey(clipboardDown);
|
||||
else if (key == Key.BackSpace) BackspaceKey(clipboardDown);
|
||||
if (key == Key.Left) LeftKey();
|
||||
else if (key == Key.Right) RightKey();
|
||||
else if (key == Key.BackSpace) BackspaceKey();
|
||||
else if (key == Key.Delete) DeleteKey();
|
||||
else if (key == Key.Home) HomeKey();
|
||||
else if (key == Key.End) EndKey();
|
||||
else if (clipboardDown && !OtherKey(key)) return false;
|
||||
else if (!OtherKey(key)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -320,11 +318,10 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
if (button == MouseButton.Left)
|
||||
SetCaretToCursor(mouseX, mouseY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BackspaceKey(bool controlDown) {
|
||||
if (controlDown) {
|
||||
void BackspaceKey() {
|
||||
if (ControlDown()) {
|
||||
if (caret == -1) caret = Text.Length - 1;
|
||||
int len = Text.GetBackLength(caret);
|
||||
if (len == 0) return;
|
||||
@ -368,8 +365,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
}
|
||||
|
||||
void LeftKey(bool controlDown) {
|
||||
if (controlDown) {
|
||||
void LeftKey() {
|
||||
if (ControlDown()) {
|
||||
if (caret == -1)
|
||||
caret = Text.Length - 1;
|
||||
caret -= Text.GetBackLength(caret);
|
||||
@ -385,8 +382,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
}
|
||||
|
||||
void RightKey(bool controlDown) {
|
||||
if (controlDown) {
|
||||
void RightKey() {
|
||||
if (ControlDown()) {
|
||||
caret += Text.GetForwardLength(caret);
|
||||
if (caret >= Text.Length) caret = -1;
|
||||
UpdateCaret();
|
||||
@ -414,6 +411,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
static char[] trimChars = new char[] {'\r', '\n', '\v', '\f', ' ', '\t', '\0'};
|
||||
bool OtherKey(Key key) {
|
||||
int maxChars = UsedLines * MaxCharsPerLine;
|
||||
if (!ControlDown()) return false;
|
||||
|
||||
if (key == Key.V && Text.Length < maxChars) {
|
||||
string text = null;
|
||||
try {
|
||||
|
@ -53,7 +53,7 @@
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<DefineConstants>DEBUG;TRACE;USE_DX</DefineConstants>
|
||||
<DefineConstants>DEBUG;TRACE;USE_DX;</DefineConstants>
|
||||
<StartAction>Project</StartAction>
|
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
|
@ -9,9 +9,7 @@ namespace ClassicalSharp.Entities {
|
||||
public sealed class HacksComponent {
|
||||
|
||||
Game game;
|
||||
public HacksComponent(Game game, Entity entity) {
|
||||
this.game = game;
|
||||
}
|
||||
public HacksComponent(Game game) { this.game = game; }
|
||||
|
||||
public byte UserType;
|
||||
|
||||
@ -31,23 +29,14 @@ namespace ClassicalSharp.Entities {
|
||||
public bool Enabled = true;
|
||||
/// <summary> Whether the player is allowed to use any type of hacks. </summary>
|
||||
public bool CanAnyHacks = true;
|
||||
/// <summary> Whether the player is allowed to use the types of cameras that use third person. </summary>
|
||||
public bool CanUseThirdPersonCamera = true;
|
||||
/// <summary> Whether the player is allowed to increase its speed beyond the normal walking speed. </summary>
|
||||
public bool CanSpeed = true;
|
||||
/// <summary> Whether the player is allowed to fly in the world. </summary>
|
||||
public bool CanFly = true;
|
||||
/// <summary> Whether the player is allowed to teleport to their respawn coordinates. </summary>
|
||||
public bool CanRespawn = true;
|
||||
/// <summary> Whether the player is allowed to pass through all blocks. </summary>
|
||||
public bool CanNoclip = true;
|
||||
/// <summary> Whether the player is allowed to use pushback block placing. </summary>
|
||||
public bool CanPushbackBlocks = true;
|
||||
/// <summary> Whether the player is allowed to see all entity name tags. </summary>
|
||||
public bool CanSeeAllNames = true;
|
||||
/// <summary> Whether the player is allowed to double jump. </summary>
|
||||
public bool CanDoubleJump = true;
|
||||
/// <summary> Whether the player can be pushed by other players. </summary>
|
||||
public bool CanBePushed = true;
|
||||
/// <summary> Base speed multiplier entity moves at horizontally. </summary>
|
||||
public float BaseHorSpeed = 1;
|
||||
@ -59,18 +48,7 @@ namespace ClassicalSharp.Entities {
|
||||
/// <summary> Whether the player has allowed the usage of fast double jumping abilities. </summary>
|
||||
public bool WOMStyleHacks;
|
||||
|
||||
/// <summary> Whether the player currently has noclip on. </summary>
|
||||
public bool Noclip;
|
||||
/// <summary> Whether the player currently has fly mode active. </summary>
|
||||
public bool Flying;
|
||||
/// <summary> Whether the player is currently flying upwards. </summary>
|
||||
public bool FlyingUp;
|
||||
/// <summary> Whether the player is currently flying downwards. </summary>
|
||||
public bool FlyingDown;
|
||||
/// <summary> Whether the player is currently walking at base speed * speed multiplier. </summary>
|
||||
public bool Speeding;
|
||||
/// <summary> Whether the player is currently walking at base speed * 0.5 * speed multiplier. </summary>
|
||||
public bool HalfSpeeding;
|
||||
public bool Noclip, Flying, FlyingUp, FlyingDown, Speeding, HalfSpeeding;
|
||||
|
||||
public bool CanJumpHigher { get { return Enabled && CanAnyHacks && CanSpeed; } }
|
||||
public bool Floating { get { return Noclip || Flying; } }
|
||||
|
@ -37,7 +37,7 @@ namespace ClassicalSharp.Entities {
|
||||
SkinName = game.Username;
|
||||
|
||||
collisions = new CollisionsComponent(game, this);
|
||||
Hacks = new HacksComponent(game, this);
|
||||
Hacks = new HacksComponent(game);
|
||||
physics = new PhysicsComponent(game, this);
|
||||
input = new InputComponent(game, this);
|
||||
sound = new SoundComponent(game, this);
|
||||
|
@ -9,7 +9,7 @@ namespace ClassicalSharp.Entities.Mobs {
|
||||
LocalInterpComponent interp;
|
||||
CollisionsComponent collisions;
|
||||
PhysicsComponent physics;
|
||||
static HacksComponent hacks = new HacksComponent(null, null);
|
||||
static HacksComponent hacks = new HacksComponent(null);
|
||||
|
||||
AI ai;
|
||||
int climbCooldown;
|
||||
|
@ -18,7 +18,7 @@ namespace ClassicalSharp.Map {
|
||||
const byte TC_STRING = 0x74, TC_ARRAY = 0x75;
|
||||
const byte TC_ENDBLOCKDATA = 0x78;
|
||||
|
||||
BinaryReader reader;
|
||||
BinaryReader reader;
|
||||
public byte[] Load(Stream stream, Game game, out int width, out int height, out int length) {
|
||||
byte[] map = null;
|
||||
width = 0;
|
||||
@ -31,10 +31,14 @@ namespace ClassicalSharp.Map {
|
||||
|
||||
using (DeflateStream gs = new DeflateStream(stream, CompressionMode.Decompress)) {
|
||||
reader = new BinaryReader(gs);
|
||||
if (ReadInt32() != 0x271BB788 || reader.ReadByte() != 0x02) {
|
||||
throw new InvalidDataException("Unexpected constant in .dat file");
|
||||
}
|
||||
|
||||
ClassDescription obj = ReadData();
|
||||
for (int i = 0; i < obj.Fields.Length; i++) {
|
||||
FieldDescription field = obj.Fields[i];
|
||||
if (field.FieldName == "width")
|
||||
if (field.FieldName == "width")
|
||||
width = (int)field.Value;
|
||||
else if (field.FieldName == "height")
|
||||
length = (int)field.Value;
|
||||
@ -54,11 +58,6 @@ namespace ClassicalSharp.Map {
|
||||
}
|
||||
|
||||
ClassDescription ReadData() {
|
||||
if (ReadInt32() != 0x271BB788 || reader.ReadByte() != 0x02) {
|
||||
throw new InvalidDataException("Unexpected constant in .lvl file");
|
||||
}
|
||||
|
||||
// Java serialization constants
|
||||
if ((ushort)ReadInt16() != 0xACED || ReadInt16() != 0x0005) {
|
||||
throw new InvalidDataException("Unexpected java serialisation constant(s).");
|
||||
}
|
||||
@ -68,7 +67,7 @@ namespace ClassicalSharp.Map {
|
||||
ClassDescription desc = ReadClassDescription();
|
||||
ReadClassData(desc.Fields);
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadClassData(FieldDescription[] fields) {
|
||||
for (int i = 0; i < fields.Length; i++) {
|
||||
@ -103,7 +102,7 @@ namespace ClassicalSharp.Map {
|
||||
ReadArray(ref fields[i]); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReadArray(ref FieldDescription field) {
|
||||
byte typeCode = reader.ReadByte();
|
||||
@ -117,7 +116,7 @@ namespace ClassicalSharp.Map {
|
||||
ClassDescription ReadClassDescription() {
|
||||
ClassDescription desc = default(ClassDescription);
|
||||
byte typeCode = reader.ReadByte();
|
||||
if (typeCode == TC_NULL) return desc;
|
||||
if (typeCode == TC_NULL) return desc;
|
||||
if (typeCode != TC_CLASSDESC) ParseError(TC_CLASSDESC, typeCode);
|
||||
|
||||
desc.ClassName = ReadString();
|
||||
|
@ -13,20 +13,20 @@ bool Header_ReadByte(Stream* s, UInt8* state, Int32* value) {
|
||||
}
|
||||
|
||||
|
||||
#define GZipState_Header1 0
|
||||
#define GZipState_Header2 1
|
||||
#define GZipState_CompressionMethod 2
|
||||
#define GZipState_Flags 3
|
||||
#define GZipState_LastModifiedTime 4
|
||||
#define GZipState_CompressionFlags 5
|
||||
#define GZipState_OperatingSystem 6
|
||||
#define GZipState_HeaderChecksum 7
|
||||
#define GZipState_Filename 8
|
||||
#define GZipState_Comment 9
|
||||
#define GZipState_Done 10
|
||||
#define GZIP_STATE_HEADER1 0
|
||||
#define GZIP_STATE_HEADER2 1
|
||||
#define GZIP_STATE_COMPRESSIONMETHOD 2
|
||||
#define GZIP_STATE_FLAGS 3
|
||||
#define GZIP_STATE_LASTMODIFIEDTIME 4
|
||||
#define GZIP_STATE_COMPRESSIONFLAGS 5
|
||||
#define GZIP_STATE_OPERATINGSYSTEM 6
|
||||
#define GZIP_STATE_HEADERCHECKSUM 7
|
||||
#define GZIP_STATE_FILENAME 8
|
||||
#define GZIP_STATE_COMMENT 9
|
||||
#define GZIP_STATE_DONE 10
|
||||
|
||||
void GZipHeader_Init(GZipHeader* header) {
|
||||
header->State = GZipState_Header1;
|
||||
header->State = GZIP_STATE_HEADER1;
|
||||
header->Done = false;
|
||||
header->Flags = 0;
|
||||
header->PartsRead = 0;
|
||||
@ -36,31 +36,31 @@ void GZipHeader_Read(Stream* s, GZipHeader* header) {
|
||||
Int32 temp;
|
||||
switch (header->State) {
|
||||
|
||||
case GZipState_Header1:
|
||||
case GZIP_STATE_HEADER1:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
if (temp != 0x1F) {
|
||||
ErrorHandler_Fail("Byte 1 of GZIP header must be 1F");
|
||||
}
|
||||
|
||||
case GZipState_Header2:
|
||||
case GZIP_STATE_HEADER2:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
if (temp != 0x8B) {
|
||||
ErrorHandler_Fail("Byte 2 of GZIP header must be 8B");
|
||||
}
|
||||
|
||||
case GZipState_CompressionMethod:
|
||||
case GZIP_STATE_COMPRESSIONMETHOD:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
if (temp != 0x08) {
|
||||
ErrorHandler_Fail("Only DEFLATE compression supported");
|
||||
}
|
||||
|
||||
case GZipState_Flags:
|
||||
case GZIP_STATE_FLAGS:
|
||||
if (!Header_ReadByte(s, &header->State, &header->Flags)) return;
|
||||
if ((header->Flags & 0x04) != 0) {
|
||||
ErrorHandler_Fail("Unsupported GZIP header flags");
|
||||
}
|
||||
|
||||
case GZipState_LastModifiedTime:
|
||||
case GZIP_STATE_LASTMODIFIEDTIME:
|
||||
for (; header->PartsRead < 4; header->PartsRead++) {
|
||||
temp = Stream_TryReadByte(s);
|
||||
if (temp == -1) return;
|
||||
@ -68,13 +68,13 @@ void GZipHeader_Read(Stream* s, GZipHeader* header) {
|
||||
header->State++;
|
||||
header->PartsRead = 0;
|
||||
|
||||
case GZipState_CompressionFlags:
|
||||
case GZIP_STATE_COMPRESSIONFLAGS:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
|
||||
case GZipState_OperatingSystem:
|
||||
case GZIP_STATE_OPERATINGSYSTEM:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
|
||||
case GZipState_Filename:
|
||||
case GZIP_STATE_FILENAME:
|
||||
if ((header->Flags & 0x08) != 0) {
|
||||
for (; ;) {
|
||||
temp = Stream_TryReadByte(s);
|
||||
@ -84,7 +84,7 @@ void GZipHeader_Read(Stream* s, GZipHeader* header) {
|
||||
}
|
||||
header->State++;
|
||||
|
||||
case GZipState_Comment:
|
||||
case GZIP_STATE_COMMENT:
|
||||
if ((header->Flags & 0x10) != 0) {
|
||||
for (; ;) {
|
||||
temp = Stream_TryReadByte(s);
|
||||
@ -94,7 +94,7 @@ void GZipHeader_Read(Stream* s, GZipHeader* header) {
|
||||
}
|
||||
header->State++;
|
||||
|
||||
case GZipState_HeaderChecksum:
|
||||
case GZIP_STATE_HEADERCHECKSUM:
|
||||
if ((header->Flags & 0x02) != 0) {
|
||||
for (; header->PartsRead < 2; header->PartsRead++) {
|
||||
temp = Stream_TryReadByte(s);
|
||||
@ -109,12 +109,12 @@ void GZipHeader_Read(Stream* s, GZipHeader* header) {
|
||||
}
|
||||
|
||||
|
||||
#define ZLibState_CompressionMethod 0
|
||||
#define ZLibState_Flags 1
|
||||
#define ZLibState_Done 2
|
||||
#define ZLIB_STATE_COMPRESSIONMETHOD 0
|
||||
#define ZLIB_STATE_FLAGS 1
|
||||
#define ZLIB_STATE_DONE 2
|
||||
|
||||
void ZLibHeader_Init(ZLibHeader* header) {
|
||||
header->State = ZLibState_CompressionMethod;
|
||||
header->State = ZLIB_STATE_COMPRESSIONMETHOD;
|
||||
header->Done = false;
|
||||
header->LZ77WindowSize = 0;
|
||||
}
|
||||
@ -123,7 +123,7 @@ void ZLibHeader_Read(Stream* s, ZLibHeader* header) {
|
||||
Int32 temp;
|
||||
switch (header->State) {
|
||||
|
||||
case ZLibState_CompressionMethod:
|
||||
case ZLIB_STATE_COMPRESSIONMETHOD:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
if ((temp & 0x0F) != 0x08) {
|
||||
ErrorHandler_Fail("Only DEFLATE compression supported");
|
||||
@ -135,7 +135,7 @@ void ZLibHeader_Read(Stream* s, ZLibHeader* header) {
|
||||
ErrorHandler_Fail("LZ77 window size must be 32KB or less");
|
||||
}
|
||||
|
||||
case ZLibState_Flags:
|
||||
case ZLIB_STATE_FLAGS:
|
||||
if (!Header_ReadByte(s, &header->State, &temp)) return;
|
||||
if ((temp & 0x20) != 0) {
|
||||
ErrorHandler_Fail("Unsupported ZLIB header flags");
|
||||
@ -145,44 +145,44 @@ void ZLibHeader_Read(Stream* s, ZLibHeader* header) {
|
||||
}
|
||||
|
||||
|
||||
#define DeflateState_Header 0
|
||||
#define DeflateState_UncompressedHeader 1
|
||||
#define DeflateState_UncompressedData 2
|
||||
#define DeflateState_DynamicHeader 3
|
||||
#define DeflateState_DynamicCodeLens 4
|
||||
#define DeflateState_DynamicLitsDists 5
|
||||
#define DeflateState_DynamicLitsDistsRepeat 6
|
||||
#define DeflateState_CompressedLit 7
|
||||
#define DeflateState_CompressedLitRepeat 8
|
||||
#define DeflateState_CompressedDist 9
|
||||
#define DeflateState_CompressedDistRepeat 10
|
||||
#define DeflateState_CompressedData 11
|
||||
#define DeflateState_FastCompressed 12
|
||||
#define DeflateState_Done 13
|
||||
#define DEFLATE_STATE_HEADER 0
|
||||
#define DEFLATE_STATE_UNCOMPRESSED_HEADER 1
|
||||
#define DEFLATE_STATE_UNCOMPRESSED_DATA 2
|
||||
#define DEFLATE_STATE_DYNAMIC_HEADER 3
|
||||
#define DEFLATE_STATE_DYNAMIC_CODELENS 4
|
||||
#define DEFLATE_STATE_DYNAMIC_LITSDISTS 5
|
||||
#define DEFLATE_STATE_DYNAMIC_LITSDISTSREPEAT 6
|
||||
#define DEFLATE_STATE_COMPRESSED_LIT 7
|
||||
#define DEFLATE_STATE_COMPRESSED_LITREPEAT 8
|
||||
#define DEFLATE_STATE_COMPRESSED_DIST 9
|
||||
#define DEFLATE_STATE_COMPRESSED_DISTREPEAT 10
|
||||
#define DEFLATE_STATE_COMPRESSED_DATA 11
|
||||
#define DEFLATE_STATE_FASTCOMPRESSED 12
|
||||
#define DEFLATE_STATE_DONE 13
|
||||
|
||||
/* Insert this byte into the bit buffer */
|
||||
#define DEFLATE_GET_BYTE(state) state->AvailIn--; state->Bits |= (UInt32)(state->Input[state->NextIn]) << state->NumBits; state->NextIn++; state->NumBits += 8;
|
||||
#define Deflate_GetByte(state) state->AvailIn--; state->Bits |= (UInt32)(state->Input[state->NextIn]) << state->NumBits; state->NextIn++; state->NumBits += 8;
|
||||
/* Retrieves bits from the bit buffer */
|
||||
#define DEFLATE_PEEK_BITS(state, bits) (state->Bits & ((1UL << (bits)) - 1UL))
|
||||
#define Deflate_PeekBits(state, bits) (state->Bits & ((1UL << (bits)) - 1UL))
|
||||
/* Consumes/eats up bits from the bit buffer */
|
||||
#define DEFLATE_CONSUME_BITS(state, bits) state->Bits >>= (bits); state->NumBits -= (bits);
|
||||
#define Deflate_ConsumeBits(state, bits) state->Bits >>= (bits); state->NumBits -= (bits);
|
||||
/* Aligns bit buffer to be on a byte boundary*/
|
||||
#define DEFLATE_ALIGN_BITS(state) UInt32 alignSkip = state->NumBits & 7; DEFLATE_CONSUME_BITS(state, alignSkip);
|
||||
#define Deflate_AlignBits(state) UInt32 alignSkip = state->NumBits & 7; Deflate_ConsumeBits(state, alignSkip);
|
||||
/* Ensures there are 'bitsCount' bits, or returns false if not. */
|
||||
#define DEFLATE_ENSURE_BITS(state, bitsCount) while (state->NumBits < bitsCount) { if (state->AvailIn == 0) return; DEFLATE_GET_BYTE(state); }
|
||||
#define Deflate_EnsureBits(state, bitsCount) while (state->NumBits < bitsCount) { if (state->AvailIn == 0) return; Deflate_GetByte(state); }
|
||||
/* Ensures there are 'bitsCount' bits. */
|
||||
#define DEFLATE_UNSAFE_ENSURE_BITS(state, bitsCount) while (state->NumBits < bitsCount) { DEFLATE_GET_BYTE(state); }
|
||||
#define Deflate_UNSAFE_EnsureBits(state, bitsCount) while (state->NumBits < bitsCount) { Deflate_GetByte(state); }
|
||||
/* Peeks then consumes given bits. */
|
||||
#define DEFLATE_READ_BITS(state, bitsCount) DEFLATE_PEEK_BITS(state, bitsCount); DEFLATE_CONSUME_BITS(state, bitsCount);
|
||||
#define Deflate_ReadBits(state, bitsCount) Deflate_PeekBits(state, bitsCount); Deflate_ConsumeBits(state, bitsCount);
|
||||
|
||||
/* Goes to the next state, after having read data of a block. */
|
||||
#define DEFLATE_NEXTBLOCK_STATE(state) (state->LastBlock ? DeflateState_Done : DeflateState_Header)
|
||||
#define Deflate_NextBlockState(state) (state->LastBlock ? DEFLATE_STATE_DONE : DEFLATE_STATE_HEADER)
|
||||
/* Goes to the next state, after having finished reading a compressed entry. */
|
||||
/* The maximum amount of bytes that can be output is 258. */
|
||||
/* The most input bytes required for huffman codes and extra data is 16 + 5 + 16 + 13 bits. Add 3 extra bytes to account for putting data into the bit buffer. */
|
||||
#define DEFLATE_FASTINF_OUT 258
|
||||
#define DEFLATE_FASTINF_IN 10
|
||||
#define DEFLATE_NEXTCOMPRESS_STATE(state) ((state->AvailIn >= DEFLATE_FASTINF_IN && state->AvailOut >= DEFLATE_FASTINF_OUT) ? DeflateState_FastCompressed : DeflateState_CompressedLit)
|
||||
#define Deflate_NextCompressState(state) ((state->AvailIn >= DEFLATE_FASTINF_IN && state->AvailOut >= DEFLATE_FASTINF_OUT) ? DEFLATE_STATE_FASTCOMPRESSED : DEFLATE_STATE_COMPRESSED_LIT)
|
||||
|
||||
UInt32 Huffman_ReverseBits(UInt32 n, UInt8 bits) {
|
||||
n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
|
||||
@ -260,15 +260,15 @@ Int32 Huffman_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
/* Buffer as many bits as possible */
|
||||
while (state->NumBits <= DEFLATE_MAX_BITS) {
|
||||
if (state->AvailIn == 0) break;
|
||||
DEFLATE_GET_BYTE(state);
|
||||
Deflate_GetByte(state);
|
||||
}
|
||||
|
||||
/* Try fast accelerated table lookup */
|
||||
if (state->NumBits >= 9) {
|
||||
Int32 packed = table->Fast[DEFLATE_PEEK_BITS(state, DEFLATE_ZFAST_BITS)];
|
||||
Int32 packed = table->Fast[Deflate_PeekBits(state, DEFLATE_ZFAST_BITS)];
|
||||
if (packed >= 0) {
|
||||
Int32 bits = packed >> 9;
|
||||
DEFLATE_CONSUME_BITS(state, bits);
|
||||
Deflate_ConsumeBits(state, bits);
|
||||
return packed & 0x1FF;
|
||||
}
|
||||
}
|
||||
@ -282,7 +282,7 @@ Int32 Huffman_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
|
||||
if (codeword < table->EndCodewords[i]) {
|
||||
Int32 offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
DEFLATE_CONSUME_BITS(state, i);
|
||||
Deflate_ConsumeBits(state, i);
|
||||
return table->Values[offset];
|
||||
}
|
||||
}
|
||||
@ -292,12 +292,12 @@ Int32 Huffman_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
}
|
||||
|
||||
Int32 Huffman_Unsafe_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
DEFLATE_UNSAFE_ENSURE_BITS(state, DEFLATE_MAX_BITS);
|
||||
UInt32 codeword = DEFLATE_PEEK_BITS(state, DEFLATE_ZFAST_BITS);
|
||||
Deflate_UNSAFE_EnsureBits(state, DEFLATE_MAX_BITS);
|
||||
UInt32 codeword = Deflate_PeekBits(state, DEFLATE_ZFAST_BITS);
|
||||
Int32 packed = table->Fast[codeword];
|
||||
if (packed >= 0) {
|
||||
Int32 bits = packed >> 9;
|
||||
DEFLATE_CONSUME_BITS(state, bits);
|
||||
Deflate_ConsumeBits(state, bits);
|
||||
return packed & 0x1FF;
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ Int32 Huffman_Unsafe_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
|
||||
if (codeword < table->EndCodewords[i]) {
|
||||
Int32 offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
DEFLATE_CONSUME_BITS(state, i);
|
||||
Deflate_ConsumeBits(state, i);
|
||||
return table->Values[offset];
|
||||
}
|
||||
}
|
||||
@ -319,7 +319,7 @@ Int32 Huffman_Unsafe_Decode(DeflateState* state, HuffmanTable* table) {
|
||||
}
|
||||
|
||||
void Deflate_Init(DeflateState* state, Stream* source) {
|
||||
state->State = DeflateState_Header;
|
||||
state->State = DEFLATE_STATE_HEADER;
|
||||
state->Source = source;
|
||||
state->Bits = 0;
|
||||
state->NumBits = 0;
|
||||
@ -374,19 +374,19 @@ void Deflate_InflateFast(DeflateState* state) {
|
||||
state->AvailOut--; copyLen++;
|
||||
curIdx = (curIdx + 1) & DEFLATE_WINDOW_MASK;
|
||||
} else {
|
||||
state->State = DEFLATE_NEXTBLOCK_STATE(state);
|
||||
state->State = Deflate_NextBlockState(state);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
UInt32 lenIdx = lit - 257;
|
||||
UInt32 bits = len_bits[lenIdx];
|
||||
DEFLATE_UNSAFE_ENSURE_BITS(state, bits);
|
||||
UInt32 len = len_base[lenIdx] + DEFLATE_READ_BITS(state, bits);
|
||||
Deflate_UNSAFE_EnsureBits(state, bits);
|
||||
UInt32 len = len_base[lenIdx] + Deflate_ReadBits(state, bits);
|
||||
|
||||
UInt32 distIdx = Huffman_Unsafe_Decode(state, &state->DistsTable);
|
||||
bits = dist_bits[distIdx];
|
||||
DEFLATE_UNSAFE_ENSURE_BITS(state, bits);
|
||||
UInt32 dist = dist_base[distIdx] + DEFLATE_READ_BITS(state, bits);
|
||||
Deflate_UNSAFE_EnsureBits(state, bits);
|
||||
UInt32 dist = dist_base[distIdx] + Deflate_ReadBits(state, bits);
|
||||
|
||||
UInt32 startIdx = (curIdx - dist) & DEFLATE_WINDOW_MASK;
|
||||
UInt32 i;
|
||||
@ -424,25 +424,25 @@ void Deflate_InflateFast(DeflateState* state) {
|
||||
void Deflate_Process(DeflateState* state) {
|
||||
for (;;) {
|
||||
switch (state->State) {
|
||||
case DeflateState_Header: {
|
||||
DEFLATE_ENSURE_BITS(state, 3);
|
||||
UInt32 blockHeader = DEFLATE_READ_BITS(state, 3);
|
||||
case DEFLATE_STATE_HEADER: {
|
||||
Deflate_EnsureBits(state, 3);
|
||||
UInt32 blockHeader = Deflate_ReadBits(state, 3);
|
||||
state->LastBlock = blockHeader & 1;
|
||||
|
||||
switch (blockHeader >> 1) {
|
||||
case 0: { /* Uncompressed block */
|
||||
DEFLATE_ALIGN_BITS(state);
|
||||
state->State = DeflateState_UncompressedHeader;
|
||||
Deflate_AlignBits(state);
|
||||
state->State = DEFLATE_STATE_UNCOMPRESSED_HEADER;
|
||||
} break;
|
||||
|
||||
case 1: { /* Fixed/static huffman compressed */
|
||||
Huffman_Build(&state->LitsTable, fixed_lits, DEFLATE_MAX_LITS);
|
||||
Huffman_Build(&state->DistsTable, fixed_dists, DEFLATE_MAX_DISTS);
|
||||
state->State = DEFLATE_NEXTCOMPRESS_STATE(state);
|
||||
state->State = Deflate_NextCompressState(state);
|
||||
} break;
|
||||
|
||||
case 2: { /* Dynamic huffman compressed */
|
||||
state->State = DeflateState_DynamicHeader;
|
||||
state->State = DEFLATE_STATE_DYNAMIC_HEADER;
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
@ -453,21 +453,21 @@ void Deflate_Process(DeflateState* state) {
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_UncompressedHeader: {
|
||||
DEFLATE_ENSURE_BITS(state, 32);
|
||||
UInt32 len = DEFLATE_READ_BITS(state, 16);
|
||||
UInt32 nlen = DEFLATE_READ_BITS(state, 16);
|
||||
case DEFLATE_STATE_UNCOMPRESSED_HEADER: {
|
||||
Deflate_EnsureBits(state, 32);
|
||||
UInt32 len = Deflate_ReadBits(state, 16);
|
||||
UInt32 nlen = Deflate_ReadBits(state, 16);
|
||||
|
||||
if (len != (nlen ^ 0xFFFFUL)) {
|
||||
ErrorHandler_Fail("DEFLATE - Uncompressed block LEN check failed");
|
||||
}
|
||||
state->Index = len; /* Reuse for 'uncompressed length' */
|
||||
state->State = DeflateState_UncompressedData;
|
||||
state->State = DEFLATE_STATE_UNCOMPRESSED_DATA;
|
||||
}
|
||||
|
||||
case DeflateState_UncompressedData: {
|
||||
case DEFLATE_STATE_UNCOMPRESSED_DATA: {
|
||||
while (state->NumBits > 0 && state->AvailOut > 0 && state->Index > 0) {
|
||||
*state->Output = DEFLATE_READ_BITS(state, 8);
|
||||
*state->Output = Deflate_ReadBits(state, 8);
|
||||
state->AvailOut--;
|
||||
state->Index--;
|
||||
}
|
||||
@ -484,26 +484,26 @@ void Deflate_Process(DeflateState* state) {
|
||||
}
|
||||
|
||||
if (state->Index == 0) {
|
||||
state->State = DEFLATE_NEXTBLOCK_STATE(state);
|
||||
state->State = Deflate_NextBlockState(state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_DynamicHeader: {
|
||||
DEFLATE_ENSURE_BITS(state, 14);
|
||||
state->NumLits = 257 + DEFLATE_READ_BITS(state, 5);
|
||||
state->NumDists = 1 + DEFLATE_READ_BITS(state, 5);
|
||||
state->NumCodeLens = 4 + DEFLATE_READ_BITS(state, 4);
|
||||
case DEFLATE_STATE_DYNAMIC_HEADER: {
|
||||
Deflate_EnsureBits(state, 14);
|
||||
state->NumLits = 257 + Deflate_ReadBits(state, 5);
|
||||
state->NumDists = 1 + Deflate_ReadBits(state, 5);
|
||||
state->NumCodeLens = 4 + Deflate_ReadBits(state, 4);
|
||||
state->Index = 0;
|
||||
state->State = DeflateState_DynamicCodeLens;
|
||||
state->State = DEFLATE_STATE_DYNAMIC_CODELENS;
|
||||
}
|
||||
|
||||
case DeflateState_DynamicCodeLens: {
|
||||
case DEFLATE_STATE_DYNAMIC_CODELENS: {
|
||||
Int32 i;
|
||||
while (state->Index < state->NumCodeLens) {
|
||||
DEFLATE_ENSURE_BITS(state, 3);
|
||||
Deflate_EnsureBits(state, 3);
|
||||
i = codelens_order[state->Index];
|
||||
state->Buffer[i] = DEFLATE_READ_BITS(state, 3);
|
||||
state->Buffer[i] = Deflate_ReadBits(state, 3);
|
||||
state->Index++;
|
||||
}
|
||||
for (i = state->NumCodeLens; i < DEFLATE_MAX_CODELENS; i++) {
|
||||
@ -511,11 +511,11 @@ void Deflate_Process(DeflateState* state) {
|
||||
}
|
||||
|
||||
state->Index = 0;
|
||||
state->State = DeflateState_DynamicLitsDists;
|
||||
state->State = DEFLATE_STATE_DYNAMIC_LITSDISTS;
|
||||
Huffman_Build(&state->CodeLensTable, state->Buffer, DEFLATE_MAX_CODELENS);
|
||||
}
|
||||
|
||||
case DeflateState_DynamicLitsDists: {
|
||||
case DEFLATE_STATE_DYNAMIC_LITSDISTS: {
|
||||
UInt32 count = state->NumLits + state->NumDists;
|
||||
while (state->Index < count) {
|
||||
Int32 bits = Huffman_Decode(state, &state->CodeLensTable);
|
||||
@ -525,28 +525,28 @@ void Deflate_Process(DeflateState* state) {
|
||||
state->Index++;
|
||||
} else {
|
||||
state->TmpCodeLens = bits;
|
||||
state->State = DeflateState_DynamicLitsDistsRepeat;
|
||||
state->State = DEFLATE_STATE_DYNAMIC_LITSDISTSREPEAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->Index == count) {
|
||||
state->Index = 0;
|
||||
state->State = DEFLATE_NEXTCOMPRESS_STATE(state);
|
||||
state->State = Deflate_NextCompressState(state);
|
||||
Huffman_Build(&state->LitsTable, state->Buffer, state->NumLits);
|
||||
Huffman_Build(&state->DistsTable, &state->Buffer[state->NumLits], state->NumDists);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_DynamicLitsDistsRepeat: {
|
||||
case DEFLATE_STATE_DYNAMIC_LITSDISTSREPEAT: {
|
||||
UInt32 repeatCount;
|
||||
UInt8 repeatValue;
|
||||
|
||||
switch (state->TmpCodeLens) {
|
||||
case 16:
|
||||
DEFLATE_ENSURE_BITS(state, 2);
|
||||
repeatCount = DEFLATE_READ_BITS(state, 2);
|
||||
Deflate_EnsureBits(state, 2);
|
||||
repeatCount = Deflate_ReadBits(state, 2);
|
||||
if (state->Index == 0) {
|
||||
ErrorHandler_Fail("DEFLATE - Tried to repeat invalid byte");
|
||||
}
|
||||
@ -554,14 +554,14 @@ void Deflate_Process(DeflateState* state) {
|
||||
break;
|
||||
|
||||
case 17:
|
||||
DEFLATE_ENSURE_BITS(state, 3);
|
||||
repeatCount = DEFLATE_READ_BITS(state, 3);
|
||||
Deflate_EnsureBits(state, 3);
|
||||
repeatCount = Deflate_ReadBits(state, 3);
|
||||
repeatCount += 3; repeatValue = 0;
|
||||
break;
|
||||
|
||||
case 18:
|
||||
DEFLATE_ENSURE_BITS(state, 7);
|
||||
repeatCount = DEFLATE_READ_BITS(state, 7);
|
||||
Deflate_EnsureBits(state, 7);
|
||||
repeatCount = Deflate_ReadBits(state, 7);
|
||||
repeatCount += 11; repeatValue = 0;
|
||||
break;
|
||||
}
|
||||
@ -573,11 +573,11 @@ void Deflate_Process(DeflateState* state) {
|
||||
|
||||
Platform_MemSet(&state->Buffer[state->Index], repeatValue, repeatCount);
|
||||
state->Index += repeatCount;
|
||||
state->State = DeflateState_DynamicLitsDists;
|
||||
state->State = DEFLATE_STATE_DYNAMIC_LITSDISTS;
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_CompressedLit: {
|
||||
case DEFLATE_STATE_COMPRESSED_LIT: {
|
||||
if (state->AvailOut == 0) return;
|
||||
|
||||
Int32 lit = Huffman_Decode(state, &state->LitsTable);
|
||||
@ -589,37 +589,37 @@ void Deflate_Process(DeflateState* state) {
|
||||
state->WindowIndex = (state->WindowIndex + 1) & DEFLATE_WINDOW_MASK;
|
||||
break;
|
||||
} else if (lit == 256) {
|
||||
state->State = DEFLATE_NEXTBLOCK_STATE(state);
|
||||
state->State = Deflate_NextBlockState(state);
|
||||
break;
|
||||
} else {
|
||||
state->TmpLit = lit - 257;
|
||||
state->State = DeflateState_CompressedLitRepeat;
|
||||
state->State = DEFLATE_STATE_COMPRESSED_LITREPEAT;
|
||||
}
|
||||
}
|
||||
|
||||
case DeflateState_CompressedLitRepeat: {
|
||||
case DEFLATE_STATE_COMPRESSED_LITREPEAT: {
|
||||
UInt32 lenIdx = (UInt32)state->TmpLit;
|
||||
UInt32 bits = len_bits[lenIdx];
|
||||
DEFLATE_ENSURE_BITS(state, bits);
|
||||
state->TmpLit = len_base[lenIdx] + DEFLATE_READ_BITS(state, bits);
|
||||
state->State = DeflateState_CompressedDist;
|
||||
Deflate_EnsureBits(state, bits);
|
||||
state->TmpLit = len_base[lenIdx] + Deflate_ReadBits(state, bits);
|
||||
state->State = DEFLATE_STATE_COMPRESSED_DIST;
|
||||
}
|
||||
|
||||
case DeflateState_CompressedDist: {
|
||||
case DEFLATE_STATE_COMPRESSED_DIST: {
|
||||
state->TmpDist = Huffman_Decode(state, &state->DistsTable);
|
||||
if (state->TmpDist == -1) return;
|
||||
state->State = DeflateState_CompressedDistRepeat;
|
||||
state->State = DEFLATE_STATE_COMPRESSED_DISTREPEAT;
|
||||
}
|
||||
|
||||
case DeflateState_CompressedDistRepeat: {
|
||||
case DEFLATE_STATE_COMPRESSED_DISTREPEAT: {
|
||||
UInt32 distIdx = (UInt32)state->TmpDist;
|
||||
UInt32 bits = dist_bits[distIdx];
|
||||
DEFLATE_ENSURE_BITS(state, bits);
|
||||
state->TmpDist = dist_base[distIdx] + DEFLATE_READ_BITS(state, bits);
|
||||
state->State = DeflateState_CompressedData;
|
||||
Deflate_EnsureBits(state, bits);
|
||||
state->TmpDist = dist_base[distIdx] + Deflate_ReadBits(state, bits);
|
||||
state->State = DEFLATE_STATE_COMPRESSED_DATA;
|
||||
}
|
||||
|
||||
case DeflateState_CompressedData: {
|
||||
case DEFLATE_STATE_COMPRESSED_DATA: {
|
||||
if (state->AvailOut == 0) return;
|
||||
UInt32 len = (UInt32)state->TmpLit, dist = (UInt32)state->TmpDist;
|
||||
len = min(len, state->AvailOut);
|
||||
@ -637,19 +637,19 @@ void Deflate_Process(DeflateState* state) {
|
||||
state->WindowIndex = (curIdx + len) & DEFLATE_WINDOW_MASK;
|
||||
state->TmpLit -= len;
|
||||
state->AvailOut -= len;
|
||||
if (state->TmpLit == 0) { state->State = DEFLATE_NEXTCOMPRESS_STATE(state); }
|
||||
if (state->TmpLit == 0) { state->State = Deflate_NextCompressState(state); }
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_FastCompressed: {
|
||||
case DEFLATE_STATE_FASTCOMPRESSED: {
|
||||
Deflate_InflateFast(state);
|
||||
if (state->State == DeflateState_FastCompressed) {
|
||||
state->State = DEFLATE_NEXTCOMPRESS_STATE(state);
|
||||
if (state->State == DEFLATE_STATE_FASTCOMPRESSED) {
|
||||
state->State = Deflate_NextCompressState(state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DeflateState_Done:
|
||||
case DEFLATE_STATE_DONE:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +155,9 @@ Int32 Menu_HandleMouseMove(Widget** widgets, Int32 count, Int32 x, Int32 y) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------ListScreen-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE ListScreen_VTABLE;
|
||||
ListScreen ListScreen_Instance;
|
||||
STRING_REF String ListScreen_UNSAFE_Get(ListScreen* screen, UInt32 index) {
|
||||
@ -314,6 +317,9 @@ Screen* ListScreen_MakeInstance(void) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------MenuScreen-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE MenuScreen_VTABLE;
|
||||
Int32 MenuScreen_Index(MenuScreen* screen, Widget* w) {
|
||||
Int32 i;
|
||||
@ -332,11 +338,15 @@ bool MenuScreen_HandlesMouseMove(GuiElement* elem, Int32 x, Int32 y) {
|
||||
MenuScreen* screen = (MenuScreen*)elem;
|
||||
return Menu_HandleMouseMove(screen->WidgetsPtr, screen->WidgetsCount, x, y) >= 0;
|
||||
}
|
||||
bool MenuScreen_HandlesMouseMove(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) { return true; }
|
||||
bool MenuScreen_HandlesMouseScroll(GuiElement* elem, Real32 delta) { return true; }
|
||||
|
||||
bool MenuScreen_TrueMouse(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) { return true; }
|
||||
bool MenuScreen_TrueMouseScroll(GuiElement* elem, Real32 delta) { return true; }
|
||||
bool MenuScreen_TrueKeyPress(GuiElement* elem, UInt8 key) { return true; }
|
||||
bool MenuScreen_TrueKey(GuiElement* elem, Key key) { return true; }
|
||||
bool MenuScreen_HandlesKeyDown(GuiElement* elem, Key key) {
|
||||
if (key == Key_Escape) { Gui_SetNewScreen(NULL); }
|
||||
return key < Key_F1 || key > Key_F35;
|
||||
}
|
||||
bool MenuScreen_HandlesKeyPress(GuiElement* elem, UInt8 key) { return true; }
|
||||
bool MenuScreen_HandlesKeyUp(GuiElement* elem, Key key) { return true; }
|
||||
|
||||
void MenuScreen_ContextLost(void* obj) {
|
||||
MenuScreen* screen = (MenuScreen*)obj;
|
||||
@ -387,18 +397,18 @@ void MenuScreen_MakeInstance(MenuScreen* screen, Widget** widgets, Int32 count,
|
||||
screen->VTABLE = &MenuScreen_VTABLE;
|
||||
Screen_Reset((Screen*)screen);
|
||||
|
||||
screen->VTABLE->HandlesKeyDown = MenuScreen_TrueKey;
|
||||
screen->VTABLE->HandlesKeyUp = MenuScreen_TrueKey;
|
||||
screen->VTABLE->HandlesKeyPress = MenuScreen_TrueKeyPress;
|
||||
screen->VTABLE->HandlesKeyDown = MenuScreen_HandlesKeyDown;
|
||||
screen->VTABLE->HandlesKeyUp = MenuScreen_HandlesKeyUp;
|
||||
screen->VTABLE->HandlesKeyPress = MenuScreen_HandlesKeyPress;
|
||||
screen->VTABLE->HandlesMouseDown = MenuScreen_HandlesMouseDown;
|
||||
screen->VTABLE->HandlesMouseUp = MenuScreen_TrueMouse;
|
||||
screen->VTABLE->HandlesMouseUp = MenuScreen_HandlesMouseMove;
|
||||
screen->VTABLE->HandlesMouseMove = MenuScreen_HandlesMouseMove;
|
||||
screen->VTABLE->HandlesMouseScroll = MenuScreen_TrueMouseScroll;
|
||||
screen->VTABLE->HandlesMouseScroll = MenuScreen_HandlesMouseScroll;
|
||||
|
||||
screen->OnResize = MenuScreen_OnResize;
|
||||
screen->VTABLE->Init = MenuScreen_Init;
|
||||
screen->VTABLE->Render = MenuScreen_Render;
|
||||
screen->VTABLE->Free = MenuScreen_Free;
|
||||
screen->OnResize = MenuScreen_OnResize;
|
||||
screen->VTABLE->Init = MenuScreen_Init;
|
||||
screen->VTABLE->Render = MenuScreen_Render;
|
||||
screen->VTABLE->Free = MenuScreen_Free;
|
||||
|
||||
screen->HandlesAllInput = true;
|
||||
screen->WidgetsPtr = widgets;
|
||||
@ -407,9 +417,11 @@ void MenuScreen_MakeInstance(MenuScreen* screen, Widget** widgets, Int32 count,
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------PauseScreen-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE PauseScreen_VTABLE;
|
||||
PauseScreen PauseScreen_Instance;
|
||||
|
||||
void PauseScreen_Make(PauseScreen* screen, Int32 i, Int32 dir, Int32 y, const UInt8* title, Widget_LeftClick onClick) {
|
||||
String text = String_FromRaw(title, UInt16_MaxValue);
|
||||
ButtonWidget* btn = &screen->Buttons[i];
|
||||
@ -498,11 +510,6 @@ void PauseScreen_Free(GuiElement* elem) {
|
||||
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, screen, PauseScreen_CheckHacksAllowed);
|
||||
}
|
||||
|
||||
bool PauseScreen_HandlesKeyDown(GuiElement* elem, Key key) {
|
||||
if (key == Key_Escape) { Gui_SetNewScreen(NULL); }
|
||||
return key < Key_F1 || key > Key_F35;
|
||||
}
|
||||
|
||||
Screen* PauseScreen_MakeInstance(void) {
|
||||
PauseScreen* screen = &PauseScreen_Instance;
|
||||
MenuScreen_MakeInstance((MenuScreen*)screen, screen->Widgets, Array_Elems(screen->Widgets), PauseScreen_ContextRecreated);
|
||||
@ -511,11 +518,13 @@ Screen* PauseScreen_MakeInstance(void) {
|
||||
|
||||
screen->VTABLE->Init = PauseScreen_Init;
|
||||
screen->VTABLE->Free = PauseScreen_Free;
|
||||
screen->VTABLE->HandlesKeyDown = PauseScreen_HandlesKeyDown;
|
||||
return screen;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------OptionsGroupScreen-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE OptionsGroupScreen_VTABLE;
|
||||
OptionsGroupScreen OptionsGroupScreen_Instance;
|
||||
const UInt8* optsGroup_descs[7] = {
|
||||
@ -612,9 +621,38 @@ Screen* OptionsGroupScreen_MakeInstance(void) {
|
||||
screen->VTABLE->Init = OptionsGroupScreen_Init;
|
||||
screen->VTABLE->Free = OptionsGroupScreen_Free;
|
||||
screen->VTABLE->HandlesMouseMove = OptionsGroupScreen_HandlesMouseMove;
|
||||
/* Pause screen key down behaviour is same for options group screen*/
|
||||
screen->VTABLE->HandlesKeyDown = PauseScreen_HandlesKeyDown;
|
||||
|
||||
screen->SelectedI = -1;
|
||||
return screen;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------DeathScreen--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
|
||||
void DeathScreen_Gen(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(GenLevelScreen_MakeInstance()); }
|
||||
void DeathScreen_Load(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(LoadLevelScreen_MakeInstance()); }
|
||||
|
||||
void DeathScreen_Init(GuiElement* elem) {
|
||||
base.Init();
|
||||
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
|
||||
regularFont = new Font(game.FontName, 40);
|
||||
ContextRecreated();
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) { return true; }
|
||||
|
||||
void DeathScreen_ContextRecreated(void* obj) {
|
||||
string score = game.Chat.Status1.Text;
|
||||
widgets = new Widget[]{
|
||||
TextWidget.Create(game, "Game over!", regularFont)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -150),
|
||||
TextWidget.Create(game, score, titleFont)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -75),
|
||||
ButtonWidget.Create(game, 400, "Generate new level...", titleFont, GenLevelClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 25),
|
||||
ButtonWidget.Create(game, 400, "Load level...", titleFont, LoadLevelClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 75),
|
||||
};
|
||||
}
|
@ -94,6 +94,9 @@ typedef struct DisconnectScreen_ {
|
||||
} DisconnectScreen;
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------InventoryScreen-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE InventoryScreen_VTABLE;
|
||||
InventoryScreen InventoryScreen_Instance;
|
||||
void InventoryScreen_OnBlockChanged(void* obj) {
|
||||
@ -240,6 +243,9 @@ Screen* InventoryScreen_MakeInstance(void) {
|
||||
extern Screen* InventoryScreen_UNSAFE_RawPointer = (Screen*)&InventoryScreen_Instance;
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------StatusScreen------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE StatusScreen_VTABLE;
|
||||
StatusScreen StatusScreen_Instance;
|
||||
void StatusScreen_MakeText(StatusScreen* screen, STRING_TRANSIENT String* status) {
|
||||
@ -269,7 +275,6 @@ void StatusScreen_MakeText(StatusScreen* screen, STRING_TRANSIENT String* status
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StatusScreen_DrawPosition(StatusScreen* screen) {
|
||||
TextAtlas* atlas = &screen->PosAtlas;
|
||||
VertexP3fT2fC4b vertices[4 * 8];
|
||||
@ -431,6 +436,9 @@ IGameComponent StatusScreen_MakeComponent(void) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------LoadingScreen------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE LoadingScreen_VTABLE;
|
||||
LoadingScreen LoadingScreen_Instance;
|
||||
void LoadingScreen_SetTitle(LoadingScreen* screen) {
|
||||
@ -606,6 +614,9 @@ Screen* LoadingScreen_MakeInstance(STRING_PURE String* title, STRING_PURE String
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------GeneratingMapScreen----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE GeneratingMapScreen_VTABLE;
|
||||
GeneratingMapScreen GeneratingMapScreen_Instance;
|
||||
void GeneratingScreen_Render(GuiElement* elem, Real64 delta) {
|
||||
@ -637,6 +648,9 @@ Screen* GeneratingScreen_MakeInstance(void) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------ChatScreen-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE ChatScreen_VTABLE;
|
||||
ChatScreen ChatScreen_Instance;
|
||||
Int32 ChatScreen_BottomOffset(void) { return ((HUDScreen*)Gui_HUD)->Hotbar.Height; }
|
||||
@ -1136,6 +1150,9 @@ Screen* ChatScreen_MakeInstance(void) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------HUDScreen--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE HUDScreenVTABLE;
|
||||
HUDScreen HUDScreen_Instance;
|
||||
#define CH_EXTENT 16
|
||||
@ -1353,6 +1370,9 @@ void HUDScreen_AppendInput(Screen* hud, STRING_PURE String* text) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*----------------------------------------------------DisconnectScreen-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
GuiElementVTABLE DisconnectScreen_VTABLE;
|
||||
DisconnectScreen DisconnectScreen_Instance;
|
||||
#define DISCONNECT_DELAY_MS 5000
|
||||
|
@ -24,6 +24,10 @@ void Widget_SetLocation(Widget* widget, UInt8 horAnchor, UInt8 verAnchor, Int32
|
||||
widget->Reposition((GuiElement*)widget);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------TextWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void TextWidget_SetHeight(TextWidget* widget, Int32 height) {
|
||||
if (widget->ReducePadding) {
|
||||
Drawer2D_ReducePadding_Height(&height, widget->Font.Size, 4);
|
||||
@ -96,6 +100,10 @@ void TextWidget_SetText(TextWidget* widget, STRING_PURE String* text) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define BUTTON_uWIDTH (200.0f / 256.0f)
|
||||
Texture Button_ShadowTex = { 0, 0, 0, 0, 0, 0.0f, 66.0f / 256.0f, 200.0f / 256.0f, 86.0f / 256.0f };
|
||||
Texture Button_SelectedTex = { 0, 0, 0, 0, 0, 0.0f, 86.0f / 256.0f, 200.0f / 256.0f, 106.0f / 256.0f };
|
||||
@ -192,6 +200,9 @@ void ButtonWidget_SetText(ButtonWidget* widget, STRING_PURE String* text) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------ScrollbarWidget-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define TABLE_MAX_ROWS_DISPLAYED 8
|
||||
#define SCROLL_WIDTH 22
|
||||
#define SCROLL_BORDER 2
|
||||
@ -315,6 +326,9 @@ void ScrollbarWidget_ClampScrollY(ScrollbarWidget* widget) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------HotbarWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void HotbarWidget_RenderHotbarOutline(HotbarWidget* widget) {
|
||||
GfxResourceID texId = Game_UseClassicGui ? Gui_GuiClassicTex : Gui_GuiTex;
|
||||
widget->BackTex.ID = texId;
|
||||
@ -494,6 +508,9 @@ void HotbarWidget_Create(HotbarWidget* widget) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------TableWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
Int32 Table_X(TableWidget* widget) { return widget->X - 5 - 10; }
|
||||
Int32 Table_Y(TableWidget* widget) { return widget->Y - 5 - 30; }
|
||||
Int32 Table_Width(TableWidget* widget) {
|
||||
@ -610,7 +627,7 @@ void TableWidget_RecreateElements(TableWidget* widget) {
|
||||
widget->ElementsCount = 0;
|
||||
Int32 count = Game_UseCPE ? BLOCK_COUNT : BLOCK_ORIGINAL_COUNT, i;
|
||||
for (i = 0; i < count;) {
|
||||
if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(i)) {
|
||||
if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(widget, i)) {
|
||||
i += widget->ElementsPerRow; continue;
|
||||
}
|
||||
|
||||
@ -625,7 +642,7 @@ void TableWidget_RecreateElements(TableWidget* widget) {
|
||||
|
||||
Int32 index = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(i)) {
|
||||
if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(widget, i)) {
|
||||
i += widget->ElementsPerRow; continue;
|
||||
}
|
||||
|
||||
@ -874,6 +891,9 @@ void TableWidget_OnInventoryChanged(TableWidget* widget) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------InputWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
bool InputWidget_ControlDown(void) {
|
||||
#if CC_BUILD_OSX
|
||||
return Key_IsWinPressed();
|
||||
@ -1168,6 +1188,8 @@ void InputWidget_EndKey(InputWidget* widget) {
|
||||
|
||||
bool InputWidget_OtherKey(InputWidget* widget, Key key) {
|
||||
Int32 maxChars = widget->GetMaxLines() * INPUTWIDGET_LEN;
|
||||
if (!InputWidget_ControlDown()) return false;
|
||||
|
||||
if (key == Key_V && widget->Text.length < maxChars) {
|
||||
UInt8 textBuffer[String_BufferSize(INPUTWIDGET_MAX_LINES * STRING_SIZE)];
|
||||
String text = String_InitAndClearArray(textBuffer);
|
||||
@ -1236,7 +1258,7 @@ bool InputWidget_HandlesKeyDown(GuiElement* elem, Key key) {
|
||||
InputWidget_HomeKey(widget);
|
||||
} else if (key == Key_End) {
|
||||
InputWidget_EndKey(widget);
|
||||
} else if (InputWidget_ControlDown() && !InputWidget_OtherKey(widget, key)) {
|
||||
} else if (!InputWidget_OtherKey(widget, key)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -1320,6 +1342,9 @@ void InputWidget_Create(InputWidget* widget, FontDesc* font, STRING_REF String*
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------MenuInputValidator----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
bool MenuInputValidator_AlwaysValidChar(MenuInputValidator* validator, UInt8 c) { return true; }
|
||||
bool MenuInputValidator_AlwaysValidString(MenuInputValidator* validator, STRING_PURE String* s) { return true; }
|
||||
|
||||
@ -1493,6 +1518,9 @@ MenuInputValidator MenuInputValidator_String(void) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------MenuInputWidget-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void MenuInputWidget_Render(GuiElement* elem, Real64 delta) {
|
||||
InputWidget* widget = (InputWidget*)elem;
|
||||
PackedCol backCol = PACKEDCOL_CONST(30, 30, 30, 200);
|
||||
@ -1590,6 +1618,9 @@ void MenuInputWidget_Create(MenuInputWidget* widget, Int32 width, Int32 height,
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------ChatInputWidget-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void ChatInputWidget_Render(GuiElement* elem, Real64 delta) {
|
||||
ChatInputWidget* widget = (ChatInputWidget*)elem;
|
||||
InputWidget* input = (InputWidget*)elem;
|
||||
@ -1785,6 +1816,9 @@ void ChatInputWidget_Create(ChatInputWidget* widget, FontDesc* font) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*----------------------------------------------------PlayerListWidget-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define GROUP_NAME_ID UInt16_MaxValue
|
||||
#define LIST_COLUMN_PADDING 5
|
||||
#define LIST_BOUNDS_SIZE 10
|
||||
@ -2160,6 +2194,9 @@ void PlayerListWidget_Create(PlayerListWidget* widget, FontDesc* font, bool clas
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------TextGroupWidget-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE String* text) {
|
||||
Int32 y = widget->Y;
|
||||
Gfx_DeleteTexture(&widget->Textures[0].ID);
|
||||
@ -2362,8 +2399,9 @@ void TextGroupWidget_Create(TextGroupWidget* widget, Int32 linesCount, FontDesc*
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------SpecialInputWidget----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void SpecialInputWidget_UpdateColString(SpecialInputWidget* widget) {
|
||||
UInt32 count = 0, i;
|
||||
for (i = 0; i < DRAWER2D_MAX_COLS; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user