clang-format AngleScript source files

Unsurprisingly it doesn't support AngelScript, so the Java language mode
is used instead. The overall result seems good, but there's one problem:
Long statements starting with `@something = ` (object handle assignment)
are broken after the `@`. To work-around this, I had to set
`ColumnLimit` to `100`.
master
yvt 2019-07-13 23:40:42 +09:00
parent cb89824f32
commit c37a013157
64 changed files with 7364 additions and 6958 deletions

View File

@ -18,3 +18,15 @@ PointerAlignment: Right
AllowShortFunctionsOnASingleLine: Inline
AllowShortCaseLabelsOnASingleLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
---
# The style for AngelScript source files
Language: Java
UseTab: Never
ColumnLimit: 100
NamespaceIndentation: All
IndentCaseLabels: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortCaseLabelsOnASingleLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true

View File

@ -19,4 +19,3 @@
*/
#include "Utils.as"

View File

@ -21,48 +21,30 @@
namespace spades {
// AngelScript doesn't seem to support user-defined template functions...
uint Min(uint a, uint b) {
return (a < b) ? a : b;
}
uint Min(uint a, uint b) { return (a < b) ? a : b; }
uint Max(uint a, uint b) {
return (a > b) ? a : b;
}
uint Max(uint a, uint b) { return (a > b) ? a : b; }
int Min(int a, int b) {
return (a < b) ? a : b;
}
int Min(int a, int b) { return (a < b) ? a : b; }
int Max(int a, int b) {
return (a > b) ? a : b;
}
int Max(int a, int b) { return (a > b) ? a : b; }
float Min(float a, float b) {
return (a < b) ? a : b;
}
float Min(float a, float b) { return (a < b) ? a : b; }
float Max(float a, float b) {
return (a > b) ? a : b;
}
float Max(float a, float b) { return (a > b) ? a : b; }
float Clamp(float val, float lower, float upper) {
return Min(Max(val, lower), upper);
}
float Clamp(float val, float lower, float upper) { return Min(Max(val, lower), upper); }
int Clamp(int val, int lower, int upper) {
return Min(Max(val, lower), upper);
}
int Clamp(int val, int lower, int upper) { return Min(Max(val, lower), upper); }
uint Clamp(uint val, uint lower, uint upper) {
return Min(Max(val, lower), upper);
}
uint Clamp(uint val, uint lower, uint upper) { return Min(Max(val, lower), upper); }
/** Renders an image in the way CSS border-image does. */
void DrawSliceImage(Renderer@ renderer, Image@ image, float x, float y, float w, float h, float border) {
void DrawSliceImage(Renderer @renderer, Image @image, float x, float y, float w, float h,
float border) {
float iw = image.Width;
float ih = image.Height;
renderer.DrawImage(image, AABB2(x, y, border, border),
AABB2(0.f, 0.f, border, border));
renderer.DrawImage(image, AABB2(x, y, border, border), AABB2(0.f, 0.f, border, border));
renderer.DrawImage(image, AABB2(x + w - border, y, border, border),
AABB2(iw - border, 0.f, border, border));
renderer.DrawImage(image, AABB2(x, y + h - border, border, border),
@ -77,7 +59,8 @@ namespace spades {
AABB2(0.f, border, border, ih - border - border));
renderer.DrawImage(image, AABB2(x + w - border, y + border, border, h - border - border),
AABB2(iw - border, border, border, ih - border - border));
renderer.DrawImage(image, AABB2(x + border, y + border, w - border - border, h - border - border),
renderer.DrawImage(image,
AABB2(x + border, y + border, w - border - border, h - border - border),
AABB2(border, border, iw - border - border, ih - border - border));
}
@ -111,7 +94,8 @@ namespace spades {
}
}
if(start > len) start = len;
if (start > len)
start = len;
return start;
}

View File

@ -75,20 +75,16 @@ namespace spades {
{
spades::ui::Button button(Manager);
button.Caption = _Tr("Client", "Close");
button.Bounds = AABB2(
contentsLeft + contentsWidth - 150.f,
contentsTop + contentsHeight - 30.f
, 150.f, 30.f);
button.Bounds = AABB2(contentsLeft + contentsWidth - 150.f,
contentsTop + contentsHeight - 30.f, 150.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.OnOkPressed);
AddChild(button);
}
{
spades::ui::Button button(Manager);
button.Caption = _Tr("Client", "Say Global");
button.Bounds = AABB2(
contentsLeft,
contentsTop + contentsHeight - 30.f
, 150.f, 30.f);
button.Bounds =
AABB2(contentsLeft, contentsTop + contentsHeight - 30.f, 150.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.OnGlobalChat);
AddChild(button);
@this.sayButton1 = button;
@ -96,10 +92,8 @@ namespace spades {
{
spades::ui::Button button(Manager);
button.Caption = _Tr("Client", "Say Team");
button.Bounds = AABB2(
contentsLeft + 155.f,
contentsTop + contentsHeight - 30.f
, 150.f, 30.f);
button.Bounds =
AABB2(contentsLeft + 155.f, contentsTop + contentsHeight - 30.f, 150.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.OnTeamChat);
AddChild(button);
@this.sayButton2 = button;
@ -107,7 +101,8 @@ namespace spades {
{
spades::ui::TextViewer viewer(Manager);
AddChild(viewer);
viewer.Bounds = AABB2(contentsLeft, contentsTop, contentsWidth, contentsHeight - 40.f);
viewer.Bounds =
AABB2(contentsLeft, contentsTop, contentsWidth, contentsHeight - 40.f);
@this.viewer = viewer;
}
}
@ -117,9 +112,7 @@ namespace spades {
viewer.ScrollToEnd();
}
void Close() {
@ui.ActiveUI = null;
}
void Close() { @ui.ActiveUI = null; }
void SayWindowClosed() {
@sayWindow = null;
@ -127,9 +120,7 @@ namespace spades {
sayButton2.Enable = true;
}
private void OnOkPressed(spades::ui::UIElement@ sender) {
Close();
}
private void OnOkPressed(spades::ui::UIElement @sender) { Close(); }
private void OnTeamChat(spades::ui::UIElement @sender) {
if (sayWindow !is null) {
@ -175,9 +166,7 @@ namespace spades {
}
}
void Record(string text, Vector4 color) {
viewer.AddLine(text, this.IsVisible, color);
}
void Record(string text, Vector4 color) { viewer.AddLine(text, this.IsVisible, color); }
void Render() {
Vector2 pos = ScreenPosition;
@ -186,19 +175,16 @@ namespace spades {
Image @img = r.RegisterImage("Gfx/White.tga");
r.ColorNP = Vector4(1, 1, 1, 0.08f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 15.f, size.x, 1.f));
r.ColorNP = Vector4(1, 1, 1, 0.2f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 14.f, size.x, 1.f));
UIElement::Render();
}
}
}

View File

@ -23,7 +23,8 @@ namespace spades {
uint StringCommonPrefixLength(string a, string b) {
for (uint i = 0, ln = Min(a.length, b.length); i < ln; i++) {
if(ToLower(a[i]) != ToLower(b[i])) return i;
if (ToLower(a[i]) != ToLower(b[i]))
return i;
}
return Min(a.length, b.length);
}
@ -54,28 +55,25 @@ namespace spades {
pos.y -= float(configNames.length) * rowHeight + 10.f;
renderer.ColorNP = Vector4(0.f, 0.f, 0.f, 0.5f);
renderer.DrawImage(null,
AABB2(pos.x, pos.y, maxNameLen + maxValueLen + 20.f,
renderer.DrawImage(null, AABB2(pos.x, pos.y, maxNameLen + maxValueLen + 20.f,
float(configNames.length) * rowHeight + 10.f));
for (uint i = 0, len = configNames.length; i < len; i++) {
font.DrawShadow(configNames[i],
pos + Vector2(5.f, 8.f + float(i) * rowHeight),
1.f, Vector4(1,1,1,0.7), Vector4(0,0,0,0.3f));
font.DrawShadow(configNames[i], pos + Vector2(5.f, 8.f + float(i) * rowHeight), 1.f,
Vector4(1, 1, 1, 0.7), Vector4(0, 0, 0, 0.3f));
font.DrawShadow(configValues[i],
pos + Vector2(15.f + maxNameLen, 8.f + float(i) * rowHeight),
1.f, Vector4(1,1,1,1), Vector4(0,0,0,0.4f));
pos + Vector2(15.f + maxNameLen, 8.f + float(i) * rowHeight), 1.f,
Vector4(1, 1, 1, 1), Vector4(0, 0, 0, 0.4f));
}
}
}
class CommandField : FieldWithHistory {
CommandFieldConfigValueView @valueView;
CommandField(spades::ui::UIManager@ manager, array<spades::ui::CommandHistoryItem@>@ history) {
CommandField(spades::ui::UIManager @manager,
array<spades::ui::CommandHistoryItem @> @history) {
super(manager, history);
}
void OnChanged() {
@ -84,8 +82,7 @@ namespace spades {
if (valueView !is null) {
@valueView.Parent = null;
}
if(Text.substr(0, 1) == "/" &&
Text.substr(1, 1) != " ") {
if (Text.substr(0, 1) == "/" && Text.substr(1, 1) != " ") {
int whitespace = Text.findFirst(" ");
if (whitespace < 0) {
whitespace = int(Text.length);
@ -96,10 +93,8 @@ namespace spades {
string[] @names = GetAllConfigNames();
string[] filteredNames;
for (uint i = 0, len = names.length; i < len; i++) {
if (
StringCommonPrefixLength(input, names[i]) == input.length &&
!ConfigItem(names[i]).IsUnknown
) {
if (StringCommonPrefixLength(input, names[i]) == input.length &&
!ConfigItem(names[i]).IsUnknown) {
filteredNames.insertLast(names[i]);
if (filteredNames.length >= 8) {
// too many
@ -118,20 +113,16 @@ namespace spades {
void KeyDown(string key) {
if (key == "Tab") {
if(SelectionLength == 0 &&
SelectionStart == int(Text.length) &&
Text.substr(0, 1) == "/" &&
Text.findFirst(" ") < 0) {
if (SelectionLength == 0 && SelectionStart == int(Text.length) &&
Text.substr(0, 1) == "/" && Text.findFirst(" ") < 0) {
// config variable auto completion
string input = Text.substr(1);
string[] @names = GetAllConfigNames();
string commonPart;
bool foundOne = false;
for (uint i = 0, len = names.length; i < len; i++) {
if (
StringCommonPrefixLength(input, names[i]) == input.length &&
!ConfigItem(names[i]).IsUnknown
) {
if (StringCommonPrefixLength(input, names[i]) == input.length &&
!ConfigItem(names[i]).IsUnknown) {
if (!foundOne) {
commonPart = names[i];
foundOne = true;
@ -146,7 +137,6 @@ namespace spades {
Text = "/" + commonPart;
Select(Text.length, 0);
}
}
} else {
FieldWithHistory::KeyDown(key);
@ -230,14 +220,13 @@ namespace spades {
}
}
void UpdateState() {
sayButton.Enable = field.Text.length > 0;
}
void UpdateState() { sayButton.Enable = field.Text.length > 0; }
bool IsTeamChat {
get final { return isTeamChat; }
set {
if(isTeamChat == value) return;
if (isTeamChat == value)
return;
isTeamChat = value;
teamButton.Toggled = isTeamChat;
globalButton.Toggled = not isTeamChat;
@ -245,20 +234,12 @@ namespace spades {
}
}
private void OnSetGlobal(spades::ui::UIElement@ sender) {
IsTeamChat = false;
}
private void OnSetTeam(spades::ui::UIElement@ sender) {
IsTeamChat = true;
}
private void OnSetGlobal(spades::ui::UIElement @sender) { IsTeamChat = false; }
private void OnSetTeam(spades::ui::UIElement @sender) { IsTeamChat = true; }
private void OnFieldChanged(spades::ui::UIElement@ sender) {
UpdateState();
}
private void OnFieldChanged(spades::ui::UIElement @sender) { UpdateState(); }
private void Close() {
@ui.ActiveUI = null;
}
private void Close() { @ui.ActiveUI = null; }
private void OnCancel(spades::ui::UIElement @sender) {
field.Cancelled();
@ -267,9 +248,11 @@ namespace spades {
private bool CheckAndSetConfigVariable() {
string text = field.Text;
if(text.substr(0, 1) != "/") return false;
if (text.substr(0, 1) != "/")
return false;
int idx = text.findFirst(" ");
if(idx < 2) return false;
if (idx < 2)
return false;
// find variable
string varname = text.substr(1, idx - 1);

View File

@ -42,7 +42,8 @@ namespace spades {
private float time = -1.f;
ClientUI(Renderer@ renderer, AudioDevice@ audioDevice, FontManager@ fontManager, ClientUIHelper@ helper) {
ClientUI(Renderer @renderer, AudioDevice @audioDevice, FontManager @fontManager,
ClientUIHelper @helper) {
@this.renderer = renderer;
@this.audioDevice = audioDevice;
@this.fontManager = fontManager;
@ -57,33 +58,21 @@ namespace spades {
@chatLogWindow = ChatLogWindow(this);
}
void MouseEvent(float x, float y) {
manager.MouseEvent(x, y);
}
void MouseEvent(float x, float y) { manager.MouseEvent(x, y); }
void WheelEvent(float x, float y) {
manager.WheelEvent(x, y);
}
void WheelEvent(float x, float y) { manager.WheelEvent(x, y); }
void KeyEvent(string key, bool down) {
manager.KeyEvent(key, down);
}
void KeyEvent(string key, bool down) { manager.KeyEvent(key, down); }
void TextInputEvent(string text) {
manager.TextInputEvent(text);
}
void TextInputEvent(string text) { manager.TextInputEvent(text); }
void TextEditingEvent(string text, int start, int len) {
manager.TextEditingEvent(text, start, len);
}
bool AcceptsTextInput() {
return manager.AcceptsTextInput;
}
bool AcceptsTextInput() { return manager.AcceptsTextInput; }
AABB2 GetTextInputRect() {
return manager.TextInputRect;
}
AABB2 GetTextInputRect() { return manager.TextInputRect; }
void RunFrame(float dt) {
if (time < 0.f) {
@ -98,17 +87,11 @@ namespace spades {
time += Min(dt, 0.05f);
}
void Closing() {
void Closing() {}
}
bool WantsClientToBeClosed() { return shouldExit; }
bool WantsClientToBeClosed() {
return shouldExit;
}
bool NeedsInput() {
return activeUI !is null;
}
bool NeedsInput() { return activeUI !is null; }
void set_ActiveUI(spades::ui::UIElement @value) {
if (activeUI !is null) {
@ -121,13 +104,9 @@ namespace spades {
}
manager.KeyPanic();
}
spades::ui::UIElement@ get_ActiveUI(){
return activeUI;
}
spades::ui::UIElement @get_ActiveUI() { return activeUI; }
void EnterClientMenu() {
@ActiveUI = clientMenu;
}
void EnterClientMenu() { @ActiveUI = clientMenu; }
void EnterTeamChatWindow() {
ClientChatWindow wnd(this, true);
@ -147,17 +126,13 @@ namespace spades {
@ActiveUI = wnd;
@manager.ActiveElement = wnd.field;
}
void CloseUI() {
@ActiveUI = null;
void CloseUI() { @ActiveUI = null; }
void RecordChatLog(string text, Vector4 color) { chatLogWindow.Record(text, color); }
}
void RecordChatLog(string text, Vector4 color) {
chatLogWindow.Record(text, color);
}
}
ClientUI@ CreateClientUI(Renderer@ renderer, AudioDevice@ audioDevice,
FontManager@ fontManager, ClientUIHelper@ helper) {
ClientUI @CreateClientUI(Renderer @renderer, AudioDevice @audioDevice, FontManager @fontManager,
ClientUIHelper @helper) {
return ClientUI(renderer, audioDevice, fontManager, helper);
}

View File

@ -39,7 +39,8 @@ namespace spades {
CommandHistoryItem @temporalLastHistory;
uint currentHistoryIndex;
FieldWithHistory(spades::ui::UIManager@ manager, array<spades::ui::CommandHistoryItem@>@ history) {
FieldWithHistory(spades::ui::UIManager @manager,
array<spades::ui::CommandHistoryItem @> @history) {
super(manager);
@this.cmdhistory = history;
@ -48,9 +49,7 @@ namespace spades {
}
private CommandHistoryItem @CommandHistoryItemRep {
get {
return CommandHistoryItem(this.Text, this.SelectionStart, this.SelectionEnd);
}
get { return CommandHistoryItem(this.Text, this.SelectionStart, this.SelectionEnd); }
set {
this.Text = value.text;
this.Select(value.selStart, value.selEnd - value.selStart);
@ -96,9 +95,7 @@ namespace spades {
currentHistoryIndex = cmdhistory.length - 1;
}
void Cancelled() {
OverwriteItem();
}
void Cancelled() { OverwriteItem(); }
};
}

View File

@ -37,8 +37,8 @@ namespace spades {
{
spades::ui::Label label(Manager);
label.BackgroundColor = Vector4(0, 0, 0, 0.5f);
label.Bounds = AABB2(0.f, 0.f,
Manager.Renderer.ScreenWidth, Manager.Renderer.ScreenHeight);
label.Bounds =
AABB2(0.f, 0.f, Manager.Renderer.ScreenWidth, Manager.Renderer.ScreenHeight);
AddChild(label);
}
@ -78,9 +78,7 @@ namespace spades {
}
}
private void OnBackToGame(spades::ui::UIElement@ sender) {
@ui.ActiveUI = null;
}
private void OnBackToGame(spades::ui::UIElement @sender) { @ui.ActiveUI = null; }
private void OnSetup(spades::ui::UIElement @sender) {
PreferenceViewOptions opt;
opt.GameActive = true;
@ -92,9 +90,7 @@ namespace spades {
@ui.ActiveUI = @ui.chatLogWindow;
ui.chatLogWindow.ScrollToEnd();
}
private void OnDisconnect(spades::ui::UIElement@ sender) {
ui.shouldExit = true;
}
private void OnDisconnect(spades::ui::UIElement @sender) { ui.shouldExit = true; }
void HotKey(string key) {
if (IsEnabled and key == "Escape") {

File diff suppressed because it is too large Load Diff

View File

@ -56,10 +56,8 @@ namespace spades {
{
spades::ui::Button button(Manager);
button.Caption = _Tr("CreateProfileScreen", "OK");
button.Bounds = AABB2(
contentsLeft + contentsWidth - 140.f,
contentsTop + contentsHeight - 40.f
, 140.f, 30.f);
button.Bounds = AABB2(contentsLeft + contentsWidth - 140.f,
contentsTop + contentsHeight - 40.f, 140.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.OnOkPressed);
button.Enable = false;
AddChild(button);
@ -68,10 +66,8 @@ namespace spades {
{
spades::ui::Button button(Manager);
button.Caption = _Tr("CreateProfileScreen", "Decide later");
button.Bounds = AABB2(
contentsLeft,
contentsTop + contentsHeight - 40.f
, 140.f, 30.f);
button.Bounds =
AABB2(contentsLeft, contentsTop + contentsHeight - 40.f, 140.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.OnChooseLater);
AddChild(button);
}
@ -101,7 +97,8 @@ namespace spades {
}
{
spades::ui::Label label(Manager);
label.Text = _Tr("CreateProfileScreen", "You can change it later in the Setup dialog.");
label.Text =
_Tr("CreateProfileScreen", "You can change it later in the Setup dialog.");
label.Bounds = AABB2(contentsLeft, contentsTop + 106.f, contentsWidth, 32.f);
label.Alignment = Vector2(0.f, 0.5f);
AddChild(label);
@ -135,9 +132,7 @@ namespace spades {
Close();
}
private void OnChooseLater(spades::ui::UIElement@ sender) {
Close();
}
private void OnChooseLater(spades::ui::UIElement @sender) { Close(); }
private void OnNameChanged(spades::ui::UIElement @sender) {
okButton.Enable = nameField.Text.length > 0;
@ -162,18 +157,15 @@ namespace spades {
Image @img = r.RegisterImage("Gfx/White.tga");
r.ColorNP = Vector4(1, 1, 1, 0.08f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 15.f, size.x, 1.f));
r.ColorNP = Vector4(1, 1, 1, 0.2f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 14.f, size.x, 1.f));
UIElement::Render();
}
}
}

View File

@ -24,9 +24,7 @@
namespace spades {
class RefreshButton : spades::ui::SimpleButton {
RefreshButton(spades::ui::UIManager@ manager){
super(manager);
}
RefreshButton(spades::ui::UIManager @manager) { super(manager); }
void Render() {
SimpleButton::Render();
@ -109,8 +107,8 @@ namespace spades {
}
{
@protocol3Button = ProtocolButton(Manager);
protocol3Button.Bounds = AABB2(contentsLeft + contentsWidth - 240.f + 6.f, 200,
40.f, 30.f);
protocol3Button.Bounds =
AABB2(contentsLeft + contentsWidth - 240.f + 6.f, 200, 40.f, 30.f);
protocol3Button.Caption = _Tr("MainScreen", "0.75");
@protocol3Button.Activated = spades::ui::EventHandler(this.OnProtocol3Pressed);
protocol3Button.Toggle = true;
@ -119,8 +117,8 @@ namespace spades {
}
{
@protocol4Button = ProtocolButton(Manager);
protocol4Button.Bounds = AABB2(contentsLeft + contentsWidth - 200.f + 6.f, 200,
40.f, 30.f);
protocol4Button.Bounds =
AABB2(contentsLeft + contentsWidth - 200.f + 6.f, 200, 40.f, 30.f);
protocol4Button.Caption = _Tr("MainScreen", "0.76");
@protocol4Button.Activated = spades::ui::EventHandler(this.OnProtocol4Pressed);
protocol4Button.Toggle = true;
@ -163,26 +161,25 @@ namespace spades {
}
{
@filterProtocol3Button = ProtocolButton(Manager);
filterProtocol3Button.Bounds = AABB2(contentsLeft + 50.f, footerPos,
40.f, 30.f);
filterProtocol3Button.Bounds = AABB2(contentsLeft + 50.f, footerPos, 40.f, 30.f);
filterProtocol3Button.Caption = _Tr("MainScreen", "0.75");
@filterProtocol3Button.Activated = spades::ui::EventHandler(this.OnFilterProtocol3Pressed);
@filterProtocol3Button.Activated
= spades::ui::EventHandler(this.OnFilterProtocol3Pressed);
filterProtocol3Button.Toggle = true;
AddChild(filterProtocol3Button);
}
{
@filterProtocol4Button = ProtocolButton(Manager);
filterProtocol4Button.Bounds = AABB2(contentsLeft + 90.f, footerPos,
40.f, 30.f);
filterProtocol4Button.Bounds = AABB2(contentsLeft + 90.f, footerPos, 40.f, 30.f);
filterProtocol4Button.Caption = _Tr("MainScreen", "0.76");
@filterProtocol4Button.Activated = spades::ui::EventHandler(this.OnFilterProtocol4Pressed);
@filterProtocol4Button.Activated
= spades::ui::EventHandler(this.OnFilterProtocol4Pressed);
filterProtocol4Button.Toggle = true;
AddChild(filterProtocol4Button);
}
{
@filterEmptyButton = ProtocolButton(Manager);
filterEmptyButton.Bounds = AABB2(contentsLeft + 135.f, footerPos,
50.f, 30.f);
filterEmptyButton.Bounds = AABB2(contentsLeft + 135.f, footerPos, 50.f, 30.f);
filterEmptyButton.Caption = _Tr("MainScreen", "Empty");
@filterEmptyButton.Activated = spades::ui::EventHandler(this.OnFilterEmptyPressed);
filterEmptyButton.Toggle = true;
@ -190,8 +187,7 @@ namespace spades {
}
{
@filterFullButton = ProtocolButton(Manager);
filterFullButton.Bounds = AABB2(contentsLeft + 185.f, footerPos,
70.f, 30.f);
filterFullButton.Bounds = AABB2(contentsLeft + 185.f, footerPos, 70.f, 30.f);
filterFullButton.Caption = _Tr("MainScreen", "Not Full");
@filterFullButton.Activated = spades::ui::EventHandler(this.OnFilterFullPressed);
filterFullButton.Toggle = true;
@ -301,27 +297,15 @@ namespace spades {
UpdateServerList();
}
private void SortServerListByPing(spades::ui::UIElement@ sender) {
SortServerList(0);
}
private void SortServerListByPing(spades::ui::UIElement @sender) { SortServerList(0); }
private void SortServerListByNumPlayers(spades::ui::UIElement @sender) {
SortServerList(1);
}
private void SortServerListByName(spades::ui::UIElement@ sender) {
SortServerList(2);
}
private void SortServerListByMapName(spades::ui::UIElement@ sender) {
SortServerList(3);
}
private void SortServerListByGameMode(spades::ui::UIElement@ sender) {
SortServerList(4);
}
private void SortServerListByProtocol(spades::ui::UIElement@ sender) {
SortServerList(5);
}
private void SortServerListByCountry(spades::ui::UIElement@ sender) {
SortServerList(6);
}
private void SortServerListByName(spades::ui::UIElement @sender) { SortServerList(2); }
private void SortServerListByMapName(spades::ui::UIElement @sender) { SortServerList(3); }
private void SortServerListByGameMode(spades::ui::UIElement @sender) { SortServerList(4); }
private void SortServerListByProtocol(spades::ui::UIElement @sender) { SortServerList(5); }
private void SortServerListByCountry(spades::ui::UIElement @sender) { SortServerList(6); }
private void SortServerList(int keyId) {
int sort = cg_serverlistSort.IntValue;
@ -345,8 +329,8 @@ namespace spades {
case 5: key = "Protocol"; break;
case 6: key = "Country"; break;
}
MainScreenServerItem@[]@ list = helper.GetServerList(key,
(cg_serverlistSort.IntValue & 0x4000) != 0);
MainScreenServerItem @[] @list =
helper.GetServerList(key, (cg_serverlistSort.IntValue & 0x4000) != 0);
if ((list is null)or(loading)) {
@serverList.Model = spades::ui::ListViewModel(); // empty
return;
@ -374,9 +358,9 @@ namespace spades {
continue;
}
if (filterText.length > 0) {
if(not (StringContainsCaseInsensitive(item.Name, filterText) or
StringContainsCaseInsensitive(item.MapName, filterText) or
StringContainsCaseInsensitive(item.GameMode, filterText))) {
if (not(StringContainsCaseInsensitive(item.Name, filterText)
or StringContainsCaseInsensitive(item.MapName, filterText)
or StringContainsCaseInsensitive(item.GameMode, filterText))) {
continue;
}
}
@ -397,7 +381,8 @@ namespace spades {
if (list is null or list.length == 0) {
// failed.
// FIXME: show error message?
loaded = false; loading = false;
loaded = false;
loading = false;
errorView.Visible = true;
loadingView.Visible = false;
@serverList.Model = spades::ui::ListViewModel(); // empty
@ -421,13 +406,9 @@ namespace spades {
cg_protocolVersion = ver;
}
private void OnProtocol3Pressed(spades::ui::UIElement@ sender) {
SetProtocolVersion(3);
}
private void OnProtocol3Pressed(spades::ui::UIElement @sender) { SetProtocolVersion(3); }
private void OnProtocol4Pressed(spades::ui::UIElement@ sender) {
SetProtocolVersion(4);
}
private void OnProtocol4Pressed(spades::ui::UIElement @sender) { SetProtocolVersion(4); }
private void OnFilterProtocol3Pressed(spades::ui::UIElement @sender) {
filterProtocol4Button.Toggled = false;
@ -445,20 +426,15 @@ namespace spades {
filterFullButton.Toggled = false;
UpdateServerList();
}
private void OnFilterTextChanged(spades::ui::UIElement@ sender) {
UpdateServerList();
}
private void OnFilterTextChanged(spades::ui::UIElement @sender) { UpdateServerList(); }
private void OnRefreshServerListPressed(spades::ui::UIElement@ sender) {
LoadServerList();
}
private void OnRefreshServerListPressed(spades::ui::UIElement @sender) { LoadServerList(); }
private void OnQuitPressed(spades::ui::UIElement@ sender) {
ui.shouldExit = true;
}
private void OnQuitPressed(spades::ui::UIElement @sender) { ui.shouldExit = true; }
private void OnCreditsPressed(spades::ui::UIElement @sender) {
AlertScreen al(this, ui.helper.Credits, Min(500.f, Manager.Renderer.ScreenHeight - 100.f));
AlertScreen al(this, ui.helper.Credits,
Min(500.f, Manager.Renderer.ScreenHeight - 100.f));
al.Run();
}
@ -476,9 +452,7 @@ namespace spades {
}
}
private void OnConnectPressed(spades::ui::UIElement@ sender) {
Connect();
}
private void OnConnectPressed(spades::ui::UIElement @sender) { Connect(); }
void HotKey(string key) {
if (IsEnabled and key == "Enter") {
@ -502,10 +476,14 @@ namespace spades {
if (msg.findFirst("Disconnected:") >= 0) {
int ind1 = msg.findFirst("Disconnected:");
int ind2 = msg.findFirst("\n", ind1);
if(ind2 < 0) ind2 = msg.length;
if (ind2 < 0)
ind2 = msg.length;
ind1 += "Disconnected:".length;
msg = msg.substr(ind1, ind2 - ind1);
msg = _Tr("MainScreen", "You were disconnected from the server because of the following reason:\n\n{0}", msg);
msg = _Tr(
"MainScreen",
"You were disconnected from the server because of the following reason:\n\n{0}",
msg);
}
// failed to connect.

View File

@ -40,7 +40,8 @@ namespace spades {
private ConfigItem cg_playerName("cg_playerName");
private ConfigItem cg_playerNameIsSet("cg_playerNameIsSet", "0");
MainScreenUI(Renderer@ renderer, AudioDevice@ audioDevice, FontManager@ fontManager, MainScreenHelper@ helper) {
MainScreenUI(Renderer @renderer, AudioDevice @audioDevice, FontManager @fontManager,
MainScreenHelper @helper) {
@this.renderer = renderer;
@this.audioDevice = audioDevice;
@this.fontManager = fontManager;
@ -56,15 +57,13 @@ namespace spades {
manager.RootElement.AddChild(mainMenu);
// Let the new player choose their IGN
if (cg_playerName.StringValue != "" &&
cg_playerName.StringValue != "Deuce") {
if (cg_playerName.StringValue != "" && cg_playerName.StringValue != "Deuce") {
cg_playerNameIsSet.IntValue = 1;
}
if (cg_playerNameIsSet.IntValue == 0) {
CreateProfileScreen al(mainMenu);
al.Run();
}
}
void SetupRenderer() {
@ -82,36 +81,24 @@ namespace spades {
manager.KeyPanic();
}
void MouseEvent(float x, float y) {
manager.MouseEvent(x, y);
}
void MouseEvent(float x, float y) { manager.MouseEvent(x, y); }
void WheelEvent(float x, float y) {
manager.WheelEvent(x, y);
}
void WheelEvent(float x, float y) { manager.WheelEvent(x, y); }
void KeyEvent(string key, bool down) {
manager.KeyEvent(key, down);
}
void KeyEvent(string key, bool down) { manager.KeyEvent(key, down); }
void TextInputEvent(string text) {
manager.TextInputEvent(text);
}
void TextInputEvent(string text) { manager.TextInputEvent(text); }
void TextEditingEvent(string text, int start, int len) {
manager.TextEditingEvent(text, start, len);
}
bool AcceptsTextInput() {
return manager.AcceptsTextInput;
}
bool AcceptsTextInput() { return manager.AcceptsTextInput; }
AABB2 GetTextInputRect() {
return manager.TextInputRect;
}
AABB2 GetTextInputRect() { return manager.TextInputRect; }
private SceneDefinition SetupCamera(SceneDefinition sceneDef,
Vector3 eye, Vector3 at, Vector3 up, float fov) {
private SceneDefinition SetupCamera(SceneDefinition sceneDef, Vector3 eye, Vector3 at,
Vector3 up, float fov) {
Vector3 dir = (at - eye).Normalized;
Vector3 side = Cross(dir, up).Normalized;
up = -Cross(dir, side);
@ -120,7 +107,9 @@ namespace spades {
sceneDef.viewAxisY = up;
sceneDef.viewAxisZ = dir;
sceneDef.fovY = fov * 3.141592654f / 180.f;
sceneDef.fovX = atan(tan(sceneDef.fovY * 0.5f) * renderer.ScreenWidth / renderer.ScreenHeight) * 2.f;
sceneDef.fovX =
atan(tan(sceneDef.fovY * 0.5f) * renderer.ScreenWidth / renderer.ScreenHeight) *
2.f;
return sceneDef;
}
@ -133,9 +122,9 @@ namespace spades {
float cameraX = time;
cameraX -= floor(cameraX / 512.f) * 512.f;
cameraX = 512.f - cameraX;
sceneDef = SetupCamera(sceneDef,
Vector3(cameraX, 256.f, 12.f), Vector3(cameraX + .1f, 257.f, 12.5f), Vector3(0.f, 0.f, -1.f),
30.f);
sceneDef =
SetupCamera(sceneDef, Vector3(cameraX, 256.f, 12.f),
Vector3(cameraX + .1f, 257.f, 12.5f), Vector3(0.f, 0.f, -1.f), 30.f);
sceneDef.zNear = 0.1f;
sceneDef.zFar = 222.f;
sceneDef.time = int(time * 1000.f);
@ -175,13 +164,9 @@ namespace spades {
time += Min(dt, 0.05f);
}
void Closing() {
shouldExit = true;
}
void Closing() { shouldExit = true; }
bool WantsToBeClosed() {
return shouldExit;
}
bool WantsToBeClosed() { return shouldExit; }
}
/**

View File

@ -53,15 +53,24 @@ namespace spades {
Font.Draw(item.Name, ScreenPosition + Vector2(4.f, 2.f), 1.f, fgcolor);
string playersStr = ToString(item.NumPlayers) + "/" + ToString(item.MaxPlayers);
Vector4 col(1, 1, 1, 1);
if(item.NumPlayers >= item.MaxPlayers) col = Vector4(1,0.7f,0.7f,1);
else if(item.NumPlayers >= item.MaxPlayers * 3 / 4) col = Vector4(1,1,0.7f,1);
else if(item.NumPlayers == 0) col = Vector4(0.7f,0.7f,1,1);
Font.Draw(playersStr, ScreenPosition + Vector2(340.f-Font.Measure(playersStr).x * 0.5f, 2.f), 1.f, col);
if (item.NumPlayers >= item.MaxPlayers)
col = Vector4(1, 0.7f, 0.7f, 1);
else if (item.NumPlayers >= item.MaxPlayers * 3 / 4)
col = Vector4(1, 1, 0.7f, 1);
else if (item.NumPlayers == 0)
col = Vector4(0.7f, 0.7f, 1, 1);
Font.Draw(playersStr,
ScreenPosition + Vector2(340.f - Font.Measure(playersStr).x * 0.5f, 2.f), 1.f,
col);
Font.Draw(item.MapName, ScreenPosition + Vector2(400.f, 2.f), 1.f, Vector4(1, 1, 1, 1));
Font.Draw(item.GameMode, ScreenPosition + Vector2(550.f, 2.f), 1.f, Vector4(1,1,1,1));
Font.Draw(item.Protocol, ScreenPosition + Vector2(630.f, 2.f), 1.f, Vector4(1,1,1,1));
if(not flagIconRenderer.DrawIcon(item.Country, ScreenPosition + Vector2(700.f, size.y * 0.5f))) {
Font.Draw(item.Country, ScreenPosition + Vector2(680.f, 2.f), 1.f, Vector4(1,1,1,1));
Font.Draw(item.GameMode, ScreenPosition + Vector2(550.f, 2.f), 1.f,
Vector4(1, 1, 1, 1));
Font.Draw(item.Protocol, ScreenPosition + Vector2(630.f, 2.f), 1.f,
Vector4(1, 1, 1, 1));
if (not flagIconRenderer.DrawIcon(item.Country,
ScreenPosition + Vector2(700.f, size.y * 0.5f))) {
Font.Draw(item.Country, ScreenPosition + Vector2(680.f, 2.f), 1.f,
Vector4(1, 1, 1, 1));
}
}
}
@ -111,15 +120,10 @@ namespace spades {
void RecycleElement(spades::ui::UIElement @elem) {}
}
class ServerListHeader : spades::ui::ButtonBase {
string Text;
ServerListHeader(spades::ui::UIManager@ manager){
super(manager);
}
void OnActivated() {
ButtonBase::OnActivated();
}
ServerListHeader(spades::ui::UIManager @manager) { super(manager); }
void OnActivated() { ButtonBase::OnActivated(); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;
@ -139,9 +143,7 @@ namespace spades {
}
class MainScreenServerListLoadingView : spades::ui::UIElement {
MainScreenServerListLoadingView(spades::ui::UIManager@ manager) {
super(manager);
}
MainScreenServerListLoadingView(spades::ui::UIManager @manager) { super(manager); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;
@ -157,9 +159,7 @@ namespace spades {
}
class MainScreenServerListErrorView : spades::ui::UIElement {
MainScreenServerListErrorView(spades::ui::UIManager@ manager) {
super(manager);
}
MainScreenServerListErrorView(spades::ui::UIManager @manager) { super(manager); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;

View File

@ -28,7 +28,8 @@ namespace spades {
private spades::ui::UIElement @owner;
MessageBoxScreen(spades::ui::UIElement@ owner, string text, string[]@ buttons, float height = 200.f) {
MessageBoxScreen(spades::ui::UIElement @owner, string text, string[] @buttons,
float height = 200.f) {
super(owner.Manager);
@this.owner = owner;
@Font = Manager.RootElement.Font;
@ -53,10 +54,9 @@ namespace spades {
for (uint i = 0; i < buttons.length; ++i) {
spades::ui::Button button(Manager);
button.Caption = buttons[i];
button.Bounds = AABB2(
contentsLeft + contentsWidth - (150.f + 10.f) * (buttons.length - i) + 10.f,
contentsTop + contentsHeight - 30.f
, 150.f, 30.f);
button.Bounds = AABB2(contentsLeft + contentsWidth -
(150.f + 10.f) * (buttons.length - i) + 10.f,
contentsTop + contentsHeight - 30.f, 150.f, 30.f);
MessageBoxScreenButtonHandler handler;
@handler.screen = this;
@ -67,7 +67,8 @@ namespace spades {
{
spades::ui::TextViewer viewer(Manager);
AddChild(viewer);
viewer.Bounds = AABB2(contentsLeft, contentsTop, contentsWidth, contentsHeight - 40.f);
viewer.Bounds =
AABB2(contentsLeft, contentsTop, contentsWidth, contentsHeight - 40.f);
viewer.Text = text;
}
}
@ -101,28 +102,23 @@ namespace spades {
Image @img = r.RegisterImage("Gfx/White.tga");
r.ColorNP = Vector4(1, 1, 1, 0.08f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 15.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 15.f, size.x, 1.f));
r.ColorNP = Vector4(1, 1, 1, 0.2f);
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + contentsTop - 14.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + contentsTop + contentsHeight + 14.f, size.x, 1.f));
UIElement::Render();
}
}
class MessageBoxScreenButtonHandler {
MessageBoxScreen @screen;
int resultIndex;
void OnPressed(spades::ui::UIElement@) {
screen.EndDialog(resultIndex);
}
void OnPressed(spades::ui::UIElement @) { screen.EndDialog(resultIndex); }
}
class AlertScreen : MessageBoxScreen {
@ -141,12 +137,11 @@ namespace spades {
class ConfirmScreen : MessageBoxScreen {
ConfirmScreen(spades::ui::UIElement @owner, string text, float height = 200.f) {
super(owner, text, array<string> = {_Tr("MessageBox", "OK"), _Tr("MessageBox", "Cancel")}, height);
super(owner, text,
array<string> = {_Tr("MessageBox", "OK"), _Tr("MessageBox", "Cancel")}, height);
}
bool get_Result() {
return ResultIndex == 0;
}
bool get_Result() { return ResultIndex == 0; }
void HotKey(string key) {
if (IsEnabled and key == "Enter") {

View File

@ -35,7 +35,8 @@ namespace spades {
spades::ui::EventHandler @Closed;
PreferenceView(spades::ui::UIElement@ owner, PreferenceViewOptions@ options, FontManager@ fontManager) {
PreferenceView(spades::ui::UIElement @owner, PreferenceViewOptions @options,
FontManager @fontManager) {
super(owner.Manager);
@this.owner = owner;
this.Bounds = owner.Bounds;
@ -57,17 +58,18 @@ namespace spades {
AddChild(label);
}
AddTab(GameOptionsPanel(Manager, options, fontManager), _Tr("Preferences", "Game Options"));
AddTab(ControlOptionsPanel(Manager, options, fontManager), _Tr("Preferences", "Controls"));
AddTab(GameOptionsPanel(Manager, options, fontManager),
_Tr("Preferences", "Game Options"));
AddTab(ControlOptionsPanel(Manager, options, fontManager),
_Tr("Preferences", "Controls"));
AddTab(MiscOptionsPanel(Manager, options, fontManager), _Tr("Preferences", "Misc"));
{
PreferenceTabButton button(Manager);
button.Caption = _Tr("Preferences", "Back");
button.Bounds = AABB2(
ContentsLeft + 10.f,
ContentsTop + 10.f + float(tabs.length) * 32.f + 5.f
, 150.f, 30.f);
button.Bounds =
AABB2(ContentsLeft + 10.f, ContentsTop + 10.f + float(tabs.length) * 32.f + 5.f,
150.f, 30.f);
button.Alignment = Vector2(0.f, 0.5f);
@button.Activated = spades::ui::EventHandler(this.OnClosePressed);
AddChild(button);
@ -79,9 +81,11 @@ namespace spades {
private void AddTab(spades::ui::UIElement @view, string caption) {
PreferenceTab tab(this, view);
int order = int(tabs.length);
tab.TabButton.Bounds = AABB2(ContentsLeft + 10.f, ContentsTop + 10.f + float(order) * 32.f, 150.f, 30.f);
tab.TabButton.Bounds =
AABB2(ContentsLeft + 10.f, ContentsTop + 10.f + float(order) * 32.f, 150.f, 30.f);
tab.TabButton.Caption = caption;
tab.View.Bounds = AABB2(ContentsLeft + 170.f, ContentsTop + 10.f, ContentsWidth - 180.f, ContentsHeight - 20.f);
tab.View.Bounds = AABB2(ContentsLeft + 170.f, ContentsTop + 10.f, ContentsWidth - 180.f,
ContentsHeight - 20.f);
tab.View.Visible = false;
@tab.TabButton.Activated = spades::ui::EventHandler(this.OnTabButtonActivated);
AddChild(tab.View);
@ -107,12 +111,11 @@ namespace spades {
}
}
private void OnClosePressed(spades::ui::UIElement@ sender) {
Close();
}
private void OnClosePressed(spades::ui::UIElement @sender) { Close(); }
private void OnClosed() {
if(Closed !is null) Closed(this);
if (Closed !is null)
Closed(this);
}
void HotKey(string key) {
@ -130,20 +133,17 @@ namespace spades {
Image @img = r.RegisterImage("Gfx/White.tga");
r.ColorNP = Vector4(1, 1, 1, 0.08f);
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop - 15.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + ContentsTop - 15.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop + ContentsHeight + 15.f, size.x, 1.f));
r.ColorNP = Vector4(1, 1, 1, 0.2f);
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop - 14.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + ContentsTop - 14.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop + ContentsHeight + 14.f, size.x, 1.f));
UIElement::Render();
}
void Close() {
owner.Enable = true;
@this.Parent = null;
@ -154,8 +154,6 @@ namespace spades {
owner.Enable = false;
owner.Parent.AddChild(this);
}
}
class PreferenceTabButton : spades::ui::Button {
@ -185,7 +183,6 @@ namespace spades {
font.DrawShadow(text, txtPos, 1.f,
color, Vector4(0.f, 0.f, 0.f, 0.4f));
}*/
}
class PreferenceTab {
@ -246,16 +243,15 @@ namespace spades {
value -= float(intPart);
value *= 10.f;
intPart = int(value);
if(intPart > 9) intPart = 9;
if (intPart > 9)
intPart = 9;
s += ToString(intPart);
}
}
s += suffix;
return s;
}
string Format(float value) {
return prefix + FormatInternal(value);
}
string Format(float value) { return prefix + FormatInternal(value); }
}
class ConfigSlider : spades::ui::Slider {
@ -264,9 +260,8 @@ namespace spades {
spades::ui::Label @label;
ConfigNumberFormatter @formatter;
ConfigSlider(spades::ui::UIManager manager, string configName,
float minValue, float maxValue, float stepValue,
ConfigNumberFormatter@ formatter) {
ConfigSlider(spades::ui::UIManager manager, string configName, float minValue,
float maxValue, float stepValue, ConfigNumberFormatter @formatter) {
super(manager);
@config = ConfigItem(configName);
this.MinValue = minValue;
@ -291,9 +286,7 @@ namespace spades {
label.Bounds = AABB2(Size.x, 0.f, 80.f, Size.y);
}
void UpdateLabel() {
label.Text = formatter.Format(config.FloatValue);
}
void UpdateLabel() { label.Text = formatter.Format(config.FloatValue); }
void DoRounding() {
float v = float(this.Value - this.MinValue);
@ -375,12 +368,8 @@ namespace spades {
}
}
void MouseEnter() {
hover = true;
}
void MouseLeave() {
hover = false;
}
void MouseEnter() { hover = true; }
void MouseLeave() { hover = false; }
void Render() {
// render background
@ -404,7 +393,9 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x + size.x - 1.f, pos.y + 1.f, 1.f, size.y - 2.f));
Font @font = this.Font;
string text = IsFocused ? _Tr("Preferences", "Press Key to Bind or [Escape] to Cancel...") : config.StringValue;
string text = IsFocused
? _Tr("Preferences", "Press Key to Bind or [Escape] to Cancel...")
: config.StringValue;
Vector4 color(1, 1, 1, 1);
@ -446,8 +437,6 @@ namespace spades {
Vector2 txtPos;
txtPos = pos + (size - txtSize) * 0.5f;
font.Draw(text, txtPos, 1.f, color);
}
}
@ -455,7 +444,8 @@ namespace spades {
class ConfigSimpleToggleButton : spades::ui::RadioButton {
ConfigItem @config;
int value;
ConfigSimpleToggleButton(spades::ui::UIManager manager, string caption, string configName, int value) {
ConfigSimpleToggleButton(spades::ui::UIManager manager, string caption, string configName,
int value) {
super(manager);
@config = ConfigItem(configName);
this.Caption = caption;
@ -478,17 +468,12 @@ namespace spades {
class StandardPreferenceLayouterModel : spades::ui::ListViewModel {
private spades::ui::UIElement @[] @items;
StandardPreferenceLayouterModel(spades::ui::UIElement@[]@ items) {
@this.items = items;
}
StandardPreferenceLayouterModel(spades::ui::UIElement @[] @items) { @this.items = items; }
int NumRows {
get { return int(items.length); }
}
spades::ui::UIElement@ CreateElement(int row) {
return items[row];
}
void RecycleElement(spades::ui::UIElement@ elem) {
}
spades::ui::UIElement @CreateElement(int row) { return items[row]; }
void RecycleElement(spades::ui::UIElement @elem) {}
}
class StandardPreferenceLayouter {
spades::ui::UIElement @Parent;
@ -552,9 +537,9 @@ namespace spades {
return field;
}
ConfigSlider@ AddSliderField(string caption, string configName,
float minRange, float maxRange, float step,
ConfigNumberFormatter@ formatter, bool enabled = true) {
ConfigSlider
@AddSliderField(string caption, string configName, float minRange, float maxRange,
float step, ConfigNumberFormatter @formatter, bool enabled = true) {
spades::ui::UIElement @container = CreateItem();
spades::ui::Label label(Parent.Manager);
@ -563,8 +548,7 @@ namespace spades {
label.Bounds = AABB2(10.f, 0.f, 300.f, 32.f);
container.AddChild(label);
ConfigSlider slider(Parent.Manager, configName, minRange, maxRange, step,
formatter);
ConfigSlider slider(Parent.Manager, configName, minRange, maxRange, step, formatter);
slider.Bounds = AABB2(FieldX, 8.f, FieldWidth - 80.f, 16.f);
slider.Enable = enabled;
container.AddChild(slider);
@ -590,7 +574,8 @@ namespace spades {
hotkeyItems.insertLast(field);
}
void AddChoiceField(string caption, string configName, array<string> labels, array<int> values, bool enabled = true) {
void AddChoiceField(string caption, string configName, array<string> labels,
array<int> values, bool enabled = true) {
spades::ui::UIElement @container = CreateItem();
spades::ui::Label label(Parent.Manager);
@ -601,8 +586,8 @@ namespace spades {
for (uint i = 0; i < labels.length; ++i) {
ConfigSimpleToggleButton field(Parent.Manager, labels[i], configName, values[i]);
field.Bounds = AABB2(FieldX + FieldWidth / labels.length * i,
1.f, FieldWidth / labels.length, 30.f);
field.Bounds = AABB2(FieldX + FieldWidth / labels.length * i, 1.f,
FieldWidth / labels.length, 30.f);
field.Enable = enabled;
container.AddChild(field);
}
@ -616,7 +601,9 @@ namespace spades {
void AddPlusMinusField(string caption, string configName, bool enabled = true) {
AddChoiceField(caption, configName,
array<string> = {_Tr("Preferences", "ON"), _Tr("Preferences", "REVERSED"), _Tr("Preferences", "OFF")},
array<string> = {_Tr("Preferences", "ON"),
_Tr("Preferences", "REVERSED"),
_Tr("Preferences", "OFF")},
array<int> = {1, -1, 0}, enabled);
}
@ -630,12 +617,14 @@ namespace spades {
}
class GameOptionsPanel : spades::ui::UIElement {
GameOptionsPanel(spades::ui::UIManager@ manager, PreferenceViewOptions@ options, FontManager@ fontManager) {
GameOptionsPanel(spades::ui::UIManager @manager, PreferenceViewOptions @options,
FontManager @fontManager) {
super(manager);
StandardPreferenceLayouter layouter(this, fontManager);
layouter.AddHeading(_Tr("Preferences", "Player Information"));
ConfigField@ nameField = layouter.AddInputField(_Tr("Preferences", "Player Name"), "cg_playerName", not options.GameActive);
ConfigField @nameField = layouter.AddInputField(
_Tr("Preferences", "Player Name"), "cg_playerName", not options.GameActive);
nameField.MaxLength = 15;
nameField.DenyNonAscii = true;
@ -645,10 +634,14 @@ namespace spades {
layouter.AddToggleField(_Tr("Preferences", "Ragdoll"), "cg_ragdoll");
layouter.AddToggleField(_Tr("Preferences", "Animations"), "cg_animations");
layouter.AddChoiceField(_Tr("Preferences", "Camera Shake"), "cg_shake",
array<string> = {_Tr("Preferences", "MORE"), _Tr("Preferences", "NORMAL"), _Tr("Preferences", "OFF")},
array<string> = {_Tr("Preferences", "MORE"),
_Tr("Preferences", "NORMAL"),
_Tr("Preferences", "OFF")},
array<int> = {2, 1, 0});
layouter.AddChoiceField(_Tr("Preferences", "Particles"), "cg_particles",
array<string> = {_Tr("Preferences", "NORMAL"), _Tr("Preferences", "LESS"), _Tr("Preferences", "OFF")},
array<string> = {_Tr("Preferences", "NORMAL"),
_Tr("Preferences", "LESS"),
_Tr("Preferences", "OFF")},
array<int> = {2, 1, 0});
layouter.AddHeading(_Tr("Preferences", "Feedbacks"));
@ -663,29 +656,33 @@ namespace spades {
layouter.AddHeading(_Tr("Preferences", "Misc"));
layouter.AddSliderField(_Tr("Preferences", "Field of View"), "cg_fov", 45, 90, 1,
ConfigNumberFormatter(0, " deg"));
layouter.AddSliderField(_Tr("Preferences", "Minimap size"), "cg_minimapSize", 128, 256, 8,
ConfigNumberFormatter(0, " px"));
layouter.AddSliderField(_Tr("Preferences", "Minimap size"), "cg_minimapSize", 128, 256,
8, ConfigNumberFormatter(0, " px"));
layouter.AddToggleField(_Tr("Preferences", "Show Statistics"), "cg_stats");
layouter.FinishLayout();
}
}
class ControlOptionsPanel : spades::ui::UIElement {
ControlOptionsPanel(spades::ui::UIManager@ manager, PreferenceViewOptions@ options, FontManager@ fontManager) {
ControlOptionsPanel(spades::ui::UIManager @manager, PreferenceViewOptions @options,
FontManager @fontManager) {
super(manager);
StandardPreferenceLayouter layouter(this, fontManager);
layouter.AddHeading(_Tr("Preferences", "Weapons/Tools"));
layouter.AddControl(_Tr("Preferences", "Attack"), "cg_keyAttack");
layouter.AddControl(_Tr("Preferences", "Alt. Attack"), "cg_keyAltAttack");
layouter.AddToggleField(_Tr("Preferences", "Hold Aim Down Sight"), "cg_holdAimDownSight");
layouter.AddSliderField(_Tr("Preferences", "Mouse Sensitivity"), "cg_mouseSensitivity", 0.1, 10, 0.1,
ConfigNumberFormatter(1, "x"));
layouter.AddSliderField(_Tr("Preferences", "ADS Mouse Sens. Scale"), "cg_zoomedMouseSensScale", 0.05, 3, 0.05,
layouter.AddToggleField(_Tr("Preferences", "Hold Aim Down Sight"),
"cg_holdAimDownSight");
layouter.AddSliderField(_Tr("Preferences", "Mouse Sensitivity"), "cg_mouseSensitivity",
0.1, 10, 0.1, ConfigNumberFormatter(1, "x"));
layouter.AddSliderField(_Tr("Preferences", "ADS Mouse Sens. Scale"),
"cg_zoomedMouseSensScale", 0.05, 3, 0.05,
ConfigNumberFormatter(2, "x"));
layouter.AddSliderField(_Tr("Preferences", "Exponential Power"), "cg_mouseExpPower", 0.5, 1.5, 0.02,
ConfigNumberFormatter(2, "", "^"));
layouter.AddToggleField(_Tr("Preferences", "Invert Y-axis Mouse Input"), "cg_invertMouseY");
layouter.AddSliderField(_Tr("Preferences", "Exponential Power"), "cg_mouseExpPower",
0.5, 1.5, 0.02, ConfigNumberFormatter(2, "", "^"));
layouter.AddToggleField(_Tr("Preferences", "Invert Y-axis Mouse Input"),
"cg_invertMouseY");
layouter.AddControl(_Tr("Preferences", "Reload"), "cg_keyReloadWeapon");
layouter.AddControl(_Tr("Preferences", "Capture Color"), "cg_keyCaptureColor");
layouter.AddControl(_Tr("Preferences", "Equip Spade"), "cg_keyToolSpade");
@ -693,7 +690,8 @@ namespace spades {
layouter.AddControl(_Tr("Preferences", "Equip Weapon"), "cg_keyToolWeapon");
layouter.AddControl(_Tr("Preferences", "Equip Grenade"), "cg_keyToolGrenade");
layouter.AddControl(_Tr("Preferences", "Last Used Tool"), "cg_keyLastTool");
layouter.AddPlusMinusField(_Tr("Preferences", "Switch Tools by Wheel"), "cg_switchToolByWheel");
layouter.AddPlusMinusField(_Tr("Preferences", "Switch Tools by Wheel"),
"cg_switchToolByWheel");
layouter.AddHeading(_Tr("Preferences", "Movement"));
layouter.AddControl(_Tr("Preferences", "Walk Forward"), "cg_keyMoveForward");
@ -720,14 +718,14 @@ namespace spades {
}
}
class MiscOptionsPanel : spades::ui::UIElement {
spades::ui::Label @msgLabel;
spades::ui::Button @enableButton;
private ConfigItem cl_showStartupWindow("cl_showStartupWindow");
MiscOptionsPanel(spades::ui::UIManager@ manager, PreferenceViewOptions@ options, FontManager@ fontManager) {
MiscOptionsPanel(spades::ui::UIManager @manager, PreferenceViewOptions @options,
FontManager @fontManager) {
super(manager);
{
@ -753,9 +751,11 @@ namespace spades {
void UpdateState() {
bool enabled = cl_showStartupWindow.IntValue != 0;
msgLabel.Text = enabled ?
_Tr("Preferences", "Quit and restart OpenSpades to access the startup window."):
_Tr("Preferences", "Some settings only can be changed in the startup window.");
msgLabel.Text = enabled
? _Tr("Preferences",
"Quit and restart OpenSpades to access the startup window.")
: _Tr("Preferences",
"Some settings only can be changed in the startup window.");
enableButton.Enable = not enabled;
}
@ -763,6 +763,5 @@ namespace spades {
cl_showStartupWindow.IntValue = 1;
UpdateState();
}
}
}

View File

@ -31,7 +31,8 @@ namespace spades {
@this.h2 = h2;
}
void Handler(spades::ui::UIElement @e) {
h(e); h2(e);
h(e);
h2(e);
}
}
class HelpHandler {
@ -59,7 +60,8 @@ namespace spades {
}
void WatchDeep(spades::ui::UIElement @elm) {
if (elm.MouseEntered !is null) {
ChainedEventHandler chain(elm.MouseEntered, spades::ui::EventHandler(this.OnMouseHover));
ChainedEventHandler chain(elm.MouseEntered,
spades::ui::EventHandler(this.OnMouseHover));
@elm.MouseEntered = spades::ui::EventHandler(chain.Handler);
} else {
Watch(elm);
@ -82,14 +84,12 @@ namespace spades {
label.Bounds = AABB2(x, y, siz.x, h);
AddChild(label);
}
}
class StartupScreenConfigViewModel : spades::ui::ListViewModel {
spades::ui::UIElement @[] items;
spades::ui::UIElement @[] @items2;
StartupScreenConfigViewModel() {
}
StartupScreenConfigViewModel() {}
int NumRows {
get {
if (items2 !is null)
@ -107,7 +107,8 @@ namespace spades {
for (uint i = 0, count = items.length; i < count; i++) {
StartupScreenConfigItemEditor @editor =
cast<StartupScreenConfigItemEditor>(items[i]);
if(editor is null) continue;
if (editor is null)
continue;
string label = editor.GetLabel();
if (StringContainsCaseInsensitive(label, text)) {
newItems.insertLast(items[i]);
@ -120,8 +121,7 @@ namespace spades {
return items2[row];
return items[row];
}
void RecycleElement(spades::ui::UIElement@ elem) {
}
void RecycleElement(spades::ui::UIElement @elem) {}
}
interface StartupScreenGenericConfig {
@ -140,12 +140,8 @@ namespace spades {
@this.cfg = ConfigItem(cfg);
cfgName = cfg;
}
string GetValue() {
return cfg.StringValue;
}
void SetValue(string v) {
cfg.StringValue = v;
}
string GetValue() { return cfg.StringValue; }
void SetValue(string v) { cfg.StringValue = v; }
string CheckValueCapability(string v) {
return ui.helper.CheckConfigCapability(cfgName, v);
}
@ -158,9 +154,7 @@ namespace spades {
@this.c = c;
this.value = value;
}
void Set(spades::ui::UIElement@) {
c.SetValue(this.value);
}
void Set(spades::ui::UIElement @) { c.SetValue(this.value); }
}
interface StartupScreenConfigItemEditor {
@ -170,8 +164,10 @@ namespace spades {
string GetLabel();
}
class StartupScreenConfigSelectItemEditor: spades::ui::UIElement, LabelAddable, StartupScreenConfigItemEditor, StartupScreenConfigItemEditor {
class StartupScreenConfigSelectItemEditor : spades::ui::UIElement,
LabelAddable,
StartupScreenConfigItemEditor,
StartupScreenConfigItemEditor {
protected StartupScreenUI @ui;
private string[] @descs;
@ -180,8 +176,7 @@ namespace spades {
protected spades::ui::RadioButton @[] buttons;
private string label;
StartupScreenConfigSelectItemEditor(StartupScreenUI@ ui,
StartupScreenGenericConfig@ cfg,
StartupScreenConfigSelectItemEditor(StartupScreenUI @ui, StartupScreenGenericConfig @cfg,
string values, string descs) {
super(ui.manager);
@this.ui = ui;
@ -199,7 +194,6 @@ namespace spades {
this.label = desc;
}
for (uint i = 0; i < this.values.length; i++) {
spades::ui::RadioButton b(Manager);
string desc = this.descs[i + 1];
@ -217,9 +211,7 @@ namespace spades {
}
}
string GetLabel() {
return label;
}
string GetLabel() { return label; }
void LoadConfig() {
string val = config.GetValue();
@ -228,12 +220,8 @@ namespace spades {
buttons[i].Enable = CheckValueCapability(values[i]).length == 0;
}
}
string CheckValueCapability(string v) {
return config.CheckValueCapability(v);
}
StartupScreenGenericConfig@ GetConfig() {
return config;
}
string CheckValueCapability(string v) { return config.CheckValueCapability(v); }
StartupScreenGenericConfig @GetConfig() { return config; }
void SetHelpTextHandler(HelpTextHandler @handler) {
for (uint i = 0, count = values.length; i < count; i++) {
string desc = descs[i + 1];
@ -261,7 +249,8 @@ namespace spades {
}
}
class StartupScreenConfigCheckItemEditor: spades::ui::UIElement, StartupScreenConfigItemEditor {
class StartupScreenConfigCheckItemEditor : spades::ui::UIElement,
StartupScreenConfigItemEditor {
protected StartupScreenUI @ui;
private string desc;
@ -271,9 +260,9 @@ namespace spades {
private spades::ui::CheckBox @button;
private string label;
StartupScreenConfigCheckItemEditor(StartupScreenUI@ ui,
StartupScreenGenericConfig@ cfg,
string valueOff, string valueOn, string label, string desc) {
StartupScreenConfigCheckItemEditor(StartupScreenUI @ui, StartupScreenGenericConfig @cfg,
string valueOff, string valueOn, string label,
string desc) {
super(ui.manager);
@this.ui = ui;
@config = cfg;
@ -289,21 +278,15 @@ namespace spades {
this.AddChild(b);
}
string GetLabel() {
return label;
}
string GetLabel() { return label; }
void LoadConfig() {
string val = config.GetValue();
button.Toggled = (val != valueOff);
button.Enable = CheckValueCapability(valueOn).length == 0;
}
string CheckValueCapability(string v) {
return config.CheckValueCapability(v);
}
StartupScreenGenericConfig@ GetConfig() {
return config;
}
string CheckValueCapability(string v) { return config.CheckValueCapability(v); }
StartupScreenGenericConfig @GetConfig() { return config; }
private void StateChanged(spades::ui::UIElement @) {
config.SetValue(button.Toggled ? valueOn : valueOff);
}
@ -319,7 +302,9 @@ namespace spades {
}
}
class StartupScreenConfigSliderItemEditor: spades::ui::UIElement, StartupScreenConfigItemEditor, LabelAddable {
class StartupScreenConfigSliderItemEditor : spades::ui::UIElement,
StartupScreenConfigItemEditor,
LabelAddable {
private StartupScreenUI @ui;
private string desc;
@ -330,9 +315,9 @@ namespace spades {
private ConfigNumberFormatter @formatter;
private string label;
StartupScreenConfigSliderItemEditor(StartupScreenUI@ ui,
StartupScreenGenericConfig@ cfg,
double minValue, double maxValue, double stepSize, string label, string desc,
StartupScreenConfigSliderItemEditor(StartupScreenUI @ui, StartupScreenGenericConfig @cfg,
double minValue, double maxValue, double stepSize,
string label, string desc,
ConfigNumberFormatter @formatter) {
super(ui.manager);
@this.ui = ui;
@ -371,9 +356,7 @@ namespace spades {
valueLabel.Text = s;
}
string GetLabel() {
return label;
}
string GetLabel() { return label; }
void LoadConfig() {
string val = config.GetValue();
@ -387,9 +370,7 @@ namespace spades {
string CheckValueCapability(string v) {
return ""; // FIXME: config.CheckValueCapability(v);
}
StartupScreenGenericConfig@ GetConfig() {
return config;
}
StartupScreenGenericConfig @GetConfig() { return config; }
void DoRounding() {
double v = double(slider.Value - slider.MinValue);
@ -415,8 +396,9 @@ namespace spades {
}
}
class StartupScreenConfigFieldItemEditor: spades::ui::UIElement, StartupScreenConfigItemEditor, LabelAddable {
class StartupScreenConfigFieldItemEditor : spades::ui::UIElement,
StartupScreenConfigItemEditor,
LabelAddable {
private StartupScreenUI @ui;
private string desc;
@ -425,8 +407,7 @@ namespace spades {
private spades::ui::Field @field;
private string label;
StartupScreenConfigFieldItemEditor(StartupScreenUI@ ui,
StartupScreenGenericConfig@ cfg,
StartupScreenConfigFieldItemEditor(StartupScreenUI @ui, StartupScreenGenericConfig @cfg,
string label, string desc) {
super(ui.manager);
@this.ui = ui;
@ -441,27 +422,18 @@ namespace spades {
@b.Changed = spades::ui::EventHandler(this.StateChanged);
@field = b;
this.AddChild(b);
}
string GetLabel() {
return label;
}
string GetLabel() { return label; }
void LoadConfig() {
string val = config.GetValue();
field.Text = val;
}
string CheckValueCapability(string v) {
return config.CheckValueCapability(v);
}
StartupScreenGenericConfig@ GetConfig() {
return config;
}
string CheckValueCapability(string v) { return config.CheckValueCapability(v); }
StartupScreenGenericConfig @GetConfig() { return config; }
private void StateChanged(spades::ui::UIElement@) {
config.SetValue(field.Text);
}
private void StateChanged(spades::ui::UIElement @) { config.SetValue(field.Text); }
void SetHelpTextHandler(HelpTextHandler @handler) {
HelpHandler(handler, desc).WatchDeep(field);
}
@ -564,8 +536,7 @@ namespace spades {
class StartupScreenConfigComplexItemEditor : StartupScreenConfigSelectItemEditor {
private string dlgTitle;
StartupScreenConfigComplexItemEditor(StartupScreenUI@ ui,
StartupScreenComplexConfig@ cfg,
StartupScreenConfigComplexItemEditor(StartupScreenUI @ui, StartupScreenComplexConfig @cfg,
string label, string desc) {
super(ui, cfg, cfg.GetValuesString(),
label + ":" + desc + "|" + cfg.GetDescriptionsString());
@ -573,16 +544,13 @@ namespace spades {
@buttons[buttons.length - 1].Activated = spades::ui::EventHandler(this.CustomClicked);
}
private void CustomClicked(spades::ui::UIElement@) {
RunDialog();
}
private void CustomClicked(spades::ui::UIElement @) { RunDialog(); }
private void DialogDone(spades::ui::UIElement@) {
LoadConfig();
}
private void DialogDone(spades::ui::UIElement @) { LoadConfig(); }
private void RunDialog() {
StartupScreenComplexConfigDialog dlg(ui.manager, cast<StartupScreenComplexConfig>(config));
StartupScreenComplexConfigDialog dlg(ui.manager,
cast<StartupScreenComplexConfig>(config));
@dlg.DialogDone = spades::ui::EventHandler(this.DialogDone);
dlg.Title = dlgTitle;
dlg.RunDialog();
@ -596,12 +564,8 @@ namespace spades {
super(manager);
this.RowHeight = 30.f;
}
void Finalize() {
@this.Model = vmodel;
}
void AddRow(spades::ui::UIElement@ elm) {
vmodel.items.insertLast(elm);
}
void Finalize() { @this.Model = vmodel; }
void AddRow(spades::ui::UIElement @elm) { vmodel.items.insertLast(elm); }
void Filter(string text) {
vmodel.Filter(text);
@ -651,7 +615,8 @@ namespace spades {
float mainWidth = size.x - 250.f;
{
spades::ui::TextViewer e(Manager);
e.Bounds = AABB2(mainWidth, ContentsTop + 30.f, size.x - mainWidth - 10.f, ContentsHeight - 60.f);
e.Bounds = AABB2(mainWidth, ContentsTop + 30.f, size.x - mainWidth - 10.f,
ContentsHeight - 60.f);
AddChild(e);
@helpView = e;
}
@ -666,7 +631,8 @@ namespace spades {
cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
cfg.Bounds = AABB2(10.f, ContentsTop + 30.f, mainWidth - 20.f, ContentsHeight - 60.f);
cfg.Bounds =
AABB2(10.f, ContentsTop + 30.f, mainWidth - 20.f, ContentsHeight - 60.f);
AddChild(cfg);
@configView = cfg;
}
@ -674,11 +640,11 @@ namespace spades {
{
spades::ui::Button button(Manager);
button.Caption = _Tr("StartupScreen", "Close");
button.Bounds = AABB2(size.x - 160.f, ContentsTop + ContentsHeight - 30.f, 150.f, 30.f);
button.Bounds =
AABB2(size.x - 160.f, ContentsTop + ContentsHeight - 30.f, 150.f, 30.f);
@button.Activated = spades::ui::EventHandler(this.CloseActivated);
AddChild(button);
}
}
private void CloseActivated(spades::ui::UIElement @) {
@ -690,9 +656,7 @@ namespace spades {
DialogDone(this);
}
private void HandleHelpText(string s) {
helpView.Text = s;
}
private void HandleHelpText(string s) { helpView.Text = s; }
void RunDialog() {
spades::ui::UIElement @root = Manager.RootElement;
@ -720,35 +684,30 @@ namespace spades {
Image @img = r.RegisterImage("Gfx/White.tga");
r.ColorNP = Vector4(0, 0, 0, 0.8f);
r.DrawImage(img,
AABB2(pos.x, pos.y, size.x, ContentsTop - 15.f));
r.DrawImage(img,
AABB2(pos.x, ContentsTop + ContentsHeight + 15.f, size.x, ContentsTop - 15.f));
r.DrawImage(img, AABB2(pos.x, pos.y, size.x, ContentsTop - 15.f));
r.DrawImage(
img, AABB2(pos.x, ContentsTop + ContentsHeight + 15.f, size.x, ContentsTop - 15.f));
r.ColorNP = Vector4(0, 0, 0, 0.95f);
r.DrawImage(img,
AABB2(pos.x, ContentsTop - 15.f, size.x, ContentsHeight + 30.f));
r.DrawImage(img, AABB2(pos.x, ContentsTop - 15.f, size.x, ContentsHeight + 30.f));
r.ColorNP = Vector4(1, 1, 1, 0.08f);
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop - 15.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + ContentsTop - 15.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop + ContentsHeight + 15.f, size.x, 1.f));
r.ColorNP = Vector4(1, 1, 1, 0.2f);
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop - 14.f, size.x, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + ContentsTop - 14.f, size.x, 1.f));
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop + ContentsHeight + 14.f, size.x, 1.f));
Font @font = Font;
r.ColorNP = Vector4(0.8f, 0.8f, 0.8f, 1.f);
r.DrawImage(img,
AABB2(pos.x, pos.y + ContentsTop, size.x, 20.f));
font.Draw(Title, Vector2(pos.x + 10.f, pos.y + ContentsTop), 1.f, Vector4(0.f, 0.f, 0.f, 1.f));
r.DrawImage(img, AABB2(pos.x, pos.y + ContentsTop, size.x, 20.f));
font.Draw(Title, Vector2(pos.x + 10.f, pos.y + ContentsTop), 1.f,
Vector4(0.f, 0.f, 0.f, 1.f));
UIElement::Render();
}
}
}

View File

@ -70,9 +70,11 @@ namespace spades {
spades::ui::CheckBox e(Manager);
e.Caption = _Tr("StartupScreen", "Fullscreen Mode");
e.Bounds = AABB2(230.f, 0.f, 200.f, 24.f);
HelpHandler(helpView,
_Tr("StartupScreen", "By running in fullscreen mode OpenSpades occupies the "
"screen, making it easier for you to concentrate on playing the game.")).Watch(e);
HelpHandler(
helpView,
_Tr("StartupScreen",
"By running in fullscreen mode OpenSpades occupies the " "screen, making it easier for you to concentrate on playing the game."))
.Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnFullscreenCheck);
AddChild(e);
@fullscreenCheck = e;
@ -84,9 +86,11 @@ namespace spades {
e.Caption = _Tr("StartupScreen", "OpenGL");
e.Bounds = AABB2(100.f, 30.f, 140.f, 24.f);
e.GroupName = "driver";
HelpHandler(helpView,
_Tr("StartupScreen", "OpenGL renderer uses your computer's graphics "
"accelerator to generate the game screen.")).Watch(e);
HelpHandler(
helpView,
_Tr("StartupScreen",
"OpenGL renderer uses your computer's graphics " "accelerator to generate the game screen."))
.Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnDriverOpenGL);
AddChild(e);
@driverOpenGL = e;
@ -96,10 +100,11 @@ namespace spades {
e.Caption = _Tr("StartupScreen", "Software");
e.Bounds = AABB2(250.f, 30.f, 140.f, 24.f);
e.GroupName = "driver";
HelpHandler(helpView,
_Tr("StartupScreen", "Software renderer uses CPU to generate the game "
"screen. Its quality and performance might be inferior to OpenGL "
"renderer, but it works even with an unsupported GPU.")).Watch(e);
HelpHandler(
helpView,
_Tr("StartupScreen",
"Software renderer uses CPU to generate the game " "screen. Its quality and performance might be inferior to OpenGL " "renderer, but it works even with an unsupported GPU."))
.Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnDriverSoftware);
AddChild(e);
@driverSoftware = e;
@ -108,126 +113,142 @@ namespace spades {
{
StartupScreenConfigView cfg(Manager);
cfg.AddRow(StartupScreenConfigSelectItemEditor(ui,
StartupScreenGraphicsAntialiasConfig(ui), "0|2|4|fxaa",
cfg.AddRow(StartupScreenConfigSelectItemEditor(
ui, StartupScreenGraphicsAntialiasConfig(ui), "0|2|4|fxaa",
_Tr("StartupScreen",
"Antialias:Enables a technique to improve the appearance of high-contrast edges.\n\n"
"MSAA: Performs antialiasing by generating an intermediate high-resolution image. "
"Looks best, but doesn't cope with some settings.\n\n"
"FXAA: Performs antialiasing by smoothing artifacts out as a post-process.|"
"Off|MSAA 2x|4x|FXAA")));
"Antialias:Enables a technique to improve the appearance of high-contrast edges.\n\n" "MSAA: Performs antialiasing by generating an intermediate high-resolution image. " "Looks best, but doesn't cope with some settings.\n\n" "FXAA: Performs antialiasing by smoothing artifacts out as a post-process.|" "Off|MSAA 2x|4x|FXAA")));
cfg.AddRow(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_radiosity"), "0", "1", _Tr("StartupScreen", "Global Illumination"),
cfg.AddRow(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_radiosity"), "0", "1",
_Tr("StartupScreen", "Global Illumination"),
_Tr("StartupScreen",
"Enables a physically based simulation of light path for more realistic lighting.")));
cfg.AddRow(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_hdr"), "0", "1", _Tr("StartupScreen", "Linear HDR Rendering"),
cfg.AddRow(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_hdr"), "0", "1",
_Tr("StartupScreen", "Linear HDR Rendering"),
_Tr("StartupScreen",
"Uses a number representation which allows wider dynamic range during rendering process. "
"Additionally, this allows color calculation whose value is in linear correspondence with actual energy, "
"that is, physically accurate blending can be achieved.")));
"Uses a number representation which allows wider dynamic range during rendering process. " "Additionally, this allows color calculation whose value is in linear correspondence with actual energy, " "that is, physically accurate blending can be achieved.")));
{
StartupScreenComplexConfig cplx;
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_cameraBlur"), "0", "1", _Tr("StartupScreen", "Camera Blur"),
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_cameraBlur"), "0", "1",
_Tr("StartupScreen", "Camera Blur"),
_Tr("StartupScreen", "Blurs the screen when you turn quickly.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_lens"), "0", "1", _Tr("StartupScreen", "Lens Effect"),
_Tr("StartupScreen", "Simulates distortion caused by a real camera lens.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_bloom"), "0", "1", _Tr("StartupScreen", "Lens Scattering Filter"),
_Tr("StartupScreen", "Simulates light being scattered by dust on the camera lens.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_lens"), "0", "1",
_Tr("StartupScreen", "Lens Effect"),
_Tr("StartupScreen",
"Simulates distortion caused by a real camera lens.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_bloom"), "0", "1",
_Tr("StartupScreen", "Lens Scattering Filter"),
_Tr("StartupScreen",
"Simulates light being scattered by dust on the camera lens.")));
// r_lens is currently no-op
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_lensFlare"), "0", "1", _Tr("StartupScreen", "Lens Flare"),
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_lensFlare"), "0", "1",
_Tr("StartupScreen", "Lens Flare"),
_Tr("StartupScreen", "The Sun causes lens flare.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_lensFlareDynamic"), "0", "1", _Tr("StartupScreen", "Flares for Dynamic Lights"),
_Tr("StartupScreen", "Enables lens flare for light sources other than the Sun.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_colorCorrection"), "0", "1", _Tr("StartupScreen", "Color Correction"),
_Tr("StartupScreen", "Applies cinematic color correction to make the image look better.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_depthOfField"), "0", "1", _Tr("StartupScreen", "Depth of Field"),
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_lensFlareDynamic"), "0", "1",
_Tr("StartupScreen", "Flares for Dynamic Lights"),
_Tr("StartupScreen",
"Enables lens flare for light sources other than the Sun.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_colorCorrection"), "0", "1",
_Tr("StartupScreen", "Color Correction"),
_Tr("StartupScreen",
"Applies cinematic color correction to make the image look better.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_depthOfField"), "0", "1",
_Tr("StartupScreen", "Depth of Field"),
_Tr("StartupScreen", "Blurs out-of-focus objects.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_ssao"), "0", "1", _Tr("StartupScreen", "Screen Space Ambient Occlusion"),
_Tr("StartupScreen", "Simulates soft shadows that occur between nearby objects.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_ssao"), "0", "1",
_Tr("StartupScreen", "Screen Space Ambient Occlusion"),
_Tr("StartupScreen",
"Simulates soft shadows that occur between nearby objects.")));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"), "0|0|0|0|0|0|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Medium"), "1|0|0|1|0|1|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"), "1|1|1|1|1|1|1|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Ultra"), "1|1|1|1|1|1|1|1"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"),
"0|0|0|0|0|0|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Medium"),
"1|0|0|1|0|1|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"),
"1|1|1|1|1|1|1|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Ultra"),
"1|1|1|1|1|1|1|1"));
cfg.AddRow(StartupScreenConfigComplexItemEditor(ui, cplx,
_Tr("StartupScreen", "Post-process"),
_Tr("StartupScreen", "Post-process modifies the image to make it look better and "
"more realistic.")));
cfg.AddRow(StartupScreenConfigComplexItemEditor(
ui, cplx, _Tr("StartupScreen", "Post-process"),
_Tr("StartupScreen",
"Post-process modifies the image to make it look better and " "more realistic.")));
}
cfg.AddRow(StartupScreenConfigSelectItemEditor(ui,
StartupScreenConfig(ui, "r_softParticles"), "0|1|2",
cfg.AddRow(StartupScreenConfigSelectItemEditor(
ui, StartupScreenConfig(ui, "r_softParticles"), "0|1|2",
_Tr("StartupScreen",
"Particles|"
"Low:Artifact occurs when a particle intersects other objects.|"
"Medium:Particle intersects objects smoothly.|"
"High:Particle intersects objects smoothly, and some objects casts "
"their shadow to particles.")));
"Particles|" "Low:Artifact occurs when a particle intersects other objects.|" "Medium:Particle intersects objects smoothly.|" "High:Particle intersects objects smoothly, and some objects casts " "their shadow to particles.")));
{
StartupScreenComplexConfig cplx;
// r_mapSoftShadow is currently no-op
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_dlights"), "0", "1", _Tr("StartupScreen", "Dynamic Lights"),
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_dlights"), "0", "1",
_Tr("StartupScreen", "Dynamic Lights"),
_Tr("StartupScreen",
"Gives some objects an ability to emit light to give them "
"an energy-emitting impression.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_modelShadows"), "0", "1", _Tr("StartupScreen", "Shadows"),
"Gives some objects an ability to emit light to give them " "an energy-emitting impression.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_modelShadows"), "0", "1",
_Tr("StartupScreen", "Shadows"),
_Tr("StartupScreen", "Non-static object casts a shadow.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_fogShadow"), "0", "1", _Tr("StartupScreen", "Volumetric Fog"),
_Tr("StartupScreen", "Simulates shadow being casted to the fog particles using a "
"super highly computationally demanding algorithm. ")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "r_physicalLighting"), "0", "1", _Tr("StartupScreen", "Physically Based Lighting"),
_Tr("StartupScreen", "Uses more accurate approximation techniques to decide the brightness of objects.")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_fogShadow"), "0", "1",
_Tr("StartupScreen", "Volumetric Fog"),
_Tr("StartupScreen",
"Simulates shadow being casted to the fog particles using a " "super highly computationally demanding algorithm. ")));
cplx.AddEditor(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_physicalLighting"), "0", "1",
_Tr("StartupScreen", "Physically Based Lighting"),
_Tr("StartupScreen",
"Uses more accurate approximation techniques to decide the brightness of objects.")));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"), "1|0|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Medium"), "1|1|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"), "1|1|0|1"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"), "1|0|0|0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Medium"),
"1|1|0|0"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"), "1|1|0|1"));
cfg.AddRow(StartupScreenConfigComplexItemEditor(ui, cplx,
_Tr("StartupScreen", "Direct Lights"),
_Tr("StartupScreen", "Controls how light encounting a material and atmosphere directly "
"affects its appearance.")));
cfg.AddRow(StartupScreenConfigComplexItemEditor(
ui, cplx, _Tr("StartupScreen", "Direct Lights"),
_Tr("StartupScreen",
"Controls how light encounting a material and atmosphere directly " "affects its appearance.")));
}
{
StartupScreenComplexConfig cplx;
cplx.AddEditor(StartupScreenConfigSelectItemEditor(ui,
StartupScreenConfig(ui, "r_water"), "0|1|2|3",
cplx.AddEditor(StartupScreenConfigSelectItemEditor(
ui, StartupScreenConfig(ui, "r_water"), "0|1|2|3",
_Tr("StartupScreen",
"Water Shader|"
"None:Water is rendered in the same way that normal blocks are done.|"
"Level 1:Refraction and the reflected Sun are simulated.|"
"Level 2:Waving water is simulated as well as reflection and refraction.|"
"Level 3:Reflections and refractions are rendered at the highest quality using screen-space techniques.")));
"Water Shader|" "None:Water is rendered in the same way that normal blocks are done.|" "Level 1:Refraction and the reflected Sun are simulated.|" "Level 2:Waving water is simulated as well as reflection and refraction.|" "Level 3:Reflections and refractions are rendered at the highest quality using screen-space techniques.")));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"), "0"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Med"), "1"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"), "2"));
cplx.AddPreset(StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Ultra"), "3"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Low"), "0"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Med"), "1"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "High"), "2"));
cplx.AddPreset(
StartupScreenComplexConfigPreset(_Tr("StartupScreen", "Ultra"), "3"));
cfg.AddRow(StartupScreenConfigComplexItemEditor(ui, cplx,
_Tr("StartupScreen", "Shader Effects"), _Tr("StartupScreen", "Special effects.")));
cfg.AddRow(StartupScreenConfigComplexItemEditor(
ui, cplx, _Tr("StartupScreen", "Shader Effects"),
_Tr("StartupScreen", "Special effects.")));
}
cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
cfg.Bounds = AABB2(0.f, 60.f, mainWidth, size.y - 60.f);
@ -238,12 +259,10 @@ namespace spades {
{
StartupScreenConfigView cfg(Manager);
cfg.AddRow(StartupScreenConfigSelectItemEditor(ui,
StartupScreenConfig(ui, "r_swUndersampling"), "0|1|2",
cfg.AddRow(StartupScreenConfigSelectItemEditor(
ui, StartupScreenConfig(ui, "r_swUndersampling"), "0|1|2",
_Tr("StartupScreen",
"Fast Mode:Reduces the image resolution to make the rendering faster.|"
"Off|2x|4x")));
"Fast Mode:Reduces the image resolution to make the rendering faster.|" "Off|2x|4x")));
cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
@ -251,18 +270,22 @@ namespace spades {
AddChild(cfg);
@configViewSoftware = cfg;
}
}
private void HandleHelpText(string text) {
helpView.Text = text;
private void HandleHelpText(string text) { helpView.Text = text; }
private void OnDriverOpenGL(spades::ui::UIElement @) {
r_renderer.StringValue = "gl";
LoadConfig();
}
private void OnDriverSoftware(spades::ui::UIElement @) {
r_renderer.StringValue = "sw";
LoadConfig();
}
private void OnDriverOpenGL(spades::ui::UIElement@){ r_renderer.StringValue = "gl"; LoadConfig(); }
private void OnDriverSoftware(spades::ui::UIElement@){ r_renderer.StringValue = "sw"; LoadConfig(); }
private void OnFullscreenCheck(spades::ui::UIElement@)
{ r_fullscreen.IntValue = fullscreenCheck.Toggled ? 1 : 0; }
private void OnFullscreenCheck(spades::ui::UIElement @) {
r_fullscreen.IntValue = fullscreenCheck.Toggled ? 1 : 0;
}
void LoadConfig() {
resEdit.LoadConfig();
@ -284,9 +307,7 @@ namespace spades {
}
class StartupScreenComboBoxDropdownButton : spades::ui::SimpleButton {
StartupScreenComboBoxDropdownButton(spades::ui::UIManager@ manager) {
super(manager);
}
StartupScreenComboBoxDropdownButton(spades::ui::UIManager @manager) { super(manager); }
void Render() {
SimpleButton::Render();
@ -342,14 +363,13 @@ namespace spades {
void SaveConfig() {
int w = ParseInt(widthField.Text);
int h = ParseInt(heightField.Text);
if(w < 640 or h < 480 or w > 8192 or h > 8192) return;
if (w<640 or h<480 or w> 8192 or h> 8192)
return;
r_videoWidth.IntValue = w;
r_videoHeight.IntValue = h;
}
private void ValueEditHandler(spades::ui::UIElement@) {
SaveConfig();
}
private void ValueEditHandler(spades::ui::UIElement @) { SaveConfig(); }
private void DropdownHandler(int index) {
if (index >= 0) {
@ -369,7 +389,8 @@ namespace spades {
string s = ToString(w) + "x" + ToString(h);
items.insertLast(s);
}
spades::ui::ShowDropDownList(this, items, spades::ui::DropDownListHandler(this.DropdownHandler));
spades::ui::ShowDropDownList(this, items,
spades::ui::DropDownListHandler(this.DropdownHandler));
}
void Render() {
Font @font = this.Font;
@ -392,8 +413,10 @@ namespace spades {
return "fxaa";
} else {
int v = msaaConfig.IntValue;
if(v < 2) return "0";
else return msaaConfig.StringValue;
if (v < 2)
return "0";
else
return msaaConfig.StringValue;
}
}
void SetValue(string v) {
@ -419,11 +442,9 @@ namespace spades {
return ui.helper.CheckConfigCapability("r_multisamples", v) +
ui.helper.CheckConfigCapability("r_fxaa", "0");
}
}
}
class StartupScreenAudioTab : spades::ui::UIElement, LabelAddable {
StartupScreenUI @ui;
StartupScreenHelper @helper;
@ -455,17 +476,17 @@ namespace spades {
@helpView = e;
}
AddLabel(0.f, 0.f, 24.f, _Tr("StartupScreen", "Backend"));
{
spades::ui::RadioButton e(Manager);
e.Caption = _Tr("StartupScreen", "OpenAL");
e.Bounds = AABB2(100.f, 0.f, 100.f, 24.f);
e.GroupName = "driver";
HelpHandler(helpView,
_Tr("StartupScreen", "Uses an OpenAL-capable sound card to process sound. "
"In most cases where there isn't such a sound card, software emulation is "
"used.")).Watch(e);
HelpHandler(
helpView,
_Tr("StartupScreen",
"Uses an OpenAL-capable sound card to process sound. " "In most cases where there isn't such a sound card, software emulation is " "used."))
.Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnDriverOpenAL);
AddChild(e);
@driverOpenAL = e;
@ -475,11 +496,11 @@ namespace spades {
e.Caption = _Tr("StartupScreen", "YSR");
e.Bounds = AABB2(210.f, 0.f, 100.f, 24.f);
e.GroupName = "driver";
HelpHandler(helpView,
_Tr("StartupScreen", "YSR is an experimental 3D HDR sound engine optimized "
"for OpenSpades. It features several enhanced features including "
"automatic load control, dynamics compressor, HRTF-based "
"3D audio, and high quality reverb.")).Watch(e);
HelpHandler(
helpView,
_Tr("StartupScreen",
"YSR is an experimental 3D HDR sound engine optimized " "for OpenSpades. It features several enhanced features including " "automatic load control, dynamics compressor, HRTF-based " "3D audio, and high quality reverb."))
.Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnDriverYSR);
AddChild(e);
@driverYSR = e;
@ -490,8 +511,7 @@ namespace spades {
e.Caption = _Tr("StartupScreen", "Null");
e.Bounds = AABB2(320.f, 0.f, 100.f, 24.f);
e.GroupName = "driver";
HelpHandler(helpView,
_Tr("StartupScreen", "Disables audio output.")).Watch(e);
HelpHandler(helpView, _Tr("StartupScreen", "Disables audio output.")).Watch(e);
@e.Activated = spades::ui::EventHandler(this.OnDriverNull);
AddChild(e);
@driverNull = e;
@ -500,19 +520,17 @@ namespace spades {
{
StartupScreenConfigView cfg(Manager);
cfg.AddRow(StartupScreenConfigSliderItemEditor(ui,
StartupScreenConfig(ui, "s_maxPolyphonics"), 16.0, 256.0, 8.0,
_Tr("StartupScreen", "Polyphonics"), _Tr("StartupScreen",
"Specifies how many sounds can be played simultaneously. "
"Higher value needs more processing power, so setting this too high might "
"cause an overload (especially with a software emulation)."),
cfg.AddRow(StartupScreenConfigSliderItemEditor(
ui, StartupScreenConfig(ui, "s_maxPolyphonics"), 16.0, 256.0, 8.0,
_Tr("StartupScreen", "Polyphonics"),
_Tr("StartupScreen",
"Specifies how many sounds can be played simultaneously. " "Higher value needs more processing power, so setting this too high might " "cause an overload (especially with a software emulation)."),
ConfigNumberFormatter(0, " poly")));
cfg.AddRow(StartupScreenConfigCheckItemEditor(ui,
StartupScreenConfig(ui, "s_eax"), "0", "1",
_Tr("StartupScreen", "EAX"), _Tr("StartupScreen",
"Enables extended features provided by the OpenAL driver to create "
"more ambience.")));
cfg.AddRow(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "s_eax"), "0", "1", _Tr("StartupScreen", "EAX"),
_Tr("StartupScreen",
"Enables extended features provided by the OpenAL driver to create " "more ambience.")));
cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
@ -524,31 +542,35 @@ namespace spades {
{
StartupScreenConfigView cfg(Manager);
cfg.AddRow(StartupScreenConfigSliderItemEditor(ui,
StartupScreenConfig(ui, "s_maxPolyphonics"), 16.0, 256.0, 8.0,
_Tr("StartupScreen", "Polyphonics"), _Tr("StartupScreen",
"Specifies how many sounds can be played simultaneously. "
"No matter what value is set, YSR might reduce the number of sounds "
"when an overload is detected."),
cfg.AddRow(StartupScreenConfigSliderItemEditor(
ui, StartupScreenConfig(ui, "s_maxPolyphonics"), 16.0, 256.0, 8.0,
_Tr("StartupScreen", "Polyphonics"),
_Tr("StartupScreen",
"Specifies how many sounds can be played simultaneously. " "No matter what value is set, YSR might reduce the number of sounds " "when an overload is detected."),
ConfigNumberFormatter(0, " poly")));
cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
cfg.Bounds = AABB2(0.f, 30.f, mainWidth, size.y - 30.f);
AddChild(cfg);
@configViewYSR = cfg;
}
}
private void HandleHelpText(string text) {
helpView.Text = text;
}
private void HandleHelpText(string text) { helpView.Text = text; }
private void OnDriverOpenAL(spades::ui::UIElement@){ s_audioDriver.StringValue = "openal"; LoadConfig(); }
private void OnDriverYSR(spades::ui::UIElement@){ s_audioDriver.StringValue = "ysr"; LoadConfig(); }
private void OnDriverNull(spades::ui::UIElement@){ s_audioDriver.StringValue = "null"; LoadConfig(); }
private void OnDriverOpenAL(spades::ui::UIElement @) {
s_audioDriver.StringValue = "openal";
LoadConfig();
}
private void OnDriverYSR(spades::ui::UIElement @) {
s_audioDriver.StringValue = "ysr";
LoadConfig();
}
private void OnDriverNull(spades::ui::UIElement @) {
s_audioDriver.StringValue = "null";
LoadConfig();
}
void LoadConfig() {
if (s_audioDriver.StringValue == "ysr") {
@ -564,16 +586,14 @@ namespace spades {
configViewOpenAL.Visible = false;
configViewYSR.Visible = false;
}
driverOpenAL.Enable = ui.helper.CheckConfigCapability("s_audioDriver", "openal").length == 0;
driverOpenAL.Enable =
ui.helper.CheckConfigCapability("s_audioDriver", "openal").length == 0;
driverYSR.Enable = ui.helper.CheckConfigCapability("s_audioDriver", "ysr").length == 0;
driverNull.Enable = ui.helper.CheckConfigCapability("s_audioDriver", "null").length == 0;
driverNull.Enable =
ui.helper.CheckConfigCapability("s_audioDriver", "null").length == 0;
configViewOpenAL.LoadConfig();
configViewYSR.LoadConfig();
}
}
class StartupScreenGenericTab : spades::ui::UIElement, LabelAddable {
@ -623,26 +643,30 @@ namespace spades {
}
}
void LoadConfig() {
locale.LoadConfig();
}
void LoadConfig() { locale.LoadConfig(); }
private void OnBrowseUserDirectoryPressed(spades::ui::UIElement @) {
if (helper.BrowseUserDirectory()) {
return;
}
string msg = _Tr("StartupScreen", "An unknown error has occurred while opening the config directory.");
string msg = _Tr("StartupScreen",
"An unknown error has occurred while opening the config directory.");
AlertScreen al(Parent, msg, 100.f);
al.Run();
}
private void OnResetSettingsPressed(spades::ui::UIElement @) {
string msg = _Tr("StartupScreen", "Are you sure to reset all settings? They include (but are not limited to):") + "\n" +
"- " + _Tr("StartupScreen", "All graphics/audio settings") + "\n" +
"- " + _Tr("StartupScreen", "All key bindings") + "\n" +
"- " + _Tr("StartupScreen", "Your player name") + "\n" +
"- " + _Tr("StartupScreen", "Other advanced settings only accessible through '{0}' tab and in-game commands",
string msg =
_Tr("StartupScreen",
"Are you sure to reset all settings? They include (but are not limited to):") +
"\n"
+ "- " + _Tr("StartupScreen", "All graphics/audio settings") + "\n"
+ "- " + _Tr("StartupScreen", "All key bindings") + "\n"
+ "- " + _Tr("StartupScreen", "Your player name") + "\n"
+ "- " +
_Tr("StartupScreen",
"Other advanced settings only accessible through '{0}' tab and in-game commands",
_Tr("StartupScreen", "Advanced"));
ConfirmScreen al(Parent, msg, 200.f);
@al.Closed = spades::ui::EventHandler(OnResetSettingsConfirmed);
@ -671,7 +695,6 @@ namespace spades {
// Some of default values may be infeasible for the user's system.
helper.FixConfigs();
}
}
class StartupScreenDropdownListDropdownButton : spades::ui::SimpleButton {
@ -691,7 +714,8 @@ namespace spades {
}
}
class StartupScreenLocaleEditor: spades::ui::UIElement, LabelAddable {StartupScreenUI@ ui;
class StartupScreenLocaleEditor : spades::ui::UIElement, LabelAddable {
StartupScreenUI @ui;
StartupScreenHelper @helper;
private ConfigItem core_locale("core_locale");
@ -720,7 +744,8 @@ namespace spades {
int cnt = helper.GetNumLocales();
for (int i = 0; i < cnt; i++) {
if (locale == helper.GetLocale(i)) {
name = helper.GetLocaleDescriptionNative(i) + " / " + helper.GetLocaleDescriptionEnglish(i);
name = helper.GetLocaleDescriptionNative(i) + " / " +
helper.GetLocaleDescriptionEnglish(i);
}
}
@ -731,10 +756,12 @@ namespace spades {
string[] items = {_Tr("StartupScreen", "System default")};
int cnt = helper.GetNumLocales();
for (int i = 0; i < cnt; i++) {
string s = helper.GetLocaleDescriptionNative(i) + " / " + helper.GetLocaleDescriptionEnglish(i);
string s = helper.GetLocaleDescriptionNative(i) + " / " +
helper.GetLocaleDescriptionEnglish(i);
items.insertLast(s);
}
spades::ui::ShowDropDownList(this, items, spades::ui::DropDownListHandler(this.DropdownHandler));
spades::ui::ShowDropDownList(this, items,
spades::ui::DropDownListHandler(this.DropdownHandler));
}
private void DropdownHandler(int index) {
@ -782,17 +809,10 @@ namespace spades {
@button.Activated = spades::ui::EventHandler(this.OnCopyReport);
AddChild(button);
}
}
private void OnCopyReport(spades::ui::UIElement@){
Manager.Copy(helper.GetReport());
private void OnCopyReport(spades::ui::UIElement @) { Manager.Copy(helper.GetReport()); }
}
}
class StartupScreenAdvancedTab : spades::ui::UIElement, LabelAddable {
StartupScreenUI @ui;
StartupScreenHelper @helper;
@ -819,7 +839,6 @@ namespace spades {
@helpView = e;
}
{
spades::ui::Field e(Manager);
e.Placeholder = _Tr("StartupScreen", "Filter");
@ -836,8 +855,8 @@ namespace spades {
for (uint i = 0, count = names.length; i < count; i++) {
cfg.AddRow(StartupScreenConfigFieldItemEditor(ui,
StartupScreenConfig(ui, names[i]), names[i], ""));
cfg.AddRow(StartupScreenConfigFieldItemEditor(
ui, StartupScreenConfig(ui, names[i]), names[i], ""));
}
cfg.Finalize();
@ -848,21 +867,11 @@ namespace spades {
}
}
private void HandleHelpText(string text) {
helpView.Text = text;
}
private void OnFilterChanged(spades::ui::UIElement@){
configView.Filter(filter.Text);
}
void LoadConfig() {
configView.LoadConfig();
}
private void HandleHelpText(string text) { helpView.Text = text; }
private void OnFilterChanged(spades::ui::UIElement @) { configView.Filter(filter.Text); }
void LoadConfig() { configView.LoadConfig(); }
}
}

View File

@ -63,10 +63,12 @@ namespace spades {
{
spades::ui::CheckBox button(Manager);
button.Caption = _Tr("StartupScreen", "Skip this screen next time");
button.Bounds = AABB2(360.f, 62.f, width - 380.f, 20.f); // note: this is updated later soon
button.Bounds = AABB2(360.f, 62.f, width - 380.f,
20.f); // note: this is updated later soon
AddChild(button);
@bypassStartupWindowCheck = button;
@button.Activated = spades::ui::EventHandler(this.OnBypassStartupWindowCheckChanged);
@button.Activated
= spades::ui::EventHandler(this.OnBypassStartupWindowCheckChanged);
}
{
UpdateCheckView view(Manager, ui.helper.PackageUpdateManager);
@ -133,15 +135,9 @@ namespace spades {
void LoadConfig() {
switch (cl_showStartupWindow.IntValue) {
case -1:
bypassStartupWindowCheck.Toggled = false;
break;
case 0:
bypassStartupWindowCheck.Toggled = true;
break;
default:
bypassStartupWindowCheck.Toggled = false;
break;
case -1: bypassStartupWindowCheck.Toggled = false; break;
case 0: bypassStartupWindowCheck.Toggled = true; break;
default: bypassStartupWindowCheck.Toggled = false; break;
}
this.graphicsTab.LoadConfig();
@ -183,15 +179,15 @@ namespace spades {
return;
}
string msg = _Tr("StartupScreen", "An unknown error has occurred while opening the update info website.");
string msg =
_Tr("StartupScreen",
"An unknown error has occurred while opening the update info website.");
msg += "\n\n" + ui.helper.PackageUpdateManager.LatestVersionInfoPageURL;
AlertScreen al(Parent, msg, 100.f);
al.Run();
}
private void OnQuitPressed(spades::ui::UIElement@ sender) {
ui.shouldExit = true;
}
private void OnQuitPressed(spades::ui::UIElement @sender) { ui.shouldExit = true; }
private void OnSetupPressed(spades::ui::UIElement @sender) {
PreferenceView al(this, PreferenceViewOptions(), ui.fontManager);
@ -203,9 +199,7 @@ namespace spades {
ui.shouldExit = true; // we have to exit from the startup screen to start the game
}
private void OnStartPressed(spades::ui::UIElement@ sender) {
Start();
}
private void OnStartPressed(spades::ui::UIElement @sender) { Start(); }
void HotKey(string key) {
if (IsEnabled and key == "Enter") {
@ -217,10 +211,7 @@ namespace spades {
}
}
void Render() {
UIElement::Render();
}
void Render() { UIElement::Render(); }
}
}

View File

@ -22,7 +22,6 @@
namespace spades {
class StartupScreenUI {
private Renderer @renderer;
private AudioDevice @audioDevice;
@ -35,7 +34,8 @@ namespace spades {
bool shouldExit = false;
StartupScreenUI(Renderer@ renderer, AudioDevice@ audioDevice, FontManager@ fontManager, StartupScreenHelper@ helper) {
StartupScreenUI(Renderer @renderer, AudioDevice @audioDevice, FontManager @fontManager,
StartupScreenHelper @helper) {
@this.renderer = renderer;
@this.audioDevice = audioDevice;
@this.fontManager = fontManager;
@ -58,7 +58,8 @@ namespace spades {
// Delete StartupScreenMainMenu
@manager.RootElement.GetChildren()[0].Parent = null;
// Reload entire the startup screen while preserving the state as much as possible
// Reload entire the startup screen while preserving the state as much
// as possible
auto @state = mainMenu.GetState();
Init();
mainMenu.SetState(state);
@ -69,33 +70,21 @@ namespace spades {
manager.KeyPanic();
}
void MouseEvent(float x, float y) {
manager.MouseEvent(x, y);
}
void MouseEvent(float x, float y) { manager.MouseEvent(x, y); }
void WheelEvent(float x, float y) {
manager.WheelEvent(x, y);
}
void WheelEvent(float x, float y) { manager.WheelEvent(x, y); }
void KeyEvent(string key, bool down) {
manager.KeyEvent(key, down);
}
void KeyEvent(string key, bool down) { manager.KeyEvent(key, down); }
void TextInputEvent(string text) {
manager.TextInputEvent(text);
}
void TextInputEvent(string text) { manager.TextInputEvent(text); }
void TextEditingEvent(string text, int start, int len) {
manager.TextEditingEvent(text, start, len);
}
bool AcceptsTextInput() {
return manager.AcceptsTextInput;
}
bool AcceptsTextInput() { return manager.AcceptsTextInput; }
AABB2 GetTextInputRect() {
return manager.TextInputRect;
}
AABB2 GetTextInputRect() { return manager.TextInputRect; }
void RunFrame(float dt) {
renderer.ColorNP = Vector4(0.f, 0.f, 0.f, 1.f);
@ -114,13 +103,9 @@ namespace spades {
renderer.Flip();
}
void Closing() {
shouldExit = true;
}
void Closing() { shouldExit = true; }
bool WantsToBeClosed() {
return shouldExit;
}
bool WantsToBeClosed() { return shouldExit; }
}
StartupScreenUI @CreateStartupScreenUI(Renderer @renderer, AudioDevice @audioDevice,

View File

@ -31,7 +31,8 @@ namespace spades {
private ConfigItem cl_checkForUpdates("cl_checkForUpdates");
UpdateCheckView(spades::ui::UIManager@ manager, PackageUpdateManager@ packageUpdateManager) {
UpdateCheckView(spades::ui::UIManager @manager,
PackageUpdateManager @packageUpdateManager) {
super(manager);
@this.packageUpdateManager = packageUpdateManager;
@ -56,10 +57,10 @@ namespace spades {
float viewWidth = Size.x;
float viewHeight = Size.y;
enableCheckButton.Bounds = AABB2(
viewWidth - 160.f, (viewHeight - 30.f) * 0.5f, 150.f, 30.f);
showDetailsButton.Bounds = AABB2(
viewWidth - 160.f, (viewHeight - 30.f) * 0.5f, 150.f, 30.f);
enableCheckButton.Bounds =
AABB2(viewWidth - 160.f, (viewHeight - 30.f) * 0.5f, 150.f, 30.f);
showDetailsButton.Bounds =
AABB2(viewWidth - 160.f, (viewHeight - 30.f) * 0.5f, 150.f, 30.f);
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;
@ -89,8 +90,8 @@ namespace spades {
float phase = fraction(Manager.Time) * 80.0f;
renderer.ColorNP = Vector4(0.15f, 0.15f, 0.15f, 1.0f);
for (float x = phase - 160.0f; x < size.x + 160.0f; x += 80.0f) {
renderer.DrawImage(white, Vector2(x, pos.y), Vector2(x + 40.f, pos.y), Vector2(x - 20.f, pos.y + size.y),
AABB2(0, 0, 0, 0));
renderer.DrawImage(white, Vector2(x, pos.y), Vector2(x + 40.f, pos.y),
Vector2(x - 20.f, pos.y + size.y), AABB2(0, 0, 0, 0));
}
}
@ -99,10 +100,13 @@ namespace spades {
switch (state) {
case PackageUpdateManagerReadyState::Loaded:
if (packageUpdateManager.UpdateAvailable) {
text = _Tr("UpdateCheck", "Version {0} is available! (You currently have {1})",
packageUpdateManager.LatestVersionInfo.Text, packageUpdateManager.CurrentVersionInfo.Text);
text =
_Tr("UpdateCheck", "Version {0} is available! (You currently have {1})",
packageUpdateManager.LatestVersionInfo.Text,
packageUpdateManager.CurrentVersionInfo.Text);
} else {
text = _Tr("UpdateCheck", "You're using the latest version of OpenSpades. ({0})",
text = _Tr("UpdateCheck",
"You're using the latest version of OpenSpades. ({0})",
packageUpdateManager.CurrentVersionInfo.Text);
}
break;
@ -146,8 +150,6 @@ namespace spades {
cl_checkForUpdates.IntValue = 1;
packageUpdateManager.CheckForUpdate();
}
private void OnShowDetailsPressed(spades::ui::UIElement@) {
OpenUpdateInfoURL(this);
}
private void OnShowDetailsPressed(spades::ui::UIElement @) { OpenUpdateInfoURL(this); }
}
}

View File

@ -51,13 +51,9 @@ namespace spades {
@repeatTimer.Tick = TimerTickEventHandler(this.RepeatTimerFired);
}
void PlayMouseEnterSound() {
Manager.PlaySound("Sounds/Feedback/Limbo/Hover.opus");
}
void PlayMouseEnterSound() { Manager.PlaySound("Sounds/Feedback/Limbo/Hover.opus"); }
void PlayActivateSound() {
Manager.PlaySound("Sounds/Feedback/Limbo/Select.opus");
}
void PlayActivateSound() { Manager.PlaySound("Sounds/Feedback/Limbo/Select.opus"); }
void OnActivated() {
if (Activated !is null) {
@ -165,22 +161,17 @@ namespace spades {
}
UIElement::KeyDown(key);
}
void KeyUp(string key) {
UIElement::KeyUp(key);
}
void KeyUp(string key) { UIElement::KeyUp(key); }
void HotKey(string key) {
if (key == ActivateHotKey) {
OnActivated();
}
}
}
class SimpleButton : spades::ui::Button {
SimpleButton(spades::ui::UIManager@ manager){
super(manager);
}
SimpleButton(spades::ui::UIManager @manager) { super(manager); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;
@ -207,13 +198,14 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x, pos.y + size.y - 1.f, size.x, 1.f));
Vector2 txtSize = Font.Measure(Caption);
float margin = 4.f;
Font.DrawShadow(Caption, pos + Vector2(margin, margin) +
(size - txtSize - Vector2(margin * 2.f, margin * 2.f)) * Alignment,
Font.DrawShadow(Caption,
pos + Vector2(margin, margin) +
(size - txtSize - Vector2(margin * 2.f, margin * 2.f)) *
Alignment,
1.f, Vector4(1, 1, 1, 1), Vector4(0, 0, 0, 0.4f));
}
}
class CheckBox : spades::ui::Button {
CheckBox(spades::ui::UIManager @manager) {
super(manager);
@ -233,7 +225,8 @@ namespace spades {
}
renderer.DrawImage(img, AABB2(pos.x, pos.y, size.x, size.y));
Vector2 txtSize = Font.Measure(Caption);
Font.DrawShadow(Caption, pos + (size - txtSize) * Vector2(0.f, 0.5f) + Vector2(16.f, 0.f),
Font.DrawShadow(Caption,
pos + (size - txtSize) * Vector2(0.f, 0.5f) + Vector2(16.f, 0.f),
1.f, Vector4(1, 1, 1, 1), Vector4(0, 0, 0, 0.2f));
@img = renderer.RegisterImage("Gfx/UI/CheckBox.png");
@ -241,11 +234,9 @@ namespace spades {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, Toggled ? .9f : 0.6f);
renderer.DrawImage(img, AABB2(pos.x, pos.y + (size.y - 16.f) * 0.5f, 16.f, 16.f),
AABB2(Toggled ? 16.f : 0.f, 0.f, 16.f, 16.f));
}
}
class RadioButton : spades::ui::Button {
string GroupName;
@ -261,7 +252,8 @@ namespace spades {
UIElement @[] @children = this.Parent.GetChildren();
for (uint i = 0, count = children.length; i < children.length; i++) {
RadioButton @btn = cast<RadioButton>(children[i]);
if(btn is this) continue;
if (btn is this)
continue;
if (btn !is null) {
if (GroupName == btn.GroupName) {
btn.Toggled = false;
@ -292,7 +284,8 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x, pos.y, size.x, size.y));
if (!this.Enable) {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.03f);
} if((Pressed && Hover) || Toggled) {
}
if ((Pressed && Hover) || Toggled) {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.1f);
} else if (Hover) {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.07f);
@ -309,10 +302,9 @@ namespace spades {
if (Toggled) {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.6f);
renderer.DrawImage(img, AABB2(pos.x + 4.f, pos.y + (size.y - 8.f) * 0.5f, 8.f, 8.f));
renderer.DrawImage(img,
AABB2(pos.x + 4.f, pos.y + (size.y - 8.f) * 0.5f, 8.f, 8.f));
}
}
}
@ -354,15 +346,14 @@ namespace spades {
txtPos = pos + (size - txtSize) * Alignment;
if (IsEnabled) {
font.DrawShadow(text, txtPos, 1.f,
Vector4(1.f, 1.f, 1.f, 1.f), Vector4(0.f, 0.f, 0.f, 0.4f));
font.DrawShadow(text, txtPos, 1.f, Vector4(1.f, 1.f, 1.f, 1.f),
Vector4(0.f, 0.f, 0.f, 0.4f));
} else {
font.DrawShadow(text, txtPos, 1.f,
Vector4(1.f, 1.f, 1.f, 0.5f), Vector4(0.f, 0.f, 0.f, 0.1f));
font.DrawShadow(text, txtPos, 1.f, Vector4(1.f, 1.f, 1.f, 0.5f),
Vector4(0.f, 0.f, 0.f, 0.1f));
}
}
}
}
}
}

View File

@ -23,9 +23,7 @@ namespace spades {
class DropDownViewItem : spades::ui::Button {
int index;
DropDownViewItem(spades::ui::UIManager@ manager){
super(manager);
}
DropDownViewItem(spades::ui::UIManager @manager) { super(manager); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;
@ -47,8 +45,9 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x + size.x - 1.f, pos.y, 1.f, size.y));
renderer.DrawImage(img, AABB2(pos.x, pos.y + size.y - 1.f, size.x, 1.f));
Vector2 txtSize = Font.Measure(Caption);
Font.DrawShadow(Caption, pos + (size - txtSize) * Vector2(0.f, 0.5f) +
Vector2(4.f, 0.f), 1.f, Vector4(1,1,1,1), Vector4(0,0,0,0.4f));
Font.DrawShadow(Caption,
pos + (size - txtSize) * Vector2(0.f, 0.5f) + Vector2(4.f, 0.f),
1.f, Vector4(1, 1, 1, 1), Vector4(0, 0, 0, 0.4f));
}
}
@ -110,21 +109,16 @@ namespace spades {
DropDownListHandler @handler;
DropDownBackground @bg;
DropDownView(UIManager@ manager,
DropDownListHandler@ handler,
string[]@ items) {
DropDownView(UIManager @manager, DropDownListHandler @handler, string[] @items) {
super(manager);
@this.handler = handler;
DropDownViewModel model(manager, items);
@model.Handler = DropDownListHandler(this.ItemActivated);
@this.Model = model;
}
void Destroy() {
bg.Destroy();
}
void Destroy() { bg.Destroy(); }
private void ItemActivated(int index) {
Destroy();
@ -134,8 +128,8 @@ namespace spades {
funcdef void DropDownListHandler(int index);
void ShowDropDownList(UIManager@ manager, float x, float y, float width,
string[]@ items, DropDownListHandler@ handler) {
void ShowDropDownList(UIManager @manager, float x, float y, float width, string[] @items,
DropDownListHandler @handler) {
DropDownView view(manager, handler, items);
DropDownBackground bg(manager, view);
@ -146,7 +140,8 @@ namespace spades {
float maxHeight = size.y - y;
float height = 24.f * float(items.length);
if(height > maxHeight) height = maxHeight;
if (height > maxHeight)
height = maxHeight;
bg.Bounds = AABB2(0.f, 0.f, size.x, size.y);
view.Bounds = AABB2(x, y, width, height);
@ -164,11 +159,9 @@ namespace spades {
root.AddChild(bg);
bg.AddChild(view);
}
void ShowDropDownList(UIElement@ e,
string[]@ items, DropDownListHandler@ handler) {
void ShowDropDownList(UIElement @e, string[] @items, DropDownListHandler @handler) {
AABB2 b = e.ScreenBounds;
ShowDropDownList(e.Manager, b.min.x, b.max.y, b.max.x - b.min.x,
items, handler);
ShowDropDownList(e.Manager, b.min.x, b.max.y, b.max.x - b.min.x, items, handler);
}
}
}

View File

@ -54,7 +54,9 @@ namespace spades {
super(manager);
IsMouseInteractive = true;
AcceptsFocus = true;
@this.Cursor = Cursor(Manager, manager.Renderer.RegisterImage("Gfx/UI/IBeam.png"), Vector2(16.f, 16.f));
@this.Cursor
= Cursor(Manager, manager.Renderer.RegisterImage("Gfx/UI/IBeam.png"),
Vector2(16.f, 16.f));
}
string Text {
@ -90,40 +92,29 @@ namespace spades {
int SelectionStart {
get final { return Min(MarkPosition, CursorPosition); }
set {
Select(value, SelectionEnd - value);
}
set { Select(value, SelectionEnd - value); }
}
int SelectionEnd {
get final {
return Max(MarkPosition, CursorPosition);
}
set {
Select(SelectionStart, value - SelectionStart);
}
get final { return Max(MarkPosition, CursorPosition); }
set { Select(SelectionStart, value - SelectionStart); }
}
int SelectionLength {
get final {
return SelectionEnd - SelectionStart;
}
set {
Select(SelectionStart, value);
}
get final { return SelectionEnd - SelectionStart; }
set { Select(SelectionStart, value); }
}
string SelectedText {
get final {
return Text.substr(SelectionStart, SelectionLength);
}
get final { return Text.substr(SelectionStart, SelectionLength); }
set {
if (!CheckCharType(value)) {
return;
}
FieldCommand cmd;
cmd.oldString = this.SelectedText;
if(cmd.oldString == value) return; // no change
if (cmd.oldString == value)
return; // no change
cmd.newString = value;
cmd.index = this.SelectionStart;
RunFieldCommand(cmd, true, true);
@ -142,7 +133,6 @@ namespace spades {
historyPos += 1;
// limit history length
}
}
private void UndoFieldCommand(FieldCommand @cmd, bool autoSelect) {
@ -150,7 +140,6 @@ namespace spades {
text.substr(cmd.index + cmd.newString.length);
if (autoSelect)
Select(cmd.index, cmd.oldString.length);
}
private void SetHistoryPos(int index) {
@ -168,13 +157,15 @@ namespace spades {
}
bool Undo() {
if(historyPos == 0) return false;
if (historyPos == 0)
return false;
SetHistoryPos(historyPos - 1);
return true;
}
bool Redo() {
if(historyPos >= int(history.length)) return false;
if (historyPos >= int(history.length))
return false;
SetHistoryPos(historyPos + 1);
return true;
}
@ -188,14 +179,15 @@ namespace spades {
Font @font = this.Font;
float width = font.Measure(text.substr(0, cursorPos)).x;
float fontHeight = font.Measure("A").y;
return AABB2(textPos.x + width, textPos.y,
siz.x - textPos.x - width, fontHeight);
return AABB2(textPos.x + width, textPos.y, siz.x - textPos.x - width,
fontHeight);
}
}
private int PointToCharIndex(float x) {
x -= TextOrigin.x;
if(x < 0.f) return 0;
if (x < 0.f)
return 0;
x /= TextScale;
string text = Text;
int len = text.length;
@ -221,22 +213,16 @@ namespace spades {
}
return len;
}
int PointToCharIndex(Vector2 pt) {
return PointToCharIndex(pt.x);
}
int PointToCharIndex(Vector2 pt) { return PointToCharIndex(pt.x); }
int ClampCursorPosition(int pos) {
return Clamp(pos, 0, Text.length);
}
int ClampCursorPosition(int pos) { return Clamp(pos, 0, Text.length); }
void Select(int start, int length = 0) {
MarkPosition = ClampCursorPosition(start);
CursorPosition = ClampCursorPosition(start + length);
}
void SelectAll() {
Select(0, Text.length);
}
void SelectAll() { Select(0, Text.length); }
void BackSpace() {
if (SelectionLength > 0) {
@ -313,8 +299,7 @@ namespace spades {
}
return;
}
if(Manager.IsControlPressed or
Manager.IsMetaPressed /* for OSX; Cmd + [a-z] */) {
if (Manager.IsControlPressed or Manager.IsMetaPressed /* for OSX; Cmd + [a-z] */) {
if (key == "A") {
SelectAll();
return;
@ -328,9 +313,11 @@ namespace spades {
OnChanged();
} else if (key == "Z") {
if (Manager.IsShiftPressed) {
if(Redo()) OnChanged();
if (Redo())
OnChanged();
} else {
if(Undo()) OnChanged();
if (Undo())
OnChanged();
}
} else if (key == "W") {
if (Redo()) {
@ -340,12 +327,10 @@ namespace spades {
}
Manager.ProcessHotKey(key);
}
void KeyUp(string key) {
}
void KeyUp(string key) {}
void KeyPress(string text) {
if(!(Manager.IsControlPressed or
Manager.IsMetaPressed)) {
if (!(Manager.IsControlPressed or Manager.IsMetaPressed)) {
Insert(text);
}
}
@ -421,7 +406,8 @@ namespace spades {
this.SelectedText = "";
markStart = SelectionStart + editStart;
markEnd = markStart + editLen;
text = text.substr(0, SelectionStart) + composition + text.substr(SelectionStart);
text =
text.substr(0, SelectionStart) + composition + text.substr(SelectionStart);
}
if (text.length == 0) {
@ -494,7 +480,8 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x, pos.y, size.x, 1.f));
renderer.DrawImage(img, AABB2(pos.x, pos.y + size.y - 1.f, size.x, 1.f));
renderer.DrawImage(img, AABB2(pos.x, pos.y + 1.f, 1.f, size.y - 2.f));
renderer.DrawImage(img, AABB2(pos.x + size.x - 1.f, pos.y + 1.f, 1.f, size.y - 2.f));
renderer.DrawImage(img,
AABB2(pos.x + size.x - 1.f, pos.y + 1.f, 1.f, size.y - 2.f));
FieldBase::Render();
}

View File

@ -30,9 +30,7 @@ namespace spades {
Vector2 Alignment = Vector2(0.f, 0.0f);
float TextScale = 1.f;
Label(UIManager@ manager) {
super(manager);
}
Label(UIManager @manager) { super(manager); }
void Render() {
Renderer @renderer = Manager.Renderer;
Vector2 pos = ScreenPosition;

View File

@ -24,7 +24,9 @@ namespace spades {
namespace ui {
class ListViewModel {
int NumRows { get { return 0; } }
int NumRows {
get { return 0; }
}
UIElement @CreateElement(int row) { return null; }
void RecycleElement(UIElement @elem) {}
}
@ -49,20 +51,14 @@ namespace spades {
@model = ListViewModel();
}
private void OnScrolled(UIElement@ sender) {
Layout();
}
private void OnScrolled(UIElement @sender) { Layout(); }
int NumVisibleRows {
get final {
return int(floor(Size.y / RowHeight));
}
get final { return int(floor(Size.y / RowHeight)); }
}
int MaxTopRowIndex {
get final {
return Max(0, model.NumRows - NumVisibleRows);
}
get final { return Max(0, model.NumRows - NumVisibleRows); }
}
int TopRowIndex {
@ -139,14 +135,10 @@ namespace spades {
}
float ItemWidth {
get {
return Size.x - ScrollBarWidth;
}
get { return Size.x - ScrollBarWidth; }
}
void MouseWheel(float delta) {
scrollBar.ScrollBy(delta);
}
void MouseWheel(float delta) { scrollBar.ScrollBy(delta); }
void Reload() {
UnloadAll();
@ -175,20 +167,13 @@ namespace spades {
}
}
void ScrollToTop() {
scrollBar.ScrollTo(0.0);
}
void ScrollToTop() { scrollBar.ScrollTo(0.0); }
void ScrollToEnd() {
scrollBar.ScrollTo(scrollBar.MaxValue);
void ScrollToEnd() { scrollBar.ScrollTo(scrollBar.MaxValue); }
}
}
class ListView : ListViewBase {
ListView(UIManager@ manager) {
super(manager);
}
ListView(UIManager @manager) { super(manager); }
void Render() {
// render background
Renderer @renderer = Manager.Renderer;
@ -202,7 +187,8 @@ namespace spades {
renderer.DrawImage(img, AABB2(pos.x, pos.y, size.x, 1.f));
renderer.DrawImage(img, AABB2(pos.x, pos.y + size.y - 1.f, size.x, 1.f));
renderer.DrawImage(img, AABB2(pos.x, pos.y + 1.f, 1.f, size.y - 2.f));
renderer.DrawImage(img, AABB2(pos.x + size.x - 1.f, pos.y + 1.f, 1.f, size.y - 2.f));
renderer.DrawImage(img,
AABB2(pos.x + size.x - 1.f, pos.y + 1.f, 1.f, size.y - 2.f));
ListViewBase::Render();
}

View File

@ -23,10 +23,7 @@
namespace spades {
namespace ui {
enum ScrollBarOrientation {
Horizontal,
Vertical
}
enum ScrollBarOrientation { Horizontal, Vertical }
class ScrollBarBase : UIElement {
double MinValue = 0.0;
@ -36,13 +33,9 @@ namespace spades {
double LargeChange = 20.0;
EventHandler @Changed;
ScrollBarBase(UIManager@ manager) {
super(manager);
}
ScrollBarBase(UIManager @manager) { super(manager); }
void ScrollBy(double delta) {
ScrollTo(Value + delta);
}
void ScrollBy(double delta) { ScrollTo(Value + delta); }
void ScrollTo(double val) {
val = Clamp(val, MinValue, MaxValue);
@ -68,8 +61,6 @@ namespace spades {
}
}
}
}
class ScrollBarTrackBar : UIElement {
@ -136,9 +127,11 @@ namespace spades {
Image @img = renderer.RegisterImage("Gfx/White.tga");
if (scrollBar.Orientation == spades::ui::ScrollBarOrientation::Horizontal) {
pos.y += 4.f; size.y -= 8.f;
pos.y += 4.f;
size.y -= 8.f;
} else {
pos.x += 4.f; size.x -= 8.f;
pos.x += 4.f;
size.x -= 8.f;
}
if (dragging) {
@ -217,23 +210,23 @@ namespace spades {
if (scrollBar.Orientation == spades::ui::ScrollBarOrientation::Horizontal) {
if (up) {
r.DrawImage(image,
Vector2(pos.x + siz, pos.y - siz), Vector2(pos.x + siz, pos.y + siz), Vector2(pos.x - siz, pos.y - siz),
srcRect);
r.DrawImage(image, Vector2(pos.x + siz, pos.y - siz),
Vector2(pos.x + siz, pos.y + siz),
Vector2(pos.x - siz, pos.y - siz), srcRect);
} else {
r.DrawImage(image,
Vector2(pos.x - siz, pos.y + siz), Vector2(pos.x - siz, pos.y - siz), Vector2(pos.x + siz, pos.y + siz),
srcRect);
r.DrawImage(image, Vector2(pos.x - siz, pos.y + siz),
Vector2(pos.x - siz, pos.y - siz),
Vector2(pos.x + siz, pos.y + siz), srcRect);
}
} else {
if (up) {
r.DrawImage(image,
Vector2(pos.x + siz, pos.y + siz), Vector2(pos.x - siz, pos.y + siz), Vector2(pos.x + siz, pos.y - siz),
srcRect);
r.DrawImage(image, Vector2(pos.x + siz, pos.y + siz),
Vector2(pos.x - siz, pos.y + siz),
Vector2(pos.x + siz, pos.y - siz), srcRect);
} else {
r.DrawImage(image,
Vector2(pos.x - siz, pos.y - siz), Vector2(pos.x + siz, pos.y - siz), Vector2(pos.x - siz, pos.y + siz),
srcRect);
r.DrawImage(image, Vector2(pos.x - siz, pos.y - siz),
Vector2(pos.x + siz, pos.y - siz),
Vector2(pos.x - siz, pos.y + siz), srcRect);
}
}
}
@ -270,18 +263,10 @@ namespace spades {
AddChild(button2);
}
private void LargeDown(UIElement@ e) {
ScrollBy(-LargeChange);
}
private void LargeUp(UIElement@ e) {
ScrollBy(LargeChange);
}
private void SmallDown(UIElement@ e) {
ScrollBy(-SmallChange);
}
private void SmallUp(UIElement@ e) {
ScrollBy(SmallChange);
}
private void LargeDown(UIElement @e) { ScrollBy(-LargeChange); }
private void LargeUp(UIElement @e) { ScrollBy(LargeChange); }
private void SmallDown(UIElement @e) { ScrollBy(-SmallChange); }
private void SmallUp(UIElement @e) { ScrollBy(SmallChange); }
void OnChanged() {
Layout();
@ -297,13 +282,15 @@ namespace spades {
button1.Bounds = AABB2(0.f, 0.f, ButtonSize, size.y);
button2.Bounds = AABB2(size.x - ButtonSize, 0.f, ButtonSize, size.y);
fill1.Bounds = AABB2(ButtonSize, 0.f, tPos - ButtonSize, size.y);
fill2.Bounds = AABB2(tPos + tLen, 0.f, size.x - ButtonSize - tPos - tLen, size.y);
fill2.Bounds =
AABB2(tPos + tLen, 0.f, size.x - ButtonSize - tPos - tLen, size.y);
trackBar.Bounds = AABB2(tPos, 0.f, tLen, size.y);
} else {
button1.Bounds = AABB2(0.f, 0.f, size.x, ButtonSize);
button2.Bounds = AABB2(0.f, size.y - ButtonSize, size.x, ButtonSize);
fill1.Bounds = AABB2(0.f, ButtonSize, size.x, tPos - ButtonSize);
fill2.Bounds = AABB2(0.f, tPos + tLen, size.x, size.y - ButtonSize - tPos - tLen);
fill2.Bounds =
AABB2(0.f, tPos + tLen, size.x, size.y - ButtonSize - tPos - tLen);
trackBar.Bounds = AABB2(0.f, tPos, size.x, tLen);
}
}
@ -324,22 +311,19 @@ namespace spades {
}
float TrackBarAreaLength {
get {
return Length - ButtonSize - ButtonSize;
}
get { return Length - ButtonSize - ButtonSize; }
}
float TrackBarLength {
get {
return Max(TrackBarAreaLength *
(LargeChange / (MaxValue - MinValue + LargeChange)), 40.f);
(LargeChange / (MaxValue - MinValue + LargeChange)),
40.f);
}
}
float TrackBarMovementRange {
get {
return TrackBarAreaLength - TrackBarLength;
}
get { return TrackBarAreaLength - TrackBarLength; }
}
float TrackBarPosition {
@ -347,7 +331,9 @@ namespace spades {
if (MaxValue == MinValue) {
return ButtonSize;
}
return float((Value - MinValue) / (MaxValue - MinValue) * TrackBarMovementRange) + ButtonSize;
return float((Value - MinValue) / (MaxValue - MinValue) *
TrackBarMovementRange) +
ButtonSize;
}
}

View File

@ -36,9 +36,7 @@ namespace spades {
IsMouseInteractive = true;
}
private float GetCursorPos(Vector2 pos) {
return pos.x + Position.x;
}
private float GetCursorPos(Vector2 pos) { return pos.x + Position.x; }
void MouseDown(MouseButton button, Vector2 clientPosition) {
if (button != spades::ui::MouseButton::LeftMouseButton) {
@ -83,14 +81,11 @@ namespace spades {
} else {
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.3f);
}
renderer.DrawImage(img,
AABB2(pos.x + size.x * 0.5f - 3.f, pos.y,
6.f, size.y));
renderer.DrawImage(img, AABB2(pos.x + size.x * 0.5f - 3.f, pos.y, 6.f, size.y));
renderer.ColorNP = Vector4(0.f, 0.f, 0.f, 0.6f);
renderer.DrawImage(img,
AABB2(pos.x + size.x * 0.5f - 2.f, pos.y + 1.f,
4.f, size.y - 2.f));
renderer.DrawImage(
img, AABB2(pos.x + size.x * 0.5f - 2.f, pos.y + 1.f, 4.f, size.y - 2.f));
}
}
@ -112,12 +107,9 @@ namespace spades {
@fill2 = ScrollBarFill(this, true);
@fill2.Activated = EventHandler(this.LargeUp);
AddChild(fill2);
}
private void LargeDown(UIElement@ e) {
ScrollBy(-LargeChange);
}
private void LargeDown(UIElement @e) { ScrollBy(-LargeChange); }
private void LargeUp(UIElement @e) {
ScrollBy(LargeChange);
} /*
@ -159,26 +151,21 @@ namespace spades {
}
float TrackBarAreaLength {
get {
return Length;
}
get { return Length; }
}
float TrackBarLength {
get {
return 16.f;
}
get { return 16.f; }
}
float TrackBarMovementRange {
get {
return TrackBarAreaLength - TrackBarLength;
}
get { return TrackBarAreaLength - TrackBarLength; }
}
float TrackBarPosition {
get {
return float((Value - MinValue) / (MaxValue - MinValue) * TrackBarMovementRange);
return float((Value - MinValue) / (MaxValue - MinValue) *
TrackBarMovementRange);
}
}
@ -191,14 +178,11 @@ namespace spades {
Image @img = renderer.RegisterImage("Gfx/White.tga");
renderer.ColorNP = Vector4(1.f, 1.f, 1.f, 0.1f);
renderer.DrawImage(img,
AABB2(pos.x, pos.y + size.y * 0.5f - 3.f,
size.x, 6.f));
renderer.DrawImage(img, AABB2(pos.x, pos.y + size.y * 0.5f - 3.f, size.x, 6.f));
renderer.ColorNP = Vector4(0.f, 0.f, 0.f, 0.2f);
renderer.DrawImage(img,
AABB2(pos.x + 1.f, pos.y + size.y * 0.5f - 2.f,
size.x - 2.f, 4.f));
renderer.DrawImage(
img, AABB2(pos.x + 1.f, pos.y + size.y * 0.5f - 2.f, size.x - 2.f, 4.f));
ScrollBarBase::Render();
}

View File

@ -64,9 +64,7 @@ namespace spades {
EventHandler @Changed;
SimpleTabStrip(UIManager@ manager) {
super(manager);
}
SimpleTabStrip(UIManager @manager) { super(manager); }
private void OnChanged() {
if (Changed !is null) {
@ -95,7 +93,6 @@ namespace spades {
@item.Activated = EventHandler(this.OnItemActivated);
this.AddChild(item);
}
void Render() {
@ -108,7 +105,6 @@ namespace spades {
renderer.ColorNP = Vector4(0.9f, 0.9f, 0.9f, 1.0f);
renderer.DrawImage(img, AABB2(pos.x, pos.y + 24.f, size.x, 1.f));
}
}
}

View File

@ -28,15 +28,11 @@ namespace spades {
int CursorPosition = 0;
int SelectionStart {
get final {
return Min(MarkPosition, CursorPosition);
}
get final { return Min(MarkPosition, CursorPosition); }
}
int SelectionEnd {
get final {
return Max(MarkPosition, CursorPosition);
}
get final { return Max(MarkPosition, CursorPosition); }
}
}
@ -47,7 +43,8 @@ namespace spades {
private TextViewerSelectionState @selection;
TextViewerItemUI(UIManager@ manager, TextViewerItem@ item, TextViewerSelectionState@ selection) {
TextViewerItemUI(UIManager @manager, TextViewerItem @item,
TextViewerSelectionState @selection) {
super(manager);
text = item.Text;
@ -154,7 +151,8 @@ namespace spades {
}
continue;
} else {
lines.insertLast(TextViewerItem(text.substr(startPos, pos - startPos), color, contentLength));
lines.insertLast(TextViewerItem(text.substr(startPos, pos - startPos),
color, contentLength));
contentLength += pos - startPos;
startPos = pos;
while (startPos < len && text[startPos] == 0x20) {
@ -167,16 +165,17 @@ namespace spades {
} else {
pos = nextPos;
if (nextPos >= len) {
lines.insertLast(TextViewerItem(text.substr(startPos, nextPos - startPos), color, contentLength));
lines.insertLast(TextViewerItem(
text.substr(startPos, nextPos - startPos), color, contentLength));
contentLength += nextPos - startPos + 1;
break;
}
}
}
}
TextViewerModel(UIManager@ manager, string text, Font@ font, float width, TextViewerSelectionState@ selection) {
TextViewerModel(UIManager @manager, string text, Font @font, float width,
TextViewerSelectionState @selection) {
@this.manager = manager;
@this.font = font;
this.width = width;
@ -186,7 +185,9 @@ namespace spades {
AddLine(lines[i], Vector4(1.f, 1.f, 1.f, 1.f));
}
int NumRows { get { return int(lines.length); } }
int NumRows {
get { return int(lines.length); }
}
UIElement @CreateElement(int row) {
return TextViewerItemUI(manager, lines[row], selection);
@ -207,10 +208,15 @@ namespace spades {
@selection.FocusElement = this;
AcceptsFocus = true;
IsMouseInteractive = true;
@this.Cursor = Cursor(Manager, manager.Renderer.RegisterImage("Gfx/UI/IBeam.png"), Vector2(16.f, 16.f));
@this.Cursor
= Cursor(Manager, manager.Renderer.RegisterImage("Gfx/UI/IBeam.png"),
Vector2(16.f, 16.f));
}
/** Sets the displayed text. Ensure TextViewer.Font is not null before setting this proeprty. */
/**
* Sets the displayed text. Ensure TextViewer.Font is not null before
* setting this proeprty.
*/
string Text {
get final { return text; }
set {
@ -267,7 +273,8 @@ namespace spades {
if (Manager.IsShiftPressed) {
MouseMove(clientPosition);
} else {
selection.MarkPosition = selection.CursorPosition = PointToCharIndex(clientPosition);
selection.MarkPosition = selection.CursorPosition =
PointToCharIndex(clientPosition);
}
}
@ -285,8 +292,7 @@ namespace spades {
}
void KeyDown(string key) {
if(Manager.IsControlPressed or
Manager.IsMetaPressed /* for OSX; Cmd + [a-z] */) {
if (Manager.IsControlPressed or Manager.IsMetaPressed /* for OSX; Cmd + [a-z] */) {
if (key == "C" && this.selection.SelectionEnd > this.selection.SelectionStart) {
Manager.Copy(this.SelectedText);
return;
@ -330,7 +336,8 @@ namespace spades {
}
}
void AddLine(string line, bool autoscroll = false, Vector4 color = Vector4(1.f, 1.f, 1.f, 1.f)) {
void AddLine(string line, bool autoscroll = false,
Vector4 color = Vector4(1.f, 1.f, 1.f, 1.f)) {
if (textmodel is null) {
this.Text = "";
}

View File

@ -68,8 +68,10 @@ namespace spades {
@RootElement = UIElement(this);
RootElement.Size = Vector2(renderer.ScreenWidth, renderer.ScreenHeight);
@DefaultCursor = Cursor(this, renderer.RegisterImage("Gfx/UI/Cursor.png"), Vector2(8.f, 8.f));
MouseCursorPosition = Vector2(renderer.ScreenWidth * 0.5f, renderer.ScreenHeight * 0.5f);
@DefaultCursor
= Cursor(this, renderer.RegisterImage("Gfx/UI/Cursor.png"), Vector2(8.f, 8.f));
MouseCursorPosition =
Vector2(renderer.ScreenWidth * 0.5f, renderer.ScreenHeight * 0.5f);
@keyRepeater.handler = KeyRepeatEventHandler(this.HandleKeyInner);
@charRepeater.handler = KeyRepeatEventHandler(this.HandleCharInner);
@ -146,10 +148,8 @@ namespace spades {
);
*/
// in current version, absolute mouse mode is supported.
MouseCursorPosition = Vector2(
Clamp(x, 0.f, renderer.ScreenWidth),
Clamp(y, 0.f, renderer.ScreenHeight)
);
MouseCursorPosition = Vector2(Clamp(x, 0.f, renderer.ScreenWidth),
Clamp(y, 0.f, renderer.ScreenHeight));
MouseEventDone();
}
@ -214,7 +214,8 @@ namespace spades {
}
e.MouseDown(mb, e.ScreenToClient(MouseCursorPosition));
} else {
// FIXME: release the mouse capture when all button are released?
// FIXME: release the mouse capture when all button are
// released?
@mouseCapturedElement = null;
e.MouseUp(mb, e.ScreenToClient(MouseCursorPosition));
MouseEventDone();
@ -279,9 +280,9 @@ namespace spades {
if (EditingText.length > 0) {
// now text is being composed by IME.
// ignore some keys to resolve confliction.
if(key == "Escape" || key == "BackSpace" || key == "Left" || key == "Right" ||
key == "Space" || key == "Enter" || key == "Up" || key == "Down" ||
key == "Tab") {
if (key == "Escape" || key == "BackSpace" || key == "Left" ||
key == "Right" || key == "Space" || key == "Enter" || key == "Up" ||
key == "Down" || key == "Tab") {
return;
}
}
@ -300,16 +301,13 @@ namespace spades {
}
}
void ProcessHotKey(string key) {
if (RootElement.Visible) {
RootElement.HotKey(key);
}
}
void AddTimer(Timer@ timer) {
timers.insertLast(timer);
}
void AddTimer(Timer @timer) { timers.insertLast(timer); }
void RemoveTimer(Timer @timer) {
int idx = -1;
@ -366,9 +364,7 @@ namespace spades {
}
}
void Copy(string text) {
SetClipboardData(text);
}
void Copy(string text) { SetClipboardData(text); }
void Paste(PasteClipboardEventHandler @handler) {
RequestClipboardData();
@ -386,9 +382,7 @@ namespace spades {
lastKey = key;
nextDelay = 0.2f;
}
void KeyUp() {
lastKey = "";
}
void KeyUp() { lastKey = ""; }
void RunFrame(float dt) {
if (lastKey.length == 0)
@ -413,14 +407,10 @@ namespace spades {
private float nextDelay;
Timer(UIManager@ manager) {
@this.manager = manager;
}
Timer(UIManager @manager) { @this.manager = manager; }
UIManager @Manager {
get final {
return manager;
}
get final { return manager; }
}
void OnTick() {
@ -447,10 +437,7 @@ namespace spades {
manager.AddTimer(this);
}
void Stop() {
manager.RemoveTimer(this);
}
void Stop() { manager.RemoveTimer(this); }
}
enum MouseButton {
@ -465,9 +452,7 @@ namespace spades {
class UIElementIterator {
private bool initial = true;
private UIElement @e;
UIElementIterator(UIElement@ parent) {
@e = parent;
}
UIElementIterator(UIElement @parent) { @e = parent; }
UIElement @Current {
get { return initial ? null : e; }
}
@ -485,9 +470,7 @@ namespace spades {
class UIElementReverseIterator {
private bool initial = true;
private UIElement @e;
UIElementReverseIterator(UIElement@ parent) {
@e = parent;
}
UIElementReverseIterator(UIElement @parent) { @e = parent; }
UIElement @Current {
get { return initial ? null : e; }
}
@ -517,24 +500,30 @@ namespace spades {
bool Visible = true;
bool Enable = true;
/** When AcceptsFocus is set to true, this element can be activated when
* it receives a mouse event. */
/**
* When AcceptsFocus is set to true, this element can be activated when
* it receives a mouse event.
*/
bool AcceptsFocus = false;
/** When IsMouseInteractive is set to true, this element receives mouse events. */
/**
* When IsMouseInteractive is set to true, this element receives mouse
* events.
*/
bool IsMouseInteractive = false;
/** When this is set to true, all mouse interraction outside the client area is
* ignored for all sub-elements, reducing the CPU load. The visual is not clipped. */
/**
* When this is set to true, all mouse interraction outside the client area
* is
* ignored for all sub-elements, reducing the CPU load. The visual is not
* clipped.
*/
bool ClipMouse = true;
Vector2 Position;
Vector2 Size;
UIElement(UIManager@ manager) {
@this.manager = manager;
}
UIElement(UIManager @manager) { @this.manager = manager; }
UIElement @Parent {
get final { return parent; }
@ -629,9 +618,7 @@ namespace spades {
}
}
void AddChild(UIElement@ element) {
AppendChild(element);
}
void AddChild(UIElement @element) { AppendChild(element); }
void RemoveChild(UIElement @element) {
if (element.parent !is this) {
@ -683,9 +670,7 @@ namespace spades {
}
return parent.Font;
}
set {
@fontOverride = value;
}
set { @fontOverride = value; }
}
Cursor @Cursor {
@ -698,31 +683,31 @@ namespace spades {
}
return parent.Cursor;
}
set {
@cursorOverride = value;
}
set { @cursorOverride = value; }
}
bool IsVisible {
get final {
if(not Visible) return false;
if(parent is null) return this is Manager.RootElement;
if (not Visible)
return false;
if (parent is null)
return this is Manager.RootElement;
return parent.IsVisible;
}
}
bool IsEnabled {
get final {
if(not Enable) return false;
if(parent is null) return true;
if (not Enable)
return false;
if (parent is null)
return true;
return parent.IsEnabled;
}
}
bool IsFocused {
get final {
return manager.ActiveElement is this;
}
get final { return manager.ActiveElement is this; }
}
Vector2 ScreenPosition {
@ -735,9 +720,7 @@ namespace spades {
}
AABB2 Bounds {
get final {
return AABB2(Position, Position + Size);
}
get final { return AABB2(Position, Position + Size); }
set {
Position = value.min;
Size = value.max - value.min;
@ -755,9 +738,7 @@ namespace spades {
// IME supports
AABB2 TextInputRect {
get {
return AABB2(0.f, 0.f, Size.x, Size.y);
}
get { return AABB2(0.f, 0.f, Size.x, Size.y); }
}
int TextEditingRangeStart {
@ -790,8 +771,7 @@ namespace spades {
}
}
void OnResized() {
}
void OnResized() {}
// relativePos is parent relative
UIElement @MouseHitTest(Vector2 relativePos) final {
@ -801,7 +781,6 @@ namespace spades {
}
}
Vector2 p = relativePos - Position;
UIElementReverseIterator iterator(this);
@ -825,9 +804,7 @@ namespace spades {
return null;
}
Vector2 ScreenToClient(Vector2 scr) final {
return scr - ScreenPosition;
}
Vector2 ScreenToClient(Vector2 scr) final { return scr - ScreenPosition; }
void MouseWheel(float delta) {
if (Parent !is null) {
@ -860,14 +837,10 @@ namespace spades {
}
}
void KeyDown(string key) {
manager.ProcessHotKey(key);
}
void KeyUp(string key) {
}
void KeyDown(string key) { manager.ProcessHotKey(key); }
void KeyUp(string key) {}
void KeyPress(string text) {
}
void KeyPress(string text) {}
void HotKey(string key) {
UIElementReverseIterator iterator(this);
@ -906,15 +879,12 @@ namespace spades {
}
}
class UIElementDeque {
private UIElement @[] @arr;
private int startIndex = 0;
private int count = 0;
UIElementDeque() {
@arr = array<spades::ui::UIElement@>(4);
}
UIElementDeque() { @arr = array<spades::ui::UIElement @>(4); }
private int MapIndex(int idx) const {
idx += startIndex;
@ -923,12 +893,8 @@ namespace spades {
return idx;
}
UIElement@ get_opIndex(int idx) const {
return arr[MapIndex(idx)];
}
void set_opIndex(int idx, UIElement@ e) {
@arr[MapIndex(idx)] = e;
}
UIElement @get_opIndex(int idx) const { return arr[MapIndex(idx)]; }
void set_opIndex(int idx, UIElement @e) { @arr[MapIndex(idx)] = e; }
void Reserve(int c) {
if (int(arr.length) >= c) {

View File

@ -20,10 +20,10 @@
namespace spades {
/** AudioChunk is an opaque type which can be passed to an audio device to
* play sounds. */
class AudioChunk {
}
/**
* AudioChunk is an opaque type which can be passed to an audio device to
* play sounds.
*/
class AudioChunk {}
}

View File

@ -23,9 +23,11 @@ namespace spades {
/** AudioDevice is an interface to the audio device. */
class AudioDevice {
/** Loads an audio data from the specified path or load one from
/**
* Loads an audio data from the specified path or load one from
* the cache, if exists.
* @param path file-system path. */
* @param path file-system path.
*/
AudioChunk @RegisterSound(const string @path) {}
/** Sets a game world map. */
@ -36,26 +38,27 @@ namespace spades {
/** Plays a sound. */
void Play(AudioChunk @, const Vector3 @origin, const AudioParam @params);
/** Plays a sound, with the source position specified in the view
* coordinate space. */
/**
* Plays a sound, with the source position specified in the view
* coordinate space.
*/
void PlayLocal(AudioChunk @, const Vector3 @origin, const AudioParam @params);
/** Plays a non-spatialized sound. */
void PlayLocal(AudioChunk @, const AudioParam @params);
/** Updates the position of the listener. */
void Respatialize(const Vector3@ eye,
const Vector3@ frontVector,
const Vector3@ upVector);
void Respatialize(const Vector3 @eye, const Vector3 @frontVector, const Vector3 @upVector);
}
class AudioParam {
/** Linear gain of the sound. */
float volume;
/** Playback speed of the sound. Doubling this value makes the sound
* played twice faster. */
/**
* Playback speed of the sound. Doubling this value makes the sound
* played twice faster.
*/
float pitch;
float referenceDistance;

View File

@ -44,6 +44,5 @@ namespace spades {
int Height {
get {}
}
}
}

View File

@ -31,6 +31,5 @@ namespace spades {
/** Renders the string with a shadow. */
void DrawShadow(const string @text, Vector2 origin, float scale, Vector4 color);
}
}

View File

@ -23,7 +23,8 @@ namespace spades {
/** Represents a game world map. */
class GameMap {
/** Creates a new map.
/**
* Creates a new map.
* @param width You must specify 512.
* @param height You must specify 512.
* @param depth You must specify 64.
@ -73,9 +74,7 @@ namespace spades {
bool ClipWorld(float x, float y, float z) {}
/** Casts a ray. */
GameMapRayCastResult CastRay(Vector3 start, Vector3 direction,
int maxScanSteps);
GameMapRayCastResult CastRay(Vector3 start, Vector3 direction, int maxScanSteps);
}
/** GameMapRayCastResult contains the result of the ray-cast. */

View File

@ -20,8 +20,10 @@
namespace spades {
/** Image is an opaque type which can be passed to rendering methods to
* draw an image quickly. */
/**
* Image is an opaque type which can be passed to rendering methods to
* draw an image quickly.
*/
class Image {
/** Retrieves the width of the image, in pixels. */
float Width {

View File

@ -238,15 +238,18 @@ namespace spades {
/** Computes a cross-product of two vectors. */
Vector3 Cross(const Vector3 @, const Vector3 @);
/** Applies the floor function to the given vector, and
* returns the computed one. */
/**
* Applies the floor function to the given vector, and
* returns the computed one.
*/
Vector3 Floor(const Vector3 @);
/** Applies the ceiling function to the given vector, and
* returns the computed one. */
/**
* Applies the ceiling function to the given vector, and
* returns the computed one.
*/
Vector3 Ceil(const Vector3 @);
/** Represents a 4-component real vector. */
class Vector4 {
float x, y, z, w;
@ -319,12 +322,16 @@ namespace spades {
/** Computes a dot-product of two vectors. */
float Dot(const Vector4 @, const Vector4 @);
/** Applies the floor function to the given vector, and
* returns the computed one. */
/**
* Applies the floor function to the given vector, and
* returns the computed one.
*/
Vector4 Floor(const Vector4 @);
/** Applies the ceiling function to the given vector, and
* returns the computed one. */
/**
* Applies the ceiling function to the given vector, and
* returns the computed one.
*/
Vector4 Ceil(const Vector4 @);
/** Represents column-major 4x4 matrix. */
@ -341,10 +348,9 @@ namespace spades {
Matrix4(const Matrix4 @other) {}
/** Initializes Matrix4 with the given values. */
Matrix4(float m00, float m10, float m20, float m30,
float m01, float m11, float m21, float m31,
float m02, float m12, float m22, float m32,
float m03, float m13, float m23, float m33) {}
Matrix4(float m00, float m10, float m20, float m30, float m01, float m11, float m21,
float m31, float m02, float m12, float m22, float m32, float m03, float m13,
float m23, float m33) {}
/** Multiplies this matrix by the given one, and returns this one. */
Matrix4 @opMulAssign(const Matrix4 @other) {}
@ -355,15 +361,19 @@ namespace spades {
/** Multiplies this matrix by the given vector, and returns a vector. */
Vector4 opMul(const Vector4 @other) {}
/** Multiplies this matrix by the vector [x, y, z, 1], and returns
* a 3-component vector, discarding the fourth component. */
/**
* Multiplies this matrix by the vector [x, y, z, 1], and returns
* a 3-component vector, discarding the fourth component.
*/
Vector3 opMul(const Vector3 @other) {}
/** Returns the transformed position of the vector [0, 0, 0]. */
Vector3 GetOrigin() const {}
/** Returns the transformed orientation of the specified axis.
* @param axis 0 for X-axis, 1 for Y-axis, and 2 for Z-axis. */
/**
* Returns the transformed orientation of the specified axis.
* @param axis 0 for X-axis, 1 for Y-axis, and 2 for Z-axis.
*/
Vector3 GetAxis(int axis) const {}
/** Returns the transposed matrix. */
@ -371,8 +381,10 @@ namespace spades {
get const {}
}
/** Returns the inverted matrix.
* This operation works in O(N^3). */
/**
* Returns the inverted matrix.
* This operation works in O(N^3).
*/
Matrix4 Inverted {
get const {}
}
@ -381,45 +393,66 @@ namespace spades {
Matrix4 InvertedFast {
get const {}
}
}
/** Creates an matrix that can be used to translate points by the
* specified displacement vector. */
/**
* Creates an matrix that can be used to translate points by the
* specified displacement vector.
*/
Matrix4 CreateTranslateMatrix(Vector3 displacement) {}
/** Creates an matrix that can be used to translate points by the
* specified displacement vector. */
/**
* Creates an matrix that can be used to translate points by the
* specified displacement vector.
*/
Matrix4 CreateTranslateMatrix(float x, float y, float z) {}
/** Creates an matrix that can be used to rotate points by the
* specified axis and rotation angle. */
/**
* Creates an matrix that can be used to rotate points by the
* specified axis and rotation angle.
*/
Matrix4 CreateRotateMatrix(Vector3 axis, float radians) {}
/** Creates an matrix that can be used to scale points by the
* specified vector. */
/**
* Creates an matrix that can be used to scale points by the
* specified vector.
*/
Matrix4 CreateScaleMatrix(Vector3 factor) {}
/** Creates an matrix that can be used to scale points by the
* specified vector. */
/**
* Creates an matrix that can be used to scale points by the
* specified vector.
*/
Matrix4 CreateScaleMatrix(float x, float y, float z) {}
/** Creates an matrix that can be used to scale points by the
* specified factor. */
/**
* Creates an matrix that can be used to scale points by the
* specified factor.
*/
Matrix4 CreateScaleMatrix(float factor) {}
/** Creates an matrix using the given axis vector. */
Matirx4 CreateMatrixFromAxes(Vector3 axisX, Vector3 axisY, Vector3 axisZ,
Vector3 origin);
Matirx4 CreateMatrixFromAxes(Vector3 axisX, Vector3 axisY, Vector3 axisZ, Vector3 origin);
/** Represents a two-dimensional AABB (axis-aligned bounding box). */
class AABB2 {
Vector2 min, max;
float minX { get const {} set {} }
float maxX { get const {} set {} }
float minY { get const {} set {} }
float maxY { get const {} set {} }
float minX {
get const {}
set {}
}
float maxX {
get const {}
set {}
}
float minY {
get const {}
set {}
}
float maxY {
get const {}
set {}
}
/** Default constructor. */
AABB2() {}
@ -427,12 +460,16 @@ namespace spades {
/** Copy constructor. */
AABB2(const AABB2 @) {}
/** Initializes AABB2 with the top-left coordinate and the
* dimensions of the bounding box. */
/**
* Initializes AABB2 with the top-left coordinate and the
* dimensions of the bounding box.
*/
AABB2(float left, float top, float width, float height) {}
/** Initializes AABB2 with the top-left coordinate and the
* bottom-right one. */
/**
* Initializes AABB2 with the top-left coordinate and the
* bottom-right one.
*/
AABB2(Vector2 min, Vector2 max) {}
/** Checks if the given vector is in the bounding box. */

View File

@ -20,10 +20,10 @@
namespace spades {
/** Model is an opaque type which can be passed to rendering methods to
* draw an three-dimensional model. */
class Model {
}
/**
* Model is an opaque type which can be passed to rendering methods to
* draw an three-dimensional model.
*/
class Model {}
}

View File

@ -29,14 +29,18 @@ namespace spades {
/** Shuts down the renderer. */
void Shutdown() {}
/** Loads an image from the specified path or load one from
/**
* Loads an image from the specified path or load one from
* the cache, if exists.
* @param path file-system path. */
* @param path file-system path.
*/
Image @RegisterImage(const string @path) {}
/** Loads an model from the specified path or load one from
/**
* Loads an model from the specified path or load one from
* the cache, if exists.
* @param path file-system path. */
* @param path file-system path.
*/
Model @RegisterModel(const string @path) {}
/** Creates an image from the specified bitmap. */
@ -60,10 +64,12 @@ namespace spades {
set {}
}
/** Sets a color that is used for drawing.
/**
* Sets a color that is used for drawing.
* @deprecated Do not use this virtual property.
* Some methods treat this value as an alpha premultiplied,
* while others treat this value has a straight alpha. */
* while others treat this value has a straight alpha.
*/
Vector4 Color {
set {}
}
@ -73,14 +79,18 @@ namespace spades {
set {}
}
/** Sets a color that is used for drawing. The color value is
* alpha premultiplied. */
/**
* Sets a color that is used for drawing. The color value is
* alpha premultiplied.
*/
Vector4 ColorP {
set {}
}
/** Sets a color that is used for drawing. The color value is
* alpha non-premultiplied (straight alpha). */
/**
* Sets a color that is used for drawing. The color value is
* alpha non-premultiplied (straight alpha).
*/
Vector4 ColorNP {
set {}
}
@ -88,55 +98,72 @@ namespace spades {
/** Starts a 3D scene rendering. */
void StartScene(const SceneDefinition @) {}
/** Adds a dynamic light to the scene.
* This should be called between StartScene and EndScene. */
/**
* Adds a dynamic light to the scene.
* This should be called between StartScene and EndScene.
*/
void AddLight(const DynamicLightParam @) {}
/** Adds a model to the scene.
* This should be called between StartScene and EndScene. */
/**
* Adds a model to the scene.
* This should be called between StartScene and EndScene.
*/
void AddModel(Model @, const ModelRenderParam @) {}
/** Adds a line for debugging.
* This should be called between StartScene and EndScene. */
void AddDebugLine(const Vector3@ pt1, const Vector3@ pt2,
const Vector4@ color) {}
/**
* Adds a line for debugging.
* This should be called between StartScene and EndScene.
*/
void AddDebugLine(const Vector3 @pt1, const Vector3 @pt2, const Vector4 @color) {}
/** Adds a sprite.
/**
* Adds a sprite.
* This should be called between StartScene and EndScene.
* The color is specified using the property `Color` with
* alpha values premultiplied. */
void AddSprite(Image@, const Vector3@ origin, float radius,
float rotateRadians) {}
* alpha values premultiplied.
*/
void AddSprite(Image @, const Vector3 @origin, float radius, float rotateRadians) {}
/** Adds a long-sprite.
/**
* Adds a long-sprite.
* This should be called between StartScene and EndScene.
* The color is specified using the property `Color` with
* alpha values premultiplied. */
* alpha values premultiplied.
*/
void AddLongSprite(Image @, const Vector3 @pt1, const Vector3 @pt2, float radius) {}
/** Ends a 3D scene rendering. */
void EndScene() {}
/** Multiplies color of the screen by the specified color.
* This should never be called between StartScene and EndScene. */
/**
* Multiplies color of the screen by the specified color.
* This should never be called between StartScene and EndScene.
*/
void MultiplyScreenColor(Vector3 color) {}
/** Draws a 2D image.
* This should never be called between StartScene and EndScene. */
/**
* Draws a 2D image.
* This should never be called between StartScene and EndScene.
*/
void DrawImage(Image @, const Vector2 @topLeft) {}
/** Draws a 2D image.
* This should never be called between StartScene and EndScene. */
/**
* Draws a 2D image.
* This should never be called between StartScene and EndScene.
*/
void DrawImage(Image @, const AABB2 @outRect) {}
/** Draws a 2D image.
* This should never be called between StartScene and EndScene. */
/**
* Draws a 2D image.
* This should never be called between StartScene and EndScene.
*/
void DrawImage(Image @, const AABB2 @outRect, const AABB2 @inRect) {}
/** Draws a 2D image.
* This should never be called between StartScene and EndScene. */
void DrawImage(Image@,
const Vector2@ outTopLeft, const Vector2@ outTopRight,
/**
* Draws a 2D image.
* This should never be called between StartScene and EndScene.
*/
void DrawImage(Image @, const Vector2 @outTopLeft, const Vector2 @outTopRight,
const Vector2 @outBottomLeft, const AABB2 @inRect) {}
/** Finalizes the drawing. */

View File

@ -21,10 +21,7 @@
namespace spades {
/** Replaces any occurrence of the pattern string with another string. */
string Replace(const string@ str,
const string@ pattern,
const string@ after) {}
string Replace(const string @str, const string @pattern, const string @after) {}
/** Removes preceding/following white-spaces. */
string TrimSpaces(const string @input) {}

View File

@ -23,7 +23,8 @@ namespace spades {
/** Represents a small voxel model. */
class VoxelModel {
/** Creates a new voxel model.
/**
* Creates a new voxel model.
* @param width Width of the voxel model.
* @param height Height of the voxel model.
* @param depth Depth of the voxel model, which must be <= 64.
@ -59,7 +60,6 @@ namespace spades {
int Depth {
get {}
}
}
}

View File

@ -20,12 +20,16 @@
namespace spades {
/** A skin of blocks held in hands. A class that implements
/**
* A skin of blocks held in hands. A class that implements
* this might also have to implement either IThirdPersonToolSkin
* or IViewToolSkin. */
* or IViewToolSkin.
*/
interface IBlockSkin {
/** Receives a ready state. 0 = soon after placing a block,
* >=1 = ready to place a block. */
/**
* Receives a ready state. 0 = soon after placing a block,
* >=1 = ready to place a block.
*/
float ReadyState { set; }
Vector3 BlockColor { set; }

View File

@ -20,16 +20,22 @@
namespace spades {
/** A skin of grenades. A class that implements
/**
* A skin of grenades. A class that implements
* this might also have to implement either IThirdPersonToolSkin
* or IViewToolSkin. */
* or IViewToolSkin.
*/
interface IGrenadeSkin {
/** Receives a ready state. 0 = soon after placing a block,
* >=1 = ready to place a block. */
/**
* Receives a ready state. 0 = soon after placing a block,
* >=1 = ready to place a block.
*/
float ReadyState { set; }
/** Receives how long a player is cooking the grenade.
* 0 if the player isn't cooking a grenade. */
/**
* Receives how long a player is cooking the grenade.
* 0 if the player isn't cooking a grenade.
*/
float CookTime { set; }
}

View File

@ -21,20 +21,19 @@
namespace spades {
/** Action what a user doing with his/her spade. */
enum SpadeActionType {
Idle,
Bash,
Dig,
DigStart
}
enum SpadeActionType { Idle, Bash, Dig, DigStart }
/** A skin of spades. A class that implements this might also have to
* implement either IThirdPersonToolSkin or IViewToolSkin. */
/**
* A skin of spades. A class that implements this might also have to
* implement either IThirdPersonToolSkin or IViewToolSkin.
*/
interface ISpadeSkin {
SpadeActionType ActionType { set; }
/** Receives an action progress. 0 = soon after swinging,
* 1 = ready for the next swing. */
/**
* Receives an action progress. 0 = soon after swinging,
* 1 = ready for the next swing.
*/
float ActionProgress { set; }
}

View File

@ -20,15 +20,16 @@
namespace spades {
/** A skin of all tools for third-person view. A class that implements
* this might also have to implement IToolSkin. */
/**
* A skin of all tools for third-person view. A class that implements
* this might also have to implement IToolSkin.
*/
interface IThirdPersonToolSkin {
/** Receives a transform matrix from tool coordinate to world one. */
Matrix4 OriginMatrix { set; }
float PitchBias { get; }
}
}

View File

@ -23,12 +23,16 @@ namespace spades {
/** A skin of all tools for third-person view. */
interface IToolSkin {
/** Receives a value that indicates whether the owner of the tool is sprinting.
* 0 = not sprinting, 1 = sprinting. */
/**
* Receives a value that indicates whether the owner of the tool is
* sprinting. 0 = not sprinting, 1 = sprinting.
*/
float SprintState { set; }
/** Receives a value that indicates whether this tool is raised.
* 0 = brought down, 1 = raised. */
/**
* Receives a value that indicates whether this tool is raised.
* 0 = brought down, 1 = raised.
*/
float RaiseState { set; }
/** Receives the team color. */
@ -42,7 +46,6 @@ namespace spades {
/** Issues draw commands to add models of this tool to the scene. */
void AddToScene();
}
}

View File

@ -20,8 +20,10 @@
namespace spades {
/** A skin of all tools for first-person view. A class that implements
* this might also have to implement IToolSkin. */
/**
* A skin of all tools for first-person view. A class that implements
* this might also have to implement IToolSkin.
*/
interface IViewToolSkin {
/** Receives a transform matrix from view coordinate to world one. */

View File

@ -20,12 +20,16 @@
namespace spades {
/** A skin of weapons. A class that implements
/**
* A skin of weapons. A class that implements
* this might also have to implement either IThirdPersonToolSkin
* or IViewToolSkin. */
* or IViewToolSkin.
*/
interface IWeaponSkin {
/** Receives a ready state. 0 = soon after firing,
* >=1 = ready to fire the next bullet. */
/**
* Receives a ready state. 0 = soon after firing,
* >=1 = ready to fire the next bullet.
*/
float ReadyState { set; }
/** 0 = normal, 1 = aiming down the sight. */
@ -43,12 +47,16 @@ namespace spades {
/** Called when a player fired the weapon. */
void WeaponFired();
/** Called when a player started reloading the weapon.
* For shotgun, this is called for every pellets. */
/**
* Called when a player started reloading the weapon.
* For shotgun, this is called for every pellets.
*/
void ReloadingWeapon();
/** Called when a played reloaded the weapon.
* For shotgun, this is called for every pellets. */
/**
* Called when a played reloaded the weapon.
* For shotgun, this is called for every pellets.
*/
void ReloadedWeapon();
}

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class BasicViewWeapon:
IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2 {
class BasicViewWeapon : IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2 {
// IToolSkin
protected float sprintState;
protected float raiseState;
@ -64,9 +63,7 @@ namespace spades {
aimDownSightState = value;
aimDownSightStateSmooth = SmoothStep(value);
}
get {
return aimDownSightState;
}
get { return aimDownSightState; }
}
float AimDownSightStateSmooth {
@ -113,20 +110,12 @@ namespace spades {
}
Vector3 LeftHandPosition {
get {
return leftHand;
}
set {
leftHand = value;
}
get { return leftHand; }
set { leftHand = value; }
}
Vector3 RightHandPosition {
get {
return rightHand;
}
set {
rightHand = value;
}
get { return rightHand; }
set { rightHand = value; }
}
// IWeaponSkin2
@ -148,28 +137,20 @@ namespace spades {
BasicViewWeapon(Renderer @renderer) {
@this.renderer = renderer;
localFireVibration = 0.f;
@sightImage = renderer.RegisterImage
("Gfx/Sight.tga");
@sightImage = renderer.RegisterImage("Gfx/Sight.tga");
}
float GetLocalFireVibration() {
return localFireVibration;
}
float GetLocalFireVibration() { return localFireVibration; }
float GetMotionGain() {
return 1.f - AimDownSightStateSmooth * 0.4f;
}
float GetMotionGain() { return 1.f - AimDownSightStateSmooth * 0.4f; }
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.05f;
}
float GetZPos() { return 0.2f - AimDownSightStateSmooth * 0.05f; }
Vector3 GetLocalFireVibrationOffset() {
float vib = GetLocalFireVibration();
float motion = GetMotionGain();
Vector3 hip = Vector3(
sin(vib * PiF * 2.f) * 0.008f * motion,
vib * (vib - 1.f) * 0.14f * motion,
Vector3 hip =
Vector3(sin(vib * PiF * 2.f) * 0.008f * motion, vib * (vib - 1.f) * 0.14f * motion,
vib * (1.f - vib) * 0.03f * motion);
Vector3 ads = Vector3(0.f, vib * (vib - 1.f) * vib * 0.3f * motion, 0.f);
return Mix(hip, ads, AimDownSightStateSmooth);
@ -178,29 +159,22 @@ namespace spades {
Matrix4 GetViewWeaponMatrix() {
Matrix4 mat;
if (sprintStateSmooth > 0.f) {
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f),
sprintStateSmooth * -0.1f) * mat;
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f),
sprintStateSmooth * 0.3f) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f),
sprintStateSmooth * -0.55f) * mat;
mat = CreateTranslateMatrix(Vector3(0.23f, -0.05f, 0.15f)
* sprintStateSmooth) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f), sprintStateSmooth * -0.1f) * mat;
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f), sprintStateSmooth * 0.3f) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), sprintStateSmooth * -0.55f) * mat;
mat =
CreateTranslateMatrix(Vector3(0.23f, -0.05f, 0.15f) * sprintStateSmooth) * mat;
}
if (raiseState < 1.f) {
float putdown = 1.f - raiseState;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f),
putdown * -1.3f) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f),
putdown * 0.2f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.3f, 0.1f)
* putdown) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), putdown * -1.3f) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f), putdown * 0.2f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.3f, 0.1f) * putdown) * mat;
}
Vector3 trans(0.f, 0.f, 0.f);
trans += Vector3(-0.13f * (1.f - AimDownSightStateSmooth),
0.5f, GetZPos());
trans += Vector3(-0.13f * (1.f - AimDownSightStateSmooth), 0.5f, GetZPos());
trans += swing * GetMotionGain();
trans += GetLocalFireVibrationOffset();
mat = CreateTranslateMatrix(trans) * mat;
@ -222,18 +196,13 @@ namespace spades {
}
}
void WeaponFired(){
localFireVibration = 1.f;
}
void WeaponFired() { localFireVibration = 1.f; }
void AddToScene() {
}
void AddToScene() {}
void ReloadingWeapon() {
}
void ReloadingWeapon() {}
void ReloadedWeapon() {
}
void ReloadedWeapon() {}
void Draw2D() {
renderer.ColorNP = (Vector4(1.f, 1.f, 1.f, 1.f));

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonBlockSkin:
IToolSkin, IThirdPersonToolSkin, IBlockSkin {
class ThirdPersonBlockSkin : IToolSkin, IThirdPersonToolSkin, IBlockSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -69,12 +68,10 @@
ThirdPersonBlockSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Block/Block2.kv6");
@model = renderer.RegisterModel("Models/Weapons/Block/Block2.kv6");
}
void Update(float dt) {
}
void Update(float dt) {}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.05f);

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ViewBlockSkin:
IToolSkin, IViewToolSkin, IBlockSkin {
class ViewBlockSkin : IToolSkin, IViewToolSkin, IBlockSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -60,14 +59,10 @@
}
Vector3 LeftHandPosition {
get {
return leftHand;
}
get { return leftHand; }
}
Vector3 RightHandPosition {
get {
return rightHand;
}
get { return rightHand; }
}
Vector3 BlockColor {
@ -86,10 +81,8 @@
ViewBlockSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Block/Block2.kv6");
@sightImage = renderer.RegisterImage
("Gfx/Sight.tga");
@model = renderer.RegisterModel("Models/Weapons/Block/Block2.kv6");
@sightImage = renderer.RegisterImage("Gfx/Sight.tga");
}
void Update(float dt) {
@ -112,17 +105,14 @@
Matrix4 mat = CreateScaleMatrix(0.033f);
if (sprintStateSmooth > 0.f) {
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f),
sprintStateSmooth * -0.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.4f, -0.05f) * sprintStateSmooth)
* mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), sprintStateSmooth * -0.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.4f, -0.05f) * sprintStateSmooth) * mat;
}
mat = CreateTranslateMatrix(-0.3f, 0.7f, 0.3f) * mat;
mat = CreateTranslateMatrix(swing) * mat;
mat = CreateTranslateMatrix(Vector3(-0.1f, -0.3f, 0.2f) * (1.f - raiseState))
* mat;
mat = CreateTranslateMatrix(Vector3(-0.1f, -0.3f, 0.2f) * (1.f - raiseState)) * mat;
leftHand = mat * Vector3(5.f, -1.f, 4.f);
rightHand = mat * Vector3(-5.5f, 3.f, -5.f);
@ -142,7 +132,5 @@
}
}
IBlockSkin@ CreateViewBlockSkin(Renderer@ r, AudioDevice@ dev) {
return ViewBlockSkin(r, dev);
}
IBlockSkin @CreateViewBlockSkin(Renderer @r, AudioDevice @dev) { return ViewBlockSkin(r, dev); }
}

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonGrenadeSkin:
IToolSkin, IThirdPersonToolSkin, IGrenadeSkin {
class ThirdPersonGrenadeSkin : IToolSkin, IThirdPersonToolSkin, IGrenadeSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -69,12 +68,10 @@
ThirdPersonGrenadeSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Grenade/Grenade.kv6");
@model = renderer.RegisterModel("Models/Weapons/Grenade/Grenade.kv6");
}
void Update(float dt) {
}
void Update(float dt) {}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.05f);

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ViewGrenadeSkin:
IToolSkin, IViewToolSkin, IGrenadeSkin {
class ViewGrenadeSkin : IToolSkin, IViewToolSkin, IGrenadeSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -60,14 +59,10 @@
}
Vector3 LeftHandPosition {
get {
return leftHand;
}
get { return leftHand; }
}
Vector3 RightHandPosition {
get {
return rightHand;
}
get { return rightHand; }
}
float CookTime {
@ -86,10 +81,8 @@
ViewGrenadeSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Grenade/Grenade.kv6");
@sightImage = renderer.RegisterImage
("Gfx/Sight.tga");
@model = renderer.RegisterModel("Models/Weapons/Grenade/Grenade.kv6");
@sightImage = renderer.RegisterImage("Gfx/Sight.tga");
}
void Update(float dt) {
@ -123,16 +116,16 @@
}
if (sprintStateSmooth > 0.f) {
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f),
sprintStateSmooth * -0.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.2f, -0.05f)
* sprintStateSmooth) * mat;
mat =
CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), sprintStateSmooth * -0.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.1f, -0.2f, -0.05f) * sprintStateSmooth) *
mat;
}
mat = CreateTranslateMatrix(-0.3f - side * 0.8f,
0.8f - bring * 0.1f, 0.45f - bring * 0.15f) * mat;
mat = CreateTranslateMatrix(-0.3f - side * 0.8f, 0.8f - bring * 0.1f,
0.45f - bring * 0.15f) *
mat;
mat = CreateTranslateMatrix(Vector3(-0.1f, -0.3f, 0.1f) * (1.f - raiseState))
* mat;
mat = CreateTranslateMatrix(Vector3(-0.1f, -0.3f, 0.1f) * (1.f - raiseState)) * mat;
mat = CreateTranslateMatrix(swing) * mat;
@ -164,7 +157,6 @@
p2 = 0.9f - p2 * p2 * 2.5f;
rightHand = Vector3(-0.2f, p2, -0.9f + per * 1.8f);
}
}
void Draw2D() {
renderer.ColorNP = (Vector4(1.f, 1.f, 1.f, 1.f));

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonRifleSkin:
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
class ThirdPersonRifleSkin : IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -105,30 +104,20 @@
ThirdPersonRifleSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Rifle/Weapon.kv6");
@model = renderer.RegisterModel("Models/Weapons/Rifle/Weapon.kv6");
@fireSounds[0] = dev.RegisterSound
("Sounds/Weapons/Rifle/Fire1.opus");
@fireSounds[1] = dev.RegisterSound
("Sounds/Weapons/Rifle/Fire2.opus");
@fireSounds[2] = dev.RegisterSound
("Sounds/Weapons/Rifle/Fire3.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/Rifle/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/Rifle/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/Rifle/Reload.opus");
@fireSounds[0] = dev.RegisterSound("Sounds/Weapons/Rifle/Fire1.opus");
@fireSounds[1] = dev.RegisterSound("Sounds/Weapons/Rifle/Fire2.opus");
@fireSounds[2] = dev.RegisterSound("Sounds/Weapons/Rifle/Fire3.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/Rifle/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/Rifle/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/Rifle/Reload.opus");
@fireSmallReverbSound = dev.RegisterSound
("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound
("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
@fireSmallReverbSound = dev.RegisterSound("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
}
void Update(float dt) {
}
void Update(float dt) {}
void WeaponFired() {
if (!muted) {
@ -162,8 +151,7 @@
}
}
void ReloadedWeapon() {
}
void ReloadedWeapon() {}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.05f);

View File

@ -19,9 +19,7 @@
*/
namespace spades {
class ViewRifleSkin:
IToolSkin, IViewToolSkin, IWeaponSkin,
BasicViewWeapon {
class ViewRifleSkin : IToolSkin, IViewToolSkin, IWeaponSkin, BasicViewWeapon {
private AudioDevice @audioDevice;
private Model @gunModel;
@ -39,33 +37,21 @@
ViewRifleSkin(Renderer @r, AudioDevice @dev) {
super(r);
@audioDevice = dev;
@gunModel = renderer.RegisterModel
("Models/Weapons/Rifle/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel
("Models/Weapons/Rifle/Magazine.kv6");
@sightModel1 = renderer.RegisterModel
("Models/Weapons/Rifle/Sight1.kv6");
@sightModel2 = renderer.RegisterModel
("Models/Weapons/Rifle/Sight2.kv6");
@gunModel = renderer.RegisterModel("Models/Weapons/Rifle/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel("Models/Weapons/Rifle/Magazine.kv6");
@sightModel1 = renderer.RegisterModel("Models/Weapons/Rifle/Sight1.kv6");
@sightModel2 = renderer.RegisterModel("Models/Weapons/Rifle/Sight2.kv6");
@fireSound = dev.RegisterSound
("Sounds/Weapons/Rifle/FireLocal.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/Rifle/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/Rifle/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/Rifle/ReloadLocal.opus");
@fireSound = dev.RegisterSound("Sounds/Weapons/Rifle/FireLocal.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/Rifle/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/Rifle/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/Rifle/ReloadLocal.opus");
@fireSmallReverbSound = dev.RegisterSound
("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound
("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
@fireSmallReverbSound = dev.RegisterSound("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
}
void Update(float dt) {
BasicViewWeapon::Update(dt);
}
void Update(float dt) { BasicViewWeapon::Update(dt); }
void WeaponFired() {
BasicViewWeapon::WeaponFired();
@ -100,9 +86,7 @@
}
}
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.0520f;
}
float GetZPos() { return 0.2f - AimDownSightStateSmooth * 0.0520f; }
// rotates gun matrix to ensure the sight is in
// the center of screen (0, ?, 0).
@ -135,13 +119,14 @@
Vector3 rightHand4 = mat * Vector3(-3.f, -4.f, -6.f);
if (AimDownSightStateSmooth > 0.8f) {
mat = AdjustToAlignSight(mat, Vector3(0.f, 16.f, -4.6f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
mat = AdjustToAlignSight(mat, Vector3(0.f, 16.f, -4.6f),
(AimDownSightStateSmooth - 0.8f) / 0.2f);
}
ModelRenderParam param;
Matrix4 weapMatrix = eyeMatrix * mat;
param.matrix = weapMatrix * CreateScaleMatrix(0.5f) *
CreateTranslateMatrix(-0.5f, 0.f, 0.f);
param.matrix =
weapMatrix * CreateScaleMatrix(0.5f) * CreateTranslateMatrix(-0.5f, 0.f, 0.f);
param.depthHack = true;
renderer.AddModel(gunModel, param);
@ -165,15 +150,14 @@
if (reload < 0.1f) {
// move hand to magazine
float per = reload / 0.1f;
leftHand = Mix(leftHand,
mat * Vector3(0.f, 0.f, 4.f),
SmoothStep(per));
leftHand = Mix(leftHand, mat * Vector3(0.f, 0.f, 4.f), SmoothStep(per));
} else if (reload < 0.7f) {
// magazine release
float per = (reload - 0.1f) / 0.6f;
if (per < 0.2f) {
// non-smooth pull out
per *= 4.0f; per -= 0.4f;
per *= 4.0f;
per -= 0.4f;
per = Clamp(per, 0.0f, 0.2f);
}
if (per > 0.5f) {
@ -193,7 +177,8 @@
float per = (1.4f - reload) / 0.7f;
if (per < 0.3f) {
// non-smooth insertion
per *= 4.f; per -= 0.4f;
per *= 4.f;
per -= 0.4f;
per = Clamp(per, 0.0f, 0.3f);
}

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonSMGSkin:
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
class ThirdPersonSMGSkin : IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -106,62 +105,54 @@
ThirdPersonSMGSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/SMG/Weapon.kv6");
@model = renderer.RegisterModel("Models/Weapons/SMG/Weapon.kv6");
@fireMediumSounds[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2Third1.opus");
@fireMediumSounds[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2Third2.opus");
@fireMediumSounds[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2Third3.opus");
@fireMediumSounds[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2Third4.opus");
@fireMediumSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Third1.opus");
@fireMediumSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Third2.opus");
@fireMediumSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Third3.opus");
@fireMediumSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Third4.opus");
@fireSmallReverbSounds
[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
@fireSmallReverbSounds
[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
@fireSmallReverbSounds
[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
@fireSmallReverbSounds
[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
@fireSmallReverbSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
@fireSmallReverbSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
@fireSmallReverbSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
@fireSmallReverbSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
@fireLargeReverbSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
@fireLargeReverbSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
@fireLargeReverbSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
@fireLargeReverbSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/SMG/Reload.opus");
@fireLargeReverbSounds
[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
@fireLargeReverbSounds
[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
@fireLargeReverbSounds
[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
@fireLargeReverbSounds
[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/SMG/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/SMG/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/SMG/Reload.opus");
}
void Update(float dt) {
}
void Update(float dt) {}
void WeaponFired() {
if (!muted) {
Vector3 origin = soundOrigin;
AudioParam param;
param.volume = 9.f;
audioDevice.Play(fireMediumSounds[GetRandom(fireMediumSounds.length)], origin, param);
audioDevice.Play(fireMediumSounds[GetRandom(fireMediumSounds.length)], origin,
param);
param.volume = 8.f * environmentRoom;
param.referenceDistance = 10.f;
if (environmentSize < 0.5f) {
audioDevice.Play(fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)], origin, param);
audioDevice.Play(fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)],
origin, param);
} else {
audioDevice.Play(fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)], origin, param);
audioDevice.Play(fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)],
origin, param);
}
param.volume = .4f;
@ -169,7 +160,6 @@
audioDevice.Play(fireFarSound, origin, param);
param.referenceDistance = 1.f;
audioDevice.Play(fireStereoSound, origin, param);
}
}
void ReloadingWeapon() {
@ -181,8 +171,7 @@
}
}
void ReloadedWeapon() {
}
void ReloadedWeapon() {}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.05f);

View File

@ -19,9 +19,7 @@
*/
namespace spades {
class ViewSMGSkin:
IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2,
BasicViewWeapon {
class ViewSMGSkin : IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2, BasicViewWeapon {
private AudioDevice @audioDevice;
private Model @gunModel;
@ -40,55 +38,40 @@
ViewSMGSkin(Renderer @r, AudioDevice @dev) {
super(r);
@audioDevice = dev;
@gunModel = renderer.RegisterModel
("Models/Weapons/SMG/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel
("Models/Weapons/SMG/Magazine.kv6");
@sightModel1 = renderer.RegisterModel
("Models/Weapons/SMG/Sight1.kv6");
@sightModel2 = renderer.RegisterModel
("Models/Weapons/SMG/Sight2.kv6");
@sightModel3 = renderer.RegisterModel
("Models/Weapons/SMG/Sight3.kv6");
@gunModel = renderer.RegisterModel("Models/Weapons/SMG/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel("Models/Weapons/SMG/Magazine.kv6");
@sightModel1 = renderer.RegisterModel("Models/Weapons/SMG/Sight1.kv6");
@sightModel2 = renderer.RegisterModel("Models/Weapons/SMG/Sight2.kv6");
@sightModel3 = renderer.RegisterModel("Models/Weapons/SMG/Sight3.kv6");
@fireSmallReverbSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
@fireSmallReverbSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
@fireSmallReverbSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
@fireSmallReverbSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
@fireSmallReverbSounds
[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
@fireSmallReverbSounds
[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
@fireSmallReverbSounds
[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
@fireSmallReverbSounds
[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
@fireLargeReverbSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
@fireLargeReverbSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
@fireLargeReverbSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
@fireLargeReverbSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
@fireSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Local1.opus");
@fireSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Local2.opus");
@fireSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Local3.opus");
@fireSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/V2Local4.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/SMG/ReloadLocal.opus");
@fireLargeReverbSounds
[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
@fireLargeReverbSounds
[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
@fireLargeReverbSounds
[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
@fireLargeReverbSounds
[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
@fireSounds[0] = dev.RegisterSound("Sounds/Weapons/SMG/V2Local1.opus");
@fireSounds[1] = dev.RegisterSound("Sounds/Weapons/SMG/V2Local2.opus");
@fireSounds[2] = dev.RegisterSound("Sounds/Weapons/SMG/V2Local3.opus");
@fireSounds[3] = dev.RegisterSound("Sounds/Weapons/SMG/V2Local4.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/SMG/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/SMG/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/SMG/ReloadLocal.opus");
}
void Update(float dt) {
BasicViewWeapon::Update(dt);
}
void Update(float dt) { BasicViewWeapon::Update(dt); }
void WeaponFired() {
BasicViewWeapon::WeaponFired();
@ -101,9 +84,13 @@
param.volume = 8.f * environmentRoom;
if (environmentSize < 0.5f) {
audioDevice.PlayLocal(fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)], origin, param);
audioDevice.PlayLocal(
fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)], origin,
param);
} else {
audioDevice.PlayLocal(fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)], origin, param);
audioDevice.PlayLocal(
fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)], origin,
param);
}
}
}
@ -117,9 +104,7 @@
}
}
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.038f;
}
float GetZPos() { return 0.2f - AimDownSightStateSmooth * 0.038f; }
// rotates gun matrix to ensure the sight is in
// the center of screen (0, ?, 0).
@ -152,7 +137,8 @@
Vector3 leftHand4 = mat * Vector3(1.f, 9.f, -6.f);
if (AimDownSightStateSmooth > 0.8f) {
mat = AdjustToAlignSight(mat, Vector3(0.f, 5.f, -4.9f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
mat = AdjustToAlignSight(mat, Vector3(0.f, 5.f, -4.9f),
(AimDownSightStateSmooth - 0.8f) / 0.2f);
}
ModelRenderParam param;
@ -194,7 +180,8 @@
float per = (1.4f - reload) / 0.7f;
if (per < 0.3f) {
// non-smooth insertion
per *= 4.f; per -= 0.4f;
per *= 4.f;
per -= 0.4f;
per = Clamp(per, 0.0f, 0.3f);
}
@ -221,10 +208,7 @@
LeftHandPosition = leftHand;
RightHandPosition = rightHand;
}
}
IWeaponSkin@ CreateViewSMGSkin(Renderer@ r, AudioDevice@ dev) {
return ViewSMGSkin(r, dev);
}
IWeaponSkin @CreateViewSMGSkin(Renderer @r, AudioDevice @dev) { return ViewSMGSkin(r, dev); }
}

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonShotgunSkin:
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
class ThirdPersonShotgunSkin : IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -107,28 +106,21 @@
ThirdPersonShotgunSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Shotgun/Weapon.kv6");
@model = renderer.RegisterModel("Models/Weapons/Shotgun/Weapon.kv6");
@fireSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/Fire.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/Reload.opus");
@cockSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/Cock.opus");
@fireSound = dev.RegisterSound("Sounds/Weapons/Shotgun/Fire.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/Shotgun/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/Shotgun/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/Shotgun/Reload.opus");
@cockSound = dev.RegisterSound("Sounds/Weapons/Shotgun/Cock.opus");
@fireSmallReverbSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
@fireSmallReverbSound
= dev.RegisterSound("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
@fireLargeReverbSound
= dev.RegisterSound("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
}
void Update(float dt) {
}
void Update(float dt) {}
void WeaponFired() {
if (!muted) {
@ -149,7 +141,6 @@
audioDevice.Play(fireFarSound, origin, param);
param.referenceDistance = 1.f;
audioDevice.Play(fireStereoSound, origin, param);
}
}
void ReloadingWeapon() {

View File

@ -19,9 +19,7 @@
*/
namespace spades {
class ViewShotgunSkin:
IToolSkin, IViewToolSkin, IWeaponSkin,
BasicViewWeapon {
class ViewShotgunSkin : IToolSkin, IViewToolSkin, IWeaponSkin, BasicViewWeapon {
private AudioDevice @audioDevice;
private Model @gunModel;
@ -40,35 +38,24 @@
ViewShotgunSkin(Renderer @r, AudioDevice @dev) {
super(r);
@audioDevice = dev;
@gunModel = renderer.RegisterModel
("Models/Weapons/Shotgun/WeaponNoPump.kv6");
@pumpModel = renderer.RegisterModel
("Models/Weapons/Shotgun/Pump.kv6");
@sightModel1 = renderer.RegisterModel
("Models/Weapons/Shotgun/Sight1.kv6");
@sightModel2 = renderer.RegisterModel
("Models/Weapons/Shotgun/Sight2.kv6");
@gunModel = renderer.RegisterModel("Models/Weapons/Shotgun/WeaponNoPump.kv6");
@pumpModel = renderer.RegisterModel("Models/Weapons/Shotgun/Pump.kv6");
@sightModel1 = renderer.RegisterModel("Models/Weapons/Shotgun/Sight1.kv6");
@sightModel2 = renderer.RegisterModel("Models/Weapons/Shotgun/Sight2.kv6");
@fireSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/FireLocal.opus");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/FireFar.opus");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/FireStereo.opus");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/ReloadLocal.opus");
@cockSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/CockLocal.opus");
@fireSound = dev.RegisterSound("Sounds/Weapons/Shotgun/FireLocal.opus");
@fireFarSound = dev.RegisterSound("Sounds/Weapons/Shotgun/FireFar.opus");
@fireStereoSound = dev.RegisterSound("Sounds/Weapons/Shotgun/FireStereo.opus");
@reloadSound = dev.RegisterSound("Sounds/Weapons/Shotgun/ReloadLocal.opus");
@cockSound = dev.RegisterSound("Sounds/Weapons/Shotgun/CockLocal.opus");
@fireSmallReverbSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
@fireLargeReverbSound = dev.RegisterSound
("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
@fireSmallReverbSound
= dev.RegisterSound("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
@fireLargeReverbSound
= dev.RegisterSound("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
}
void Update(float dt) {
BasicViewWeapon::Update(dt);
}
void Update(float dt) { BasicViewWeapon::Update(dt); }
void WeaponFired() {
BasicViewWeapon::WeaponFired();
@ -110,9 +97,7 @@
}
}
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.0535f;
}
float GetZPos() { return 0.2f - AimDownSightStateSmooth * 0.0535f; }
// rotates gun matrix to ensure the sight is in
// the center of screen (0, ?, 0).
@ -173,24 +158,20 @@
if (reloading) {
if (reload < 0.2f) {
float per = reload / 0.2f;
leftHand = Mix(leftHand, leftHand2,
SmoothStep(per));
leftHand = Mix(leftHand, leftHand2, SmoothStep(per));
} else if (reload < 0.35f) {
float per = (reload - 0.2f) / 0.15f;
leftHand = Mix(leftHand2, leftHand3,
SmoothStep(per));
leftHand = Mix(leftHand2, leftHand3, SmoothStep(per));
} else if (reload < 0.5f) {
float per = (reload - 0.35f) / 0.15f;
leftHand = Mix(leftHand3, leftHand,
SmoothStep(per));
leftHand = Mix(leftHand3, leftHand, SmoothStep(per));
}
}
// motion blending parameter
float cockFade = 1.f;
if (reloading) {
if(reload < 0.25f ||
ammo < (clipSize - 1)) {
if (reload < 0.25f || ammo < (clipSize - 1)) {
cockFade = 0.f;
} else {
cockFade = (reload - 0.25f) * 10.f;
@ -230,8 +211,7 @@
cock *= cockFade;
mat = mat * CreateTranslateMatrix(0.f, cock * -1.5f, 0.f);
leftHand = Mix(leftHand,
mat * Vector3(0.f, 4.f, 2.f), cockFade);
leftHand = Mix(leftHand, mat * Vector3(0.f, 4.f, 2.f), cockFade);
}
param.matrix = eyeMatrix * mat;

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ThirdPersonSpadeSkin:
IToolSkin, IThirdPersonToolSkin, ISpadeSkin {
class ThirdPersonSpadeSkin : IToolSkin, IThirdPersonToolSkin, ISpadeSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -76,21 +75,17 @@
ThirdPersonSpadeSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Spade/Spade.kv6");
@model = renderer.RegisterModel("Models/Weapons/Spade/Spade.kv6");
}
void Update(float dt) {
}
void Update(float dt) {}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.05f);
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), Pi) * mat;
mat = CreateTranslateMatrix(0.35f, -1.f, 0.f) * mat;
ModelRenderParam param;
param.matrix = originMatrix * mat;
renderer.AddModel(model, param);

View File

@ -19,8 +19,7 @@
*/
namespace spades {
class ViewSpadeSkin:
IToolSkin, IViewToolSkin, ISpadeSkin {
class ViewSpadeSkin : IToolSkin, IViewToolSkin, ISpadeSkin {
private float sprintState;
private float raiseState;
private Vector3 teamColor;
@ -60,14 +59,10 @@
}
Vector3 LeftHandPosition {
get {
return leftHand;
}
get { return leftHand; }
}
Vector3 RightHandPosition {
get {
return rightHand;
}
get { return rightHand; }
}
SpadeActionType ActionType {
@ -86,10 +81,8 @@
ViewSpadeSkin(Renderer @r, AudioDevice @dev) {
@renderer = r;
@audioDevice = dev;
@model = renderer.RegisterModel
("Models/Weapons/Spade/Spade.kv6");
@sightImage = renderer.RegisterImage
("Gfx/Sight.tga");
@model = renderer.RegisterModel("Models/Weapons/Spade/Spade.kv6");
@sightImage = renderer.RegisterImage("Gfx/Sight.tga");
}
void Update(float dt) {
@ -106,10 +99,8 @@
if (actionType == spades::SpadeActionType::Bash) {
float per = 1.f - actionProgress;
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f),
per * 1.7f) * mat;
mat = CreateTranslateMatrix(0.f, per * 0.3f, 0.f)
* mat;
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f), per * 1.7f) * mat;
mat = CreateTranslateMatrix(0.f, per * 0.3f, 0.f) * mat;
} else if (actionType == spades::SpadeActionType::DigStart ||
actionType == spades::SpadeActionType::Dig) {
bool first = actionType == spades::SpadeActionType::DigStart;
@ -135,7 +126,8 @@
// soon after digging
angle = readyAngle;
per = (0.5f - per) / 0.5f;
per *= per; per *= per;
per *= per;
per *= per;
angle += per * digAngle;
front += per * 2.0f;
}
@ -146,24 +138,19 @@
front += per * 2.f;
}
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f),
angle) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f),
front * 0.15f) * mat;
mat = CreateRotateMatrix(Vector3(1.f, 0.f, 0.f), angle) * mat;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), front * 0.15f) * mat;
side *= 0.3f;
front *= 0.1f;
mat = CreateTranslateMatrix(side, front, front * 0.2f)
* mat;
mat = CreateTranslateMatrix(side, front, front * 0.2f) * mat;
}
if (sprintStateSmooth > 0.f || raiseState < 1.f) {
float per = Max(sprintStateSmooth, 1.f - raiseState);
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f),
per * 1.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.3f, -0.4f, -0.1f) * per)
* mat;
mat = CreateRotateMatrix(Vector3(0.f, 1.f, 0.f), per * 1.3f) * mat;
mat = CreateTranslateMatrix(Vector3(0.3f, -0.4f, -0.1f) * per) * mat;
}
mat = CreateTranslateMatrix(0.f, (1.f - raiseState) * -0.3f, 0.f) * mat;
@ -188,7 +175,5 @@
}
}
ISpadeSkin@ CreateViewSpadeSkin(Renderer@ r, AudioDevice@ dev) {
return ViewSpadeSkin(r, dev);
}
ISpadeSkin @CreateViewSpadeSkin(Renderer @r, AudioDevice @dev) { return ViewSpadeSkin(r, dev); }
}

37
run-clang-format.ps1 Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env pwsh
param(
[string]$SourceDirectory = ".",
[string]$ClangFormat = "clang-format"
)
# TODO: Run clang-format on C++ source files
# Run clang-format on AngelScript source files
$ScriptDirectory = Join-Path $SourceDirectory "Resources" "Scripts"
$Scripts = Get-ChildItem -Recurse -Include "*.as" $ScriptDirectory
$I = 0
foreach ($Item in $Scripts) {
$Path = $Item.FullName
$TmpPath = $Path.Substring(0, $Path.Length - 3) + ".java"
# Make it pretend to be a Java source file (which clang-format understands)
# I didn't choose C++ mainly due to the difference in how accessibility is
# specified.
Copy-Item $Path $TmpPath
# Run clang-format
&$ClangFormat -i -style=file $TmpPath
# Rename it back
Move-Item -Force $TmpPath $Path
# Fix `@ this.`
$Text = Get-Content $Path
$Text = $Text.Replace("@ this.", "@this.")
Set-Content $Path $Text
$I += 1
Write-Progress -Activity "Running clang-format on AngelScript source files" `
-PercentComplete ($I / $Scripts.Count * 100)
}