X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_gui.pas;h=79b46ad6692ab1f3ae0c262b85a8e04a9d574545;hb=d7d166dc3cd287276202e862746208892c4cc89f;hp=d7735ab374d568a4e51cf47c543f1a2c458d7522;hpb=923fa980434e55419f35422119af2faae2bf68d7;p=d2df-sdl.git diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index d7735ab..79b46ad 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -19,6 +19,7 @@ unit g_gui; interface uses + mempool, e_graphics, e_input, e_log, g_playermodel, g_basic, MAPDEF, wadreader; const @@ -82,9 +83,9 @@ type lParam: LongInt; end; - TFontType = (FONT_TEXTURE, FONT_CHAR); + TFontType = (Texture, Character); - TFont = class(TObject) + TFont = class(TPoolObject) private ID: DWORD; FScale: Single; @@ -108,7 +109,7 @@ type TOnChangeEvent = procedure(Sender: TGUIControl); TOnEnterEvent = procedure(Sender: TGUIControl); - TGUIControl = class + TGUIControl = class(TPoolObject) private FX, FY: Integer; FEnabled: Boolean; @@ -133,7 +134,7 @@ type property RightAlign: Boolean read FRightAlign write FRightAlign; // for menu end; - TGUIWindow = class + TGUIWindow = class(TPoolObject) private FActiveControl: TGUIControl; FDefControl: string; @@ -267,6 +268,7 @@ type FMiddleID: DWORD; FOnChangeEvent: TOnChangeEvent; FOnEnterEvent: TOnEnterEvent; + FInvalid: Boolean; procedure SetText(Text: string); public constructor Create(FontID: DWORD); @@ -282,6 +284,7 @@ type property Text: string read FText write SetText; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + property Invalid: Boolean read FInvalid write FInvalid; end; TGUIKeyRead = class(TGUIControl) @@ -416,7 +419,7 @@ type property Font: TFont read FFont write FFont; end; - TGUIFileListBox = class (TGUIListBox) + TGUIFileListBox = class(TGUIListBox) private FBasePath: String; FPath: String; @@ -914,7 +917,7 @@ begin Self.Proc := aProc; ProcEx := nil; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FText := Text; end; @@ -983,7 +986,7 @@ end; procedure TFont.Draw(X, Y: Integer; Text: string; R, G, B: Byte); begin - if FFontType = FONT_CHAR then e_CharFont_PrintEx(ID, X, Y, Text, _RGB(R, G, B), FScale) + if FFontType = TFontType.Character then e_CharFont_PrintEx(ID, X, Y, Text, _RGB(R, G, B), FScale) else e_TextureFontPrintEx(X, Y, Text, ID, R, G, B, FScale); end; @@ -991,7 +994,7 @@ procedure TFont.GetTextSize(Text: string; var w, h: Word); var cw, ch: Byte; begin - if FFontType = FONT_CHAR then e_CharFont_GetSize(ID, Text, w, h) + if FFontType = TFontType.Character then e_CharFont_GetSize(ID, Text, w, h) else begin e_TextureFontGetSize(ID, cw, ch); @@ -1214,7 +1217,7 @@ constructor TGUILabel.Create(Text: string; FontID: DWORD); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FText := Text; FFixedLen := 0; @@ -2134,7 +2137,7 @@ begin FIndex := -1; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); end; procedure TGUISwitch.Draw; @@ -2214,10 +2217,11 @@ constructor TGUIEdit.Create(FontID: DWORD); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FMaxLength := 0; FWidth := 0; + FInvalid := false; g_Texture_Get(EDIT_LEFT, FLeftID); g_Texture_Get(EDIT_RIGHT, FRightID); @@ -2227,6 +2231,7 @@ end; procedure TGUIEdit.Draw; var c, w, h: Word; + r, g, b: Byte; begin inherited; @@ -2236,9 +2241,13 @@ begin for c := 0 to FWidth-1 do e_Draw(FMiddleID, FX+8+c*16, FY, 0, True, False); - FFont.Draw(FX+8, FY, FText, FColor.R, FColor.G, FColor.B); + r := FColor.R; + g := FColor.G; + b := FColor.B; + if FInvalid and (FWindow.FActiveControl <> self) then begin r := 128; g := 128; b := 128; end; + FFont.Draw(FX+8, FY, FText, r, g, b); - if FWindow.FActiveControl = Self then + if (FWindow.FActiveControl = self) then begin FFont.GetTextSize(Copy(FText, 1, FCaretPos), w, h); h := e_CharFont_GetMaxHeight(FFont.ID); @@ -2330,7 +2339,7 @@ begin FKey := 0; FIsQuery := false; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); end; procedure TGUIKeyRead.Draw; @@ -2453,7 +2462,7 @@ begin FIsQuery := False; FFontID := FontID; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FMaxKeyNameWdt := 0; for a := 0 to 255 do @@ -2810,61 +2819,68 @@ begin try map := g_Map_ParseMap(Data, Len); except + FreeMem(Data); map.Free(); - raise; + //raise; + exit; end; FreeMem(Data); - panlist := map.field['panel']; - //header := GetMapHeader(map); + if (map = nil) then exit; - FMapSize.X := map.Width div 16; - FMapSize.Y := map.Height div 16; + try + panlist := map.field['panel']; + //header := GetMapHeader(map); - rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0)); - rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0)); - FScale := max(rX, rY); + FMapSize.X := map.Width div 16; + FMapSize.Y := map.Height div 16; - FMapData := nil; + rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0)); + rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0)); + FScale := max(rX, rY); - if (panlist <> nil) then - begin - for pan in panlist do + FMapData := nil; + + if (panlist <> nil) then begin - if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or - PANEL_STEP or PANEL_WATER or - PANEL_ACID1 or PANEL_ACID2)) <> 0 then + for pan in panlist do begin - SetLength(FMapData, Length(FMapData)+1); - with FMapData[High(FMapData)] do + if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or + PANEL_STEP or PANEL_WATER or + PANEL_ACID1 or PANEL_ACID2)) <> 0 then begin - X1 := pan.X div 16; - Y1 := pan.Y div 16; + SetLength(FMapData, Length(FMapData)+1); + with FMapData[High(FMapData)] do + begin + X1 := pan.X div 16; + Y1 := pan.Y div 16; - X2 := (pan.X + pan.Width) div 16; - Y2 := (pan.Y + pan.Height) div 16; + X2 := (pan.X + pan.Width) div 16; + Y2 := (pan.Y + pan.Height) div 16; - X1 := Trunc(X1/FScale + 0.5); - Y1 := Trunc(Y1/FScale + 0.5); - X2 := Trunc(X2/FScale + 0.5); - Y2 := Trunc(Y2/FScale + 0.5); + X1 := Trunc(X1/FScale + 0.5); + Y1 := Trunc(Y1/FScale + 0.5); + X2 := Trunc(X2/FScale + 0.5); + Y2 := Trunc(Y2/FScale + 0.5); - if (X1 <> X2) or (Y1 <> Y2) then - begin - if X1 = X2 then - X2 := X2 + 1; - if Y1 = Y2 then - Y2 := Y2 + 1; - end; + if (X1 <> X2) or (Y1 <> Y2) then + begin + if X1 = X2 then + X2 := X2 + 1; + if Y1 = Y2 then + Y2 := Y2 + 1; + end; - PanelType := pan.PanelType; + PanelType := pan.PanelType; + end; end; end; end; + finally + //writeln('freeing map'); + map.Free(); end; - - map.Free(); end; procedure TGUIMapPreview.ClearMap(); @@ -2919,7 +2935,7 @@ constructor TGUIListBox.Create(FontID: DWORD; Width, Height: Word); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FWidth := Width; FHeight := Height; @@ -3306,7 +3322,7 @@ constructor TGUIMemo.Create(FontID: DWORD; Width, Height: Word); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FWidth := Width; FHeight := Height;