mDefSize.w += ww+mShadowSize;
mDefSize.h += mShadowSize;
end;
+ end
+ else
+ begin
+ ods := TLaySize.Create(0, 0); // fpc is dumb!
end;
inherited layPrepare();
if (not mSkipLayPrepare) then mDefSize := ods;
implementation
+uses
+ fui_wadread;
+
-// ////////////////////////////////////////////////////////////////////////// //
-const
- defaultStyleStr =
- 'default {'#10+
- ' back-color: #008;'#10+
- ' #active: { text-color: #fff; hot-color: #f00; switch-color: #fff; frame-color: #fff; frame-text-color: #fff; frame-icon-color: #0f0; }'#10+
- ' #inactive: { text-color: #aaa; hot-color: #a00; switch-color: #aaa; frame-color: #aaa; frame-text-color: #aaa; frame-icon-color: #0a0; }'#10+
- ' #disabled: { text-color: #666; hot-color: #600; switch-color: #666; frame-color: #888; frame-text-color: #888; frame-icon-color: #080; }'#10+
- ' @window: { #inactive(#active): { darken: 128; } }'#10+
- ' @button: { back-color: #999; text-color: #000; hot-color: #600; #active: { back-color: #fff; hot-color: #c00; } #disabled: { back-color: #444; text-color: #333; hot-color: #333; } }'#10+
- ' @label: { #inactive(#active); }'#10+
- ' @static: { text-color: #ff0; #inactive(#active); }'#10+
- ' @box: { #inactive(#active); }'#10+
- ' @switchbox: { #active: { back-color: #080; } #inactive: { switch-color: #fff; } }'#10+
- ' @checkbox(@switchbox): {}'#10+
- ' @radiobox(@switchbox): {}'#10+
- '}'#10+
- '';
var
styles: array of TUIStyle = nil;
+{
function createDefaultStyle (): TUIStyle;
var
st: TStream;
FreeAndNil(st);
end;
end;
+}
function uiFindStyle (const stname: AnsiString): TUIStyle;
for stl in styles do if (strEquCI1251(stl.mId, stname)) then begin result := stl; exit; end;
end;
for stl in styles do if (strEquCI1251(stl.mId, 'default')) then begin result := stl; exit; end;
+ raise Exception.Create('FlexUI FATAL: no "default" style in stylesheet');
+ {
stl := createDefaultStyle();
SetLength(styles, Length(styles)+1);
styles[High(styles)] := stl;
result := stl;
+ }
end;
var
st: TStream;
begin
- st := openDiskFileRO(fname);
+ st := fuiOpenFile(fname);
+ if (st = nil) then raise Exception.Create('FlexUI file '''+fname+''' not found!');
try
uiLoadStyles(st);
finally
end;
// we should have "default" style
for f := 0 to High(styles) do if (strEquCI1251(styles[f].mId, 'default')) then exit;
+ raise Exception.Create('FlexUI FATAL: no "default" style in stylesheet');
+ {
stl := createDefaultStyle();
SetLength(styles, Length(styles)+1);
styles[High(styles)] := stl;
+ }
end;
--- /dev/null
+(* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
+ * Understanding is not required. Only obedience.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
+{.$DEFINE FUI_WADREAD_DEBUG}
+unit fui_wadread;
+
+interface
+
+uses
+ SysUtils, Classes;
+
+
+function fuiAddWad (const wadfile: AnsiString): Boolean;
+
+// returns `nil` if file wasn't found
+function fuiOpenFile (const fname: AnsiString): TStream;
+
+
+var
+ fuiDiskFirst: Boolean = true;
+
+
+implementation
+
+uses
+ sfs, utils;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+type
+ TFUIWad = class
+ public
+ wadname: AnsiString;
+ iter: TSFSFileList;
+
+ public
+ constructor Create (const awadname: AnsiString);
+ destructor Destroy (); override;
+
+ // returns `nil` if file wasn't found
+ function openFile (const fname: AnsiString): TStream;
+ end;
+
+
+constructor TFUIWad.Create (const awadname: AnsiString);
+{$IFDEF FUI_WADREAD_DEBUG}
+var
+ f: Integer;
+{$ENDIF}
+begin
+ if not SFSAddDataFile(awadname, true) then raise Exception.Create('cannot open wad');
+ wadname := awadname;
+ iter := SFSFileList(awadname);
+ {$IFDEF FUI_WADREAD_DEBUG}
+ if (iter <> nil) then
+ begin
+ writeln('==== ', awadname, ' ====');
+ for f := 0 to iter.Count-1 do
+ begin
+ if (iter.Files[f] = nil) then continue;
+ writeln(' ', f, ': ', iter.Files[f].path, iter.Files[f].name);
+ end;
+ writeln('========');
+ end;
+ {$ENDIF}
+end;
+
+
+destructor TFUIWad.Destroy ();
+begin
+ wadname := '';
+ FreeAndNil(iter);
+ inherited;
+end;
+
+
+function TFUIWad.openFile (const fname: AnsiString): TStream;
+var
+ f: Integer;
+ fi: TSFSFileInfo;
+begin
+ result := nil;
+ if (iter = nil) then exit;
+ // backwards, due to possible similar names and such
+ for f := iter.Count-1 downto 0 do
+ begin
+ fi := iter.Files[f];
+ if (fi = nil) then continue;
+ if (StrEquCI1251(fi.path+fi.name, fname)) then
+ begin
+ try
+ result := iter.volume.OpenFileByIndex(f);
+ except
+ result := nil;
+ end;
+ if (result <> nil) then exit;
+ end;
+ end;
+end;
+
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function getExeDataPath (): AnsiString;
+begin
+ result := getFilenamePath(ParamStr(0))+'data/';
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+var
+ wadlist: array of TFUIWad = nil;
+
+
+function fuiAddWad (const wadfile: AnsiString): Boolean;
+var
+ exepath: AnsiString;
+ awadname: AnsiString;
+ f, c: Integer;
+ wad: TFUIWad;
+begin
+ result := false;
+
+ // find disk file
+ if (Length(wadfile) = 0) then exit;
+
+ if (Length(wadfile) > 2) and (wadfile[1] = '.') and ((wadfile[2] = '/') or (wadfile[2] = '\')) then
+ begin
+ awadname := wadfile;
+ awadname := findDiskWad(awadname);
+ if (Length(awadname) = 0) then
+ begin
+ writeln('WARNING: FlexUI WAD ''', wadfile, ''' not found');
+ exit;
+ end;
+ end
+ else
+ begin
+ exepath := getExeDataPath();
+ awadname := exepath+wadfile;
+ awadname := findDiskWad(awadname);
+ if (Length(awadname) = 0) then
+ begin
+ awadname := wadfile;
+ awadname := findDiskWad(awadname);
+ if (Length(awadname) = 0) then
+ begin
+ writeln('WARNING: FlexUI WAD ''', exepath+wadfile, ''' not found');
+ exit;
+ end;
+ end;
+ end;
+
+ // check if we already have this file opened
+ for f := 0 to High(wadlist) do
+ begin
+ wad := wadlist[f];
+ if (strEquCI1251(awadname, wad.wadname)) then
+ begin
+ // i found her! move it to the bottom of the list, so it will be checked first
+ for c := f+1 to High(wadlist) do wadlist[c-1] := wadlist[c];
+ wadlist[High(wadlist)] := wad;
+ exit;
+ end;
+ end;
+
+ // create new wad file
+ try
+ wad := TFUIWad.Create(awadname);
+ except // sorry
+ writeln('WARNING: error opening FlexUI WAD ''', wadfile, '''');
+ exit;
+ end;
+
+ SetLength(wadlist, Length(wadlist)+1);
+ wadlist[High(wadlist)] := wad;
+ {$IFDEF FUI_WADREAD_DEBUG}writeln('FUI: added WAD: ''', wad.wadname, '''');{$ENDIF}
+
+ result := true;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+// returns `nil` if file wasn't found
+function tryDiskFile (const fname: AnsiString): TStream;
+var
+ fn: AnsiString;
+begin
+ fn := getExeDataPath()+fname;
+ try
+ result := openDiskFileRO(fn);
+ {$IFDEF FUI_WADREAD_DEBUG}writeln('FUI: opened DISK file: ''', fn, '''');{$ENDIF}
+ except
+ result := nil;
+ end;
+end;
+
+
+// returns `nil` if file wasn't found
+function fuiOpenFile (const fname: AnsiString): TStream;
+var
+ f: Integer;
+begin
+ // disk
+ if (fuiDiskFirst) then
+ begin
+ result := tryDiskFile(fname);
+ if (result <> nil) then exit;
+ end;
+ // wads
+ for f := High(wadlist) downto 0 do
+ begin
+ result := wadlist[f].openFile(fname);
+ if (result <> nil) then
+ begin
+ {$IFDEF FUI_WADREAD_DEBUG}writeln('FUI: opened WAD file: ''', fname, ''' (from ''', wadlist[f].wadname, ''')');{$ENDIF}
+ exit;
+ end;
+ end;
+ // disk
+ if (not fuiDiskFirst) then
+ begin
+ result := tryDiskFile(fname);
+ if (result <> nil) then exit;
+ end;
+ {$IFDEF FUI_WADREAD_DEBUG}writeln('FUI: file: ''', fname, ''' NOT FOUND!');{$ENDIF}
+ result := nil;
+end;
+
+
+end.
sdlcarcass in '../flexui/sdlcarcass.pas',
//sdlstandalone in '../flexui/sdlstandalone.pas',
+ fui_wadread in '../flexui/fui_wadread.pas',
fui_common in '../flexui/fui_common.pas',
fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
fui_events in '../flexui/fui_events.pas',
var
+ g_holmes_imfunctional: Boolean = false;
g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
begin
if g_Game_IsNet then exit;
if not g_holmes_enabled then exit;
+ if g_holmes_imfunctional then exit;
holmesInitCommands();
holmesInitBinds();
begin
if g_Game_IsNet then exit;
if not g_holmes_enabled then exit;
+ if g_holmes_imfunctional then exit;
holmesInitCommands();
holmesInitBinds();
begin
if g_Game_IsNet then exit;
if not g_holmes_enabled then exit;
+ if g_holmes_imfunctional then exit;
{$IF not DEFINED(HEADLESS)}
gGfxDoClear := false;
//if assigned(prerenderFrameCB) then prerenderFrameCB();
procedure onMouseEvent (var ev: THMouseEvent);
begin
if not g_holmes_enabled then exit;
+ if g_holmes_imfunctional then exit;
g_Holmes_MouseEvent(ev);
end;
procedure onKeyEvent (var ev: THKeyEvent);
begin
if not g_holmes_enabled then exit;
+ if g_holmes_imfunctional then exit;
g_Holmes_KeyEvent(ev);
end;
e_graphics, e_input, g_game, g_console, g_gui,
e_sound, g_options, g_sound, g_player,
g_weapons, SysUtils, g_triggers, MAPDEF, g_map,
- g_menu, g_language, g_net,
- utils, conbuf, envvars;
+ g_menu, g_language, g_net, g_holmes,
+ utils, conbuf, envvars, fui_wadread, fui_style,
+ xparser;
var
SDL_StartTextInput();
{$ENDIF}
+{$IFNDEF HEADLESS}
+ if not fuiAddWad('flexui.wad') then
+ begin
+ if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
+ end;
+ g_holmes_imfunctional := true;
+ try
+ e_LogWriteln('FlexUI: loading stylesheet...');
+ uiLoadStyles('flexui/widgets.wgs');
+ g_holmes_imfunctional := false;
+ except on e: TParserException do
+ begin
+ writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
+ //raise;
+ end;
+ else
+ begin
+ //raise;
+ end;
+ end;
+{$ENDIF}
+
e_WriteLog('Entering SDLMain', TMsgType.Notify);
{$WARNINGS OFF}
SDLMain();
{$WARNINGS ON}
-{$IFDEF HEADLESS}
+{$IFNDEF HEADLESS}
SDL_StopTextInput();
{$ENDIF}
result :=
StrEquCI1251(prefix, 'zip') or
StrEquCI1251(prefix, 'pk3') or
- StrEquCI1251(prefix, 'dfwad');
+ StrEquCI1251(prefix, 'dfwad') or
+ StrEquCI1251(prefix, 'dfzip');
end;
procedure TSFSZipVolumeFactory.Recycle (vol: TSFSVolume);
// nobody cares about shitdoze, so i'll use the same code path for it
function findFileCI (var pathname: AnsiString; lastIsDir: Boolean=false): Boolean;
+// return fixed AnsiString or empty AnsiString
+function findDiskWad (fname: AnsiString): AnsiString;
+
// they throws
function openDiskFileRO (pathname: AnsiString): TStream;
function createDiskFile (pathname: AnsiString): TStream;
end;
+const fileExtensions: array [0..5] of AnsiString = ('.wad', '.dfzip', '.dfwad', '.pk3', '.pak', '.zip');
+
+function findDiskWad (fname: AnsiString): AnsiString;
+var
+ origExt: AnsiString = '';
+ newExt: AnsiString = '';
+begin
+ result := '';
+ //writeln('findDiskWad00: fname=<', fname, '>');
+ if (findFileCI(fname)) then begin result := fname; exit; end;
+ origExt := getFilenameExt(fname);
+ fname := forceFilenameExt(fname, '');
+ //writeln(' findDiskWad01: fname=<', fname, '>; origExt=<', origExt, '>');
+ for newExt in fileExtensions do
+ begin
+ //writeln(' findDiskWad02: fname=<', fname, '>; origExt=<', origExt, '>; newExt=<', newExt, '>');
+ if (StrEquCI1251(newExt, origExt)) then
+ begin
+ //writeln(' SKIP');
+ continue;
+ end;
+ result := fname+newExt;
+ if (findFileCI(result)) then exit;
+ end;
+ result := '';
+end;
+
+
function openDiskFileRO (pathname: AnsiString): TStream;
begin
if not findFileCI(pathname) then raise Exception.Create('can''t open file "'+pathname+'"');
function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path
function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString;
-// return fixed AnsiString or empty AnsiString
-function findDiskWad (fname: AnsiString): AnsiString;
-
var
wadoptDebug: Boolean = false;
SysUtils, e_log, MAPDEF, xdynrec;
-function findDiskWad (fname: AnsiString): AnsiString;
-begin
- result := '';
- if not findFileCI(fname) then
- begin
- //e_WriteLog(Format('findDiskWad: error looking for [%s]', [fname]), MSG_NOTIFY);
- if StrEquCI1251(ExtractFileExt(fname), '.wad') then
- begin
- fname := ChangeFileExt(fname, '.pk3');
- //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
- if not findFileCI(fname) then
- begin
- fname := ChangeFileExt(fname, '.zip');
- //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
- if not findFileCI(fname) then exit;
- end;
- end
- else
- begin
- exit;
- end;
- end;
- //e_WriteLog(Format('findDiskWad: FOUND [%s]', [fname]), MSG_NOTIFY);
- result := fname;
-end;
-
-
function normSlashes (s: AnsiString): AnsiString;
var
f: Integer;