Open source Star Ruler 2 source code!
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
import tabs.tabbar;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiPanel;
|
||||
import elements.MarkupTooltip;
|
||||
import dialogs.MessageDialog;
|
||||
import dialogs.QuestionDialog;
|
||||
import util.design_export;
|
||||
import icons;
|
||||
from tabs.DesignEditorTab import createDesignEditorTab;
|
||||
from community.DesignPage import createCommunityDesignPage;
|
||||
|
||||
class DesignElement : BaseGuiElement {
|
||||
GuiDownloadedBlueprint@ bp;
|
||||
GuiMarkupText@ description;
|
||||
GuiMarkupText@ curLine;
|
||||
const Design@ dsg;
|
||||
|
||||
GuiButton@ downloadProfile;
|
||||
GuiButton@ downloadEmpire;
|
||||
GuiButton@ editButton;
|
||||
|
||||
bool Hovered = false;
|
||||
|
||||
DesignElement(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
updateAbsolutePosition();
|
||||
_();
|
||||
}
|
||||
|
||||
DesignElement(IGuiElement@ parent, const recti& pos) {
|
||||
super(parent, pos);
|
||||
updateAbsolutePosition();
|
||||
_();
|
||||
}
|
||||
|
||||
void _() {
|
||||
@bp = GuiDownloadedBlueprint(this, recti());
|
||||
@description = GuiMarkupText(this, recti());
|
||||
description.flexHeight = false;
|
||||
@curLine = GuiMarkupText(this, recti());
|
||||
|
||||
@downloadEmpire = GuiButton(this, Alignment(Right-42, Top+8, Width=34, Height=34));
|
||||
downloadEmpire.style = SS_IconButton;
|
||||
downloadEmpire.setIcon(icons::Add);
|
||||
setMarkupTooltip(downloadEmpire, locale::TT_DOWNLOAD_TO_EMPIRE, width=400);
|
||||
|
||||
@downloadProfile = GuiButton(this, Alignment(Right-42, Top+8+40, Width=34, Height=34));
|
||||
downloadProfile.style = SS_IconButton;
|
||||
downloadProfile.setIcon(icons::Import);
|
||||
setMarkupTooltip(downloadProfile, locale::TT_DOWNLOAD_TO_PROFILE, width=400);
|
||||
|
||||
@editButton = GuiButton(this, Alignment(Right-42, Top+8+40+40, Width=34, Height=34));
|
||||
editButton.style = SS_IconButton;
|
||||
editButton.setIcon(icons::Edit);
|
||||
editButton.allowOtherButtons = true;
|
||||
setMarkupTooltip(editButton, locale::TT_DOWNLOAD_EDIT, width=400);
|
||||
}
|
||||
|
||||
void load(int id) {
|
||||
bp.load(id);
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
if(bp !is null) {
|
||||
int unit = min(size.height-8, size.width-8);
|
||||
bp.rect = recti_area(vec2i(4,4), vec2i(unit, unit));
|
||||
description.rect = recti_area(vec2i(12+unit, 4), vec2i(size.width-unit-24-42, size.height-42));
|
||||
curLine.rect = recti_area(vec2i(12+unit, size.height-34), vec2i(size.width-unit-24-42, 30));
|
||||
}
|
||||
}
|
||||
|
||||
void finishLoad(JSONNode@ root) {
|
||||
bp.finishLoad(root);
|
||||
}
|
||||
|
||||
void update() {
|
||||
@dsg = bp.dsg;
|
||||
if(dsg !is null) {
|
||||
string author = bp.author;
|
||||
if(author.length > 20)
|
||||
author = author.substr(0,17)+"...";
|
||||
string specLine = format(locale::COMMUNITY_DESIGN_SPEC, toString(dsg.size,0),
|
||||
bbescape(author), bbescape(bp.ctime));
|
||||
|
||||
string desc = bp.description;
|
||||
string name = dsg.name;
|
||||
uint len = 100;
|
||||
if(size.height > 150)
|
||||
len = 200;
|
||||
if(desc.length > len) {
|
||||
desc = desc.substr(0,len);
|
||||
desc += "...";
|
||||
}
|
||||
if(name.length > 36) {
|
||||
name = name.substr(0,36);
|
||||
name += "...";
|
||||
}
|
||||
|
||||
description.text = format("[font=Medium][color=$1]$2[/color][/font]\n"
|
||||
"[b]$3[/b]\n[i][color=#aaa]$4[/color][/i]",
|
||||
toString(dsg.color), bbescape(name),
|
||||
specLine, bbescape(desc, true));
|
||||
|
||||
curLine.text = format(locale::COMMUNITY_DESIGN_CURLINE, toString(bp.upvotes), toString(bp.commentCount));
|
||||
|
||||
updateAbsolutePosition();
|
||||
|
||||
downloadEmpire.disabled = dsg.hasFatalErrors();
|
||||
if(dsg.hasFatalErrors()) {
|
||||
string errors = locale::TT_DOWNLOAD_ERRORS;
|
||||
for(uint i = 0, cnt = dsg.errorCount; i < cnt; ++i)
|
||||
errors += "\n\n"+dsg.errors[i].text;
|
||||
setMarkupTooltip(downloadEmpire, errors, width=400);
|
||||
}
|
||||
else {
|
||||
setMarkupTooltip(downloadEmpire, locale::TT_DOWNLOAD_TO_EMPIRE, width=400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void showPage(bool bg) {
|
||||
if(bg)
|
||||
newTab(createCommunityDesignPage(bp.designId));
|
||||
else
|
||||
browseTab(ActiveTab, createCommunityDesignPage(bp.designId), true);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
if(evt.caller is this)
|
||||
Hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
if(evt.caller is this)
|
||||
Hovered = false;
|
||||
break;
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is downloadEmpire) {
|
||||
if(dsg !is null) {
|
||||
auto@ cls = playerEmpire.getDesignClass(locale::DOWNLOAD_DESIGN_CLASS, true);
|
||||
auto@ prev = playerEmpire.getDesign(dsg.name);
|
||||
if(prev !is null)
|
||||
playerEmpire.changeDesign(prev, dsg, cls);
|
||||
else
|
||||
playerEmpire.addDesign(cls, dsg);
|
||||
message(locale::SUCCESS_DOWNLOAD_TO_EMPIRE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is downloadProfile) {
|
||||
string fname = path_join(modProfile["designs"], dsg.name+".design");
|
||||
write_design(dsg, fname);
|
||||
message(locale::SUCCESS_DOWNLOAD_TO_PROFILE);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is editButton) {
|
||||
if(dsg !is null) {
|
||||
if(ctrlKey || evt.value == 2)
|
||||
newTab(createDesignEditorTab(dsg));
|
||||
else
|
||||
browseTab(ActiveTab, createDesignEditorTab(dsg), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this || source.isChildOf(this)) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
if(event.button == 0 || event.button == 2)
|
||||
return true;
|
||||
break;
|
||||
case MET_Button_Up:
|
||||
if(event.button == 0 || event.button == 2) {
|
||||
showPage(ctrlKey || event.button == 2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Color color;
|
||||
if(bp.dsg !is null)
|
||||
color = bp.dsg.color;
|
||||
if(bp.dsg !is dsg)
|
||||
update();
|
||||
|
||||
skin.draw(SS_PatternBox, SF_Normal, AbsolutePosition, color);
|
||||
if(Hovered)
|
||||
skin.draw(SS_SubtleGlow, SF_Normal, AbsolutePosition, color);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,194 @@
|
||||
import tabs.tabbar;
|
||||
import elements.GuiBlueprint;
|
||||
import community.DesignElement;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiPanel;
|
||||
import elements.MarkupTooltip;
|
||||
import icons;
|
||||
|
||||
class CommunityDesignList : Tab {
|
||||
WebData query;
|
||||
string listSpec;
|
||||
|
||||
int offset = 0;
|
||||
|
||||
GuiButton@ backButton;
|
||||
GuiText@ titleBox;
|
||||
|
||||
GuiButton@ prevButton;
|
||||
GuiButton@ nextButton;
|
||||
|
||||
GuiPanel@ panel;
|
||||
array<DesignElement@> elements;
|
||||
|
||||
bool loaded = true;
|
||||
bool loading = false;
|
||||
bool hasNextPage = false;
|
||||
int elementsInPage = 10;
|
||||
|
||||
CommunityDesignList(const string& spec) {
|
||||
@backButton = GuiButton(this, Alignment(Left+8, Top+8, Left+144, Height=50), locale::BACK);
|
||||
backButton.buttonIcon = icons::Back;
|
||||
|
||||
@titleBox = GuiText(this, Alignment(Left+164, Top+8, Right-8, Top+60));
|
||||
titleBox.font = FT_Medium;
|
||||
titleBox.stroke = colors::Black;
|
||||
|
||||
@prevButton = GuiButton(this, Alignment(Left+0.5f-152, Bottom-60, Left+0.5f-2, Bottom-8), locale::PREVIOUS);
|
||||
prevButton.disabled = true;
|
||||
prevButton.setIcon(icons::Previous);
|
||||
|
||||
@nextButton = GuiButton(this, Alignment(Left+0.5f+2, Bottom-60, Left+0.5f+152, Bottom-8), locale::NEXT);
|
||||
nextButton.disabled = true;
|
||||
nextButton.setIcon(icons::Next);
|
||||
|
||||
@panel = GuiPanel(this, Alignment(Left, Top+64, Right, Bottom-64));
|
||||
|
||||
updateAbsolutePosition();
|
||||
listSpec = spec;
|
||||
}
|
||||
|
||||
void reload() {
|
||||
load(listSpec);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
for(uint i = 0, cnt = elements.length; i < cnt; ++i)
|
||||
elements[i].remove();
|
||||
elements.length = 0;
|
||||
}
|
||||
|
||||
void load(const string& spec) {
|
||||
listSpec = spec;
|
||||
|
||||
if(!loading) {
|
||||
title = format(locale::COMMUNITY_TITLE, listSpec);
|
||||
titleBox.text = title;
|
||||
|
||||
int limit = getListCount();
|
||||
int page = offset / limit;
|
||||
webAPICall(format("$1?page=$2&limit=$3", spec, toString(page), toString(limit)), query);
|
||||
|
||||
loading = true;
|
||||
loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
void show() {
|
||||
if(!loading)
|
||||
reload();
|
||||
Tab::show();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
backButton.disabled = previous is null;
|
||||
prevButton.disabled = offset == 0 || loading;
|
||||
nextButton.disabled = hasNextPage || loading;
|
||||
|
||||
if(loading && !loaded && query.completed)
|
||||
finish();
|
||||
}
|
||||
|
||||
void finish() {
|
||||
loaded = true;
|
||||
loading = false;
|
||||
|
||||
for(uint i = 0, cnt = elements.length; i < cnt; ++i)
|
||||
elements[i].remove();
|
||||
elements.length = 0;
|
||||
|
||||
JSONTree tree;
|
||||
tree.parse(query.result);
|
||||
|
||||
if(!tree.root.isArray())
|
||||
return;
|
||||
|
||||
hasNextPage = tree.root.size() <= getListCount();
|
||||
elementsInPage = getListCount();
|
||||
prevButton.disabled = offset == 0;
|
||||
nextButton.disabled = hasNextPage;
|
||||
|
||||
int startx = (size.width - elemsPerRow*712) / 2;
|
||||
int y = 12;
|
||||
int x = startx;
|
||||
for(uint i = 0, cnt = min(tree.root.size(), getListCount()); i < cnt; ++i) {
|
||||
auto@ mem = tree.root[i];
|
||||
if(mem !is null && mem.isObject()) {
|
||||
DesignElement elem(panel, recti_area(x,y, 700,160));
|
||||
elem.finishLoad(mem);
|
||||
elements.insertLast(elem);
|
||||
|
||||
x += 712;
|
||||
if(x+712 >= size.width) {
|
||||
x = startx;
|
||||
y += 168;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xff83bcff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xff0077ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8d4969ff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Wiki;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabWiki);
|
||||
}
|
||||
|
||||
int get_elemsPerRow() {
|
||||
return size.width / 712;
|
||||
}
|
||||
|
||||
uint getListCount() {
|
||||
int rows = (size.height - 64 - 64 - 24) / 168;
|
||||
return clamp(elemsPerRow * rows, 3, 50);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is backButton) {
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is prevButton) {
|
||||
offset = max(0, offset-elementsInPage);
|
||||
clear();
|
||||
reload();
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is nextButton) {
|
||||
offset += elements.length;
|
||||
clear();
|
||||
reload();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_WikiBG, SF_Normal, AbsolutePosition);
|
||||
skin.draw(SS_PlainBox, SF_Normal, recti(AbsolutePosition.topLeft,
|
||||
vec2i(AbsolutePosition.botRight.x, AbsolutePosition.topLeft.y+64)));
|
||||
Tab::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createCommunityDesignList(const string& spec = "designs/recent") {
|
||||
return CommunityDesignList(spec);
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
import tabs.tabbar;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiPanel;
|
||||
import elements.MarkupTooltip;
|
||||
import dialogs.MessageDialog;
|
||||
import dialogs.QuestionDialog;
|
||||
import util.design_export;
|
||||
import icons;
|
||||
from tabs.DesignEditorTab import createDesignEditorTab;
|
||||
from tabs.WikiTab import LinkableMarkupText;
|
||||
|
||||
class CommunityDesign : Tab, QuestionDialogCallback {
|
||||
GuiDownloadedBlueprint@ bp;
|
||||
GuiText@ titleBox;
|
||||
GuiPanel@ headerPanel;
|
||||
GuiMarkupText@ header;
|
||||
GuiText@ linkTip;
|
||||
const Design@ dsg;
|
||||
|
||||
GuiButton@ backButton;
|
||||
GuiButton@ downloadProfile;
|
||||
GuiButton@ downloadEmpire;
|
||||
GuiButton@ editButton;
|
||||
|
||||
GuiButton@ votesButton;
|
||||
GuiButton@ commentsButton;
|
||||
|
||||
GuiButton@ deleteButton;
|
||||
|
||||
GuiSkinElement@ commentsBox;
|
||||
GuiPanel@ commentsPanel;
|
||||
GuiMarkupText@ comments;
|
||||
|
||||
GuiTextbox@ commentText;
|
||||
GuiButton@ commentSubmit;
|
||||
|
||||
WebData@ waitReload;
|
||||
|
||||
CommunityDesign(int id) {
|
||||
@bp = GuiDownloadedBlueprint(this, Alignment().fill());
|
||||
bp.showStats = true;
|
||||
bp.padding = recti(0,136,0,0);
|
||||
bp.load(id);
|
||||
bp.bp.hoverArcs = true;
|
||||
|
||||
@backButton = GuiButton(this, Alignment(Left+8, Top+8, Left+144, Height=50), locale::BACK);
|
||||
backButton.buttonIcon = icons::Back;
|
||||
|
||||
@downloadEmpire = GuiButton(this, Alignment(Right-208-260, Top+8, Right-264, Height=38), locale::DOWNLOAD_TO_EMPIRE);
|
||||
downloadEmpire.setIcon(icons::Add);
|
||||
setMarkupTooltip(downloadEmpire, locale::TT_DOWNLOAD_TO_EMPIRE, width=400);
|
||||
|
||||
@downloadProfile = GuiButton(this, Alignment(Right-208-260, Top+8+40, Right-264, Height=38), locale::DOWNLOAD_TO_PROFILE);
|
||||
downloadProfile.setIcon(icons::Import);
|
||||
setMarkupTooltip(downloadProfile, locale::TT_DOWNLOAD_TO_PROFILE, width=400);
|
||||
|
||||
@editButton = GuiButton(this, Alignment(Right-208-260, Top+8+40+40, Right-264, Height=38), locale::DOWNLOAD_EDIT);
|
||||
editButton.setIcon(icons::Edit);
|
||||
editButton.allowOtherButtons = true;
|
||||
setMarkupTooltip(editButton, locale::TT_DOWNLOAD_EDIT, width=400);
|
||||
|
||||
@deleteButton = GuiButton(this, Alignment(Left+8, Top+8+40+40, Left+144, Height=38), locale::DELETE);
|
||||
deleteButton.color = colors::Red;
|
||||
deleteButton.setIcon(icons::Delete);
|
||||
deleteButton.visible = false;
|
||||
|
||||
@headerPanel = GuiPanel(this, Alignment(Left+154, Top+8, Right-264-208-208, Top+135));
|
||||
headerPanel.horizType = ST_Never;
|
||||
|
||||
@titleBox = GuiText(headerPanel, Alignment(Left, Top, Right, Top+38));
|
||||
titleBox.font = FT_Big;
|
||||
titleBox.stroke = colors::Black;
|
||||
titleBox.vertAlign = 0.15;
|
||||
|
||||
@header = LinkableMarkupText(headerPanel, recti());
|
||||
@linkTip = GuiText(headerPanel, recti());
|
||||
linkTip.font = FT_Italic;
|
||||
linkTip.color = Color(0x8888aaff);
|
||||
|
||||
@votesButton = GuiButton(this, Alignment(Right-208-260-208+50, Top+20, Width=100, Height=50), locale::VOTES_BUTTON);
|
||||
votesButton.font = FT_Medium;
|
||||
votesButton.textColor = colors::Green;
|
||||
votesButton.setIcon(icons::Upvote);
|
||||
setMarkupTooltip(votesButton, locale::TT_VOTES_BUTTON);
|
||||
|
||||
@commentsBox = GuiSkinElement(this, Alignment(Right-250-500, Top+136, Right-250, Bottom), SS_PlainBox);
|
||||
commentsBox.visible = false;
|
||||
|
||||
@commentsPanel = GuiPanel(commentsBox, Alignment(Left, Top, Right, Bottom-100));
|
||||
|
||||
@comments = LinkableMarkupText(commentsPanel, recti_area(6,6,472,100));
|
||||
|
||||
@commentText = GuiTextbox(commentsBox, Alignment(Left+4, Bottom-100, Right-4, Bottom-40));
|
||||
commentText.emptyText = locale::COMMENT_TEXT;
|
||||
commentText.multiLine = true;
|
||||
|
||||
@commentSubmit = GuiButton(commentsBox, Alignment(Right-200, Bottom-38, Right-4, Bottom-4), locale::COMMENT_SUBMIT);
|
||||
commentSubmit.buttonIcon = icons::Chat;
|
||||
|
||||
@commentsButton = GuiButton(this, Alignment(Right-208-260-208, Top+8+40+40, Width=200, Height=38),
|
||||
locale::COMMENTS_BUTTON);
|
||||
commentsButton.font = FT_Bold;
|
||||
commentsButton.toggleButton = true;
|
||||
commentsButton.setIcon(icons::Chat);
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
Tab::updateAbsolutePosition();
|
||||
if(header !is null)
|
||||
header.rect = recti_area(vec2i(0,36), vec2i(headerPanel.size.width-20, header.size.height));
|
||||
if(linkTip !is null)
|
||||
linkTip.rect = recti_area(vec2i(0, header.rect.botRight.y), vec2i(headerPanel.size.width, 26));
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xff83bcff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xff0077ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8d4969ff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Wiki;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabWiki);
|
||||
}
|
||||
|
||||
void reload() {
|
||||
bp.load(bp.designId);
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(waitReload !is null && waitReload.completed) {
|
||||
reload();
|
||||
@waitReload = null;
|
||||
}
|
||||
|
||||
backButton.disabled = previous is null;
|
||||
commentsBox.visible = commentsButton.pressed;
|
||||
commentSubmit.disabled = commentText.text.length == 0;
|
||||
bp.update();
|
||||
|
||||
if(dsg !is bp.dsg) {
|
||||
@dsg = bp.dsg;
|
||||
|
||||
if(dsg !is null) {
|
||||
title = format(locale::COMMUNITY_TITLE, dsg.name);
|
||||
titleBox.text = dsg.name;
|
||||
titleBox.color = dsg.color;
|
||||
|
||||
votesButton.text = format(locale::VOTES_BUTTON, toString(bp.upvotes));
|
||||
votesButton.disabled = bp.hasUpvoted;
|
||||
if(votesButton.disabled)
|
||||
setMarkupTooltip(votesButton, "");
|
||||
else
|
||||
setMarkupTooltip(votesButton, locale::TT_VOTES_BUTTON);
|
||||
|
||||
string hstr = format(locale::COMMUNITY_DESIGN_SPEC, toString(dsg.size,0), bbescape(bp.author), bbescape(bp.ctime));
|
||||
hstr = format("[b]$1[/b]\n[i][color=#aaa]", hstr);
|
||||
hstr += bbescape(bp.description, true);
|
||||
hstr += "[/color][/i]";
|
||||
header.text = hstr;
|
||||
|
||||
linkTip.text = format(locale::DESIGN_LINK_TIP, toString(bp.designId));
|
||||
|
||||
downloadEmpire.disabled = dsg.hasFatalErrors();
|
||||
if(dsg.hasFatalErrors()) {
|
||||
string errors = locale::TT_DOWNLOAD_ERRORS;
|
||||
for(uint i = 0, cnt = dsg.errorCount; i < cnt; ++i)
|
||||
errors += "\n\n"+dsg.errors[i].text;
|
||||
setMarkupTooltip(downloadEmpire, errors, width=400);
|
||||
}
|
||||
else {
|
||||
setMarkupTooltip(downloadEmpire, locale::TT_DOWNLOAD_TO_EMPIRE, width=400);
|
||||
}
|
||||
|
||||
deleteButton.visible = bp.isMine;
|
||||
|
||||
commentsButton.text = format(locale::COMMENTS_BUTTON, toString(bp.commentCount));
|
||||
string cstr;
|
||||
for(uint i = 0, cnt = bp.comments.length; i < cnt; ++i) {
|
||||
auto@ c = bp.comments[i];
|
||||
cstr += format("[font=Subtitle]$1[color=#aaa] on $2[/color][/font]\n[vspace=6/][offset=20]",
|
||||
bbescape(c.author), bbescape(c.ctime));
|
||||
cstr += bbescape(c.content, true);
|
||||
cstr += "[/offset]\n\n";
|
||||
}
|
||||
|
||||
comments.text = cstr;
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
else {
|
||||
titleBox.text = "---";
|
||||
title = "---";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void questionCallback(QuestionDialog@ dialog, int answer) {
|
||||
if(answer == QA_Yes) {
|
||||
WebData dat;
|
||||
dat.addPost("delete", "true");
|
||||
webAPICall("design/"+bp.designId+"/delete", dat);
|
||||
while(!dat.completed)
|
||||
sleep(100);
|
||||
popTab(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is backButton) {
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is votesButton) {
|
||||
WebData dat;
|
||||
dat.addPost("vote", "true");
|
||||
webAPICall("design/"+bp.designId+"/vote", dat);
|
||||
|
||||
votesButton.text = format(locale::VOTES_BUTTON, toString(bp.upvotes+1));
|
||||
votesButton.disabled = true;
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is deleteButton) {
|
||||
question(locale::COMMUNITY_CONFIRM_DELETE_DESIGN, this);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is commentSubmit) {
|
||||
if(commentText.text.length > 0 ){
|
||||
WebData dat;
|
||||
dat.addPost("author", settings::sNickname);
|
||||
dat.addPost("content", commentText.text);
|
||||
webAPICall("design/"+bp.designId+"/comment", dat);
|
||||
|
||||
commentText.text = "";
|
||||
@waitReload = dat;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is downloadEmpire) {
|
||||
if(dsg !is null) {
|
||||
auto@ cls = playerEmpire.getDesignClass(locale::DOWNLOAD_DESIGN_CLASS, true);
|
||||
auto@ prev = playerEmpire.getDesign(dsg.name);
|
||||
if(prev !is null)
|
||||
playerEmpire.changeDesign(prev, dsg, cls);
|
||||
else
|
||||
playerEmpire.addDesign(cls, dsg);
|
||||
message(locale::SUCCESS_DOWNLOAD_TO_EMPIRE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is downloadProfile) {
|
||||
string fname = path_join(modProfile["designs"], dsg.name+".design");
|
||||
write_design(dsg, fname);
|
||||
message(locale::SUCCESS_DOWNLOAD_TO_PROFILE);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is editButton) {
|
||||
if(dsg !is null) {
|
||||
if(ctrlKey || evt.value == 2)
|
||||
newTab(createDesignEditorTab(dsg));
|
||||
else
|
||||
browseTab(this, createDesignEditorTab(dsg), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_WikiBG, SF_Normal, AbsolutePosition);
|
||||
skin.draw(SS_PlainBox, SF_Normal, recti(AbsolutePosition.topLeft,
|
||||
vec2i(AbsolutePosition.botRight.x-250, AbsolutePosition.topLeft.y+136)));
|
||||
Tab::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createCommunityDesignPage(int id) {
|
||||
return CommunityDesign(id);
|
||||
}
|
||||
|
||||
class CommunityDesignCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
auto@ page = createCommunityDesignPage(toInt(args));
|
||||
newTab(page);
|
||||
switchToTab(page);
|
||||
}
|
||||
};
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("design_page", CommunityDesignCommand());
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
import tabs.tabbar;
|
||||
import elements.GuiBlueprint;
|
||||
import community.DesignElement;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiDropdown;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.MarkupTooltip;
|
||||
import dialogs.Dialog;
|
||||
import util.formatting;
|
||||
from tabs.WikiTab import LinkableMarkupText;
|
||||
from community.DesignList import createCommunityDesignList;
|
||||
from community.DesignPage import createCommunityDesignPage;
|
||||
import icons;
|
||||
|
||||
class CommunityHome : Tab {
|
||||
WebData query;
|
||||
WebData wiki;
|
||||
string listSpec;
|
||||
|
||||
BaseGuiElement@ container;
|
||||
|
||||
GuiBackgroundPanel@ designBG;
|
||||
GuiPanel@ panel;
|
||||
array<DesignElement@> elements;
|
||||
|
||||
GuiBackgroundPanel@ wikiBG;
|
||||
GuiPanel@ wikiPanel;
|
||||
LinkableMarkupText@ wikiText;
|
||||
|
||||
GuiButton@ uploadButton;
|
||||
GuiButton@ recentDesigns;
|
||||
GuiButton@ topratedDesigns;
|
||||
GuiTextbox@ searchDesigns;
|
||||
GuiButton@ internetButton;
|
||||
|
||||
bool loaded = true;
|
||||
bool loading = false;
|
||||
|
||||
CommunityHome() {
|
||||
title = locale::COMMUNITY_HOME_TITLE;
|
||||
|
||||
@container = BaseGuiElement(this, Alignment().fill());
|
||||
@internetButton = GuiButton(this, Alignment(Left+0.5f-200, Top+0.5f-30, Left+0.5f+200, Top+0.5f+30), locale::ENABLE_INTERNET);
|
||||
internetButton.visible = false;
|
||||
|
||||
@designBG = GuiBackgroundPanel(container, Alignment(Left+29, Top+35, Left+35+600+48, Bottom-80));
|
||||
designBG.title = locale::FEATURED_DESIGNS;
|
||||
designBG.titleColor = colors::FTL;
|
||||
designBG.titleHeight = 42;
|
||||
designBG.titleFont = FT_Big;
|
||||
|
||||
@panel = GuiPanel(designBG, Alignment(Left+4, Top+42, Right-4, Bottom-8));
|
||||
|
||||
@uploadButton = GuiButton(container, Alignment(Left+34+600+48-200, Bottom-72, Width=200, Height=52), locale::UPLOAD_DESIGN);
|
||||
uploadButton.font = FT_Bold;
|
||||
uploadButton.setIcon(icons::Export);
|
||||
|
||||
@recentDesigns = GuiButton(container, Alignment(Left+30+600+48-424, Bottom-75, Width=200, Height=30), locale::RECENT_DESIGNS);
|
||||
|
||||
@topratedDesigns = GuiButton(container, Alignment(Left+30+600+48-424, Bottom-75+32, Width=200, Height=30), locale::TOPRATED_DESIGNS);
|
||||
|
||||
@searchDesigns = GuiTextbox(container, Alignment(Left+30, Bottom-69, Width=200, Height=46));
|
||||
searchDesigns.emptyText = locale::SEARCH_DESIGNS_PROMPT;
|
||||
|
||||
@wikiBG = GuiBackgroundPanel(container, Alignment(Left+30+600+48+30, Top+30, Right-30, Bottom-30));
|
||||
wikiBG.title = locale::COMMUNITY_WIKI;
|
||||
wikiBG.titleColor = colors::Research;
|
||||
wikiBG.titleHeight = 42;
|
||||
wikiBG.titleFont = FT_Big;
|
||||
|
||||
@wikiPanel = GuiPanel(wikiBG, Alignment(Left+4, Top+42, Right-4, Bottom-12));
|
||||
|
||||
@wikiText = LinkableMarkupText(wikiPanel, recti_area(12,12, 100,100), true);
|
||||
|
||||
if(cloud::isActive)
|
||||
settings::bEnableInternet = true;
|
||||
|
||||
updateAbsolutePosition();
|
||||
listSpec = "designs/featured";
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
Tab::updateAbsolutePosition();
|
||||
if(wikiText.size.width != wikiPanel.size.width-44) {
|
||||
wikiText.size = vec2i(wikiPanel.size.width-44, wikiText.size.height);
|
||||
wikiText.updateAbsolutePosition();
|
||||
}
|
||||
}
|
||||
|
||||
void reload() {
|
||||
if(settings::bEnableInternet) {
|
||||
container.visible = true;
|
||||
internetButton.visible = false;
|
||||
|
||||
load(listSpec);
|
||||
}
|
||||
else {
|
||||
container.visible = false;
|
||||
internetButton.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
void load(const string& spec) {
|
||||
listSpec = spec;
|
||||
webAPICall(spec, query);
|
||||
|
||||
getWikiPage("Main Page", wiki);
|
||||
|
||||
loading = true;
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
void show() {
|
||||
if(!loading)
|
||||
reload();
|
||||
Tab::show();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(loading && !loaded && query.completed && wiki.completed)
|
||||
finish();
|
||||
}
|
||||
|
||||
void finish() {
|
||||
loaded = true;
|
||||
loading = false;
|
||||
|
||||
wikiText.text = wiki.result;
|
||||
|
||||
for(uint i = 0, cnt = elements.length; i < cnt; ++i)
|
||||
elements[i].remove();
|
||||
elements.length = 0;
|
||||
|
||||
JSONTree tree;
|
||||
tree.parse(query.result);
|
||||
|
||||
if(!tree.root.isArray())
|
||||
return;
|
||||
|
||||
int y = 12;
|
||||
for(uint i = 0, cnt = min(tree.root.size(), panel.size.height / 138); i < cnt; ++i) {
|
||||
auto@ mem = tree.root[i];
|
||||
if(mem !is null && mem.isObject()) {
|
||||
DesignElement elem(panel, recti_area(20,y, 600,130));
|
||||
elem.finishLoad(mem);
|
||||
elements.insertLast(elem);
|
||||
y += 138;
|
||||
}
|
||||
}
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xff83bcff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xff0077ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8d4969ff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Wiki;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabWiki);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is recentDesigns) {
|
||||
browseTab(this, createCommunityDesignList("designs/recent"), true);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is topratedDesigns) {
|
||||
browseTab(this, createCommunityDesignList("designs/toprated"), true);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is uploadButton) {
|
||||
UploadDialog(this);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is internetButton) {
|
||||
settings::bEnableInternet = true;
|
||||
saveSettings();
|
||||
reload();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(evt.type == GUI_Confirmed) {
|
||||
if(evt.caller is searchDesigns) {
|
||||
browseTab(this, createCommunityDesignList("designs/search/"+searchDesigns.text), true);
|
||||
searchDesigns.text = "";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_WikiBG, SF_Normal, AbsolutePosition);
|
||||
Tab::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class UploadDialog : Dialog {
|
||||
GuiDropdown@ design;
|
||||
GuiTextbox@ description;
|
||||
|
||||
GuiButton@ accept;
|
||||
GuiButton@ cancel;
|
||||
|
||||
array<const Design@> designs;
|
||||
|
||||
UploadDialog(IGuiElement@ bind) {
|
||||
super(bind, bindInside=true);
|
||||
width = 600;
|
||||
height = 200;
|
||||
|
||||
@accept = GuiButton(bg, recti());
|
||||
accept.text = locale::UPLOAD;
|
||||
accept.tabIndex = 100;
|
||||
accept.disabled = true;
|
||||
@accept.callback = this;
|
||||
accept.color = colors::Green;
|
||||
|
||||
@cancel = GuiButton(bg, recti());
|
||||
cancel.text = locale::CANCEL;
|
||||
cancel.tabIndex = 101;
|
||||
@cancel.callback = this;
|
||||
cancel.color = colors::Red;
|
||||
|
||||
@design = GuiDropdown(bg, Alignment(Left+12, Top+40, Right-12, Top+76));
|
||||
|
||||
ReadLock lck(playerEmpire.designMutex);
|
||||
uint cnt = playerEmpire.designCount;
|
||||
designs.reserve(cnt);
|
||||
designs.length = 0;
|
||||
design.addItem(locale::DESIGN_CHOOSE_PROMPT);
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
const Design@ other = playerEmpire.designs[i];
|
||||
if(other.obsolete || other.newest() !is other)
|
||||
continue;
|
||||
design.addItem(formatShipName(other));
|
||||
designs.insertLast(other);
|
||||
}
|
||||
|
||||
@description = GuiTextbox(bg, Alignment(Left+12, Top+80, Right-12, Bottom-46));
|
||||
description.multiLine = true;
|
||||
description.emptyText = locale::DESIGN_DESCRIPTION_PROMPT;
|
||||
|
||||
addTitle(locale::UPLOAD_DESIGN, color=colors::FTL);
|
||||
|
||||
alignAcceptButtons(accept, cancel);
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void update() {
|
||||
accept.disabled = design.selected < 1;
|
||||
}
|
||||
|
||||
void close() {
|
||||
close(false);
|
||||
}
|
||||
|
||||
void close(bool accepted) {
|
||||
if(accepted && design.selected >= 1) {
|
||||
int id = upload_design(designs[design.selected-1], description.text, waitId=true);
|
||||
if(id > 0)
|
||||
browseTab(ActiveTab, createCommunityDesignPage(id), true);
|
||||
}
|
||||
Dialog::close();
|
||||
}
|
||||
|
||||
void confirmDialog() {
|
||||
close(true);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(Closed)
|
||||
return false;
|
||||
if(event.type == GUI_Clicked && (event.caller is accept || event.caller is cancel)) {
|
||||
close(event.caller is accept);
|
||||
return true;
|
||||
}
|
||||
else if(event.type == GUI_Changed) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return Dialog::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createCommunityHome() {
|
||||
return CommunityHome();
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
#priority init 10
|
||||
|
||||
enum StatType {
|
||||
ST_Hex,
|
||||
ST_Subsystem,
|
||||
ST_Global,
|
||||
};
|
||||
|
||||
enum SysVariableType {
|
||||
SVT_SubsystemVariable,
|
||||
SVT_HexVariable,
|
||||
SVT_ShipVariable
|
||||
};
|
||||
|
||||
enum StatAggregate {
|
||||
SA_Sum,
|
||||
};
|
||||
|
||||
enum StatDisplayMode {
|
||||
SDM_Normal,
|
||||
SDM_Short,
|
||||
};
|
||||
|
||||
class DesignStat {
|
||||
uint index = 0;
|
||||
string ident;
|
||||
string name;
|
||||
string description;
|
||||
string suffix;
|
||||
Sprite icon;
|
||||
Color color;
|
||||
StatDisplayMode display = SDM_Normal;
|
||||
|
||||
int reqTag = -1;
|
||||
int secondary = -1;
|
||||
|
||||
StatType type;
|
||||
|
||||
SysVariableType varType;
|
||||
int variable;
|
||||
int usedVariable;
|
||||
|
||||
SysVariableType divType;
|
||||
int divVar = -1;
|
||||
|
||||
int importance;
|
||||
|
||||
StatAggregate aggregate;
|
||||
double defaultValue;
|
||||
|
||||
DesignStat() {
|
||||
importance = 0;
|
||||
aggregate = SA_Sum;
|
||||
varType = SVT_SubsystemVariable;
|
||||
defaultValue = 0;
|
||||
variable = -1;
|
||||
usedVariable = -1;
|
||||
}
|
||||
};
|
||||
|
||||
class DesignStats {
|
||||
DesignStat@[] stats;
|
||||
double[] values;
|
||||
double[] used;
|
||||
|
||||
void dump() {
|
||||
for(uint i = 0, cnt = stats.length; i < cnt; ++i)
|
||||
print(stats[i].name+": "+values[i]);
|
||||
}
|
||||
};
|
||||
|
||||
namespace design_stats {
|
||||
bool hasValue(const ::Design@ dsg, const ::Subsystem@ sys, ::DesignStat@ stat) {
|
||||
switch(stat.varType) {
|
||||
case ::SVT_HexVariable:
|
||||
return sys.has(::HexVariable(stat.variable));
|
||||
case ::SVT_SubsystemVariable:
|
||||
return sys.has(::SubsystemVariable(stat.variable)) && sys.variable(::SubsystemVariable(stat.variable)) != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double getValue(const Design@ dsg, const Subsystem@ sys, vec2u hex, SysVariableType type, int var, int aggregate = 0) {
|
||||
if(type == SVT_HexVariable) {
|
||||
if(hex != vec2u(uint(-1))) {
|
||||
return dsg.variable(hex, HexVariable(var));
|
||||
}
|
||||
else if(sys !is null) {
|
||||
double val = 0.0;
|
||||
for(uint i = 0, cnt = sys.hexCount; i < cnt; ++i) {
|
||||
switch(aggregate) {
|
||||
case ::SA_Sum:
|
||||
val += double(sys.hexVariable(HexVariable(var), i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
else {
|
||||
double val = 0.0;
|
||||
for(uint n = 0, ncnt = dsg.subsystemCount; n < ncnt; ++n) {
|
||||
auto@ sys = dsg.subsystem(n);
|
||||
if(sys.has(HexVariable(var))) {
|
||||
for(uint i = 0, cnt = sys.hexCount; i < cnt; ++i) {
|
||||
switch(aggregate) {
|
||||
case ::SA_Sum:
|
||||
val += double(sys.hexVariable(HexVariable(var), i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else if(type == SVT_SubsystemVariable) {
|
||||
if(sys !is null) {
|
||||
return dsg.variable(sys, SubsystemVariable(var));
|
||||
}
|
||||
else {
|
||||
double val = 0.0;
|
||||
for(uint n = 0, ncnt = dsg.subsystemCount; n < ncnt; ++n) {
|
||||
auto@ sys = dsg.subsystem(n);
|
||||
if(sys.has(SubsystemVariable(var))) {
|
||||
switch(aggregate) {
|
||||
case ::SA_Sum:
|
||||
val += double(dsg.variable(sys, SubsystemVariable(var)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else if(type == SVT_ShipVariable) {
|
||||
return dsg.variable(ShipVariable(var));
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
::DesignStat@[] hexStats;
|
||||
::DesignStat@[] sysStats;
|
||||
::DesignStat@[] globalStats;
|
||||
};
|
||||
|
||||
DesignStats@ getDesignStats(const Design@ dsg) {
|
||||
DesignStats stats;
|
||||
|
||||
uint sysCnt = dsg.subsystemCount;
|
||||
for(uint i = 0, cnt = design_stats::globalStats.length; i < cnt; ++i) {
|
||||
DesignStat@ stat = design_stats::globalStats[i];
|
||||
if(stat.reqTag != -1 && !dsg.hasTag(SubsystemTag(stat.reqTag)))
|
||||
continue;
|
||||
bool has = false;
|
||||
double val = design_stats::getValue(dsg, null, vec2u(uint(-1)), stat.varType, stat.variable, stat.aggregate);
|
||||
double used = -1.0;
|
||||
if(stat.usedVariable != -1)
|
||||
used = design_stats::getValue(dsg, null, vec2u(uint(-1)), stat.varType, stat.usedVariable, stat.aggregate);
|
||||
if(stat.divVar != -1) {
|
||||
double div = design_stats::getValue(dsg, null, vec2u(uint(-1)), stat.divType, stat.divVar, stat.aggregate);
|
||||
if(div != 0.0)
|
||||
val /= div;
|
||||
}
|
||||
|
||||
if(val != 0.0) {
|
||||
stats.stats.insertLast(stat);
|
||||
stats.values.insertLast(val);
|
||||
stats.used.insertLast(used);
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
DesignStats@ getHexStats(const Design@ dsg, vec2u hex) {
|
||||
DesignStats stats;
|
||||
|
||||
const Subsystem@ sys = dsg.subsystem(hex);
|
||||
for(uint i = 0, cnt = design_stats::hexStats.length; i < cnt; ++i) {
|
||||
DesignStat@ stat = design_stats::hexStats[i];
|
||||
if(stat.reqTag != -1 && !dsg.hasTag(stat.reqTag))
|
||||
continue;
|
||||
if(design_stats::hasValue(dsg, sys, stat)) {
|
||||
float val = design_stats::getValue(dsg, sys, hex, stat.varType, stat.variable, stat.aggregate);
|
||||
if(val != 0.f) {
|
||||
stats.stats.insertLast(stat);
|
||||
stats.values.insertLast(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
DesignStats@ getSubsystemStats(const Design@ dsg, const Subsystem@ sys) {
|
||||
DesignStats stats;
|
||||
|
||||
for(uint i = 0, cnt = design_stats::sysStats.length; i < cnt; ++i) {
|
||||
DesignStat@ stat = design_stats::sysStats[i];
|
||||
if(stat.reqTag != -1 && !sys.type.hasTag(stat.reqTag))
|
||||
continue;
|
||||
if(design_stats::hasValue(dsg, sys, stat)) {
|
||||
float val = design_stats::getValue(dsg, sys, vec2u(uint(-1)),
|
||||
stat.varType, stat.variable, stat.aggregate);
|
||||
if(val != 0.f) {
|
||||
stats.stats.insertLast(stat);
|
||||
stats.values.insertLast(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
void loadStats(const string& filename) {
|
||||
//Load stat descriptors
|
||||
ReadFile file(filename);
|
||||
|
||||
DesignStat@ stat;
|
||||
array<DesignStat@>@ list;
|
||||
string key, value;
|
||||
while(file++) {
|
||||
key = file.key;
|
||||
value = file.value;
|
||||
|
||||
if(key == "HexStat") {
|
||||
@list = design_stats::hexStats;
|
||||
@stat = DesignStat();
|
||||
stat.type = ST_Hex;
|
||||
stat.ident = value;
|
||||
stat.display = SDM_Short;
|
||||
stat.index = design_stats::hexStats.length;
|
||||
design_stats::hexStats.insertLast(stat);
|
||||
}
|
||||
else if(key == "SubsystemStat") {
|
||||
@list = design_stats::sysStats;
|
||||
@stat = DesignStat();
|
||||
stat.ident = value;
|
||||
stat.type = ST_Subsystem;
|
||||
stat.display = SDM_Short;
|
||||
stat.index = design_stats::sysStats.length;
|
||||
design_stats::sysStats.insertLast(stat);
|
||||
}
|
||||
else if(key == "GlobalStat") {
|
||||
@list = design_stats::globalStats;
|
||||
@stat = DesignStat();
|
||||
stat.ident = value;
|
||||
stat.type = ST_Global;
|
||||
stat.index = design_stats::globalStats.length;
|
||||
design_stats::globalStats.insertLast(stat);
|
||||
}
|
||||
else if(key == "Name") {
|
||||
stat.name = localize(value);
|
||||
}
|
||||
else if(key == "Description") {
|
||||
stat.description = localize(value);
|
||||
}
|
||||
else if(key == "Variable") {
|
||||
if(value.startswith("Hex.")) {
|
||||
value = value.substr(4);
|
||||
stat.varType = SVT_HexVariable;
|
||||
stat.variable = getHexVariable(value);
|
||||
}
|
||||
else if(value.startswith("Ship.")) {
|
||||
value = value.substr(5);
|
||||
stat.varType = SVT_ShipVariable;
|
||||
stat.variable = getShipVariable(value);
|
||||
}
|
||||
else {
|
||||
stat.varType = SVT_SubsystemVariable;
|
||||
stat.variable = getSubsystemVariable(value);
|
||||
}
|
||||
}
|
||||
else if(key == "UsedVariable") {
|
||||
if(value.startswith("Ship.")) {
|
||||
value = value.substr(5);
|
||||
stat.usedVariable = getShipVariable(value);
|
||||
}
|
||||
else {
|
||||
error("UsedVariable needs to be a ship variable.");
|
||||
}
|
||||
}
|
||||
else if(key == "Default") {
|
||||
stat.defaultValue = toDouble(value);
|
||||
}
|
||||
else if(key == "Aggregate") {
|
||||
if(value == "Sum") {
|
||||
stat.aggregate = SA_Sum;
|
||||
stat.defaultValue = 0;
|
||||
}
|
||||
}
|
||||
else if(key == "Importance") {
|
||||
stat.importance = toInt(value);
|
||||
}
|
||||
else if(key == "Icon") {
|
||||
stat.icon = getSprite(value);
|
||||
}
|
||||
else if(key == "Color") {
|
||||
stat.color = toColor(value);
|
||||
}
|
||||
else if(key == "Suffix") {
|
||||
stat.suffix = localize(value);
|
||||
}
|
||||
else if(key == "RequireTag") {
|
||||
stat.reqTag = getSubsystemTag(value);
|
||||
}
|
||||
else if(key == "Secondary") {
|
||||
int sec = -1;
|
||||
for(uint i = 0, cnt = list.length; i < cnt; ++i) {
|
||||
if(list[i].ident.equals_nocase(value)) {
|
||||
sec = int(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(sec == -1)
|
||||
file.error("Could not find previous stat for secondary: "+value);
|
||||
else
|
||||
stat.secondary = sec;
|
||||
}
|
||||
else if(key == "DivBy") {
|
||||
if(value.startswith("Hex.")) {
|
||||
value = value.substr(4);
|
||||
stat.divType = SVT_HexVariable;
|
||||
stat.divVar = getHexVariable(value);
|
||||
}
|
||||
else if(value.startswith("Ship.")) {
|
||||
value = value.substr(5);
|
||||
stat.divType = SVT_ShipVariable;
|
||||
stat.divVar = getShipVariable(value);
|
||||
}
|
||||
else {
|
||||
stat.divType = SVT_SubsystemVariable;
|
||||
stat.divVar = getSubsystemVariable(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
FileList list("data/design_stats", "*.txt", true);
|
||||
for(uint i = 0, cnt = list.length; i < cnt; ++i)
|
||||
loadStats(list.path[i]);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
class Completion {
|
||||
string ident;
|
||||
string name;
|
||||
string description;
|
||||
string longDescription;
|
||||
string category;
|
||||
string cls;
|
||||
Sprite icon;
|
||||
Color color;
|
||||
|
||||
string format(bool shortForm = true, uint limit = 60) {
|
||||
string desc = description;
|
||||
if(desc.length > limit)
|
||||
desc = desc.substr(0, limit-3)+"...";
|
||||
|
||||
if(shortForm)
|
||||
return ::format(
|
||||
"[img=$3;30x30][vspace=4/][color=$4][b]$5[/b][/color][/img]",
|
||||
name, desc, getSpriteDesc(icon), toString(color), ident);
|
||||
else
|
||||
return ::format(
|
||||
"[img=$3;40x40][color=$4][b]$5[/b] ($1)\n[offset=20][i]$2[/i][/offset][/color][/img]",
|
||||
name, desc, getSpriteDesc(icon), toString(color), ident);
|
||||
}
|
||||
};
|
||||
|
||||
void loadCompletions(array<Completion@>@ arr, const string& folder, const string& blockName) {
|
||||
arr.length = 0;
|
||||
FileList list(folder, "*.txt", true);
|
||||
Completion@ compl;
|
||||
for(uint i = 0, cnt = list.length; i < cnt; ++i) {
|
||||
ReadFile file(list.path[i], true);
|
||||
|
||||
uint index = 0;
|
||||
int indent = 0;
|
||||
while(file++) {
|
||||
if(indent == -1)
|
||||
indent = file.indent;
|
||||
if(file.indent > indent)
|
||||
continue;
|
||||
if(file.indent < indent && compl !is null)
|
||||
@compl = null;
|
||||
if(file.key.equals_nocase(blockName)) {
|
||||
@compl = Completion();
|
||||
arr.insertLast(compl);
|
||||
compl.ident = file.value;
|
||||
compl.name = compl.ident;
|
||||
indent = -1;
|
||||
}
|
||||
else if(compl is null) {
|
||||
continue;
|
||||
}
|
||||
else if(file.key.equals_nocase("Name")) {
|
||||
compl.name = localize(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Description")) {
|
||||
if(compl.description.length == 0)
|
||||
compl.description = localize(file.value);
|
||||
compl.longDescription = localize(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Blurb")) {
|
||||
compl.description = localize(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Icon")) {
|
||||
if(!compl.icon.valid)
|
||||
compl.icon = getSprite(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Sprite")) {
|
||||
if(!compl.icon.valid)
|
||||
compl.icon = getSprite(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Small Icon")) {
|
||||
compl.icon = getSprite(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Color")) {
|
||||
compl.color = toColor(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Base Color")) {
|
||||
compl.color = toColor(file.value);
|
||||
}
|
||||
else if(file.key.equals_nocase("Category")) {
|
||||
compl.category = file.value;
|
||||
}
|
||||
else if(file.key.equals_nocase("Class")) {
|
||||
compl.cls = file.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
array<Completion@> abilityCompletions;
|
||||
array<Completion@> resourceCompletions;
|
||||
array<Completion@> buildingCompletions;
|
||||
array<Completion@> constructionCompletions;
|
||||
array<Completion@> statusCompletions;
|
||||
array<Completion@> subsysCompletions;
|
||||
array<Completion@> traitCompletions;
|
||||
array<Completion@> orbitalCompletions;
|
||||
array<Completion@> artifactCompletions;
|
||||
array<Completion@> techCompletions;
|
||||
array<Completion@> biomeCompletions;
|
||||
array<Completion@> cardCompletions;
|
||||
array<Completion@> voteCompletions;
|
||||
array<Completion@> effectCompletions;
|
||||
array<Completion@> anomalyCompletions;
|
||||
array<Completion@> creepCompletions;
|
||||
array<Completion@> eventCompletions;
|
||||
array<Completion@> cargoCompletions;
|
||||
array<Completion@> attitudeCompletions;
|
||||
|
||||
bool completionsInitialized = false;
|
||||
void initCompletions() {
|
||||
if(completionsInitialized)
|
||||
return;
|
||||
completionsInitialized = true;
|
||||
|
||||
loadCompletions(abilityCompletions, "data/abilities", "Ability");
|
||||
loadCompletions(resourceCompletions, "data/resources", "Resource");
|
||||
loadCompletions(buildingCompletions, "data/buildings", "Building");
|
||||
loadCompletions(constructionCompletions, "data/constructions", "Construction");
|
||||
loadCompletions(statusCompletions, "data/statuses", "Status");
|
||||
loadCompletions(subsysCompletions, "data/subsystems", "Subsystem");
|
||||
loadCompletions(traitCompletions, "data/traits", "Trait");
|
||||
loadCompletions(orbitalCompletions, "data/orbitals", "Module");
|
||||
loadCompletions(artifactCompletions, "data/artifacts", "Artifact");
|
||||
loadCompletions(techCompletions, "data/research", "Technology");
|
||||
loadCompletions(biomeCompletions, "data/biomes", "Biome");
|
||||
loadCompletions(cardCompletions, "data/influence", "Card");
|
||||
loadCompletions(voteCompletions, "data/influence", "Vote");
|
||||
loadCompletions(effectCompletions, "data/influence", "Effect");
|
||||
loadCompletions(anomalyCompletions, "data/anomalies", "Anomaly");
|
||||
loadCompletions(creepCompletions, "data/creeps", "Camp");
|
||||
loadCompletions(eventCompletions, "data/random_events", "Event");
|
||||
loadCompletions(cargoCompletions, "data/cargo", "Cargo");
|
||||
loadCompletions(attitudeCompletions, "data/attitudes", "Attitude");
|
||||
}
|
||||
@@ -0,0 +1,937 @@
|
||||
//Deals with definition specifications. A definition specification takes a loaded datafile
|
||||
//structure and defines properties for its fields so it can be represented with a UI.
|
||||
|
||||
import hooks;
|
||||
import editor.loader;
|
||||
import editor.completion;
|
||||
import icons;
|
||||
|
||||
class FileDef {
|
||||
array<BlockDef@> blocks;
|
||||
BlockDef defaultBlock;
|
||||
BlockDef@ curBlock;
|
||||
string localeFile;
|
||||
|
||||
FileDef() {
|
||||
@curBlock = defaultBlock;
|
||||
}
|
||||
|
||||
BlockDef@ getBlock(const string& key) {
|
||||
return defaultBlock.getBlock(key);
|
||||
}
|
||||
|
||||
BlockDef@ block(const string& key, const string& doc, const string& hookType = "", const string& hookModule = "") {
|
||||
@curBlock = defaultBlock.block(key, doc, hookType, hookModule);
|
||||
curBlock.closeDefault = false;
|
||||
return curBlock;
|
||||
}
|
||||
|
||||
void unblock() {
|
||||
@curBlock = defaultBlock;
|
||||
}
|
||||
|
||||
FieldDef@ field(const string& key, ArgumentType type, const string& defaultValue, const string& doc, const Sprite& icon = Sprite(), bool repeatable = false) {
|
||||
return curBlock.field(key, type, defaultValue, doc, icon, repeatable);
|
||||
}
|
||||
|
||||
void onChange() {}
|
||||
};
|
||||
|
||||
class BlockDef {
|
||||
string key;
|
||||
string doc;
|
||||
string hookType;
|
||||
string hookModule;
|
||||
string hookPrefix;
|
||||
string editMode;
|
||||
bool hasIdentifier = true;
|
||||
bool identifierLimit = true;
|
||||
bool closeDefault = true;
|
||||
array<BlockDef@> blocks;
|
||||
array<FieldDef@> fields;
|
||||
array<Completion@>@ duplicateCheck;
|
||||
|
||||
BlockDef@ getBlock(const string& key) {
|
||||
for(uint i = 0, cnt = blocks.length; i < cnt; ++i) {
|
||||
if(blocks[i].key == key)
|
||||
return blocks[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FieldDef@ getField(const string& key) {
|
||||
for(uint i = 0, cnt = fields.length; i < cnt; ++i) {
|
||||
if(fields[i].key == key)
|
||||
return fields[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FieldDef@ getField(LineDesc@ line) {
|
||||
for(uint i = 0, cnt = fields.length; i < cnt; ++i) {
|
||||
if(fields[i].condition is null)
|
||||
continue;
|
||||
if(fields[i].condition.matches(line)) {
|
||||
fields[i].condition.modify(line);
|
||||
return fields[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockDef@ block(const string& key, const string& doc, const string& hookType = "", const string& hookModule = "") {
|
||||
BlockDef b;
|
||||
b.key = key;
|
||||
b.doc = doc;
|
||||
b.hookType = hookType;
|
||||
b.hookModule = hookModule;
|
||||
blocks.insertLast(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
FieldDef@ field(const string& key, ArgumentType type, const string& defaultValue, const string& doc, const Sprite& icon = Sprite(), bool repeatable = false) {
|
||||
FieldDef f;
|
||||
f.index = fields.length;
|
||||
f.key = key;
|
||||
f.type = type;
|
||||
f.defaultValue = defaultValue;
|
||||
f.doc = doc;
|
||||
f.icon = icon;
|
||||
f.repeatable = repeatable;
|
||||
fields.insertLast(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
BlockDef& checkDuplicates(array<Completion@>@ dups) {
|
||||
@duplicateCheck = dups;
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockDef& setEditMode(const string& mode) {
|
||||
editMode = mode;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
class FieldCondition {
|
||||
bool matches(LineDesc@ line) { return false; }
|
||||
void modify(LineDesc@ line) {}
|
||||
};
|
||||
|
||||
class VariableCondition : FieldCondition {
|
||||
bool matches(LineDesc@ line) {
|
||||
if(!line.isKey)
|
||||
return false;
|
||||
if(line.value.length != 0 && line.value[0] == '=')
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void modify(LineDesc@ line) {
|
||||
line.line = line.key+" :"+line.value;
|
||||
line.isKey = false;
|
||||
}
|
||||
};
|
||||
|
||||
class ValueCondition : FieldCondition {
|
||||
bool matches(LineDesc@ line) {
|
||||
if(line.isKey)
|
||||
return false;
|
||||
int pos = line.line.findFirst("=");
|
||||
return pos != -1;
|
||||
}
|
||||
};
|
||||
|
||||
class FieldDef {
|
||||
uint index;
|
||||
string key;
|
||||
string defaultValue;
|
||||
string doc;
|
||||
Sprite icon;
|
||||
ArgumentType type;
|
||||
FieldCondition@ condition;
|
||||
bool fullLine = false;
|
||||
array<string>@ options;
|
||||
bool repeatable = false;
|
||||
int fieldPriority = 0;
|
||||
|
||||
FieldDef& setOptions(array<string>@ opts) {
|
||||
@options = opts;
|
||||
return this;
|
||||
}
|
||||
|
||||
FieldDef& setCondition(FieldCondition@ cond) {
|
||||
@this.condition = cond;
|
||||
return this;
|
||||
}
|
||||
|
||||
FieldDef& setFullLine(bool value) {
|
||||
this.fullLine = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
FieldDef& setPriority(int prior) {
|
||||
fieldPriority = prior;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
class StatusFile : FileDef {
|
||||
array<string> visibilities = {"Everybody", "Owner", "Origin Empire", "Owner and Origin Empire", "Nobody", "Global"};
|
||||
|
||||
StatusFile() {
|
||||
localeFile = "statuses.txt";
|
||||
block("Status", doc="A type of status effect that can be added to an object.",
|
||||
hookType="statuses::IStatusHook", hookModule="status_effects").checkDuplicates(statusCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the status.");
|
||||
field("Description", AT_Locale, "", doc="Description of the status.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to represent the status.");
|
||||
field("Color", AT_Color, "", doc="The status' representative color.");
|
||||
field("Condition Frequency", AT_Decimal, "0", doc="How often this status appears on planets as a planet condition, relative to other statuses' condition frequency.");
|
||||
field("Condition Tier", AT_Integer, "0", doc="The minimum level the planet's resource must be for this status to be able to appear as a planet condition.");
|
||||
field("Condition Type", AT_Custom, "", doc="The planet type a planet must have in order for this status to be able to appear as a planet condition..");
|
||||
field("Unique", AT_Boolean, "False", doc="Unique statuses indicate that the status cannot affect an object more than once, so should not be given a stack count display.");
|
||||
field("Collapses", AT_Boolean, "False", doc="A status that collapses will show a stack count instead of being a separate status for each instance. The status hooks are responsible for dealing with stack counts on an individual basis.");
|
||||
field("Visible To", AT_Selection, "Everybody", doc="Which empires the status can be seen by when looking at the object.").setOptions(visibilities);
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(statusCompletions, "data/statuses", "Status");
|
||||
}
|
||||
};
|
||||
|
||||
class AbilityFile : FileDef {
|
||||
AbilityFile() {
|
||||
localeFile = "abilities.txt";
|
||||
block("Ability", doc="An ability that objects can trigger.",
|
||||
hookType="abilities::IAbilityHook", hookModule="ability_effects").checkDuplicates(abilityCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the ability.");
|
||||
field("Description", AT_Locale, "", doc="Description of the ability.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to represent the ability.");
|
||||
field("Energy Cost", AT_Decimal, "0", doc="The base energy cost to activate the ability. Can be modified further by hooks.");
|
||||
field("Cooldown", AT_Decimal, "0", doc="The base cooldown between uses of the ability. Can be modified further by hooks.");
|
||||
field("Range", AT_Decimal, "", doc="The base maximum distance that the ability can be casted from. Can be modified further by hooks.");
|
||||
field("Hotkey", AT_Custom, "", doc="If set, create a hotkey for activating this ability when the object is selected to the specified key combination.");
|
||||
field("Hide Global", AT_Boolean, "False", doc="Hide this from the global action bar if added as an empire ability.");
|
||||
field("Target", AT_TargetSpec, "", /*repeatable=true,*/ doc="A type of target this ability needs to be triggered on.");
|
||||
field("Activate Sound", AT_Custom, "", doc="Name of the sound effect to be played in the UI for the person that triggers this ability.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(abilityCompletions, "data/abilities", "Ability");
|
||||
}
|
||||
};
|
||||
|
||||
class AnomalyFile : FileDef {
|
||||
AnomalyFile() {
|
||||
localeFile = "anomalies.txt";
|
||||
auto@ anom = block("Anomaly", doc="A type of anomaly that can be investigated.").checkDuplicates(anomalyCompletions);
|
||||
anom.field("Name", AT_Locale, "", doc="Name of the anomaly.");
|
||||
anom.field("Description", AT_Locale, "", doc="Basic, unscanned description of the anomaly.");
|
||||
anom.field("Narrative", AT_Locale, "", doc="Narrative for a scanned anomaly not in any state.");
|
||||
anom.field("Model", AT_Model, "Debris", doc="Model for the unscanned anomaly.");
|
||||
anom.field("Material", AT_Material, "Asteroid", doc="Model material for the unscanned anomaly.");
|
||||
anom.field("Frequency", AT_Decimal, "1", doc="How often this anomaly appears, relative to other anomalies' frequency.");
|
||||
anom.field("Scan Time", AT_Decimal, "60", doc="Amount of time in seconds that the anomaly takes to scan.");
|
||||
anom.field("Unique", AT_Boolean, "False", doc="Whether this anomaly is unique and can only occur once in a game.");
|
||||
|
||||
auto@ state = anom.block("State", doc="One of the states that the anomaly can trigger when scanned.");
|
||||
state.field("Narrative", AT_Locale, "", doc="Description of the anomaly in this state.");
|
||||
state.field("Model", AT_Model, "Debris", doc="Model for the anomaly in this state.");
|
||||
state.field("Material", AT_Material, "Asteroid", doc="Model material for the anomaly in this state.");
|
||||
state.field("Frequency", AT_Decimal, "1", doc="How often the anomaly scans to this state, relative to other states' frequency.");
|
||||
state.field("Choice", AT_Custom, "", repeatable=true, doc="Indicates an available choice when the anomaly is in this state.");
|
||||
|
||||
auto@ option = anom.block("Option", doc="One of the option choices that can be added to a state.",
|
||||
hookType="anomalies::IAnomalyHook", hookModule="anomaly_effects");
|
||||
option.field("Description", AT_Locale, "", doc="The description for triggering the option.");
|
||||
option.field("Icon", AT_Sprite, "", doc="Icon used to represent the option.");
|
||||
option.field("Chance", AT_Custom, "100%", doc="Chance for this option to appear, if no specific chance is given in the state.");
|
||||
option.field("Safe", AT_Boolean, "True", doc="Whether this option is safe and cannot result in unwanted consequences. Mainly used by the AI for decision making.");
|
||||
option.field("Target", AT_TargetSpec, "", /*repeatable=true,*/ doc="A type of target this option needs to be triggered on.");
|
||||
|
||||
auto@ result = option.block("Result", doc="A possible result when the option is chosen.",
|
||||
hookType="anomalies::IAnomalyHook", hookModule="anomaly_effects");
|
||||
result.identifierLimit = false;
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(anomalyCompletions, "data/anomalies", "Anomaly");
|
||||
}
|
||||
};
|
||||
|
||||
class ArtifactFile : FileDef {
|
||||
ArtifactFile() {
|
||||
localeFile = "artifacts.txt";
|
||||
block("Artifact", doc="A type of artifact that can be found and used.").checkDuplicates(artifactCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the artifact.");
|
||||
field("Description", AT_Locale, "", doc="Description of what the artifact does.");
|
||||
field("Icon", AT_Sprite, "ArtifactIcon::0", doc="Icon used to represent the artifact on the interface.");
|
||||
field("Strategic Icon", AT_Sprite, "ArtifactIcon::0", doc="Icon used for the artifact at strategic zoom.");
|
||||
field("Icon Size", AT_Decimal, "0.02", doc="Size of the artifact's distant icon.");
|
||||
field("Model", AT_Model, "Artifact", doc="Model for the artifact.");
|
||||
field("Material", AT_Material, "VolkurGenericPBR", doc="Model material for the artifact.");
|
||||
field("Physical Size", AT_Decimal, "5.0", doc="Physical size of the artifact in the world.");
|
||||
field("Mass", AT_Decimal, "300", doc="Mass of the artifact. Affects tractor beams.");
|
||||
field("Frequency", AT_Decimal, "1", doc="How often this artifact appears, relative to other artifacts' frequency.");
|
||||
field("Time Frequency", AT_Decimal, "0", doc="Increase to the artifact's base frequency for every 20 minutes of game time that passes.");
|
||||
field("Single Use", AT_Boolean, "True", doc="Whether the artifact disappears after it has been used once.");
|
||||
field("Single Use", AT_Boolean, "True", doc="Whether the artifact disappears after it has been used once.");
|
||||
field("Orbit", AT_Boolean, "False", doc="Whether the artifact orbits the star or stays at a static position.");
|
||||
field("Unique", AT_Boolean, "False", doc="Unique artifacts can only be generated into the galaxy once.");
|
||||
field("Natural", AT_Boolean, "False", doc="Natural artifacts are not generated by seed ships, but only spawn when the game starts.");
|
||||
field("Collapses", AT_Boolean, "True", doc="Whether multiple instances of this artifact are considered the same, and collapsed into a stacked view.");
|
||||
field("Can Donate", AT_Boolean, "True", doc="Whether this artifact can be donated to another player.");
|
||||
field("Can Own", AT_Boolean, "True", doc="Whether it is possible for a player to gain exclusive access to this artifact.");
|
||||
field("Require Contestation", AT_Decimal, "0", doc="If nonzero, this artifact type can only spawn in systems with a minimum contestation value. Contestation is an abstract number based on how many empires are close enough to potentially contest the system.");
|
||||
field("Spread Variable", AT_Custom, "", doc="If specified, turns this artifact into a 'Spread Artifact'. If the game_config parameter specified is active, exactly one instance of this artifact will be created when the universe is generated. Implies False for Can Donate and Can Own, and a 0 Frequency.");
|
||||
field("Tag", AT_Custom, "", repeatable=true, doc="Add a named tag to this artifact.");
|
||||
field("Ability", AT_Ability, "", repeatable=true, doc="This artifact grants the capability of using the specified ability.");
|
||||
field("AI", AT_Custom, "", repeatable=true, doc="Behaviour the AI follows for using this artifact.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(artifactCompletions, "data/artifacts", "Artifact");
|
||||
}
|
||||
};
|
||||
|
||||
class InfluenceFile : FileDef {
|
||||
array<string> cardClasses = {"Support", "Vote", "Effect", "Action", "Event", "Instant", "Misc"};
|
||||
array<string> cardRarities = {"Common", "Uncommon", "Rare", "Epic", "Basic"};
|
||||
array<string> cardSides = {"Neutral", "Both", "Oppose", "Support"};
|
||||
|
||||
InfluenceFile() {
|
||||
localeFile = "diplomacy.txt";
|
||||
auto@ card = block("Card", doc="A type of influence card.",
|
||||
hookType="influence::InfluenceCardEffect", hookModule="card_effects").checkDuplicates(cardCompletions);
|
||||
card.field("Name", AT_Locale, "", doc="Title of the card.");
|
||||
card.field("Description", AT_Locale, "", doc="Description of the card.");
|
||||
card.field("Icon", AT_Sprite, "", doc="Icon used to represent the card.");
|
||||
card.field("Color", AT_Color, "", doc="The card's representative color.");
|
||||
card.field("Frequency", AT_Decimal, "-1", doc="How often this card appears in the deck. A value of -1 indicates the frequency is dependent on the card rarity.");
|
||||
card.field("Collapse Uses", AT_Boolean, "True", doc="Whether multiple uses of this card should be considered the same and collapsed into a stack.");
|
||||
card.field("Points", AT_Integer, "0", doc="How many points this card adds to the empire's point total, in addition to basic points based on rarity.");
|
||||
card.field("Leader Only", AT_Boolean, "False", doc="Whether only the senate leader can play this card.");
|
||||
card.field("Class", AT_Selection, "Misc", doc="The type of card this is.").setOptions(cardClasses);
|
||||
card.field("Rarity", AT_Selection, "Common", doc="The rarity of this card in the deck.").setOptions(cardRarities);
|
||||
card.field("Side", AT_Selection, "Neutral", doc="For support cards, which sides of the vote the card can be played on.").setOptions(cardSides);
|
||||
card.field("Base Purchase Cost", AT_Integer, "0", doc="The base influence cost to buy the card off the stack.");
|
||||
card.field("Quality Purchase Cost", AT_Integer, "0", doc="The additional influence cost per extra quality this card costs to buy off the stack.");
|
||||
card.field("Uses Purchase Cost", AT_Integer, "0", doc="The additional influence cost per use this card costs to buy off the stack.");
|
||||
card.field("Placement Purchase Cost", AT_Integer, "1", doc="How much influence each space in the card stack the buy cost increases by.");
|
||||
card.field("Base Play Cost", AT_Integer, "0", doc="The base influence cost to play this card.");
|
||||
card.field("Quality Play Cost", AT_Integer, "0", doc="The additional influence cost per quality this card costs to play.");
|
||||
card.field("Base Weight", AT_Integer, "0", doc="For support cards, the base weight this adds to a vote.");
|
||||
card.field("Quality Weight", AT_Integer, "0", doc="For support cards, the extra weight this adds to a vote per extra quality.");
|
||||
card.field("Min Quality", AT_Integer, "1", doc="The minimum quality this card appears in the stack with.");
|
||||
card.field("Max Quality", AT_Integer, "1", doc="The maximum quality this card appears in the stack with.");
|
||||
card.field("Can Overquality", AT_Boolean, "True", doc="Whether this card can be boosted beyond its max quality. (For example, by Enhance cards)");
|
||||
card.field("Min Uses", AT_Integer, "1", doc="The minimum uses this card appears in the stack with.");
|
||||
card.field("Max Uses", AT_Integer, "1", doc="The maximum uses this card appears in the stack with.");
|
||||
card.field("Target", AT_TargetSpec, "", repeatable=true, doc="A type of target this card needs to be triggered on.");
|
||||
card.field("AI", AT_Custom, "", repeatable=true, doc="Behaviour the AI follows for using this card.");
|
||||
|
||||
auto@ vote = block("Vote", doc="A type of influence vote.",
|
||||
hookType="influence::InfluenceVoteEffect", hookModule="vote_effects").checkDuplicates(voteCompletions);
|
||||
vote.field("Name", AT_Locale, "", doc="Title of the vote.");
|
||||
vote.field("Description", AT_Locale, "", doc="Description of the vote.");
|
||||
vote.field("Icon", AT_Sprite, "", doc="Icon used to represent the vote.");
|
||||
vote.field("Color", AT_Color, "", doc="The vote's representative color.");
|
||||
vote.field("Target", AT_TargetSpec, "", /*repeatable=true,*/ doc="A type of target this vote needs to be triggered on.");
|
||||
vote.field("AI", AT_Custom, "", repeatable=true, doc="Behaviour the AI follows for judging this vote.");
|
||||
|
||||
auto@ effect = block("Effect", doc="A type of persistent influence effect.",
|
||||
hookType="influence::InfluenceEffectEffect", hookModule="influence_effects").checkDuplicates(effectCompletions);
|
||||
effect.field("Name", AT_Locale, "", doc="Title of the effect.");
|
||||
effect.field("Description", AT_Locale, "", doc="Description of the effect.");
|
||||
effect.field("Icon", AT_Sprite, "", doc="Icon used to represent the effect.");
|
||||
effect.field("Color", AT_Color, "", doc="The effect's representative color.");
|
||||
effect.field("Default Duration", AT_Decimal, "-1", doc="The default duration an effect of this type has when triggered. A negative value indicates a permanent effect.");
|
||||
effect.field("Upkeep", AT_Decimal, "0.0", doc="The portion of influence generation having this effect active consumes, from 0.0 to 1.0.");
|
||||
effect.field("Dismissable", AT_Boolean, "True", doc="Whether this effect can be dismissed at will.");
|
||||
effect.field("Dismiss Needs Owner", AT_Boolean, "True", doc="Whether only the owner of the effect can dismiss it at will.");
|
||||
effect.field("Target", AT_TargetSpec, "", /*repeatable=true,*/ doc="A type of target this effect needs to be triggered on.");
|
||||
effect.field("Tag", AT_Custom, "", repeatable=true, doc="A tag added to the effect for future identification.");
|
||||
|
||||
auto@ clause = block("Clause", doc="A clause that can be added to a treaty.",
|
||||
hookType="influence::InfluenceClauseHook", hookModule="clause_effects");
|
||||
clause.field("Name", AT_Locale, "", doc="Title of the clause.");
|
||||
clause.field("Description", AT_Locale, "", doc="Description of the clause.");
|
||||
clause.field("Icon", AT_Sprite, "", doc="Icon used to represent the clause.");
|
||||
clause.field("Color", AT_Color, "", doc="The clause's representative color.");
|
||||
clause.field("Free Clause", AT_Boolean, "False", doc="Whether this clause is available to be added freely to any treaty an empire wants to make.");
|
||||
clause.field("Team Clause", AT_Boolean, "False", doc="Whether this clause should be added to treaties created for 'Teams' from the game settings.");
|
||||
clause.field("Default Clause", AT_Boolean, "False", doc="Whether this clause is checked to be added by default for new treaties, and needs to be unchecked if players do not want to propose it.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(cardCompletions, "data/influence", "Card");
|
||||
loadCompletions(voteCompletions, "data/influence", "Vote");
|
||||
loadCompletions(effectCompletions, "data/influence", "Effect");
|
||||
}
|
||||
};
|
||||
|
||||
class ResearchFile : FileDef {
|
||||
array<string> classes = {"Boost", "Upgrade", "BigUpgrade", "Unlock", "Keystone", "Secret", "Special"};
|
||||
|
||||
ResearchFile() {
|
||||
localeFile = "research.txt";
|
||||
block("Technology", doc="A type of technology that can be placed on the research grid.",
|
||||
hookType="research::ITechnologyHook", hookModule="research_effects").checkDuplicates(techCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the technology.");
|
||||
field("Blurb", AT_Locale, "", doc="Very short description of the technology's effects, for display on the grid.");
|
||||
field("Description", AT_Locale, "", doc="Description of the technology.");
|
||||
field("Class", AT_Selection, "Upgrade", doc="The type of technology. For display purposes.").setOptions(classes);
|
||||
field("Category", AT_Custom, "", doc="The category the technology is listed under in the research editor. No effect on the game.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to represent the technology.");
|
||||
field("Symbol", AT_Sprite, "", doc="Additional symbol displayed on the technology icon.");
|
||||
field("Color", AT_Color, "", doc="The technology's representative color.");
|
||||
field("Point Cost", AT_Decimal, "0", doc="The base amount of research points this technology costs to research.");
|
||||
field("Time Cost", AT_Decimal, "0", doc="The base time in seconds this technology takes to research.");
|
||||
field("Default Unlock", AT_Boolean, "False", doc="Whether all nodes of this technology type start unlocked by default.");
|
||||
field("Secret", AT_Boolean, "False", doc="Whether this is a secret project technology.");
|
||||
block("Grid", doc="A grid or grid overlay that can be loaded. Must be in its own separate file.").setEditMode("research_grid");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(techCompletions, "data/research", "Technology");
|
||||
}
|
||||
};
|
||||
|
||||
class AttitudeFile : FileDef {
|
||||
AttitudeFile() {
|
||||
localeFile = "attitudes.txt";
|
||||
auto@ attid = block("Attitude", doc="An attitude that can be taken by an empire.",
|
||||
hookType="attitudes::IAttitudeHook", hookModule="attitude_effects").checkDuplicates(attitudeCompletions);
|
||||
attid.field("Name", AT_Locale, "", doc="Name of the attitude.");
|
||||
attid.field("Description", AT_Locale, "", doc="Description of the attitude.");
|
||||
attid.field("Progress", AT_Locale, "", doc="Locale entry used to display the attitude's progress indicator.");
|
||||
attid.field("Sort", AT_Integer, "0", doc="Sort order for the attitude in the list.");
|
||||
attid.field("Color", AT_Color, "", doc="The attitude's representative color.");
|
||||
|
||||
auto@ level = attid.block("Level", doc="A level that can be reached in this attitude.",
|
||||
hookType="attitudes::IAttitudeHook", hookModule="attitude_effects");
|
||||
level.hasIdentifier = false;
|
||||
level.field("Description", AT_Locale, "", doc="Description for the effect this level has.");
|
||||
level.field("Icon", AT_Sprite, "", doc="Icon to display this level on the bar.");
|
||||
level.field("Threshold", AT_Decimal, "0", doc="The amount of progress that needs to be made in this attitude to unlock this level.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(attitudeCompletions, "data/attitudes", "Attitude");
|
||||
}
|
||||
};
|
||||
|
||||
class ResourceFile : FileDef {
|
||||
array<string> vanishModes = {"Never", "Always", "When Exported", "Exported In Combat", "Custom"};
|
||||
array<string> resourceModes = {"Normal", "Universal", "Universal Unique", "Non Requirement"};
|
||||
array<string> resourceRarities = {"Common", "Uncommon", "Rare", "Epic", "Mythical", "Unique"};
|
||||
array<string> affinityTypes = {
|
||||
"", "Money", "Influence", "Energy", "Research", "Defense", "Labor",
|
||||
"Money + Influence", "Energy + Money", "Research + Defense", "Energy + Defense",
|
||||
"Influence + Research", "ALL"
|
||||
};
|
||||
|
||||
ResourceFile() {
|
||||
localeFile = "resources.txt";
|
||||
block("Resource", doc="A type of resource that can be found in the galaxy.",
|
||||
hookType="resources::IResourceHook", hookModule="resource_effects").checkDuplicates(resourceCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the resource.");
|
||||
field("Description", AT_Locale, "", doc="Full description of the resource.");
|
||||
field("Blurb", AT_Locale, "", doc="Short blurb to describe the resource. Defaults to Description if left empty.");
|
||||
field("Small Icon", AT_Sprite, "", doc="Small icon used for compact interface display, and on the planet's distant icon in the 3D world.");
|
||||
field("Icon", AT_Sprite, "", doc="Large icon used in detailed interface display.");
|
||||
field("Native Biome", AT_PlanetBiome, "", doc="The biome that is most likely to hold this resource.");
|
||||
field("Class", AT_Custom, "", doc="Identifier of the resource class this belongs in.");
|
||||
field("Level", AT_Integer, "0", doc="The planet level required to produce this resource.");
|
||||
field("Frequency", AT_Decimal, "1", doc="Global multiplier to the occurrence of this resource, at the expense of every other resource.");
|
||||
field("Distribution", AT_Decimal, "1", doc="Multiplier to the occurrence of this resource in its level/rarity class.");
|
||||
field("Cargo Worth", AT_Integer, "0", doc="How much money killing a cargo ship is worth per unit of resource. Civilian ships carry multiple units of a resource, dependent on their type and size of ship.");
|
||||
field("Artificial", AT_Boolean, "False", doc="Whether this is considered an 'artificial' resource and not affected by terraforming.");
|
||||
field("Exportable", AT_Boolean, "True", doc="Whether this resource can be exported from its original planet, or is static on its source.");
|
||||
field("Unique", AT_Boolean, "False", doc="A unique resource can only be generated in one system in the entire universe.");
|
||||
field("Require Contestation", AT_Decimal, "0", doc="If nonzero, this resource type can only spawn in systems with a minimum contestation value. Contestation is an abstract number based on how many empires are close enough to potentially contest the system.");
|
||||
field("Mode", AT_Selection, "Normal", doc="How this resource affects planet levelup. Universal resources (Drugs) can count as any other resource. Universal Unique resources only work once per planet.").setOptions(resourceModes);
|
||||
field("Rarity", AT_Selection, "Common", doc="The resource's base rarity level.").setOptions(resourceRarities);
|
||||
field("Display Requirement", AT_Boolean, "True", doc="Whether this resource should be listed as a possibility for levelup, regardless of whether it can actually be used.");
|
||||
field("Display Weight", AT_Integer, "0", doc="What order this resource should be displayed in relative to other resources in a list.");
|
||||
field("Asteroid Frequency", AT_Decimal, "0", doc="How often this resource appears on asteroids, relative to other resources that appear on asteroids.");
|
||||
field("Asteroid Labor", AT_Decimal, "0", doc="The base amount of labor this resource costs to build an asteroid base for.");
|
||||
field("Terraform Cost", AT_Integer, "0", doc="Base amount of money it takes to terraform a planet to this resource.");
|
||||
field("Terraform Labor", AT_Integer, "0", doc="Base amount of labor it takes to terraform a planet to this resource.");
|
||||
field("Limitless Level", AT_Boolean, "False", doc="Whether the resource level counts as being a limitless level, instead of its minimum level for penalty purposes.");
|
||||
field("Rarity Level", AT_Integer, "-1", doc="If not set to -1, override the occurrence of this resource as if it was a different level.");
|
||||
field("Vanish Time", AT_Decimal, "-1", doc="For temporary resources, the amount of time before the resource vanishes.");
|
||||
field("Vanish Mode", AT_Selection, "Never", doc="Condition for when the resource is ticking down or not.").setOptions(vanishModes);
|
||||
field("Can Be Terraformed", AT_Boolean, "True", doc="Whether planets with this as their primary resource can be terraformed to something else.");
|
||||
field("Pressure", AT_TileResourceSpec, "", repeatable=true, doc="An amount of pressure this resource provides.");
|
||||
field("Affinity", AT_Selection, "", repeatable=true, doc="A resource's affinities indicate what types of resources it is associated with. Icons for each of the specified affinities will be shown next to the name of the resource. These do not currently have a gameplay effect.")
|
||||
.setOptions(affinityTypes);
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(resourceCompletions, "data/resources", "Resource");
|
||||
}
|
||||
};
|
||||
|
||||
class BuildingFile : FileDef {
|
||||
BuildingFile() {
|
||||
localeFile = "buildings.txt";
|
||||
block("Building", doc="A type of building that is built on a planet surface.",
|
||||
hookType="buildings::IBuildingHook", hookModule="building_effects").checkDuplicates(buildingCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the building.");
|
||||
field("Description", AT_Locale, "", doc="Description of the building.");
|
||||
field("Sprite", AT_Sprite, "", doc="Picture used to display the building.");
|
||||
field("Category", AT_Custom, "", doc="Category under which the building is listed in the build list.");
|
||||
field("Size", AT_Custom, "1x1", doc="Size in tiles of the building on the surface grid.");
|
||||
field("Base Cost", AT_Integer, "0", doc="Base money cost to purchase this imperial building.");
|
||||
field("Tile Cost", AT_Integer, "0", doc="Extra build cost added for every tile that is not developed.");
|
||||
field("Base Maintenance", AT_Integer, "0", doc="Base maintenance cost for this imperial building.");
|
||||
field("Tile Maintenance", AT_Integer, "0", doc="Extra maintenance cost for every tile of the building that is not developed.");
|
||||
field("Labor Cost", AT_Decimal, "0", doc="How much labor this building costs to construct.");
|
||||
field("In Queue", AT_Boolean, "False", doc="Whether this building should be built in the construction queue. Automatically enabled if a labor cost is specified.");
|
||||
field("Build Time", AT_Decimal, "0", doc="For buildings with no labor cost, the time it takes to construct on the surface.");
|
||||
field("Civilian", AT_Boolean, "False", doc="Whether this is a civilian building.");
|
||||
field("Upgrades From", AT_Building, "", doc="For civilian buildings, what other building this is an 'upgrade' to.");
|
||||
field("City", AT_Boolean, "False", doc="Whether this is a city.");
|
||||
field("Saturation", AT_TileResourceSpec, "", repeatable=true, doc="For civilian structures, the amount of pressure this building takes up to be built.");
|
||||
field("Production", AT_TileResourceSpec, "", repeatable=true, doc="For civilian structures, the amount of units of resource generation this building grants.");
|
||||
field("Pressure Cap", AT_Integer, "1", repeatable=true, doc="For civilian structures, the amount of pressure capacity this building takes up from the total cap when built.");
|
||||
field("Build Affinity", AT_PlanetBiome, "", repeatable=true, doc="Undeveloped tiles of the specified biome do not add their 'Tile Cost' to the building's initial build cost.");
|
||||
field("Maintenance Affinity", AT_PlanetBiome, "", repeatable=true, doc="Undeveloped tiles of the specified biome do not add their 'Maintenance Cost' to the building's maintenance cost.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(buildingCompletions, "data/buildings", "Building");
|
||||
}
|
||||
};
|
||||
|
||||
class ConstructionFile : FileDef {
|
||||
ConstructionFile() {
|
||||
localeFile = "constructions.txt";
|
||||
block("Construction", doc="A construction that can be built generically.",
|
||||
hookType="constructions::IConstructionHook", hookModule="construction_effects").checkDuplicates(constructionCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the construction.");
|
||||
field("Description", AT_Locale, "", doc="Description of the construction.");
|
||||
field("Icon", AT_Sprite, "", doc="Picture used to display the construction.");
|
||||
field("Category", AT_Custom, "", doc="Category under which the construction is listed in the build list.");
|
||||
field("Build Cost", AT_Integer, "0", doc="Base money cost for constructing this.");
|
||||
field("Labor Cost", AT_Integer, "0", doc="Base labor cost for constructing this. Only one of Time or Labor cost must be specified.");
|
||||
field("Time Cost", AT_Integer, "0", doc="Time cost for constructing this, independent of labor generation. Only one of Time or Labor cost must be specified.");
|
||||
field("Maintenance Cost", AT_Integer, "0", doc="Base maintenance for constructing this. Note: Applied permanently after being constructed.");
|
||||
field("Target", AT_TargetSpec, "", /*repeatable=true,*/ doc="A type of target this construction needs to be triggered on.");
|
||||
field("In Context", AT_Boolean, "False", doc="Whether to show this construction in the context menu where appropriate.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(constructionCompletions, "data/constructions", "Construction");
|
||||
}
|
||||
};
|
||||
|
||||
class BiomeFile : FileDef {
|
||||
BiomeFile() {
|
||||
localeFile = "biomes.txt";
|
||||
block("Biome", doc="A type of biome for on a planet.").checkDuplicates(biomeCompletions);
|
||||
field("Name", AT_Locale, "", doc="Title of the biome.");
|
||||
field("Description", AT_Locale, "", doc="Description of the biome.");
|
||||
field("Sprite", AT_Sprite, "", doc="Icon used to represent the biome.");
|
||||
field("Color", AT_Color, "", doc="The biome's representative color.");
|
||||
field("Temperature", AT_Decimal, "0.5", doc="The biome's relative temperature, from 0 to 1.");
|
||||
field("Humidity", AT_Decimal, "0.5", doc="The biome's relative humidity, from 0 to 1.");
|
||||
field("Frequency", AT_Integer, "1", doc="The relative frequency this biome appears in.");
|
||||
field("UseWeight", AT_Decimal, "1", doc="Relative weight for civilians to develop this tile compared to other tiles.");
|
||||
field("BuildCost", AT_Decimal, "1", doc="Multiplier to imperial building cost on this tile.");
|
||||
field("BuildTime", AT_Decimal, "1", doc="Multiplier to civilian build time of this tile.");
|
||||
field("IsVoid", AT_Boolean, "False", doc="Whether this is a void.");
|
||||
field("IsWater", AT_Boolean, "False", doc="Whether this is water.");
|
||||
field("IsCrystallic", AT_Boolean, "False", doc="Whether this is crystallic.");
|
||||
field("IsMoon", AT_Boolean, "False", doc="Whether this is on a moon.");
|
||||
field("Buildable", AT_Boolean, "False", doc="Whether this can have buildings on it.");
|
||||
field("Picks", AT_Custom, "", doc="Special UV values for biomes using the procedural planet shader.");
|
||||
field("Lookup Range", AT_Custom, "", doc="Special UV values for biomes using the procedural planet shader.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(biomeCompletions, "data/biomes", "Biome");
|
||||
}
|
||||
};
|
||||
|
||||
class CreepFile : FileDef {
|
||||
CreepFile() {
|
||||
localeFile = "creeps.txt";
|
||||
auto@ camp = block("Camp", doc="A particular type of remnant camp that can be spawned.").checkDuplicates(creepCompletions);
|
||||
camp.field("Frequency", AT_Decimal, "1", doc="Frequency of this camp spawning, relative to other types of camps' frequency.");
|
||||
camp.field("Ship", AT_Custom, "", repeatable=true, doc="A remnant ship spawned to defend the pickup in this camp.");
|
||||
camp.field("Target Strength", AT_Decimal, "", doc="If specified, generate a random fleet close to the specified strength.");
|
||||
camp.field("Flagship Size", AT_Integer, "", doc="If specified, generate a random remnant design of this size to protect the camp.");
|
||||
camp.field("Support Occupation", AT_Decimal, "1.0", doc="If a flagship size is specified for a randomized design, how much of its support capacity should be filled with support ships.");
|
||||
camp.field("Remnant Status", AT_Status, "", repeatable=true, doc="Add a status effect that is added to all remnant flagships generated in this creep camp.");
|
||||
camp.field("Region Status", AT_Status, "", repeatable=true, doc="While this camp is not yet defeated, all objects in the system it is in are given the specified status.");
|
||||
|
||||
auto@ pickup = camp.block("Pickup", doc="A possible type of pickup reward to be spawned with this camp.",
|
||||
hookType="pickup_effects::IPickupHook", hookModule="pickup_effects");
|
||||
pickup.field("Frequency", AT_Decimal, "1", doc="Frequency of the camp having this pickup, relative to the other pickups' frequency.");
|
||||
pickup.field("Name", AT_Locale, "", doc="Name of the pickup.");
|
||||
pickup.field("Description", AT_Locale, "", doc="Description of the pickup.");
|
||||
pickup.field("Verb", AT_Locale, "#VERB_PICKUP", doc="Verb used for the pickup option.");
|
||||
pickup.field("Model", AT_Model, "Research_Station", doc="Model for the pickup.");
|
||||
pickup.field("Material", AT_Material, "GenericPBR_Research_Station", doc="Model material for the pickup.");
|
||||
pickup.field("Physical Size", AT_Decimal, "5.0", doc="Physical size of the pickup in the world.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(creepCompletions, "data/creeps", "Camp");
|
||||
}
|
||||
};
|
||||
|
||||
class OrbitalFile : FileDef {
|
||||
OrbitalFile() {
|
||||
localeFile = "orbitals.txt";
|
||||
block("Module", doc="A type of orbital module that can be constructed.",
|
||||
hookType="orbital_effects::IOrbitalEffect", hookModule="orbital_effects").checkDuplicates(orbitalCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the orbital.");
|
||||
field("Description", AT_Locale, "", doc="Description of the orbital.");
|
||||
field("Blurb", AT_Locale, "", doc="Short blurb to describe the orbital. Defaults to Description if left empty.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to represent the orbital.");
|
||||
field("Icon Size", AT_Decimal, "0.03", doc="Size of the orbitals's distant icon.");
|
||||
field("Distant Icon", AT_Sprite, "", doc="Icon used in the 3D view on the orbital's distant icon.");
|
||||
field("Strategic Icon", AT_Sprite, "", doc="Icon used in the 3D view for the orbital's strategic icon.");
|
||||
field("Spin", AT_Decimal, "30", doc="Speed at which the orbital spins.");
|
||||
field("Solid", AT_Boolean, "True", doc="Whether the orbital is considered solid and pushes things away.");
|
||||
field("Maintenance", AT_Integer, "0", doc="The orbital's maintenance cost.");
|
||||
field("Build Cost", AT_Integer, "0", doc="The orbital's build cost.");
|
||||
field("Labor Cost", AT_Decimal, "0", doc="The orbital's labor cost.");
|
||||
field("Combat Repair", AT_Boolean, "True", doc="Whether the orbital can repair when in combat.");
|
||||
field("Can Fling", AT_Boolean, "True", doc="Whether this orbital can be FTLed with fling.");
|
||||
field("Health", AT_Decimal, "0", doc="The orbital's base maximum health.");
|
||||
field("Armor", AT_Decimal, "0", doc="The orbital's base maximum armor. Armor is additional health on top of base health that has damage reduction.");
|
||||
field("Size", AT_Decimal, "10", doc="The physical size of the orbital in the world.");
|
||||
field("Mass", AT_Decimal, "-1", doc="The physical mass of the orbital (used in tractoring). Set to -1 to auto-calculate based on Size.");
|
||||
field("Model", AT_Model, "", doc="Model for the orbital.");
|
||||
field("Material", AT_Material, "", doc="Model material for the orbital.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(orbitalCompletions, "data/orbitals", "Module");
|
||||
}
|
||||
};
|
||||
|
||||
class TraitFile : FileDef {
|
||||
TraitFile() {
|
||||
localeFile = "traits.txt";
|
||||
block("Trait", doc="A trait that can be taken at game start.",
|
||||
hookType="trait_effects::ITraitEffect", hookModule="trait_effects").checkDuplicates(traitCompletions);
|
||||
field("Name", AT_Locale, "", doc="Name of the trait.");
|
||||
field("Description", AT_Locale, "", doc="Description of the trait.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to represent the trait.");
|
||||
field("Color", AT_Color, "", doc="The trait's representative color.");
|
||||
field("Costs Points", AT_Integer, "0", doc="Amount of points this trait costs to take.");
|
||||
field("Gives Points", AT_Integer, "0", doc="Amount of points this trait gives when taken.");
|
||||
field("Category", AT_Custom, "", doc="Category that the trait is listed in.");
|
||||
field("Order", AT_Integer, "0", doc="Order of the trait in the category's list.");
|
||||
field("Unique", AT_Custom, "", doc="If specified, only one trait with the same 'unique' tag can be chosen at a time.");
|
||||
field("Default", AT_Boolean, "False", doc="Whether this trait should be chosen by default.");
|
||||
field("AI Support", AT_Boolean, "True", doc="Whether the AI knows how to deal with this trait.");
|
||||
field("Available", AT_Boolean, "True", doc="Whether this trait is available to be chosen at all.");
|
||||
field("Conflict", AT_Trait, "", repeatable=true, doc="Another trait that cannot be taken at the same time as this trait.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(traitCompletions, "data/traits", "Trait");
|
||||
}
|
||||
};
|
||||
|
||||
class SubsystemFile : FileDef {
|
||||
SubsystemFile() {
|
||||
localeFile = "subsystems.txt";
|
||||
auto@ sys = block("Subsystem", doc="A subsystem type that can be placed on a design.",
|
||||
hookType="subsystem_effects::SubsystemHook", hookModule="subsystem_effects").checkDuplicates(subsysCompletions);
|
||||
sys.hookPrefix = "Hook: ";
|
||||
sys.field("Name", AT_Locale, "", doc="The subsystem's name.");
|
||||
sys.field("Description", AT_Locale, "", doc="The subsystem's description.");
|
||||
sys.field("BaseColor", AT_Color, "", doc="Color of the hexagon base/floor that the subsystem is drawn on.");
|
||||
sys.field("TypeColor", AT_Color, "", doc="Color contribution of this subsystem to the ship's overall type color.");
|
||||
sys.field("Elevation", AT_Integer, "0", doc="Elevation of this subsystem's hexes in the isometric hex view.");
|
||||
sys.field("Tags", AT_Custom, "", doc="A list of comma-separated arbitrary tags that the subsystem is assigned with.");
|
||||
sys.field("Hull", AT_Custom, "", doc="List of comma-separated hull types that this subsystem can be used on.");
|
||||
sys.field("EvaluationOrder", AT_Integer, "0", doc="Subsystems with lower evaluation orders are executed before higher ones. This is significant for the order in which modifiers and asserts are executed.");
|
||||
sys.field("DamageOrder", AT_Integer, "0", doc="Indicates the order in which this subsystem's GlobalDamage events are run. This does not have any effect on normal hex-based damage, only on globaldamage interception steps that happen beforehand.");
|
||||
sys.field("OnCheckErrors", AT_Custom, "", doc="Script function that is used to check the subsystem for design errors when placed.");
|
||||
|
||||
vars(sys);
|
||||
sysInner(sys);
|
||||
effBlock(sys);
|
||||
|
||||
auto@ templ = block("Template", doc="All blocks inside this template are added to subsystems that match the template's condition.");
|
||||
templ.identifierLimit = false;
|
||||
sysInner(templ);
|
||||
effBlock(templ);
|
||||
|
||||
auto@ defaults = templ.block("Defaults", doc="Default values for variables that can be overwritten.");
|
||||
defaults.hasIdentifier = false;
|
||||
vars(defaults);
|
||||
}
|
||||
|
||||
void sysInner(BlockDef@ sys) {
|
||||
sys.field("AddShipModifier", AT_Custom, "", repeatable=true, doc="If this subsystem is present, the specified modifier is applied to every subsystem on the ship with a higher evaluation order.");
|
||||
sys.field("AddPostModifier", AT_Custom, "", repeatable=true, doc="This modifier is added to this subsystem after all other subsystems have been evaluated.");
|
||||
sys.field("AddAdjacentModifier", AT_Custom, "", repeatable=true, doc="If this subsystem is present, the specified modifier is applied to every hex adjacent to this hex.");
|
||||
|
||||
auto@ modif = sys.block("Modifier", doc="A modifier function that can be applied to this subsystem.");
|
||||
modif.identifierLimit = false;
|
||||
modif.field("Stage", AT_Integer, "", doc="Sets a static evaluation stage for this modifier. Not needed in most cases.");
|
||||
vars(modif);
|
||||
|
||||
auto@ modu = sys.block("Module", doc="Every hex on the subsystem has exactly one module on it. Modules are parts of the subsystem that can behave differently, ie the default module, modifiers, or the core/turret module.",
|
||||
hookType="subsystem_effects::SubsystemHook", hookModule="subsystem_effects");
|
||||
modu.hookPrefix = "Hook: ";
|
||||
modu.field("Name", AT_Locale, "", doc="Name of the module.");
|
||||
modu.field("Description", AT_Locale, "", doc="Description of the module.");
|
||||
modu.field("Color", AT_Color, "", doc="The module's color.");
|
||||
modu.field("Required", AT_Boolean, "False", doc="Whether every subsystem is required to have at least one of these modules. 'Core' modules are implied to be required.");
|
||||
modu.field("Unique", AT_Boolean, "False", doc="Whether subsystems can only have up to one of these modules in them. 'Core' modules are implied to be unique.");
|
||||
modu.field("Vital", AT_Boolean, "False", doc="Whether subsystems are deactivated when a module of this type is destroyed. 'Core' modules are implied to be vital.");
|
||||
modu.field("DefaultUnlock", AT_Boolean, "False", doc="Whether empires have access to this module by default. 'Core' and 'Default' modules are implied to be unlocked by default.");
|
||||
modu.field("Sprite", AT_Sprite, "", doc="Sprite that is rendered on the isometric design view.");
|
||||
modu.field("DrawMode", AT_Integer, "0", doc="The way the sprite is drawn on the design. 0 indicates a singular sprite, 1 is used for rotatable turrets.");
|
||||
modu.field("OnEnable", AT_Custom, "", doc="Script function that is called when this module gets enabled.");
|
||||
modu.field("OnDisable", AT_Custom, "", doc="Script function that is called when this module gets disabled.");
|
||||
modu.field("AddModifier", AT_Custom, "", repeatable=true, doc="If this module is present in a subsystem, the specified modifier is added to the entire subsystem.");
|
||||
modu.field("AddUniqueModifier", AT_Custom, "", repeatable=true, doc="If this module is present in a subsystem, the specified modifier is added to the entire subsystem, but only once, regardless of the amount of modules.");
|
||||
modu.field("AddAdjacentModifier", AT_Custom, "", repeatable=true, doc="The specified modifier is applied to every hex adjacent to the module's hex.");
|
||||
|
||||
vars(modu);
|
||||
effBlock(modu);
|
||||
asserts(modu);
|
||||
|
||||
auto@ efftr = sys.block("Effector", doc="An effector that can trigger projectiles on objects.");
|
||||
vals(efftr);
|
||||
|
||||
asserts(sys);
|
||||
}
|
||||
|
||||
void asserts(BlockDef@ sys) {
|
||||
auto@ ass = sys.block("Assert", doc="A criterion that must be satisfied for the subsystem.");
|
||||
ass.identifierLimit = false;
|
||||
ass.field("Unique", AT_Boolean, "False", doc="Whether this criterion should only be checked once per ship.");
|
||||
ass.field("Fatal", AT_Boolean, "True", doc="Whether failing this criterion makes the design invalid and unable to be saved.");
|
||||
ass.field("Message", AT_Locale, "", doc="The message for failing the criterion.");
|
||||
|
||||
auto@ req = sys.block("Requires", doc="A list of ship variable requirements.");
|
||||
vals(req);
|
||||
req.hasIdentifier = false;
|
||||
|
||||
auto@ prov = sys.block("Provides", doc="A list of ship variable provisions.");
|
||||
vals(prov);
|
||||
prov.hasIdentifier = false;
|
||||
}
|
||||
|
||||
void effBlock(BlockDef@ sys) {
|
||||
auto@ eff = sys.block("Effect", doc="An effect that is active while the subsystem or module is.");
|
||||
vals(eff);
|
||||
}
|
||||
|
||||
void vars(BlockDef@ sys) {
|
||||
sys.field("Variable", AT_VariableDef, "", repeatable=true, doc="An arbitrary variable that can store data about this subsystem and be used.")
|
||||
.setCondition(VariableCondition()).setFullLine(true);
|
||||
}
|
||||
|
||||
void vals(BlockDef@ blk) {
|
||||
blk.field("Value", AT_ValueDef, "", repeatable=true, doc="A filled in value for a particular block.")
|
||||
.setCondition(ValueCondition()).setFullLine(true);
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(subsysCompletions, "data/subsystems", "Subsystem");
|
||||
}
|
||||
};
|
||||
|
||||
class EffectorFile : FileDef {
|
||||
array<string> efficiencyModes = {"Normal", "Reload Only", "Duration Only", "Reload Partial", "Duration Partial"};
|
||||
array<string> physicalTypes = {"Instant", "Projectile", "Missile", "Beam", "Aimed Missile"};
|
||||
|
||||
EffectorFile() {
|
||||
auto@ efftr = block("Effector", doc="An effector that can trigger projectiles on objects.");
|
||||
field("Value", AT_Custom, "", repeatable=true, doc="A value that can be passed in by the subsystem using the effector. A default value can also be specified.");
|
||||
field("Range", AT_Custom, "", doc="Formula based on values for the range at which this effector can activate.");
|
||||
field("Lifetime", AT_Custom, "", doc="Formula based on values for the lifetime of the projectile.");
|
||||
field("Speed", AT_Custom, "", doc="Formula based on values for the speed of the projectile.");
|
||||
field("Tracking", AT_Custom, "", doc="Formula based on values for the projectile/turret's tracking speed.");
|
||||
field("Spread", AT_Custom, "", doc="Formula based on values for the spread angle of the turret. A higher spread means a more inaccurate weapon.");
|
||||
field("CapTarget", AT_Custom, "", doc="Formula based on values for the amount of times to fire before switching targets.");
|
||||
field("FireArc", AT_Custom, "", doc="Formula based on values for the firing arc angle of the turret, expressed in radians.");
|
||||
field("TargetTolerance", AT_Custom, "", doc="Formula based on values for how far from the firing arc turrets will target enemies, expressed in radians.");
|
||||
field("FireTolerance", AT_Custom, "", doc="Formula based on values for how far from the firing arc turrets will fire at enemies, expressed in radians.");
|
||||
field("TargetAlgorithm", AT_Custom, "", doc="Algorithm used for targeting nearby enemies. Should be set to 'SingleTarget' almost all of the time.");
|
||||
field("Activation", AT_Custom, "", doc="Function that governs the activation cycle of the turret.");
|
||||
field("OnTrigger", AT_Custom, "", doc="Function that can be called when the effector triggers.");
|
||||
field("CanTarget", AT_Custom, "", doc="Expression that determines whether this turret can fire at a particular object.");
|
||||
field("AutoTarget", AT_Custom, "", doc="Expression that determines whether this turret should automatically target a particular object when in range.");
|
||||
field("Physical", AT_Boolean, "True", doc="Whether the projectile should be physically simulated and can miss, or should always hits its intended target.");
|
||||
field("EfficiencyMode", AT_Selection, "Normal", doc="The way increased or decreased efficiency effects the turret's behaviour. When set to reload, the reload time of the turret is affected by efficiency. When set to duration, the duration of a beam is affected by efficiency. When set to partial, only part of the increased efficiency is used this way, and the rest is passed along to the effect (to, for example, deal increased damage).")
|
||||
.setOptions(efficiencyModes);
|
||||
field("PhysicalType", AT_Selection, "Instant", doc="The type of projectile that is emitted by this effector.")
|
||||
.setOptions(physicalTypes);
|
||||
field("PhysicalSize", AT_Decimal, "1.0", doc="The relative physical size of the projectile.");
|
||||
gfx(efftr);
|
||||
|
||||
auto@ skin = efftr.block("Skin", doc="A secondary graphical skin for this effector that can be selected from a subsystem or from the empire's weapon skin.");
|
||||
skin.field("Inherit", AT_Custom, "", doc="Copy over the graphical values from a different non-default skin.").setPriority(-100);
|
||||
gfx(skin);
|
||||
|
||||
auto@ eff = efftr.block("Effect", doc="An effect that is activated on the target object when hit. Only one is allowed per effector.");
|
||||
eff.field("Value", AT_ValueDef, "", repeatable=true, doc="A filled in value that is passed to the effect.")
|
||||
.setCondition(ValueCondition()).setFullLine(true);
|
||||
}
|
||||
|
||||
array<string> gfxTypes = {"Sprite", "Line", "Beam"};
|
||||
void gfx(BlockDef@ b) {
|
||||
b.field("GfxType", AT_Selection, "Sprite", doc="The type of graphics associated with the projectile.")
|
||||
.setOptions(gfxTypes);
|
||||
b.field("GfxSize", AT_Decimal, "1.0", doc="The relative size of the projectile graphics.");
|
||||
b.field("Trail", AT_Material, "", doc="The material for the graphics trail.");
|
||||
b.field("TrailCol", AT_Custom, "", doc="The color(s) for the graphics trail.");
|
||||
b.field("Color", AT_Color, "", doc="The override color for the projectile.");
|
||||
b.field("Color", AT_Color, "", doc="The override color for the projectile.");
|
||||
b.field("ImpactGfx", AT_Custom, "", doc="Particle system to play when the projectile impacts.");
|
||||
b.field("Material", AT_Material, "", doc="Material to display the projectile with.");
|
||||
b.field("ImpactSfx", AT_Custom, "", doc="Sound effect to play when the projectile impacts.");
|
||||
b.field("FireSfx", AT_Custom, "", repeatable=true, doc="Sound effect to play when the turret fires. When multiple FireSfx entries are specified, one is chosen randomly every time the weapon fires.");
|
||||
b.field("FirePitchVariance", AT_Decimal, "0", doc="Variance in the fire sound's pitch.");
|
||||
}
|
||||
};
|
||||
|
||||
class MaterialFile : FileDef {
|
||||
array<string> sheetModes = {"Horizontal", "Vertical"};
|
||||
MaterialFile() {
|
||||
defaultBlock.doc = "[font=Subtitle]Note: Changes to material files will not be updated on other pages until the game is restarted.[/font]";
|
||||
|
||||
auto@ mat = block("Material", doc="A material that can be rendered on models or in the GUI.");
|
||||
mat.closeDefault = true;
|
||||
common(mat);
|
||||
|
||||
auto@ sheet = block("SpriteSheet", doc="A material that consists of multiple sprites laid out in a spritesheet.");
|
||||
sheet.closeDefault = true;
|
||||
sheet.field("Size", AT_Custom, "", doc="Size of each individual sprite in the sheet, expressed as 'width,height'.");
|
||||
sheet.field("Spacing", AT_Integer, "", doc="Spacing in front of each individual sprite in the sheet, in pixels.");
|
||||
sheet.field("Mode", AT_Selection, "Horizontal", doc="Whether the spritesheet should be numbered left to right first (horizontal), or top to bottom first (vertical).")
|
||||
.setOptions(sheetModes);
|
||||
common(sheet);
|
||||
|
||||
auto@ grp = block("MaterialGroup", doc="A group of materials automatically generated from all images in a folder, according to a template.");
|
||||
grp.closeDefault = true;
|
||||
grp.field("Folder", AT_File, "", doc="Path to the folder that images are taken from.");
|
||||
grp.field("Prefix", AT_Custom, "", doc="Prefix added to the filenames in the folder to make the names of the related materials.");
|
||||
grp.field("Template", AT_Custom, "", doc="A material declared earlier in the file that materials generated from the folder are based on.");
|
||||
}
|
||||
|
||||
array<string> depthTest = {"", "Never", "Less", "LessEqual", "Equal", "GreaterEqual", "Greater", "Always", "NoDepthTest"};
|
||||
array<string> culling = {"", "None", "Front", "Back", "Both"};
|
||||
array<string> wrapModes = {"", "Repeat", "Clamp", "ClampEdge", "Mirror"};
|
||||
array<string> filters = {"", "Linear", "Nearest"};
|
||||
array<string> modes = {"", "Fill", "Line"};
|
||||
array<string> blends = {"", "Alpha", "Solid", "Add", "Overlay", "Font"};
|
||||
void common(BlockDef@ b) {
|
||||
b.field("Inherit", AT_Custom, "", doc="Copy material render data from a builtin material or one defined earlier in the file.\n\nCommonly used to inherit the Image2D engine material, indicating that a material is intended for GUI use.").setPriority(-100);
|
||||
|
||||
b.field("LoadPriority", AT_Custom, "", doc="Indicates at what stage of the game the texture should be ensured to be loaded. Can be set to a number (higher is earlier), or one of 'Critical', 'Menu', 'Game', 'High', or 'Low'. Textures with a priority lower than 'Game' will be streamed while the game is already running.").setPriority(-10);
|
||||
|
||||
for(uint i = 1; i <= 6; ++i) {
|
||||
string key = "Texture";
|
||||
if(i != 1)
|
||||
key += i;
|
||||
b.field(key, AT_File, "", doc="The file location of a png texture that this material renders with.").setPriority(10);
|
||||
}
|
||||
|
||||
b.field("Shader", AT_Custom, "", doc="Name of the shader to use for rendering this material.");
|
||||
b.field("DepthWrite", AT_Boolean, "True", doc="Whether the material should write to the depth buffer.");
|
||||
b.field("DepthTest", AT_Selection, "", doc="How the material should test against the depth buffer.")
|
||||
.setOptions(depthTest);
|
||||
b.field("Culling", AT_Selection, "", doc="How the material should apply face culling.")
|
||||
.setOptions(culling);
|
||||
b.field("Lighting", AT_Boolean, "True", doc="Whether the material should use lighting.");
|
||||
b.field("NormalizeNormals", AT_Boolean, "False", doc="Whether to normalize the normal values when this material is rendered.");
|
||||
b.field("Shininess", AT_Decimal, "", doc="Shininess factor for lighting when this material is rendered.");
|
||||
b.field("WrapVertical", AT_Selection, "", doc="What behaviour should be used for wrapping texture lookups beyond the vertical edges of the material.")
|
||||
.setOptions(wrapModes);
|
||||
b.field("WrapHorizontal", AT_Selection, "", doc="What behaviour should be used for wrapping texture lookups beyond the horizontal edges of the material.")
|
||||
.setOptions(wrapModes);
|
||||
b.field("FilterMin", AT_Selection, "", doc="When the texture is scaled down, which texture filter method to use.")
|
||||
.setOptions(filters);
|
||||
b.field("FilterMag", AT_Selection, "", doc="When the texture is scaled up, which texture filter method to use.")
|
||||
.setOptions(filters);
|
||||
b.field("DrawMode", AT_Selection, "", doc="The mode that the texture draws on top of a model with.")
|
||||
.setOptions(modes);
|
||||
b.field("Blend", AT_Selection, "", doc="How the material blends with things rendered behind it.")
|
||||
.setOptions(blends);
|
||||
b.field("Alpha", AT_Boolean, "False", doc="Whether the material should use alpha rendering.");
|
||||
b.field("Diffuse", AT_Color, "", doc="Color to use for the material's diffuse lighting.");
|
||||
b.field("Specular", AT_Color, "", doc="Color to use for the material's specular lighting.");
|
||||
}
|
||||
};
|
||||
|
||||
class SoundFile : FileDef {
|
||||
SoundFile() {
|
||||
auto@ snd = block("Sound", doc="A sound effect that can be played in the game.");
|
||||
snd.closeDefault = true;
|
||||
common(snd);
|
||||
|
||||
auto@ strm = block("Stream", doc="A sound effect that is streamed as it is played. Should be used for longer sound effects.");
|
||||
strm.closeDefault = true;
|
||||
common(strm);
|
||||
}
|
||||
|
||||
void common(BlockDef@ b) {
|
||||
field("File", AT_File, "", doc="Path to the .ogg file that contains the sound.");
|
||||
field("Volume", AT_Decimal, "1", doc="Relative volume to play the sound at.");
|
||||
}
|
||||
};
|
||||
|
||||
class EventFile : FileDef {
|
||||
EventFile() {
|
||||
localeFile = "random_events.txt";
|
||||
auto@ evt = block("Event", doc="A random event that can be triggered in game when conditions are met.",
|
||||
hookType="random_events::IRandomEventHook", hookModule="event_effects").checkDuplicates(eventCompletions);
|
||||
evt.field("Name", AT_Locale, "", doc="Name of the random event.");
|
||||
evt.field("Text", AT_Locale, "", doc="Text and narrative of the random event.");
|
||||
evt.field("Frequency", AT_Decimal, "1.0", doc="Rate at which this random event occurs relative to other random events.");
|
||||
evt.field("Timer", AT_Decimal, "180", doc="Time in seconds that the choice is available. If it runs out, the first available Default option is chosen automatically.");
|
||||
evt.field("Unique", AT_Boolean, "True", doc="Unique events can only occur once per game.");
|
||||
evt.field("Target", AT_TargetSpec, "", repeatable=true, doc="A type of target this event triggers on.");
|
||||
|
||||
auto@ opt = evt.block("Option", doc="An option that can be chosen for this event.",
|
||||
hookType="random_events::IRandomOptionHook", hookModule="event_effects");
|
||||
opt.field("Text", AT_Locale, "", doc="Text and narrative of the option.");
|
||||
opt.field("Icon", AT_Sprite, "", doc="Icon used to represent the option.");
|
||||
opt.field("Safe", AT_Boolean, "True", doc="Whether this option is safe and cannot result in horrible unwanted consequences. Mainly used by the AI for decision making.");
|
||||
opt.field("Default", AT_Boolean, "False", doc="When the timer runs out on a random event, the first available option that has Default set is chosen.");
|
||||
|
||||
auto@ res = opt.block("Result", doc="One particular result that may occur. The chance specified is the chance of this result happening rather than any other result.",
|
||||
hookType="random_events::IRandomOptionHook", hookModule="event_effects");
|
||||
|
||||
res.block("On", doc="Hooks inside an On block are applied on the target specified by the On block, instead of only on the event's owning empire.",
|
||||
hookType="random_events::IRandomOptionHook", hookModule="event_effects");
|
||||
opt.block("On", doc="Hooks inside an On block are applied on the target specified by the On block, instead of only on the event's owning empire.",
|
||||
hookType="random_events::IRandomOptionHook", hookModule="event_effects");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(eventCompletions, "data/random_events", "Event");
|
||||
}
|
||||
};
|
||||
|
||||
class CargoFile : FileDef {
|
||||
CargoFile() {
|
||||
localeFile = "resources.txt";
|
||||
block("Cargo", doc="A type of cargo that can be stored and moved.");
|
||||
field("Name", AT_Locale, "", doc="Name of the cargo type.");
|
||||
field("Description", AT_Locale, "", doc="Description of the cargo type.");
|
||||
field("Icon", AT_Sprite, "", doc="Icon used to display the cargo.");
|
||||
field("Color", AT_Color, "", doc="Color used to display the cargo.");
|
||||
field("Storage Size", AT_Decimal, "1.0", doc="Size of one unit of this cargo in cargo storage.");
|
||||
}
|
||||
|
||||
void onChange() {
|
||||
loadCompletions(cargoCompletions, "data/cargo", "Cargo");
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,272 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import icons;
|
||||
|
||||
class FileFolder : BaseGuiElement {
|
||||
array<FileFolder@> folders;
|
||||
array<FileElement@> files;
|
||||
bool expanded = true;
|
||||
|
||||
string fullPath;
|
||||
string basePath;
|
||||
string basename;
|
||||
|
||||
GuiSkinElement@ heading;
|
||||
GuiButton@ btn;
|
||||
GuiSprite@ toggle;
|
||||
|
||||
FileFolder(IGuiElement@ parent, const recti& pos) {
|
||||
super(parent, pos);
|
||||
|
||||
@heading = GuiSkinElement(this, Alignment(Left, Top, Right, Top+30), SS_PlainBox);
|
||||
@btn = GuiButton(heading, Alignment().fill());
|
||||
btn.style = SS_IconButton;
|
||||
btn.buttonIcon = spritesheet::FileIcons+2;
|
||||
btn.horizAlign = 0.0;
|
||||
btn.font = FT_Bold;
|
||||
@toggle = GuiSprite(btn, Alignment(Right-26, Top+4, Right-4, Top+26));
|
||||
toggle.desc = icons::Minus;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i)
|
||||
folders[i].remove();
|
||||
folders.length = 0;
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i)
|
||||
files[i].remove();
|
||||
files.length = 0;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(expanded) {
|
||||
toggle.desc = icons::Minus;
|
||||
}
|
||||
else {
|
||||
toggle.desc = icons::Plus;
|
||||
}
|
||||
|
||||
if(cast<FileFolder>(parent) !is null)
|
||||
cast<FileFolder>(parent).update();
|
||||
else
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void clearSelection(bool upwards = true) {
|
||||
if(upwards) {
|
||||
if(cast<FileFolder>(parent) !is null)
|
||||
cast<FileFolder>(parent).clearSelection();
|
||||
else
|
||||
clearSelection(false);
|
||||
}
|
||||
else {
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i)
|
||||
folders[i].clearSelection(false);
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i)
|
||||
files[i].pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
FileElement@ getSelection() {
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i)
|
||||
if(files[i].pressed)
|
||||
return files[i];
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i) {
|
||||
auto@ sel = folders[i].getSelection();
|
||||
if(sel !is null)
|
||||
return sel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FileElement@ getFile(const string& basePath) {
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i) {
|
||||
if(files[i].basePath == basePath)
|
||||
return files[i];
|
||||
}
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i) {
|
||||
auto@ sel = folders[i].getFile(basePath);
|
||||
if(sel !is null)
|
||||
return sel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void select(const string& basePath, bool bubble = true) {
|
||||
clearSelection();
|
||||
auto file = getFile(basePath);
|
||||
if(file !is null) {
|
||||
file.pressed = true;
|
||||
if(bubble)
|
||||
emitConfirmed();
|
||||
}
|
||||
}
|
||||
|
||||
FileFolder@ getRoot() {
|
||||
if(cast<FileFolder>(parent) !is null)
|
||||
return cast<FileFolder>(parent).getRoot();
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
if(evt.type == GUI_Clicked && evt.caller is btn) {
|
||||
expanded = !expanded;
|
||||
update();
|
||||
}
|
||||
if(evt.type == GUI_Clicked) {
|
||||
auto@ file = cast<FileElement>(evt.caller);
|
||||
if(file !is null) {
|
||||
clearSelection();
|
||||
file.pressed = true;
|
||||
setGuiFocus(null);
|
||||
getRoot().emitConfirmed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void load(const string& folder, const string& base = "", const string& extension = "", bool resolve = true) {
|
||||
reset();
|
||||
|
||||
fullPath = folder;
|
||||
basePath = folder;
|
||||
if(base.length != 0)
|
||||
basePath = base;
|
||||
basename = getBasename(folder);
|
||||
btn.text = basename;
|
||||
heading.visible = false;
|
||||
|
||||
FileList list(folder, "*", false, resolve);
|
||||
for(uint i = 0, cnt = list.length; i < cnt; ++i) {
|
||||
if(list.isDirectory[i]) {
|
||||
FileFolder elem(this, recti());
|
||||
elem.load(path_join(fullPath, list.basename[i]), path_join(basePath, list.basename[i]), resolve=resolve, extension=extension);
|
||||
elem.heading.visible = true;
|
||||
|
||||
if(elem.folders.length == 0 && elem.files.length == 0)
|
||||
elem.remove();
|
||||
else
|
||||
folders.insertLast(elem);
|
||||
}
|
||||
else {
|
||||
string basename = list.basename[i];
|
||||
if(extension.length != 0 && !basename.endswith(extension))
|
||||
continue;
|
||||
|
||||
FileElement elem(this, recti());
|
||||
elem.fullPath = list.path[i];
|
||||
elem.basePath = path_join(basePath, basename);
|
||||
elem.basename = basename;
|
||||
elem.update();
|
||||
|
||||
files.insertLast(elem);
|
||||
}
|
||||
}
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
uint get_needHeight() {
|
||||
int h = heading !is null && heading.visible ? 30 : 0;
|
||||
if(!expanded)
|
||||
return h;
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i)
|
||||
h += folders[i].needHeight;
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i)
|
||||
h += files[i].needHeight;
|
||||
return h;
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
int fileOffset = 30;
|
||||
int folderOffset = 0;
|
||||
if(cast<FileFolder>(parent) is null) {
|
||||
size = vec2i(parent.size.width-20, needHeight);
|
||||
fileOffset = 0;
|
||||
folderOffset = -30;
|
||||
}
|
||||
|
||||
int y = heading !is null && heading.visible ? 30 : 0;
|
||||
for(uint i = 0, cnt = folders.length; i < cnt; ++i) {
|
||||
auto@ elem = folders[i];
|
||||
int h = elem.needHeight;
|
||||
elem.size = vec2i(size.width-30-folderOffset, h);
|
||||
elem.position = vec2i(30+folderOffset, y);
|
||||
y += h;
|
||||
}
|
||||
|
||||
for(uint i = 0, cnt = files.length; i < cnt; ++i) {
|
||||
auto@ elem = files[i];
|
||||
int h = elem.needHeight;
|
||||
elem.size = vec2i(size.width-fileOffset, h);
|
||||
elem.position = vec2i(fileOffset, y);
|
||||
y += h;
|
||||
}
|
||||
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_Panel, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class FileElement : GuiButton {
|
||||
string fullPath;
|
||||
string basePath;
|
||||
string basename;
|
||||
|
||||
FileElement(IGuiElement@ parent, const recti& pos) {
|
||||
super(parent, pos);
|
||||
|
||||
style = SS_ListboxItem;
|
||||
toggleButton = true;
|
||||
horizAlign = 0.0;
|
||||
buttonIcon = spritesheet::FileIcons+0;
|
||||
}
|
||||
|
||||
uint get_needHeight() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
void update() {
|
||||
text = basename;
|
||||
|
||||
bool existsInMod = fileExists(path_join(topMod.abspath, basePath));
|
||||
bool existsInParent = false;
|
||||
|
||||
if(topMod.parent is null) {
|
||||
if(currentMod is topMod) {
|
||||
existsInParent = true;
|
||||
}
|
||||
else {
|
||||
existsInParent = fileExists(path_join(currentMod.abspath, basePath));
|
||||
}
|
||||
}
|
||||
else {
|
||||
existsInParent = fileExists(path_join(topMod.parent.abspath, basePath));
|
||||
}
|
||||
|
||||
Color color;
|
||||
if(topMod is currentMod) {
|
||||
color = Color(0xffffffff);
|
||||
}
|
||||
else if(existsInMod) {
|
||||
if(existsInParent)
|
||||
color = Color(0xffff00ff);
|
||||
else
|
||||
color = Color(0x00ff00ff);
|
||||
}
|
||||
else {
|
||||
color = Color(0xaaaaaaff);
|
||||
}
|
||||
|
||||
textColor = color;
|
||||
Icon.color = color;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,322 @@
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiListbox;
|
||||
import editor.fields;
|
||||
import dialogs.Dialog;
|
||||
import void fillTargetsFromTab(Field@ sourceField, TargetChooser@ fld) from "editor.editor";
|
||||
|
||||
class HookEditor : Dialog {
|
||||
HookField@ field;
|
||||
string typeName;
|
||||
Hook@ type;
|
||||
GuiButton@ ok;
|
||||
string suffix;
|
||||
|
||||
GuiMarkupText@ text;
|
||||
array<Field@> args;
|
||||
|
||||
HookEditor(HookField@ field) {
|
||||
@this.field = field;
|
||||
@type = field.type;
|
||||
super(null);
|
||||
width = 1000;
|
||||
addTitle(getClass(field.type).name);
|
||||
|
||||
@text = GuiMarkupText(bg, recti_area(12,32,width-24,30));
|
||||
|
||||
@ok = GuiButton(bg, recti());
|
||||
ok.text = locale::OK;
|
||||
|
||||
if(isWindows) {
|
||||
//Legacy OS support
|
||||
@ok.alignment = Alignment(Left+0.4f+DIALOG_PADDING, Bottom-DIALOG_BUTTON_ROW, Right-0.4f-DIALOG_PADDING, Bottom-DIALOG_PADDING);
|
||||
}
|
||||
else {
|
||||
@ok.alignment = Alignment(Right-0.2f-DIALOG_PADDING, Bottom-DIALOG_BUTTON_ROW, Right-0.0f-DIALOG_PADDING, Bottom-DIALOG_PADDING);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void focus() {
|
||||
if(args.length != 0)
|
||||
args[0].focus();
|
||||
}
|
||||
|
||||
void update() {
|
||||
int y = 32;
|
||||
string doc = type.formatDeclaration();
|
||||
if(type.documentation !is null)
|
||||
doc += "\n[offset=20][i]"+type.documentation.text+"[/i][/offset]";
|
||||
text.text = doc;
|
||||
text.updateAbsolutePosition();
|
||||
y += text.size.height+12;
|
||||
|
||||
array<string> argValues;
|
||||
array<string> argSpecs;
|
||||
argValues.length = type.arguments.length;
|
||||
string hookText = field.value;
|
||||
if(funcSplit(hookText, typeName, argSpecs)) {
|
||||
for(uint i = 0, cnt = argSpecs.length; i < cnt; ++i) {
|
||||
if(i >= argValues.length) {
|
||||
if(argValues.length != 0)
|
||||
argValues[argValues.length - 1] += ","+argSpecs[i].trimmed();
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check for named arguments
|
||||
int eqPos = argSpecs[i].findFirst("=");
|
||||
int brkPos = argSpecs[i].findFirst("(");
|
||||
|
||||
if(eqPos != -1 && (brkPos == -1 || eqPos < brkPos)) {
|
||||
//Named argument
|
||||
uint index = uint(-1);
|
||||
string name = argSpecs[i].substr(0, eqPos).trimmed();
|
||||
string value = argSpecs[i].substr(eqPos+1).trimmed();
|
||||
for(uint n = 0, ncnt = argValues.length; n < ncnt; ++n) {
|
||||
if(type.arguments[n].argName.equals_nocase(name)) {
|
||||
index = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(index != uint(-1))
|
||||
argValues[index] = value;
|
||||
}
|
||||
else {
|
||||
argValues[i] = argSpecs[i].trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
int brktPos = hookText.findLast(")");
|
||||
if(brktPos != -1)
|
||||
suffix = hookText.substr(brktPos+1);
|
||||
}
|
||||
|
||||
for(uint i = 0, cnt = type.arguments.length; i < cnt; ++i) {
|
||||
auto@ arg = type.arguments[i];
|
||||
auto atype = arg.type;
|
||||
if(atype == AT_VarArgs)
|
||||
atype = ArgumentType(arg.integer);
|
||||
auto@ fld = makeField(atype, bg, recti());
|
||||
if(atype == AT_Target) {
|
||||
fld.setValue(arg.integer2);
|
||||
fillTargetsFromTab(field, cast<TargetChooser>(fld));
|
||||
}
|
||||
|
||||
fld.setVerbose(true);
|
||||
fld.set(arg.argName, arg.doc, arg.filled ? arg.str : "");
|
||||
if(argValues[i].length != 0)
|
||||
fld.value = argValues[i];
|
||||
else
|
||||
fld.value = fld.defaultValue;
|
||||
fld.tabIndex = i;
|
||||
fld.updateAbsolutePosition();
|
||||
|
||||
int h = fld.needHeight;
|
||||
fld.size = vec2i(width-24, h);
|
||||
fld.position = vec2i(12, y);
|
||||
|
||||
y += h;
|
||||
args.insertLast(fld);
|
||||
}
|
||||
|
||||
if(args.length != 0)
|
||||
args[0].focus();
|
||||
|
||||
y += 40;
|
||||
height = y;
|
||||
updatePosition();
|
||||
bg.updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void confirm() {
|
||||
string spec = typeName+"(";
|
||||
bool skipped = false, filled = false;
|
||||
for(uint i = 0, cnt = type.arguments.length; i < cnt; ++i) {
|
||||
auto@ arg = type.arguments[i];
|
||||
string value = args[i].value;
|
||||
if(arg.filled && value == arg.str) {
|
||||
skipped = true;
|
||||
continue;
|
||||
}
|
||||
if(filled)
|
||||
spec += ", ";
|
||||
if(skipped || (arg.filled && arg.type != AT_Hook))
|
||||
spec += arg.argName+" = ";
|
||||
spec += value;
|
||||
filled = true;
|
||||
}
|
||||
spec += ")";
|
||||
spec += suffix;
|
||||
|
||||
field.value = spec;
|
||||
field.emitConfirmed();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked && event.caller is ok && !Closed) {
|
||||
confirm();
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
return Dialog::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
class HookSorter {
|
||||
string name;
|
||||
string text;
|
||||
AnyClass@ cls;
|
||||
Hook@ hook;
|
||||
|
||||
int opCmp(const HookSorter@ other) const {
|
||||
return name.opCmp(other.name);
|
||||
}
|
||||
};
|
||||
|
||||
class HookList : Dialog {
|
||||
HookField@ field;
|
||||
Hook@ type;
|
||||
GuiButton@ accept;
|
||||
GuiButton@ cancel;
|
||||
|
||||
GuiListbox@ hookList;
|
||||
array<HookSorter@> hooks;
|
||||
|
||||
HookList(HookField@ field) {
|
||||
@this.field = field;
|
||||
@type = field.type;
|
||||
super(null);
|
||||
width = 800;
|
||||
addTitle("Add Hook");
|
||||
|
||||
@hookList = GuiListbox(bg, Alignment(Left+12, Top+32, Right-12, Bottom-40));
|
||||
hookList.itemHeight = 70;
|
||||
|
||||
@accept = GuiButton(bg, recti());
|
||||
accept.text = locale::ACCEPT;
|
||||
accept.tabIndex = 100;
|
||||
@accept.callback = this;
|
||||
accept.color = colors::Green;
|
||||
|
||||
@cancel = GuiButton(bg, recti());
|
||||
cancel.text = locale::CANCEL;
|
||||
cancel.tabIndex = 101;
|
||||
@cancel.callback = this;
|
||||
cancel.color = colors::Red;
|
||||
|
||||
alignAcceptButtons(accept, cancel);
|
||||
|
||||
height = 600;
|
||||
update();
|
||||
setGuiFocus(hookList);
|
||||
}
|
||||
|
||||
void update() {
|
||||
AnyClass@ intf = getClass(field.hookType);
|
||||
array<AnyClass@> classes;
|
||||
getClassesImplementing(classes, intf);
|
||||
|
||||
set_int types;
|
||||
for(uint i = 0, cnt = classes.length; i < cnt; ++i) {
|
||||
auto@ cls = classes[i];
|
||||
if(types.contains(cls.id))
|
||||
continue;
|
||||
types.insert(cls.id);
|
||||
|
||||
Hook@ hook = cast<Hook>(cls.create());
|
||||
if(hook is null)
|
||||
continue;
|
||||
hook.initClass();
|
||||
if(hook.documentation !is null && hook.documentation.hidden)
|
||||
continue;
|
||||
|
||||
string txt = "[b]"+hook.formatDeclaration()+"[/b]";
|
||||
if(hook.documentation !is null) {
|
||||
txt += "\n[offset=24][i][color=#aaa]"+hook.documentation.text+"[/color][/i][/offset]";
|
||||
}
|
||||
|
||||
HookSorter s;
|
||||
s.name = getClass(hook).name;
|
||||
s.text = txt;
|
||||
@s.cls = cls;
|
||||
@s.hook = hook;
|
||||
|
||||
hooks.insertLast(s);
|
||||
}
|
||||
|
||||
hooks.sortAsc();
|
||||
for(uint i = 0, cnt = hooks.length; i < cnt; ++i) {
|
||||
GuiMarkupListText elem(hooks[i].text);
|
||||
elem.basicText = hooks[i].name;
|
||||
hookList.addItem(elem);
|
||||
}
|
||||
}
|
||||
|
||||
bool confirmed = false;
|
||||
void close() {
|
||||
if(!confirmed && field.value == "")
|
||||
field.resetButton.emitClicked();
|
||||
Dialog::close();
|
||||
}
|
||||
|
||||
void confirm() {
|
||||
int selected = hookList.selected;
|
||||
if(selected == -1)
|
||||
return;
|
||||
|
||||
confirmed = true;
|
||||
auto@ s = hooks[selected];
|
||||
string hname = "";
|
||||
if(getClass(field.hookModule+"::"+s.name) !is s.cls)
|
||||
hname += s.cls.module.name+"::";
|
||||
hname += s.name;
|
||||
hname += "()";
|
||||
|
||||
field.value = hname;
|
||||
if(s.hook.arguments.length != 0)
|
||||
openHookEditor(field);
|
||||
else
|
||||
field.emitConfirmed();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked && event.caller is accept && !Closed) {
|
||||
confirm();
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
if(event.type == GUI_Clicked && event.caller is cancel && !Closed) {
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
if(event.type == GUI_Confirmed && event.caller is hookList && hookList.selected >= 0) {
|
||||
confirm();
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
return Dialog::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
void openHookList(HookField@ field) {
|
||||
HookList hl(field);
|
||||
addDialog(hl);
|
||||
setGuiFocus(hl.hookList);
|
||||
}
|
||||
|
||||
void openHookList(HookField@ field, bool isStatic) {
|
||||
HookList hl(field);
|
||||
if(isStatic)
|
||||
hl.confirmed = true;
|
||||
addDialog(hl);
|
||||
setGuiFocus(hl.hookList);
|
||||
}
|
||||
|
||||
void openHookEditor(HookField@ field) {
|
||||
if(field.type is null)
|
||||
return;
|
||||
HookEditor ed(field);
|
||||
addDialog(ed);
|
||||
ed.focus();
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
//Loads a datafile into a logical structure that can be mutated, then
|
||||
//dumped back into the datafile properly.
|
||||
|
||||
class FileDesc {
|
||||
array<LineDesc@> lines;
|
||||
bool exists = false;
|
||||
|
||||
FileDesc() {}
|
||||
FileDesc(const string& filename) {
|
||||
load(filename);
|
||||
}
|
||||
|
||||
bool opEquals(const FileDesc& other) const {
|
||||
if(lines.length != other.lines.length)
|
||||
return false;
|
||||
for(uint i = 0, cnt = lines.length; i < cnt; ++i) {
|
||||
if(lines[i] != other.lines[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void load(const string& filename) {
|
||||
clear();
|
||||
if(fileExists(filename)) {
|
||||
exists = true;
|
||||
ReadFile f(filename, true);
|
||||
f.skipEmpty = false;
|
||||
f.skipComments = false;
|
||||
|
||||
while(f++)
|
||||
lines.insertLast(LineDesc(f));
|
||||
while(lines.length != 0 && lines[lines.length-1].isEmpty && lines[lines.length-1].comment.length == 0)
|
||||
lines.removeAt(lines.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
lines.length = 0;
|
||||
exists = false;
|
||||
}
|
||||
|
||||
void save(const string& filename) {
|
||||
WriteFile file(filename);
|
||||
for(uint i = 0, cnt = lines.length; i < cnt; ++i)
|
||||
lines[i].write(file);
|
||||
}
|
||||
|
||||
string toString() const {
|
||||
string str;
|
||||
for(uint i = 0, cnt = lines.length; i < cnt; ++i)
|
||||
str += lines[i].toString()+"\n";
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
class LineDesc {
|
||||
bool isEmpty = false;
|
||||
bool isKey = true;
|
||||
uint indent = 0;
|
||||
string line;
|
||||
string key;
|
||||
string value;
|
||||
string comment;
|
||||
|
||||
LineDesc() {}
|
||||
LineDesc(const ReadFile& f) {
|
||||
indent = f.indent;
|
||||
isKey = !f.fullLine;
|
||||
|
||||
if(isKey) {
|
||||
key = f.key.trimmed();
|
||||
value = f.value.trimmed();
|
||||
line = f.line.trimmed();
|
||||
isEmpty = false;
|
||||
|
||||
if(value.findFirst("\n") == -1) {
|
||||
int pos = value.findFirst("//");
|
||||
if(pos != -1) {
|
||||
comment = value.substr(pos+2);
|
||||
value = value.substr(0, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
line = f.line.trimmed();
|
||||
int pos = line.findFirst("//");
|
||||
if(pos != -1) {
|
||||
comment = line.substr(pos+2);
|
||||
line = line.substr(0, pos);
|
||||
}
|
||||
|
||||
line = line.trimmed();
|
||||
isEmpty = line.length == 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool opEquals(const LineDesc& other) const {
|
||||
if(other.isEmpty != isEmpty)
|
||||
return false;
|
||||
if(other.isKey != isKey)
|
||||
return false;
|
||||
if(isKey) {
|
||||
if(other.key != key)
|
||||
return false;
|
||||
if(other.value != value)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(other.line != line)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void write(WriteFile& file) {
|
||||
if(isKey && value.length != 0) {
|
||||
file.indent(indent);
|
||||
file.writeKeyValue(key, value);
|
||||
file.deindent(indent);
|
||||
}
|
||||
else
|
||||
file.writeLine(toString());
|
||||
}
|
||||
|
||||
string toString() const {
|
||||
string str;
|
||||
if(!isEmpty || comment.length != 0) {
|
||||
for(uint i = 0; i < indent; ++i)
|
||||
str += "\t";
|
||||
}
|
||||
if(!isEmpty) {
|
||||
if(isKey) {
|
||||
str += key+":";
|
||||
if(value.length != 0)
|
||||
str += " "+value;
|
||||
}
|
||||
else
|
||||
str += line;
|
||||
}
|
||||
if(comment.length != 0) {
|
||||
if(str.length != 0 && !isEmpty)
|
||||
str += " ";
|
||||
str += "//"+comment;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,305 @@
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiText;
|
||||
import editor.fields;
|
||||
import dialogs.Dialog;
|
||||
import string getLocaleFile(IGuiElement@ elem) from "editor.editor";
|
||||
|
||||
bool localesInitialized = false;
|
||||
void initLocaleMap() {
|
||||
if(localesInitialized) {
|
||||
loadLocaleMap();
|
||||
localesInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
dictionary localeMap;
|
||||
dictionary localeValues;
|
||||
string localeName;
|
||||
void loadLocaleMap() {
|
||||
localeName = settings::sLocale;
|
||||
|
||||
string resolved = resolve("locales/"+localeName);
|
||||
if(!fileExists(resolved))
|
||||
localeName = "english";
|
||||
localeMap.deleteAll();
|
||||
|
||||
string folder = topMod.abspath+"/locales/"+localeName;
|
||||
FileList list(folder, "*.txt", true, false);
|
||||
for(uint i = 0, cnt = list.length; i < cnt; ++i) {
|
||||
ReadFile file(list.path[i]);
|
||||
string fname = "locales/"+localeName+"/"+list.basename[i];
|
||||
while(file++) {
|
||||
localeMap.set(file.key, fname);
|
||||
localeValues.set(file.key, file.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string getFromLocale(string ident) {
|
||||
loadLocaleMap();
|
||||
if(ident.length != 0 && ident[0] == '#')
|
||||
ident = ident.substr(1);
|
||||
string val;
|
||||
if(!localeValues.get(ident, val))
|
||||
val = localize(ident);
|
||||
return val;
|
||||
}
|
||||
|
||||
void changeLocale(string ident, string value, string filename = "misc.txt") {
|
||||
initLocaleMap();
|
||||
if(topMod !is baseMod)
|
||||
filename = topMod.ident+"_"+filename;
|
||||
if(ident.length != 0 && ident[0] == '#')
|
||||
ident = ident.substr(1);
|
||||
|
||||
//Check if it's in an existing locale
|
||||
string fname;
|
||||
if(localeMap.get(ident, fname)) {
|
||||
filename = path_join(topMod.abspath, fname);
|
||||
changeLocaleIn(filename, ident, value);
|
||||
localeValues.set(ident, value);
|
||||
}
|
||||
else {
|
||||
localeMap.set(ident, "locales/"+localeName+"/"+filename);
|
||||
filename = path_join(path_join(topMod.abspath, "locales/"+localeName), filename);
|
||||
changeLocaleIn(filename, ident, value);
|
||||
localeValues.set(ident, value);
|
||||
}
|
||||
}
|
||||
|
||||
void ensureFile(const string& path) {
|
||||
string dir = path_up(path);
|
||||
array<string> folders;
|
||||
while(!fileExists(dir) && dir.length != 0) {
|
||||
folders.insertLast(dir);
|
||||
dir = path_up(dir);
|
||||
}
|
||||
for(int i = int(folders.length-1); i >= 0; --i)
|
||||
makeDirectory(folders[i]);
|
||||
}
|
||||
|
||||
void changeLocaleIn(const string& filename, const string& ident, const string& value) {
|
||||
array<string> lines;
|
||||
int pos = -1;
|
||||
|
||||
//Read existing file
|
||||
if(fileExists(filename)) {
|
||||
ReadFile read(filename);
|
||||
read.allowLines = true;
|
||||
read.allowMultiline = false;
|
||||
read.skipEmpty = false;
|
||||
read.skipComments = false;
|
||||
bool inMulti = false;
|
||||
while(read++) {
|
||||
if(inMulti) {
|
||||
if(read.line.trimmed().startswith(">>"))
|
||||
inMulti = false;
|
||||
continue;
|
||||
}
|
||||
if(read.key == ident) {
|
||||
pos = lines.length;
|
||||
if(read.value.trimmed().startswith("<<"))
|
||||
inMulti = true;
|
||||
read.key = "";
|
||||
continue;
|
||||
}
|
||||
lines.insertLast(read.line);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(value.length == 0)
|
||||
return;
|
||||
ensureFile(filename);
|
||||
}
|
||||
|
||||
for(int i = lines.length-1; i >= 0; --i) {
|
||||
if(lines[i].trimmed().length == 0)
|
||||
lines.removeAt(i);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
//Manipulate lines
|
||||
if(value.length != 0) {
|
||||
string line = ident+": ";
|
||||
if(value.findFirst("\n") == -1) {
|
||||
line += escape(value);
|
||||
}
|
||||
else {
|
||||
line += "<<\r\n";
|
||||
array<string>@ splt = value.split("\n");
|
||||
for(uint i = 0, cnt = splt.length; i < cnt; ++i) {
|
||||
if(splt[i].length == 0)
|
||||
line += "\r\n";
|
||||
else
|
||||
line += "\t"+splt[i].trimmed()+"\r\n";
|
||||
}
|
||||
line += ">>";
|
||||
}
|
||||
|
||||
if(pos == -1)
|
||||
lines.insertLast(line);
|
||||
else
|
||||
lines.insertAt(pos, line);
|
||||
}
|
||||
|
||||
//Write new file
|
||||
WriteFile write(filename);
|
||||
for(uint i = 0, cnt = lines.length; i < cnt; ++i)
|
||||
write.writeLine(lines[i]);
|
||||
}
|
||||
|
||||
class LocaleEditor : Dialog {
|
||||
LocaleField@ field;
|
||||
GuiButton@ accept;
|
||||
GuiButton@ cancel;
|
||||
|
||||
GuiText@ identLabel;
|
||||
GuiTextbox@ identBox;
|
||||
GuiButton@ identLoad;
|
||||
|
||||
GuiText@ valueLabel;
|
||||
GuiTextbox@ valueBox;
|
||||
|
||||
GuiText@ previewLabel;
|
||||
GuiPanel@ previewPanel;
|
||||
GuiMarkupText@ previewBox;
|
||||
|
||||
bool changed = false;
|
||||
string localeIdent;
|
||||
string suffix;
|
||||
string origValue;
|
||||
|
||||
LocaleEditor(LocaleField@ field) {
|
||||
@this.field = field;
|
||||
super(null);
|
||||
width = 1000;
|
||||
addTitle("Edit Locale");
|
||||
|
||||
string value;
|
||||
localeIdent = field.value;
|
||||
suffix = "";
|
||||
|
||||
if(localeIdent.length == 0 || localeIdent[0] != '#') {
|
||||
value = localeIdent;
|
||||
localeIdent = "";
|
||||
}
|
||||
else {
|
||||
int sep = localeIdent.findFirst(":");
|
||||
if(sep != -1) {
|
||||
suffix = localeIdent.substr(sep);
|
||||
localeIdent = localeIdent.substr(0, sep);
|
||||
}
|
||||
value = getFromLocale(localeIdent);
|
||||
origValue = value;
|
||||
}
|
||||
|
||||
@identLabel = GuiText(bg, Alignment(Left+10, Top+34, Width=80, Height=30), "Locale Key:");
|
||||
identLabel.font = FT_Bold;
|
||||
@identBox = GuiTextbox(bg, Alignment(Left+100, Top+34, Width=400, Height=30), localeIdent);
|
||||
identBox.setIdentifierLimit();
|
||||
identBox.characterLimit.insert('#');
|
||||
@identLoad = GuiButton(bg, Alignment(Left+508, Top+34, Width=80, Height=30), "Load");
|
||||
setMarkupTooltip(identLoad, "Load the value of the specified locale key into the value box. Will override anything already written.");
|
||||
|
||||
@valueLabel = GuiText(bg, Alignment(Left+10, Top+70, Left+0.5f-6, Top+100), "Value:");
|
||||
valueLabel.font = FT_Bold;
|
||||
@valueBox = GuiTextbox(bg, Alignment(Left+12, Top+100, Left+0.5f-6, Bottom-60));
|
||||
valueBox.multiLine = true;
|
||||
|
||||
@previewLabel = GuiText(bg, Alignment(Left+0.5f+4, Top+70, Right-12, Top+100), "Preview:");
|
||||
previewLabel.font = FT_Bold;
|
||||
@previewPanel = GuiPanel(bg, Alignment(Left+0.5f+6, Top+100, Right-12, Bottom-60));
|
||||
@previewBox = GuiMarkupText(previewPanel, recti_area(0,0,482,100));
|
||||
|
||||
@accept = GuiButton(bg, recti());
|
||||
accept.text = locale::ACCEPT;
|
||||
accept.tabIndex = 100;
|
||||
@accept.callback = this;
|
||||
accept.color = colors::Green;
|
||||
|
||||
@cancel = GuiButton(bg, recti());
|
||||
cancel.text = locale::CANCEL;
|
||||
cancel.tabIndex = 101;
|
||||
@cancel.callback = this;
|
||||
cancel.color = colors::Red;
|
||||
|
||||
alignAcceptButtons(accept, cancel);
|
||||
|
||||
valueBox.text = value;
|
||||
previewBox.text = value;
|
||||
valueBox.scroll = 0;
|
||||
|
||||
height = 500;
|
||||
update();
|
||||
bg.updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void update() {
|
||||
previewBox.text = valueBox.text;
|
||||
}
|
||||
|
||||
void confirm() {
|
||||
if(changed) {
|
||||
if(identBox.text.length != 0) {
|
||||
string fname = field.filename;
|
||||
if(fname.length == 0)
|
||||
fname = getLocaleFile(field);
|
||||
if(origValue != valueBox.text)
|
||||
changeLocale(identBox.text, valueBox.text, fname);
|
||||
}
|
||||
}
|
||||
|
||||
localeIdent = identBox.text;
|
||||
if(localeIdent.length == 0) {
|
||||
field.value = valueBox.text;
|
||||
}
|
||||
else {
|
||||
if(localeIdent[0] != '#')
|
||||
localeIdent = "#"+localeIdent;
|
||||
field.value = localeIdent+suffix;
|
||||
}
|
||||
field.emitConfirmed();
|
||||
}
|
||||
|
||||
void focus() {
|
||||
valueBox.focus();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked && event.caller is accept && !Closed) {
|
||||
confirm();
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
if(event.type == GUI_Clicked && event.caller is cancel && !Closed) {
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
if(event.type == GUI_Changed && (event.caller is valueBox || event.caller is identBox)) {
|
||||
previewBox.text = valueBox.text;
|
||||
previewPanel.updateAbsolutePosition();
|
||||
changed = true;
|
||||
return true;
|
||||
}
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is identLoad) {
|
||||
string v = getFromLocale(identBox.text);
|
||||
valueBox.text = v;
|
||||
previewBox.text = v;
|
||||
previewPanel.updateAbsolutePosition();
|
||||
changed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Dialog::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
void openLocaleEditor(LocaleField@ field) {
|
||||
LocaleEditor ed(field);
|
||||
addDialog(ed);
|
||||
ed.focus();
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
import tabs.Tab;
|
||||
import tabs.tabbar;
|
||||
import editor.editor;
|
||||
import dialogs.MessageDialog;
|
||||
import dialogs.InputDialog;
|
||||
import elements.GuiSkinElement;
|
||||
import icons;
|
||||
import cloud_mods;
|
||||
|
||||
class ModInfoFile : FileDef {
|
||||
array<string> compatModes = {"", "200"};
|
||||
|
||||
ModInfoFile() {
|
||||
field("Name", AT_Custom, "", doc="The mod's full name.");
|
||||
field("Description", AT_Custom, "", doc="Description of the mod and its contents.");
|
||||
field("Base Mod", AT_Boolean, "False", doc="Whether this mod is considered a full base mod. Only one base mod may be active at the same time. [b][color=#f00]Should only be checked for total conversion mods that want to override all base files.[/color][/b]");
|
||||
field("Derives From", AT_Custom, "", doc="Inherit the file structure of a different mod. [b]Should only be used for specific extentions of different mods.[/b]");
|
||||
field("Override", AT_Custom, "", repeatable=true, doc="[b]Only applies when Deriving From a different mod.[/b] Ignore any files in the specified directory from the base mod.");
|
||||
field("Compatibility", AT_Selection, "", doc="Which version of the game this mod was created/updated for.").setOptions(compatModes);
|
||||
}
|
||||
};
|
||||
|
||||
class Legal : onButtonClick {
|
||||
bool onClick(GuiButton@ btn) {
|
||||
cloud::openLegalPrompt();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
array<string> contentTags = {
|
||||
"Shipsets",
|
||||
"Subsystems",
|
||||
"Resources",
|
||||
"Races",
|
||||
"Maps",
|
||||
"Graphics",
|
||||
"Sounds"
|
||||
};
|
||||
|
||||
class ModInfoTab : Tab, IInputDialogCallback {
|
||||
GuiPanel@ editPanel;
|
||||
BlockEditor@ editor;
|
||||
GuiMarkupText@ header;
|
||||
GuiButton@ uploadButton;
|
||||
GuiText@ folderText;
|
||||
GuiButton@ folderButton;
|
||||
MessageDialog@ diag;
|
||||
|
||||
ModInfoTab() {
|
||||
super();
|
||||
title = "modinfo.txt";
|
||||
|
||||
GuiSkinElement bg(this, Alignment(Left+12, Top+12, Right-12, Top+200-12), SS_PlainBox);
|
||||
|
||||
@header = GuiMarkupText(this, Alignment(Left+24, Top+24, Right-24, Top+200-46-12));
|
||||
|
||||
@folderText = GuiText(this, Alignment(Left+424, Top+200-46-12, Right-234, Height=40));
|
||||
folderText.color = Color(0xaaaaaaff);
|
||||
folderText.font = FT_Italic;
|
||||
folderText.horizAlign = 1.0;
|
||||
folderText.vertAlign = 0.9;
|
||||
folderText.text = topMod.abspath;
|
||||
|
||||
@folderButton = GuiButton(this, Alignment(Right-224, Top+200-46-12, Width=200, Height=40), "Open Directory");
|
||||
folderButton.buttonIcon = spritesheet::FileIcons+2;
|
||||
|
||||
@uploadButton = GuiButton(this, Alignment(Left+24, Top+200-46-12, Width=400, Height=40), "Upload to Steam Workshop");
|
||||
uploadButton.buttonIcon = icons::Export;
|
||||
uploadButton.color = Color(0xffff00ff);
|
||||
|
||||
@editPanel = GuiPanel(this, Alignment(Left+12, Top+200, Right-12, Bottom-12));
|
||||
@editor = BlockEditor(editPanel);
|
||||
editor.parse(path_join(topMod.abspath, "modinfo.txt"), ModInfoFile());
|
||||
|
||||
for(uint i = 0, cnt = editor.fields.length; i < cnt; ++i) {
|
||||
if(editor.fields[i].def.key == "Description")
|
||||
cast<TextField>(editor.fields[i].elem).setLines(5);
|
||||
}
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void changeCallback(InputDialog@ dialog) {}
|
||||
void inputCallback(InputDialog@ dialog, bool accepted) {
|
||||
if(accepted) {
|
||||
array<string> tags;
|
||||
tags.insertLast(dialog.getSelectionValue(1));
|
||||
for(uint i = 0; i < contentTags.length; ++i)
|
||||
if(dialog.getToggle(i + 2))
|
||||
tags.insertLast(contentTags[i]);
|
||||
|
||||
uploadMod(topMod.name, dialog.getTextInput(0), tags);
|
||||
@diag = message("Uploading to steam workshop...");
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.type == GUI_Confirmed) {
|
||||
for(uint i = 0, cnt = editor.fields.length; i < cnt; ++i) {
|
||||
if(editor.fields[i].def.key == "Name") {
|
||||
string val = editor.fields[i].elem.value;
|
||||
if(val.length == 0)
|
||||
editor.fields[i].elem.value = topMod.ident;
|
||||
topMod.name = editor.fields[i].elem.value;
|
||||
}
|
||||
else if(editor.fields[i].def.key == "Description") {
|
||||
string val = editor.fields[i].elem.value;
|
||||
topMod.description = val;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
editor.commit();
|
||||
string path = path_join(topMod.abspath, "modinfo.txt");
|
||||
editor.file.save(path);
|
||||
saveModState();
|
||||
updateAbsolutePosition();
|
||||
return true;
|
||||
}
|
||||
else if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is uploadButton) {
|
||||
InputDialog@ dialog = InputDialog(this, this);
|
||||
dialog.width = 650;
|
||||
dialog.addTitle("Upload to Steam Workshop");
|
||||
dialog.accept.text = "Upload";
|
||||
dialog.accept.color = colors::Green;
|
||||
|
||||
dialog.addTextInput("Change Note", "", height=200);
|
||||
|
||||
dialog.addSelection("Type");
|
||||
dialog.addItem("Mod");
|
||||
|
||||
for(uint i = 0; i < contentTags.length; ++i)
|
||||
dialog.addToggle("Tag: " + contentTags[i], false);
|
||||
|
||||
dialog.height += 60;
|
||||
GuiButton legalBtn(dialog.bg, Alignment(Left+0.5f-250, Bottom-84, Width=500, Height=34));
|
||||
legalBtn.text = "By submitting this item, you agree to the workshop terms of service.";
|
||||
@legalBtn.onClick = Legal();
|
||||
|
||||
addDialog(dialog);
|
||||
dialog.focusInput();
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is folderButton) {
|
||||
openFileManager(topMod.abspath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
string txt = format("Welcome to the mod editor. You are currently editing the [b]$1[/b] mod.", topMod.name);
|
||||
bool errors = false;
|
||||
|
||||
if(!fileExists(path_join(topMod.abspath, "logo.png"))) {
|
||||
txt += format(
|
||||
"\n\n[b][color=#f00]Please ensure a thumbnail picture for your mod is located in $1.[/color][/b]",
|
||||
escape(path_join(topMod.abspath, "logo.png").replaced("\\","/"))
|
||||
);
|
||||
errors = true;
|
||||
}
|
||||
|
||||
uploadButton.visible = cloud::isActive;
|
||||
uploadButton.disabled = errors;
|
||||
|
||||
header.text = txt;
|
||||
}
|
||||
|
||||
double timer = 0.0;
|
||||
void tick(double time) {
|
||||
timer -= time;
|
||||
if(timer <= 0.0) {
|
||||
timer = 1.0;
|
||||
update();
|
||||
}
|
||||
|
||||
if(diag !is null) {
|
||||
if(diag.Closed) {
|
||||
@diag = null;
|
||||
}
|
||||
else {
|
||||
switch(uploadStage) {
|
||||
case 0:
|
||||
diag.txt.text = "Finished uploading to steam workshop!";
|
||||
diag.ok.visible = true;
|
||||
break;
|
||||
case 1:
|
||||
diag.txt.text = "Uploading to steam workshop.... Creating item...";
|
||||
diag.ok.visible = false;
|
||||
break;
|
||||
case 2:
|
||||
diag.txt.text = "Uploading to steam workshop.... Updating item....";
|
||||
diag.ok.visible = false;
|
||||
break;
|
||||
case 3:
|
||||
diag.txt.text = "Uploading to steam workshop.... "+uploadPercent+"%";
|
||||
diag.ok.visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return icons::Info;
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0x74fc4eff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x37ff00ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x408c2bff);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createModInfoTab() {
|
||||
return ModInfoTab();
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
import tabs.Tab;
|
||||
import tabs.tabbar;
|
||||
import editor.files;
|
||||
import editor.editor;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiSkinElement;
|
||||
import dialogs.QuestionDialog;
|
||||
from tabs.ResearchTab import ResearchEditor;
|
||||
import icons;
|
||||
|
||||
class OverviewTab : Tab, QuestionDialogCallback {
|
||||
GuiPanel@ filePanel;
|
||||
FileFolder@ files;
|
||||
string selFile;
|
||||
GuiButton@ editButton;
|
||||
GuiButton@ deleteButton;
|
||||
|
||||
array<GuiButton@> buttons;
|
||||
|
||||
GuiButton@ researchGridBtn;
|
||||
GuiButton@ researchGridBtn2;
|
||||
|
||||
OverviewTab() {
|
||||
super();
|
||||
title = "Overview";
|
||||
|
||||
GuiSkinElement bg(this, Alignment(Left, Top, Left+400, Bottom), SS_Panel);
|
||||
@filePanel = GuiPanel(this, Alignment(Left, Top, Left+400, Bottom-50));
|
||||
@files = FileFolder(filePanel, recti());
|
||||
|
||||
@editButton = GuiButton(this, Alignment(Left+200-154, Bottom-46, Width=150, Height=42), "Edit");
|
||||
editButton.buttonIcon = icons::Paint;
|
||||
editButton.color = colors::Green;
|
||||
editButton.visible = false;
|
||||
|
||||
@deleteButton = GuiButton(this, Alignment(Left+200+4, Bottom-46, Width=150, Height=42), "Delete");
|
||||
deleteButton.buttonIcon = icons::Delete;
|
||||
deleteButton.color = colors::Red;
|
||||
deleteButton.visible = false;
|
||||
|
||||
GuiMarkupText desc(this, Alignment(Left+412, Top+12, Right-12, Top+42));
|
||||
desc.text = "[i]Choose what type of data files to edit, or choose a specific file contained in your mod from the sidebar to edit.[/i]";
|
||||
|
||||
for(uint i = 0, cnt = fileClasses.length; i < cnt; ++i) {
|
||||
GuiButton btn(this, Alignment(Left+412+(i%3)*258, Top+42+(i/3)*50, Width=250, Height=42));
|
||||
btn.font = FT_Medium;
|
||||
|
||||
string txt = fileClasses[i];
|
||||
txt[0] = uppercase(txt[0]);
|
||||
btn.text = txt;
|
||||
|
||||
buttons.insertLast(btn);
|
||||
}
|
||||
|
||||
int y = ceil(double(fileClasses.length) / 3.0) * 50 + 42 + 50;
|
||||
@researchGridBtn = GuiButton(this, Alignment(Left+412, Top+y, Width=250, Height=42), "Research Grid");
|
||||
researchGridBtn.font = FT_Medium;
|
||||
|
||||
if(hasDLC("Heralds")) {
|
||||
@researchGridBtn2 = GuiButton(this, Alignment(Left+712, Top+y, Width=250, Height=42), "Grid (Heralds)");
|
||||
researchGridBtn2.font = FT_Medium;
|
||||
}
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0x83cfffff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x009cffff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x49738dff);
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return icons::Edit;
|
||||
}
|
||||
|
||||
void show() override {
|
||||
files.load(topMod.abspath, base="./", resolve=false);
|
||||
selFile = "";
|
||||
editButton.visible = false;
|
||||
deleteButton.visible = false;
|
||||
Tab::show();
|
||||
}
|
||||
|
||||
void questionCallback(QuestionDialog@ dialog, int answer) {
|
||||
if(answer == QA_Yes) {
|
||||
string path = path_join(topMod.abspath, selFile);
|
||||
if(fileExists(path))
|
||||
::deleteFile(path);
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
void open(Tab@ tab, int button = 0) {
|
||||
if(tab !is null) {
|
||||
if(locked || button == 2) {
|
||||
newTab(tab);
|
||||
switchToTab(tab);
|
||||
}
|
||||
else {
|
||||
browseTab(tab, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is editButton) {
|
||||
open(createEditorTab(selFile), evt.value);
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is deleteButton) {
|
||||
question("Are you sure you wish to delete "+selFile+" from the mod? This cannot be undone.\n\nIf the file consisted of changes to a base mod file, deleting the file from your mod will revert the changes back to the original version.", this);
|
||||
}
|
||||
else if(evt.caller is researchGridBtn) {
|
||||
open(ResearchEditor("base_grid.txt", "Base"));
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is researchGridBtn2) {
|
||||
open(ResearchEditor("heralds_grid.txt", "Heralds"));
|
||||
return true;
|
||||
}
|
||||
else for(uint i = 0, cnt = buttons.length; i < cnt; ++i) {
|
||||
if(buttons[i] is evt.caller) {
|
||||
auto@ tab = createEditorTab(fileFolders[i], cast<FileDef>(getClass(fileTypes[i]).create()));
|
||||
open(tab, evt.value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(evt.type == GUI_Confirmed) {
|
||||
if(evt.caller is files) {
|
||||
setGuiFocus(this);
|
||||
selFile = files.getSelection().basePath.substr(2);
|
||||
editButton.visible = canEditFile(selFile);
|
||||
deleteButton.visible = selFile != "modinfo.txt";
|
||||
}
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createOverviewTab() {
|
||||
return OverviewTab();
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiDraggable;
|
||||
|
||||
final class ElementDefinition {
|
||||
string type;
|
||||
Alignment alignment;
|
||||
|
||||
ElementDefinition(IGuiElement@ element) {
|
||||
type = element.elementType;
|
||||
|
||||
BaseGuiElement@ ele = cast<BaseGuiElement@>(element);
|
||||
alignment = ele.Alignment;
|
||||
}
|
||||
};
|
||||
|
||||
final class GuiEditor : BaseGuiElement {
|
||||
BaseGuiElement@ focus;
|
||||
GuiDraggable@ editPanel;
|
||||
GuiElementEditor@ editor;
|
||||
bool left = false, top = false, right = false, bottom = false;
|
||||
|
||||
GuiEditor() {
|
||||
super(null, Alignment_Fill());
|
||||
|
||||
@editPanel = GuiDraggable(this, recti(0,0,128,128));
|
||||
editPanel.visible = false;
|
||||
|
||||
@editor = GuiElementEditor(editPanel);
|
||||
}
|
||||
|
||||
void drawScaleBound(AlignedPoint@ bound, const recti& within, bool horiz) {
|
||||
//Only show lines for scaled alignments
|
||||
if(bound.percent == 0.f)
|
||||
return;
|
||||
|
||||
if(horiz) {
|
||||
int y = within.topLeft.y + bound.resolve(within.size.height);
|
||||
skin.draw(SS_AlignmentBoundHoriz, 0, recti(0,y,screenSize.width,y+1));
|
||||
}
|
||||
else {
|
||||
int x = within.topLeft.x + bound.resolve(within.size.width);
|
||||
skin.draw(SS_AlignmentBoundVert, 0, recti(x,0,x+1,screenSize.height));
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(focus !is null) {
|
||||
//Draw bounding box of selected element
|
||||
skin.draw(SS_EditHighlight, 0, focus.absolutePosition);
|
||||
|
||||
//Draw alignment bounds
|
||||
Alignment@ align = focus.Alignment;
|
||||
if(align !is null) {
|
||||
recti within = focus.parent.absolutePosition;
|
||||
drawScaleBound(align.left, within, false);
|
||||
drawScaleBound(align.right, within, false);
|
||||
drawScaleBound(align.top, within, true);
|
||||
drawScaleBound(align.bottom, within, true);
|
||||
}
|
||||
}
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
void chooseElement(vec2i point) {
|
||||
//Hide this element so it won't be chosen
|
||||
Visible = false;
|
||||
IGuiElement@ element = getRootGuiElement().elementFromPosition(point);
|
||||
Visible = true;
|
||||
|
||||
@focus = cast<BaseGuiElement@>(element);
|
||||
editPanel.visible = focus !is null;
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
chooseElement(vec2i(event.x, event.y));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return BaseGuiElement::onMouseEvent(event,source);
|
||||
}
|
||||
|
||||
void nudge(vec2i amount) {
|
||||
if(focus is null)
|
||||
return;
|
||||
|
||||
if(focus.Alignment is null) {
|
||||
focus.move(amount);
|
||||
}
|
||||
else {
|
||||
//Adjust an alignment if its key is pressed, or no key is pressed (WASD)
|
||||
Alignment@ align = focus.Alignment;
|
||||
if(top || !(left || right || bottom))
|
||||
align.top.pixels += align.top.type == AS_Top ? amount.y : -amount.y;
|
||||
if(bottom || !(left || right || top))
|
||||
align.bottom.pixels += align.bottom.type == AS_Top ? amount.y : -amount.y;
|
||||
if(left || !(top || right || bottom))
|
||||
align.left.pixels += align.left.type == AS_Left ? amount.x : -amount.x;
|
||||
if(right || !(left || top || bottom))
|
||||
align.right.pixels += align.right.type == AS_Left ? amount.x : -amount.x;
|
||||
}
|
||||
|
||||
focus.updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void nudgeScale(vec2f amount) {
|
||||
if(focus is null)
|
||||
return;
|
||||
|
||||
if(focus.Alignment is null) {
|
||||
//TODO: Generate an alignment
|
||||
@focus.Alignment = Alignment(focus.rect);
|
||||
}
|
||||
|
||||
//Adjust an alignment if its key is pressed, or no key is pressed (WASD)
|
||||
Alignment@ align = focus.Alignment;
|
||||
if(top || !(left || right || bottom))
|
||||
align.top.percent += align.top.type == AS_Top ? amount.y : -amount.y;
|
||||
if(bottom || !(left || right || top))
|
||||
align.bottom.percent += align.bottom.type == AS_Top ? amount.y : -amount.y;
|
||||
if(left || !(top || right || bottom))
|
||||
align.left.percent += align.left.type == AS_Left ? amount.x : -amount.x;
|
||||
if(right || !(left || top || bottom))
|
||||
align.right.percent += align.right.type == AS_Left ? amount.x : -amount.x;
|
||||
|
||||
focus.updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case KET_Key_Down:
|
||||
switch(event.key) {
|
||||
case KEY_UP:
|
||||
if(ctrlKey)
|
||||
nudgeScale(vec2f(0,shiftKey ? -0.04 : -0.0025));
|
||||
else
|
||||
nudge(vec2i(0,shiftKey ? -10 : -1));
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if(ctrlKey)
|
||||
nudgeScale(vec2f(0,shiftKey ? 0.04 : 0.0025));
|
||||
else
|
||||
nudge(vec2i(0,shiftKey ? 10 : 1));
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if(ctrlKey)
|
||||
nudgeScale(vec2f(shiftKey ? -0.04 : -0.0025, 0));
|
||||
else
|
||||
nudge(vec2i(shiftKey ? -10 : -1, 0));
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if(ctrlKey)
|
||||
nudgeScale(vec2f(shiftKey ? 0.04 : 0.0025, 0));
|
||||
else
|
||||
nudge(vec2i(shiftKey ? 10 : 1, 0));
|
||||
break;
|
||||
case KEY_ESC:
|
||||
@parent = null;
|
||||
break;
|
||||
case 'W': top = true; break;
|
||||
case 'A': left = true; break;
|
||||
case 'S': bottom = true; break;
|
||||
case 'D': right = true; break;
|
||||
}
|
||||
break;
|
||||
case KET_Key_Up:
|
||||
switch(event.key) {
|
||||
case 'W': top = false; break;
|
||||
case 'A': left = false; break;
|
||||
case 'S': bottom = false; break;
|
||||
case 'D': right = false; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return BaseGuiElement::onKeyEvent(event, source);
|
||||
}
|
||||
};
|
||||
|
||||
class GuiElementEditor : BaseGuiElement {
|
||||
BaseGuiElement@ element;
|
||||
|
||||
GuiElementEditor(BaseGuiElement@ parent) {
|
||||
super(parent, Alignment_Fill());
|
||||
GuiSkinElement bg(this, Alignment_Fill(), SS_Panel);
|
||||
}
|
||||
|
||||
void set_element(IGuiElement@ ele) {
|
||||
@element = cast<BaseGuiElement@>(ele);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class GuiEditorCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
GuiEditor@ editor = GuiEditor();
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("gui_editor", GuiEditorCommand());
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
import dialogs.MessageDialog;
|
||||
import dialogs.InputDialog;
|
||||
import dialogs.Dialog;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiResizeHandle;
|
||||
import influence;
|
||||
|
||||
class PlayEmpireDialog : Dialog {
|
||||
GuiButton@[] buttons;
|
||||
Empire@[] empires;
|
||||
|
||||
PlayEmpireDialog() {
|
||||
super(null);
|
||||
|
||||
addTitle(locale::PLAY_EMPIRE_TITLE, closeButton=false);
|
||||
|
||||
height = 32;
|
||||
|
||||
//Empires
|
||||
for(uint i = 0, cnt = getEmpireCount(); i < cnt; ++i) {
|
||||
Empire@ emp = getEmpire(i);
|
||||
if(!emp.major)
|
||||
continue;
|
||||
|
||||
GuiText text(window, recti(12, height, width-212, height+30));
|
||||
text.text = emp.name;
|
||||
text.color = emp.color;
|
||||
text.font = FT_Subtitle;
|
||||
|
||||
GuiButton btn(window, recti(width-200, height, width-12, height+30));
|
||||
btn.text = locale::PLAY_EMPIRE;
|
||||
btn.color = emp.color;
|
||||
buttons.insertLast(btn);
|
||||
empires.insertLast(emp);
|
||||
height += 34;
|
||||
}
|
||||
|
||||
//Spectating
|
||||
{
|
||||
GuiButton btn(window, recti(width-200, height, width-12, height+30));
|
||||
btn.text = locale::SPECTATE;
|
||||
buttons.insertLast(btn);
|
||||
empires.insertLast(null);
|
||||
height += 34;
|
||||
}
|
||||
|
||||
height += 12;
|
||||
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(Closed)
|
||||
return false;
|
||||
if(event.type == GUI_Clicked) {
|
||||
for(uint i = 0, cnt = buttons.length(); i < cnt; ++i) {
|
||||
if(buttons[i] is cast<GuiButton@>(event.caller)) {
|
||||
Empire@ emp = empires[i];
|
||||
if(emp is null) {
|
||||
close();
|
||||
playAsEmpire(spectatorEmpire);
|
||||
wantSpectator = true;
|
||||
}
|
||||
else {
|
||||
playAsEmpire(emp);
|
||||
wantSpectator = false;
|
||||
}
|
||||
if(chooseOpen) {
|
||||
chooseOpen = false;
|
||||
close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Dialog::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
class PlayEmpire : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
int id = toInt(args);
|
||||
Empire@ emp;
|
||||
if(id == -1)
|
||||
@emp = spectatorEmpire;
|
||||
else
|
||||
@emp = getEmpireByID(id);
|
||||
if(emp !is null)
|
||||
playAsEmpire(emp);
|
||||
else
|
||||
throw("Invalid empire id: "+args);
|
||||
}
|
||||
}
|
||||
|
||||
void change_emp(bool pressed) {
|
||||
chooseOpen = true;
|
||||
wantSpectator = false;
|
||||
if(dialog is null || dialog.Closed) {
|
||||
@dialog = PlayEmpireDialog();
|
||||
addDialog(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
bool wasMPClient = false;
|
||||
bool wantSpectator = false;
|
||||
bool chooseOpen = false;
|
||||
Dialog@ dialog;
|
||||
MPChatWindow@ mpChatWin;
|
||||
void init() {
|
||||
if(mpClient) {
|
||||
addConsoleCommand("play_emp", PlayEmpire());
|
||||
wasMPClient = true;
|
||||
}
|
||||
if(mpClient || mpServer)
|
||||
@mpChatWin = MPChatWindow();
|
||||
keybinds::Global.addBind(KB_CHANGE_EMPIRE, "change_emp");
|
||||
keybinds::Global.addBind(KB_MP_CHAT, "mp_chat");
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(wasMPClient && !mpIsConnected()) {
|
||||
message("Lost connection to server:\n "
|
||||
+localize("DISCONNECT_"+uint(mpDisconnectReason)));
|
||||
wasMPClient = false;
|
||||
}
|
||||
|
||||
if(mpClient) {
|
||||
if(dialog is null || dialog.Closed) {
|
||||
if(playerEmpire is spectatorEmpire && !wantSpectator) {
|
||||
@dialog = PlayEmpireDialog();
|
||||
addDialog(dialog);
|
||||
}
|
||||
}
|
||||
else if(!chooseOpen) {
|
||||
if(playerEmpire !is spectatorEmpire || wantSpectator) {
|
||||
dialog.close();
|
||||
@dialog = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mpChatWin !is null)
|
||||
mpChatWin.tick(time);
|
||||
}
|
||||
|
||||
class MPChatWindow : GuiDraggable {
|
||||
GuiBackgroundPanel@ bg;
|
||||
GuiPanel@ panel;
|
||||
GuiMarkupText@ log;
|
||||
GuiTextbox@ input;
|
||||
GuiResizeHandle@ handle;
|
||||
GuiButton@ closeButton;
|
||||
|
||||
GuiDropdown@ mode;
|
||||
array<uint> modeMasks;
|
||||
|
||||
array<string> messages;
|
||||
|
||||
Mutex mtx;
|
||||
array<string> waitingMessages;
|
||||
|
||||
MPChatWindow() {
|
||||
super(null, recti_area(vec2i(screenSize.width - 412, 200), vec2i(400, 200)));
|
||||
@bg = GuiBackgroundPanel(this, Alignment_Fill());
|
||||
bg.title = locale::CHAT;
|
||||
bg.titleColor = Color(0xb3fe00ff);
|
||||
|
||||
@closeButton = GuiButton(bg, Alignment(Right-31, Top+3, Right-5, Top+28), "X");
|
||||
closeButton.color = colors::Red;
|
||||
|
||||
@handle = GuiResizeHandle(this, Alignment(Right-12, Bottom-12, Right, Bottom));
|
||||
handle.minSize = vec2i(200, 100);
|
||||
|
||||
@panel = GuiPanel(bg, Alignment(Left+7, Top+34, Right-8, Bottom-38));
|
||||
@log = GuiMarkupText(panel, recti_area(0, 0, 100, 100));
|
||||
@input = GuiTextbox(bg, Alignment(Left+6, Bottom-36, Right-136, Bottom-6));
|
||||
|
||||
@mode = GuiDropdown(bg, Alignment(Right-133, Bottom-36, Right-6, Bottom-6));
|
||||
|
||||
log.text = locale::MP_CHAT_INTRO;
|
||||
|
||||
updateMode();
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
array<Treaty> treaties;
|
||||
void updateMode() {
|
||||
string prev;
|
||||
if(uint(mode.selected) < mode.itemCount)
|
||||
prev = mode.getItemElement(mode.selected).get();
|
||||
|
||||
modeMasks.length = 0;
|
||||
uint ind = 0;
|
||||
|
||||
mode.setItem(ind++, locale::MP_CHAT_ALL);
|
||||
modeMasks.insertLast(0xffffffff);
|
||||
|
||||
mode.setItem(ind++, locale::MP_CHAT_ALLIES);
|
||||
modeMasks.insertLast(playerEmpire.mask);
|
||||
|
||||
mode.setItem(ind++, locale::MP_CHAT_PEACE);
|
||||
modeMasks.insertLast(playerEmpire.mask);
|
||||
|
||||
for(uint i = 0, cnt = getEmpireCount(); i < cnt; ++i) {
|
||||
auto@ other = getEmpire(i);
|
||||
if(other is playerEmpire)
|
||||
continue;
|
||||
if(!other.major)
|
||||
continue;
|
||||
|
||||
if(playerEmpire.ForcedPeaceMask & other.mask != 0)
|
||||
modeMasks[1] |= other.mask;
|
||||
if(!playerEmpire.isHostile(other))
|
||||
modeMasks[2] |= other.mask;
|
||||
|
||||
mode.setItem(ind++, format(locale::MP_CHAT_TO, other.name));
|
||||
modeMasks.insertLast(other.mask | playerEmpire.mask);
|
||||
}
|
||||
|
||||
treaties.syncFrom(getActiveTreaties());
|
||||
for(uint i = 0, cnt = treaties.length; i < cnt; ++i) {
|
||||
auto@ treaty = treaties[i];
|
||||
mode.setItem(ind++, format(locale::MP_CHAT_TO, treaty.name));
|
||||
modeMasks.insertLast(treaty.presentMask | playerEmpire.mask);
|
||||
}
|
||||
|
||||
mode.removeItemsFrom(ind);
|
||||
|
||||
mode.selected = 0;
|
||||
for(uint i = 0, cnt = modeMasks.length; i < cnt; ++i) {
|
||||
if(mode.getItemElement(i).get() == prev) {
|
||||
mode.selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double timer = 0;
|
||||
void tick(double time) {
|
||||
Lock lck(mtx);
|
||||
for(uint i = 0, cnt = waitingMessages.length; i < cnt; ++i)
|
||||
addChat(waitingMessages[i]);
|
||||
if(waitingMessages.length != 0 && !visible)
|
||||
visible = true;
|
||||
waitingMessages.length = 0;
|
||||
|
||||
timer -= time;
|
||||
if(timer <= 0.0) {
|
||||
updateMode();
|
||||
timer = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
void addChat(const string& str) {
|
||||
messages.insertLast(str);
|
||||
if(messages.length > 80)
|
||||
messages.removeAt(0);
|
||||
string content;
|
||||
for(uint i = 0, cnt = messages.length; i < cnt; ++i)
|
||||
content += messages[i]+"\n";
|
||||
bool wasBottom = panel.vert.pos >= (panel.vert.end - panel.vert.page);
|
||||
log.text = content;
|
||||
panel.updateAbsolutePosition();
|
||||
if(wasBottom) {
|
||||
panel.vert.pos = max(0.0, panel.vert.end - panel.vert.page);
|
||||
panel.updateAbsolutePosition();
|
||||
}
|
||||
}
|
||||
|
||||
void queueMessage(const string& str) {
|
||||
Lock lck(mtx);
|
||||
waitingMessages.insertLast(str);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.caller is input) {
|
||||
if(evt.type == GUI_Confirmed) {
|
||||
string text = input.text;
|
||||
if(text.length != 0) {
|
||||
if(mode.selected == 0 || uint(mode.selected) >= modeMasks.length) {
|
||||
mpChat(text);
|
||||
}
|
||||
else {
|
||||
uint mask = modeMasks[mode.selected];
|
||||
string spec = mode.getItemElement(mode.selected).get();
|
||||
mpChat(text, mask, spec);
|
||||
}
|
||||
}
|
||||
input.text = "";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(evt.caller is closeButton) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
visible = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return GuiDraggable::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() override {
|
||||
GuiDraggable::updateAbsolutePosition();
|
||||
if(log !is null)
|
||||
log.size = vec2i(panel.size.width-20, log.size.height);
|
||||
}
|
||||
};
|
||||
|
||||
void mp_chat(bool pressed) {
|
||||
if(!pressed && (mpClient || mpServer)) {
|
||||
if(mpChatWin is null)
|
||||
@mpChatWin = MPChatWindow();
|
||||
mpChatWin.visible = true;
|
||||
mpChatWin.bringToFront();
|
||||
setGuiFocus(mpChatWin.input);
|
||||
}
|
||||
}
|
||||
|
||||
void chatMessage(string text) {
|
||||
if(mpChatWin !is null)
|
||||
mpChatWin.queueMessage(text);
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
//Adds functionality to the normal engine camera to make it
|
||||
//more intelligent and context-sensitive
|
||||
|
||||
import double getElevation(double x, double z) from "navigation.elevation";
|
||||
import double getAverageElevation() from "navigation.elevation";
|
||||
import bool getElevationIntersect(const line3dd& line, vec3d& point) from "navigation.elevation";
|
||||
import Object@ get_hoveredObject() from "obj_selection";
|
||||
import saving;
|
||||
|
||||
bool CAM_PANNED = false;
|
||||
bool CAM_ZOOMED = false;
|
||||
bool CAM_ROTATED = false;
|
||||
|
||||
double OBJLOCK_ZOOMDIST = 5.0;
|
||||
|
||||
class SmartCamera : Savable {
|
||||
//Main engine camera
|
||||
Camera camera;
|
||||
|
||||
//Configuration
|
||||
double camAnglesPerPixel;
|
||||
double movePerPixel;
|
||||
double tickZoom;
|
||||
|
||||
//Object locks
|
||||
Object@ lockedObject;
|
||||
vec3d lockOffset;
|
||||
|
||||
SmartCamera() {
|
||||
camAnglesPerPixel = 0.22 * twopi / 360.0;
|
||||
movePerPixel = 8.0;
|
||||
tickZoom = 1.2;
|
||||
camera.setPositionBound(vec3d(-200000), vec3d(200000));
|
||||
}
|
||||
|
||||
void reset() {
|
||||
//Set the camera to the normal angle
|
||||
camera.resetRotation();
|
||||
camera.resetZoom();
|
||||
camera.zoom(5.0);
|
||||
camera.pitch(0.7);
|
||||
camera.snap();
|
||||
}
|
||||
|
||||
vec3d get_lookAt() {
|
||||
return camera.lookAt;
|
||||
}
|
||||
|
||||
vec3d get_finalLookAt() {
|
||||
return camera.finalLookAt;
|
||||
}
|
||||
|
||||
double screenAngle(const vec3d& pos) {
|
||||
return camera.screenAngle(pos);
|
||||
}
|
||||
|
||||
double get_distance() {
|
||||
return camera.distance;
|
||||
}
|
||||
|
||||
//Rotate by a certain amount of screen pixels dragged
|
||||
void rotate(int dx, int dy) {
|
||||
CAM_ROTATED = true;
|
||||
if(settings::bInvertHorizRot)
|
||||
dx = -dx;
|
||||
if(settings::bInvertVertRot)
|
||||
dy = -dy;
|
||||
|
||||
if(settings::bFreeCamera) {
|
||||
camera.yaw(clamp(double(dx) * camAnglesPerPixel, -pi * 0.5, pi * 0.5));
|
||||
camera.pitch(clamp(double(dy) * camAnglesPerPixel, -pi * 0.5, pi * 0.5));
|
||||
}
|
||||
else {
|
||||
camera.abs_yaw(clamp(double(dx) * camAnglesPerPixel, -pi * 0.5, pi * 0.5));
|
||||
camera.pitch(clamp(double(dy) * camAnglesPerPixel, -pi * 0.5, pi * 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
//Roll based on dragged script pixels
|
||||
void roll(int delta) {
|
||||
CAM_ROTATED = true;
|
||||
camera.roll(double(delta) * camAnglesPerPixel);
|
||||
}
|
||||
|
||||
//Zoom with world plane
|
||||
void zoom(int delta) {
|
||||
//Get zoom speed
|
||||
double factor;
|
||||
if(settings::bInvertZoom)
|
||||
factor = pow(tickZoom, delta * settings::dZoomSpeed);
|
||||
else
|
||||
factor = pow(tickZoom, -delta * settings::dZoomSpeed);
|
||||
CAM_ZOOMED = true;
|
||||
|
||||
if(lockedObject !is null) {
|
||||
camera.zoom(factor);
|
||||
return;
|
||||
}
|
||||
|
||||
if(factor < 1.0 ? settings::bZoomToCursor : settings::bZoomFromCursor) {
|
||||
if(hoveredObject !is null) {
|
||||
double minDist = hoveredObject.radius * getMinZoomDist(hoveredObject);
|
||||
vec3d point = hoveredObject.position;
|
||||
camera.zoomTo(factor, point, minDist);
|
||||
}
|
||||
else {
|
||||
//Interpolate plane position
|
||||
line3dd ray = screenToRay(mousePos);
|
||||
if(factor > 1.0)
|
||||
ray.start -= ray.direction * 1.0;
|
||||
|
||||
vec3d point;
|
||||
if(!getElevationIntersect(ray, point))
|
||||
return;
|
||||
|
||||
double minDist = 0.0;
|
||||
camera.zoomTo(factor, point, minDist);
|
||||
}
|
||||
}
|
||||
else {
|
||||
camera.zoom(factor);
|
||||
}
|
||||
}
|
||||
|
||||
void zoomTo(Object@ obj) {
|
||||
clearObjectLock();
|
||||
zoomTo(obj.position);
|
||||
}
|
||||
|
||||
void zoomTo(const vec3d& pos) {
|
||||
clearObjectLock();
|
||||
vec3d finalPos = camera.finalLookAt;
|
||||
vec3d movement;
|
||||
movement.x = pos.x - finalPos.x;
|
||||
movement.z = pos.z - finalPos.z;
|
||||
movement.y = getElevation(pos.x, pos.z) - finalPos.y;
|
||||
|
||||
camera.move_abs(movement);
|
||||
}
|
||||
|
||||
double getMinZoomDist(Object@ obj) {
|
||||
switch(obj.type) {
|
||||
case OT_Star:
|
||||
return 1.4;
|
||||
case OT_Planet:
|
||||
return 1.6;
|
||||
}
|
||||
return 1.15;
|
||||
}
|
||||
|
||||
//Pan on top of the world plane
|
||||
void pan(int dx, int dy) {
|
||||
if(!settings::bInvertPanX)
|
||||
dx = -dx;
|
||||
if(settings::bInvertPanY)
|
||||
dy = -dy;
|
||||
|
||||
//Normal world plane movement
|
||||
vec2d movement;
|
||||
movement.x = movePerPixel * double(dx);
|
||||
movement.y = movePerPixel * double(dy);
|
||||
|
||||
pan(movement);
|
||||
}
|
||||
|
||||
void pan(vec2d movement) {
|
||||
clearObjectLock();
|
||||
|
||||
//Speed based on zoom and modifiers
|
||||
double speed = camera.distance / 2500.0;
|
||||
if(settings::bModSpeedPan) {
|
||||
if(shiftKey)
|
||||
speed *= 3.0;
|
||||
else if(altKey)
|
||||
speed *= 0.333;
|
||||
}
|
||||
|
||||
movement *= settings::dPanSpeed * speed;
|
||||
|
||||
//Normal world plane movement
|
||||
vec3d prevPos = camera.finalLookAt;
|
||||
camera.move_world_abs(vec3d(movement.x, 0, movement.y));
|
||||
|
||||
//Change in elevation
|
||||
vec3d nextPos = camera.finalLookAt;
|
||||
camera.move_abs(vec3d(0, getElevation(nextPos.x, nextPos.z) - prevPos.y, 0));
|
||||
CAM_PANNED = true;
|
||||
}
|
||||
|
||||
bool panTo(const vec3d& pos, double speed, double threshold = 10.0) {
|
||||
clearObjectLock();
|
||||
|
||||
//Modify speed
|
||||
speed *= max(camera.distance / 2500.0, 0.2);
|
||||
if(settings::bModSpeedPan) {
|
||||
if(shiftKey)
|
||||
speed *= 3.0;
|
||||
else if(altKey)
|
||||
speed *= 0.333;
|
||||
}
|
||||
speed *= settings::dPanSpeed;
|
||||
|
||||
//Pan on a flat plane
|
||||
vec3d cur = lookAt;
|
||||
vec3d final = finalLookAt;
|
||||
|
||||
vec3d flatPos = pos;
|
||||
flatPos.y = 0;
|
||||
cur.y = 0;
|
||||
final.y = 0;
|
||||
|
||||
vec3d panDir = flatPos - final;
|
||||
double len = panDir.length;
|
||||
if(len <= threshold) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if(len > speed)
|
||||
panDir.length = speed;
|
||||
|
||||
vec3d prevPos = camera.finalLookAt;
|
||||
camera.move_abs(panDir);
|
||||
vec3d nextPos = camera.finalLookAt;
|
||||
camera.move_abs(vec3d(0, getElevation(nextPos.x, nextPos.z) - prevPos.y, 0));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
line3dd screenToRay(const vec2i& pos) {
|
||||
vec2i size = screenSize;
|
||||
return camera.screenToRay(double(pos.x) / double(size.x),
|
||||
double(pos.y) / double(size.y));
|
||||
}
|
||||
|
||||
vec3d screenToPoint(const vec2i& pos) {
|
||||
line3dd ray = screenToRay(mousePos);
|
||||
vec3d point;
|
||||
if(!getElevationIntersect(ray, point))
|
||||
ray.intersectY(point, getAverageElevation(), false);
|
||||
return point;
|
||||
}
|
||||
|
||||
void clearObjectLock() {
|
||||
@lockedObject = null;
|
||||
}
|
||||
|
||||
void zoomLockObject(Object& obj) {
|
||||
zoomTo(obj.position);
|
||||
camera.move_abs(obj.node_position - camera.finalLookAt);
|
||||
if(!shiftKey)
|
||||
camera.zoom((obj.radius * OBJLOCK_ZOOMDIST) / camera.distance);
|
||||
setLocked(obj);
|
||||
}
|
||||
|
||||
void setLocked(Object& obj) {
|
||||
@lockedObject = obj;
|
||||
lockOffset = camera.finalLookAt - obj.node_position;
|
||||
}
|
||||
|
||||
void animateLocked(double time) {
|
||||
if(lockedObject is null)
|
||||
return;
|
||||
if(!lockedObject.visible) {
|
||||
@lockedObject = null;
|
||||
return;
|
||||
}
|
||||
|
||||
vec3d finalPos = camera.finalLookAt;
|
||||
double tDiff = frameGameTime - lockedObject.lastTick;
|
||||
vec3d objPos = lockedObject.position + (lockedObject.velocity + lockedObject.acceleration * (tDiff * 0.5)) * tDiff;
|
||||
if(finalPos.distanceToSQ(objPos) > sqr(lockedObject.radius * 2.0 + lockedObject.velocity.length)) {
|
||||
@lockedObject = null;
|
||||
return;
|
||||
}
|
||||
|
||||
objPos += lockOffset;
|
||||
vec3d movement = objPos - finalPos;
|
||||
bool snap = camera.lookAt.distanceTo(finalPos) < 15.0;
|
||||
camera.move_abs(movement);
|
||||
if(snap)
|
||||
camera.snapTranslation();
|
||||
}
|
||||
|
||||
void animate(double time) {
|
||||
camera.animate(time);
|
||||
if(lockedObject !is null)
|
||||
animateLocked(time);
|
||||
}
|
||||
|
||||
void save(SaveFile& file) {
|
||||
file << camera.finalLookAt;
|
||||
file << camera.radius;
|
||||
}
|
||||
|
||||
void load(SaveFile& file) {
|
||||
vec3d position;
|
||||
file >> position;
|
||||
if(file >= SV_0149) {
|
||||
double radius = 0;
|
||||
file >> radius;
|
||||
camera.radius = radius;
|
||||
}
|
||||
camera.move_abs(position - camera.finalLookAt);
|
||||
camera.snap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#priority init 50
|
||||
import systems;
|
||||
|
||||
ElevationMap emap;
|
||||
double epower = 4.0;
|
||||
double egrid = 1000.0;
|
||||
double vgrid = 1000.0;
|
||||
bool drawGrid = false;
|
||||
|
||||
void init() {
|
||||
recalculateElevation();
|
||||
|
||||
addConsoleCommand("grid_smoothing", GridPowerCommand());
|
||||
addConsoleCommand("grid_spacing", GridSpacingCommand());
|
||||
addConsoleCommand("grid_visual", GridVisualCommand());
|
||||
addConsoleCommand("show_grid", ShowGridCommand());
|
||||
}
|
||||
|
||||
void recalculateElevation() {
|
||||
//Elevation map
|
||||
emap.clear();
|
||||
vec2d minPoint, maxPoint;
|
||||
for(uint i = 0, cnt = systemCount; i < cnt; ++i) {
|
||||
auto@ sys = getSystem(i);
|
||||
vec3d pos = sys.position;
|
||||
emap.addPoint(pos, sys.radius);
|
||||
|
||||
minPoint.x = min(minPoint.x, pos.x);
|
||||
minPoint.y = min(minPoint.y, pos.y);
|
||||
maxPoint.x = max(maxPoint.x, pos.x);
|
||||
maxPoint.y = max(maxPoint.y, pos.y);
|
||||
}
|
||||
|
||||
emap.generate(vec2d(max(egrid, (maxPoint.x-minPoint.x)/100.0), max(egrid, (maxPoint.y-minPoint.y)/100.0)), epower);
|
||||
}
|
||||
|
||||
double getElevation(double x, double z) {
|
||||
return emap.get(x, z);
|
||||
}
|
||||
|
||||
double getAverageElevation() {
|
||||
return emap.gridStart.y;
|
||||
}
|
||||
|
||||
bool getElevationIntersect(const line3dd& line, vec3d&out point) {
|
||||
return emap.getClosestPoint(line, point);
|
||||
}
|
||||
|
||||
class GridPowerCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
epower = toDouble(args);
|
||||
emap.generate(vec2d(egrid, egrid), epower);
|
||||
}
|
||||
};
|
||||
|
||||
class GridSpacingCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
egrid = toDouble(args);
|
||||
emap.generate(vec2d(egrid, egrid), epower);
|
||||
}
|
||||
};
|
||||
|
||||
class GridVisualCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
vgrid = toDouble(args);
|
||||
}
|
||||
};
|
||||
|
||||
class ShowGridCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
drawGrid = args.length == 0 || toBool(args);
|
||||
}
|
||||
};
|
||||
|
||||
void render(double time) {
|
||||
if(!drawGrid)
|
||||
return;
|
||||
|
||||
//Draw the elevation grid
|
||||
for(int x = -10, xcnt = emap.gridSize.x / vgrid + 10; x < xcnt; ++x) {
|
||||
for(int y = -10, ycnt = emap.gridSize.y / vgrid + 10; y < ycnt; ++y) {
|
||||
vec3d tlpos = emap.gridStart + vec3d(vgrid * x, 0, vgrid * y);
|
||||
vec3d brpos = tlpos + vec3d(vgrid, 0.0, vgrid);
|
||||
|
||||
vec3d tl = vec3d(tlpos.x, emap.get(tlpos.x, tlpos.z), tlpos.z);
|
||||
vec3d tr = vec3d(brpos.x, emap.get(brpos.x, tlpos.z), tlpos.z);
|
||||
vec3d bl = vec3d(tlpos.x, emap.get(tlpos.x, brpos.z), brpos.z);
|
||||
vec3d br = vec3d(brpos.x, emap.get(brpos.x, brpos.z), brpos.z);
|
||||
|
||||
drawPolygonStart(2, material::TestGrid);
|
||||
drawPolygonPoint(tl, vec2f(0.f, 0.f));
|
||||
drawPolygonPoint(tr, vec2f(1.f, 0.f));
|
||||
drawPolygonPoint(br, vec2f(1.f, 1.f));
|
||||
|
||||
drawPolygonPoint(tl, vec2f(0.f, 0.f));
|
||||
drawPolygonPoint(bl, vec2f(0.f, 1.f));
|
||||
drawPolygonPoint(br, vec2f(1.f, 1.f));
|
||||
drawPolygonEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
from obj_selection import selectedObjects, selectedObject;
|
||||
import ftl;
|
||||
|
||||
import void targetHyperdrive() from "targeting.Hyperdrive";
|
||||
import void targetJumpdrive() from "targeting.Jumpdrive";
|
||||
import void targetFling() from "targeting.Fling";
|
||||
import void targetSlipstream() from "targeting.Slipstream";
|
||||
|
||||
bool canMove() {
|
||||
Object@[]@ selected = selectedObjects;
|
||||
if(selected.length == 0)
|
||||
return false;
|
||||
for(uint i = 0, cnt = selected.length; i < cnt; ++i) {
|
||||
if(!selected[i].hasMover)
|
||||
return false;
|
||||
if(!selected[i].owner.controlled)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canHyperdrive() {
|
||||
Object@[]@ selected = selectedObjects;
|
||||
if(selected.length == 0)
|
||||
return false;
|
||||
for(uint i = 0, cnt = selected.length; i < cnt; ++i) {
|
||||
if(!canHyperdrive(selected[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canJumpdrive() {
|
||||
Object@[]@ selected = selectedObjects;
|
||||
if(selected.length == 0)
|
||||
return false;
|
||||
for(uint i = 0, cnt = selected.length; i < cnt; ++i) {
|
||||
if(!canJumpdrive(selected[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canFling() {
|
||||
Object@[]@ selected = selectedObjects;
|
||||
if(selected.length == 0 || !playerEmpire.hasFlingBeacons)
|
||||
return false;
|
||||
for(uint i = 0, cnt = selected.length; i < cnt; ++i) {
|
||||
Object@ obj = selected[i];
|
||||
if(obj.owner is null || !obj.owner.valid)
|
||||
return false;
|
||||
if(!canFling(obj))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canSlipstream() {
|
||||
Object@[]@ selected = selectedObjects;
|
||||
for(uint i = 0, cnt = selected.length; i < cnt; ++i) {
|
||||
Object@ obj = selected[i];
|
||||
if(canSlipstream(obj))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool targetFTL() {
|
||||
if(!canMove())
|
||||
return false;
|
||||
|
||||
//Check for fling
|
||||
if(canFling()) {
|
||||
targetFling();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check for hyperdrive
|
||||
if(canHyperdrive()) {
|
||||
targetHyperdrive();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check for jumpdrive
|
||||
if(canJumpdrive()) {
|
||||
targetJumpdrive();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check for slipstream
|
||||
if(canSlipstream()) {
|
||||
targetSlipstream();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FTLBind(bool pressed) {
|
||||
if(!pressed) {
|
||||
if(!targetFTL())
|
||||
sound::error.play(priority=true);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
keybinds::Global.addBind(KB_FTL, "FTLBind");
|
||||
}
|
||||
@@ -0,0 +1,857 @@
|
||||
#priority init -1
|
||||
import tabs.Tab;
|
||||
import elements.GuiTextbox;
|
||||
import systems;
|
||||
/*import research;*/
|
||||
import resources;
|
||||
from input import ActiveCamera;
|
||||
|
||||
import uint get_tabCount() from "tabs.tabbar";
|
||||
import Tab@ get_Tabs(uint i) from "tabs.tabbar";
|
||||
import Tab@ get_ActiveTab() from "tabs.tabbar";
|
||||
import void switchToTab(Tab@) from "tabs.tabbar";
|
||||
import Tab@ newTab(Tab@) from "tabs.tabbar";
|
||||
import void browseTab(Tab@,Tab@,bool) from "tabs.tabbar";
|
||||
import void browseTab(Tab@,bool) from "tabs.tabbar";
|
||||
import Tab@ findTab(int cat) from "tabs.tabbar";
|
||||
import Tab@ createResearchTab() from "tabs.ResearchTab";
|
||||
import Tab@ createDesignOverviewTab() from "tabs.DesignOverviewTab";
|
||||
import Tab@ createDesignEditorTab(const Design@) from "tabs.DesignEditorTab";
|
||||
import Tab@ createGalaxyTab() from "tabs.GalaxyTab";
|
||||
import Tab@ createGalaxyTab(Object@) from "tabs.GalaxyTab";
|
||||
import Tab@ createGalaxyTab(vec3d) from "tabs.GalaxyTab";
|
||||
/*import Tab@ createResearchTab(ResearchNode@ node) from "tabs.ResearchTab";*/
|
||||
/*import void researchTabView(Tab@ tab, ResearchNode@ node) from "tabs.ResearchTab";*/
|
||||
import void zoomTabTo(vec3d pos) from "tabs.GalaxyTab";
|
||||
import void zoomTo(Object@ obj) from "tabs.GalaxyTab";
|
||||
|
||||
const uint ITEM_COUNT = 5;
|
||||
|
||||
class GoItem {
|
||||
Sprite get_icon() {
|
||||
return Sprite();
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_NULL;
|
||||
}
|
||||
|
||||
int match(const string&) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return "(null)";
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void go() {
|
||||
}
|
||||
|
||||
bool go(TabCategory cat) {
|
||||
Tab@ found = findTab(cat);
|
||||
if(shiftKey || found is null) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
switchToTab(found);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void go(Tab@ tab, TabCategory cat) {
|
||||
if(shiftKey) {
|
||||
newTab(tab);
|
||||
switchToTab(tab);
|
||||
}
|
||||
else {
|
||||
Tab@ found = findTab(cat);
|
||||
if(ctrlKey || found is null) {
|
||||
browseTab(tab, false); //TODO: History
|
||||
}
|
||||
else {
|
||||
browseTab(found, tab, false); //TODO: History
|
||||
switchToTab(tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void go(Tab@ tab) {
|
||||
if(shiftKey) {
|
||||
newTab(tab);
|
||||
switchToTab(tab);
|
||||
}
|
||||
else {
|
||||
browseTab(tab, false); //TODO: History
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
string str_galaxy = locale::GALAXY_CAMERA;
|
||||
class GoGalaxy : GoItem {
|
||||
int match(const string& str) {
|
||||
if(str_galaxy.startswith_nocase(str))
|
||||
return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_GalaxyIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return str_galaxy;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createGalaxyTab());
|
||||
}
|
||||
};
|
||||
|
||||
string str_research = locale::RESEARCH_OVERVIEW;
|
||||
class GoResearch : GoItem {
|
||||
int match(const string& str) {
|
||||
if(str_research.startswith_nocase(str))
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_ResearchIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return str_research;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createResearchTab());
|
||||
}
|
||||
};
|
||||
|
||||
string str_designs = locale::DESIGN_OVERVIEW;
|
||||
class GoDesigns : GoItem {
|
||||
int match(const string& str) {
|
||||
if(str_designs.startswith_nocase(str))
|
||||
return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_DesignsIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return str_designs;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createDesignOverviewTab());
|
||||
}
|
||||
};
|
||||
|
||||
class GoConsole : GoItem {
|
||||
int match(const string& str) {
|
||||
if(locale::CONSOLE.startswith_nocase(str))
|
||||
return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return locale::CONSOLE;
|
||||
}
|
||||
|
||||
void go() {
|
||||
toggleConsole();
|
||||
}
|
||||
};
|
||||
|
||||
class GoSystem : GoItem {
|
||||
SystemDesc@ sys;
|
||||
|
||||
GoSystem(SystemDesc@ _sys) {
|
||||
@sys = _sys;
|
||||
}
|
||||
|
||||
int match(const string& str) {
|
||||
if(playerEmpire.valid && sys.object.ExploredMask & playerEmpire.mask == 0)
|
||||
return 0;
|
||||
if(sys.object.name.contains_nocase(str))
|
||||
return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_GalaxyIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return sys.object.name;
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return locale::SYSTEM;
|
||||
}
|
||||
|
||||
void go() {
|
||||
if(go(TC_Galaxy))
|
||||
zoomTabTo(sys.position);
|
||||
else
|
||||
go(createGalaxyTab(sys.position));
|
||||
}
|
||||
}
|
||||
|
||||
string str_tab = locale::TAB;
|
||||
class GoTab : GoItem {
|
||||
Tab@ tab;
|
||||
|
||||
GoTab(Tab@ _tab) {
|
||||
@tab = _tab;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return tab.icon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return tab.title;
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return str_tab;
|
||||
}
|
||||
|
||||
void go() {
|
||||
switchToTab(tab);
|
||||
}
|
||||
}
|
||||
|
||||
string str_design = locale::DESIGN;
|
||||
class GoDesign : GoItem {
|
||||
const Design@ dsg;
|
||||
|
||||
GoDesign(const Design@ _dsg) {
|
||||
@dsg = _dsg;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_DesignsIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return dsg.name;
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return str_design;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createDesignEditorTab(dsg), TC_Designs);
|
||||
}
|
||||
}
|
||||
|
||||
string str_planet = locale::PLANET;
|
||||
class GoPlanet : GoItem {
|
||||
Object@ obj;
|
||||
|
||||
GoPlanet(Object@ _obj) {
|
||||
@obj = _obj;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_GalaxyIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return obj.name;
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return str_planet;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createGalaxyTab(obj), TC_Galaxy);
|
||||
}
|
||||
}
|
||||
|
||||
string str_ship = locale::SHIP;
|
||||
class GoShip : GoItem {
|
||||
Object@ obj;
|
||||
|
||||
GoShip(Object@ _obj) {
|
||||
@obj = _obj;
|
||||
}
|
||||
|
||||
SkinStyle get_skinIcon() {
|
||||
return SS_GalaxyIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return obj.name;
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return str_ship;
|
||||
}
|
||||
|
||||
void go() {
|
||||
go(createGalaxyTab(obj), TC_Galaxy);
|
||||
}
|
||||
}
|
||||
|
||||
/*string str_technology = locale::TECHNOLOGY;*/
|
||||
/*class GoTechnology : GoItem {*/
|
||||
/* ResearchNode@ node;*/
|
||||
|
||||
/* GoTechnology(ResearchNode@ _node) {*/
|
||||
/* @node = _node;*/
|
||||
/* }*/
|
||||
|
||||
/* SkinStyle get_skinIcon() {*/
|
||||
/* return SS_ResearchIcon;*/
|
||||
/* }*/
|
||||
|
||||
/* string get_text() {*/
|
||||
/* return node.tech.name;*/
|
||||
/* }*/
|
||||
|
||||
/* string get_type() {*/
|
||||
/* return str_technology;*/
|
||||
/* }*/
|
||||
|
||||
/* void go() {*/
|
||||
/* go(createResearchTab(node), TC_Research);*/
|
||||
/* }*/
|
||||
/*}*/
|
||||
|
||||
class GoResource : GoItem {
|
||||
const ResourceType@ resType;
|
||||
|
||||
GoResource(const ResourceType@ type) {
|
||||
@this.resType = type;
|
||||
}
|
||||
|
||||
int match(const string& str) {
|
||||
if(resType.name.contains_nocase(str) && str.length >= 3) {
|
||||
if(str.equals_nocase(resType.name))
|
||||
return 10;
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return resType.smallIcon;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return format(locale::GO_RESOURCE, resType.name);
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return format(locale::GO_RESOURCE_TYPE, resType.name);
|
||||
}
|
||||
|
||||
void go() {
|
||||
uint sysCnt = systemCount;
|
||||
Planet@ best;
|
||||
double closestDist = INFINITY;
|
||||
bool foundOwned = false;
|
||||
vec3d camPos = ActiveCamera.lookAt;
|
||||
|
||||
for(uint i = 0; i < sysCnt; ++i) {
|
||||
auto@ sys = getSystem(i);
|
||||
uint plCnt = sys.object.planetCount;
|
||||
for(uint n = 0; n < plCnt; ++n) {
|
||||
Planet@ pl = sys.object.planets[n];
|
||||
if(pl.known) {
|
||||
auto@ type = getResource(pl.nativeResourceType[0]);
|
||||
if(type !is null && type is resType) {
|
||||
Empire@ owner = pl.visibleOwner;
|
||||
if(owner is playerEmpire) {
|
||||
Object@ dest = pl.nativeResourceDestination[0];
|
||||
if(dest !is null)
|
||||
continue;
|
||||
if(type.isMaterial(pl.level))
|
||||
continue;
|
||||
double dist = camPos.distanceToSQ(pl.position);
|
||||
if(dist < closestDist || !foundOwned) {
|
||||
@best = pl;
|
||||
closestDist = dist;
|
||||
foundOwned = true;
|
||||
}
|
||||
}
|
||||
else if(owner is null || !owner.valid) {
|
||||
if(!foundOwned) {
|
||||
double dist = camPos.distanceToSQ(pl.position);
|
||||
if(dist < closestDist) {
|
||||
@best = pl;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(best !is null)
|
||||
zoomTo(best);
|
||||
}
|
||||
};
|
||||
|
||||
class GoResourceClass : GoItem {
|
||||
const ResourceClass@ resType;
|
||||
|
||||
GoResourceClass(const ResourceClass@ type) {
|
||||
@this.resType = type;
|
||||
}
|
||||
|
||||
int match(const string& str) {
|
||||
if(resType.name.contains_nocase(str) && str.length >= 3) {
|
||||
if(str.equals_nocase(resType.name))
|
||||
return 9;
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
string get_text() {
|
||||
return format(locale::GO_RESOURCE, resType.name);
|
||||
}
|
||||
|
||||
string get_type() {
|
||||
return format(locale::GO_RESOURCE_TYPE, resType.name);
|
||||
}
|
||||
|
||||
void go() {
|
||||
uint sysCnt = systemCount;
|
||||
Planet@ best;
|
||||
double closestDist = INFINITY;
|
||||
bool foundOwned = false;
|
||||
vec3d camPos = ActiveCamera.lookAt;
|
||||
|
||||
for(uint i = 0; i < sysCnt; ++i) {
|
||||
auto@ sys = getSystem(i);
|
||||
uint plCnt = sys.object.planetCount;
|
||||
for(uint n = 0; n < plCnt; ++n) {
|
||||
Planet@ pl = sys.object.planets[n];
|
||||
if(pl.known) {
|
||||
auto@ type = getResource(pl.nativeResourceType[0]);
|
||||
if(type !is null && type.cls is resType) {
|
||||
Empire@ owner = pl.visibleOwner;
|
||||
if(owner is playerEmpire) {
|
||||
Object@ dest = pl.nativeResourceDestination[0];
|
||||
if(dest !is null)
|
||||
continue;
|
||||
if(type.isMaterial(pl.level))
|
||||
continue;
|
||||
double dist = camPos.distanceToSQ(pl.position);
|
||||
if(dist < closestDist || !foundOwned) {
|
||||
@best = pl;
|
||||
closestDist = dist;
|
||||
foundOwned = true;
|
||||
}
|
||||
}
|
||||
else if(owner is null || !owner.valid) {
|
||||
if(!foundOwned) {
|
||||
double dist = camPos.distanceToSQ(pl.position);
|
||||
if(dist < closestDist) {
|
||||
@best = pl;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(best !is null)
|
||||
zoomTo(best);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GoItem@[] staticItems;
|
||||
|
||||
bool WouldInsert(uint amount, int match, int[]& priorities) {
|
||||
if(match < 0)
|
||||
return false;
|
||||
if(priorities[amount - 1] == -1)
|
||||
return true;
|
||||
if(priorities[amount - 1] >= match)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GoInsert(GoItem@ item, uint amount, int match, GoItem@[]& list, int[]& priorities) {
|
||||
if(list[amount - 1] !is null && priorities[amount - 1] >= match)
|
||||
return;
|
||||
|
||||
for(int j = amount - 1; j >= 0; --j) {
|
||||
//Push it up
|
||||
if(j < int(amount) - 1) {
|
||||
priorities[j + 1] = priorities[j];
|
||||
@list[j + 1] = list[j];
|
||||
}
|
||||
|
||||
//Check if we should insert here
|
||||
if(j == 0 || match < priorities[j - 1]) {
|
||||
//Insert here
|
||||
priorities[j] = match;
|
||||
@list[j] = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GoSearch(const string& text, GoItem@[]& list, uint amount = 5) {
|
||||
//Cache of priorities
|
||||
int[] priorities;
|
||||
priorities.length = amount;
|
||||
|
||||
//Clear the list
|
||||
list.length = amount;
|
||||
for(uint i = 0; i < amount; ++i) {
|
||||
@list[i] = null;
|
||||
priorities[i] = -1;
|
||||
}
|
||||
|
||||
//Empty text matches nothing
|
||||
if(text.length == 0)
|
||||
return;
|
||||
|
||||
//Search static items
|
||||
uint cnt = staticItems.length;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
int match = staticItems[i].match(text);
|
||||
if(match > 0)
|
||||
GoInsert(staticItems[i], amount, match, list, priorities);
|
||||
}
|
||||
|
||||
//Search tabs
|
||||
cnt = tabCount;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
Tab@ tab = Tabs[i];
|
||||
if(tab.title.contains_nocase(text)) {
|
||||
if(WouldInsert(amount, 50, priorities))
|
||||
GoInsert(GoTab(tab), amount, 50, list, priorities);
|
||||
}
|
||||
}
|
||||
|
||||
//Search designs
|
||||
{
|
||||
ReadLock lock(playerEmpire.designMutex);
|
||||
cnt = playerEmpire.designCount;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
const Design@ dsg = playerEmpire.designs[i];
|
||||
if(dsg.name.contains_nocase(text)) {
|
||||
int p = text.length > 3 ? 10 : 2;
|
||||
if(dsg.name.equals_nocase(text))
|
||||
p += 100;
|
||||
if(WouldInsert(amount, p, priorities))
|
||||
GoInsert(GoDesign(dsg), amount, p, list, priorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Search empire objects
|
||||
//cnt = playerEmpire.objectCount;
|
||||
//for(uint i = 0; i < cnt; ++i) {
|
||||
//Object@ obj = playerEmpire.objects[i];
|
||||
//Ship@ ship = cast<Ship@>(obj);
|
||||
//Planet@ pl = cast<Planet@>(obj);
|
||||
|
||||
//int prior = -1;
|
||||
//if(ship !is null || pl !is null) {
|
||||
//if(obj.name.contains_nocase(text)) {
|
||||
//if(pl !is null)
|
||||
//prior = text.length > 3 ? 16 : 4;
|
||||
//else
|
||||
//prior = text.length > 3 ? 6 : 4;
|
||||
//}
|
||||
//if(obj.name.equals_nocase(text))
|
||||
//prior += 100;
|
||||
//}
|
||||
|
||||
//if(WouldInsert(amount, prior, priorities)) {
|
||||
//GoItem@ it;
|
||||
//if(pl !is null)
|
||||
//@it = GoPlanet(obj);
|
||||
//else if(ship !is null)
|
||||
//@it = GoShip(obj);
|
||||
|
||||
//if(it !is null)
|
||||
//GoInsert(it, amount, prior, list, priorities);
|
||||
//}
|
||||
//}
|
||||
|
||||
//Search research
|
||||
/*cnt = getResearchNodeCount();*/
|
||||
/*for(uint i = 0; i < cnt; ++i) {*/
|
||||
/* ResearchNode@ node = getResearchNode(i);*/
|
||||
/* if(node.tech.name.contains_nocase(text)) {*/
|
||||
/* int p = text.length > 3 ? 7 : 1;*/
|
||||
/* if(node.tech.name.equals_nocase(text))*/
|
||||
/* p += 100;*/
|
||||
/* if(!node.unlocked)*/
|
||||
/* p += 1;*/
|
||||
|
||||
/* if(WouldInsert(amount, p, priorities))*/
|
||||
/* GoInsert(GoTechnology(node), amount, p, list, priorities);*/
|
||||
/* }*/
|
||||
/*}*/
|
||||
}
|
||||
|
||||
class GoDialog : BaseGuiElement {
|
||||
GuiTextbox@ box;
|
||||
GoItem@[] items;
|
||||
uint selected;
|
||||
int hovered;
|
||||
|
||||
GoDialog() {
|
||||
super(null, recti());
|
||||
alignment.left.set(AS_Left, 0.1f, 0);
|
||||
alignment.right.set(AS_Right, 0.1f, 0);
|
||||
alignment.top.set(AS_Top, 0.5f, -32 - int(ITEM_COUNT * 15));
|
||||
alignment.bottom.set(AS_Top, 0.5f, int(ITEM_COUNT * 15) + 40);
|
||||
|
||||
@box = GuiTextbox(this, recti(0, 0, 100, 48), "");
|
||||
box.font = FT_Big;
|
||||
@box.alignment = Alignment(Left+8, Top+8, Right-8, Top+56);
|
||||
|
||||
selected = 0;
|
||||
hovered = -1;
|
||||
items.length = ITEM_COUNT;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
box.text = "";
|
||||
for(uint i = 0; i < ITEM_COUNT; ++i)
|
||||
@items[i] = null;
|
||||
selected = 0;
|
||||
hovered = -1;
|
||||
}
|
||||
|
||||
void hide() {
|
||||
visible = false;
|
||||
clear();
|
||||
}
|
||||
|
||||
void next() {
|
||||
if(selected < ITEM_COUNT - 1) {
|
||||
if(items[selected + 1] !is null)
|
||||
selected += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void prev() {
|
||||
if(selected > 0)
|
||||
selected -= 1;
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
switch(event.type) {
|
||||
case KET_Key_Down:
|
||||
if(event.key == KEY_UP) {
|
||||
prev();
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_DOWN) {
|
||||
next();
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_TAB) {
|
||||
if(shiftKey)
|
||||
prev();
|
||||
else
|
||||
next();
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_ESC) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case KET_Key_Up:
|
||||
if(event.key == KEY_ESC) {
|
||||
hide();
|
||||
setGuiFocus(ActiveTab);
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_UP) {
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_DOWN) {
|
||||
return true;
|
||||
}
|
||||
else if(event.key == KEY_TAB) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onKeyEvent(event, source);
|
||||
}
|
||||
|
||||
void updateHovered() {
|
||||
vec2i rel = mousePos - AbsolutePosition.topLeft;
|
||||
if(rel.x < 4 || rel.x > size.width - 4) {
|
||||
hovered = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
hovered = (rel.y - 64) / 30;
|
||||
if(hovered < 0 || hovered >= ITEM_COUNT || items[hovered] is null) {
|
||||
hovered = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
switch(event.type) {
|
||||
case GUI_Focus_Lost:
|
||||
if(event.other is null || !event.other.isChildOf(this)) {
|
||||
hide();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case GUI_Changed:
|
||||
search();
|
||||
break;
|
||||
case GUI_Confirmed:
|
||||
if(box.text != "" && items[selected] !is null)
|
||||
items[selected].go();
|
||||
hide();
|
||||
if(getGuiFocus() !is null && getGuiFocus().isChildOf(this))
|
||||
setGuiFocus(ActiveTab);
|
||||
return true;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Up:
|
||||
if(hovered >= 0)
|
||||
items[hovered].go();
|
||||
hide();
|
||||
return true;
|
||||
case MET_Moved:
|
||||
updateHovered();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void search() {
|
||||
GoSearch(box.text, items);
|
||||
selected = 0;
|
||||
hovered = -1;
|
||||
}
|
||||
|
||||
void drawItem(uint i, const recti& absPos) {
|
||||
GoItem@ item = items[i];
|
||||
|
||||
uint flags = SF_Normal;
|
||||
if(i == selected)
|
||||
flags |= SF_Active;
|
||||
if(int(i) == hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
skin.draw(SS_GoItem, flags, absPos);
|
||||
|
||||
recti iconPos = recti_area(
|
||||
absPos.topLeft + vec2i(4, 6),
|
||||
vec2i(20, 18));
|
||||
|
||||
Sprite sprt = item.icon;
|
||||
|
||||
if(sprt.valid)
|
||||
sprt.draw(iconPos);
|
||||
else if(item.skinIcon != SS_NULL)
|
||||
skin.draw(item.skinIcon, SF_Normal, iconPos);
|
||||
|
||||
skin.draw(FT_Medium, absPos.topLeft + vec2i(28, 4), item.text);
|
||||
skin.draw(FT_Medium, absPos.botRight - vec2i(204, 26), item.type);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
//Draw the background
|
||||
skin.draw(SS_GoDialog, SF_Normal, AbsolutePosition);
|
||||
|
||||
//Draw the items
|
||||
for(uint i = 0; i < ITEM_COUNT; ++i) {
|
||||
if(items[i] is null)
|
||||
break;
|
||||
drawItem(i, recti_area(
|
||||
AbsolutePosition.topLeft + vec2i(8, 64 + i * 30),
|
||||
vec2i(size.width - 16, 30)));
|
||||
}
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
void gogogo(bool pressed) {
|
||||
if(pressed) {
|
||||
dialog.visible = true;
|
||||
dialog.bringToFront();
|
||||
setGuiFocus(dialog.box);
|
||||
}
|
||||
}
|
||||
|
||||
void toggleGoDialog() {
|
||||
if(!dialog.visible) {
|
||||
dialog.visible = true;
|
||||
dialog.bringToFront();
|
||||
setGuiFocus(dialog.box);
|
||||
}
|
||||
else {
|
||||
dialog.hide();
|
||||
}
|
||||
}
|
||||
|
||||
GoDialog@ dialog;
|
||||
IGuiElement@ getGoDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
void init() {
|
||||
//Initialize dialog
|
||||
@dialog = GoDialog();
|
||||
dialog.visible = false;
|
||||
|
||||
//Initialize static items
|
||||
staticItems.insertLast(GoResearch());
|
||||
staticItems.insertLast(GoDesigns());
|
||||
staticItems.insertLast(GoGalaxy());
|
||||
staticItems.insertLast(GoConsole());
|
||||
|
||||
//Add systems to static items
|
||||
for(uint i = 0, cnt = systemCount; i < cnt; ++i)
|
||||
staticItems.insertLast(GoSystem(getSystem(i)));
|
||||
|
||||
//Add resource finds
|
||||
for(uint i = 0, cnt = getResourceCount(); i < cnt; ++i) {
|
||||
auto@ type = getResource(i);
|
||||
if(!type.artificial)
|
||||
staticItems.insertLast(GoResource(type));
|
||||
}
|
||||
|
||||
//Add resource classes
|
||||
for(uint i = 0, cnt = getResourceClassCount(); i < cnt; ++i) {
|
||||
auto@ type = getResourceClass(i);
|
||||
staticItems.insertLast(GoResourceClass(type));
|
||||
}
|
||||
|
||||
keybinds::Global.addBind(KB_GO_MENU, "gogogo");
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#priority init 90
|
||||
import systems;
|
||||
|
||||
enum ScopeType {
|
||||
ST_Invalid,
|
||||
ST_System,
|
||||
|
||||
ST_COUNT
|
||||
};
|
||||
|
||||
class Scope {
|
||||
int id;
|
||||
|
||||
Scope() {
|
||||
id = -1;
|
||||
}
|
||||
|
||||
ScopeType get_type() {
|
||||
return ST_Invalid;
|
||||
}
|
||||
|
||||
vec3d get_position() {
|
||||
return vec3d();
|
||||
}
|
||||
|
||||
string get_name() {
|
||||
return "---";
|
||||
}
|
||||
|
||||
double get_radius() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int get_priority() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class SystemScope : Scope {
|
||||
SystemDesc@ sys;
|
||||
|
||||
SystemScope(SystemDesc@ system) {
|
||||
@sys = system;
|
||||
id = -1;
|
||||
}
|
||||
|
||||
ScopeType get_type() {
|
||||
return ST_System;
|
||||
}
|
||||
|
||||
vec3d get_position() {
|
||||
return sys.position;
|
||||
}
|
||||
|
||||
double get_radius() {
|
||||
return sys.radius;
|
||||
}
|
||||
|
||||
int get_priority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
string get_name() {
|
||||
return sys.object.name;
|
||||
}
|
||||
};
|
||||
|
||||
class ScopeSearch {
|
||||
int minPriority;
|
||||
int maxPriority;
|
||||
double priorityFactor;
|
||||
double minDistance;
|
||||
double maxDistance;
|
||||
bool[] allowedTypes;
|
||||
|
||||
vec3d position;
|
||||
Scope@[] results;
|
||||
double[] factors;
|
||||
|
||||
ScopeSearch() {
|
||||
minPriority = INT_MIN;
|
||||
maxPriority = INT_MAX;
|
||||
priorityFactor = 1.0;
|
||||
minDistance = -INFINITY;
|
||||
maxDistance = INFINITY;
|
||||
|
||||
allowedTypes.length = ST_COUNT;
|
||||
for(int i = 0; i < ST_COUNT; ++i)
|
||||
allowedTypes[i] = true;
|
||||
}
|
||||
};
|
||||
|
||||
namespace scopes {
|
||||
::map scopes;
|
||||
int nextScopeId = 1;
|
||||
};
|
||||
|
||||
void init() {
|
||||
//Add systems as scopes
|
||||
for(uint i = 0, cnt = systemCount; i < cnt; ++i)
|
||||
addScope(SystemScope(getSystem(i)));
|
||||
}
|
||||
|
||||
int addScope(Scope@ scope) {
|
||||
if(scope.id <= 0)
|
||||
scope.id = scopes::nextScopeId++;
|
||||
scopes::scopes.set(scope.id, @scope);
|
||||
return scope.id;
|
||||
}
|
||||
|
||||
void removeScope(Scope@ scope) {
|
||||
removeScope(scope.id);
|
||||
}
|
||||
|
||||
void removeScope(int id) {
|
||||
if(id > 0)
|
||||
scopes::scopes.delete(id);
|
||||
}
|
||||
|
||||
uint searchScopes(ScopeSearch@ s, uint amount) {
|
||||
uint found = 0;
|
||||
s.results.length = amount;
|
||||
s.factors.length = amount;
|
||||
double maxFactor = 0.0;
|
||||
|
||||
map_iterator it = scopes::scopes.iterator();
|
||||
Scope@ scope;
|
||||
while(it.iterate(@scope)) {
|
||||
int priority = scope.priority;
|
||||
if(priority < s.minPriority || priority > s.maxPriority)
|
||||
continue;
|
||||
|
||||
double factor = s.position.distanceTo(scope.position);
|
||||
factor -= scope.radius;
|
||||
if(factor < s.minDistance || factor > s.maxDistance)
|
||||
continue;
|
||||
if(priority != 0)
|
||||
factor /= double(priority) * s.priorityFactor;
|
||||
|
||||
if(found < amount) {
|
||||
if(found == 0) {
|
||||
@s.results[0] = scope;
|
||||
s.factors[0] = factor;
|
||||
}
|
||||
else {
|
||||
for(int i = found; i >= 0; --i) {
|
||||
if(i == 0 || factor > s.factors[i-1]) {
|
||||
@s.results[i] = scope;
|
||||
s.factors[i] = factor;
|
||||
break;
|
||||
}
|
||||
@s.results[i] = s.results[i-1];
|
||||
s.factors[i] = s.factors[i-1];
|
||||
}
|
||||
}
|
||||
maxFactor = s.factors[found];
|
||||
++found;
|
||||
}
|
||||
else if(factor < maxFactor) {
|
||||
for(int i = amount - 1; i >= 0; --i) {
|
||||
if(i == 0 || factor > s.factors[i-1]) {
|
||||
@s.results[i] = scope;
|
||||
s.factors[i] = factor;
|
||||
break;
|
||||
}
|
||||
@s.results[i] = s.results[i-1];
|
||||
s.factors[i] = s.factors[i-1];
|
||||
}
|
||||
maxFactor = s.factors[amount-1];
|
||||
}
|
||||
}
|
||||
|
||||
if(found != amount) {
|
||||
s.results.length = found;
|
||||
s.factors.length = found;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
#priority init 10
|
||||
import navigation.scopes;
|
||||
import navigation.SmartCamera;
|
||||
from input import activeCamera;
|
||||
import elements.BaseGuiElement;
|
||||
|
||||
const int TOPBAR_OFFSET = 77;
|
||||
const int SCOPE_SPACING = 4;
|
||||
const int SCOPE_WIDTH = 50;
|
||||
const int SCOPE_HEIGHT = 50;
|
||||
const int SCOPE_PADDING = 2;
|
||||
|
||||
const double SEARCH_INTERVAL = 1.0;
|
||||
const uint MAX_SCOPES = 16;
|
||||
|
||||
Color scopeColor(0xffffff40);
|
||||
Color scopeHoverColor(0x00ff0040);
|
||||
Color scopeActiveColor(0xff000040);
|
||||
Color scopePanningColor(0x0000ff40);
|
||||
string ellipsis = "-";
|
||||
|
||||
const double smartPanSpeed = 10000.0;
|
||||
const double fadeDistanceMin = 10000.0;
|
||||
const double fadeDistanceMax = 16000.0;
|
||||
|
||||
ScopeSearch search;
|
||||
double searchTimer = 0.0;
|
||||
ScopeButton@ panningButton;
|
||||
ScopeButton@[] buttons;
|
||||
bool shown = false;
|
||||
uint displayedScopes = 0;
|
||||
|
||||
void init() {
|
||||
search.maxDistance = 16000.0;
|
||||
|
||||
@panningButton = ScopeButton();
|
||||
panningButton.visible = false;
|
||||
|
||||
buttons.length = MAX_SCOPES;
|
||||
for(uint i = 0; i < MAX_SCOPES; ++i) {
|
||||
@buttons[i] = ScopeButton();
|
||||
buttons[i].visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void showSmartPan() {
|
||||
shown = true;
|
||||
update();
|
||||
searchTimer = SEARCH_INTERVAL;
|
||||
}
|
||||
|
||||
void hideSmartPan() {
|
||||
shown = false;
|
||||
for(uint i = 0; i < MAX_SCOPES; ++i)
|
||||
buttons[i].visible = false;
|
||||
}
|
||||
|
||||
void toggleSmartPan() {
|
||||
if(shown)
|
||||
hideSmartPan();
|
||||
else
|
||||
showSmartPan();
|
||||
}
|
||||
|
||||
void update() {
|
||||
search.position = activeCamera.lookAt;
|
||||
displayedScopes = searchScopes(search, MAX_SCOPES);
|
||||
|
||||
for(uint i = 0; i < displayedScopes; ++i) {
|
||||
Scope@ scope = search.results[i];
|
||||
|
||||
//Ignore current scope
|
||||
if(search.position.distanceTo(scope.position) < scope.radius
|
||||
|| (panningButton.visible && panningButton.scope is scope)) {
|
||||
buttons[i].visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Ready the scope button
|
||||
buttons[i].visible = true;
|
||||
buttons[i].set(scope);
|
||||
buttons[i].updatePosition();
|
||||
}
|
||||
|
||||
//Hide extra buttons
|
||||
for(uint i = displayedScopes; i < MAX_SCOPES; ++i)
|
||||
buttons[i].visible = false;
|
||||
}
|
||||
|
||||
void updatePositions() {
|
||||
for(uint i = 0; i < displayedScopes; ++i) {
|
||||
Scope@ scope = buttons[i].scope;
|
||||
if(scope is null || search.position.distanceTo(scope.position) < scope.radius
|
||||
|| (panningButton.visible && panningButton.scope is scope)) {
|
||||
buttons[i].visible = false;
|
||||
}
|
||||
else {
|
||||
buttons[i].visible = true;
|
||||
buttons[i].updatePosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool waitForMove = true;
|
||||
int buttonAlpha = 80;
|
||||
void tick(double time) {
|
||||
if(!shown)
|
||||
return;
|
||||
|
||||
//Fade the buttons out at large distances
|
||||
double dist = activeCamera.distance;
|
||||
if(dist > fadeDistanceMin) {
|
||||
if(dist >= fadeDistanceMax) {
|
||||
buttonAlpha = 0;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
buttonAlpha = 80 - ceil(80.0 * (dist - fadeDistanceMin) / (fadeDistanceMax - fadeDistanceMin));
|
||||
}
|
||||
}
|
||||
else {
|
||||
buttonAlpha = 80;
|
||||
}
|
||||
|
||||
//Check if we're panning with a button
|
||||
vec2i mpos = mousePos;
|
||||
if(buttonAlpha > 0 && mpos.x < 6 || mpos.x >= screenSize.width - 6) {
|
||||
if(!waitForMove) {
|
||||
bool found = false;
|
||||
if(panningButton.visible) {
|
||||
if(!panningButton.AbsolutePosition.isWithin(mpos)) {
|
||||
panningButton.visible = false;
|
||||
}
|
||||
else {
|
||||
double tickPan = time * smartPanSpeed;
|
||||
if(activeCamera.panTo(panningButton.scope.position, tickPan)) {
|
||||
panningButton.visible = false;
|
||||
waitForMove = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(uint i = 0; i < displayedScopes; ++i) {
|
||||
if(buttons[i].visible && buttons[i].AbsolutePosition.isWithin(mpos)) {
|
||||
buttons[i].visible = false;
|
||||
panningButton.set(buttons[i].scope);
|
||||
panningButton.AbsolutePosition = buttons[i].AbsolutePosition;
|
||||
panningButton.AbsoluteClipRect = buttons[i].AbsoluteClipRect;
|
||||
panningButton.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
panningButton.visible = false;
|
||||
waitForMove = false;
|
||||
}
|
||||
|
||||
//Update the buttons
|
||||
//if(searchTimer <= 0.0) {
|
||||
//searchTimer = SEARCH_INTERVAL;
|
||||
update();
|
||||
//}
|
||||
//else {
|
||||
//updatePositions();
|
||||
//searchTimer -= time;
|
||||
//}
|
||||
}
|
||||
|
||||
class ScopeButton : BaseGuiElement {
|
||||
Scope@ scope;
|
||||
string name;
|
||||
bool left;
|
||||
bool Hovered;
|
||||
bool Pressed;
|
||||
|
||||
ScopeButton() {
|
||||
Hovered = false;
|
||||
Pressed = false;
|
||||
super(null, recti(0, 0, SCOPE_WIDTH, SCOPE_HEIGHT));
|
||||
}
|
||||
|
||||
void updatePosition() {
|
||||
vec3d camPos = activeCamera.lookAt;
|
||||
vec3d scopePos = scope.position;
|
||||
double flatAngle = activeCamera.screenAngle(scopePos);
|
||||
double percentage = 0.0;
|
||||
|
||||
vec2i pos();
|
||||
if(flatAngle >= 0 && flatAngle <= 0.5) {
|
||||
left = false;
|
||||
percentage = 0.5 - flatAngle;
|
||||
}
|
||||
else if(flatAngle > 0.5 && flatAngle <= 1.0) {
|
||||
left = true;
|
||||
percentage = flatAngle - 0.5;
|
||||
}
|
||||
else if(flatAngle < 0 && flatAngle >= -0.5) {
|
||||
left = false;
|
||||
percentage = 0.5 + flatAngle * -1.0;
|
||||
}
|
||||
else if(flatAngle < -0.5 && flatAngle >= -1.0) {
|
||||
left = true;
|
||||
percentage = 1.5 + flatAngle;
|
||||
}
|
||||
|
||||
if(left)
|
||||
pos.x = 0;
|
||||
else
|
||||
pos.x = screenSize.width - size.width;
|
||||
|
||||
pos.y = TOPBAR_OFFSET;
|
||||
pos.y += double(screenSize.height - TOPBAR_OFFSET - SCOPE_HEIGHT) * percentage;
|
||||
|
||||
bool overlap;
|
||||
do {
|
||||
overlap = false;
|
||||
recti box = recti_area(pos, size);
|
||||
if(panningButton.visible && panningButton.AbsolutePosition.overlaps(box)) {
|
||||
overlap = true;
|
||||
pos.y = panningButton.AbsolutePosition.topLeft.y;
|
||||
|
||||
if(percentage < 0.5)
|
||||
pos.y += SCOPE_HEIGHT + SCOPE_SPACING;
|
||||
else
|
||||
pos.y -= SCOPE_HEIGHT + SCOPE_SPACING;
|
||||
continue;
|
||||
}
|
||||
|
||||
for(uint i = 0; i < MAX_SCOPES; ++i) {
|
||||
if(buttons[i] is this)
|
||||
break;
|
||||
if(buttons[i].left == left && buttons[i].AbsolutePosition.overlaps(box)) {
|
||||
overlap = true;
|
||||
pos.y = buttons[i].AbsolutePosition.topLeft.y;
|
||||
|
||||
if(percentage < 0.5)
|
||||
pos.y += SCOPE_HEIGHT + SCOPE_SPACING;
|
||||
else
|
||||
pos.y -= SCOPE_HEIGHT + SCOPE_SPACING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pos.y < 0 || pos.y + SCOPE_HEIGHT > screenSize.height) {
|
||||
visible = false;
|
||||
return;
|
||||
}
|
||||
} while(overlap);
|
||||
|
||||
position = pos;
|
||||
}
|
||||
|
||||
void set(Scope@ s) {
|
||||
@scope = s;
|
||||
name = scope.name;
|
||||
}
|
||||
|
||||
void trigger() {
|
||||
activeCamera.zoomTo(scope.position);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.caller is this && buttonAlpha > 0) {
|
||||
switch(event.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
Hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
Hovered = false;
|
||||
Pressed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this && buttonAlpha > 0) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
if(event.button == 0) {
|
||||
Pressed = true;
|
||||
}
|
||||
return true;
|
||||
case MET_Button_Up:
|
||||
if(event.button == 0 && Pressed) {
|
||||
Pressed = false;
|
||||
trigger();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(buttonAlpha <= 0)
|
||||
return;
|
||||
|
||||
Color col = scopeColor;
|
||||
if(panningButton is this)
|
||||
col = scopePanningColor;
|
||||
else if(Pressed)
|
||||
col = scopeActiveColor;
|
||||
else if(Hovered && !panningButton.visible)
|
||||
col = scopeHoverColor;
|
||||
|
||||
col.a = buttonAlpha;
|
||||
drawRectangle(AbsolutePosition, col);
|
||||
|
||||
const Font@ fnt = skin.getFont(FT_Normal);
|
||||
recti textPos = AbsolutePosition;
|
||||
textPos.topLeft.x += SCOPE_PADDING;
|
||||
textPos.botRight.x -= SCOPE_PADDING;
|
||||
|
||||
int vpadd = (textPos.height - fnt.getLineHeight()) / 2;
|
||||
textPos.topLeft.y += vpadd;
|
||||
textPos.botRight.y -= vpadd;
|
||||
|
||||
fnt.draw(textPos, name, ellipsis);
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
#priority init 100
|
||||
from settings.map_lib import SystemDesc;
|
||||
import void recalculateElevation() from "navigation.elevation";
|
||||
import void promptExtentRefresh() from "tabs.GalaxyTab";
|
||||
|
||||
SystemDesc[] Systems;
|
||||
|
||||
uint get_systemCount() {
|
||||
return Systems.length;
|
||||
}
|
||||
|
||||
SystemDesc@ getSystem(uint index) {
|
||||
return Systems[index];
|
||||
}
|
||||
|
||||
SystemDesc@ getSystem(Region@ region) {
|
||||
if(region is null || region.SystemId == -1)
|
||||
return null;
|
||||
return Systems[region.SystemId];
|
||||
}
|
||||
|
||||
SystemDesc@ getSystem(const string& name) {
|
||||
//TODO: Use dictionary
|
||||
uint cnt = systemCount;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
if(getSystem(i).name == name)
|
||||
return getSystem(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
SystemDesc@ getSystem(const vec3d& point) {
|
||||
//TODO: This really should not be O(n), implement a better
|
||||
//structure for these lookups
|
||||
for(uint i = 0, cnt = Systems.length; i < cnt; ++i) {
|
||||
SystemDesc@ sys = Systems[i];
|
||||
if(point.distanceToSQ(sys.position) < sys.radius * sys.radius)
|
||||
return sys;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool loaded = false, doRefresh = false;
|
||||
void init() {
|
||||
if(loaded)
|
||||
return;
|
||||
Systems.syncFrom(getSystems());
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(doRefresh) {
|
||||
Systems.length = 0;
|
||||
Systems.syncFrom(getSystems());
|
||||
doRefresh = false;
|
||||
promptExtentRefresh();
|
||||
recalculateElevation();
|
||||
}
|
||||
}
|
||||
|
||||
void save(SaveFile& data) {
|
||||
data << uint(Systems.length);
|
||||
for(uint i = 0; i < Systems.length; ++i)
|
||||
Systems[i].save(data);
|
||||
}
|
||||
|
||||
void load(SaveFile& data) {
|
||||
loaded = true;
|
||||
uint count = 0;
|
||||
data >> count;
|
||||
Systems.length = count;
|
||||
for(uint i = 0; i < Systems.length; ++i)
|
||||
Systems[i].load(data);
|
||||
}
|
||||
|
||||
void refreshClientSystems() {
|
||||
doRefresh = true;
|
||||
}
|
||||
@@ -0,0 +1,876 @@
|
||||
#priority init 100
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.Gui3DObject;
|
||||
import notifications;
|
||||
import influence;
|
||||
import planet_loyalty;
|
||||
import util.icon_view;
|
||||
import util.formatting;
|
||||
from util.draw_model import drawLitModel;
|
||||
from obj_selection import selectObject;
|
||||
from overlays.AnomalyOverlay import AnomalyOverlay;
|
||||
from gui import animate_speed, animate_time;
|
||||
import hooks;
|
||||
|
||||
import tabs.tabbar;
|
||||
import void showInfluenceVote(uint voteId) from "tabs.DiplomacyTab";
|
||||
import Tab@ createInfluenceVoteTab(int voteId) from "tabs.InfluenceVoteTab";
|
||||
import Tab@ createDiplomacyTab() from "tabs.DiplomacyTab";
|
||||
import void zoomTabTo(Object@ obj) from "tabs.GalaxyTab";
|
||||
import Tab@ createGalaxyTab(Object@ obj) from "tabs.GalaxyTab";
|
||||
|
||||
const double ANIM_SPEED = 1000.0;
|
||||
const double CLASS_SCROLL = 30.0;
|
||||
const double EVENT_SCROLL = 50.0;
|
||||
const double FLASH_TIME = 1.0;
|
||||
const double ICON_PULSE_TIME = 0.4;
|
||||
|
||||
void showNotifications() {
|
||||
overlay.visible = true;
|
||||
}
|
||||
|
||||
void hideNotifications() {
|
||||
overlay.visible = false;
|
||||
}
|
||||
|
||||
void gotoNotification(Notification@ n, bool bg = false) {
|
||||
if(n.type == NT_TreatyEvent) {
|
||||
Tab@ tb = findTab(TC_Diplomacy);
|
||||
if(tb is null)
|
||||
@tb = newTab(createDiplomacyTab());
|
||||
switchToTab(tb);
|
||||
}
|
||||
else if(n.type == NT_Card && cast<CardNotification>(n).voteId >= 0) {
|
||||
if(bg)
|
||||
newTab(createInfluenceVoteTab(cast<CardNotification>(n).voteId));
|
||||
else
|
||||
showInfluenceVote(cast<CardNotification>(n).voteId);
|
||||
}
|
||||
else {
|
||||
Object@ obj = n.relatedObject;
|
||||
if(obj !is null) {
|
||||
zoomTabTo(obj);
|
||||
if(n.type == NT_FlagshipBuilt)
|
||||
selectObject(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotifyOverlay : BaseGuiElement {
|
||||
array<NotifyClass@> classes;
|
||||
|
||||
NotifyOverlay() {
|
||||
super(null, Alignment().fill());
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
//Don't consider this element part of the tree
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is this)
|
||||
return null;
|
||||
return elem;
|
||||
}
|
||||
};
|
||||
|
||||
class ClassDisplay {
|
||||
Notification@ base;
|
||||
ClassDisplay(Notification@ n) {
|
||||
@base = n;
|
||||
}
|
||||
|
||||
string formatDescription() {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool update(NotifyClass@ cls, double time) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool goto(Notification@ evt, bool bg = false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void draw(NotifyClass@ cls, const recti& iconPos) {
|
||||
}
|
||||
|
||||
void add(NotifyClass@ cls, Notification@ n) {
|
||||
}
|
||||
}
|
||||
|
||||
class NotifyClass : BaseGuiElement {
|
||||
recti animPos;
|
||||
bool shown = false;
|
||||
int textWidth = 0;
|
||||
double scroll = 0.0;
|
||||
bool animating = false;
|
||||
bool closing = false;
|
||||
bool hovered = false;
|
||||
Notification@ base;
|
||||
Sprite icon;
|
||||
array<NotifyEvent@> active;
|
||||
double flashTime = 0;
|
||||
int flashes = 0;
|
||||
ClassDisplay@ clsDisp;
|
||||
const Model@ iconModel;
|
||||
const Material@ iconMaterial;
|
||||
Object@ related;
|
||||
Draw3D@ drawObject;
|
||||
|
||||
MarkupRenderer render;
|
||||
|
||||
NotifyClass(Notification@ n) {
|
||||
super(overlay, recti());
|
||||
@base = n;
|
||||
@clsDisp = createClassDisplay(base);
|
||||
|
||||
string clsText = n.formatClass();
|
||||
if(clsText.length == 0)
|
||||
clsText = n.formatEvent();
|
||||
else if(n.formatEvent().length != 0)
|
||||
add(n);
|
||||
icon = n.icon;
|
||||
if(!icon.valid) {
|
||||
@iconModel = n.model;
|
||||
@iconMaterial = n.material;
|
||||
if(iconModel is null) {
|
||||
@related = n.relatedObject;
|
||||
if(related !is null)
|
||||
@drawObject = makeDrawMode(related);
|
||||
}
|
||||
}
|
||||
|
||||
render.defaultFont = FT_Medium;
|
||||
render.expandWidth = true;
|
||||
render.parse(skin, clsText, recti(0, 0, 300, 34));
|
||||
render.update(skin, recti(0, 0, 300, 34));
|
||||
textWidth = clamp(render.width+16, 300, 800);
|
||||
updateTooltip();
|
||||
}
|
||||
|
||||
void add(Notification@ n) {
|
||||
if(active.length != 0) {
|
||||
NotifyEvent@ prev = active[active.length - 1];
|
||||
prev.visible = false;
|
||||
}
|
||||
|
||||
NotifyEvent evt(this, n);
|
||||
animate_speed(evt, getEventArea(rect), ANIM_SPEED);
|
||||
evt.animating = true;
|
||||
active.insertLast(evt);
|
||||
flashes += n.flashCount;
|
||||
updateTooltip();
|
||||
|
||||
if(n.pulseIcon)
|
||||
PulseIcon(this, n.icon);
|
||||
|
||||
clsDisp.add(this, n);
|
||||
}
|
||||
|
||||
void animate(const recti& pos) {
|
||||
if(closing)
|
||||
return;
|
||||
if(!shown) {
|
||||
rect = pos + vec2i(pos.width+60, 0);
|
||||
shown = true;
|
||||
}
|
||||
animating = true;
|
||||
animPos = pos;
|
||||
animate_speed(this, animPos, ANIM_SPEED);
|
||||
if(active.length != 0) {
|
||||
NotifyEvent@ prev = active[active.length - 1];
|
||||
prev.animating = true;
|
||||
animate_speed(prev, getEventArea(animPos), ANIM_SPEED);
|
||||
}
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.type == GUI_Animation_Complete) {
|
||||
animating = false;
|
||||
if(closing)
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
else if(evt.type == GUI_Mouse_Entered) {
|
||||
hovered = true;
|
||||
}
|
||||
else if(evt.type == GUI_Mouse_Left) {
|
||||
hovered = false;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
recti getTextArea(const recti& atPos) {
|
||||
return recti_area(
|
||||
vec2i(8+max(atPos.size.width - textWidth - 80 - 8, 0), 4)+atPos.topLeft,
|
||||
vec2i(min(atPos.size.width-16, textWidth + 80), 26));
|
||||
}
|
||||
|
||||
recti getEventArea(const recti& atPos) {
|
||||
recti textArea = getTextArea(atPos);
|
||||
int offset = max(30, atPos.size.width - textArea.width+30);
|
||||
return recti_area(vec2i(offset, 33), vec2i(atPos.size.width - offset, 26));
|
||||
}
|
||||
|
||||
recti getIconArea(const recti& atPos) {
|
||||
recti iconPos = recti_area(atPos.botRight - vec2i(80, 60), vec2i(80, 60));
|
||||
return iconPos;
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() override {
|
||||
render.update(skin, getTextArea(rect));
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool update(double time) {
|
||||
//Update tooltip state
|
||||
if(settings::bIconifyNotifications) {
|
||||
if(tooltipObject is null)
|
||||
updateTooltip();
|
||||
}
|
||||
else {
|
||||
if(tooltipObject !is null)
|
||||
@tooltipObject = null;
|
||||
}
|
||||
|
||||
//Update icon
|
||||
if(!icon.valid) {
|
||||
if(iconModel is null) {
|
||||
if(related !is null && drawObject is null)
|
||||
@drawObject = makeDrawMode(related);
|
||||
}
|
||||
}
|
||||
|
||||
//Update class display
|
||||
if(!clsDisp.update(this, time))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dismiss() {
|
||||
closing = true;
|
||||
animating = true;
|
||||
active.length = 0;
|
||||
animate_speed(this, rect+vec2i(size.width, 0), ANIM_SPEED);
|
||||
overlay.classes.remove(this);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void dismissEvents() {
|
||||
for(uint i = 0, cnt = active.length; i < cnt; ++i)
|
||||
active[i].remove();
|
||||
active.length = 0;
|
||||
}
|
||||
|
||||
void dismissEvent(NotifyEvent@ evt) {
|
||||
active.remove(evt);
|
||||
evt.remove();
|
||||
|
||||
if(active.length != 0) {
|
||||
NotifyEvent@ prev = active[active.length - 1];
|
||||
prev.animating = true;
|
||||
prev.visible = true;
|
||||
animate_speed(prev, getEventArea(animPos), ANIM_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
void popEvent(bool bg = false) {
|
||||
NotifyEvent@ evt;
|
||||
Notification@ n;
|
||||
if(active.length == 0) {
|
||||
@n = base;
|
||||
}
|
||||
else {
|
||||
@evt = active[active.length - 1];
|
||||
@n = evt.notification;
|
||||
}
|
||||
|
||||
if(!clsDisp.goto(n, bg))
|
||||
gotoNotification(n, bg);
|
||||
switch(n.triggerMode) {
|
||||
case NTM_Ignore:
|
||||
break;
|
||||
case NTM_KillClass:
|
||||
dismiss();
|
||||
break;
|
||||
case NTM_KillEvents:
|
||||
dismissEvents();
|
||||
break;
|
||||
case NTM_KillTop:
|
||||
if(evt !is null)
|
||||
dismissEvent(evt);
|
||||
break;
|
||||
}
|
||||
|
||||
flashes = 0;
|
||||
updateTooltip();
|
||||
}
|
||||
|
||||
void updateTooltip() {
|
||||
if(!settings::bIconifyNotifications) {
|
||||
@tooltipObject = null;
|
||||
return;
|
||||
}
|
||||
|
||||
string tt = base.formatClass();
|
||||
if(tt.length == 0)
|
||||
tt = base.formatEvent();
|
||||
tt = "[font=Medium]"+tt+"[/font]";
|
||||
if(clsDisp !is null)
|
||||
tt += clsDisp.formatDescription();
|
||||
|
||||
for(int i = active.length - 1; i >= 0; --i) {
|
||||
Notification@ n = active[i].notification;
|
||||
tt += "\n\n";
|
||||
tt += formatTimeStamp(n.time);
|
||||
tt += " [offset=80]";
|
||||
string evt = n.formatEvent();
|
||||
if(evt.length == 0)
|
||||
evt = n.formatClass();
|
||||
tt += evt;
|
||||
tt += "[/offset]";
|
||||
}
|
||||
|
||||
setMarkupTooltip(this, tt, true, textWidth+30);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& mevt, IGuiElement@ caller) override {
|
||||
if(mevt.type == MET_Button_Down) {
|
||||
return true;
|
||||
}
|
||||
else if(mevt.type == MET_Button_Up) {
|
||||
if(mevt.button == 0) {
|
||||
popEvent();
|
||||
}
|
||||
else if(mevt.button == 1) {
|
||||
if(caller is this)
|
||||
dismiss();
|
||||
else if(active.length != 0)
|
||||
dismissEvent(active[active.length - 1]);
|
||||
}
|
||||
else if(mevt.button == 2) {
|
||||
popEvent(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return BaseGuiElement::onMouseEvent(mevt, caller);
|
||||
}
|
||||
|
||||
//Don't consider this element part of the tree
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(settings::bIconifyNotifications) {
|
||||
if(getIconArea(rect).isWithin(pos))
|
||||
return this;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
if(elem is this) {
|
||||
if(getTextArea(rect).isWithin(pos))
|
||||
return this;
|
||||
if(getIconArea(rect).isWithin(pos))
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
recti textBox = getTextArea(rect);
|
||||
recti iconPos = getIconArea(rect);
|
||||
|
||||
//Show the class text
|
||||
if(!settings::bIconifyNotifications) {
|
||||
skin.draw(SS_PlainOverlay, SF_Normal, textBox.padded(-8, -4));
|
||||
}
|
||||
|
||||
BaseGuiElement::draw();
|
||||
|
||||
if(!settings::bIconifyNotifications) {
|
||||
setClip(textBox);
|
||||
int tbWidth = textBox.width - iconPos.width;
|
||||
if(textWidth > tbWidth && !animating) {
|
||||
int area = textWidth + max(tbWidth / 3, 50);
|
||||
scroll = (scroll + frameLength * CLASS_SCROLL) % double(area);
|
||||
|
||||
int startPos = area - int(scroll);
|
||||
if(startPos < textBox.width) {
|
||||
render.draw(skin, recti_area(textBox.topLeft+vec2i(startPos, 1),
|
||||
vec2i(size.width*2, textBox.height)));
|
||||
}
|
||||
}
|
||||
|
||||
render.draw(skin, recti_area(textBox.topLeft-vec2i(int(scroll), -1),
|
||||
vec2i(size.width*2, textBox.height)));
|
||||
}
|
||||
|
||||
//Show the icon
|
||||
clearClip();
|
||||
if(icon.sheet is spritesheet::Notifications) {
|
||||
icon.draw(iconPos);
|
||||
}
|
||||
else {
|
||||
spritesheet::Notifications.draw(0, iconPos);
|
||||
|
||||
if(icon.valid) {
|
||||
vec2i iSize = icon.size;
|
||||
recti pos = iconPos.padded(30,0,0,0).aspectAligned(double(iSize.width) / double(iSize.height), 1.0, 0.5);
|
||||
icon.draw(pos);
|
||||
}
|
||||
else if(iconModel !is null) {
|
||||
recti pos = iconPos.padded(30,0,0,0).aspectAligned(1.0, 1.0, 0.5);
|
||||
drawLitModel(iconModel, iconMaterial, pos, quaterniond_fromAxisAngle(vec3d_front(), 0.5*pi));
|
||||
}
|
||||
else if(drawObject !is null) {
|
||||
recti pos = iconPos.padded(30,0,0,0).aspectAligned(1.0, 1.0, 0.5);
|
||||
if(related.owner !is null)
|
||||
NODE_COLOR = related.owner.color;
|
||||
else
|
||||
NODE_COLOR = colors::White;
|
||||
drawObject.preRender(related);
|
||||
drawObject.draw(pos, quaterniond_fromAxisAngle(vec3d_front(), 0.5*pi));
|
||||
}
|
||||
}
|
||||
|
||||
//Show class-specifics
|
||||
clsDisp.draw(this, iconPos);
|
||||
|
||||
//Show flashes
|
||||
if(flashTime > 0.0) {
|
||||
float alpha = 0.f;
|
||||
if(flashTime < FLASH_TIME * 0.5)
|
||||
alpha = 1.f - (FLASH_TIME * 0.5 - flashTime) / (FLASH_TIME * 0.5);
|
||||
else
|
||||
alpha = 1.f - (flashTime - FLASH_TIME * 0.5) / (FLASH_TIME * 0.5);
|
||||
|
||||
Color col(0xffffffff);
|
||||
col.a = alpha * 255;
|
||||
spritesheet::Notifications.draw(7, iconPos, col);
|
||||
flashTime -= frameLength;
|
||||
}
|
||||
else {
|
||||
if(flashes > 0) {
|
||||
--flashes;
|
||||
flashTime = FLASH_TIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PulseIcon : BaseGuiElement {
|
||||
Sprite sprite;
|
||||
Color color;
|
||||
|
||||
PulseIcon(NotifyClass@ cls, const Sprite& icon) {
|
||||
noClip = true;
|
||||
sprite = icon;
|
||||
super(cls, recti_area(cls.size, vec2i(1, 1)));
|
||||
|
||||
recti target(cls.size * -2, cls.size);
|
||||
vec2i iSize = icon.size;
|
||||
if(iSize.x != 0 && iSize.y != 0)
|
||||
target = target.aspectAligned(double(iSize.x) / double(iSize.y), 1.0, 1.0);
|
||||
animate_time(this, target, ICON_PULSE_TIME);
|
||||
rect = target;
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.type == GUI_Animation_Complete) {
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
clearClip();
|
||||
sprite.draw(AbsolutePosition, color);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class PulseCard : PulseIcon {
|
||||
Empire@ from;
|
||||
|
||||
PulseCard(NotifyClass@ cls, const Sprite& icon, Empire@ emp) {
|
||||
super(cls, icon);
|
||||
@from = emp;
|
||||
color = Color(0xffffff80);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
PulseIcon::draw();
|
||||
if(from !is null) {
|
||||
Color color = from.color;
|
||||
color.a = 0x80;
|
||||
material::CardBorder.draw(AbsolutePosition, color);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class NotifyEvent : BaseGuiElement {
|
||||
Notification@ notification;
|
||||
MarkupRenderer render;
|
||||
int textWidth;
|
||||
double scroll = 0.0;
|
||||
bool animating = false;
|
||||
|
||||
NotifyEvent(NotifyClass@ cls, Notification@ n) {
|
||||
@notification = n;
|
||||
super(cls, recti_area(vec2i(cls.size.width+20, 33), vec2i(20, 26)));
|
||||
|
||||
string evtText = n.formatEvent();
|
||||
|
||||
render.expandWidth = true;
|
||||
render.parse(skin, evtText, recti(0, 0, 300, 26));
|
||||
render.update(skin, recti(0, 0, 300, 26));
|
||||
textWidth = render.width+16;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.type == GUI_Animation_Complete) {
|
||||
animating = false;
|
||||
return true;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(settings::bIconifyNotifications)
|
||||
return;
|
||||
recti textBox = AbsolutePosition;
|
||||
skin.draw(SS_PlainOverlay, SF_Normal, textBox);
|
||||
|
||||
//Show the event text
|
||||
if(textWidth > textBox.width - 80 && !animating) {
|
||||
int area = textWidth + max((textBox.width - 80) / 3, 50);
|
||||
scroll = (scroll + frameLength * EVENT_SCROLL) % double(area);
|
||||
|
||||
int startPos = area - int(scroll);
|
||||
if(startPos < textBox.width) {
|
||||
render.draw(skin, recti_area(textBox.topLeft+vec2i(startPos, 5),
|
||||
vec2i(size.width*2, textBox.height)));
|
||||
}
|
||||
}
|
||||
|
||||
render.draw(skin, recti_area(textBox.topLeft-vec2i(int(scroll), -5),
|
||||
vec2i(size.width*2, textBox.height)));
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
void handle(Notification@ n) {
|
||||
if(n.time <= minGameTime)
|
||||
return;
|
||||
|
||||
const SoundSource@ sound = n.sound;
|
||||
if(sound !is null)
|
||||
sound.play(priority=true);
|
||||
|
||||
//Check if this notification can be added to any classes
|
||||
for(uint i = 0, cnt = overlay.classes.length; i < cnt; ++i) {
|
||||
NotifyClass@ cls = overlay.classes[i];
|
||||
if(cls.base.sharesClass(n)) {
|
||||
cls.add(n);
|
||||
if(i != 0) {
|
||||
overlay.classes.removeAt(i);
|
||||
overlay.classes.insertLast(cls);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Add a new class if none is there
|
||||
overlay.classes.insertLast(NotifyClass(n));
|
||||
while(overlay.classes.length > uint(settings::dMaxNotifications))
|
||||
overlay.classes[0].dismiss();
|
||||
}
|
||||
|
||||
void updatePositions() {
|
||||
vec2i osize = overlay.size;
|
||||
int w = osize.width * 0.25, h = 60, o = 12;
|
||||
for(uint i = 0, cnt = overlay.classes.length; i < cnt; ++i) {
|
||||
NotifyClass@ cls = overlay.classes[i];
|
||||
recti target = recti_area(osize - vec2i(w, h+h*i+o*i+8), vec2i(w, h));
|
||||
if(target != cls.animPos)
|
||||
cls.animate(target);
|
||||
}
|
||||
}
|
||||
|
||||
uint nextNotify = 0;
|
||||
array<Notification@> unhandled;
|
||||
void tick(double time) {
|
||||
//Update notifications
|
||||
uint latest = playerEmpire.notificationCount;
|
||||
if(latest != nextNotify) {
|
||||
receiveNotifications(unhandled, playerEmpire.getNotifications(100, nextNotify, false));
|
||||
nextNotify = latest;
|
||||
}
|
||||
|
||||
//Handle all unhandled
|
||||
if(unhandled.length > 0) {
|
||||
for(uint i = 0, cnt = unhandled.length; i < cnt; ++i)
|
||||
handle(unhandled[i]);
|
||||
unhandled.length = 0;
|
||||
}
|
||||
|
||||
//Update positioning of classes
|
||||
updatePositions();
|
||||
|
||||
//Update clasess
|
||||
for(uint i = 0, cnt = overlay.classes.length; i < cnt; ++i) {
|
||||
NotifyClass@ cls = overlay.classes[i];
|
||||
if(!cls.update(time)) {
|
||||
cls.dismiss();
|
||||
--i; --cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VoteDisplay : ClassDisplay {
|
||||
double timer = 0.0;
|
||||
InfluenceVote@ vote;
|
||||
|
||||
VoteDisplay(Notification@ n) {
|
||||
super(n);
|
||||
|
||||
@vote = InfluenceVote();
|
||||
VoteNotification@ vn = cast<VoteNotification>(n);
|
||||
receive(getInfluenceVoteByID(vn.vote.id), vote);
|
||||
}
|
||||
|
||||
bool update(NotifyClass@ cls, double time) override {
|
||||
timer += time;
|
||||
if(timer >= 1.0) {
|
||||
timer = 0.0;
|
||||
|
||||
VoteNotification@ vn = cast<VoteNotification>(base);
|
||||
receive(getInfluenceVoteByID(vn.vote.id), vote);
|
||||
|
||||
if(!vote.active && base.time + 10.0 < gameTime
|
||||
&& (cls.active.length == 0 || settings::bIconifyNotifications))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string formatDescription() {
|
||||
if(vote !is null && vote.id != uint(-1)) {
|
||||
if(vote.startedBy is defaultEmpire)
|
||||
return "\n[font=Small]"+vote.type.description+"[/font]";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void draw(NotifyClass@ cls, const recti& iconPos) override {
|
||||
const Font@ ft = cls.skin.getFont(FT_Bold);
|
||||
|
||||
if(vote !is null && vote.id != uint(-1)) {
|
||||
//Show type of vote icon
|
||||
vote.type.icon.draw(iconPos.padded(30, 0, -10, 0).aspectAligned(vote.type.icon.aspect),
|
||||
Color(0xffffff70));
|
||||
if(vote.type.targets.targets.length > 0 && vote.type.targets.targets[0].type == TT_Object) {
|
||||
drawObjectIcon(vote.targets.targets[0].obj,
|
||||
iconPos.padded(30, 10, 10, 10));
|
||||
}
|
||||
|
||||
//Show starter of proposition as glow color
|
||||
Color col = vote.startedBy.color;
|
||||
col.a = 0x80;
|
||||
spritesheet::Notifications.draw(8, iconPos, col);
|
||||
|
||||
//Timer
|
||||
Color timerColor;
|
||||
string timeText;
|
||||
if(vote.totalFor > vote.totalAgainst) {
|
||||
timerColor = Color(0x00ff00ff);
|
||||
timeText = formatShortTime(vote.remainingTime);
|
||||
}
|
||||
else {
|
||||
timerColor = Color(0xff0000ff);
|
||||
timeText = formatShortTime(vote.remainingTime);
|
||||
}
|
||||
ft.draw(iconPos, timeText, locale::SHORT_ELLIPSIS, timerColor, 0.85, 0.9);
|
||||
|
||||
//Status
|
||||
Color voteColor(0x00ff00ff);
|
||||
if(vote.totalAgainst >= vote.totalFor)
|
||||
voteColor = Color(0xff0000ff);
|
||||
|
||||
int net = vote.totalFor - vote.totalAgainst;
|
||||
string netStr = toString(net, 0);
|
||||
if(net > 0)
|
||||
netStr = "+"+netStr;
|
||||
ft.draw(iconPos, netStr,
|
||||
locale::SHORT_ELLIPSIS, voteColor, 0.75, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
void add(NotifyClass@ cls, Notification@ n) override {
|
||||
VoteNotification@ vn = cast<VoteNotification>(n);
|
||||
if(vn !is null) {
|
||||
if(vn.event.type == IVET_Card)
|
||||
PulseCard(cls, vn.event.cardEvent.card.type.icon, vn.event.emp);
|
||||
}
|
||||
}
|
||||
|
||||
bool goto(Notification@ evt, bool bg = false) override {
|
||||
if(bg) {
|
||||
if(!ctrlKey && vote.type.targets.targets.length > 0 && vote.type.targets.targets[0].type == TT_Object)
|
||||
zoomTabTo(vote.targets.targets[0].obj);
|
||||
else
|
||||
newTab(createInfluenceVoteTab(vote.id));
|
||||
}
|
||||
else
|
||||
showInfluenceVote(vote.id);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ContestDisplay : ClassDisplay {
|
||||
Region@ region;
|
||||
uint loyaltyState = CM_None;
|
||||
|
||||
ContestDisplay(Notification@ n) {
|
||||
super(n);
|
||||
|
||||
Object@ obj = base.relatedObject;
|
||||
@region = cast<Region>(obj);
|
||||
if(region is null)
|
||||
@region = obj.region;
|
||||
}
|
||||
|
||||
bool update(NotifyClass@ cls, double time) override {
|
||||
//Dismiss empty contested notifications if the
|
||||
//system is no longer contested.
|
||||
if(base.time + 10.0 < gameTime) {
|
||||
//Check if we have any substantial actual notifications
|
||||
//left, and don't kill it if we do
|
||||
bool hasSubstantial = false;
|
||||
if(!settings::bIconifyNotifications) {
|
||||
for(uint i = 0, cnt = cls.active.length; i < cnt; ++i) {
|
||||
WarEventNotification@ wn = cast<WarEventNotification>(cls.active[i].notification);
|
||||
if(wn is null || wn.eventType != WET_ContestedSystem) {
|
||||
hasSubstantial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(region !is null && !hasSubstantial) {
|
||||
if(region.ContestedMask & playerEmpire.mask == 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(region !is null)
|
||||
loyaltyState = region.getContestedState(playerEmpire);
|
||||
return true;
|
||||
}
|
||||
|
||||
void draw(NotifyClass@ cls, const recti& iconPos) override {
|
||||
if(loyaltyState != CM_None) {
|
||||
Color col = ContestedColors[loyaltyState];
|
||||
col.a = 0x80;
|
||||
spritesheet::Notifications.draw(8, iconPos, col);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class AnomalyDisplay : ClassDisplay {
|
||||
Draw3D@ mode;
|
||||
|
||||
AnomalyDisplay(Notification@ n) {
|
||||
super(n);
|
||||
|
||||
AnomalyNotification@ dn = cast<AnomalyNotification>(n);
|
||||
@mode = makeDrawMode(dn.obj);
|
||||
}
|
||||
|
||||
bool update(NotifyClass@ cls, double time) override {
|
||||
AnomalyNotification@ n = cast<AnomalyNotification>(cls.base);
|
||||
if(!n.obj.valid)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void draw(NotifyClass@ cls, const recti& iconPos) override {
|
||||
if(mode !is null)
|
||||
mode.draw(iconPos, quaterniond());
|
||||
}
|
||||
|
||||
bool goto(Notification@ evt, bool bg = false) override {
|
||||
AnomalyNotification@ n = cast<AnomalyNotification>(evt);
|
||||
if(bg)
|
||||
zoomTabTo(n.obj);
|
||||
else
|
||||
AnomalyOverlay(ActiveTab, cast<Anomaly>(n.obj));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ClassDisplay@ createClassDisplay(Notification@ n) {
|
||||
ClassDisplay@ cls;
|
||||
switch(n.type) {
|
||||
case NT_Vote: @cls = VoteDisplay(n); break;
|
||||
case NT_WarEvent: @cls = ContestDisplay(n); break;
|
||||
case NT_Anomaly: @cls = AnomalyDisplay(n); break;
|
||||
}
|
||||
if(cls is null)
|
||||
@cls = ClassDisplay(n);
|
||||
return cls;
|
||||
}
|
||||
|
||||
NotifyOverlay@ overlay;
|
||||
double minGameTime = 0.0;
|
||||
void init() {
|
||||
@overlay = NotifyOverlay();
|
||||
minGameTime = gameTime;
|
||||
}
|
||||
|
||||
void save(SaveFile& file) {
|
||||
uint cnt = overlay.classes.length;
|
||||
file << cnt;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
NotifyClass@ cls = overlay.classes[i];
|
||||
file << cls.base;
|
||||
|
||||
uint evcnt = cls.active.length;
|
||||
file << evcnt;
|
||||
for(uint j = 0; j < evcnt; ++j) {
|
||||
NotifyEvent@ evt = cls.active[j];
|
||||
file << evt.notification;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load(SaveFile& file) {
|
||||
uint cnt = 0;
|
||||
file >> cnt;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
Notification@ n = loadNotification(file);
|
||||
NotifyClass cls(n);
|
||||
overlay.classes.insertLast(cls);
|
||||
|
||||
uint evcnt = 0;
|
||||
file >> evcnt;
|
||||
|
||||
for(uint j = 0; j < evcnt; ++j) {
|
||||
Notification@ n = loadNotification(file);
|
||||
cls.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
updatePositions();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,219 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiOverlay;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiText;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiSprite;
|
||||
from dialogs.MessageDialog import message;
|
||||
import anomalies;
|
||||
import targeting.ObjectTarget;
|
||||
|
||||
class Option : GuiButton {
|
||||
const AnomalyOption@ option;
|
||||
GuiSprite@ icon;
|
||||
GuiMarkupText@ content;
|
||||
uint index;
|
||||
|
||||
Option(IGuiElement@ parent) {
|
||||
super(parent, recti());
|
||||
@icon = GuiSprite(this, Alignment(Left+4, Top+0.5f-30, Left+64, Top+0.5f+30));
|
||||
@content = GuiMarkupText(this, recti(68, 4, 100, 100));
|
||||
style = SS_ChoiceBox;
|
||||
}
|
||||
|
||||
int set(const AnomalyOption@ option, int y, uint index) {
|
||||
@this.option = option;
|
||||
this.index = index;
|
||||
position = vec2i(4, y);
|
||||
size = vec2i(parent.size.width-8, size.height);
|
||||
content.size = vec2i(size.width - 72, content.size.height);
|
||||
content.text = option.desc;
|
||||
icon.desc = option.icon;
|
||||
updateAbsolutePosition();
|
||||
size = vec2i(size.width, max(content.size.height + 12, 68));
|
||||
return size.height;
|
||||
}
|
||||
};
|
||||
|
||||
class AnomalyOverlay : GuiOverlay {
|
||||
Anomaly@ anomaly;
|
||||
GuiBackgroundPanel@ bg;
|
||||
GuiBackgroundPanel@ choices;
|
||||
|
||||
GuiPanel@ descPanel;
|
||||
GuiMarkupText@ description;
|
||||
GuiText@ progressLabel;
|
||||
Gui3DObject@ model;
|
||||
GuiProgressbar@ bar;
|
||||
|
||||
GuiPanel@ choicePanel;
|
||||
array<Option@> options;
|
||||
|
||||
AnomalyOverlay(IGuiElement@ parent, Anomaly@ obj) {
|
||||
@anomaly = obj;
|
||||
|
||||
super(parent);
|
||||
|
||||
uint left = 500;
|
||||
uint right = 500;
|
||||
uint total = left + 12 + right;
|
||||
|
||||
@bg = GuiBackgroundPanel(this, Alignment(Left+0.5f-total/2, Top+0.5f-200, Left+0.5f-total/2+left, Top+0.5f+200));
|
||||
bg.title = obj.name;
|
||||
bg.titleColor = Color(0x00ff00ff);
|
||||
|
||||
@choices = GuiBackgroundPanel(this, Alignment(Left+0.5f-total/2+left+12, Top+0.5f-300, Left+0.5f+total/2, Top+0.5f+300));
|
||||
choices.title = locale::ANOMALY_CHOICES;
|
||||
choices.titleColor = Color(0xff8000ff);
|
||||
|
||||
@progressLabel = GuiText(choices, Alignment(Left+8, Top+0.4f-30, Right-8, Top+0.4f-3), locale::SCAN_PROGRESS);
|
||||
progressLabel.horizAlign = 0.5;
|
||||
progressLabel.vertAlign = 1.0;
|
||||
@bar = GuiProgressbar(choices, Alignment(Left+12, Top+0.4f+3, Right-12, Top+0.4f+30));
|
||||
bar.frontColor = Color(0x6aadcbff);
|
||||
|
||||
@descPanel = GuiPanel(bg, Alignment(Left+4, Top+36, Left+left-4, Bottom-8));
|
||||
|
||||
@description = GuiMarkupText(descPanel, recti_area(4, 0, left-8, 100), obj.narrative);
|
||||
description.fitWidth = true;
|
||||
@model = Gui3DObject(descPanel, recti_area(7, 250, 100, 100), obj);
|
||||
|
||||
@choicePanel = GuiPanel(choices, Alignment(Left, Top+38, Right, Bottom));
|
||||
choicePanel.visible = true;
|
||||
|
||||
closeSelf = false;
|
||||
updateAbsolutePosition();
|
||||
update();
|
||||
bringToFront();
|
||||
|
||||
overlays.insertLast(this);
|
||||
}
|
||||
|
||||
void remove() {
|
||||
overlays.remove(this);
|
||||
GuiOverlay::remove();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
{
|
||||
Option@ opt = cast<Option>(evt.caller);
|
||||
if(opt !is null) {
|
||||
if(opt.option.targets.length == 0) {
|
||||
anomaly.choose(opt.index);
|
||||
}
|
||||
else {
|
||||
targetObject(AnomalyTargeting(anomaly, opt.option, opt.index, 0));
|
||||
GuiOverlay::close();
|
||||
}
|
||||
timer = 0.05f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return GuiOverlay::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
float timer = 0.f;
|
||||
void update() {
|
||||
if(!anomaly.valid) {
|
||||
GuiOverlay::close();
|
||||
return;
|
||||
}
|
||||
|
||||
timer -= frameLength;
|
||||
if(timer <= 0.f) {
|
||||
float progress = anomaly.progress;
|
||||
if(progress >= 1.f) {
|
||||
description.text = anomaly.narrative;
|
||||
|
||||
const AnomalyType@ type = getAnomalyType(anomaly.anomalyType);
|
||||
uint optCount = anomaly.optionCount;
|
||||
|
||||
choicePanel.visible = true;
|
||||
progressLabel.visible = false;
|
||||
bar.visible = false;
|
||||
|
||||
uint oldCnt = options.length;
|
||||
for(uint i = optCount; i < oldCnt; ++i)
|
||||
options[i].remove();
|
||||
options.length = optCount;
|
||||
int y = 0;
|
||||
for(uint i = 0; i < optCount; ++i) {
|
||||
AnomalyOption@ option = type.options[anomaly.option[i]];
|
||||
|
||||
if(options[i] is null)
|
||||
@options[i] = Option(choicePanel);
|
||||
|
||||
y += options[i].set(option, y, i) + 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
choicePanel.visible = false;
|
||||
progressLabel.visible = true;
|
||||
bar.visible = true;
|
||||
}
|
||||
|
||||
if(bar.visible) {
|
||||
bar.progress = progress;
|
||||
bar.text = toString(floor(progress * 100.0),0) + "%";
|
||||
}
|
||||
|
||||
@model.drawMode = makeDrawMode(anomaly);
|
||||
updateAbsolutePosition();
|
||||
timer += 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
GuiOverlay::updateAbsolutePosition();
|
||||
if(model !is null) {
|
||||
int mh = max(128, descPanel.size.height - description.size.height - 42);
|
||||
model.rect = recti_area(8, description.size.height+42, descPanel.size.width-16, mh);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class AnomalyTargeting : ObjectTargeting {
|
||||
Anomaly@ obj;
|
||||
const AnomalyOption@ option;
|
||||
Targets@ targets;
|
||||
uint optIndex;
|
||||
uint targIndex;
|
||||
|
||||
AnomalyTargeting(Anomaly@ obj, const AnomalyOption@ opt, uint optIndex, uint targIndex, Targets@ targets = null) {
|
||||
if(targets is null)
|
||||
@targets = Targets(opt.targets);
|
||||
@this.obj = obj;
|
||||
this.optIndex = optIndex;
|
||||
this.targIndex = targIndex;
|
||||
@this.option = opt;
|
||||
@this.targets = targets;
|
||||
}
|
||||
|
||||
bool valid(Object@ obj) override {
|
||||
@targets[targIndex].obj = obj;
|
||||
targets[targIndex].filled = true;
|
||||
return option.checkTargets(playerEmpire, targets);
|
||||
}
|
||||
|
||||
void call(Object@ targ) override {
|
||||
obj.choose(optIndex, targ);
|
||||
}
|
||||
|
||||
string message(Object@ obj, bool valid) override {
|
||||
return option.blurb;
|
||||
}
|
||||
};
|
||||
|
||||
array<AnomalyOverlay@> overlays;
|
||||
void tick(double time) {
|
||||
for(uint i = 0, cnt = overlays.length; i < cnt; ++i)
|
||||
overlays[i].update();
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import overlays.InfoBar;
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiResources;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiGroupDisplay;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiMarkupText;
|
||||
import ship_groups;
|
||||
import util.formatting;
|
||||
import artifacts;
|
||||
from obj_selection import isSelected, selectObject, clearSelection, addToSelection;
|
||||
|
||||
class ArtifactInfoBar : InfoBar {
|
||||
Artifact@ obj;
|
||||
Gui3DObject@ objView;
|
||||
|
||||
GuiSkinElement@ nameBox;
|
||||
GuiText@ name;
|
||||
|
||||
GuiSkinElement@ descBox;
|
||||
GuiMarkupText@ desc;
|
||||
|
||||
ActionBar@ actions;
|
||||
|
||||
ArtifactInfoBar(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
@alignment = Alignment(Left, Bottom-228, Left+395, Bottom);
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(
|
||||
Left-1.f, Top, Right, Bottom+3.f));
|
||||
objView.objectRotation = false;
|
||||
objView.internalRotation = quaterniond_fromAxisAngle(vec3d(0.0, 0.0, 1.0), -0.15*pi);
|
||||
|
||||
@actions = ActionBar(this, vec2i(315, 172));
|
||||
actions.noClip = true;
|
||||
|
||||
int y = 104;
|
||||
@nameBox = GuiSkinElement(this, Alignment(Left+4, Top+y, Left+266, Top+y+34), SS_PlainOverlay);
|
||||
@name = GuiText(nameBox, Alignment().padded(8, 0));
|
||||
name.font = FT_Medium;
|
||||
|
||||
y += 40;
|
||||
@descBox = GuiSkinElement(this, Alignment(Left+4, Top+y, Left+266, Top+y+80), SS_PlainOverlay);
|
||||
@desc = GuiMarkupText(descBox, Alignment().padded(3));
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
actions.clear();
|
||||
if(obj.owner is playerEmpire || obj.owner is null || !obj.owner.valid)
|
||||
actions.addAbilities(obj, expanded=true);
|
||||
actions.init(obj);
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) override {
|
||||
return obj.isArtifact;
|
||||
}
|
||||
|
||||
Object@ get() override {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void set(Object@ obj) override {
|
||||
@this.obj = cast<Artifact>(obj);
|
||||
@objView.object = obj;
|
||||
updateTimer = 0.0;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) override {
|
||||
if(obj is this.obj)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
double updateTimer = 1.0;
|
||||
void update(double time) override {
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateTimer = randomd(0.1,0.9);
|
||||
Empire@ owner = obj.owner;
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(owner !is null)
|
||||
name.color = owner.color;
|
||||
|
||||
auto@ type = getArtifactType(obj.ArtifactType);
|
||||
if(type !is null)
|
||||
desc.text = type.description;
|
||||
|
||||
//Update action bar
|
||||
updateActions();
|
||||
}
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is this)
|
||||
return null;
|
||||
if(elem is objView) {
|
||||
int height = AbsolutePosition.size.height;
|
||||
vec2i origin(AbsolutePosition.topLeft.x, AbsolutePosition.botRight.y);
|
||||
origin.y += height;
|
||||
if(pos.distanceTo(origin) > height * 1.6)
|
||||
return null;
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(actions.visible) {
|
||||
recti pos = actions.absolutePosition;
|
||||
skin.draw(SS_Panel, SF_Normal, recti(pos.topLeft - vec2i(80, 0), pos.botRight + vec2i(0, 20)));
|
||||
}
|
||||
InfoBar::draw();
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ makeArtifactInfoBar(IGuiElement@ parent, Object@ obj) {
|
||||
ArtifactInfoBar bar(parent);
|
||||
bar.set(obj);
|
||||
return bar;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import util.formatting;
|
||||
import artifacts;
|
||||
import abilities;
|
||||
import icons;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class ArtifactPopup : Popup {
|
||||
GuiText@ name;
|
||||
GuiMarkupText@ description;
|
||||
GuiText@ cost;
|
||||
GuiSprite@ icon;
|
||||
Gui3DObject@ objView;
|
||||
Artifact@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
ArtifactPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(210, 220);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+4, Right-4, Top+30));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+3+4, Top+30+4, Right-4-4, Top+110-4));
|
||||
|
||||
@description = GuiMarkupText(this, Alignment(Left+8, Top+110, Right-8, Bottom-4));
|
||||
|
||||
@icon = GuiSprite(this, Alignment(Left+8, Bottom-34, Left+35, Bottom-7));
|
||||
|
||||
@cost = GuiText(this, Alignment(Left+35, Bottom-34, Right, Bottom-4));
|
||||
cost.horizAlign = 0.5;
|
||||
cost.font = FT_Bold;
|
||||
cost.color = colors::Energy;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isArtifact;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Artifact>(Obj);
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
skin.draw(SS_Panel, SF_Normal, bgPos);
|
||||
skin.draw(SS_BG3D, SF_Normal, objView.absolutePosition.padded(-4));
|
||||
skin.draw(SS_SubTitle, SF_Normal, recti_area(bgPos.topLeft+vec2i(2,1), vec2i(bgPos.width-5, 30)));
|
||||
if(cost.visible)
|
||||
skin.draw(SS_SubTitle, SF_Normal, cost.absolutePosition.padded(-31,-3,4,-1), colors::Energy);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 1.0 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
const ArtifactType@ type = getArtifactType(obj.ArtifactType);
|
||||
if(type !is null)
|
||||
description.text = type.description;
|
||||
else
|
||||
description.text = "--";
|
||||
|
||||
//Update cost
|
||||
array<Ability> abilities;
|
||||
abilities.syncFrom(obj.getAbilities());
|
||||
|
||||
if(abilities.length != 0) {
|
||||
icon.visible = true;
|
||||
cost.visible = true;
|
||||
|
||||
double energyCost = abilities[0].getEnergyCost();
|
||||
|
||||
@abilities[0].emp = playerEmpire;
|
||||
icon.desc = abilities[0].type.icon;
|
||||
cost.text = format("$1 $2", energyCost, locale::RESOURCE_ENERGY);
|
||||
|
||||
cost.visible = energyCost != 0;
|
||||
icon.visible = cost.visible;
|
||||
}
|
||||
else {
|
||||
icon.visible = false;
|
||||
cost.visible = false;
|
||||
}
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,194 @@
|
||||
import overlays.InfoBar;
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiResources;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiGroupDisplay;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiResources;
|
||||
import cargo;
|
||||
import resources;
|
||||
import ship_groups;
|
||||
import util.formatting;
|
||||
from obj_selection import isSelected, selectObject, clearSelection, addToSelection;
|
||||
|
||||
class AsteroidInfoBar : InfoBar {
|
||||
Asteroid@ obj;
|
||||
Gui3DObject@ objView;
|
||||
|
||||
GuiSkinElement@ nameBox;
|
||||
GuiText@ name;
|
||||
|
||||
GuiSkinElement@ resourceBox;
|
||||
GuiSprite@ cargoIcon;
|
||||
GuiText@ cargoName;
|
||||
GuiText@ cargoValue;
|
||||
GuiResourceGrid@ resources;
|
||||
|
||||
GuiSkinElement@ stateBox;
|
||||
GuiMarkupText@ state;
|
||||
|
||||
ActionBar@ actions;
|
||||
|
||||
AsteroidInfoBar(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
@alignment = Alignment(Left, Bottom-228, Left+395, Bottom);
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(
|
||||
Left-1.f, Top, Right, Bottom+3.f));
|
||||
objView.objectRotation = false;
|
||||
objView.internalRotation = quaterniond_fromAxisAngle(vec3d(0.0, 0.0, 1.0), -0.15*pi);
|
||||
|
||||
@actions = ActionBar(this, vec2i(305, 172));
|
||||
actions.noClip = true;
|
||||
|
||||
int y = 56;
|
||||
@nameBox = GuiSkinElement(this, Alignment(Left+12, Top+y, Left+156, Top+y+34), SS_PlainOverlay);
|
||||
@name = GuiText(nameBox, Alignment().padded(8, 0));
|
||||
name.font = FT_Medium;
|
||||
|
||||
y += 40;
|
||||
@resourceBox = GuiSkinElement(this, Alignment(Left+12, Top+y, Left+226, Top+y+34), SS_PlainOverlay);
|
||||
@resources = GuiResourceGrid(resourceBox, Alignment(Left+8, Top+5, Right-8, Bottom-5));
|
||||
resources.visible = false;
|
||||
resources.spacing.x = 6;
|
||||
resources.horizAlign = 0.0;
|
||||
@cargoIcon = GuiSprite(resourceBox, Alignment(Left+2, Top+2, Left+31, Bottom-2));
|
||||
@cargoName = GuiText(resourceBox, Alignment(Left+38, Top+4, Right-4, Bottom-4));
|
||||
cargoName.font = FT_Bold;
|
||||
@cargoValue = GuiText(resourceBox, Alignment(Left+38, Top+4, Right-12, Bottom-4));
|
||||
cargoValue.horizAlign = 1.0;
|
||||
|
||||
y += 40;
|
||||
@stateBox = GuiSkinElement(this, Alignment(Left+12, Top+y, Left+236, Bottom-4), SS_PlainOverlay);
|
||||
@state = GuiMarkupText(stateBox, Alignment(Left+8, Top+4, Right-4, Bottom));
|
||||
state.memo = true;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
actions.clear();
|
||||
|
||||
if(obj.owner is playerEmpire) {
|
||||
actions.addBasic(obj);
|
||||
actions.addEmpireAbilities(playerEmpire, obj);
|
||||
}
|
||||
|
||||
actions.init(obj);
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) override {
|
||||
return obj.isAsteroid;
|
||||
}
|
||||
|
||||
Object@ get() override {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void set(Object@ obj) override {
|
||||
@this.obj = cast<Asteroid>(obj);
|
||||
@objView.object = obj;
|
||||
updateTimer = 0.0;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) override {
|
||||
if(obj is this.obj)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
double updateTimer = 1.0;
|
||||
void update(double time) override {
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateTimer = randomd(0.1,0.9);
|
||||
Empire@ owner = obj.owner;
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(owner !is null)
|
||||
name.color = owner.color;
|
||||
|
||||
if(obj.cargoTypes != 0) {
|
||||
//Update cargo display
|
||||
auto@ cargo = getCargoType(obj.cargoType[0]);
|
||||
resourceBox.visible = cargo !is null;
|
||||
if(cargo !is null) {
|
||||
cargoIcon.desc = cargo.icon;
|
||||
cargoName.text = cargo.name+":";
|
||||
cargoValue.text = standardize(obj.getCargoStored(cargo.id), true);
|
||||
}
|
||||
|
||||
cargoIcon.visible = true;
|
||||
cargoName.visible = true;
|
||||
cargoValue.visible = true;
|
||||
resources.visible = false;
|
||||
|
||||
state.text = locale::ASTEROID_MINING;
|
||||
}
|
||||
else if(obj.nativeResourceCount != 0) {
|
||||
//Update resource display
|
||||
resources.resources.syncFrom(obj.getAllResources());
|
||||
resources.resources.sortDesc();
|
||||
resources.setSingleMode(align=0.0);
|
||||
|
||||
resourceBox.visible = resources.length != 0;
|
||||
|
||||
cargoIcon.visible = false;
|
||||
cargoName.visible = false;
|
||||
cargoValue.visible = false;
|
||||
resources.visible = true;
|
||||
|
||||
if(owner.valid && obj.visible)
|
||||
state.text = locale::ASTEROID_OWNED;
|
||||
else
|
||||
state.text = locale::ASTEROID_UNOWNED;
|
||||
}
|
||||
else {
|
||||
resourceBox.visible = false;
|
||||
}
|
||||
|
||||
//Update action bar
|
||||
updateActions();
|
||||
}
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is this)
|
||||
return null;
|
||||
if(elem is objView) {
|
||||
int height = AbsolutePosition.size.height;
|
||||
vec2i origin(AbsolutePosition.topLeft.x, AbsolutePosition.botRight.y);
|
||||
origin.y += height;
|
||||
if(pos.distanceTo(origin) > height * 1.6)
|
||||
return null;
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(actions.visible) {
|
||||
recti pos = actions.absolutePosition;
|
||||
skin.draw(SS_Panel, SF_Normal, recti(pos.topLeft - vec2i(70, 0), pos.botRight + vec2i(0, 20)));
|
||||
}
|
||||
InfoBar::draw();
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ makeAsteroidInfoBar(IGuiElement@ parent, Object@ obj) {
|
||||
AsteroidInfoBar bar(parent);
|
||||
bar.set(obj);
|
||||
return bar;
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiResources;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
import resources;
|
||||
import cargo;
|
||||
|
||||
class AsteroidPopup : Popup {
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
Asteroid@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
GuiSkinElement@ band;
|
||||
GuiSprite@ cargoIcon;
|
||||
GuiText@ cargoName;
|
||||
GuiText@ cargoValue;
|
||||
GuiResourceGrid@ resources;
|
||||
|
||||
AsteroidPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(150, 135);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+25, Right-4, Top+95));
|
||||
|
||||
@band = GuiSkinElement(this, Alignment(Left+3, Bottom-35, Right-4, Bottom-2), SS_SubTitle);
|
||||
band.color = Color(0xaaaaaaff);
|
||||
|
||||
@resources = GuiResourceGrid(band, Alignment(Left+4, Top+4, Right-3, Bottom-4));
|
||||
resources.visible = false;
|
||||
|
||||
@cargoIcon = GuiSprite(band, Alignment(Left+2, Top+2, Left+31, Bottom-2));
|
||||
@cargoName = GuiText(band, Alignment(Left+38, Top+4, Right-4, Bottom-4));
|
||||
cargoName.font = FT_Bold;
|
||||
@cargoValue = GuiText(band, Alignment(Left+38, Top+4, Right-4, Bottom-4));
|
||||
cargoValue.horizAlign = 1.0;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isAsteroid;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Asteroid>(Obj);
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = SS_GenericPopupBG;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
if(obj.owner !is null) {
|
||||
skin.draw(style, flags, bgPos, obj.owner.color);
|
||||
if(obj.owner.flag !is null)
|
||||
obj.owner.flag.draw(
|
||||
objView.absolutePosition.aspectAligned(1.0, horizAlign=1.0, vertAlign=1.0),
|
||||
obj.owner.color * Color(0xffffff30));
|
||||
}
|
||||
else
|
||||
skin.draw(style, flags, bgPos, Color(0xffffffff));
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.5 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
if(obj.cargoTypes != 0) {
|
||||
auto@ cargo = getCargoType(obj.cargoType[0]);
|
||||
band.visible = cargo !is null;
|
||||
if(cargo !is null) {
|
||||
cargoIcon.desc = cargo.icon;
|
||||
cargoName.text = cargo.name+":";
|
||||
cargoValue.text = standardize(obj.getCargoStored(cargo.id), true);
|
||||
}
|
||||
cargoIcon.visible = true;
|
||||
cargoName.visible = true;
|
||||
cargoValue.visible = true;
|
||||
resources.visible = false;
|
||||
}
|
||||
else if(obj.nativeResourceCount != 0) {
|
||||
cargoIcon.visible = false;
|
||||
cargoName.visible = false;
|
||||
cargoValue.visible = false;
|
||||
resources.visible = true;
|
||||
|
||||
resources.resources.syncFrom(obj.getAllResources());
|
||||
resources.setSingleMode();
|
||||
|
||||
band.visible = resources.length != 0;
|
||||
}
|
||||
else {
|
||||
band.visible = false;
|
||||
}
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,176 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiResources;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiSkinElement;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
import icons;
|
||||
import resources;
|
||||
import civilians;
|
||||
|
||||
class CivilianPopup : Popup {
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
Civilian@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
GuiResourceGrid@ resources;
|
||||
|
||||
GuiText@ cargoLabel;
|
||||
GuiMarkupText@ worth;
|
||||
GuiMarkupText@ cargoText;
|
||||
|
||||
GuiProgressbar@ health;
|
||||
|
||||
CivilianPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(190, 185);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+25, Right-4, Top+95));
|
||||
|
||||
@health = GuiProgressbar(this, Alignment(Left+3, Bottom-89, Right-4, Bottom-63));
|
||||
health.tooltip = locale::HEALTH;
|
||||
GuiSprite healthIcon(health, Alignment(Left+2, Top+1, Width=24, Height=24), icons::Health);
|
||||
|
||||
GuiSkinElement band(this, Alignment(Left+3, Bottom-65, Right-4, Bottom-32), SS_SubTitle);
|
||||
band.color = Color(0xaaaaaaff);
|
||||
|
||||
@cargoLabel = GuiText(band, Alignment(Left+5, Top+3, Left+70, Bottom-2), locale::SHIP_CARGO);
|
||||
cargoLabel.font = FT_Bold;
|
||||
cargoLabel.stroke = colors::Black;
|
||||
@worth = GuiMarkupText(band, Alignment(Left+70, Top+6, Right-5, Bottom-2));
|
||||
|
||||
GuiSkinElement band2(this, Alignment(Left+3, Bottom-34, Right-4, Bottom-2), SS_SubTitle);
|
||||
|
||||
@cargoText = GuiMarkupText(band2, Alignment(Left+3, Top+4, Right-3, Bottom-2));
|
||||
cargoText.defaultFont = FT_Bold;
|
||||
@resources = GuiResourceGrid(band2, Alignment(Left+3, Top+3, Right-3, Bottom-2));
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isCivilian;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Civilian>(Obj);
|
||||
@objView.object = Obj;
|
||||
@resources.drawFrom = obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = SS_GenericPopupBG;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
if(obj.owner !is null) {
|
||||
skin.draw(style, flags, bgPos, obj.owner.color);
|
||||
if(obj.owner.flag !is null)
|
||||
obj.owner.flag.draw(
|
||||
objView.absolutePosition.aspectAligned(1.0, horizAlign=1.0, vertAlign=1.0),
|
||||
obj.owner.color * Color(0xffffff30));
|
||||
}
|
||||
else
|
||||
skin.draw(style, flags, bgPos, Color(0xffffffff));
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.5 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
//Update hp display
|
||||
double curHP = obj.health;
|
||||
double maxHP = obj.maxHealth;
|
||||
|
||||
Color high(0x00ff00ff);
|
||||
Color low(0xff0000ff);
|
||||
|
||||
health.progress = curHP / maxHP;
|
||||
health.frontColor = low.interpolate(high, health.progress);
|
||||
health.text = standardize(curHP)+" / "+standardize(maxHP);
|
||||
|
||||
//Update resources
|
||||
uint type = obj.getCargoType();
|
||||
int value = obj.getCargoWorth();
|
||||
cargoLabel.color = obj.owner.color;
|
||||
if(type == CT_Goods) {
|
||||
resources.visible = false;
|
||||
cargoText.visible = true;
|
||||
cargoText.text = locale::CARGO_GOODS;
|
||||
}
|
||||
else if(type == CT_Resource) {
|
||||
const ResourceType@ res = getResource(obj.getCargoResource());
|
||||
resources.visible = true;
|
||||
cargoText.visible = false;
|
||||
if(res !is null) {
|
||||
resources.types.length = 1;
|
||||
@resources.types[0] = res;
|
||||
resources.typeMode = true;
|
||||
resources.setSingleMode();
|
||||
}
|
||||
else {
|
||||
resources.types.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
worth.text = format(locale::SHIP_CARGO_WORTH, formatMoney(value));
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,139 @@
|
||||
#priority init -100
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiContextMenu;
|
||||
import elements.MarkupTooltip;
|
||||
import tabs.Tab;
|
||||
import util.formatting;
|
||||
import timing;
|
||||
import influence;
|
||||
from tabs.tabbar import TAB_HEIGHT, GLOBAL_BAR_HEIGHT, ActiveTab;
|
||||
|
||||
class ClearEdictOption : GuiContextOption {
|
||||
ClearEdictOption() {
|
||||
super(locale::EDICT_CLEAR_OPTION);
|
||||
}
|
||||
|
||||
void call(GuiContextMenu@ menu) override {
|
||||
playerEmpire.clearEdict();
|
||||
}
|
||||
};
|
||||
|
||||
class EdictDisplay : BaseGuiElement {
|
||||
GuiMarkupText@ text;
|
||||
string prevText;
|
||||
bool clicking = false;
|
||||
|
||||
EdictDisplay() {
|
||||
super(null, recti_area(210,TAB_HEIGHT+GLOBAL_BAR_HEIGHT, 200, 30));
|
||||
@text = GuiMarkupText(this, recti_area(6,6, 120,24));
|
||||
text.expandWidth = true;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Mouse_Left:
|
||||
if(evt.caller is this)
|
||||
clicking = false;
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
if(playerEmpire.SubjugatedBy !is null)
|
||||
return;
|
||||
|
||||
GuiContextMenu menu(mousePos);
|
||||
menu.addOption(ClearEdictOption());
|
||||
menu.finalize();
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this || source is text) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
if(event.button == 1) {
|
||||
clicking = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MET_Button_Up:
|
||||
if(event.button == 1) {
|
||||
if(clicking)
|
||||
showMenu();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
Empire@ master = playerEmpire.SubjugatedBy;
|
||||
uint type = 0;
|
||||
if(master is null)
|
||||
type = playerEmpire.getEdictType();
|
||||
else
|
||||
type = master.getEdictType();
|
||||
|
||||
visible = (ActiveTab.category == TC_Galaxy) && type != 0;
|
||||
|
||||
if(visible) {
|
||||
string txt;
|
||||
Empire@ emp; Object@ obj;
|
||||
if(master !is null) {
|
||||
@emp = master.getEdictEmpire();
|
||||
@obj = master.getEdictObject();
|
||||
txt = locale::EDICT_FROM_MASTER;
|
||||
}
|
||||
else {
|
||||
@emp = playerEmpire.getEdictEmpire();
|
||||
@obj = playerEmpire.getEdictObject();
|
||||
txt = locale::EDICT_TO_VASSALS;
|
||||
}
|
||||
|
||||
txt = format(txt, formatEmpireName(master),
|
||||
format(localize("#EDICT_"+toString(type)),
|
||||
formatEmpireName(emp), formatObject(obj)));
|
||||
|
||||
if(txt != prevText) {
|
||||
prevText = txt;
|
||||
text.text = txt;
|
||||
text.updateAbsolutePosition();
|
||||
size = vec2i(text.textWidth + 12, 30);
|
||||
|
||||
string tt;
|
||||
if(master !is null)
|
||||
tt = locale::TT_EDICT_FROM_MASTER;
|
||||
else
|
||||
tt = locale::TT_EDICT_TO_VASSALS;
|
||||
|
||||
tt = format(tt, formatEmpireName(master),
|
||||
format(localize("#TT_EDICT_"+toString(type)),
|
||||
formatEmpireName(emp), formatObject(obj)));
|
||||
setMarkupTooltip(this, tt, width=300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
skin.draw(SS_TimeDisplay, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
EdictDisplay@ disp;
|
||||
void init() {
|
||||
@disp = EdictDisplay();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
disp.tick(time);
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiOverlay;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiText;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiSprite;
|
||||
import random_events;
|
||||
import util.formatting;
|
||||
import tabs.tabbar;
|
||||
|
||||
class Option : GuiButton {
|
||||
CurrentEvent@ event;
|
||||
const EventOption@ option;
|
||||
|
||||
GuiSprite@ icon;
|
||||
GuiMarkupText@ content;
|
||||
uint index;
|
||||
|
||||
Option(IGuiElement@ parent) {
|
||||
super(parent, recti());
|
||||
@icon = GuiSprite(this, Alignment(Left+4, Top+0.5f-30, Left+64, Top+0.5f+30));
|
||||
@content = GuiMarkupText(this, recti(68, 4, 100, 100));
|
||||
style = SS_ChoiceBox;
|
||||
}
|
||||
|
||||
int set(CurrentEvent@ evt, const EventOption@ option, int y, uint index) {
|
||||
@this.event = evt;
|
||||
@this.option = option;
|
||||
this.index = index;
|
||||
position = vec2i(4, y);
|
||||
size = vec2i(parent.size.width-8, size.height);
|
||||
@content.targets = evt.targets;
|
||||
content.size = vec2i(size.width - 72, content.size.height);
|
||||
content.text = option.text;
|
||||
icon.desc = option.icon;
|
||||
updateAbsolutePosition();
|
||||
size = vec2i(size.width, max(content.size.height + 12, 68));
|
||||
return size.height;
|
||||
}
|
||||
};
|
||||
|
||||
class EventOverlay : GuiOverlay {
|
||||
CurrentEvent event;
|
||||
GuiBackgroundPanel@ bg;
|
||||
GuiBackgroundPanel@ choices;
|
||||
|
||||
GuiPanel@ descPanel;
|
||||
GuiMarkupText@ description;
|
||||
|
||||
GuiPanel@ choicePanel;
|
||||
array<Option@> options;
|
||||
GuiProgressbar@ bar;
|
||||
|
||||
EventOverlay(IGuiElement@ parent, int eventId) {
|
||||
super(parent);
|
||||
|
||||
uint left = 500;
|
||||
uint right = 500;
|
||||
uint total = left + 12 + right;
|
||||
|
||||
@bg = GuiBackgroundPanel(this, Alignment(Left+0.5f-total/2, Top+0.5f-200, Left+0.5f-total/2+left, Top+0.5f+200));
|
||||
bg.titleColor = Color(0x00ff00ff);
|
||||
|
||||
@choices = GuiBackgroundPanel(this, Alignment(Left+0.5f-total/2+left+12, Top+0.5f-300, Left+0.5f+total/2, Top+0.5f+300));
|
||||
choices.title = locale::ANOMALY_CHOICES;
|
||||
choices.titleColor = Color(0xff8000ff);
|
||||
|
||||
@descPanel = GuiPanel(bg, Alignment(Left+4, Top+36, Left+left-4, Bottom-8));
|
||||
|
||||
@description = GuiMarkupText(descPanel, recti_area(4, 0, left-8, 100));
|
||||
description.fitWidth = true;
|
||||
|
||||
@choicePanel = GuiPanel(choices, Alignment(Left, Top+38, Right, Bottom-34));
|
||||
|
||||
@bar = GuiProgressbar(choices, Alignment(Left+12, Bottom-34, Right-12, Bottom-4));
|
||||
bar.frontColor = Color(0xf4b62bff);
|
||||
|
||||
closeSelf = false;
|
||||
updateAbsolutePosition();
|
||||
update();
|
||||
bringToFront();
|
||||
|
||||
overlays.insertLast(this);
|
||||
|
||||
if(!receive(playerEmpire.getEvent(eventId), event))
|
||||
close();
|
||||
else
|
||||
update();
|
||||
}
|
||||
|
||||
void remove() {
|
||||
overlays.remove(this);
|
||||
GuiOverlay::remove();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
{
|
||||
Option@ opt = cast<Option>(evt.caller);
|
||||
if(opt !is null) {
|
||||
playerEmpire.chooseEventOption(event.id, opt.option.id);
|
||||
autoOpen = 1.0;
|
||||
timer = 0.05f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return GuiOverlay::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
float timer = 0.f;
|
||||
void update() {
|
||||
if(event.type is null)
|
||||
return;
|
||||
timer -= frameLength;
|
||||
if(timer <= 0.f) {
|
||||
if(playerEmpire.currentEventID != event.id) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if(!receive(playerEmpire.getEvent(event.id), event)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
description.text = event.type.text;
|
||||
@description.targets = event.targets;
|
||||
bg.title = event.type.name;
|
||||
|
||||
bar.visible = event.timer > 0;
|
||||
if(bar.visible) {
|
||||
if(event.type.timer > 0)
|
||||
bar.progress = 1.f - (event.timer / event.type.timer);
|
||||
else
|
||||
bar.progress = 0.f;
|
||||
bar.text = formatTime(event.timer);
|
||||
}
|
||||
|
||||
uint optCount = event.options.length;
|
||||
uint oldCnt = options.length;
|
||||
for(uint i = optCount; i < oldCnt; ++i)
|
||||
options[i].remove();
|
||||
options.length = optCount;
|
||||
int y = 0;
|
||||
for(uint i = 0; i < optCount; ++i) {
|
||||
auto@ optType = event.options[i];
|
||||
|
||||
if(options[i] is null)
|
||||
@options[i] = Option(choicePanel);
|
||||
y += options[i].set(event, optType, y, i) + 8;
|
||||
}
|
||||
updateAbsolutePosition();
|
||||
timer += 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
GuiOverlay::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
update();
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
GuiButton@ eventButton;
|
||||
|
||||
double autoOpen = 0.0;
|
||||
array<EventOverlay@> overlays;
|
||||
void tick(double time) {
|
||||
for(uint i = 0, cnt = overlays.length; i < cnt; ++i)
|
||||
overlays[i].update();
|
||||
|
||||
eventButton.visible = playerEmpire.hasCurrentEvents();
|
||||
eventButton.pressed = overlays.length != 0;
|
||||
|
||||
if(autoOpen > 0) {
|
||||
if(overlays.length == 0 && eventButton.visible)
|
||||
EventOverlay(ActiveTab, playerEmpire.currentEventID);
|
||||
autoOpen -= time;
|
||||
}
|
||||
}
|
||||
|
||||
class OpenEvent : onButtonClick {
|
||||
bool onClick(GuiButton@ btn) {
|
||||
for(uint i = 0, cnt = overlays.length; i < cnt; ++i) {
|
||||
if(overlays[i].isChildOf(ActiveTab)) {
|
||||
overlays[i].close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
EventOverlay(ActiveTab, playerEmpire.currentEventID);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void init() {
|
||||
@eventButton = GuiButton(null, Alignment(Left+0.5f-120, Top+TAB_HEIGHT+GLOBAL_BAR_HEIGHT, Width=240, Height=40), "Event");
|
||||
@eventButton.onClick = OpenEvent();
|
||||
eventButton.font = FT_Bold;
|
||||
eventButton.visible = false;
|
||||
eventButton.toggleButton = true;
|
||||
}
|
||||
@@ -0,0 +1,659 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiButton;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiContextMenu;
|
||||
import abilities;
|
||||
import tabs.Tab;
|
||||
import util.formatting;
|
||||
import targeting.ObjectTarget;
|
||||
import targeting.PointTarget;
|
||||
import ftl;
|
||||
import icons;
|
||||
import systems;
|
||||
import ship_groups;
|
||||
from obj_selection import selectObject, selectedObjects;
|
||||
from targeting.Hyperdrive import targetHyperdrive;
|
||||
from targeting.Jumpdrive import targetJumpdrive;
|
||||
from targeting.Fling import targetFling;
|
||||
from targeting.Slipstream import targetSlipstream;
|
||||
|
||||
import InfoBar@ makeOrbitalInfoBar(IGuiElement@ parent, Object@ obj) from "overlays.OrbitalInfoBar";
|
||||
import InfoBar@ makePlanetInfoBar(IGuiElement@ parent, Object@ obj) from "overlays.PlanetInfoBar";
|
||||
import InfoBar@ makeShipInfoBar(IGuiElement@ parent, Object@ obj) from "overlays.ShipInfoBar";
|
||||
import InfoBar@ makeAsteroidInfoBar(IGuiElement@ parent, Object@ obj) from "overlays.AsteroidInfoBar";
|
||||
import InfoBar@ makeArtifactInfoBar(IGuiElement@ parent, Object@ obj) from "overlays.ArtifactInfoBar";
|
||||
import void toggleSupportOverlay(Object@ obj) from "tabs.GalaxyTab";
|
||||
import void openOverlay(Object@ obj) from "tabs.GalaxyTab";
|
||||
|
||||
export InfoBar, createInfoBar;
|
||||
export BarAction, ActionBar;
|
||||
|
||||
class InfoBar : BaseGuiElement {
|
||||
InfoBar(IGuiElement@ parent) {
|
||||
super(parent, Alignment(Left+0.1f, Bottom-68, Right-0.1f, Bottom));
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void set(Object@ obj) {
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) {
|
||||
return get() is obj;
|
||||
}
|
||||
|
||||
void update(double time) {
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_showingManage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
IGuiElement@ findTab() {
|
||||
IGuiElement@ check = parent;
|
||||
while(check !is null && cast<Tab>(check) is null)
|
||||
@check = check.parent;
|
||||
return check;
|
||||
}
|
||||
};
|
||||
|
||||
const int BTN_SIZE = 40;
|
||||
const int BTN_PADD = 12;
|
||||
const int BTN_SPACE = 12;
|
||||
class BarAction : GuiButton {
|
||||
Object@ obj;
|
||||
Sprite icon;
|
||||
|
||||
BarAction() {
|
||||
super(NoParent=true);
|
||||
}
|
||||
|
||||
int get_needWidth() {
|
||||
return BTN_SIZE;
|
||||
}
|
||||
|
||||
void set_tooltip(const string& text) override {
|
||||
setMarkupTooltip(this, text, width=400, hoverStyle=true);
|
||||
}
|
||||
|
||||
void update(double time) {
|
||||
}
|
||||
|
||||
bool opEquals(const BarAction& other) const {
|
||||
return getClass(this) is getClass(other);
|
||||
}
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
void postInit() {
|
||||
}
|
||||
|
||||
void call() {
|
||||
}
|
||||
|
||||
void from(BarAction@ act) {
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override{
|
||||
if(evt.type == GUI_Clicked) {
|
||||
call();
|
||||
return true;
|
||||
}
|
||||
return GuiButton::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
GuiButton::draw();
|
||||
icon.draw(AbsolutePosition.padded(4));
|
||||
}
|
||||
};
|
||||
|
||||
funcdef void TrivialCB();
|
||||
class TrivialAction : BarAction {
|
||||
TrivialCB@ cb;
|
||||
bool doSelect;
|
||||
|
||||
TrivialAction(TrivialCB@ cb, const string& text, const Sprite& icon, bool doSelect = true) {
|
||||
super();
|
||||
@this.cb = cb;
|
||||
this.tooltip = text;
|
||||
this.icon = icon;
|
||||
this.doSelect = doSelect;
|
||||
}
|
||||
|
||||
void call() {
|
||||
if(doSelect && !obj.selected)
|
||||
selectObject(obj);
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
class AbilityAction : BarAction {
|
||||
Ability@ abl;
|
||||
string str;
|
||||
Object@ objCast;
|
||||
bool expanded = false;
|
||||
bool independent = false;
|
||||
|
||||
int get_needWidth() {
|
||||
return expanded ? 160 : BTN_SIZE;
|
||||
}
|
||||
|
||||
AbilityAction(Ability@ abl, const string& opt, Object@ objCast = null, bool expanded = false) {
|
||||
@this.abl = abl;
|
||||
@this.objCast = objCast;
|
||||
this.expanded = expanded;
|
||||
@abl.emp = playerEmpire;
|
||||
str = opt;
|
||||
}
|
||||
|
||||
void init() override {
|
||||
tooltip = abl.formatTooltip();
|
||||
|
||||
bool usable = true;
|
||||
if(abl.cooldown > 0)
|
||||
usable = false;
|
||||
if(!abl.canActivate())
|
||||
usable = false;
|
||||
|
||||
if(usable) {
|
||||
double cost = abl.getEnergyCost();
|
||||
if(cost > 0) {
|
||||
double have = abl.emp.EnergyStored;
|
||||
if(cost > have)
|
||||
usable = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(abl.obj !is null && abl.obj.isArtifact) {
|
||||
auto@ reg = abl.obj.region;
|
||||
if(reg is null)
|
||||
usable = false;
|
||||
else if(reg.PlanetsMask != 0)
|
||||
usable = usable ? (reg.PlanetsMask & playerEmpire.mask != 0) : false;
|
||||
else
|
||||
usable = usable ? hasTradeAdjacent(playerEmpire, reg) : false;
|
||||
}
|
||||
|
||||
disabled = !usable;
|
||||
|
||||
if(expanded || independent) {
|
||||
if(disabled)
|
||||
color = colors::Red;
|
||||
else
|
||||
color = colors::Energy;
|
||||
}
|
||||
else
|
||||
color = colors::White;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
if(abl.type.targets.length == 0) {
|
||||
if(abl.obj !is null)
|
||||
abl.obj.activateAbility(abl.id);
|
||||
else
|
||||
abl.emp.activateAbility(abl.id);
|
||||
if(abl.type.activateSound !is null)
|
||||
abl.type.activateSound.play(priority=true);
|
||||
}
|
||||
else if(abl.type.targets[0].type == TT_Point) {
|
||||
targetPoint(AbilityTargetPoint(abl));
|
||||
}
|
||||
else if(abl.type.targets[0].type == TT_Object) {
|
||||
if(objCast !is null) {
|
||||
abl.emp.activateAbility(abl.id, objCast);
|
||||
}
|
||||
else {
|
||||
targetObject(AbilityTargetObject(abl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void from(BarAction@ act) override {
|
||||
@abl = cast<AbilityAction>(act).abl;
|
||||
str = cast<AbilityAction>(act).str;
|
||||
expanded = cast<AbilityAction>(act).expanded;
|
||||
init();
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
GuiButton::draw();
|
||||
const Font@ ft = skin.getFont(FT_Small);
|
||||
recti pos = AbsolutePosition.padded(4);
|
||||
if(expanded || independent)
|
||||
pos = recti_area(vec2i(4,4) + AbsolutePosition.topLeft,
|
||||
vec2i(AbsolutePosition.height-4, AbsolutePosition.height-4));
|
||||
if(abl.cooldown <= 0) {
|
||||
abl.type.icon.draw(pos.aspectAligned(abl.type.icon.aspect));
|
||||
}
|
||||
else {
|
||||
if(abl.cooldown > 0) {
|
||||
if(abl.type.cooldown == 0)
|
||||
shader::PROGRESS = 1.f - clamp(abl.cooldown / abl.type.cooldown, 0.f, 1.f);
|
||||
else
|
||||
shader::PROGRESS = 0.f;
|
||||
shader::DIM_FACTOR = 0.2f;
|
||||
abl.type.icon.draw(pos.aspectAligned(abl.type.icon.aspect), color=colors::White, shader=shader::RadialDimmed);
|
||||
ft.draw(pos=pos, text=formatShortTime(abl.cooldown), color=colors::Red, horizAlign=0.5, vertAlign=1.0);
|
||||
}
|
||||
else if(abl.type.cooldown > 0) {
|
||||
abl.type.icon.draw(pos.aspectAligned(abl.type.icon.aspect));
|
||||
ft.draw(pos=pos, text=formatShortTime(abl.type.cooldown), color=colors::Green, horizAlign=0.5, vertAlign=1.0);
|
||||
}
|
||||
}
|
||||
|
||||
if(expanded) {
|
||||
pos = recti_area(vec2i(AbsolutePosition.topLeft.x+AbsolutePosition.height, AbsolutePosition.topLeft.y+2),
|
||||
vec2i(AbsolutePosition.width-AbsolutePosition.height, AbsolutePosition.height-4));
|
||||
|
||||
auto cost = abl.getEnergyCost();
|
||||
|
||||
if(cost <= 0) {
|
||||
@ft = skin.getFont(FT_Bold);
|
||||
ft.draw(pos=pos, horizAlign=0.0, vertAlign=0.1, text=abl.type.name);
|
||||
}
|
||||
else {
|
||||
@ft = skin.getFont(FT_Bold);
|
||||
ft.draw(pos=pos, horizAlign=0.0, vertAlign=0.1, text=locale::ACTIVATE);
|
||||
|
||||
string txt = format("$1 $2", toString(cost, 0), locale::RESOURCE_ENERGY);
|
||||
ft.draw(pos=pos, horizAlign=0.5, vertAlign=0.85, text=txt, color=colors::Energy);
|
||||
}
|
||||
}
|
||||
else if(independent) {
|
||||
pos = recti_area(vec2i(AbsolutePosition.topLeft.x+AbsolutePosition.height, AbsolutePosition.topLeft.y+2),
|
||||
vec2i(AbsolutePosition.width-AbsolutePosition.height, AbsolutePosition.height-4));
|
||||
|
||||
@ft = skin.getFont(FT_Bold);
|
||||
ft.draw(pos=pos, horizAlign=0.5, vertAlign=0.5, text=abl.type.name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SupportsAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::ManageSupports;
|
||||
tooltip = locale::TT_MANAGE_PLANET_SUPPORTS;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
selectObject(obj);
|
||||
toggleSupportOverlay(obj);
|
||||
}
|
||||
};
|
||||
|
||||
class ConstructionAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::Labor;
|
||||
tooltip = locale::TT_OPEN_CONSTRUCTION;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
selectObject(obj);
|
||||
openOverlay(obj);
|
||||
}
|
||||
};
|
||||
|
||||
class ScoutAction : BarAction {
|
||||
bool useFTL = false;
|
||||
|
||||
ScoutAction(bool ftl) {
|
||||
useFTL = ftl;
|
||||
}
|
||||
|
||||
void init() override {
|
||||
if(useFTL) {
|
||||
icon = icons::HyperExplore;
|
||||
tooltip = locale::TT_EXPLORE_FTL;
|
||||
}
|
||||
else {
|
||||
icon = icons::Explore;
|
||||
tooltip = locale::TT_EXPLORE;
|
||||
}
|
||||
}
|
||||
|
||||
void call() override {
|
||||
obj.addAutoExploreOrder(useFTL, shiftKey);
|
||||
}
|
||||
};
|
||||
|
||||
class ModeAction : BarAction {
|
||||
uint mode = 0;
|
||||
array<string> names;
|
||||
array<string> descriptions;
|
||||
array<Sprite> icons;
|
||||
|
||||
void init() override {
|
||||
value = get();
|
||||
}
|
||||
|
||||
void set_value(uint v) {
|
||||
mode = min(v, names.length-1);
|
||||
icon = icons[mode];
|
||||
tooltip = format("[img=$1;42][font=Subtitle][b]$2[/b][/font]\n$3[/img]",
|
||||
getSpriteDesc(icons[mode]), names[mode], descriptions[mode]);
|
||||
}
|
||||
|
||||
void update(double time) {
|
||||
uint val = get();
|
||||
if(val != mode)
|
||||
this.value = val;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
GuiContextMenu menu(mousePos, 400);
|
||||
menu.itemHeight = 64;
|
||||
|
||||
for(uint i = 0, cnt = names.length; i < cnt; ++i) {
|
||||
string text = format("[font=Subtitle][b]$1[/b][/font]\n$2",
|
||||
names[i], descriptions[i]);
|
||||
menu.addOption(ModeOption(this), text, icons[i], i);
|
||||
}
|
||||
|
||||
menu.finalize();
|
||||
}
|
||||
|
||||
void call(uint type) {
|
||||
value = type;
|
||||
set(type);
|
||||
for(uint i = 0, cnt = selectedObjects.length; i < cnt; ++i) {
|
||||
Object@ other = selectedObjects[i];
|
||||
if(other !is obj)
|
||||
setSecondary(other, type);
|
||||
}
|
||||
}
|
||||
|
||||
uint get() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set(uint type) {
|
||||
set(obj, type);
|
||||
}
|
||||
|
||||
void set(Object& obj, uint type) {
|
||||
}
|
||||
|
||||
void setSecondary(Object& obj, uint type) {
|
||||
set(obj, type);
|
||||
}
|
||||
};
|
||||
|
||||
class ModeOption : GuiMarkupContextOption {
|
||||
ModeAction@ act;
|
||||
ModeOption(ModeAction@ act) {
|
||||
@this.act = act;
|
||||
}
|
||||
|
||||
void call(GuiContextMenu@ menu) override {
|
||||
act.call(value);
|
||||
}
|
||||
};
|
||||
|
||||
class AutoModeAction : ModeAction {
|
||||
AutoModeAction() {
|
||||
names.insertLast(locale::HOLD_POSITION);
|
||||
descriptions.insertLast(locale::HOLD_POSITION_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+12);
|
||||
|
||||
names.insertLast(locale::AREA_BOUND);
|
||||
descriptions.insertLast(locale::AREA_BOUND_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+13);
|
||||
|
||||
names.insertLast(locale::REGION_BOUND);
|
||||
descriptions.insertLast(locale::REGION_BOUND_DESC);
|
||||
icons.insertLast((spritesheet::ActionBarIcons+13)*Color(0xff8080ff));
|
||||
|
||||
names.insertLast(locale::HOLD_FIRE);
|
||||
descriptions.insertLast(locale::HOLD_FIRE_DESC);
|
||||
icons.insertLast(Sprite(material::Minus));
|
||||
}
|
||||
|
||||
uint get() override {
|
||||
switch(obj.getAutoMode()) {
|
||||
case AM_HoldPosition: return 0;
|
||||
case AM_AreaBound: return 1;
|
||||
case AM_RegionBound: return 2;
|
||||
case AM_HoldFire: return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set(Object& obj, uint type) override {
|
||||
uint autoMode = AM_AreaBound;
|
||||
switch(type) {
|
||||
case 0: autoMode = AM_HoldPosition; break;
|
||||
case 1: autoMode = AM_AreaBound; break;
|
||||
case 2: autoMode = AM_RegionBound; break;
|
||||
case 3: autoMode = AM_HoldFire; break;
|
||||
}
|
||||
obj.setAutoMode(autoMode);
|
||||
}
|
||||
};
|
||||
|
||||
class EngageBehaveAction : ModeAction {
|
||||
EngageBehaveAction() {
|
||||
names.insertLast(locale::BEH_CLOSE_IN);
|
||||
descriptions.insertLast(locale::BEH_CLOSE_IN_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+16);
|
||||
|
||||
names.insertLast(locale::BEH_KEEP_DISTANCE);
|
||||
descriptions.insertLast(locale::BEH_KEEP_DISTANCE_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+17);
|
||||
}
|
||||
|
||||
uint get() override {
|
||||
return obj.getEngageBehave();
|
||||
}
|
||||
|
||||
void set(Object& obj, uint type) override {
|
||||
obj.setEngageBehave(type);
|
||||
}
|
||||
};
|
||||
|
||||
class EngageTypeAction : ModeAction {
|
||||
EngageTypeAction() {
|
||||
names.insertLast(locale::ENG_FLAGSHIP_MIN);
|
||||
descriptions.insertLast(locale::ENG_FLAGSHIP_MIN_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+20);
|
||||
|
||||
names.insertLast(locale::ENG_FLAGSHIP_MAX);
|
||||
descriptions.insertLast(locale::ENG_FLAGSHIP_MAX_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+21);
|
||||
|
||||
names.insertLast(locale::ENG_SUPPORT_MIN);
|
||||
descriptions.insertLast(locale::ENG_SUPPORT_MIN_DESC);
|
||||
icons.insertLast(spritesheet::ActionBarIcons+22);
|
||||
|
||||
names.insertLast(locale::ENG_RAIDING_ONLY);
|
||||
descriptions.insertLast(locale::ENG_RAIDING_ONLY_DESC);
|
||||
icons.insertLast(Sprite(spritesheet::ActionBarIcons, 22, Color(0xff0000ff)));
|
||||
}
|
||||
|
||||
uint get() override {
|
||||
return obj.getEngageType();
|
||||
}
|
||||
|
||||
void set(Object& obj, uint type) override {
|
||||
obj.setEngageType(type);
|
||||
}
|
||||
};
|
||||
|
||||
class ActionBar : BaseGuiElement {
|
||||
array<BarAction@> actions;
|
||||
uint index = 0;
|
||||
|
||||
ActionBar(IGuiElement@ bar, vec2i pos) {
|
||||
super(bar, recti_area(pos, vec2i(100, BTN_SIZE+BTN_PADD*2)));
|
||||
}
|
||||
|
||||
void clear() {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
void add(BarAction@ act) {
|
||||
if(index >= actions.length) {
|
||||
@act.parent = this;
|
||||
actions.insertLast(act);
|
||||
}
|
||||
else {
|
||||
if(act != actions[index]) {
|
||||
actions[index].remove();
|
||||
@act.parent = this;
|
||||
@actions[index] = act;
|
||||
}
|
||||
else {
|
||||
actions[index].from(act);
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
void init(Object@ obj) {
|
||||
for(uint i = index, cnt = actions.length; i < cnt; ++i)
|
||||
actions[i].remove();
|
||||
|
||||
actions.length = index;
|
||||
for(uint i = 0, cnt = actions.length; i < cnt; ++i) {
|
||||
@actions[i].obj = obj;
|
||||
actions[i].init();
|
||||
actions[i].postInit();
|
||||
}
|
||||
visible = actions.length != 0;
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void update(double time) {
|
||||
for(uint i = 0, cnt = actions.length; i < cnt; ++i)
|
||||
actions[i].update(time);
|
||||
}
|
||||
|
||||
void addBasic(Object@ obj) {
|
||||
if(obj.hasLeaderAI) {
|
||||
if(obj.SupplyCapacity > 0)
|
||||
add(SupportsAction());
|
||||
if(obj.hasMover && !obj.hasOrbit) {
|
||||
add(AutoModeAction());
|
||||
add(EngageBehaveAction());
|
||||
add(EngageTypeAction());
|
||||
}
|
||||
if(!obj.isPlanet && obj.hasConstruction)
|
||||
add(ConstructionAction());
|
||||
}
|
||||
}
|
||||
|
||||
void addScouting(Object@ obj) {
|
||||
if(obj.hasLeaderAI && obj.getFleetMaxStrength() < 5000.0 && obj.owner.ForbidDeepSpace == 0) {
|
||||
add(ScoutAction(ftl=false));
|
||||
if(obj.owner.hasFlingBeacons || canHyperdrive(obj) || canJumpdrive(obj))
|
||||
add(ScoutAction(ftl=true));
|
||||
}
|
||||
}
|
||||
|
||||
void addAbilities(Object@ obj, bool expanded = false) {
|
||||
if(!obj.hasAbilities)
|
||||
return;
|
||||
|
||||
array<Ability> abilities;
|
||||
abilities.syncFrom(obj.getAbilities());
|
||||
|
||||
for(uint i = 0, cnt = abilities.length; i < cnt; ++i) {
|
||||
Ability@ abl = abilities[i];
|
||||
if(abl.disabled)
|
||||
continue;
|
||||
|
||||
string option = format(locale::ABILITY_TRIGGER, abl.type.name);
|
||||
double cost = abl.getEnergyCost();
|
||||
if(cost > 0)
|
||||
option += format(locale::ABILITY_ENERGY, standardize(cost));
|
||||
|
||||
add(AbilityAction(abl, option, expanded=expanded));
|
||||
}
|
||||
}
|
||||
|
||||
void addEmpireAbilities(Empire@ emp, Object@ obj) {
|
||||
array<Ability> abilities;
|
||||
abilities.syncFrom(emp.getAbilities());
|
||||
|
||||
Targets targs;
|
||||
@targs.add(TT_Object, fill=true).obj = obj;
|
||||
|
||||
for(uint i = 0, cnt = abilities.length; i < cnt; ++i) {
|
||||
Ability@ abl = abilities[i];
|
||||
if(abl.disabled)
|
||||
continue;
|
||||
if(obj is null) {
|
||||
if(abl.type.objectCast != -1)
|
||||
continue;
|
||||
if(abl.type.hideGlobal)
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if(abl.type.objectCast == -1)
|
||||
continue;
|
||||
if(!abl.canActivate(targs, ignoreCost=true))
|
||||
continue;
|
||||
}
|
||||
|
||||
string option = format(locale::ABILITY_TRIGGER, abl.type.name);
|
||||
double cost = abl.getEnergyCost();
|
||||
if(cost > 0)
|
||||
option += format(locale::ABILITY_ENERGY, standardize(cost));
|
||||
|
||||
add(AbilityAction(abl, option, obj));
|
||||
}
|
||||
}
|
||||
|
||||
void addFTL(Object@ obj) {
|
||||
if(canHyperdrive(obj))
|
||||
add(TrivialAction(targetHyperdrive, locale::TT_HYPERDRIVE, icons::Hyperdrive));
|
||||
if(canJumpdrive(obj))
|
||||
add(TrivialAction(targetJumpdrive, locale::TT_JUMPDRIVE, icons::Hyperdrive));
|
||||
if(canFling(obj) && obj.owner.getFlingBeacon(obj.position) !is null)
|
||||
add(TrivialAction(targetFling, locale::TT_FLING, icons::Fling));
|
||||
if(canSlipstream(obj))
|
||||
add(TrivialAction(targetSlipstream, locale::TT_SLIPSTREAM, icons::Slipstream));
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() override {
|
||||
int w = BTN_PADD;
|
||||
for(uint i = 0, cnt = actions.length; i < cnt; ++i) {
|
||||
if(i != 0)
|
||||
w += BTN_SPACE;
|
||||
int size = actions[i].needWidth;
|
||||
actions[i].size = vec2i(size, BTN_SIZE);
|
||||
actions[i].position = vec2i(w, 8);
|
||||
w += size;
|
||||
}
|
||||
|
||||
w += BTN_PADD;
|
||||
size = vec2i(w, BTN_SIZE + BTN_PADD*2);
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ createInfoBar(IGuiElement@ parent, Object& obj) {
|
||||
if(obj.isPlanet)
|
||||
return makePlanetInfoBar(parent, obj);
|
||||
if(obj.isShip)
|
||||
return makeShipInfoBar(parent, obj);
|
||||
if(obj.isOrbital)
|
||||
return makeOrbitalInfoBar(parent, obj);
|
||||
if(obj.isAsteroid)
|
||||
return makeAsteroidInfoBar(parent, obj);
|
||||
if(obj.isArtifact)
|
||||
return makeArtifactInfoBar(parent, obj);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class ObjectPopup : Popup {
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
Object@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
ObjectPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(150, 110);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+25, Right-4, Top+95));
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return obj is Obj;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = Obj;
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = SS_GenericPopupBG;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
Color col;
|
||||
if(obj.isStar) {
|
||||
Region@ reg = obj.region;
|
||||
if(reg !is null) {
|
||||
Empire@ other = reg.visiblePrimaryEmpire;
|
||||
if(other !is null)
|
||||
col = other.color;
|
||||
}
|
||||
}
|
||||
else if(obj.owner !is null)
|
||||
col = obj.owner.color;
|
||||
|
||||
skin.draw(style, flags, bgPos, col);
|
||||
if(obj.owner !is null && obj.owner.flag !is null) {
|
||||
obj.owner.flag.draw(
|
||||
objView.absolutePosition.aspectAligned(1.0, horizAlign=1.0, vertAlign=1.0),
|
||||
obj.owner.color * Color(0xffffff30));
|
||||
}
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,129 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import util.formatting;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class OddityPopup : Popup {
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
Object@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
GuiText@ timerBox;
|
||||
|
||||
OddityPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(150, 110);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+25, Right-4, Top+95));
|
||||
@timerBox = GuiText(this, Alignment(Left+10, Top+10, Right-10, Bottom-10));
|
||||
timerBox.horizAlign = 1.0;
|
||||
timerBox.vertAlign = 1.0;
|
||||
timerBox.visible = false;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isOddity;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = Obj;
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = SS_GenericPopupBG;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
Color col;
|
||||
if(obj.isStar) {
|
||||
Region@ reg = obj.region;
|
||||
if(reg !is null) {
|
||||
Empire@ other = reg.visiblePrimaryEmpire;
|
||||
if(other !is null)
|
||||
col = other.color;
|
||||
}
|
||||
}
|
||||
else if(obj.owner !is null)
|
||||
col = obj.owner.color;
|
||||
|
||||
skin.draw(style, flags, bgPos, col);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
//Update timer
|
||||
Oddity@ odd = cast<Oddity>(obj);
|
||||
if(odd !is null) {
|
||||
double timer = odd.getTimer();
|
||||
if(timer <= 0.0) {
|
||||
timerBox.visible = false;
|
||||
}
|
||||
else {
|
||||
timerBox.visible = true;
|
||||
timerBox.text = formatTime(timer);
|
||||
}
|
||||
}
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,265 @@
|
||||
import overlays.InfoBar;
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiResources;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiGroupDisplay;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiIconGrid;
|
||||
import elements.MarkupTooltip;
|
||||
import ship_groups;
|
||||
import orbitals;
|
||||
import util.formatting;
|
||||
import icons;
|
||||
from overlays.ContextMenu import openContextMenu, FinanceDryDock;
|
||||
from overlays.Construction import ConstructionOverlay;
|
||||
from obj_selection import isSelected, selectObject, clearSelection, addToSelection, selectedObject;
|
||||
from tabs.GalaxyTab import zoomTabTo, openOverlay;
|
||||
|
||||
class ModuleGrid : GuiIconGrid {
|
||||
array<OrbitalSection> sections;
|
||||
|
||||
ModuleGrid(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
}
|
||||
|
||||
uint get_length() override {
|
||||
return sections.length;
|
||||
}
|
||||
|
||||
void drawElement(uint index, const recti& pos) override {
|
||||
sections[index].type.icon.draw(pos);
|
||||
}
|
||||
|
||||
string get_tooltip() override {
|
||||
if(hovered < 0 || hovered >= int(length))
|
||||
return "";
|
||||
return sections[hovered].type.getTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
class OrbitalInfoBar : InfoBar {
|
||||
Orbital@ obj;
|
||||
Gui3DObject@ objView;
|
||||
ConstructionOverlay@ overlay;
|
||||
|
||||
GuiSkinElement@ nameBox;
|
||||
GuiText@ name;
|
||||
|
||||
GuiSkinElement@ moduleBox;
|
||||
GuiMarkupText@ moduleText;
|
||||
GuiSprite@ moduleIcon;
|
||||
|
||||
ActionBar@ actions;
|
||||
|
||||
OrbitalInfoBar(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
@alignment = Alignment(Left, Bottom-228, Left+395, Bottom);
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(
|
||||
Left-0.5f, Top, Right+0.15f, Bottom));
|
||||
|
||||
@actions = ActionBar(this, vec2i(305, 172));
|
||||
actions.noClip = true;
|
||||
|
||||
int y = 90;
|
||||
@nameBox = GuiSkinElement(this, Alignment(Left+12, Top+y, Left+256, Top+y+34), SS_PlainOverlay);
|
||||
@name = GuiText(nameBox, Alignment().padded(8, 0, 30, 0));
|
||||
name.font = FT_Medium;
|
||||
@moduleIcon = GuiSprite(nameBox, Alignment(Right-30, Top, Right, Bottom));
|
||||
|
||||
y += 40;
|
||||
@moduleBox = GuiSkinElement(this, Alignment(Left+12, Top+y, Left+256, Top+y+94), SS_PlainOverlay);
|
||||
@moduleText = GuiMarkupText(moduleBox, Alignment().padded(6, 3, 6, 0));
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
actions.clear();
|
||||
|
||||
if(obj.owner is playerEmpire) {
|
||||
auto@ core = getOrbitalModule(obj.coreModule);
|
||||
if(!core.isStandalone)
|
||||
actions.add(ManageAction());
|
||||
if(obj.getDesign(OV_PackUp) !is null)
|
||||
actions.add(PackUpAction());
|
||||
actions.addBasic(obj);
|
||||
actions.addFTL(obj);
|
||||
actions.addAbilities(obj);
|
||||
actions.addEmpireAbilities(playerEmpire, obj);
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
actions.init(obj);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(actions.visible) {
|
||||
recti pos = actions.absolutePosition;
|
||||
skin.draw(SS_Panel, SF_Normal, recti(vec2i(-5, pos.topLeft.y), pos.botRight + vec2i(0, 20)));
|
||||
}
|
||||
InfoBar::draw();
|
||||
}
|
||||
|
||||
void remove() override {
|
||||
if(overlay !is null)
|
||||
overlay.remove();
|
||||
InfoBar::remove();
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) override {
|
||||
return obj.isOrbital;
|
||||
}
|
||||
|
||||
Object@ get() override {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void set(Object@ obj) override {
|
||||
@this.obj = cast<Orbital>(obj);
|
||||
@objView.object = obj;
|
||||
updateTimer = 0.0;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) override {
|
||||
if(obj is this.obj)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) override {
|
||||
if(overlay !is null)
|
||||
overlay.remove();
|
||||
if(cast<Orbital>(obj).getDesign(OV_DRY_Design) !is null) {
|
||||
FinanceDryDock(obj);
|
||||
return false;
|
||||
}
|
||||
if(obj.hasConstruction) {
|
||||
@overlay = ConstructionOverlay(findTab(), obj);
|
||||
visible = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double updateTimer = 1.0;
|
||||
void update(double time) override {
|
||||
if(overlay !is null) {
|
||||
if(overlay.parent is null) {
|
||||
@overlay = null;
|
||||
visible = true;
|
||||
}
|
||||
else
|
||||
overlay.update(time);
|
||||
}
|
||||
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateTimer = randomd(0.1,0.9);
|
||||
Empire@ owner = obj.owner;
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(obj.isDisabled)
|
||||
name.color = colors::Red;
|
||||
else if(owner !is null)
|
||||
name.color = owner.color;
|
||||
else
|
||||
name.color = colors::White;
|
||||
|
||||
const Font@ ft = skin.getFont(FT_Medium);
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Bold;
|
||||
else
|
||||
name.font = FT_Medium;
|
||||
|
||||
//Update description
|
||||
auto@ core = getOrbitalModule(obj.coreModule);
|
||||
if(core !is null) {
|
||||
moduleText.text = core.blurb;
|
||||
moduleIcon.desc = core.icon;
|
||||
setMarkupTooltip(moduleBox, format("[font=Medium]$1[/font]\n$2", core.name, core.description), width=350);
|
||||
setMarkupTooltip(nameBox, format("[font=Medium]$1[/font]\n$2", core.name, core.description), width=350);
|
||||
}
|
||||
|
||||
updateActions();
|
||||
}
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is this)
|
||||
return null;
|
||||
if(elem is objView) {
|
||||
int height = AbsolutePosition.size.height;
|
||||
vec2i origin(AbsolutePosition.topLeft.x, AbsolutePosition.botRight.y);
|
||||
origin.y += height;
|
||||
if(pos.distanceTo(origin) > height * 1.6)
|
||||
return null;
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
selectObject(obj, shiftKey);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
if(selectedObject is null)
|
||||
openContextMenu(obj, obj);
|
||||
else
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
zoomTabTo(obj);
|
||||
return true;
|
||||
case OA_DoubleClick:
|
||||
showManage(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return InfoBar::onGuiEvent(evt);
|
||||
}
|
||||
};
|
||||
|
||||
class ManageAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::Manage;
|
||||
tooltip = locale::TT_MANAGE_ORBITAL;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
selectObject(obj);
|
||||
openOverlay(obj);
|
||||
}
|
||||
};
|
||||
|
||||
class PackUpAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::Gate;
|
||||
tooltip = locale::TT_PACKUP_ORBITAL;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
cast<Orbital>(obj).sendValue(OV_PackUp);
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ makeOrbitalInfoBar(IGuiElement@ parent, Object@ obj) {
|
||||
OrbitalInfoBar bar(parent);
|
||||
bar.set(obj);
|
||||
return bar;
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiOverlay;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiResources;
|
||||
import elements.GuiIconGrid;
|
||||
import orbitals;
|
||||
import util.formatting;
|
||||
import icons;
|
||||
import buildings;
|
||||
import resources;
|
||||
import tile_resources;
|
||||
import overlays.Construction;
|
||||
from gui import animate_time;
|
||||
|
||||
const double ANIM1_TIME = 0.15;
|
||||
const double ANIM2_TIME = 0.001;
|
||||
const uint BORDER = 20;
|
||||
const uint WIDTH = 500;
|
||||
const uint R_HEIGHT = 256;
|
||||
|
||||
// {{{ Overlay
|
||||
class OrbitalOverlay : GuiOverlay, ConstructionParent {
|
||||
Gui3DObject@ objView;
|
||||
Orbital@ obj;
|
||||
bool closing = false;
|
||||
|
||||
ResourceDisplay@ resources;
|
||||
ModuleDisplay@ modules;
|
||||
ConstructionDisplay@ construction;
|
||||
|
||||
Alignment@ objTarget;
|
||||
|
||||
OrbitalRequirements reqs;
|
||||
array<OrbitalSection> sections;
|
||||
array<Resource> resList;
|
||||
|
||||
OrbitalOverlay(IGuiElement@ parent, Orbital@ Obj) {
|
||||
super(parent);
|
||||
fade.a = 0;
|
||||
@obj = Obj;
|
||||
|
||||
vec2i parSize = parent.size;
|
||||
@objView = Gui3DObject(this, recti_area(vec2i(-456, parSize.y-228), vec2i(912, 912)));
|
||||
objView.internalRotation = quaterniond_fromAxisAngle(vec3d(0.0, 0.0, 1.0), -0.25*pi);
|
||||
@objView.object = obj;
|
||||
|
||||
int plSize = parSize.x * 2;
|
||||
@objTarget = Alignment(Left+0.5f-plSize/2, Top+0.5f, Width=plSize, Height=plSize);
|
||||
recti targPos = objTarget.resolve(parSize);
|
||||
animate_time(objView, targPos, ANIM1_TIME);
|
||||
|
||||
updateAbsolutePosition();
|
||||
|
||||
vec2i origin = targPos.center;
|
||||
@resources = ResourceDisplay(this, origin, Alignment(Left+0.5f-BORDER/2-WIDTH,
|
||||
Top+BORDER, Left+0.5f-BORDER/2, Top+BORDER+R_HEIGHT));
|
||||
resources.visible = false;
|
||||
@modules = ModuleDisplay(this, origin, Alignment(Left+0.5f-BORDER/2-WIDTH,
|
||||
Top+BORDER, Left+0.5f-BORDER/2, Bottom-BORDER));
|
||||
|
||||
@construction = ConstructionDisplay(this, origin, Alignment(Right-0.5f+BORDER/2,
|
||||
Top+BORDER, Right-0.5f+BORDER/2+WIDTH, Bottom-BORDER));
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is objView)
|
||||
return this;
|
||||
return elem;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Animation_Complete:
|
||||
if(evt.caller is objView) {
|
||||
if(closing) {
|
||||
GuiOverlay::close();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Make sure the object view stays in the right position
|
||||
@objView.alignment = objTarget;
|
||||
|
||||
//Start showing all the data
|
||||
resources.animate();
|
||||
modules.animate();
|
||||
construction.animate();
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GUI_Confirmed:
|
||||
triggerUpdate();
|
||||
break;
|
||||
}
|
||||
return GuiOverlay::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& evt, IGuiElement@ source) override {
|
||||
return GuiOverlay::onMouseEvent(evt, source);
|
||||
}
|
||||
|
||||
void close() override {
|
||||
if(parent is null)
|
||||
return;
|
||||
closing = true;
|
||||
@objView.alignment = null;
|
||||
|
||||
modules.visible = false;
|
||||
resources.visible = false;
|
||||
construction.visible = false;
|
||||
|
||||
vec2i parSize = parent.size;
|
||||
recti targPos = recti_area(vec2i(-456, parSize.y-228), vec2i(912, 912));
|
||||
animate_time(objView, targPos, ANIM1_TIME);
|
||||
}
|
||||
|
||||
void startBuild(const BuildingType@ type) {
|
||||
}
|
||||
|
||||
Object@ get_object() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object@ get_slaved() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void updateData() {
|
||||
resList.syncFrom(obj.getAllResources());
|
||||
sections.syncFrom(obj.getSections());
|
||||
|
||||
reqs.init(resList);
|
||||
for(uint i = 0, cnt = sections.length; i < cnt; ++i) {
|
||||
if(sections[i].enabled)
|
||||
reqs.add(sections[i].type);
|
||||
}
|
||||
|
||||
for(uint i = 0, cnt = construction.modulesList.items.length; i < cnt; ++i) {
|
||||
GuiListbox@ list = cast<GuiListbox>(construction.modulesList.items[i]);
|
||||
for(uint n = 0, ncnt = list.itemCount; n < ncnt; ++n) {
|
||||
auto@ item = cast<BuildElement>(list.getItemElement(n));
|
||||
if(item !is null && item.orb !is null) {
|
||||
item.incomplete = !reqs.check(item.orb);
|
||||
item.update(construction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double updateTimer = 0.0;
|
||||
void update(double time) {
|
||||
construction.update(time);
|
||||
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0 || construction.longTimer == 5.0) {
|
||||
updateData();
|
||||
updateTimer = 1.0;
|
||||
}
|
||||
|
||||
resources.update(time);
|
||||
modules.update(time);
|
||||
}
|
||||
|
||||
void triggerUpdate() {
|
||||
updateData();
|
||||
updateTimer = 0.0;
|
||||
resources.updateTimer = 0.0;
|
||||
modules.updateTimer = 0.0;
|
||||
construction.updateTimer = 0.0;
|
||||
construction.longTimer = 0.0;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(!settings::bGalaxyBG && objView.Alignment !is null)
|
||||
material::Skybox.draw(AbsolutePosition);
|
||||
GuiOverlay::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class DisplayBox : BaseGuiElement {
|
||||
OrbitalOverlay@ overlay;
|
||||
Alignment@ targetAlign;
|
||||
|
||||
DisplayBox(OrbitalOverlay@ ov, vec2i origin, Alignment@ target) {
|
||||
@overlay = ov;
|
||||
@targetAlign = target;
|
||||
super(overlay, recti_area(origin, vec2i(1,1)));
|
||||
visible = false;
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void animate() {
|
||||
visible = true;
|
||||
animate_time(this, targetAlign.resolve(overlay.size), ANIM2_TIME);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Animation_Complete:
|
||||
@alignment = targetAlign;
|
||||
return true;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& evt, IGuiElement@ source) override {
|
||||
switch(evt.type) {
|
||||
case MET_Button_Down:
|
||||
if(evt.button == 0)
|
||||
return true;
|
||||
break;
|
||||
case MET_Button_Up:
|
||||
if(evt.button == 0)
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
return BaseGuiElement::onMouseEvent(evt, source);
|
||||
}
|
||||
|
||||
void remove() override {
|
||||
@overlay = null;
|
||||
BaseGuiElement::remove();
|
||||
}
|
||||
|
||||
void update(double time) {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_OverlayBox, SF_Normal, AbsolutePosition, Color(0x888888ff));
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
//}}}
|
||||
|
||||
// {{{ Resources
|
||||
class ResourceDisplay : DisplayBox {
|
||||
GuiText@ resourceLabel;
|
||||
GuiSkinElement@ resourceBox;
|
||||
GuiResources@ resources;
|
||||
|
||||
GuiText@ affinityLabel;
|
||||
GuiSpriteGrid@ affinities;
|
||||
|
||||
ResourceDisplay(OrbitalOverlay@ ov, vec2i origin, Alignment@ target) {
|
||||
super(ov, origin, target);
|
||||
|
||||
@resourceLabel = GuiText(this, Alignment(Left+8, Top+8, Right-8, Top+30), locale::LAB_RESOURCES);
|
||||
resourceLabel.font = FT_Bold;
|
||||
|
||||
@resourceBox = GuiSkinElement(this, Alignment(Left+20, Top+34, Right-20, Top+78), SS_PlainOverlay);
|
||||
@resources = GuiResources(resourceBox, Alignment().fill());
|
||||
resources.horizAlign = 0.0;
|
||||
@resources.drawFrom = overlay.obj;
|
||||
|
||||
@affinityLabel = GuiText(this, Alignment(Left+8, Top+88, Right-8, Top+110), locale::LAB_AVAIL_AFFINITIES);
|
||||
affinityLabel.font = FT_Bold;
|
||||
|
||||
@affinities = GuiSpriteGrid(this, Alignment(Left+20, Top+114, Right-20, Bottom-8), vec2i(40, 40));
|
||||
affinities.horizAlign = 0.0;
|
||||
affinities.vertAlign = 0.0;
|
||||
}
|
||||
|
||||
void updateData() {
|
||||
resources.resources = overlay.resList;
|
||||
|
||||
affinities.clear();
|
||||
for(uint i = 0, cnt = overlay.reqs.available.length; i < cnt; ++i) {
|
||||
if(overlay.reqs.used[i])
|
||||
continue;
|
||||
auto@ res = overlay.reqs.available[i];
|
||||
for(uint n = 0, ncnt = res.affinities.length; n < ncnt; ++n)
|
||||
affinities.add(getAffinitySprite(res.affinities[n]));
|
||||
}
|
||||
affinityLabel.visible = affinities.sprites.length != 0;
|
||||
}
|
||||
|
||||
double updateTimer = 0.0;
|
||||
void update(double time) override {
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateData();
|
||||
updateTimer = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ Modules
|
||||
class ModuleElement : BaseGuiElement {
|
||||
Orbital@ obj;
|
||||
OrbitalSection section;
|
||||
|
||||
GuiSprite@ icon;
|
||||
GuiText@ name;
|
||||
GuiMarkupText@ blurb;
|
||||
GuiMarkupText@ data;
|
||||
Color color;
|
||||
GuiButton@ removeButton;
|
||||
|
||||
ModuleElement(IGuiElement@ disp, OrbitalSection@ section, Orbital@ obj) {
|
||||
super(disp, Alignment(Left+8, Top, Right-8, Top+76));
|
||||
@icon = GuiSprite(this, recti_area(8, 13, 50, 50));
|
||||
@name = GuiText(this, Alignment(Left+70, Top+4, Right-4, Top+28));
|
||||
name.font = FT_Bold;
|
||||
@blurb = GuiMarkupText(this, Alignment(Left+68, Top+26, Right-4, Top+48));
|
||||
@data = GuiMarkupText(this, Alignment(Left+68, Top+48, Right-4, Bottom-4));
|
||||
data.defaultFont = FT_Italic;
|
||||
@removeButton = GuiButton(this, Alignment(Right-40, Bottom-26, Right, Bottom), "-");
|
||||
removeButton.color = colors::Red;
|
||||
|
||||
set(section, obj);
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
int prevY = 0;
|
||||
void setPos(int y) {
|
||||
alignment.top.pixels = y;
|
||||
alignment.bottom.pixels = y + 76;
|
||||
if(prevY != y)
|
||||
updateAbsolutePosition();
|
||||
prevY = y;
|
||||
}
|
||||
|
||||
void set(OrbitalSection@ section, Orbital@ obj) {
|
||||
@this.obj = obj;
|
||||
this.section = section;
|
||||
icon.desc = section.type.icon;
|
||||
name.text = section.type.name;
|
||||
blurb.text = section.type.blurb;
|
||||
data.text = section.getData(obj);
|
||||
if(section.enabled) {
|
||||
color = colors::White;
|
||||
name.color = colors::White;
|
||||
}
|
||||
else {
|
||||
color = colors::Red;
|
||||
name.color = colors::Red;
|
||||
}
|
||||
setMarkupTooltip(this, section.type.getTooltip());
|
||||
removeButton.visible = !section.type.isCore && !obj.isContested;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.caller is removeButton) {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
obj.destroyModule(section.id);
|
||||
emitConfirmed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
skin.draw(SS_PlainOverlay, SF_Normal, AbsolutePosition, color=color);
|
||||
BaseGuiElement::draw();
|
||||
|
||||
int x = AbsolutePosition.width - 32;
|
||||
for(uint i = 0; i < TR_COUNT; ++i) {
|
||||
for(uint n = 0, ncnt = section.type.affinities[i]; n < ncnt; ++n) {
|
||||
getTileResourceSprite(i).draw(
|
||||
recti_area(AbsolutePosition.topLeft + vec2i(x, 4), vec2i(26, 26)));
|
||||
x -= 30;
|
||||
}
|
||||
}
|
||||
for(uint i = 0, cnt = section.type.requirements.length; i < cnt; ++i) {
|
||||
section.type.requirements[i].icon.draw(
|
||||
recti_area(vec2i(x, 4)+AbsolutePosition.topLeft, vec2i(26, 26)));
|
||||
x -= 30;
|
||||
}
|
||||
if(section.type.maintenance != 0) {
|
||||
x -= 60;
|
||||
skin.getFont(FT_Bold).draw(
|
||||
pos=recti_area(vec2i(x, 4)+AbsolutePosition.topLeft, vec2i(86, 26)),
|
||||
text=formatMoney(section.type.maintenance),
|
||||
color=Color(0xd1cb6aff),
|
||||
horizAlign=1.0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleDisplay : DisplayBox {
|
||||
GuiPanel@ panel;
|
||||
array<ModuleElement@> modules;
|
||||
|
||||
ModuleDisplay(OrbitalOverlay@ ov, vec2i origin, Alignment@ target) {
|
||||
super(ov, origin, target);
|
||||
@panel = GuiPanel(this, Alignment().fill());
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateData() {
|
||||
uint oldCnt = modules.length;
|
||||
uint newCnt = overlay.sections.length;
|
||||
for(uint i = newCnt; i < oldCnt; ++i)
|
||||
modules[i].remove();
|
||||
modules.length = newCnt;
|
||||
int y = 8;
|
||||
for(uint i = 0; i < newCnt; ++i) {
|
||||
if(modules[i] is null)
|
||||
@modules[i] = ModuleElement(panel, overlay.sections[i], overlay.obj);
|
||||
else
|
||||
modules[i].set(overlay.sections[i], overlay.obj);
|
||||
modules[i].setPos(y);
|
||||
y += 80;
|
||||
}
|
||||
}
|
||||
|
||||
double updateTimer = 0.0;
|
||||
void update(double time) override {
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateData();
|
||||
updateTimer = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
@@ -0,0 +1,283 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiCargoDisplay;
|
||||
from elements.Gui3DObject import Gui3DObject, ObjectAction;
|
||||
import orbitals;
|
||||
from obj_selection import isSelected;
|
||||
import constructible;
|
||||
import statuses;
|
||||
import util.constructible_view;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class OrbitalPopup : Popup {
|
||||
Constructible cons;
|
||||
bool hasConstruction = false;
|
||||
|
||||
array<GuiSprite@> statusIcons;
|
||||
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
|
||||
GuiProgressbar@ health;
|
||||
GuiProgressbar@ strength;
|
||||
|
||||
GuiCargoDisplay@ cargo;
|
||||
|
||||
GuiSprite@ defIcon;
|
||||
|
||||
Orbital@ obj;
|
||||
bool selected = false;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
OrbitalPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(190, 155);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@health = GuiProgressbar(this, Alignment(Left+3, Bottom-56, Right-4, Bottom-30));
|
||||
health.tooltip = locale::HEALTH;
|
||||
|
||||
GuiSprite healthIcon(health, Alignment(Left+2, Top+1, Width=24, Height=24), icons::Health);
|
||||
|
||||
@strength = GuiProgressbar(this, Alignment(Left+3, Bottom-30, Right-4, Bottom-4));
|
||||
strength.tooltip = locale::FLEET_STRENGTH;
|
||||
|
||||
GuiSprite strIcon(strength, Alignment(Left+2, Top+1, Width=24, Height=24), icons::Strength);
|
||||
|
||||
@objView = Gui3DObject(this, recti(34, 24, 156, 98));
|
||||
|
||||
@cargo = GuiCargoDisplay(objView, Alignment(Left, Top, Right, Top+25));
|
||||
|
||||
@defIcon = GuiSprite(this, Alignment(Right-44, Top+25, Width=40, Height=40));
|
||||
defIcon.desc = icons::Defense;
|
||||
setMarkupTooltip(defIcon, locale::TT_IS_DEFENDING);
|
||||
defIcon.visible = false;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return cast<Orbital>(Obj) !is null;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Orbital>(Obj);
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
statusUpdate = 0.f;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = isSelectable ? SS_SelectablePopup : SS_GenericPopupBG;
|
||||
if(selected)
|
||||
flags |= SF_Active;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
skin.draw(style, flags, bgPos, obj.owner.color);
|
||||
if(obj.owner.flag !is null)
|
||||
obj.owner.flag.draw(
|
||||
objView.absolutePosition.aspectAligned(1.0, horizAlign=1.0, vertAlign=1.0),
|
||||
obj.owner.color * Color(0xffffff30));
|
||||
|
||||
objView.draw();
|
||||
|
||||
if(cargo.visible)
|
||||
drawRectangle(cargo.absolutePosition, Color(0x00000040));
|
||||
|
||||
//Construction display
|
||||
if(hasConstruction) {
|
||||
recti plPos = objView.absolutePosition;
|
||||
const Font@ ft = skin.getFont(FT_Small);
|
||||
int sz = ft.getLineHeight() * 2 + 6;
|
||||
Color nameCol(0xffffffff);
|
||||
if(!cons.started)
|
||||
nameCol = Color(0xff0000ff);
|
||||
ft.draw(plPos.resized(0, sz, 0.0, 1.0),
|
||||
cons.name, locale::ELLIPSIS, nameCol, 0.5, 0.0);
|
||||
|
||||
string prog = toString(cons.progress * 100.f, 0)+"%";
|
||||
if(cons.type == CT_DryDock)
|
||||
prog += " / "+toString(cons.pct * 100.f, 0)+"%";
|
||||
ft.draw(plPos.resized(0, sz - ft.getLineHeight(), 0.0, 1.0),
|
||||
prog, locale::ELLIPSIS, Color(0xffffffff), 0.5, 0.0);
|
||||
|
||||
drawConstructible(cons, plPos.resized(0, plPos.size.height - sz + 6));
|
||||
}
|
||||
|
||||
objView.visible = false;
|
||||
BaseGuiElement::draw();
|
||||
objView.visible = true;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void updateStrengthBar() {
|
||||
double curStr = 0, totStr = 0;
|
||||
if(obj.hasLeaderAI) {
|
||||
curStr = obj.getFleetStrength() * 0.001;
|
||||
totStr = obj.getFleetMaxStrength() * 0.001;
|
||||
}
|
||||
else {
|
||||
curStr = obj.dps * obj.efficiency * (obj.health + obj.armor) * 0.001;
|
||||
totStr = obj.dps * (obj.maxHealth + obj.maxArmor) * 0.001;
|
||||
}
|
||||
|
||||
if(totStr == 0) {
|
||||
strength.progress = 0.f;
|
||||
strength.frontColor = Color(0xff6a00ff);
|
||||
strength.text = "--";
|
||||
}
|
||||
else {
|
||||
strength.progress = curStr / totStr;
|
||||
if(strength.progress > 1.001f) {
|
||||
strength.progress = 1.f;
|
||||
strength.font = FT_Bold;
|
||||
}
|
||||
else {
|
||||
strength.font = FT_Normal;
|
||||
}
|
||||
|
||||
strength.frontColor = Color(0xff6a00ff).interpolate(Color(0xffc600ff), strength.progress);
|
||||
strength.text = standardize(curStr);
|
||||
strength.tooltip = locale::FLEET_STRENGTH+": "+standardize(curStr)+"/"+standardize(totStr);
|
||||
}
|
||||
}
|
||||
|
||||
float statusUpdate = 0.f;
|
||||
void update() {
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
lastUpdate = frameTime;
|
||||
|
||||
bool owned = obj.owner is playerEmpire;
|
||||
if(!isSelectable)
|
||||
selected = separated && isSelected(obj);
|
||||
|
||||
//Update static info
|
||||
name.text = obj.name;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
if(obj.isDisabled)
|
||||
name.color = colors::Red;
|
||||
else
|
||||
name.color = colors::White;
|
||||
|
||||
//Update hp display
|
||||
double curHP = obj.health + obj.armor;
|
||||
double maxHP = max(obj.maxHealth + obj.maxArmor, 0.001);
|
||||
|
||||
Color high(0x00ff00ff);
|
||||
Color low(0xff0000ff);
|
||||
|
||||
health.progress = curHP / maxHP;
|
||||
health.frontColor = low.interpolate(high, health.progress);
|
||||
health.text = standardize(curHP)+" / "+standardize(maxHP);
|
||||
|
||||
defIcon.visible = playerEmpire.isDefending(obj);
|
||||
|
||||
updateStrengthBar();
|
||||
|
||||
//Find master obj
|
||||
Object@ fromMaster = obj;
|
||||
if(obj.hasMaster())
|
||||
@fromMaster = obj.getMaster();
|
||||
|
||||
//Update cargo
|
||||
cargo.visible = fromMaster.hasCargo && fromMaster.cargoTypes > 0;
|
||||
if(cargo.visible)
|
||||
cargo.update(fromMaster);
|
||||
|
||||
//Update construction
|
||||
Object@ constructObj = fromMaster;
|
||||
if(owned && constructObj.hasConstruction) {
|
||||
DataList@ list = constructObj.getConstructionQueue(1);
|
||||
hasConstruction = receive(list, cons);
|
||||
}
|
||||
else {
|
||||
const Design@ dsg = obj.getDesign(OV_DRY_Design);
|
||||
if(dsg !is null) {
|
||||
cons.type = CT_DryDock;
|
||||
@cons.obj = obj;
|
||||
@cons.dsg = dsg;
|
||||
cons.prog = obj.getValue(OV_DRY_Progress);
|
||||
cons.pct = obj.getValue(OV_DRY_Financed);
|
||||
cons.started = true;
|
||||
cons.id = -1;
|
||||
hasConstruction = true;
|
||||
}
|
||||
else {
|
||||
hasConstruction = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Update statuses
|
||||
statusUpdate -= frameLength;
|
||||
if(statusUpdate <= 0.f) {
|
||||
array<Status> statuses;
|
||||
if(obj.statusEffectCount > 0)
|
||||
statuses.syncFrom(obj.getStatusEffects());
|
||||
uint prevCnt = statusIcons.length, cnt = statuses.length;
|
||||
for(uint i = cnt; i < prevCnt; ++i)
|
||||
statusIcons[i].remove();
|
||||
statusIcons.length = cnt;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
auto@ icon = statusIcons[i];
|
||||
if(icon is null) {
|
||||
@icon = GuiSprite(this, recti_area(6, 25+25*i, 25, 25));
|
||||
@statusIcons[i] = icon;
|
||||
}
|
||||
|
||||
auto@ status = statuses[i];
|
||||
icon.desc = status.type.icon;
|
||||
setMarkupTooltip(icon, format("[b]$1[/b]\n$2", status.type.name, status.type.description));
|
||||
}
|
||||
statusUpdate += 1.f;
|
||||
}
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,152 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import util.formatting;
|
||||
import pickups;
|
||||
import icons;
|
||||
from overlays.ShipPopup import ShipPopup;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class PickupPopup : Popup {
|
||||
GuiText@ title;
|
||||
GuiText@ name;
|
||||
GuiMarkupText@ description;
|
||||
Gui3DObject@ objView;
|
||||
Pickup@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
ShipPopup@ ship;
|
||||
|
||||
PickupPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(180, 220);
|
||||
|
||||
@title = GuiText(this, Alignment(Left+4, Top+4, Right-4, Top+24), locale::PICKUP_PROTECTING);
|
||||
title.font = FT_Bold;
|
||||
title.vertAlign = 0.0;
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+20, Right-4, Top+46));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+3, Top+46, Right-4, Top+130));
|
||||
|
||||
@description = GuiMarkupText(this, Alignment(Left+8, Top+134, Right-8, Bottom-4));
|
||||
|
||||
@ship = ShipPopup(null);
|
||||
ship.mouseLinked = true;
|
||||
ship.updateAbsolutePosition();
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void remove() {
|
||||
ship.remove();
|
||||
Popup::remove();
|
||||
}
|
||||
|
||||
void set_visible(bool v) {
|
||||
ship.visible = v;
|
||||
Popup::set_visible(v);
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isPickup;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Pickup>(Obj);
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
skin.draw(SS_Panel, SF_Normal, bgPos);
|
||||
skin.draw(SS_BG3D, SF_Normal, objView.absolutePosition);
|
||||
skin.draw(SS_SubTitle, SF_Normal, recti_area(bgPos.topLeft+vec2i(2,1), vec2i(bgPos.width-5, 45)));
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
Ship@ prot = cast<Ship>(obj.getProtector());
|
||||
if(!separated && prot !is null && prot.valid) {
|
||||
if(ship.get() !is prot)
|
||||
ship.set(prot);
|
||||
ship.update();
|
||||
ship.visible = true;
|
||||
|
||||
objOffset = vec2i(200, 0);
|
||||
mouseOffset = objOffset;
|
||||
|
||||
title.text = locale::PICKUP_PROTECTING;
|
||||
title.color = colors::Artifact;
|
||||
}
|
||||
else {
|
||||
ship.visible = false;
|
||||
|
||||
objOffset = vec2i();
|
||||
mouseOffset = objOffset;
|
||||
|
||||
title.text = locale::PICKUP_UNPROTECTED;
|
||||
title.color = colors::Green;
|
||||
}
|
||||
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
const PickupType@ type = getPickupType(obj.PickupType);
|
||||
if(type !is null)
|
||||
description.text = type.description;
|
||||
else
|
||||
description.text = "--";
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,557 @@
|
||||
import overlays.InfoBar;
|
||||
import elements.GuiResources;
|
||||
import elements.GuiIconGrid;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiStatusBox;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.MarkupTooltip;
|
||||
import constructible;
|
||||
import resources;
|
||||
import obj_selection;
|
||||
import planet_levels;
|
||||
import util.constructible_view;
|
||||
import util.formatting;
|
||||
import icons;
|
||||
import targeting.ObjectTarget;
|
||||
import statuses;
|
||||
from elements.GuiResources import LEVEL_REQ;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
from overlays.PlanetOverlay import PlanetOverlay;
|
||||
from tabs.GalaxyTab import zoomTabTo, openOverlay, toggleSupportOverlay;
|
||||
|
||||
//Temporary to avoid allocations
|
||||
Resources available;
|
||||
|
||||
Color boxColors(0xffffffff);
|
||||
|
||||
class PlanetInfoBar : InfoBar {
|
||||
Constructible[] cons;
|
||||
array<Status> statuses;
|
||||
|
||||
Planet@ pl;
|
||||
PlanetOverlay@ overlay;
|
||||
Gui3DObject@ objView;
|
||||
|
||||
GuiSkinElement@ nameBox;
|
||||
GuiText@ name;
|
||||
|
||||
GuiSkinElement@ levelBox;
|
||||
GuiText@ level;
|
||||
|
||||
GuiSkinElement@ requireBox;
|
||||
GuiText@ reqLabel;
|
||||
GuiText@ reqTimer;
|
||||
GuiMarkupText@ popReq;
|
||||
GuiResourceReqGrid@ reqDisplay;
|
||||
|
||||
GuiSkinElement@ resourceBox;
|
||||
GuiResourceGrid@ resources;
|
||||
GuiMarkupText@ resourceDesc;
|
||||
|
||||
GuiSkinElement@ popBox;
|
||||
GuiSprite@ popIcon;
|
||||
GuiText@ popValue;
|
||||
|
||||
GuiSkinElement@ consBox;
|
||||
|
||||
GuiSkinElement@ statusBox;
|
||||
GuiMarkupText@ statusText;
|
||||
|
||||
GuiSkinElement@ actionBG;
|
||||
ActionBar@ actions;
|
||||
|
||||
array<GuiStatusBox@> statusIcons;
|
||||
GuiSkinElement@ statusList;
|
||||
|
||||
PlanetInfoBar(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
@alignment = Alignment(Left, Bottom-228, Left+456, Bottom);
|
||||
|
||||
@actionBG = GuiSkinElement(this, recti_area(vec2i(335, 172), vec2i(100, 60)), SS_Panel);
|
||||
actionBG.noClip = true;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(
|
||||
Left-1.f, Top, Right, Bottom+3.f));
|
||||
objView.internalRotation = quaterniond_fromAxisAngle(vec3d(0.0, 0.0, 1.0), -0.25*pi);
|
||||
|
||||
@actions = ActionBar(this, vec2i(385, 172));
|
||||
actions.noClip = true;
|
||||
|
||||
int y = 40;
|
||||
@nameBox = GuiSkinElement(this, Alignment(Left+5, Top+y, Left+0.4f-4, Top+y+34), SS_PlainOverlay);
|
||||
nameBox.color = boxColors;
|
||||
@name = GuiText(nameBox, Alignment().padded(10, 0));
|
||||
name.font = FT_Medium;
|
||||
name.stroke = colors::Black;
|
||||
|
||||
y += 40;
|
||||
@levelBox = GuiSkinElement(this, Alignment(Left+5, Top+y, Left+0.22f-4, Top+y+34), SS_PlainOverlay);
|
||||
levelBox.color = boxColors;
|
||||
@level = GuiText(levelBox, Alignment().padded(8, 0));
|
||||
level.stroke = colors::Black;
|
||||
level.font = FT_Medium;
|
||||
|
||||
@requireBox = GuiSkinElement(this, Alignment(Left+0.22f+4, Top+y, Left+0.55f, Top+y+34), SS_PlainOverlay);
|
||||
requireBox.color = boxColors;
|
||||
@reqLabel = GuiText(requireBox, Alignment(Left-4, Top-6, Left+96, Top+6), locale::REQUIRED_RESOURCES);
|
||||
reqLabel.noClip = true;
|
||||
reqLabel.font = FT_Small;
|
||||
reqLabel.stroke = colors::Black;
|
||||
@reqTimer = GuiText(requireBox, Alignment(Right-96, Top-6, Right+4, Top+6));
|
||||
reqTimer.color = Color(0xff0000fff);
|
||||
reqTimer.noClip = true;
|
||||
reqTimer.font = FT_Small;
|
||||
reqTimer.horizAlign = 1.0;
|
||||
reqTimer.visible = false;
|
||||
reqTimer.stroke = colors::Black;
|
||||
@reqDisplay = GuiResourceReqGrid(requireBox, Alignment(Left+8, Top+8, Right-8, Bottom));
|
||||
reqDisplay.spacing.x = 6;
|
||||
reqDisplay.horizAlign = 0.0;
|
||||
reqDisplay.vertAlign = 0.0;
|
||||
@popReq = GuiMarkupText(requireBox, Alignment(Left+4, Top+8, Right-4, Bottom));
|
||||
popReq.visible = false;
|
||||
|
||||
y += 38;
|
||||
|
||||
@resourceBox = GuiSkinElement(this, Alignment(), SS_PlainOverlay);
|
||||
resourceBox.color = boxColors;
|
||||
@resources = GuiResourceGrid(resourceBox, Alignment(Left+8, Top+5, Right-8, Bottom-2));
|
||||
resources.spacing.x = 6;
|
||||
resources.horizAlign = 0.0;
|
||||
resources.vertAlign = 0.0;
|
||||
@resourceDesc = GuiMarkupText(resourceBox, Alignment(Left+8, Bottom-42, Right-8, Bottom));
|
||||
resourceDesc.visible = false;
|
||||
resourceDesc.defaultColor = Color(0xaaaaaaff);
|
||||
|
||||
@statusList = GuiSkinElement(this, Alignment(Left+295, Top+118, Left+295+34, Top+118+70), SS_PlainBox);
|
||||
statusList.noClip = true;
|
||||
statusList.visible = false;
|
||||
|
||||
@statusBox = GuiSkinElement(this, Alignment(Left+5, Top+153, Left+295, Bottom-2), SS_PlainOverlay);
|
||||
statusBox.color = boxColors;
|
||||
@statusText = GuiMarkupText(statusBox, Alignment().padded(2,0));
|
||||
statusBox.visible = false;
|
||||
|
||||
int x = 5;
|
||||
y += 72;
|
||||
@popBox = GuiSkinElement(this, Alignment(Left, Bottom-32, Left+x+94, Bottom), SS_HorizBar);
|
||||
popBox.color = Color(0x80ffffff);
|
||||
popBox.padding = recti(0,4,4,4);
|
||||
@popIcon = GuiSprite(popBox, Alignment(Left-16, Top-8, Width=50, Height=50));
|
||||
popIcon.noClip = true;
|
||||
popIcon.desc = icons::Population;
|
||||
@popValue = GuiText(popBox, Alignment(Left+32, Top, Right-8, Bottom));
|
||||
popValue.horizAlign = 0.5;
|
||||
popValue.stroke = colors::Black;
|
||||
|
||||
MarkupTooltip popTT(locale::PLANET_POPULATION_TIP);
|
||||
@popIcon.tooltipObject = popTT;
|
||||
@popValue.tooltipObject = popTT;
|
||||
|
||||
@consBox = GuiSkinElement(this, Alignment(Left+112, Bottom-33, Left+336, Bottom-2), SS_PlainOverlay);
|
||||
consBox.color = boxColors;
|
||||
GuiSprite consIcon(consBox, Alignment(Left-16, Top-10, Left+35, Bottom+10), icons::Labor);
|
||||
|
||||
y += 30;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
actions.clear();
|
||||
|
||||
if(pl.owner is playerEmpire) {
|
||||
actions.add(ManageAction());
|
||||
actions.addBasic(pl);
|
||||
actions.addFTL(pl);
|
||||
|
||||
if(pl.population > 1.0 && playerEmpire.ForbidColonization == 0)
|
||||
actions.add(ColonizeAction());
|
||||
|
||||
actions.addAbilities(pl);
|
||||
actions.addEmpireAbilities(playerEmpire, pl);
|
||||
}
|
||||
else {
|
||||
if((pl.owner is null || !pl.owner.valid) && !pl.quarantined && playerEmpire.ForbidColonization == 0)
|
||||
actions.add(ColonizeThisAction());
|
||||
}
|
||||
|
||||
actions.init(pl);
|
||||
actionBG.size = vec2i(actions.size.width + 50, 60);
|
||||
actionBG.visible = actions.visible;
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) override {
|
||||
return obj.isPlanet;
|
||||
}
|
||||
|
||||
Object@ get() override {
|
||||
return pl;
|
||||
}
|
||||
|
||||
void remove() override {
|
||||
if(overlay !is null)
|
||||
overlay.remove();
|
||||
InfoBar::remove();
|
||||
}
|
||||
|
||||
void set(Object@ obj) override {
|
||||
@pl = cast<Planet>(obj);
|
||||
@objView.object = obj;
|
||||
@resources.drawFrom = obj;
|
||||
updateTimer = 0.0;
|
||||
modID = 0;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) override {
|
||||
if(obj is pl)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_showingManage() override {
|
||||
return overlay !is null;
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) override {
|
||||
if(overlay !is null)
|
||||
overlay.remove();
|
||||
@overlay = PlanetOverlay(findTab(), cast<Planet>(obj));
|
||||
visible = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
selectObject(pl, shiftKey);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
if(selectedObject is null)
|
||||
openContextMenu(pl, pl);
|
||||
else
|
||||
openContextMenu(pl);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
zoomTabTo(pl);
|
||||
return true;
|
||||
case OA_DoubleClick:
|
||||
showManage(pl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return InfoBar::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& evt, IGuiElement@ source) override {
|
||||
if(source !is objView) {
|
||||
switch(evt.type) {
|
||||
case MET_Button_Up:
|
||||
case MET_Button_Down:
|
||||
return objView.onMouseEvent(evt, objView);
|
||||
}
|
||||
}
|
||||
|
||||
return BaseGuiElement::onMouseEvent(evt, source);
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(elem is this)
|
||||
return null;
|
||||
if(elem is objView) {
|
||||
int height = AbsolutePosition.size.height;
|
||||
vec2i origin(AbsolutePosition.topLeft.x, AbsolutePosition.botRight.y);
|
||||
origin.y += height;
|
||||
if(pos.distanceTo(origin) > height * 2)
|
||||
return null;
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
double updateTimer = 1.0;
|
||||
uint modID = 0;
|
||||
void update(double time) override {
|
||||
if(overlay !is null) {
|
||||
if(overlay.parent is null) {
|
||||
@overlay = null;
|
||||
visible = true;
|
||||
}
|
||||
else
|
||||
overlay.update(time);
|
||||
}
|
||||
|
||||
if(actions !is null)
|
||||
actions.update(time);
|
||||
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateTimer = randomd(0.1,0.9);
|
||||
Empire@ owner = pl.visibleOwner;
|
||||
bool owned = owner is playerEmpire;
|
||||
bool colonized = owner !is null && owner.valid;
|
||||
|
||||
updateActions();
|
||||
|
||||
//Update name
|
||||
name.text = pl.name;
|
||||
if(owner !is null)
|
||||
name.color = owner.color;
|
||||
|
||||
//Update level
|
||||
uint lv = pl.level;
|
||||
level.text = locale::LEVEL+" "+lv;
|
||||
|
||||
//Update resource display
|
||||
resources.resources.syncFrom(pl.getAllResources());
|
||||
if(!colonized)
|
||||
resources.resources.length = min(resources.resources.length, 1);
|
||||
else
|
||||
resources.resources.sortDesc();
|
||||
resources.setSingleMode(align=0.0);
|
||||
|
||||
auto@ primary = getResource(pl.primaryResourceType);
|
||||
if(resources.resources.length == 1 || (primary !is null && primary.limitlessLevel)) {
|
||||
resources.alignment.bottom.pixels = 40;
|
||||
|
||||
auto@ type = resources.resources[0].type;
|
||||
string desc = format(type.blurb, toString(pl.level, 0));
|
||||
if(desc.length == 0)
|
||||
desc = format(type.description, toString(pl.level, 0));
|
||||
if(desc.length == 0) {
|
||||
if(type.level > 0) {
|
||||
desc = format(locale::RESOURCE_TIER_DESC,
|
||||
toString(type.level),
|
||||
type.level < LEVEL_REQ.length ? getSpriteDesc(LEVEL_REQ[type.level]) : "ResourceClassIcons::5");
|
||||
}
|
||||
}
|
||||
resourceDesc.text = desc;
|
||||
resourceDesc.visible = true;
|
||||
}
|
||||
else {
|
||||
resources.alignment.bottom.pixels = 2;
|
||||
resourceDesc.visible = false;
|
||||
}
|
||||
|
||||
//Update statuses
|
||||
if(pl.statusEffectCount > 0)
|
||||
statuses.syncFrom(pl.getStatusEffects());
|
||||
else
|
||||
statuses.length = 0;
|
||||
|
||||
//Update condition display
|
||||
levelBox.visible = colonized;
|
||||
popBox.visible = colonized && owner.HasPopulation != 0;
|
||||
if(colonized || statuses.length == 0) {
|
||||
if(statuses.length != 0) {
|
||||
uint prevCnt = statusIcons.length, cnt = statuses.length;
|
||||
for(uint i = cnt; i < prevCnt; ++i)
|
||||
statusIcons[i].remove();
|
||||
statusIcons.length = cnt;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
auto@ icon = statusIcons[i];
|
||||
if(icon is null) {
|
||||
@icon = GuiStatusBox(statusList, recti_area(2, 2+32*i, 30, 30));
|
||||
@statusIcons[i] = icon;
|
||||
}
|
||||
@icon.fromObject = pl;
|
||||
icon.update(statuses[i]);
|
||||
}
|
||||
statusList.visible = true;
|
||||
}
|
||||
else {
|
||||
statusList.visible = false;
|
||||
}
|
||||
resourceBox.alignment = Alignment(Left+5, Top+118, Left+295, Top+118+70);
|
||||
resourceBox.updateAbsolutePosition();
|
||||
statusBox.visible = false;
|
||||
resourceBox.visible = resources.length != 0;
|
||||
}
|
||||
else {
|
||||
resourceBox.alignment = Alignment(Left+5, Top+80, Left+295, Top+80+70);
|
||||
resourceBox.updateAbsolutePosition();
|
||||
statusList.visible = false;
|
||||
statusBox.visible = true;
|
||||
resourceBox.visible = resources.length != 0;
|
||||
|
||||
auto@ status = statuses[0].type;
|
||||
for(uint i = 0, cnt = statuses.length; i < cnt; ++i) {
|
||||
if(statuses[i].type.conditionFrequency > 0) {
|
||||
@status = statuses[i].type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
statusText.text = format("[b][img=$3;22x22/] [color=$4][vspace=3]$1[/vspace][/color][/b]"
|
||||
"\n[offset=6][vspace=4][color=#aaa]$2[/color][/vspace][/offset]",
|
||||
status.name, status.description,
|
||||
getSpriteDesc(status.icon), toString(status.color));
|
||||
}
|
||||
|
||||
//Update population display
|
||||
if(colonized) {
|
||||
popValue.text = standardize(pl.population, true) + "/" + standardize(pl.maxPopulation, true);
|
||||
popValue.color = Color(0xffffffff);
|
||||
}
|
||||
else {
|
||||
popValue.text = "-";
|
||||
}
|
||||
|
||||
//Update construction
|
||||
if(owned)
|
||||
cons.syncFrom(pl.getConstructionQueue(1));
|
||||
else
|
||||
cons.length = 0;
|
||||
|
||||
consBox.visible = cons.length != 0;
|
||||
|
||||
//Update level requirements
|
||||
double decay = pl.decayTime;
|
||||
uint maxLevel = getMaxPlanetLevel(pl);
|
||||
if(!owned || (lv == maxLevel && decay <= 0) || (lv >= uint(pl.maxLevel) && decay <= 0)) {
|
||||
requireBox.visible = false;
|
||||
}
|
||||
else if(decay > 0) {
|
||||
requireBox.visible = true;
|
||||
reqTimer.visible = true;
|
||||
reqTimer.text = formatTime(decay);
|
||||
reqLabel.color = Color(0xff0000ff);
|
||||
reqLabel.tooltip = format(locale::REQ_STOP_DECAY, toString(lv-1), formatTime(decay));
|
||||
reqLabel.text = format(locale::REQUIRED_RESOURCES, toString(lv));
|
||||
|
||||
uint newMod = pl.resourceModID;
|
||||
if(modID != newMod) {
|
||||
available.clear();
|
||||
receive(pl.getResourceAmounts(), available);
|
||||
|
||||
const PlanetLevel@ lvl = getPlanetLevel(pl, lv);
|
||||
reqDisplay.set(lvl.reqs, available);
|
||||
reqDisplay.visible = true;
|
||||
reqLabel.visible = true;
|
||||
|
||||
popReq.visible = reqDisplay.length == 0;
|
||||
if(popReq.visible)
|
||||
popReq.text = format(locale::POP_REQ, standardize(lvl.requiredPop, true));
|
||||
|
||||
reqLabel.tooltip = format(locale::REQ_FOR_LEVEL, toString(lv + 1));
|
||||
modID = newMod;
|
||||
}
|
||||
}
|
||||
else {
|
||||
requireBox.visible = pl.nativeResourceDestination[0] is null || !pl.nativeResourceUsable[0];
|
||||
reqTimer.visible = false;
|
||||
reqLabel.color = Color(0xffffffff);
|
||||
|
||||
uint newMod = pl.resourceModID;
|
||||
if(modID != newMod) {
|
||||
available.clear();
|
||||
receive(pl.getResourceAmounts(), available);
|
||||
|
||||
const PlanetLevel@ lvl = getPlanetLevel(pl, lv + 1);
|
||||
reqDisplay.set(lvl.reqs, available);
|
||||
reqDisplay.visible = true;
|
||||
reqLabel.visible = true;
|
||||
reqLabel.text = format(locale::REQUIRED_RESOURCES, toString(lv+1));
|
||||
|
||||
popReq.visible = reqDisplay.length == 0;
|
||||
if(popReq.visible)
|
||||
popReq.text = format(locale::POP_REQ, standardize(lvl.requiredPop, true));
|
||||
|
||||
reqLabel.tooltip = format(locale::REQ_FOR_LEVEL, toString(lv + 1));
|
||||
modID = newMod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InfoBar::update(time);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
BaseGuiElement::draw();
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
//Construction display
|
||||
if(cons.length != 0) {
|
||||
recti pos = consBox.AbsolutePosition.padded(4);
|
||||
drawConstructible(cons[0], consBox.AbsolutePosition, isBox=true);
|
||||
ft.draw(pos=pos, text=formatTime(cons[0].getETA(pl)), horizAlign=1.0, vertAlign=1.0, stroke=colors::Black);
|
||||
|
||||
if(ft.bold !is null)
|
||||
@ft = ft.bold;
|
||||
ft.draw(pos=pos, text=cons[0].name, horizAlign=0.0, vertAlign=0.0, stroke=colors::Black);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ManageAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::Manage;
|
||||
tooltip = locale::TT_MANAGE_PLANET;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
selectObject(obj);
|
||||
openOverlay(obj);
|
||||
}
|
||||
};
|
||||
|
||||
class ColonizeAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::Colonize;
|
||||
tooltip = locale::TT_COLONIZE;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
targetObject(ColonizeTarget(obj));
|
||||
}
|
||||
};
|
||||
|
||||
class ColonizeTarget : ObjectTargeting {
|
||||
Object@ obj;
|
||||
|
||||
ColonizeTarget(Object@ obj) {
|
||||
@this.obj = obj;
|
||||
}
|
||||
|
||||
void call(Object@ target) {
|
||||
obj.colonize(target);
|
||||
}
|
||||
|
||||
string message(Object@ obj, bool valid) {
|
||||
return locale::COLONIZE;
|
||||
}
|
||||
|
||||
bool valid(Object@ obj) {
|
||||
if(!obj.isPlanet)
|
||||
return false;
|
||||
if(obj.quarantined)
|
||||
return false;
|
||||
return obj.owner is null || !obj.owner.valid;
|
||||
}
|
||||
};
|
||||
|
||||
class ColonizeThisAction : BarAction {
|
||||
void init() override {
|
||||
icon = icons::ColonizeThis;
|
||||
tooltip = locale::TT_COLONIZE_THIS;
|
||||
}
|
||||
|
||||
void call() override {
|
||||
playerEmpire.autoColonize(obj);
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ makePlanetInfoBar(IGuiElement@ parent, Object@ obj) {
|
||||
PlanetInfoBar bar(parent);
|
||||
bar.set(obj);
|
||||
return bar;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,347 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiImage;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiResources;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiStatusBox;
|
||||
import elements.GuiCargoDisplay;
|
||||
import biomes;
|
||||
import orbitals;
|
||||
from obj_selection import isSelected;
|
||||
import constructible;
|
||||
import util.constructible_view;
|
||||
import util.obj_locate;
|
||||
import util.icon_view;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
import statuses;
|
||||
|
||||
const uint CONSTRUCTION_SLIDESHOW_TIMER = 2.0;
|
||||
|
||||
class PlanetPopup : Popup {
|
||||
Constructible[] cons;
|
||||
uint consDisp = 0;
|
||||
double consDispTimer = 0;
|
||||
|
||||
GuiText@ name;
|
||||
GuiText@ ownerName;
|
||||
|
||||
array<GuiStatusBox@> statusIcons;
|
||||
Gui3DObject@ objView;
|
||||
GuiSprite@ defIcon;
|
||||
|
||||
BaseGuiElement@ popBox;
|
||||
GuiSprite@ popIcon;
|
||||
GuiText@ popValue;
|
||||
|
||||
BaseGuiElement@ loyBox;
|
||||
GuiSprite@ loyIcon;
|
||||
GuiText@ loyValue;
|
||||
|
||||
GuiResourceGrid@ resources;
|
||||
|
||||
GuiSkinElement@ statusBox;
|
||||
|
||||
GuiProgressbar@ health;
|
||||
|
||||
GuiCargoDisplay@ cargo;
|
||||
|
||||
Planet@ pl;
|
||||
bool selected = false;
|
||||
bool showOrbitalConstruction = true;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
PlanetPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(190, 160);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+50, Top+6, Right-4, Top+28));
|
||||
@ownerName = GuiText(this, Alignment(Left+48, Top+28, Right-6, Top+46));
|
||||
ownerName.horizAlign = 1.0;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+50, Right-4, Top+120));
|
||||
|
||||
@cargo = GuiCargoDisplay(objView, Alignment(Left, Top, Right, Top+25));
|
||||
|
||||
@defIcon = GuiSprite(this, Alignment(Left+4, Top+50, Width=40, Height=40));
|
||||
defIcon.desc = icons::Defense;
|
||||
setMarkupTooltip(defIcon, locale::TT_IS_DEFENDING);
|
||||
defIcon.visible = false;
|
||||
|
||||
GuiSkinElement band(this, Alignment(Left+3, Bottom-35, Right-4, Bottom-2), SS_SubTitle);
|
||||
band.color = Color(0xaaaaaaff);
|
||||
|
||||
@popBox = BaseGuiElement(this, Alignment(Left+3, Bottom-67, Left+50, Bottom-35));
|
||||
@popIcon = GuiSprite(popBox, Alignment(Left-12, Top+2, Left+24, Bottom+6));
|
||||
popIcon.desc = icons::Population;
|
||||
@popValue = GuiText(popBox, Alignment(Left+26, Top+12, Right, Height=20));
|
||||
popIcon.tooltip = locale::POPULATION;
|
||||
popValue.tooltip = locale::POPULATION;
|
||||
|
||||
@loyBox = BaseGuiElement(this, Alignment(Right-50, Bottom-67, Right-5, Bottom-35));
|
||||
@loyIcon = GuiSprite(loyBox, Alignment(Right-24, Top+8, Right, Bottom-1));
|
||||
loyIcon.desc = icons::Loyalty;
|
||||
@loyValue = GuiText(loyBox, Alignment(Right-50, Top+12, Right-26, Height=20));
|
||||
loyValue.horizAlign = 1.0;
|
||||
loyIcon.tooltip = locale::LOYALTY;
|
||||
loyValue.tooltip = locale::LOYALTY;
|
||||
|
||||
@resources = GuiResourceGrid(band, Alignment(Left+4, Top+4, Right-3, Bottom-4));
|
||||
|
||||
@statusBox = GuiSkinElement(this, Alignment(Right-2, Top, Right+34, Bottom), SS_PlainBox);
|
||||
statusBox.noClip = true;
|
||||
statusBox.visible = false;
|
||||
|
||||
@health = GuiProgressbar(this, Alignment(Left+8, Top+53, Right-8, Top+75));
|
||||
health.visible = false;
|
||||
|
||||
auto@ healthIcon = GuiSprite(health, Alignment(Left-8, Top-9, Left+24, Bottom-8), icons::Health);
|
||||
healthIcon.noClip = true;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) {
|
||||
return cast<Planet>(obj) !is null;
|
||||
}
|
||||
|
||||
void set(Object@ obj) {
|
||||
@pl = cast<Planet>(obj);
|
||||
@objView.object = obj;
|
||||
@resources.drawFrom = obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return pl;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(pl);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = isSelectable ? SS_SelectablePopup : SS_PopupBG;
|
||||
if(selected)
|
||||
flags |= SF_Active;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
Empire@ owner = pl.visibleOwner;
|
||||
Color color;
|
||||
if(owner !is null) {
|
||||
color = owner.color;
|
||||
skin.draw(style, flags, bgPos, owner.color);
|
||||
if(owner.flag !is null) {
|
||||
vec2i s = objView.absolutePosition.size;
|
||||
owner.flag.draw(
|
||||
objView.absolutePosition
|
||||
.resized(s.x*0.5, s.y*0.5, 0.0, 0.0)
|
||||
.aspectAligned(1.0, horizAlign=0.0, vertAlign=0.0),
|
||||
owner.color * Color(0xffffff40));
|
||||
}
|
||||
}
|
||||
else {
|
||||
skin.draw(style, flags, bgPos, Color(0xffffffff));
|
||||
}
|
||||
|
||||
skin.draw(SS_SubTitle, SF_Normal, recti_area(bgPos.topLeft + vec2i(2,2), vec2i(bgPos.width-5, 50-4)), color);
|
||||
|
||||
if(resources.resources.length != 0)
|
||||
drawPlanetIcon(pl, recti_area(bgPos.topLeft+vec2i(2, 2), vec2i(46,46)), resources.resources[0]);
|
||||
else
|
||||
drawObjectIcon(pl, recti_area(bgPos.topLeft+vec2i(2, 2), vec2i(46,46)));
|
||||
|
||||
objView.draw();
|
||||
|
||||
if(cargo.visible)
|
||||
drawRectangle(cargo.absolutePosition, Color(0x00000040));
|
||||
|
||||
//Construction display
|
||||
if(cons.length != 0) {
|
||||
//Slide through different constructions
|
||||
if(consDisp >= cons.length)
|
||||
consDisp = 0;
|
||||
if(consDispTimer < frameTime) {
|
||||
consDispTimer = frameTime + CONSTRUCTION_SLIDESHOW_TIMER;
|
||||
consDisp = (consDisp + 1) % cons.length;
|
||||
}
|
||||
|
||||
//Draw the construction
|
||||
recti plPos = objView.absolutePosition;
|
||||
const Font@ ft = skin.getFont(FT_Small);
|
||||
drawConstructible(cons[consDisp], plPos, ft);
|
||||
}
|
||||
|
||||
objView.Visible = false;
|
||||
BaseGuiElement::draw();
|
||||
objView.Visible = true;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(pl);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
emitClicked(PA_Zoom);
|
||||
return true;
|
||||
case OA_DoubleClick:
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
if(pl is null)
|
||||
return;
|
||||
lastUpdate = frameTime;
|
||||
|
||||
bool owned = pl.owner is playerEmpire;
|
||||
auto@ owner = pl.visibleOwner;
|
||||
bool colonized = owner !is null && owner.valid;
|
||||
if(!isSelectable)
|
||||
selected = separated && isSelected(pl);
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
defIcon.visible = playerEmpire.isDefending(pl);
|
||||
|
||||
//Update planet name
|
||||
name.text = pl.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
if(colonized && owner !is null) {
|
||||
ownerName.color = owner.color;
|
||||
ownerName.text = owner.name;
|
||||
|
||||
if(ft.getDimension(ownerName.text).x > ownerName.size.width)
|
||||
ownerName.font = FT_Detail;
|
||||
else
|
||||
ownerName.font = FT_Normal;
|
||||
}
|
||||
else {
|
||||
ownerName.color = Color(0xaaaaaaff);
|
||||
ownerName.text = locale::UNCOLONIZED;
|
||||
ownerName.font = FT_Normal;
|
||||
}
|
||||
|
||||
//Update statuses
|
||||
{
|
||||
array<Status> statuses;
|
||||
if(pl.statusEffectCount > 0)
|
||||
statuses.syncFrom(pl.getStatusEffects());
|
||||
if(!pl.visible) {
|
||||
for(uint i = 0, cnt = statuses.length; i < cnt; ++i) {
|
||||
if(statuses[i].type.conditionFrequency <= 0 && statuses[i].type.visibility != StV_Global) {
|
||||
statuses.removeAt(i);
|
||||
--i; --cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint prevCnt = statusIcons.length, cnt = statuses.length;
|
||||
for(uint i = cnt; i < prevCnt; ++i)
|
||||
statusIcons[i].remove();
|
||||
statusIcons.length = cnt;
|
||||
statusBox.visible = cnt != 0;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
auto@ icon = statusIcons[i];
|
||||
if(icon is null) {
|
||||
@icon = GuiStatusBox(statusBox, recti_area(2, 2+32*i, 30, 30));
|
||||
icon.noClip = true;
|
||||
@statusIcons[i] = icon;
|
||||
}
|
||||
icon.update(statuses[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//Update health
|
||||
if(pl.Health < pl.MaxHealth) {
|
||||
health.progress = pl.Health / pl.MaxHealth;
|
||||
health.frontColor = colors::Red.interpolate(colors::Green, health.progress);
|
||||
health.text = standardize(pl.Health)+" / "+standardize(pl.MaxHealth);
|
||||
health.visible = true;
|
||||
}
|
||||
else {
|
||||
health.visible = false;
|
||||
}
|
||||
|
||||
//Update resources
|
||||
resources.resources.syncFrom(pl.getAllResources());
|
||||
resources.resources.sortDesc();
|
||||
resources.setSingleMode();
|
||||
|
||||
//Update cargo
|
||||
cargo.visible = pl.cargoTypes > 0;
|
||||
if(cargo.visible)
|
||||
cargo.update(pl);
|
||||
|
||||
//Update population display
|
||||
if(colonized && owner.HasPopulation != 0) {
|
||||
double pop = pl.population, maxPop = pl.maxPopulation;
|
||||
if(pop < 1.0)
|
||||
popValue.text = toString(pl.population, 1);
|
||||
else if(maxPop >= 10.0 || pop >= 10.0)
|
||||
popValue.text = toString(pl.population, 0);
|
||||
else
|
||||
popValue.text = toString(floor(pl.population), 0) + "/" + toString(pl.maxPopulation, 0);
|
||||
popValue.color = Color(0xffffffff);
|
||||
popValue.visible = true;
|
||||
popIcon.visible = true;
|
||||
}
|
||||
else {
|
||||
popValue.visible = false;
|
||||
popIcon.visible = false;
|
||||
}
|
||||
|
||||
//Update loyalty display
|
||||
if(colonized) {
|
||||
loyValue.text = toString(pl.currentLoyalty);
|
||||
loyValue.visible = true;
|
||||
loyIcon.visible = true;
|
||||
}
|
||||
else {
|
||||
loyValue.visible = false;
|
||||
loyIcon.visible = false;
|
||||
}
|
||||
|
||||
//Update construction
|
||||
uint consIndex = 0;
|
||||
if(owned) {
|
||||
if(pl.constructionCount != 0) {
|
||||
if(cons.length <= consIndex)
|
||||
cons.length = consIndex + 1;
|
||||
DataList@ list = pl.getConstructionQueue(1);
|
||||
receive(list, cons[consIndex]);
|
||||
++consIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if(cons.length > consIndex)
|
||||
cons.length = consIndex;
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(pl);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,199 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiButton;
|
||||
from input import activeCamera;
|
||||
|
||||
enum PopupAction {
|
||||
PA_Select,
|
||||
PA_Manage,
|
||||
PA_Zoom,
|
||||
};
|
||||
|
||||
class Popup : BaseGuiElement {
|
||||
GuiButton@ pinButton;
|
||||
GuiButton@ closeButton;
|
||||
|
||||
bool Hovered = false;
|
||||
bool separated = false;
|
||||
bool dragging = false;
|
||||
bool dragged = false;
|
||||
bool mouseLinked = false;
|
||||
bool objLinked = false;
|
||||
bool findPin = false;
|
||||
bool isSelectable = false;
|
||||
double zDist = 0;
|
||||
vec2i dragStart;
|
||||
vec2i objOffset;
|
||||
vec2i mouseOffset;
|
||||
|
||||
Popup(BaseGuiElement@ parent) {
|
||||
super(parent, recti(0, 0, 190, 115));
|
||||
|
||||
@closeButton = GuiButton(this, Alignment(Right-18, Top+6, Right-4, Top+20));
|
||||
closeButton.style = SS_GameTabClose;
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& evt, IGuiElement@ source) {
|
||||
//Make sure we can zoom over this
|
||||
switch(evt.type) {
|
||||
case MET_Button_Down:
|
||||
if(evt.button == 0) {
|
||||
if(isSelectable) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
dragging = true;
|
||||
dragged = false;
|
||||
dragStart = mousePos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MET_Button_Up:
|
||||
if(evt.button == 0) {
|
||||
if(dragging) {
|
||||
dragging = false;
|
||||
dragged = false;
|
||||
}
|
||||
else if(isSelectable) {
|
||||
emitClicked(PA_Select);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.button == 1 && !isSelectable) {
|
||||
if(separated)
|
||||
remove();
|
||||
else
|
||||
visible = false;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MET_Scrolled:
|
||||
if(!isSelectable)
|
||||
activeCamera.zoom(evt.y);
|
||||
return true;
|
||||
case MET_Moved:
|
||||
if(dragging) {
|
||||
if(separated) {
|
||||
vec2i moved = mousePos - dragStart;
|
||||
if(!dragged) {
|
||||
if(moved.x < 2 && moved.y < 2)
|
||||
return false;
|
||||
}
|
||||
|
||||
dragged = true;
|
||||
objLinked = false;
|
||||
move(moved);
|
||||
dragStart = mousePos;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
vec2i moved = mousePos - dragStart;
|
||||
if(moved.x < 2 && moved.y < 2)
|
||||
return false;
|
||||
|
||||
separated = true;
|
||||
objLinked = false;
|
||||
mouseLinked = false;
|
||||
dragStart = mousePos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return BaseGuiElement::onMouseEvent(evt, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
if(evt.caller is this)
|
||||
Hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
if(evt.caller is this)
|
||||
Hovered = false;
|
||||
break;
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is closeButton) {
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is pinButton) {
|
||||
separated = true;
|
||||
objLinked = shiftKey;
|
||||
mouseLinked = false;
|
||||
findPin = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void set(Object@ obj) {
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) {
|
||||
return get() is obj;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(pinButton !is null)
|
||||
pinButton.visible = !mouseLinked && !separated;
|
||||
if(closeButton !is null)
|
||||
closeButton.visible = separated;
|
||||
}
|
||||
|
||||
vec2i objPos(Object@ obj) {
|
||||
if(parent is null)
|
||||
return vec2i();
|
||||
vec2i pos = activeCamera.camera.screenPos(obj.node_position);
|
||||
pos -= parent.absolutePosition.topLeft;
|
||||
pos.x += 16;
|
||||
return pos;
|
||||
}
|
||||
|
||||
void updatePosition(Object@ obj) {
|
||||
if(parent is null)
|
||||
return;
|
||||
zDist = 0;
|
||||
if(obj !is null)
|
||||
obj.focus();
|
||||
if(objLinked && obj !is null) {
|
||||
vec2i newPos = objPos(obj);
|
||||
newPos += objOffset;
|
||||
position = newPos;
|
||||
zDist = obj.node_position.distanceToSQ(activeCamera.camera.position);
|
||||
}
|
||||
else if(mouseLinked) {
|
||||
vec2i newPos = mousePos;
|
||||
newPos -= parent.absolutePosition.topLeft;
|
||||
newPos.x += 16;
|
||||
newPos += mouseOffset;
|
||||
position = newPos;
|
||||
}
|
||||
if(closeButton !is null)
|
||||
closeButton.bringToFront();
|
||||
}
|
||||
|
||||
int opCmp(const Popup@ other) const {
|
||||
if(other is null)
|
||||
return 0;
|
||||
double diff = zDist - other.zDist;
|
||||
if(diff < 0)
|
||||
return -1;
|
||||
else if(diff > 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import overlays.Popup;
|
||||
from overlays.PlanetPopup import PlanetPopup;
|
||||
|
||||
class ObjectPopupTooltip : ITooltip {
|
||||
Popup@ pop;
|
||||
Object@ obj;
|
||||
|
||||
ObjectPopupTooltip() {
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = Obj;
|
||||
}
|
||||
|
||||
void show(const Skin@ skin, IGuiElement@ elem) {
|
||||
if(obj is null)
|
||||
return;
|
||||
if(pop is null) {
|
||||
@pop = PlanetPopup(null);
|
||||
pop.set(obj);
|
||||
pop.mouseLinked = true;
|
||||
pop.isSelectable = true;
|
||||
pop.update();
|
||||
}
|
||||
pop.visible = true;
|
||||
}
|
||||
|
||||
void hide(const Skin@ skin, IGuiElement@ elem) {
|
||||
if(pop !is null) {
|
||||
pop.remove();
|
||||
@pop = null;
|
||||
}
|
||||
}
|
||||
|
||||
float get_delay() {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
bool get_persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void update(const Skin@ skin, IGuiElement@ elem) {
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(pop is null)
|
||||
return;
|
||||
pop.update();
|
||||
}
|
||||
|
||||
void draw(const Skin@ skin, IGuiElement@ elem) {
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,660 @@
|
||||
import overlays.InfoBar;
|
||||
import elements.BaseGuiElement;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiGroupDisplay;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiStatusBox;
|
||||
import ship_groups;
|
||||
import util.formatting;
|
||||
import statuses;
|
||||
from statuses import getStatusID;
|
||||
import icons;
|
||||
from overlays.Construction import ConstructionOverlay;
|
||||
from obj_selection import isSelected, selectObject, clearSelection, addToSelection;
|
||||
from tabs.GalaxyTab import zoomTabTo, openOverlay, toggleSupportOverlay;
|
||||
|
||||
bool SHIP_INFOBAR_EXPANDED = false;
|
||||
|
||||
class ShipInfoBar : InfoBar {
|
||||
Ship@ ship;
|
||||
ConstructionOverlay@ construction;
|
||||
|
||||
GuiBlueprint@ bpdisp;
|
||||
|
||||
GuiText@ name;
|
||||
GuiText@ subsystem;
|
||||
|
||||
GuiSprite@ healthIcon;
|
||||
GuiText@ healthLabel;
|
||||
GuiProgressbar@ health;
|
||||
|
||||
GuiSprite@ supplyIcon;
|
||||
GuiText@ supplyLabel;
|
||||
GuiProgressbar@ supply;
|
||||
|
||||
GuiSprite@ strengthIcon;
|
||||
GuiText@ strengthLabel;
|
||||
GuiProgressbar@ strength;
|
||||
|
||||
GuiSkinElement@ groupBox;
|
||||
GuiGroupDisplay@ groupdisp;
|
||||
|
||||
BaseGuiElement@ buttonBar;
|
||||
GuiButton@ supportsButton;
|
||||
GuiButton@ formationButton;
|
||||
GuiButton@ ordersButton;
|
||||
|
||||
GuiProgressbar@ shield;
|
||||
GuiSprite@ shieldIcon;
|
||||
|
||||
GuiProgressbar@ exp;
|
||||
|
||||
GuiButton@ expandButton;
|
||||
|
||||
ActionBar@ actions;
|
||||
bool expanded = false;
|
||||
|
||||
array<Status> statuses;
|
||||
array<GuiStatusBox@> statusBoxes;
|
||||
|
||||
ShipInfoBar(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
@alignment = Alignment(Left, Bottom-263, Left+395, Bottom);
|
||||
|
||||
@actions = ActionBar(this, vec2i(385, 207));
|
||||
actions.noClip = true;
|
||||
|
||||
int y = -8;
|
||||
|
||||
y += 38;
|
||||
@bpdisp = GuiBlueprint(this, Alignment(Left+4, Top+y, Right-128, Bottom-70));
|
||||
bpdisp.noClip = true;
|
||||
bpdisp.popHover = true;
|
||||
bpdisp.popSize = vec2i(77, 40);
|
||||
bpdisp.horizAlign = 0.25;
|
||||
bpdisp.vertAlign = 1.0;
|
||||
bpdisp.hoverArcs = true;
|
||||
|
||||
@name = GuiText(bpdisp, Alignment(Left+12, Top+28, Right-12, Top+60));
|
||||
name.horizAlign = 0.0;
|
||||
name.vertAlign = 0.0;
|
||||
name.font = FT_Medium;
|
||||
name.stroke = colors::Black;
|
||||
name.visible = false;
|
||||
|
||||
@subsystem = GuiText(bpdisp, Alignment(Left+12, Top+28, Right-12, Top+60));
|
||||
subsystem.horizAlign = 1.0;
|
||||
subsystem.vertAlign = 0.0;
|
||||
subsystem.font = FT_Subtitle;
|
||||
subsystem.stroke = colors::Black;
|
||||
subsystem.visible = false;
|
||||
|
||||
@expandButton = GuiButton(bpdisp, Alignment(Right+75, Bottom-20, Width=20, Height=20), icons::Add);
|
||||
expandButton.noClip = true;
|
||||
expandButton.style = SS_IconButton;
|
||||
|
||||
@health = GuiProgressbar(this, Alignment(Left+8, Bottom-68, Left+200, Bottom-38));
|
||||
health.textHorizAlign = 0.9;
|
||||
|
||||
@healthIcon = GuiSprite(health, Alignment(Left-8, Top-9, Left+24, Bottom-8), icons::Health);
|
||||
healthIcon.noClip = true;
|
||||
@healthLabel = GuiText(health, Alignment(Left+23, Top, Left+100, Bottom));
|
||||
healthLabel.font = FT_Bold;
|
||||
healthLabel.text = locale::HEALTH;
|
||||
healthLabel.stroke = colors::Black;
|
||||
|
||||
@shield = GuiProgressbar(this, Alignment(Left+9, Bottom-48, Left+199, Bottom-38));
|
||||
shield.noClip = true;
|
||||
shield.textHorizAlign = 0.85;
|
||||
shield.textVertAlign = 1.65;
|
||||
shield.visible = false;
|
||||
shield.frontColor = Color(0x429cffff);
|
||||
shield.backColor = Color(0x59a8ff20);
|
||||
|
||||
@shieldIcon = GuiSprite(shield, Alignment(Right-25, Bottom-25, Width=30, Height=30), icons::Shield);
|
||||
shieldIcon.noClip = true;
|
||||
|
||||
@supply = GuiProgressbar(this, Alignment(Left+206, Bottom-68, Right-22, Bottom-38));
|
||||
supply.textHorizAlign = 0.9;
|
||||
|
||||
@supplyIcon = GuiSprite(supply, Alignment(Left-5, Top-6, Left+24, Bottom-8), icons::Supply);
|
||||
supplyIcon.noClip = true;
|
||||
@supplyLabel = GuiText(supply, Alignment(Left+23, Top, Left+100, Bottom));
|
||||
supplyLabel.font = FT_Bold;
|
||||
supplyLabel.text = locale::SUPPLY;
|
||||
supplyLabel.stroke = colors::Black;
|
||||
|
||||
@strength = GuiProgressbar(this, Alignment(Left+8, Bottom-34, Left+200, Bottom-4));
|
||||
strength.textHorizAlign = 0.9;
|
||||
|
||||
@exp = GuiProgressbar(strength, Alignment(Left, Bottom-6, Right, Bottom));
|
||||
exp.frontColor = Color(0xff009eff);
|
||||
exp.backColor = colors::Invisible;
|
||||
exp.visible = false;
|
||||
|
||||
@strengthIcon = GuiSprite(strength, Alignment(Left-5, Top-6, Left+24, Bottom-8), icons::Strength);
|
||||
strengthIcon.noClip = true;
|
||||
@strengthLabel = GuiText(strength, Alignment(Left+23, Top, Left+100, Bottom));
|
||||
strengthLabel.font = FT_Bold;
|
||||
strengthLabel.text = locale::STRENGTH;
|
||||
strengthLabel.stroke = colors::Black;
|
||||
|
||||
@groupBox = GuiSkinElement(this, Alignment(Left+206, Bottom-34, Right-22, Bottom-5), SS_PlainOverlay);
|
||||
@groupdisp = GuiGroupDisplay(groupBox, Alignment(Left+3, Top+4, Right-3, Bottom));
|
||||
groupdisp.horizAlign = 0.0;
|
||||
|
||||
updateAbsolutePosition();
|
||||
setExpanded(SHIP_INFOBAR_EXPANDED);
|
||||
}
|
||||
|
||||
void remove() override {
|
||||
if(construction !is null)
|
||||
construction.remove();
|
||||
InfoBar::remove();
|
||||
}
|
||||
|
||||
void setExpanded(bool value) {
|
||||
if(expanded == value)
|
||||
return;
|
||||
expanded = value;
|
||||
|
||||
bpdisp.alignment.set(Left+4, Top+30, Right-128, Bottom-70);
|
||||
if(expanded) {
|
||||
bpdisp.alignment.padded(0,
|
||||
-480.0/1920.0*double(screenSize.width),
|
||||
-610.0/1080.0*double(screenSize.height),
|
||||
0);
|
||||
bpdisp.horizAlign = 0.5;
|
||||
bpdisp.vertAlign = 0.5;
|
||||
expandButton.alignment.set(Right-34, Bottom-20, Right-34+28, Bottom-20+28);
|
||||
expandButton.setIcon(icons::Minus);
|
||||
}
|
||||
else {
|
||||
bpdisp.horizAlign = 0.25;
|
||||
bpdisp.vertAlign = 1.0;
|
||||
expandButton.alignment.set(Right+75, Bottom-20, Right+75+20, Bottom-20+20);
|
||||
expandButton.setIcon(icons::Add);
|
||||
}
|
||||
|
||||
bpdisp.updateAbsolutePosition();
|
||||
|
||||
bpdisp.popHover = !expanded;
|
||||
name.visible = expanded;
|
||||
subsystem.visible = expanded;
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
actions.clear();
|
||||
|
||||
if(ship.owner !is null && ship.owner.controlled) {
|
||||
actions.addBasic(ship);
|
||||
actions.addFTL(ship);
|
||||
actions.addAbilities(ship);
|
||||
actions.addEmpireAbilities(ship.owner, ship);
|
||||
actions.addScouting(ship);
|
||||
}
|
||||
|
||||
actions.init(ship);
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) override {
|
||||
return obj.isShip;
|
||||
}
|
||||
|
||||
Object@ get() override {
|
||||
return ship;
|
||||
}
|
||||
|
||||
void set(Object@ obj) override {
|
||||
@ship = cast<Ship>(obj);
|
||||
bpdisp.display(ship);
|
||||
|
||||
setExpanded(SHIP_INFOBAR_EXPANDED);
|
||||
updateActions();
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) override {
|
||||
if(obj is ship)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool showManage(Object@ obj) override {
|
||||
if(construction !is null)
|
||||
construction.remove();
|
||||
if(obj.hasConstruction && obj.owner.controlled) {
|
||||
@construction = ConstructionOverlay(findTab(), obj);
|
||||
return false;
|
||||
}
|
||||
if(!expanded)
|
||||
setExpanded(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
void toggleExpanded() {
|
||||
if(expanded == SHIP_INFOBAR_EXPANDED) {
|
||||
SHIP_INFOBAR_EXPANDED = !SHIP_INFOBAR_EXPANDED;
|
||||
setExpanded(SHIP_INFOBAR_EXPANDED);
|
||||
}
|
||||
else {
|
||||
setExpanded(!expanded);
|
||||
}
|
||||
}
|
||||
|
||||
double lastClick = -INFINITY;
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Up: {
|
||||
if(event.button == 0) {
|
||||
if(lastClick > frameTime - double(settings::iDoubleClickMS) / 1000.0) {
|
||||
selectObject(ship);
|
||||
setExpanded(!expanded);
|
||||
if(SHIP_INFOBAR_EXPANDED && !expanded)
|
||||
SHIP_INFOBAR_EXPANDED = false;
|
||||
}
|
||||
else
|
||||
lastClick = frameTime;
|
||||
}
|
||||
else if(event.button == 2) {
|
||||
zoomTabTo(ship);
|
||||
return true;
|
||||
}
|
||||
else if(event.button == 1) {
|
||||
toggleExpanded();
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
return InfoBar::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is groupdisp) {
|
||||
if(groupdisp.hovered == 0) {
|
||||
selectObject(groupdisp.leader);
|
||||
}
|
||||
else {
|
||||
if(!shiftKey)
|
||||
clearSelection();
|
||||
Object@ leader = groupdisp.leader;
|
||||
GroupData@ dat = groupdisp.groups[groupdisp.hovered-1];
|
||||
for(uint i = 0, cnt = leader.supportCount; i < cnt; ++i) {
|
||||
Ship@ supp = cast<Ship>(leader.supportShip[i]);
|
||||
if(supp !is null && supp.valid && supp.blueprint.design is dat.dsg)
|
||||
addToSelection(supp);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is expandButton) {
|
||||
toggleExpanded();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GUI_Hover_Changed:
|
||||
if(evt.caller is bpdisp) {
|
||||
updateHealthBar();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return InfoBar::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void updateHealthBar() {
|
||||
if(ship is null)
|
||||
return;
|
||||
|
||||
const Blueprint@ bp = ship.blueprint;
|
||||
const Design@ design = bp.design;
|
||||
const Hull@ hull = design.hull;
|
||||
|
||||
Color high;
|
||||
Color low;
|
||||
|
||||
double curHP = 0, maxHP = 1;
|
||||
if(bpdisp.hexHovered.x < 0 || bpdisp.hexHovered.y < 0) {
|
||||
curHP = bp.currentHP * bp.hpFactor;
|
||||
maxHP = (design.totalHP - bp.removedHP) * bp.hpFactor;
|
||||
|
||||
high = Color(0x00ff00ff);
|
||||
low = Color(0xff0000ff);
|
||||
|
||||
subsystem.visible = false;
|
||||
}
|
||||
else {
|
||||
ObjectLock lock(ship, true);
|
||||
vec2u hex = vec2u(bpdisp.hexHovered);
|
||||
const HexStatus@ status = bp.getHexStatus(hex.x, hex.y);
|
||||
if(status !is null) {
|
||||
maxHP = design.variable(hex, HV_HP) * bp.hpFactor;
|
||||
curHP = maxHP * double(status.hp) / double(0xff);
|
||||
}
|
||||
|
||||
high = Color(0x9768ffff);
|
||||
low = Color(0xff689bff);
|
||||
|
||||
auto@ sys = design.subsystem(hex);
|
||||
auto@ mod = design.module(hex);
|
||||
if(sys !is null && expanded) {
|
||||
subsystem.visible = true;
|
||||
if(mod is null || mod is sys.type.coreModule || mod is sys.type.defaultModule) {
|
||||
if(mod is sys.type.coreModule)
|
||||
subsystem.text = format("$1 ($2)", sys.type.name, locale::SUBSYS_CORE);
|
||||
else
|
||||
subsystem.text = sys.type.name;
|
||||
subsystem.color = sys.type.color;
|
||||
}
|
||||
else {
|
||||
subsystem.text = mod.name;
|
||||
subsystem.color = mod.color;
|
||||
}
|
||||
}
|
||||
else {
|
||||
subsystem.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ship.visible)
|
||||
curHP = maxHP;
|
||||
|
||||
health.progress = curHP / maxHP;
|
||||
health.frontColor = low.interpolate(high, health.progress);
|
||||
health.text = standardize(curHP)+" / "+standardize(maxHP);
|
||||
|
||||
double repair = 0.0, combatMod = 1.0;
|
||||
if(design !is null) {
|
||||
repair = design.total(SV_Repair);
|
||||
combatMod *= min(bp.shipEffectiveness, 1.0);
|
||||
}
|
||||
|
||||
string tt = format(locale::TT_SHIP_HEALTH,
|
||||
standardize(curHP), standardize(maxHP),
|
||||
standardize(repair * 1.0/3.0 * combatMod), standardize(repair));
|
||||
|
||||
//Update shields
|
||||
double curShield = ship.Shield;
|
||||
double maxShield = ship.MaxShield;
|
||||
|
||||
if(maxShield != 0) {
|
||||
shield.visible = true;
|
||||
health.textHorizAlign = 0.25;
|
||||
healthLabel.visible = false;
|
||||
|
||||
shield.progress = min(curShield / max(maxShield, 0.01), 1.0);
|
||||
shield.text = standardize(curShield, true);
|
||||
|
||||
double shieldRegen = design.total(SV_ShieldRegen);
|
||||
tt += "\n\n";
|
||||
tt += format(locale::TT_SHIP_SHIELD,
|
||||
standardize(curShield), standardize(maxShield),
|
||||
standardize(shieldRegen));
|
||||
}
|
||||
else {
|
||||
shield.visible = false;
|
||||
health.textHorizAlign = 0.9;
|
||||
healthLabel.visible = true;
|
||||
}
|
||||
|
||||
setMarkupTooltip(health, tt, width = 350);
|
||||
@shield.tooltipObject = health.tooltipObject;
|
||||
}
|
||||
|
||||
void updateStrengthBar() {
|
||||
if(groupdisp.leader is null) {
|
||||
strength.progress = 0.f;
|
||||
strength.text = "-";
|
||||
setMarkupTooltip(strength, "");
|
||||
return;
|
||||
}
|
||||
|
||||
Ship@ leader = cast<Ship>(groupdisp.leader);
|
||||
const Design@ design;
|
||||
if(leader !is null)
|
||||
@design = leader.blueprint.design;
|
||||
|
||||
double curStr = groupdisp.leader.getFleetStrength() * 0.001;
|
||||
double totStr = groupdisp.leader.getFleetMaxStrength() * 0.001;
|
||||
|
||||
if(!ship.visible)
|
||||
curStr = totStr;
|
||||
|
||||
if(totStr == 0) {
|
||||
strength.progress = 0.f;
|
||||
strength.frontColor = Color(0xff6a00ff);
|
||||
strength.text = "-";
|
||||
}
|
||||
else {
|
||||
strength.progress = curStr / totStr;
|
||||
if(strength.progress > 1.001f) {
|
||||
strength.progress = 1.f;
|
||||
strength.font = FT_Bold;
|
||||
}
|
||||
else {
|
||||
strength.font = FT_Normal;
|
||||
}
|
||||
|
||||
strength.frontColor = Color(0xff6a00ff).interpolate(Color(0xffc600ff), strength.progress);
|
||||
strength.text = standardize(curStr);
|
||||
}
|
||||
|
||||
double dps = groupdisp.leader.getFleetDPS();
|
||||
double hp = groupdisp.leader.getFleetHP();
|
||||
|
||||
float curEff = groupdisp.leader.getFleetEffectiveness();
|
||||
float baseEff = groupdisp.leader.getBaseFleetEffectiveness();
|
||||
float eff = curEff / baseEff;
|
||||
|
||||
string tt = format(locale::TT_SHIP_STRENGTH,
|
||||
standardize(curStr), standardize(totStr),
|
||||
standardize(hp), standardize(dps),
|
||||
toString(eff*100.f, 0)+"%");
|
||||
if(baseEff != 1.f)
|
||||
tt += "\n"+format(locale::TT_SHIP_EFF_BONUS,
|
||||
toString((baseEff-1.f)*100.f, 0)+"%");
|
||||
|
||||
if(design !is null) {
|
||||
int curLevel = groupdisp.leader.getStatusStackCountAny(levelStatus);
|
||||
double needExp = groupdisp.leader.getRemainingExp();
|
||||
double totalExp = design.size * (config::EXPERIENCE_BASE_AMOUNT + config::EXPERIENCE_INCREASE_AMOUNT * curLevel);
|
||||
|
||||
if(config::EXPERIENCE_GAIN_FACTOR != 0 && totalExp != 0) {
|
||||
exp.progress = 1.0 - (needExp / totalExp);
|
||||
exp.visible = true;
|
||||
|
||||
tt += "\n\n";
|
||||
tt += format(locale::TT_SHIP_EXPERIENCE,
|
||||
toString(needExp, 0), toString(totalExp, 0),
|
||||
toString(curLevel, 0), toString(totalExp-needExp, 0));
|
||||
}
|
||||
else {
|
||||
exp.visible = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
exp.visible = false;
|
||||
}
|
||||
|
||||
setMarkupTooltip(strength, tt, width = 350);
|
||||
}
|
||||
|
||||
void updateSupplyBar() {
|
||||
double curSup = 0.0;
|
||||
double totSup = 0.0;
|
||||
|
||||
Ship@ leader = cast<Ship>(groupdisp.leader);
|
||||
const Design@ design;
|
||||
if(leader !is null) {
|
||||
curSup = leader.Supply;
|
||||
totSup = leader.MaxSupply;
|
||||
@design = leader.blueprint.design;
|
||||
}
|
||||
|
||||
if(!ship.visible)
|
||||
curSup = totSup;
|
||||
|
||||
if(totSup == 0) {
|
||||
supply.progress = 0.f;
|
||||
supply.frontColor = Color(0xff6a00ff);
|
||||
supply.text = "-";
|
||||
}
|
||||
else {
|
||||
supply.progress = curSup / totSup;
|
||||
if(supply.progress > 1.001f) {
|
||||
supply.progress = 1.f;
|
||||
supply.font = FT_Bold;
|
||||
}
|
||||
else {
|
||||
supply.font = FT_Normal;
|
||||
}
|
||||
|
||||
if(supply.progress < 0.4f)
|
||||
supply.frontColor = Color(0xd53f1eff).interpolate(Color(0xd5cc1eff), supply.progress/0.4f);
|
||||
else
|
||||
supply.frontColor = Color(0x4a9487ff);
|
||||
supply.text = standardize(curSup);
|
||||
}
|
||||
|
||||
double resupply = 0.0;
|
||||
if(design !is null)
|
||||
resupply = design.total(SV_SupplyRate);
|
||||
setMarkupTooltip(supply, format(locale::TT_SHIP_SUPPLY,
|
||||
standardize(curSup), standardize(totSup),
|
||||
standardize(resupply * 0.12f), standardize(resupply)),
|
||||
width = 350);
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) override {
|
||||
IGuiElement@ elem = BaseGuiElement::elementFromPosition(pos);
|
||||
if(!expanded && (elem is this || elem is bpdisp)) {
|
||||
vec2i relPos = pos - AbsolutePosition.topLeft;
|
||||
bool active = material::ShipInfoBar.isPixelActive(relPos);
|
||||
if(!active)
|
||||
return null;
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
double updateTimer = 1.0;
|
||||
void update(double time) override {
|
||||
Empire@ owner = ship.owner;
|
||||
bool owned = owner is playerEmpire;
|
||||
const Blueprint@ bp = ship.blueprint;
|
||||
const Design@ design = bp.design;
|
||||
const Hull@ hull = design.hull;
|
||||
|
||||
if(expanded && !SHIP_INFOBAR_EXPANDED && !ship.selected)
|
||||
setExpanded(false);
|
||||
|
||||
if(design !is bpdisp.design)
|
||||
set(ship);
|
||||
|
||||
if(ship.visible) {
|
||||
@bpdisp.bp = bp;
|
||||
groupdisp.visible = true;
|
||||
}
|
||||
else {
|
||||
@bpdisp.bp = null;
|
||||
groupdisp.visible = false;
|
||||
}
|
||||
|
||||
if(construction !is null) {
|
||||
if(construction.parent is null) {
|
||||
@construction = null;
|
||||
visible = true;
|
||||
}
|
||||
else
|
||||
construction.update(time);
|
||||
}
|
||||
|
||||
//Update ship data
|
||||
name.font = FT_Medium;
|
||||
name.text = formatShipName(ship);
|
||||
if(owner !is null)
|
||||
name.color = owner.color;
|
||||
vec2i dim = name.getTextDimension();
|
||||
int w = clamp(dim.x+26, 160, 1000);
|
||||
if(dim.x > name.size.width) {
|
||||
name.font = FT_Bold;
|
||||
dim = name.getTextDimension();
|
||||
if(dim.x > name.size.width)
|
||||
name.font = FT_Small;
|
||||
}
|
||||
|
||||
//Update statuses
|
||||
Object@ leader = groupdisp.leader;
|
||||
if(leader !is null && leader.statusEffectCount > 0)
|
||||
statuses.syncFrom(leader.getStatusEffects());
|
||||
else
|
||||
statuses.length = 0;
|
||||
|
||||
updateStatusBoxes(bpdisp, statuses, statusBoxes, fromObject=leader);
|
||||
int off = expanded ? -70 : 30;
|
||||
for(uint i = 0, cnt = statusBoxes.length; i < cnt; ++i) {
|
||||
statusBoxes[i].noClip = true;
|
||||
statusBoxes[i].rect = recti_area(bpdisp.size.width+off-36*i, bpdisp.size.height-26, 32,32);
|
||||
}
|
||||
|
||||
//Update whatever health is displayed
|
||||
updateHealthBar();
|
||||
updateSupplyBar();
|
||||
updateStrengthBar();
|
||||
|
||||
//Update group
|
||||
groupdisp.update(ship);
|
||||
|
||||
updateTimer -= time;
|
||||
if(updateTimer <= 0) {
|
||||
updateTimer = 1.0;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
InfoBar::update(time);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
Color col;
|
||||
Empire@ owner = ship.owner;
|
||||
if(owner !is null)
|
||||
col = owner.color;
|
||||
|
||||
if(!expanded)
|
||||
material::ShipInfoBar.draw(AbsolutePosition.padded(0,0,0,35), col);
|
||||
else {
|
||||
skin.draw(SS_Panel, SF_Normal, bpdisp.absolutePosition.padded(-20,0,0,-100), col);
|
||||
skin.draw(SS_BG3D, SF_Normal, bpdisp.absolutePosition.padded(0,4,4,-12), col);
|
||||
}
|
||||
|
||||
if(actions.visible) {
|
||||
recti pos = actions.absolutePosition;
|
||||
skin.draw(SS_Panel, SF_Normal, recti(pos.topLeft - vec2i(50, 0), pos.botRight + vec2i(0, 20)));
|
||||
}
|
||||
|
||||
skin.draw(SS_InfoBar, SF_Normal, recti_area(vec2i(AbsolutePosition.topLeft.x, AbsolutePosition.botRight.y-40), vec2i(AbsolutePosition.width-13, 45)));
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
InfoBar@ makeShipInfoBar(IGuiElement@ parent, Object@ obj) {
|
||||
ShipInfoBar bar(parent);
|
||||
bar.set(obj);
|
||||
return bar;
|
||||
}
|
||||
|
||||
import void resetGalaxyTabs() from "tabs.GalaxyTab";
|
||||
void postReload(Message& msg) {
|
||||
resetGalaxyTabs();
|
||||
}
|
||||
|
||||
int levelStatus = -1;
|
||||
void init() {
|
||||
levelStatus = getStatusID("ShipLevel");
|
||||
}
|
||||
@@ -0,0 +1,549 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.GuiImage;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiGroupDisplay;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiStatusBox;
|
||||
import elements.GuiCargoDisplay;
|
||||
import constructible;
|
||||
import util.constructible_view;
|
||||
import ship_groups;
|
||||
import icons;
|
||||
import biomes;
|
||||
import statuses;
|
||||
from statuses import getStatusID;
|
||||
import util.icon_view;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
from obj_selection import isSelected, selectObject, clearSelection, addToSelection;
|
||||
|
||||
class ShipPopup : Popup {
|
||||
Object@ origObject;
|
||||
Ship@ ship;
|
||||
|
||||
Constructible cons;
|
||||
bool hasConstruction = false;
|
||||
|
||||
array<GuiStatusBox@> statusIcons;
|
||||
GuiBlueprint@ bpdisp;
|
||||
GuiText@ name;
|
||||
GuiText@ ownerName;
|
||||
|
||||
GuiSprite@ shieldIcon;
|
||||
GuiProgressbar@ health;
|
||||
GuiProgressbar@ strength;
|
||||
GuiProgressbar@ exp;
|
||||
GuiProgressbar@ shield;
|
||||
GuiProgressbar@ supply;
|
||||
|
||||
GuiCargoDisplay@ cargo;
|
||||
GuiGroupDisplay@ groupdisp;
|
||||
|
||||
bool selected = false;
|
||||
|
||||
ShipPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(190, 220);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+40, Top+6, Right-4, Top+28));
|
||||
@ownerName = GuiText(this, Alignment(Left+40, Top+28, Right-6, Top+46));
|
||||
ownerName.horizAlign = 1.0;
|
||||
|
||||
@bpdisp = GuiBlueprint(this, Alignment(Left+4, Top+50, Right-4, Bottom-80));
|
||||
bpdisp.popHover = true;
|
||||
bpdisp.popSize = vec2i(77, 40);
|
||||
|
||||
@cargo = GuiCargoDisplay(bpdisp, Alignment(Left, Top, Right, Top+25));
|
||||
|
||||
GuiSkinElement band(this, Alignment(Left+3, Bottom-80, Right-4, Bottom-50), SS_NULL);
|
||||
|
||||
@health = GuiProgressbar(band, Alignment(Left, Top, Right, Bottom));
|
||||
health.tooltip = locale::HEALTH;
|
||||
|
||||
@shield = GuiProgressbar(band, Alignment(Left+1, Top+20, Right-1, Bottom));
|
||||
shield.noClip = true;
|
||||
shield.tooltip = locale::SHIELD_STRENGTH;
|
||||
shield.textHorizAlign = 0.85;
|
||||
shield.textVertAlign = 1.65;
|
||||
shield.visible = false;
|
||||
shield.frontColor = Color(0x429cffff);
|
||||
shield.backColor = Color(0x59a8ff20);
|
||||
|
||||
GuiSprite healthIcon(band, Alignment(Left, Top, Width=30, Height=30), icons::Health);
|
||||
healthIcon.noClip = true;
|
||||
|
||||
@shieldIcon = GuiSprite(band, Alignment(Right-23, Bottom-23, Width=30, Height=30), icons::Shield);
|
||||
shieldIcon.visible = false;
|
||||
|
||||
GuiSkinElement strband(this, Alignment(Left+3, Bottom-50, Right-4, Bottom-30), SS_NULL);
|
||||
|
||||
@strength = GuiProgressbar(strband, Alignment(Left+0, Top, Right-0.5f, Bottom));
|
||||
strength.tooltip = locale::FLEET_STRENGTH;
|
||||
|
||||
@exp = GuiProgressbar(strength, Alignment(Left, Bottom-4, Right, Bottom));
|
||||
exp.frontColor = Color(0xff009eff);
|
||||
exp.backColor = colors::Invisible;
|
||||
exp.visible = false;
|
||||
|
||||
GuiSprite strIcon(strband, Alignment(Left, Top, Left+24, Bottom), icons::Strength);
|
||||
|
||||
@supply = GuiProgressbar(strband, Alignment(Left+0.5f, Top, Right-1, Bottom));
|
||||
supply.tooltip = locale::SUPPLY;
|
||||
|
||||
GuiSprite supIcon(strband, Alignment(Right-24, Top, Right, Bottom), icons::Supply);
|
||||
|
||||
@groupdisp = GuiGroupDisplay(this, Alignment(Left+8, Bottom-31, Right-8, Bottom-3));
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void remove() {
|
||||
Popup::remove();
|
||||
}
|
||||
|
||||
bool compatible(Object@ obj) {
|
||||
return cast<Ship>(obj) !is null;
|
||||
}
|
||||
|
||||
void set(Object@ obj) {
|
||||
if(!obj.valid)
|
||||
return;
|
||||
if(origObject is null)
|
||||
@origObject = obj;
|
||||
@ship = cast<Ship>(obj);
|
||||
bpdisp.display(ship);
|
||||
|
||||
if(ship.MaxShield > 0) {
|
||||
shield.visible = true;
|
||||
shieldIcon.visible = true;
|
||||
health.textHorizAlign = 0.3;
|
||||
health.textVertAlign = 0.25;
|
||||
}
|
||||
else {
|
||||
shield.visible = false;
|
||||
shieldIcon.visible = false;
|
||||
health.textHorizAlign = 0.5;
|
||||
health.textVertAlign = 0.5;
|
||||
}
|
||||
statusUpdate = 0.f;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return ship;
|
||||
}
|
||||
|
||||
bool displays(Object@ obj) {
|
||||
return obj is ship;
|
||||
}
|
||||
|
||||
double dblClick = 0;
|
||||
bool onMouseEvent(const MouseEvent& evt, IGuiElement@ source) {
|
||||
if(source is name) {
|
||||
switch(evt.type) {
|
||||
case MET_Button_Up:
|
||||
if(evt.button == 0 && !dragged) {
|
||||
dragging = false;
|
||||
if(size.width == 800)
|
||||
size = vec2i(1200, 910);
|
||||
else if(size.width == 380)
|
||||
size = vec2i(800, 640);
|
||||
else if(size.width == 190)
|
||||
size = vec2i(380, 360);
|
||||
else
|
||||
size = vec2i(190, 220);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(source is bpdisp) {
|
||||
switch(evt.type) {
|
||||
case MET_Button_Up:
|
||||
if(!dragged) {
|
||||
dragging = false;
|
||||
if(evt.button == 0) {
|
||||
if(frameTime < dblClick) {
|
||||
emitClicked(PA_Manage);
|
||||
}
|
||||
else {
|
||||
emitClicked(PA_Select);
|
||||
dblClick = frameTime + 0.2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(evt.button == 1) {
|
||||
openContextMenu(ship);
|
||||
return true;
|
||||
}
|
||||
else if(evt.button == 2) {
|
||||
emitClicked(PA_Zoom);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return Popup::onMouseEvent(evt, source);
|
||||
}
|
||||
|
||||
vec2i objPos(Object@ obj) {
|
||||
return Popup::objPos(origObject);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is groupdisp) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
if(groupdisp.hovered == 0) {
|
||||
if(cast<Ship>(groupdisp.leader) !is null) {
|
||||
selectObject(groupdisp.leader);
|
||||
set(groupdisp.leader);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!shiftKey)
|
||||
clearSelection();
|
||||
Object@ leader = groupdisp.leader;
|
||||
GroupData@ dat = groupdisp.groups[groupdisp.hovered-1];
|
||||
bool found = false;
|
||||
for(uint i = 0, cnt = leader.supportCount; i < cnt; ++i) {
|
||||
Ship@ supp = cast<Ship>(leader.supportShip[i]);
|
||||
if(supp !is null && supp.blueprint.design is dat.dsg) {
|
||||
addToSelection(supp);
|
||||
if(!found) {
|
||||
set(supp);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GUI_Hover_Changed:
|
||||
if(evt.caller is bpdisp) {
|
||||
updateHealthBar();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(ship);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
if(selected)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
Color col(0xffffffff);
|
||||
Empire@ owner;
|
||||
if(ship !is null) {
|
||||
@owner = ship.owner;
|
||||
if(owner !is null)
|
||||
col = owner.color;
|
||||
}
|
||||
|
||||
skin.draw(SS_ShipPopupBG, flags, bgPos, col);
|
||||
|
||||
if(owner !is null && owner.flag !is null) {
|
||||
vec2i s = bpdisp.absolutePosition.size;
|
||||
owner.flag.draw(
|
||||
bpdisp.absolutePosition
|
||||
.resized(s.x*0.5, s.y*0.5, 1.0, 0.0)
|
||||
.aspectAligned(1.0, horizAlign=1.0, vertAlign=0.0),
|
||||
owner.color * Color(0xffffff40));
|
||||
}
|
||||
|
||||
skin.draw(SS_SubTitle, SF_Normal, recti_area(bgPos.topLeft + vec2i(2,2), vec2i(bgPos.width-5, 50-4)), col);
|
||||
drawFleetIcon(ship, recti_area(bgPos.topLeft+vec2i(-2, 2), vec2i(46,46)), showStrength=false);
|
||||
|
||||
bpdisp.draw();
|
||||
|
||||
//Construction display
|
||||
if(hasConstruction) {
|
||||
recti plPos = bpdisp.absolutePosition;
|
||||
plPos.topLeft.y += plPos.height / 2;
|
||||
drawRectangle(plPos, Color(0x00000040));
|
||||
|
||||
const Font@ ft = skin.getFont(FT_Small);
|
||||
int sz = ft.getLineHeight() * 2 + 6;
|
||||
Color nameCol(0xffffffff);
|
||||
if(!cons.started)
|
||||
nameCol = Color(0xff0000ff);
|
||||
ft.draw(plPos.resized(0, sz, 0.0, 1.0),
|
||||
cons.name, locale::ELLIPSIS, nameCol, 0.5, 0.0);
|
||||
|
||||
string prog = toString(cons.progress * 100.f, 0)+"%";
|
||||
if(cons.type == CT_DryDock)
|
||||
prog += " / "+toString(cons.pct * 100.f, 0)+"%";
|
||||
ft.draw(plPos.resized(0, sz - ft.getLineHeight(), 0.0, 1.0),
|
||||
prog, locale::ELLIPSIS, Color(0xffffffff), 0.5, 0.0);
|
||||
|
||||
drawConstructible(cons, plPos.resized(0, plPos.size.height - sz + 6));
|
||||
}
|
||||
|
||||
if(cargo.visible)
|
||||
drawRectangle(cargo.absolutePosition, Color(0x00000040));
|
||||
|
||||
bpdisp.visible = false;
|
||||
Popup::draw();
|
||||
bpdisp.visible = true;
|
||||
}
|
||||
|
||||
void updateHealthBar() {
|
||||
if(ship is null)
|
||||
return;
|
||||
|
||||
const Blueprint@ bp = ship.blueprint;
|
||||
const Design@ design = bp.design;
|
||||
const Hull@ hull = design.hull;
|
||||
|
||||
Color high;
|
||||
Color low;
|
||||
|
||||
double curHP = 0, maxHP = 1;
|
||||
if(bpdisp.hexHovered.x < 0 || bpdisp.hexHovered.y < 0) {
|
||||
curHP = bp.currentHP * bp.hpFactor;
|
||||
maxHP = (design.totalHP - bp.removedHP) * bp.hpFactor;
|
||||
|
||||
high = Color(0x00ff00ff);
|
||||
low = Color(0xff0000ff);
|
||||
}
|
||||
else {
|
||||
vec2u hex = vec2u(bpdisp.hexHovered);
|
||||
const HexStatus@ status = bp.getHexStatus(hex.x, hex.y);
|
||||
if(status !is null) {
|
||||
maxHP = design.variable(hex, HV_HP) * bp.hpFactor;
|
||||
curHP = maxHP * double(status.hp) / double(0xff);
|
||||
}
|
||||
|
||||
high = Color(0x9768ffff);
|
||||
low = Color(0xff689bff);
|
||||
}
|
||||
|
||||
if(!ship.visible)
|
||||
curHP = maxHP;
|
||||
|
||||
health.progress = curHP / maxHP;
|
||||
health.frontColor = low.interpolate(high, health.progress);
|
||||
if(shield.visible)
|
||||
health.text = standardize(curHP);
|
||||
else
|
||||
health.text = standardize(curHP)+" / "+standardize(maxHP);
|
||||
}
|
||||
|
||||
void updateStrengthBar() {
|
||||
if(groupdisp.leader is null)
|
||||
return;
|
||||
|
||||
double curStr = groupdisp.leader.getFleetStrength() * 0.001;
|
||||
double totStr = groupdisp.leader.getFleetMaxStrength() * 0.001;
|
||||
|
||||
Ship@ leader = cast<Ship>(groupdisp.leader);
|
||||
const Design@ design;
|
||||
if(leader !is null)
|
||||
@design = leader.blueprint.design;
|
||||
|
||||
if(!ship.visible)
|
||||
curStr = totStr;
|
||||
|
||||
if(totStr == 0) {
|
||||
strength.progress = 0.f;
|
||||
strength.frontColor = Color(0xff6a00ff);
|
||||
strength.text = "--";
|
||||
}
|
||||
else {
|
||||
strength.progress = curStr / totStr;
|
||||
if(strength.progress > 1.001f) {
|
||||
strength.progress = 1.f;
|
||||
strength.font = FT_Bold;
|
||||
}
|
||||
else {
|
||||
strength.font = FT_Normal;
|
||||
}
|
||||
|
||||
strength.frontColor = Color(0xff6a00ff).interpolate(Color(0xffc600ff), strength.progress);
|
||||
strength.text = standardize(curStr);
|
||||
strength.tooltip = locale::FLEET_STRENGTH+": "+standardize(curStr)+"/"+standardize(totStr);
|
||||
}
|
||||
|
||||
if(design !is null) {
|
||||
int curLevel = groupdisp.leader.getStatusStackCountAny(levelStatus);
|
||||
double needExp = groupdisp.leader.getRemainingExp();
|
||||
double totalExp = design.size * (config::EXPERIENCE_BASE_AMOUNT + config::EXPERIENCE_INCREASE_AMOUNT * curLevel);
|
||||
|
||||
if(config::EXPERIENCE_GAIN_FACTOR != 0 && totalExp != 0) {
|
||||
exp.progress = 1.0 - (needExp / totalExp);
|
||||
exp.visible = true;
|
||||
}
|
||||
else {
|
||||
exp.visible = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
exp.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSupplyBar() {
|
||||
double curSup = 0.0;
|
||||
double totSup = 0.0;
|
||||
|
||||
Ship@ leader = cast<Ship>(groupdisp.leader);
|
||||
if(ship.MaxSupply >= 0) {
|
||||
curSup = ship.Supply;
|
||||
totSup = ship.MaxSupply;
|
||||
}
|
||||
else if(leader !is null) {
|
||||
curSup = leader.Supply;
|
||||
totSup = leader.MaxSupply;
|
||||
}
|
||||
|
||||
if(!ship.visible)
|
||||
curSup = totSup;
|
||||
|
||||
if(totSup == 0) {
|
||||
supply.progress = 0.f;
|
||||
supply.frontColor = Color(0xff6a00ff);
|
||||
supply.text = "--";
|
||||
}
|
||||
else {
|
||||
supply.progress = curSup / totSup;
|
||||
if(supply.progress > 1.001f) {
|
||||
supply.progress = 1.f;
|
||||
supply.font = FT_Bold;
|
||||
}
|
||||
else {
|
||||
supply.font = FT_Normal;
|
||||
}
|
||||
|
||||
if(supply.progress < 0.5f)
|
||||
supply.frontColor = Color(0xd53f1eff).interpolate(Color(0xd5cc1eff), supply.progress/0.5f);
|
||||
else
|
||||
supply.frontColor = Color(0x4a9487ff);
|
||||
supply.text = standardize(curSup);
|
||||
supply.tooltip = locale::SUPPLY+": "+standardize(curSup)+"/"+standardize(totSup);
|
||||
}
|
||||
}
|
||||
|
||||
float statusUpdate = 0.f;
|
||||
void update() {
|
||||
if(ship is null)
|
||||
return;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
Empire@ owner = ship.owner;
|
||||
bool owned = ship.owner is playerEmpire;
|
||||
const Blueprint@ bp = ship.blueprint;
|
||||
const Design@ design = bp.design;
|
||||
const Hull@ hull = design.hull;
|
||||
|
||||
if(design !is bpdisp.design)
|
||||
set(ship);
|
||||
|
||||
if(ship.visible) {
|
||||
@bpdisp.bp = bp;
|
||||
groupdisp.visible = true;
|
||||
}
|
||||
else {
|
||||
@bpdisp.bp = null;
|
||||
groupdisp.visible = false;
|
||||
}
|
||||
|
||||
//Update name
|
||||
name.text = formatShipName(ship);
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
//Update owner
|
||||
if(owner !is null) {
|
||||
ownerName.color = owner.color;
|
||||
ownerName.text = owner.name;
|
||||
|
||||
if(ft.getDimension(ownerName.text).x > ownerName.size.width)
|
||||
ownerName.font = FT_Detail;
|
||||
else
|
||||
ownerName.font = FT_Normal;
|
||||
}
|
||||
|
||||
//Update whatever health is displayed
|
||||
updateHealthBar();
|
||||
|
||||
//Update the strength display
|
||||
updateStrengthBar();
|
||||
|
||||
//Update the supply display
|
||||
updateSupplyBar();
|
||||
|
||||
//Update cargo
|
||||
cargo.visible = ship.hasCargo && ship.cargoTypes > 0;
|
||||
if(cargo.visible)
|
||||
cargo.update(ship);
|
||||
|
||||
//Update construction
|
||||
if(owned && ship.hasConstruction) {
|
||||
DataList@ list = ship.getConstructionQueue(1);
|
||||
hasConstruction = receive(list, cons);
|
||||
}
|
||||
else {
|
||||
hasConstruction = false;
|
||||
}
|
||||
|
||||
//Update statuses
|
||||
statusUpdate -= frameLength;
|
||||
if(statusUpdate <= 0.f) {
|
||||
array<Status> statuses;
|
||||
if(ship.visible && ship.statusEffectCount > 0)
|
||||
statuses.syncFrom(ship.getStatusEffects());
|
||||
uint prevCnt = statusIcons.length, cnt = statuses.length;
|
||||
for(uint i = cnt; i < prevCnt; ++i)
|
||||
statusIcons[i].remove();
|
||||
statusIcons.length = cnt;
|
||||
int y = 50;
|
||||
if(cargo.visible)
|
||||
y += 25;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
auto@ icon = statusIcons[i];
|
||||
if(icon is null) {
|
||||
@icon = GuiStatusBox(this, recti_area(6, y+25*i, 25, 25));
|
||||
icon.noClip = true;
|
||||
@statusIcons[i] = icon;
|
||||
}
|
||||
icon.update(statuses[i]);
|
||||
}
|
||||
statusUpdate += 1.f;
|
||||
}
|
||||
|
||||
//Update energy display
|
||||
if(shield.visible) {
|
||||
float curshield = ship.Shield;
|
||||
float maxshield = max(ship.MaxShield, 0.01);
|
||||
|
||||
shield.progress = min(curshield / maxshield, 1.0);
|
||||
shield.text = standardize(curshield, true);
|
||||
shield.tooltip = locale::SHIELD_STRENGTH+": "+standardize(curshield)+" / "+standardize(maxshield);
|
||||
}
|
||||
|
||||
//Update group
|
||||
groupdisp.update(ship);
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(ship);
|
||||
}
|
||||
};
|
||||
|
||||
int levelStatus = -1;
|
||||
void init() {
|
||||
levelStatus = getStatusID("ShipLevel");
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import overlays.Popup;
|
||||
import elements.GuiText;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.Gui3DObject;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.MarkupTooltip;
|
||||
import icons;
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
|
||||
class StarPopup : Popup {
|
||||
GuiText@ name;
|
||||
Gui3DObject@ objView;
|
||||
Star@ obj;
|
||||
double lastUpdate = -INFINITY;
|
||||
|
||||
GuiSprite@ defIcon;
|
||||
|
||||
GuiProgressbar@ health;
|
||||
|
||||
StarPopup(BaseGuiElement@ parent) {
|
||||
super(parent);
|
||||
size = vec2i(150, 110);
|
||||
|
||||
@name = GuiText(this, Alignment(Left+4, Top+2, Right-4, Top+24));
|
||||
name.horizAlign = 0.5;
|
||||
|
||||
@objView = Gui3DObject(this, Alignment(Left+4, Top+25, Right-4, Bottom-4));
|
||||
|
||||
@defIcon = GuiSprite(this, Alignment(Left+4, Top+25, Width=40, Height=40));
|
||||
defIcon.desc = icons::Defense;
|
||||
setMarkupTooltip(defIcon, locale::TT_IS_DEFENDING);
|
||||
defIcon.visible = false;
|
||||
|
||||
@health = GuiProgressbar(this, Alignment(Left+8, Top+28, Right-8, Top+50));
|
||||
health.visible = false;
|
||||
|
||||
auto@ healthIcon = GuiSprite(health, Alignment(Left-8, Top-9, Left+24, Bottom-8), icons::Health);
|
||||
healthIcon.noClip = true;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool compatible(Object@ Obj) {
|
||||
return Obj.isStar;
|
||||
}
|
||||
|
||||
void set(Object@ Obj) {
|
||||
@obj = cast<Star>(Obj);
|
||||
@objView.object = Obj;
|
||||
lastUpdate = -INFINITY;
|
||||
}
|
||||
|
||||
Object@ get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
Popup::updatePosition(obj);
|
||||
recti bgPos = AbsolutePosition;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
SkinStyle style = SS_GenericPopupBG;
|
||||
if(isSelectable && Hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
Color col;
|
||||
Region@ reg = obj.region;
|
||||
if(reg !is null) {
|
||||
Empire@ other = reg.visiblePrimaryEmpire;
|
||||
if(other !is null)
|
||||
col = other.color;
|
||||
}
|
||||
|
||||
skin.draw(style, flags, bgPos, col);
|
||||
if(obj.owner !is null && obj.owner.flag !is null) {
|
||||
obj.owner.flag.draw(
|
||||
objView.absolutePosition.aspectAligned(1.0, horizAlign=1.0, vertAlign=1.0),
|
||||
obj.owner.color * Color(0xffffff30));
|
||||
}
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is objView) {
|
||||
dragging = false;
|
||||
if(!dragged) {
|
||||
switch(evt.value) {
|
||||
case OA_LeftClick:
|
||||
emitClicked(PA_Select);
|
||||
return true;
|
||||
case OA_RightClick:
|
||||
openContextMenu(obj);
|
||||
return true;
|
||||
case OA_MiddleClick:
|
||||
case OA_DoubleClick:
|
||||
if(isSelectable)
|
||||
emitClicked(PA_Select);
|
||||
else
|
||||
emitClicked(PA_Manage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Popup::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(frameTime - 0.2 < lastUpdate)
|
||||
return;
|
||||
|
||||
lastUpdate = frameTime;
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
defIcon.visible = playerEmpire.isDefending(obj.region);
|
||||
|
||||
//Update name
|
||||
name.text = obj.name;
|
||||
if(ft.getDimension(name.text).x > name.size.width)
|
||||
name.font = FT_Detail;
|
||||
else
|
||||
name.font = FT_Normal;
|
||||
|
||||
//Update health
|
||||
if(obj.Health < obj.MaxHealth) {
|
||||
health.progress = obj.Health / obj.MaxHealth;
|
||||
health.frontColor = colors::Red.interpolate(colors::Green, health.progress);
|
||||
health.text = standardize(obj.Health)+" / "+standardize(obj.MaxHealth);
|
||||
health.visible = true;
|
||||
}
|
||||
else {
|
||||
health.visible = false;
|
||||
}
|
||||
|
||||
Popup::update();
|
||||
Popup::updatePosition(obj);
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
#priority init -100
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.MarkupTooltip;
|
||||
import tabs.Tab;
|
||||
import util.formatting;
|
||||
import timing;
|
||||
from tabs.tabbar import TAB_HEIGHT, GLOBAL_BAR_HEIGHT, ActiveTab;
|
||||
|
||||
class TimeDisplay : BaseGuiElement {
|
||||
GuiSprite@ icon;
|
||||
GuiMarkupText@ text;
|
||||
bool showGameTime = true;
|
||||
bool clicking = false;
|
||||
bool wasAutoPause = false;
|
||||
string prevText;
|
||||
|
||||
GuiButton@ pauseButton;
|
||||
GuiButton@ slowButton;
|
||||
GuiButton@ fastButton;
|
||||
|
||||
TimeDisplay() {
|
||||
super(null, recti_area(-4,TAB_HEIGHT+GLOBAL_BAR_HEIGHT, 210, 30));
|
||||
@icon = GuiSprite(this, recti_area(9,3, 24,24));
|
||||
@text = GuiMarkupText(this, recti_area(35,6, 120,24));
|
||||
setMarkupTooltip(icon, locale::TT_GAMETIME);
|
||||
setMarkupTooltip(text, locale::TT_GAMETIME);
|
||||
|
||||
if(mpClient) {
|
||||
size = vec2i(128, 30);
|
||||
}
|
||||
else {
|
||||
@slowButton = GuiButton(this, Alignment(Right-69, Top+7, Width=18, Height=18));
|
||||
setMarkupTooltip(slowButton, locale::TT_SLOWER);
|
||||
slowButton.allowOtherButtons = true;
|
||||
slowButton.spriteStyle = Sprite(spritesheet::TimeSlow, 0);
|
||||
|
||||
@pauseButton = GuiButton(this, Alignment(Right-48, Top+7, Width=18, Height=18));
|
||||
setMarkupTooltip(pauseButton, locale::TT_PAUSE);
|
||||
pauseButton.allowOtherButtons = true;
|
||||
pauseButton.spriteStyle = Sprite(spritesheet::TimeStop, 0);
|
||||
|
||||
@fastButton = GuiButton(this, Alignment(Right-26, Top+7, Width=18, Height=18));
|
||||
setMarkupTooltip(fastButton, locale::TT_FASTER);
|
||||
fastButton.allowOtherButtons = true;
|
||||
fastButton.spriteStyle = Sprite(spritesheet::TimeHaste, 0);
|
||||
}
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
visible = (ActiveTab.category == TC_Galaxy) && ShowTimeDisplay;
|
||||
|
||||
if(!mpClient && !mpServer && settings::bAutoPause) {
|
||||
bool shouldAutoPause = ActiveTab.category != TC_Galaxy && ActiveTab.category != TC_Diplomacy;
|
||||
if(gameSpeed != 0 && shouldAutoPause) {
|
||||
pause();
|
||||
wasAutoPause = true;
|
||||
}
|
||||
else if(!shouldAutoPause && wasAutoPause && gameSpeed == 0) {
|
||||
pause();
|
||||
wasAutoPause = false;
|
||||
}
|
||||
}
|
||||
string str;
|
||||
if(showGameTime) {
|
||||
double time = floor(gameTime / 60.0);
|
||||
int hrs = floor(time / 60.0);
|
||||
int mins = floor(time - (hrs * 60.0));
|
||||
str = format(locale::TIME_HM, toString(hrs), toString(mins));
|
||||
|
||||
icon.desc = Sprite(spritesheet::MenuIcons, 0);
|
||||
}
|
||||
else {
|
||||
icon.desc = Sprite(material::TimeReal);
|
||||
str = strftime("%H:%M", getSystemTime());
|
||||
}
|
||||
if(abs(gameSpeed - 1.0) > 0.05) {
|
||||
if(mpIsSerializing)
|
||||
str += format(" [color=#fff900]$1[/color]", locale::WAITING);
|
||||
else if(gameSpeed == 0.0)
|
||||
str += format(" [color=#f00]$1[/color]", locale::PAUSED);
|
||||
else if(gameSpeed > 1.0)
|
||||
str += format(" [color=#0f0]x$1[/color]", toString(gameSpeed, 1));
|
||||
else
|
||||
str += format(" [color=#f00]x$1[/color]", toString(gameSpeed, 1));
|
||||
}
|
||||
if(str != prevText) {
|
||||
text.text = str;
|
||||
text.updateAbsolutePosition();
|
||||
prevText = str;
|
||||
}
|
||||
if(pauseButton !is null) {
|
||||
if(gameSpeed == 0.0)
|
||||
pauseButton.spriteStyle = Sprite(spritesheet::TimeResume, 0);
|
||||
else
|
||||
pauseButton.spriteStyle = Sprite(spritesheet::TimeStop, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Mouse_Left:
|
||||
if(evt.caller is this)
|
||||
clicking = false;
|
||||
break;
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is pauseButton) {
|
||||
if(evt.value == 1)
|
||||
speed_default();
|
||||
else
|
||||
pause();
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is slowButton) {
|
||||
if(evt.value == 1)
|
||||
speed_slowest();
|
||||
else
|
||||
speed_slower();
|
||||
return true;
|
||||
}
|
||||
else if(evt.caller is fastButton) {
|
||||
if(evt.value == 1)
|
||||
speed_fastest();
|
||||
else
|
||||
speed_faster();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this || source is icon || source is text) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
if(event.button == 0) {
|
||||
clicking = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MET_Button_Up:
|
||||
if(event.button == 0) {
|
||||
if(clicking) {
|
||||
showGameTime = !showGameTime;
|
||||
if(showGameTime) {
|
||||
setMarkupTooltip(icon, locale::TT_GAMETIME);
|
||||
setMarkupTooltip(text, locale::TT_GAMETIME);
|
||||
}
|
||||
else {
|
||||
setMarkupTooltip(icon, locale::TT_REALTIME);
|
||||
setMarkupTooltip(text, locale::TT_REALTIME);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
skin.draw(SS_TimeDisplay, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
TimeDisplay@ disp;
|
||||
bool ShowTimeDisplay = true;
|
||||
void init() {
|
||||
@disp = TimeDisplay();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
disp.tick(time);
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
import dialogue;
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiDraggable;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiButton;
|
||||
import dialogs.MessageDialog;
|
||||
from gui import animate_time;
|
||||
|
||||
const double FLASH_TIME = 0.6;
|
||||
|
||||
class ScenarioWindow : GuiDraggable {
|
||||
GuiBackgroundPanel@ bg;
|
||||
vec2i prevScreenSize;
|
||||
recti prevSmallPos;
|
||||
recti prevBigPos;
|
||||
|
||||
GuiButton@ minButton;
|
||||
bool expanded = true;
|
||||
|
||||
Dialogue dialogue;
|
||||
Dialogue newDialogue;
|
||||
GuiMarkupText@ dialogueBox;
|
||||
|
||||
Objective objective;
|
||||
Objective newObjective;
|
||||
|
||||
GuiSkinElement@ objBG;
|
||||
GuiMarkupText@ objBox;
|
||||
|
||||
GuiButton@ nextButton;
|
||||
double flashTimer = -1.0;
|
||||
|
||||
ScenarioWindow() {
|
||||
super(null, recti(0,0,550,280));
|
||||
@bg = GuiBackgroundPanel(this, Alignment_Fill());
|
||||
bg.titleColor = Color(0xb3fe00ff);
|
||||
bg.titleStyle = SS_FullTitle;
|
||||
|
||||
@dialogueBox = GuiMarkupText(this, recti());
|
||||
|
||||
@minButton = GuiButton(this, Alignment(Right-30, Top+2, Right-4, Top+28));
|
||||
minButton.color = Color(0xff8080ff);
|
||||
minButton.setIcon(Sprite(material::Minus));
|
||||
|
||||
@objBG = GuiSkinElement(this, Alignment(Left+8, Top+188, Right-8, Bottom-8), SS_PlainBox);
|
||||
@objBox = GuiMarkupText(objBG, Alignment(Left+4, Top+4, Right-4, Bottom-4));
|
||||
|
||||
@nextButton = GuiButton(this, Alignment(Right-92, Bottom-36, Right-2, Bottom-2), locale::NEXT);
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.type == GUI_Clicked) {
|
||||
if(evt.caller is minButton) {
|
||||
toggleExpand();
|
||||
return true;
|
||||
}
|
||||
if(evt.caller is nextButton) {
|
||||
skipDialogueObjective();
|
||||
objective.id = -1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return GuiDraggable::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void toggleExpand() {
|
||||
expanded = !expanded;
|
||||
if(expanded) {
|
||||
minButton.color = Color(0xff8080ff);
|
||||
minButton.setIcon(Sprite(material::Minus));
|
||||
|
||||
recti pos;
|
||||
if(rect == prevSmallPos && prevBigPos.width != 0)
|
||||
pos = prevBigPos;
|
||||
else
|
||||
pos = recti_area(vec2i(rect.topLeft.x, max(rect.botRight.y-280, 0)), vec2i(550, 280));
|
||||
|
||||
animate_time(this, pos, 0.2);
|
||||
prevBigPos = pos;
|
||||
prevSmallPos = rect;
|
||||
}
|
||||
else {
|
||||
minButton.color = Color(0x80ff80ff);
|
||||
minButton.setIcon(Sprite(material::Plus));
|
||||
|
||||
recti pos;
|
||||
if(rect == prevBigPos && prevSmallPos.width != 0)
|
||||
pos = prevSmallPos;
|
||||
else
|
||||
pos = recti_area(vec2i(rect.topLeft.x, max(rect.botRight.y-32, 0)), vec2i(550, 32));
|
||||
|
||||
animate_time(this, pos, 0.2);
|
||||
prevSmallPos = pos;
|
||||
prevBigPos = rect;
|
||||
}
|
||||
|
||||
dialogueBox.visible = expanded;
|
||||
objBG.visible = expanded;
|
||||
objBox.visible = expanded;
|
||||
nextButton.visible = expanded;
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() override {
|
||||
if(screenSize != prevScreenSize) {
|
||||
rect = recti_area(vec2i((screenSize.width - 550) / 2,
|
||||
screenSize.height - size.height - 12), vec2i(550, size.height));
|
||||
prevScreenSize = screenSize;
|
||||
}
|
||||
GuiDraggable::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(!hasDialogue()) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!receive(getActiveDialogue(), newDialogue))
|
||||
return;
|
||||
|
||||
if(!receive(getActiveDialogueObjective(), newObjective)) {
|
||||
newObjective.title = "";
|
||||
newObjective.id = -1;
|
||||
}
|
||||
if(newObjective.id != objective.id) {
|
||||
if(flashTimer >= FLASH_TIME || objective.id == -1 || !objBG.visible) {
|
||||
objective = newObjective;
|
||||
dialogue = newDialogue;
|
||||
flashTimer = -1.0;
|
||||
}
|
||||
else {
|
||||
if(flashTimer < 0.0) {
|
||||
flashTimer = 0.0;
|
||||
sound::confirm.play();
|
||||
}
|
||||
}
|
||||
if(!expanded)
|
||||
toggleExpand();
|
||||
}
|
||||
else {
|
||||
objective = newObjective;
|
||||
dialogue = newDialogue;
|
||||
}
|
||||
|
||||
bg.title = dialogue.title;
|
||||
dialogueBox.text = dialogue.text;
|
||||
|
||||
if(objective.title.length != 0) {
|
||||
objBG.visible = expanded;
|
||||
objBox.text = format("[b]$1[/b]\n$2", objective.title, objective.text);
|
||||
dialogueBox.rect = recti(8,36, 542,188);
|
||||
nextButton.text = locale::NEXT;
|
||||
}
|
||||
else {
|
||||
objBG.visible = false;
|
||||
dialogueBox.rect = recti(8,36, 542,272);
|
||||
if(dialogue.proceedText.length != 0)
|
||||
nextButton.text = dialogue.proceedText;
|
||||
else
|
||||
nextButton.text = locale::NEXT;
|
||||
}
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
update();
|
||||
if(flashTimer >= 0.0)
|
||||
flashTimer += time;
|
||||
nextButton.visible =
|
||||
(objective.id == -1 || objective.skippable)
|
||||
&& flashTimer < 0 && expanded;
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
GuiDraggable::draw();
|
||||
if(flashTimer >= 0.0) {
|
||||
double alpha = flashTimer / FLASH_TIME;
|
||||
Color color = colors::Green;
|
||||
color.a = uint(alpha * 140.0);
|
||||
|
||||
recti pos = objBG.absolutePosition;
|
||||
drawRectangle(pos, color);
|
||||
objBox.draw();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ScenarioWindow@ window;
|
||||
class ServerMessage {
|
||||
string title;
|
||||
string text;
|
||||
Color color;
|
||||
};
|
||||
Mutex msgMtx;
|
||||
array<ServerMessage> messages;
|
||||
|
||||
void sendMessage(string title, string text, uint color) {
|
||||
Lock lck(msgMtx);
|
||||
ServerMessage msg;
|
||||
msg.title = localize(title);
|
||||
msg.text = localize(text);
|
||||
if(color != 0)
|
||||
msg.color = Color(color);
|
||||
messages.insertLast(msg);
|
||||
}
|
||||
|
||||
void init() {
|
||||
if(hasDialogue())
|
||||
@window = ScenarioWindow();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(window !is null) {
|
||||
if(window.parent is null)
|
||||
@window = null;
|
||||
else
|
||||
window.tick(time);
|
||||
}
|
||||
if(messages.length != 0) {
|
||||
Lock lck(msgMtx);
|
||||
for(uint i = 0, cnt = messages.length; i < cnt; ++i) {
|
||||
auto@ dialog = message(messages[i].text);
|
||||
dialog.addTitle(messages[i].title);
|
||||
dialog.titleColor = messages[i].color;
|
||||
}
|
||||
messages.length = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiEmpire;
|
||||
import elements.GuiOverlay;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.MarkupTooltip;
|
||||
import dialogs.QuestionDialog;
|
||||
import attitudes;
|
||||
import abilities;
|
||||
|
||||
from overlays.InfoBar import AbilityAction;
|
||||
|
||||
import tabs.tabbar;
|
||||
|
||||
class LevelMarker : BaseGuiElement {
|
||||
const AttitudeLevel@ lvl;
|
||||
Color color;
|
||||
bool reached;
|
||||
bool hovered = false;
|
||||
|
||||
LevelMarker(IGuiElement@ parent) {
|
||||
super(parent, recti(0,0, 42,70));
|
||||
noClip = true;
|
||||
auto@ tt = addLazyMarkupTooltip(this, width=300);
|
||||
tt.FollowMouse = false;
|
||||
tt.offset = vec2i(0, 5);
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
string tt;
|
||||
tt += format("[font=Medium]$1 $2[/font]\n", locale::LEVEL, toString(lvl.level+1));
|
||||
tt += lvl.description;
|
||||
return tt;
|
||||
}
|
||||
|
||||
void update(Attitude& att) {
|
||||
double finalProgress = att.levels[att.maxLevel].threshold;
|
||||
double pct = clamp(lvl.threshold / finalProgress, 0.0, 1.0);
|
||||
|
||||
reached = att.level >= lvl.level+1;
|
||||
position = vec2i(parent.size.x * pct - size.width / 2, 0);
|
||||
|
||||
if(reached)
|
||||
color = Color(0x000000ff).interpolate(att.type.color, 0.4);
|
||||
else
|
||||
color = Color(0x666666ff);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
if(evt.caller is this)
|
||||
hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
if(evt.caller is this)
|
||||
hovered = false;
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(hovered) {
|
||||
drawLine(AbsolutePosition.topLeft + vec2i(size.width/2, 2),
|
||||
AbsolutePosition.topLeft + vec2i(size.width/2, size.height-35),
|
||||
Color(0xffffff40), 12);
|
||||
}
|
||||
|
||||
drawLine(AbsolutePosition.topLeft + vec2i(size.width/2, 2),
|
||||
AbsolutePosition.topLeft + vec2i(size.width/2, size.height),
|
||||
Color(0x00000080), 5);
|
||||
|
||||
drawLine(AbsolutePosition.topLeft + vec2i(size.width/2, 2),
|
||||
AbsolutePosition.topLeft + vec2i(size.width/2, size.height),
|
||||
color, 3);
|
||||
|
||||
recti iconPos = recti_area(5,size.height-32, 32,32) + AbsolutePosition.topLeft;
|
||||
if(hovered)
|
||||
drawRectangle(iconPos.padded(-4), Color(0xffffff40));
|
||||
drawRectangle(iconPos.padded(-2), Color(0x00000080));
|
||||
drawRectangle(iconPos, color);
|
||||
|
||||
lvl.icon.draw(iconPos.aspectAligned(lvl.icon.aspect));
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class DiscardConfirm : QuestionDialogCallback {
|
||||
const AttitudeType@ type;
|
||||
|
||||
DiscardConfirm(const AttitudeType@ type) {
|
||||
@this.type = type;
|
||||
}
|
||||
|
||||
void questionCallback(QuestionDialog@ dialog, int answer) {
|
||||
if(answer == QA_Yes)
|
||||
playerEmpire.discardAttitude(type.id);
|
||||
}
|
||||
};
|
||||
|
||||
class AttitudeBox : BaseGuiElement {
|
||||
Attitude@ att;
|
||||
|
||||
GuiMarkupText@ title;
|
||||
GuiMarkupText@ progressText;
|
||||
GuiProgressbar@ bar;
|
||||
|
||||
array<LevelMarker@> markers;
|
||||
array<AbilityAction@> abilities;
|
||||
|
||||
GuiButton@ discardButton;
|
||||
GuiMarkupText@ discardText;
|
||||
|
||||
AttitudeBox(IGuiElement@ parent) {
|
||||
super(parent, recti());
|
||||
|
||||
@title = GuiMarkupText(this, Alignment(Left+12, Top+8, Right-12, Top+40));
|
||||
title.defaultFont = FT_Medium;
|
||||
title.defaultStroke = colors::Black;
|
||||
|
||||
@progressText = GuiMarkupText(this, Alignment(Left+20, Top+36, Right-12, Top+65));
|
||||
progressText.defaultColor = Color(0x888888ff);
|
||||
progressText.defaultStroke = colors::Black;
|
||||
|
||||
@bar = GuiProgressbar(this, Alignment(Left+12, Top+65, Right-220, Top+110));
|
||||
|
||||
@discardButton = GuiButton(this, Alignment(Right-140, Top+3, Right-4, Top+36));
|
||||
discardButton.color = colors::Red;
|
||||
@discardText = GuiMarkupText(discardButton, Alignment(Left, Top+6, Right, Bottom));
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) override {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is discardButton) {
|
||||
auto@ diag = question(format(locale::ATT_CONFIRM_DISCARD, att.type.name),
|
||||
locale::DISCARD, locale::CANCEL, DiscardConfirm(att.type));
|
||||
diag.titleBox.color = Color(0xff0000ff);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(att is null || att.type is null)
|
||||
return;
|
||||
updateAbsolutePosition();
|
||||
|
||||
double curProgress = att.progress;
|
||||
double nextProgress = att.levels[att.nextLevel].threshold;
|
||||
double finalProgress = att.levels[att.maxLevel].threshold;
|
||||
|
||||
//Progress data
|
||||
if(nextProgress > curProgress) {
|
||||
progressText.text = format("[color=#aaa][b]$1 $2:[/b][/color] $3",
|
||||
locale::LEVEL, toString(att.nextLevel),
|
||||
format(att.type.progress, toString(nextProgress-curProgress, 0)));
|
||||
}
|
||||
else {
|
||||
progressText.text = locale::ATT_MAX_LEVEL;
|
||||
}
|
||||
|
||||
title.text = att.type.name;
|
||||
bar.frontColor = att.type.color;
|
||||
bar.progress = curProgress / finalProgress;
|
||||
|
||||
//Level markers
|
||||
uint prevCnt = markers.length;
|
||||
uint newCnt = att.type.levels.length;
|
||||
for(uint i = newCnt; i < prevCnt; ++i)
|
||||
markers[i].remove();
|
||||
markers.length = newCnt;
|
||||
for(uint i = prevCnt; i < newCnt; ++i)
|
||||
@markers[i] = LevelMarker(bar);
|
||||
|
||||
for(uint i = 0; i < newCnt; ++i) {
|
||||
@markers[i].lvl = att.type.levels[i];
|
||||
markers[i].update(att);
|
||||
}
|
||||
|
||||
//Discarding
|
||||
int discardCost = att.getDiscardCost(playerEmpire);
|
||||
discardText.text = "[center]"+format(locale::ATT_DISCARD, toString(discardCost))+"[/center]";
|
||||
discardButton.disabled = playerEmpire.Influence < discardCost;
|
||||
|
||||
//Abilities
|
||||
prevCnt = abilities.length;
|
||||
newCnt = 0;
|
||||
|
||||
for(uint i = 0, cnt = att.allHookCount; i < cnt; ++i) {
|
||||
Ability@ abl;
|
||||
if(newCnt < prevCnt)
|
||||
@abl = abilities[newCnt].abl;
|
||||
@abl = att.allHooks[i].showAbility(att, playerEmpire, abl);
|
||||
if(abl !is null) {
|
||||
if(newCnt >= prevCnt) {
|
||||
AbilityAction act(abl, abl.type.name);
|
||||
act.independent = true;
|
||||
@act.parent = this;
|
||||
abilities.insertLast(act);
|
||||
}
|
||||
newCnt += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(uint i = newCnt; i < prevCnt; ++i)
|
||||
abilities[i].remove();
|
||||
|
||||
int y = 62;
|
||||
if(newCnt > 1)
|
||||
y = 40;
|
||||
abilities.length = newCnt;
|
||||
for(uint i = 0, cnt = abilities.length; i < cnt; ++i) {
|
||||
auto@ btn = abilities[i];
|
||||
btn.init();
|
||||
btn.position = vec2i(size.width-184, y);
|
||||
btn.size = vec2i(172, 50);
|
||||
y += 50;
|
||||
}
|
||||
}
|
||||
|
||||
void addAbility(Ability@ abl, uint& newCnt) {
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(att is null || att.type is null)
|
||||
return;
|
||||
skin.draw(SS_EmpireBox, SF_Normal, AbsolutePosition, att.type.color);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class AttitudesTab : Tab {
|
||||
array<AttitudeBox@> boxes;
|
||||
array<Attitude> attitudes;
|
||||
|
||||
GuiButton@ takeButton;
|
||||
GuiMarkupText@ takeText;
|
||||
|
||||
GuiSkinElement@ header;
|
||||
GuiEmpire@ portrait;
|
||||
GuiMarkupText@ headerText;
|
||||
|
||||
GuiPanel@ panel;
|
||||
|
||||
AttitudesTab() {
|
||||
super();
|
||||
title = locale::ATTITUDES_TAB;
|
||||
|
||||
@panel = GuiPanel(this, Alignment());
|
||||
@takeButton = GuiButton(panel, recti_area(0,0, 280,60));
|
||||
@takeText = GuiMarkupText(takeButton, Alignment(Left, Top+15, Right, Bottom));
|
||||
takeText.defaultFont = FT_Subtitle;
|
||||
|
||||
@header = GuiSkinElement(panel, Alignment(Left+0.5f-400, Top+16, Left+0.5f+400, Top+200), SS_Panel);
|
||||
@portrait = GuiEmpire(header, Alignment(Left+4, Top+4, Left+180, Bottom-4));
|
||||
|
||||
@headerText = GuiMarkupText(header, Alignment(Left+188, Top+8, Right-8, Bottom-8));
|
||||
headerText.text = locale::ATT_HEADER_DESC;
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0x63ebdbff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x6dd6caff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x37837aff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Attitudes;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabAttitude);
|
||||
}
|
||||
|
||||
void tick(double time) override {
|
||||
if(!visible)
|
||||
return;
|
||||
if(playerEmpire is null || !playerEmpire.valid) {
|
||||
attitudes.length = 0;
|
||||
}
|
||||
else {
|
||||
attitudes.syncFrom(playerEmpire.getAttitudes());
|
||||
@portrait.empire = playerEmpire;
|
||||
}
|
||||
|
||||
uint prevCnt = boxes.length;
|
||||
uint newCnt = attitudes.length;
|
||||
for(uint i = newCnt; i < prevCnt; ++i)
|
||||
boxes[i].remove();
|
||||
boxes.length = newCnt;
|
||||
for(uint i = prevCnt; i < newCnt; ++i)
|
||||
@boxes[i] = AttitudeBox(panel);
|
||||
|
||||
int y = 216, h = 150;
|
||||
for(uint i = 0; i < newCnt; ++i) {
|
||||
@boxes[i].att = attitudes[i];
|
||||
@boxes[i].alignment = Alignment(Left+0.1f, Top+y, Right-0.1f, Top+y+h);
|
||||
boxes[i].update();
|
||||
y += h+8;
|
||||
}
|
||||
|
||||
bool haveTakeable = false;
|
||||
for(uint i = 0, cnt = getAttitudeTypeCount(); i < cnt; ++i) {
|
||||
auto@ att = getAttitudeType(i);
|
||||
if(att.canTake(playerEmpire)) {
|
||||
haveTakeable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(haveTakeable) {
|
||||
takeButton.visible = true;
|
||||
|
||||
int extraCost = playerEmpire.getNextAttitudeCost();
|
||||
takeButton.position = vec2i((size.width-takeButton.size.width)/2, y+20);
|
||||
takeText.text = "[center]"+format(locale::ATT_TAKE_COST, toString(extraCost))+"[/center]";
|
||||
}
|
||||
else {
|
||||
takeButton.visible = false;
|
||||
}
|
||||
|
||||
if(prevCnt != newCnt)
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is takeButton) {
|
||||
TakeAttitudeOverlay(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition, Color(0x6dd6caff));
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class GuiFlatButton : GuiButton {
|
||||
bool taken = false;
|
||||
bool available = false;
|
||||
|
||||
GuiFlatButton(IGuiElement@ ParentElement, const recti& Rectangle) {
|
||||
super(ParentElement, Rectangle);
|
||||
updateAbsolutePosition();
|
||||
navigable = true;
|
||||
style = SS_NULL;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(!available) {
|
||||
if(flags & SF_Active != 0)
|
||||
drawRectangle(AbsolutePosition, color.interpolate(Color(0x00000080), 0.6));
|
||||
else
|
||||
drawRectangle(AbsolutePosition, Color(0x00000040));
|
||||
}
|
||||
else {
|
||||
if(flags & SF_Active != 0)
|
||||
drawRectangle(AbsolutePosition, color);
|
||||
else
|
||||
drawRectangle(AbsolutePosition, Color(0x00000060));
|
||||
}
|
||||
|
||||
if(flags & SF_Hovered != 0)
|
||||
drawRectangle(AbsolutePosition, Color(0xffffff20));
|
||||
|
||||
if(!available) {
|
||||
drawLine(AbsolutePosition.topLeft+vec2i(size.width/5, size.height/2+3),
|
||||
AbsolutePosition.botRight-vec2i(size.width/5, size.height/2-3),
|
||||
Color(0x444444ff), 3);
|
||||
}
|
||||
|
||||
if(taken) {
|
||||
vec2i tl = AbsolutePosition.topLeft + vec2i(2,2);
|
||||
vec2i br = AbsolutePosition.botRight - vec2i(2,2);
|
||||
|
||||
drawLine(vec2i(tl.x,tl.y), vec2i(br.x,tl.y), color.interpolate(colors::White, 0.2), 3);
|
||||
drawLine(vec2i(tl.x,tl.y), vec2i(tl.x,br.y), color.interpolate(colors::White, 0.2), 3);
|
||||
|
||||
drawLine(vec2i(br.x,tl.y), vec2i(br.x,br.y), color.interpolate(colors::White, 0.2), 3);
|
||||
drawLine(vec2i(tl.x,br.y), vec2i(br.x,br.y), color.interpolate(colors::White, 0.2), 3);
|
||||
|
||||
|
||||
Color acolor = color;
|
||||
acolor.a = 0x50;
|
||||
drawRectangle(AbsolutePosition, acolor);
|
||||
}
|
||||
GuiButton::draw();
|
||||
}
|
||||
}
|
||||
|
||||
class TakeAttitudeOverlay : GuiOverlay {
|
||||
GuiSkinElement@ bg;
|
||||
GuiPanel@ leftPanel;
|
||||
GuiPanel@ rightPanel;
|
||||
GuiMarkupText@ text;
|
||||
|
||||
array<const AttitudeType@> attitudes;
|
||||
array<GuiButton@> buttons;
|
||||
const AttitudeType@ selected;
|
||||
GuiButton@ takeButton;
|
||||
GuiMarkupText@ takeText;
|
||||
GuiMarkupText@ takeCaption;
|
||||
|
||||
TakeAttitudeOverlay(IGuiElement@ parent) {
|
||||
super(parent);
|
||||
closeSelf = false;
|
||||
|
||||
for(uint i = 0, cnt = getAttitudeTypeCount(); i < cnt; ++i) {
|
||||
auto@ att = getAttitudeType(i);
|
||||
/*if(att.canTake(playerEmpire))*/
|
||||
attitudes.insertLast(att);
|
||||
}
|
||||
attitudes.sortAsc();
|
||||
|
||||
int h = 16 + clamp(attitudes.length/2 * 50, 370, 600) + 50;
|
||||
|
||||
@bg = GuiSkinElement(this, Alignment(Left+0.5f-425, Top+0.5f-(h/2), Left+0.5f+425, Top+0.5f+(h/2)), SS_Panel);
|
||||
@leftPanel = GuiPanel(bg, Alignment(Left, Top, Left+300, Bottom-50));
|
||||
@rightPanel = GuiPanel(bg, Alignment(Left+300, Top, Right, Bottom-50));
|
||||
@text = GuiMarkupText(rightPanel, recti_area(8,8, 550-16, 100));
|
||||
text.flexHeight = true;
|
||||
@takeButton = GuiButton(bg, Alignment(Left+0.5f-140, Bottom-50, Left+0.5f+140, Bottom-8));
|
||||
@takeText = GuiMarkupText(takeButton, Alignment(Left, Top+10, Right, Bottom));
|
||||
@takeCaption = GuiMarkupText(bg, Alignment(Left+0.5f-140, Bottom-40, Left+0.5f+140, Bottom-8));
|
||||
takeCaption.defaultFont = FT_Bold;
|
||||
takeCaption.defaultColor = Color(0xaa8080ff);
|
||||
takeCaption.visible = false;
|
||||
|
||||
int y = 8;
|
||||
uint sel = uint(-1);
|
||||
for(uint i = 0, cnt = attitudes.length; i < cnt; ++i) {
|
||||
int x = 8;
|
||||
if(i%2 != 0)
|
||||
x = 150;
|
||||
|
||||
auto@ att = attitudes[i];
|
||||
|
||||
GuiFlatButton btn(leftPanel, recti_area(x,y+2, 140, 46));
|
||||
btn.toggleButton = true;
|
||||
btn.pressed = (i == 0);
|
||||
btn.text = att.name;
|
||||
btn.color = att.color.interpolate(colors::Black, 0.75);
|
||||
|
||||
if(playerEmpire.hasAttitude(att.id)) {
|
||||
btn.taken = true;
|
||||
btn.available = true;
|
||||
btn.textColor = colors::White;
|
||||
}
|
||||
else if(!att.canTake(playerEmpire)) {
|
||||
btn.taken = false;
|
||||
btn.available = false;
|
||||
btn.textColor = Color(0x666666ff);
|
||||
}
|
||||
else {
|
||||
btn.taken = false;
|
||||
btn.available = true;
|
||||
btn.textColor = colors::White;
|
||||
|
||||
if(sel == uint(-1))
|
||||
sel = i;
|
||||
}
|
||||
|
||||
if(i%2 != 0)
|
||||
y += 50;
|
||||
|
||||
buttons.insertLast(btn);
|
||||
}
|
||||
|
||||
if(sel == uint(-1))
|
||||
sel = 0;
|
||||
if(attitudes.length != 0)
|
||||
select(attitudes[sel]);
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void select(const AttitudeType@ type) {
|
||||
for(uint j = 0, cnt = buttons.length; j < cnt; ++j)
|
||||
buttons[j].pressed = (type is attitudes[j]);
|
||||
@selected = type;
|
||||
|
||||
string desc = format("[font=Medium][color=$1][stroke=#000]$2[/stroke][/color][/font]\n[vspace=6/]",
|
||||
toString(type.color.interpolate(colors::White, 0.1)), type.name);
|
||||
|
||||
for(uint i = 0, cnt = type.levels.length; i < cnt; ++i) {
|
||||
auto@ lvl = type.levels[i];
|
||||
desc += format("[img=$4;32][color=#aaa][b]$1 $2:[/b][/color] [color=#888]$3[/color]\n",
|
||||
locale::LEVEL, toString(i+1),
|
||||
format(type.progress, toString(lvl.threshold, 0)),
|
||||
getSpriteDesc(lvl.icon));
|
||||
desc += "[offset=20]"+lvl.description+"[/offset][/img]";
|
||||
desc += "\n[vspace=2/]";
|
||||
}
|
||||
|
||||
takeButton.color = type.color;
|
||||
|
||||
int extraCost = playerEmpire.getNextAttitudeCost();
|
||||
takeText.text = "[center]"+format(locale::ATT_TAKE_ATT, type.name, toString(extraCost))+"[/center]";
|
||||
takeButton.disabled = playerEmpire.Influence < extraCost;
|
||||
|
||||
takeButton.visible = selected.canTake(playerEmpire);
|
||||
takeCaption.visible = !takeButton.visible;
|
||||
|
||||
if(takeCaption.visible) {
|
||||
if(playerEmpire.hasAttitude(selected.id))
|
||||
takeCaption.text = "[center]"+locale::ATT_HAVE_ATTITUDE+"[/center]";
|
||||
else
|
||||
takeCaption.text = "[center]"+locale::ATT_CANNOT_ATTITUDE+"[/center]";
|
||||
}
|
||||
|
||||
text.text = desc;
|
||||
rightPanel.updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) override {
|
||||
if(event.type == GUI_Clicked) {
|
||||
for(uint i = 0, cnt = buttons.length; i < cnt; ++i) {
|
||||
if(buttons[i] is event.caller) {
|
||||
select(attitudes[i]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(event.caller is takeButton) {
|
||||
playerEmpire.takeAttitude(selected.id);
|
||||
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return GuiOverlay::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createAttitudesTab() {
|
||||
return AttitudesTab();
|
||||
}
|
||||
|
||||
void resetTabs() {
|
||||
for(uint i = 0, cnt = tabs.length; i < cnt; ++i) {
|
||||
if(tabs[i].category == TC_Attitudes)
|
||||
browseTab(tabs[i], createAttitudesTab());
|
||||
}
|
||||
}
|
||||
|
||||
void postReload(Message& msg) {
|
||||
resetTabs();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,688 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiBlueprint;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiSprite;
|
||||
import dialogs.InputDialog;
|
||||
from dialogs.DesignImportDialog import DesignImportDialog, addDialog;
|
||||
import resources;
|
||||
import tile_resources;
|
||||
import icons;
|
||||
import heralds_icons;
|
||||
#include "dialogs/include/UniqueDialogs.as"
|
||||
|
||||
from tabs.tabbar import newTab, browseTab, switchToTab;
|
||||
from tabs.DesignEditorTab import createDesignEditorTab, loadDesignEditor;
|
||||
|
||||
const uint D_EL_WIDTH = 325;
|
||||
const uint D_EL_HEIGHT = 200;
|
||||
const uint D_EL_SPACING = 8;
|
||||
const uint D_ICON_WIDTH = 38;
|
||||
const uint D_ICON_HEIGHT = 28;
|
||||
const uint D_ICON_SPACING = 4;
|
||||
|
||||
const Color[] CLASS_COLORS = {
|
||||
Color(0x00c3ffff),
|
||||
Color(0xcf4cffff),
|
||||
Color(0xbaff4cff),
|
||||
Color(0xff6c00ff),
|
||||
Color(0xebc0ffff),
|
||||
Color(0xc7af99ff),
|
||||
Color(0xf49bcfff),
|
||||
Color(0x00ff9cff),
|
||||
Color(0x00deffff)
|
||||
};
|
||||
|
||||
enum Dialogs {
|
||||
D_CreateClass,
|
||||
};
|
||||
|
||||
class CreateClass : InputDialogCallback {
|
||||
DesignOverview@ overview;
|
||||
|
||||
CreateClass(DesignOverview@ ovw) {
|
||||
@overview = ovw;
|
||||
}
|
||||
|
||||
void inputCallback(InputDialog@ dialog, bool accepted) {
|
||||
if(accepted) {
|
||||
string name = dialog.getTextInput(0);
|
||||
if(name.length != 0)
|
||||
playerEmpire.getDesignClass(name);
|
||||
|
||||
overview.refresh(playerEmpire);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DesignImporter : DesignImportDialog {
|
||||
DesignImporter(IGuiElement@ bind) {
|
||||
super(bind);
|
||||
}
|
||||
|
||||
bool showDesign(const Design@ dsg) {
|
||||
cast<DesignOverview>(elem).showDesignEditor(dsg);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class DesignOverview : Tab {
|
||||
GuiPanel@ clsPanel;
|
||||
DesignClassElement@[] classes;
|
||||
DesignElement@ selected;
|
||||
|
||||
GuiButton@ createClassButton;
|
||||
GuiButton@ importButton;
|
||||
GuiButton@ showObsoleteButton;
|
||||
|
||||
uint prevDesignCount = 0;
|
||||
|
||||
DesignOverview() {
|
||||
super();
|
||||
|
||||
@clsPanel = GuiPanel(this, recti());
|
||||
@clsPanel.alignment = Alignment(Left+8, Top, Right-8, Bottom);
|
||||
|
||||
@createClassButton = GuiButton(clsPanel, recti(0, 0, 195, 47),
|
||||
locale::CREATE_DESIGN_CLASS);
|
||||
createClassButton.font = FT_Medium;
|
||||
createClassButton.buttonIcon = icons::Create.colorized(Color(0x8888ffff));
|
||||
|
||||
@importButton = GuiButton(clsPanel, recti(0, 0, 195, 47),
|
||||
locale::IMPORT_DESIGNS);
|
||||
importButton.font = FT_Medium;
|
||||
importButton.buttonIcon = icons::Import;
|
||||
|
||||
@showObsoleteButton = GuiButton(clsPanel, recti(0, 0, 195, 47),
|
||||
locale::SHOW_OBSOLETE);
|
||||
showObsoleteButton.tooltip = locale::TT_SHOW_OBSOLETE;
|
||||
showObsoleteButton.font = FT_Medium;
|
||||
showObsoleteButton.buttonIcon = icons::Obsolete;
|
||||
showObsoleteButton.toggleButton = true;
|
||||
|
||||
title = locale::DESIGNS;
|
||||
refresh(playerEmpire);
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0x83cfffff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x009cffff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x49738dff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Designs;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabDesigns);
|
||||
}
|
||||
|
||||
void showDesignEditor(const Design@ dsg) {
|
||||
//Keep a design editor tab in previous so we
|
||||
//don't need to create it all the time
|
||||
if(previous is null) {
|
||||
@previous = createDesignEditorTab();
|
||||
previous.locked = locked;
|
||||
}
|
||||
loadDesignEditor(previous, dsg.mostUpdated());
|
||||
browseTab(this, previous, true);
|
||||
}
|
||||
|
||||
void showDesignEditor(const Hull@ hull, const DesignClass@ cls, const string& name, uint size) {
|
||||
//Keep a design editor tab in previous so we
|
||||
//don't need to create it all the time
|
||||
if(previous is null) {
|
||||
@previous = createDesignEditorTab();
|
||||
previous.locked = locked;
|
||||
}
|
||||
loadDesignEditor(previous, hull, cls, name, size);
|
||||
browseTab(this, previous, true);
|
||||
}
|
||||
|
||||
void refresh(Empire@ emp) {
|
||||
//Keep designs locked while we're doing this
|
||||
ReadLock lock(emp.designMutex);
|
||||
prevDesignCount = emp.designCount;
|
||||
|
||||
const Design@ sel;
|
||||
if(selected !is null) {
|
||||
@sel = selected.dsg;
|
||||
selected.selected = false;
|
||||
@selected = null;
|
||||
}
|
||||
|
||||
//Create panel with list of designs in classes
|
||||
uint designCount = emp.designClassCount;
|
||||
for(uint i = designCount; i < classes.length; ++i)
|
||||
classes[i].remove();
|
||||
|
||||
classes.length = designCount;
|
||||
uint y = 6;
|
||||
for(uint i = 0; i < designCount; ++i) {
|
||||
const DesignClass@ cls = emp.getDesignClass(i);
|
||||
|
||||
//Make a new design class or repurpose one
|
||||
DesignClassElement@ el;
|
||||
if(classes[i] !is null) {
|
||||
@el = classes[i];
|
||||
}
|
||||
else {
|
||||
@el = DesignClassElement(clsPanel, this);
|
||||
@classes[i] = el;
|
||||
}
|
||||
|
||||
//Update the design class list
|
||||
el.refresh(cls);
|
||||
if(el.visible) {
|
||||
el.position = vec2i(0, y);
|
||||
y += el.size.height;
|
||||
}
|
||||
}
|
||||
|
||||
if(sel !is null) {
|
||||
for(uint i = 0, cnt = classes.length; i < cnt; ++i) {
|
||||
for(uint n = 0, ncnt = classes[i].designs.length; n < ncnt; ++n) {
|
||||
if(classes[i].designs[n].dsg is sel) {
|
||||
@selected = classes[i].designs[n];
|
||||
selected.selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createClassButton.position = vec2i(0, y + 4);
|
||||
importButton.position = vec2i(205, y + 4);
|
||||
if(!importButton.visible)
|
||||
showObsoleteButton.position = vec2i(205, y + 4);
|
||||
else
|
||||
showObsoleteButton.position = vec2i(410, y + 4);
|
||||
clsPanel.updateAbsolutePosition();
|
||||
gui_root.updateHover();
|
||||
}
|
||||
|
||||
void show() {
|
||||
visible = true;
|
||||
refresh(playerEmpire);
|
||||
}
|
||||
|
||||
void hide() {
|
||||
visible = false;
|
||||
}
|
||||
|
||||
double timer = 0.0;
|
||||
void tick(double time) {
|
||||
if(visible) {
|
||||
timer += time;
|
||||
if(playerEmpire.designCount != prevDesignCount || timer >= 1.5) {
|
||||
refresh(playerEmpire);
|
||||
timer = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
refresh(playerEmpire);
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
//Draw the global background
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
void selectDesign(const Design@ dsg) {
|
||||
uint clsCnt = classes.length;
|
||||
for(uint i = 0; i < clsCnt; ++i) {
|
||||
DesignClassElement@ clsEl = classes[i];
|
||||
|
||||
uint dsgCnt = clsEl.designs.length;
|
||||
for(uint j = 0; j < dsgCnt; ++j) {
|
||||
DesignElement@ dsgEl = clsEl.designs[j];
|
||||
if(dsgEl.dsg !is dsg) {
|
||||
dsgEl.deselect();
|
||||
}
|
||||
else {
|
||||
dsgEl.select();
|
||||
@selected = dsgEl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clickDesign(const Design@ dsg, int button = 0) {
|
||||
if(button == 2 || (button == 0 && ctrlKey)) {
|
||||
Tab@ tab = createDesignEditorTab(dsg);
|
||||
tab.locked = locked;
|
||||
newTab(this, tab);
|
||||
|
||||
if(shiftKey)
|
||||
switchToTab(tab);
|
||||
}
|
||||
else if(button == 0) {
|
||||
showDesignEditor(dsg);
|
||||
}
|
||||
}
|
||||
|
||||
void scrollToClass(const DesignClass@ cls) {
|
||||
uint clsCnt = classes.length;
|
||||
for(uint i = 0; i < clsCnt; ++i) {
|
||||
DesignClassElement@ clsEl = classes[i];
|
||||
|
||||
if(clsEl.cls !is cls)
|
||||
continue;
|
||||
|
||||
clsPanel.vertPosition = clsEl.position.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void promptCreateClass() {
|
||||
if(focusDialog(D_CreateClass))
|
||||
return;
|
||||
|
||||
InputDialog@ dialog = InputDialog(CreateClass(this), this);
|
||||
dialog.addTitle(locale::CREATE_DESIGN_CLASS);
|
||||
dialog.accept.text = locale::CREATE;
|
||||
dialog.addTextInput(locale::NAME, "");
|
||||
|
||||
addDialog(D_CreateClass, dialog);
|
||||
dialog.focusInput();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.caller is this) {
|
||||
}
|
||||
else if(event.type == GUI_Clicked) {
|
||||
if(event.caller is createClassButton) {
|
||||
promptCreateClass();
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is importButton) {
|
||||
DesignImporter diag(this);
|
||||
addDialog(diag);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is showObsoleteButton) {
|
||||
refresh(playerEmpire);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
uint clsCnt = classes.length;
|
||||
for(uint i = 0; i < clsCnt; ++i) {
|
||||
DesignClassElement@ clsEl = classes[i];
|
||||
|
||||
uint dsgCnt = clsEl.designs.length;
|
||||
for(uint j = 0; j < dsgCnt; ++j) {
|
||||
DesignElement@ dsgEl = clsEl.designs[j];
|
||||
|
||||
if(event.caller is dsgEl) {
|
||||
clickDesign(dsgEl.dsg, event.value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
class DesignClassElement : BaseGuiElement {
|
||||
DesignOverview@ overview;
|
||||
const DesignClass@ cls;
|
||||
DesignElement@[] designs;
|
||||
GuiButton@ createButton;
|
||||
|
||||
DesignClassElement(BaseGuiElement@ pnl, DesignOverview@ ovw) {
|
||||
@overview = ovw;
|
||||
super(pnl, recti());
|
||||
|
||||
@createButton = GuiButton(this,
|
||||
recti(0, 0, int(D_EL_WIDTH * 0.6),
|
||||
int(D_EL_HEIGHT * 0.3)),
|
||||
locale::CREATE_DESIGN);
|
||||
createButton.buttonIcon = icons::Create;
|
||||
createButton.font = FT_Medium;
|
||||
}
|
||||
|
||||
array<DesignSorter> sorter;
|
||||
void refresh(const DesignClass@ Cls) {
|
||||
@cls = Cls;
|
||||
|
||||
int width = parent.size.width - 20;
|
||||
int perRow = (width - 16) / (D_EL_WIDTH + D_EL_SPACING);
|
||||
|
||||
if(perRow == 0)
|
||||
return;
|
||||
|
||||
uint cnt = cls.designCount;
|
||||
for(uint i = cnt; i < designs.length; ++i)
|
||||
designs[i].remove();
|
||||
|
||||
//Sort designs
|
||||
sorter.length = cnt;
|
||||
for(uint i = 0; i < cnt; ++i)
|
||||
@sorter[i].dsg = cls.designs[i];
|
||||
sorter.sortDesc();
|
||||
|
||||
designs.length = cnt;
|
||||
uint index = 0;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
const Design@ dsg = sorter[i].dsg;
|
||||
if(!overview.showObsoleteButton.pressed && dsg.obsolete)
|
||||
continue;
|
||||
|
||||
//Make a new design class or repurpose one
|
||||
DesignElement@ el;
|
||||
if(designs[index] !is null) {
|
||||
@el = designs[index];
|
||||
}
|
||||
else {
|
||||
@el = DesignElement(this, overview);
|
||||
@designs[index] = el;
|
||||
}
|
||||
|
||||
//Update the design summary
|
||||
el.refresh(dsg);
|
||||
++index;
|
||||
}
|
||||
for(uint i = index; i < cnt; ++i) {
|
||||
if(designs[i] !is null)
|
||||
designs[i].remove();
|
||||
}
|
||||
|
||||
designs.length = index;
|
||||
cnt = index;
|
||||
uint itemCount = cnt + 1;
|
||||
int height = 40 + (itemCount / perRow) * (D_EL_HEIGHT + D_EL_SPACING);
|
||||
if(itemCount % perRow != 0 || cls.designCount == 0)
|
||||
height += D_EL_HEIGHT + D_EL_SPACING;
|
||||
|
||||
size = vec2i(width, height);
|
||||
|
||||
//Position them
|
||||
int x = 8, y = 37;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
DesignElement@ el = designs[i];
|
||||
el.position = vec2i(x, y);
|
||||
|
||||
x += D_EL_WIDTH + D_EL_SPACING;
|
||||
if(x + D_EL_WIDTH + D_EL_SPACING > width) {
|
||||
x = 8;
|
||||
y += D_EL_HEIGHT + D_EL_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
createButton.position = vec2i(
|
||||
x + D_EL_WIDTH * 0.2,
|
||||
y + D_EL_HEIGHT * 0.4);
|
||||
visible = designs.length != 0 || cls.designCount == 0;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.caller is createButton && event.type == GUI_Clicked) {
|
||||
overview.refresh(playerEmpire);
|
||||
overview.showDesignEditor(null, cls, "", 1.0);
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(cls is null)
|
||||
return;
|
||||
|
||||
skin.draw(SS_DesignClass, SF_Normal,
|
||||
recti(AbsolutePosition.topLeft,
|
||||
AbsolutePosition.botRight - vec2i(6, 6)));
|
||||
|
||||
skin.draw(SS_DesignClassHeader, SF_Normal,
|
||||
recti_area(AbsolutePosition.topLeft + vec2i(1, 1),
|
||||
vec2i(AbsolutePosition.size.width-9, 30)),
|
||||
CLASS_COLORS[cls.id % CLASS_COLORS.length]);
|
||||
skin.draw(FT_Medium, AbsolutePosition.topLeft + vec2i(12, 4), cls.name);
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class DesignSorter {
|
||||
const Design@ dsg;
|
||||
|
||||
DesignSorter(const Design@ Dsg) {
|
||||
@dsg = Dsg;
|
||||
}
|
||||
|
||||
DesignSorter() {
|
||||
}
|
||||
|
||||
int opCmp(const DesignSorter@ other) const {
|
||||
if(dsg.size > other.dsg.size)
|
||||
return 1;
|
||||
if(dsg.size < other.dsg.size)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
const string str_Support = "Support";
|
||||
class DesignElement : BaseGuiElement {
|
||||
DesignOverview@ overview;
|
||||
GuiBlueprint@ bpview;
|
||||
const Design@ dsg;
|
||||
GuiText@ title;
|
||||
GuiText@ sizeBox;
|
||||
GuiText@ moneyBox;
|
||||
GuiText@ laborBox;
|
||||
GuiSprite@ supportIcon;
|
||||
GuiSprite@ satelliteIcon;
|
||||
GuiSprite@ flagshipIcon;
|
||||
GuiSprite@ stationIcon;
|
||||
|
||||
GuiButton@ editButton;
|
||||
GuiButton@ obsoleteButton;
|
||||
|
||||
bool hovered;
|
||||
bool selected;
|
||||
bool pressed;
|
||||
|
||||
DesignElement(BaseGuiElement@ pnl, DesignOverview@ ovw) {
|
||||
super(pnl, recti(0, 0, D_EL_WIDTH, D_EL_HEIGHT));
|
||||
|
||||
@overview = ovw;
|
||||
|
||||
hovered = false;
|
||||
selected = false;
|
||||
pressed = false;
|
||||
|
||||
@bpview = GuiBlueprint(this, recti());
|
||||
@bpview.alignment = Alignment(Left+2, Top+28, Left+1.0f-2, Bottom-28);
|
||||
bpview.displayHovered = false;
|
||||
|
||||
@editButton = GuiButton(this, Alignment(Right-40, Top+38, Width=34, Height=34));
|
||||
editButton.style = SS_IconButton;
|
||||
editButton.setIcon(icons::Edit);
|
||||
setMarkupTooltip(editButton, locale::TT_EDIT_DESIGN);
|
||||
|
||||
@obsoleteButton = GuiButton(this, Alignment(Right-40, Top+76, Width=34, Height=34));
|
||||
obsoleteButton.style = SS_IconButton;
|
||||
obsoleteButton.setIcon(icons::Obsolete);
|
||||
setMarkupTooltip(obsoleteButton, locale::TT_OBSOLETE_DESIGN);
|
||||
|
||||
@title = GuiText(this, Alignment(Left+8, Top+3, Right-100, Top+30));
|
||||
title.font = FT_Subtitle;
|
||||
title.stroke = colors::Black;
|
||||
|
||||
@sizeBox = GuiText(this, Alignment(Right-150, Top+3, Right-10, Top+30));
|
||||
sizeBox.horizAlign = 1.0;
|
||||
sizeBox.font = FT_Subtitle;
|
||||
sizeBox.stroke = colors::Black;
|
||||
|
||||
@moneyBox = GuiText(this, Alignment(Left+30, Bottom-31, Right, Bottom-4));
|
||||
moneyBox.stroke = colors::Black;
|
||||
|
||||
@laborBox = GuiText(this, Alignment(Left+0.5f, Bottom-31, Right-30, Bottom-4));
|
||||
laborBox.horizAlign = 1.0;
|
||||
laborBox.stroke = colors::Black;
|
||||
|
||||
@supportIcon = GuiSprite(this, Alignment(Left+8, Top+38, Width=30, Height=30));
|
||||
supportIcon.desc = icons::ManageSupports;
|
||||
setMarkupTooltip(supportIcon, locale::TT_SUPPORT_DESIGN);
|
||||
supportIcon.visible = false;
|
||||
|
||||
@satelliteIcon = GuiSprite(this, Alignment(Left+10, Top+38, Width=36, Height=36));
|
||||
satelliteIcon.desc = icons::Satellite;
|
||||
setMarkupTooltip(satelliteIcon, locale::TT_SATELLITE_DESIGN);
|
||||
satelliteIcon.visible = false;
|
||||
|
||||
@flagshipIcon = GuiSprite(this, Alignment(Left+8, Top+38, Width=30, Height=30));
|
||||
flagshipIcon.desc = Sprite(spritesheet::AttributeIcons, 1);
|
||||
flagshipIcon.color = Color(0x00e5f7ff);
|
||||
setMarkupTooltip(flagshipIcon, locale::TT_FLAGSHIP_DESIGN);
|
||||
flagshipIcon.visible = false;
|
||||
|
||||
@stationIcon = GuiSprite(this, Alignment(Left+8, Top+38, Width=30, Height=30));
|
||||
stationIcon.desc = Sprite(spritesheet::GuiOrbitalIcons, 0);
|
||||
stationIcon.color = Color(0x00e5f7ff);
|
||||
setMarkupTooltip(stationIcon, locale::TT_STATION_DESIGN);
|
||||
stationIcon.visible = false;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void select() {
|
||||
selected = true;
|
||||
}
|
||||
|
||||
void deselect() {
|
||||
selected = false;
|
||||
}
|
||||
|
||||
void refresh(const Design@ Dsg) {
|
||||
@dsg = Dsg;
|
||||
@bpview.hull = dsg.hull;
|
||||
@bpview.design = dsg;
|
||||
|
||||
title.text = dsg.name;
|
||||
|
||||
sizeBox.text = format(locale::DESIGN_SIZE, toString(dsg.size, 0));
|
||||
|
||||
const Font@ fnt = skin.getFont(FT_Subtitle);
|
||||
@fnt = skin.getFont(FT_Normal);
|
||||
|
||||
int build = 0, maintain = 0;
|
||||
double labor = 0;
|
||||
getBuildCost(dsg, build, maintain, labor);
|
||||
|
||||
moneyBox.text = formatMoney(build, maintain);
|
||||
laborBox.text = standardize(labor);
|
||||
|
||||
supportIcon.visible = dsg.hasTag(ST_SupportShip);
|
||||
satelliteIcon.visible = dsg.hasTag(ST_Satellite);
|
||||
stationIcon.visible = !supportIcon.visible && dsg.hasTag(ST_Station);
|
||||
flagshipIcon.visible = !supportIcon.visible && !stationIcon.visible && !satelliteIcon.visible;
|
||||
|
||||
if(dsg.obsolete) {
|
||||
obsoleteButton.setIcon(icons::Unobsolete);
|
||||
setMarkupTooltip(obsoleteButton, locale::TT_UNOBSOLETE_DESIGN);
|
||||
}
|
||||
else {
|
||||
obsoleteButton.setIcon(icons::Obsolete);
|
||||
setMarkupTooltip(obsoleteButton, locale::TT_OBSOLETE_DESIGN);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(dsg is null)
|
||||
return;
|
||||
|
||||
uint flags = SF_Normal;
|
||||
if(selected)
|
||||
flags |= SF_Active;
|
||||
if(hovered)
|
||||
flags |= SF_Hovered;
|
||||
|
||||
skin.draw(SS_DesignSummary, flags, AbsolutePosition, dsg.color);
|
||||
skin.draw(SS_FullTitle, flags, recti_area(AbsolutePosition.topLeft+vec2i(1,0),
|
||||
vec2i(AbsolutePosition.size.width-3,33)), dsg.color);
|
||||
if(hovered)
|
||||
skin.draw(SS_SubtleGlow, SF_Normal, AbsolutePosition, dsg.color);
|
||||
|
||||
BaseGuiElement::draw();
|
||||
|
||||
//Draw cost
|
||||
const Font@ normal = skin.getFont(FT_Normal);
|
||||
recti pos = recti_area(vec2i(AbsolutePosition.topLeft.x+4,
|
||||
AbsolutePosition.botRight.y-31), vec2i(24, 24));
|
||||
getTileResourceSprite(TR_Money).draw(pos);
|
||||
|
||||
//Draw labor
|
||||
pos = recti_area(vec2i(AbsolutePosition.botRight.x-32,
|
||||
AbsolutePosition.botRight.y-31), vec2i(24, 24));
|
||||
getTileResourceSprite(TR_Labor).draw(pos + vec2i(4, 0));
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) override {
|
||||
if(cast<GuiButton>(source) is null) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
pressed = true;
|
||||
return true;
|
||||
case MET_Button_Up:
|
||||
if(hovered && pressed) {
|
||||
GuiEvent evt;
|
||||
evt.type = GUI_Clicked;
|
||||
evt.value = event.button;
|
||||
@evt.caller = this;
|
||||
onGuiEvent(evt);
|
||||
pressed = false;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) override {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is editButton) {
|
||||
emitClicked(event.value);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is obsoleteButton) {
|
||||
bool value = !dsg.obsolete;
|
||||
markDesignObsolete(dsg, value);
|
||||
dsg.setObsolete(value);
|
||||
overview.refresh(playerEmpire);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(event.caller is this) {
|
||||
switch(event.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
hovered = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createDesignOverviewTab() {
|
||||
return DesignOverview();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,624 @@
|
||||
import elements.BaseGuiElement;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiContextMenu;
|
||||
import elements.GuiProgressbar;
|
||||
import elements.MarkupTooltip;
|
||||
import targeting.ObjectTarget;
|
||||
import resources;
|
||||
import research;
|
||||
import icons;
|
||||
#include "include/resource_constants.as"
|
||||
|
||||
import tabs.tabbar;
|
||||
from tabs.ResearchTab import createResearchTab;
|
||||
from tabs.DiplomacyTab import createDiplomacyTab;
|
||||
|
||||
const double UPDATE_INTERVAL = 0.05;
|
||||
|
||||
class ResourceDisplay : BaseGuiElement {
|
||||
Color color;
|
||||
GuiSprite@ icon;
|
||||
BaseGuiElement@ value;
|
||||
int padding = 4;
|
||||
MarkupTooltip@ ttip;
|
||||
|
||||
GuiMarkupText@ upperText;
|
||||
GuiMarkupText@ lowerText;
|
||||
|
||||
ResourceDisplay(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
updateAbsolutePosition();
|
||||
@value = BaseGuiElement(this, recti());
|
||||
|
||||
@ttip = MarkupTooltip("", 320, 0.5f, true, false);
|
||||
ttip.StaticPosition = true;
|
||||
ttip.Lazy = true;
|
||||
ttip.LazyUpdate = true;
|
||||
@tooltipObject = ttip;
|
||||
}
|
||||
|
||||
void addIcon(const Sprite& sprt) {
|
||||
@icon = GuiSprite(this, recti_area(vec2i(), sprt.size));
|
||||
icon.desc = sprt;
|
||||
}
|
||||
|
||||
void addTexts() {
|
||||
@upperText = GuiMarkupText(value, recti());
|
||||
upperText.defaultFont = FT_Medium;
|
||||
upperText.memo = true;
|
||||
@lowerText = GuiMarkupText(value, recti());
|
||||
lowerText.memo = true;
|
||||
lowerText.defaultColor = Color(0xaaaaaaff);
|
||||
}
|
||||
|
||||
int get_baseValueWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void update() {
|
||||
//Center the elements
|
||||
int width = 0;
|
||||
if(icon !is null)
|
||||
width += icon.size.width + padding;
|
||||
|
||||
if(value !is null) {
|
||||
int valueWidth = this.baseValueWidth;
|
||||
if(upperText !is null) {
|
||||
valueWidth = max(valueWidth, upperText.textWidth);
|
||||
upperText.position = vec2i(0, 1);
|
||||
upperText.size = vec2i(300, size.height/2);
|
||||
}
|
||||
if(lowerText !is null) {
|
||||
valueWidth = max(valueWidth, lowerText.textWidth);
|
||||
lowerText.position = vec2i(2, size.height/2-1);
|
||||
lowerText.size = vec2i(300, size.height/2);
|
||||
}
|
||||
width += valueWidth;
|
||||
value.size = vec2i(valueWidth+padding, size.height);
|
||||
}
|
||||
|
||||
int pos = (size.width - width) / 2;
|
||||
if(icon !is null) {
|
||||
icon.position = vec2i(pos, (size.height - icon.size.height) / 2 - 2);
|
||||
pos += icon.size.width + padding;
|
||||
}
|
||||
if(value !is null) {
|
||||
value.size = vec2i(value.size.width, size.height);
|
||||
value.position = vec2i(pos, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
if(value !is null)
|
||||
update();
|
||||
if(ttip !is null) {
|
||||
ttip.width = max(size.width, 250);
|
||||
ttip.offset = absolutePosition.topLeft + vec2i(min(size.width-250,0), size.height);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_PlainBox, SF_Normal, AbsolutePosition.padded(0,-2,0,1));
|
||||
|
||||
Color topColor = color;
|
||||
topColor.a = 0x30;
|
||||
|
||||
Color botColor = color;
|
||||
botColor.a = 0x10;
|
||||
|
||||
drawRectangle(AbsolutePosition, topColor, topColor, botColor, botColor);
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class InfluenceResource : ResourceDisplay {
|
||||
InfluenceResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::Influence;
|
||||
addIcon(icons::Influence);
|
||||
addTexts();
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
return format(locale::GTT_INFLUENCE,
|
||||
toString(playerEmpire.Influence),
|
||||
toString(playerEmpire.InfluenceCap, 0),
|
||||
formatIncomeRate(playerEmpire.InfluenceIncome, perMinute=true),
|
||||
toString(playerEmpire.InfluencePercentage*100.0, 0)+"%",
|
||||
toString(playerEmpire.getInfluenceStock(), 0));
|
||||
}
|
||||
|
||||
void update() {
|
||||
int influence = playerEmpire.Influence;
|
||||
double income = playerEmpire.InfluenceIncome;
|
||||
double percentage = playerEmpire.InfluencePercentage;
|
||||
double efficiency = playerEmpire.InfluenceEfficiency;
|
||||
int cap = playerEmpire.InfluenceCap;
|
||||
|
||||
Color storedColor = colors::White;
|
||||
if(efficiency < 1.0 - 0.01)
|
||||
storedColor = Color(0xff0000ff).interpolate(storedColor, efficiency);
|
||||
|
||||
upperText.text = format(
|
||||
"[color=$3]$1[/color][color=#aaa][vspace=6][font=Normal]/$2[/font][/vspace][/color]",
|
||||
toString(influence), toString(cap), toString(storedColor));
|
||||
|
||||
lowerText.text = format(
|
||||
"$1 ($2%)",
|
||||
formatIncomeRate(income, perMinute=true), toString(percentage * 100.f, 0));
|
||||
ResourceDisplay::update();
|
||||
}
|
||||
};
|
||||
|
||||
class EnergyResource : ResourceDisplay {
|
||||
EnergyResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::Energy;
|
||||
addIcon(icons::Energy);
|
||||
addTexts();
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
double income = playerEmpire.EnergyIncome - playerEmpire.EnergyUse;
|
||||
double factor = playerEmpire.EnergyEfficiency;
|
||||
if(income > 0)
|
||||
income *= factor;
|
||||
|
||||
return format(locale::GTT_ENERGY,
|
||||
toString(playerEmpire.EnergyStored, 0),
|
||||
formatIncomeRate(income),
|
||||
toString(playerEmpire.FreeEnergyStorage, 0),
|
||||
"-"+toString((1.0-factor)*100.0, 0)+"%");
|
||||
}
|
||||
|
||||
void update() {
|
||||
double stored = playerEmpire.EnergyStored;
|
||||
double income = playerEmpire.EnergyIncome - playerEmpire.EnergyUse;
|
||||
double factor = playerEmpire.EnergyEfficiency;
|
||||
if(income > 0)
|
||||
income *= factor;
|
||||
|
||||
upperText.text = toString(stored, 0);
|
||||
lowerText.text = formatIncomeRate(income);
|
||||
ResourceDisplay::update();
|
||||
}
|
||||
};
|
||||
|
||||
class FTLResource : ResourceDisplay {
|
||||
FTLResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::FTLResource;
|
||||
addIcon(icons::FTL);
|
||||
addTexts();
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
return format(locale::GTT_FTL,
|
||||
toString(playerEmpire.FTLStored, 0),
|
||||
toString(playerEmpire.FTLCapacity, 0),
|
||||
formatIncomeRate(playerEmpire.FTLIncome - playerEmpire.FTLUse));
|
||||
}
|
||||
|
||||
void update() {
|
||||
double stored = playerEmpire.FTLStored;
|
||||
double income = playerEmpire.FTLIncome - playerEmpire.FTLUse;
|
||||
double capacity = playerEmpire.FTLCapacity;
|
||||
|
||||
upperText.text = format(
|
||||
"$1[color=#aaa][vspace=6][font=Normal]/$2[/font][/vspace][/color]",
|
||||
toString(stored, 0), toString(capacity, 0));
|
||||
|
||||
lowerText.text = formatIncomeRate(income);
|
||||
ResourceDisplay::update();
|
||||
}
|
||||
};
|
||||
|
||||
class ResearchResource : ResourceDisplay {
|
||||
array<TechnologyNode> researching;
|
||||
|
||||
GuiProgressbar@ techBar;
|
||||
GuiSprite@ techIcon;
|
||||
|
||||
ResearchResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::Research;
|
||||
addIcon(icons::Research);
|
||||
addTexts();
|
||||
|
||||
@techBar = GuiProgressbar(value, Alignment(Left, Bottom-0.5f+3, Left+100, Bottom-4));
|
||||
techBar.strokeColor = colors::Black;
|
||||
techBar.textHorizAlign = 0.9;
|
||||
@techIcon = GuiSprite(techBar, Alignment(Left+2, Top+0.5f-12, Left+2+24, Top+0.5f+12));
|
||||
techIcon.noClip = true;
|
||||
}
|
||||
|
||||
int get_baseValueWidth() {
|
||||
if(techBar is null || !techBar.visible)
|
||||
return 0;
|
||||
return 100;
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
string tt = format(locale::GTT_RESEARCH,
|
||||
toString(playerEmpire.ResearchPoints, 0),
|
||||
formatIncomeRate(playerEmpire.ResearchRate));
|
||||
for(uint i = 0, cnt = researching.length; i < cnt; ++i) {
|
||||
tt += "\n"+format(locale::GTT_RESEARCH_TECH,
|
||||
researching[i].type.name, formatTime(researching[i].timer),
|
||||
toString(researching[i].type.color));
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
|
||||
void update() {
|
||||
double stored = playerEmpire.ResearchPoints;
|
||||
double income = playerEmpire.ResearchRate;
|
||||
|
||||
upperText.text = toString(stored, 0);
|
||||
lowerText.text = formatIncomeRate(income);
|
||||
|
||||
researching.syncFrom(playerEmpire.getResearchingNodes());
|
||||
if(researching.length != 0) {
|
||||
researching.sortAsc();
|
||||
|
||||
techBar.visible = true;
|
||||
lowerText.visible = false;
|
||||
|
||||
auto@ activeTech = researching[0];
|
||||
techBar.text = formatTime(activeTech.timer);
|
||||
techIcon.desc = activeTech.type.icon;
|
||||
techBar.frontColor = activeTech.type.color;
|
||||
techBar.textColor = activeTech.type.color.interpolate(colors::White, 0.75f);
|
||||
techBar.progress = 1.0 - (activeTech.timer / activeTech.getTimeCost(playerEmpire));
|
||||
}
|
||||
else {
|
||||
techBar.visible = false;
|
||||
lowerText.visible = true;
|
||||
}
|
||||
|
||||
ResourceDisplay::update();
|
||||
}
|
||||
};
|
||||
|
||||
class ChangeWelfare : GuiContextOption {
|
||||
ChangeWelfare(const string& text, uint index) {
|
||||
value = int(index);
|
||||
this.text = text;
|
||||
icon = Sprite(spritesheet::ConvertIcon, index);
|
||||
}
|
||||
|
||||
void call(GuiContextMenu@ menu) override {
|
||||
playerEmpire.WelfareMode = uint(value);
|
||||
}
|
||||
};
|
||||
|
||||
class BudgetResource : ResourceDisplay {
|
||||
array<TechnologyNode> researching;
|
||||
|
||||
GuiProgressbar@ cycleBar;
|
||||
|
||||
GuiButton@ welfareButton;
|
||||
GuiSprite@ welfareIcon;
|
||||
|
||||
GuiText@ nextBudget;
|
||||
|
||||
BudgetResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::Money;
|
||||
addIcon(icons::Money);
|
||||
addTexts();
|
||||
|
||||
@cycleBar = GuiProgressbar(value, Alignment(Left, Bottom-0.5f+3, Left+120, Bottom-4));
|
||||
cycleBar.font = FT_Small;
|
||||
|
||||
@nextBudget = GuiText(value, Alignment(Left+120, Bottom-0.5f+1, Left+200, Bottom-1));
|
||||
nextBudget.horizAlign = 0.5;
|
||||
|
||||
@welfareButton = GuiButton(value, Alignment(Right-84+40-25, Top, Width=50, Height=24));
|
||||
@welfareIcon = GuiSprite(welfareButton, Alignment(Left+8, Top-5, Right-8, Bottom+5),
|
||||
Sprite(spritesheet::ConvertIcon, 0));
|
||||
|
||||
setMarkupTooltip(welfareButton, locale::WELFARE_TT, hoverStyle=false);
|
||||
}
|
||||
|
||||
int get_baseValueWidth() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
string tt = format(locale::GTT_MONEY,
|
||||
formatMoneyChange(playerEmpire.RemainingBudget, colored=true),
|
||||
formatMoneyChange(playerEmpire.EstNextBudget, colored=true),
|
||||
formatTime(playerEmpire.BudgetCycle - playerEmpire.BudgetTimer),
|
||||
getSpriteDesc(welfareIcon.desc));
|
||||
tt += format("\n[font=Medium]$1[/font]\n", locale::RESOURCE_BUDGET);
|
||||
for(int i = MoT_COUNT - 1; i >= 0; --i) {
|
||||
int money = playerEmpire.getMoneyFromType(i);
|
||||
if(money != 0) {
|
||||
tt += format("$1: [right]$2[/right]",
|
||||
localize("MONEY_TYPE_"+i), formatMoneyChange(money, true));
|
||||
}
|
||||
}
|
||||
|
||||
int bonusMoney = playerEmpire.BonusBudget;
|
||||
if(bonusMoney != 0)
|
||||
tt += "\n\n"+format(locale::GTT_BONUS_MONEY, formatMoney(bonusMoney));
|
||||
|
||||
float debtFactor = playerEmpire.DebtFactor;
|
||||
if(debtFactor > 1.f) {
|
||||
float effFactor = pow(0.5f, debtFactor-1.f);
|
||||
tt += "\n\n"+format(locale::GTT_FLEET_PENALTY, "-"+toString((1.f - effFactor)*100.f, 0)+"%");
|
||||
}
|
||||
if(debtFactor > 0.f) {
|
||||
float growthFactor = 1.f;
|
||||
for(; debtFactor > 0; debtFactor -= 1.f)
|
||||
growthFactor *= 0.33f + 0.67f * (1.f - min(debtFactor, 1.f));
|
||||
tt += "\n\n"+format(locale::GTT_DEBT_PENALTY, "-"+toString((1.f - growthFactor)*100.f, 0)+"%");
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.caller is welfareButton && evt.type == GUI_Clicked) {
|
||||
GuiContextMenu menu(mousePos);
|
||||
menu.itemHeight = 54;
|
||||
string money = formatMoney(350.0 / playerEmpire.WelfareEfficiency);
|
||||
menu.addOption(ChangeWelfare(format(locale::WELFARE_INFLUENCE, money), 0));
|
||||
menu.addOption(ChangeWelfare(format(locale::WELFARE_ENERGY, money), 1));
|
||||
menu.addOption(ChangeWelfare(format(locale::WELFARE_RESEARCH, money), 2));
|
||||
menu.addOption(ChangeWelfare(format(locale::WELFARE_LABOR, money), 3));
|
||||
menu.addOption(ChangeWelfare(format(locale::WELFARE_DEFENSE, money), 4));
|
||||
menu.updateAbsolutePosition();
|
||||
return true;
|
||||
}
|
||||
return ResourceDisplay::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
//NOTE: Maybe related to spectating?
|
||||
if(playerEmpire is null)
|
||||
return;
|
||||
|
||||
//Current budget
|
||||
int curBudget = playerEmpire.RemainingBudget;
|
||||
int bonusBudget = playerEmpire.BonusBudget;
|
||||
|
||||
Color color(0xffffffff);
|
||||
if(curBudget < 0)
|
||||
color = Color(0xff0000ff);
|
||||
else if(curBudget - bonusBudget < 0)
|
||||
color = Color(0xff8000ff);
|
||||
else
|
||||
color = Color(0xffffffff);
|
||||
|
||||
upperText.defaultColor = color;
|
||||
upperText.text = formatMoney(curBudget, roundUp=false);
|
||||
|
||||
welfareIcon.desc = Sprite(spritesheet::ConvertIcon, playerEmpire.WelfareMode);
|
||||
|
||||
//Cycle timer
|
||||
double cycle = playerEmpire.BudgetCycle;
|
||||
double timer = playerEmpire.BudgetTimer;
|
||||
|
||||
cycleBar.text = formatTime(cycle - timer);
|
||||
if(cycle == 0)
|
||||
cycleBar.progress = 0.f;
|
||||
else
|
||||
cycleBar.progress = timer / cycle;
|
||||
|
||||
if(cycleBar.progress < (1.0 / 3.0))
|
||||
cycleBar.frontColor = colors::Money;
|
||||
else if(cycleBar.progress < (2.0 / 3.0))
|
||||
cycleBar.frontColor = colors::Money.interpolate(colors::Red, 0.3);
|
||||
else
|
||||
cycleBar.frontColor = colors::Money.interpolate(colors::Red, 0.6);
|
||||
|
||||
//Next budget
|
||||
int upcoming = playerEmpire.EstNextBudget;
|
||||
if(upcoming < 0)
|
||||
nextBudget.color = Color(0xbb0000ff);
|
||||
else
|
||||
nextBudget.color = Color(0xbbbbbbff);
|
||||
nextBudget.text = formatMoney(upcoming);
|
||||
|
||||
ResourceDisplay::update();
|
||||
}
|
||||
};
|
||||
|
||||
class DeployTarget : ObjectTargeting {
|
||||
DeployTarget() {
|
||||
icon = icons::Defense;
|
||||
}
|
||||
|
||||
void call(Object@ target) {
|
||||
playerEmpire.deployDefense(target);
|
||||
}
|
||||
|
||||
string message(Object@ obj, bool valid) {
|
||||
return locale::TT_DEPLOY;
|
||||
}
|
||||
|
||||
bool valid(Object@ obj) {
|
||||
if(!obj.isPlanet)
|
||||
return false;
|
||||
return obj.owner !is null && obj.owner.valid;
|
||||
}
|
||||
};
|
||||
|
||||
class DefenseResource : ResourceDisplay {
|
||||
GuiProgressbar@ bar;
|
||||
GuiButton@ button;
|
||||
|
||||
DefenseResource(IGuiElement@ parent, Alignment@ align) {
|
||||
super(parent, align);
|
||||
|
||||
color = colors::Defense;
|
||||
addIcon(icons::Defense);
|
||||
addTexts();
|
||||
|
||||
@bar = GuiProgressbar(value, Alignment(Left, Bottom-0.5f+3, Left+100, Bottom-4));
|
||||
bar.frontColor = colors::Defense;
|
||||
bar.font = FT_Small;
|
||||
bar.visible = false;
|
||||
|
||||
@button = GuiButton(value, Alignment(Left+70, Top+2, Left+100, Top+28));
|
||||
GuiSprite(button, Alignment().padded(-2), icons::Strength);
|
||||
button.visible = false;
|
||||
setMarkupTooltip(button, locale::TT_DEPLOY);
|
||||
}
|
||||
|
||||
string get_tooltip() {
|
||||
return format(locale::GTT_DEFENSE,
|
||||
standardize(playerEmpire.globalDefenseRate * 60.0 / DEFENSE_LABOR_PM, true)+locale::PER_MINUTE,
|
||||
standardize(playerEmpire.globalDefenseStorage, true),
|
||||
standardize(playerEmpire.globalDefenseStored, true));
|
||||
}
|
||||
|
||||
int get_baseValueWidth() {
|
||||
return bar.visible ? 100 : 0;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) override {
|
||||
if(evt.caller is button && evt.type == GUI_Clicked) {
|
||||
targetObject(DeployTarget());
|
||||
return true;
|
||||
}
|
||||
return ResourceDisplay::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
void update() {
|
||||
double income = playerEmpire.globalDefenseRate / DEFENSE_LABOR_PM;
|
||||
upperText.text = format(
|
||||
"$1[color=#aaa][vspace=6][font=Normal]$2[/font][/vspace][/color]",
|
||||
toString(income * 60.0, 0), locale::PER_MINUTE);
|
||||
ResourceDisplay::update();
|
||||
|
||||
double storage = playerEmpire.globalDefenseStorage;
|
||||
double stored = playerEmpire.globalDefenseStored;
|
||||
|
||||
if(storage == 0) {
|
||||
upperText.position = vec2i(0, 8);
|
||||
bar.visible = false;
|
||||
button.visible = false;
|
||||
}
|
||||
else {
|
||||
upperText.position = vec2i(0, 1);
|
||||
bar.text = standardize(floor(stored), true)+" / "+standardize(storage, true);
|
||||
bar.progress= stored / storage;
|
||||
bar.visible = true;
|
||||
button.visible = stored >= storage*0.9999;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class GlobalBar : BaseGuiElement {
|
||||
BaseGuiElement@ container;
|
||||
double updateTimer = -INFINITY;
|
||||
|
||||
array<ResourceDisplay@> sections;
|
||||
ResourceDisplay@ budget;
|
||||
ResourceDisplay@ energy;
|
||||
ResourceDisplay@ ftl;
|
||||
ResourceDisplay@ influence;
|
||||
ResourceDisplay@ research;
|
||||
ResourceDisplay@ defense;
|
||||
|
||||
GlobalBar() {
|
||||
super(null, recti());
|
||||
|
||||
@container = BaseGuiElement(this, Alignment_Fill());
|
||||
container.StrictBounds = true;
|
||||
|
||||
@budget = BudgetResource(container, Alignment());
|
||||
sections.insertLast(budget);
|
||||
|
||||
@influence = InfluenceResource(container, Alignment());
|
||||
sections.insertLast(influence);
|
||||
|
||||
@energy = EnergyResource(container, Alignment());
|
||||
sections.insertLast(energy);
|
||||
|
||||
@ftl = FTLResource(container, Alignment());
|
||||
sections.insertLast(ftl);
|
||||
|
||||
@research = ResearchResource(container, Alignment());
|
||||
sections.insertLast(research);
|
||||
|
||||
@defense = DefenseResource(container, Alignment());
|
||||
sections.insertLast(defense);
|
||||
|
||||
updateSections();
|
||||
}
|
||||
|
||||
void update() {
|
||||
for(uint i = 0, cnt = sections.length; i < cnt; ++i)
|
||||
sections[i].update();
|
||||
}
|
||||
|
||||
void updateSections(){
|
||||
float x = 0.f;
|
||||
for(uint i = 0, cnt = sections.length; i < cnt; ++i) {
|
||||
float w;
|
||||
if(size.width >= 1600)
|
||||
w = 1.f / 6.f;
|
||||
else if(i == 0)
|
||||
w = 1.f / 5.f;
|
||||
else
|
||||
w = (1.f - (1.f / 5.f)) / 5.f;
|
||||
|
||||
sections[i].alignment = Alignment(Left+x, Top, Left+x+w, Bottom);
|
||||
x += w;
|
||||
}
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
int width = AbsolutePosition.width;
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
if(width != AbsolutePosition.width)
|
||||
updateSections();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(frameTime - UPDATE_INTERVAL >= updateTimer) {
|
||||
update();
|
||||
updateTimer = frameTime;
|
||||
}
|
||||
|
||||
skin.draw(SS_GlobalBar, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
}
|
||||
|
||||
BaseGuiElement@ createGlobalBar() {
|
||||
return GlobalBar();
|
||||
}
|
||||
|
||||
void preReload(Message& msg) {
|
||||
globalBar.remove();
|
||||
}
|
||||
|
||||
void postReload(Message& msg) {
|
||||
@globalBar = GlobalBar();
|
||||
@globalBar.alignment = Alignment(Left, Top+TAB_HEIGHT + 2, Right, Top+TAB_HEIGHT + 2 + GLOBAL_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
void deploy_defense(bool pressed) {
|
||||
if(pressed)
|
||||
targetObject(DeployTarget());
|
||||
}
|
||||
|
||||
void init() {
|
||||
keybinds::Global.addBind(KB_DEPLOY_DEFENSE, "deploy_defense");
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import tabs.Tab;
|
||||
from tabs.tabbar import newTab, switchToTab;
|
||||
|
||||
Tab@ createGraphicsEditorTab() {
|
||||
return GraphicsEditor();
|
||||
}
|
||||
|
||||
class GraphicsEditor : Tab {
|
||||
string& get_title() {
|
||||
return locale::GRAPHICS_EDITOR;
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xaaaaaaff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x777777ff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Graphics;
|
||||
}
|
||||
};
|
||||
|
||||
interface Anchor {
|
||||
vec3d get_position() const;
|
||||
|
||||
vec3d get_normal() const;
|
||||
};
|
||||
|
||||
class PointAnchor : Anchor {
|
||||
vec3d point;
|
||||
vec3d direction;
|
||||
|
||||
vec3d get_position() const {
|
||||
return point;
|
||||
}
|
||||
|
||||
vec3d get_normal() const {
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
class CurveAnchor : Anchor {
|
||||
const Anchor@ from;
|
||||
const Anchor@ to;
|
||||
float percent;
|
||||
|
||||
vec3d get_position() const {
|
||||
vec3d p0 = from.position;
|
||||
vec3d p1 = p0 + from.normal;
|
||||
vec3d p3 = to.position;
|
||||
vec3d p2 = p3 + to.normal;
|
||||
|
||||
double t = percent, nt = 1.0 - percent;
|
||||
|
||||
return p0 * (nt*nt*nt) + p1 * (3.0*t*nt*nt) + p2 * (3.0*t*t*nt) + p3 * (t*t*t);
|
||||
}
|
||||
|
||||
vec3d get_normal() const {
|
||||
vec3d p0 = from.position;
|
||||
vec3d p1 = p0 + from.normal;
|
||||
vec3d p3 = to.position;
|
||||
vec3d p2 = p3 + to.normal;
|
||||
|
||||
double t = percent, nt = 1.0 - percent;
|
||||
|
||||
return (p0*(t*t) + p1 * (3.0*t*t - 4.0*t + 1.0) + p2*(-3.0*t*t + 2.0*t) + p3 * ((t - 1.0)*(t-1.0))).normalize();
|
||||
}
|
||||
}
|
||||
|
||||
class GraphicsEditorCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
Tab@ editor = createGraphicsEditorTab();
|
||||
newTab(editor);
|
||||
switchToTab(editor);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("graphics_editor", GraphicsEditorCommand());
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiButton;
|
||||
|
||||
from tabs.tabbar import popTab, browseTab;
|
||||
from tabs.DiplomacyTab import createDiplomacyTab;
|
||||
from tabs.GalaxyTab import createGalaxyTab;
|
||||
from tabs.DesignOverviewTab import createDesignOverviewTab;
|
||||
from tabs.WikiTab import createWikiTab;
|
||||
from tabs.ResearchTab import createResearchTab;
|
||||
from tabs.PlanetsTab import createPlanetsTab;
|
||||
from tabs.AttitudesTab import createAttitudesTab;
|
||||
from community.Home import createCommunityHome;
|
||||
|
||||
class HomeTab : Tab {
|
||||
GuiButton@ galaxyButton;
|
||||
GuiButton@ researchButton;
|
||||
GuiButton@ designsButton;
|
||||
GuiButton@ diplomacyButton;
|
||||
GuiButton@ planetsButton;
|
||||
GuiButton@ wikiButton;
|
||||
GuiButton@ menuButton;
|
||||
GuiButton@ attButton;
|
||||
|
||||
HomeTab() {
|
||||
super();
|
||||
title = "Home";
|
||||
|
||||
int w = 300, hw = w/2;
|
||||
@galaxyButton = GuiButton(this, Alignment(Left+0.5f-w-hw, Top+20, Width=w-10, Height=80), locale::GALAXY);
|
||||
galaxyButton.font = FT_Medium;
|
||||
galaxyButton.buttonIcon = Sprite(material::SystemUnderAttack);
|
||||
galaxyButton.color = Color(0xff9600ff);
|
||||
@researchButton = GuiButton(this, Alignment(Left+0.5f-hw, Top+20, Width=w-10, Height=80), locale::RESEARCH);
|
||||
researchButton.font = FT_Medium;
|
||||
researchButton.buttonIcon = Sprite(material::TabResearch);
|
||||
researchButton.color = Color(0xd482ffff);
|
||||
@designsButton = GuiButton(this, Alignment(Left+0.5f+hw, Top+20, Width=w-10, Height=80), locale::DESIGNS);
|
||||
designsButton.font = FT_Medium;
|
||||
designsButton.buttonIcon = Sprite(material::TabDesigns);
|
||||
designsButton.color = Color(0x009cffff);
|
||||
@diplomacyButton = GuiButton(this, Alignment(Left+0.5f-w-hw, Top+110, Width=w-10, Height=80), locale::DIPLOMACY);
|
||||
diplomacyButton.font = FT_Medium;
|
||||
diplomacyButton.buttonIcon = Sprite(material::TabDiplomacy);
|
||||
diplomacyButton.color = Color(0x37ff00ff);
|
||||
@planetsButton = GuiButton(this, Alignment(Left+0.5f-hw, Top+110, Width=w-10, Height=80), locale::PLANETS_TAB);
|
||||
planetsButton.font = FT_Medium;
|
||||
planetsButton.buttonIcon = Sprite(material::TabPlanets);
|
||||
planetsButton.color = Color(0xccff00ff);
|
||||
@wikiButton = GuiButton(this, Alignment(Left+0.5f+hw, Top+110, Width=w-10, Height=80), locale::COMMUNITY_HOME_TITLE);
|
||||
wikiButton.font = FT_Medium;
|
||||
wikiButton.buttonIcon = Sprite(spritesheet::MenuIcons, 3);
|
||||
wikiButton.color = Color(0xff0077ff);
|
||||
|
||||
if(hasDLC("Heralds")) {
|
||||
@attButton = GuiButton(this, Alignment(Left+0.5f-w-hw, Top+200, Width=w-10, Height=80), locale::ATTITUDES_TAB);
|
||||
attButton.font = FT_Medium;
|
||||
attButton.buttonIcon = Sprite(material::TabGalaxy);
|
||||
attButton.color = Color(0x63ebdbff);
|
||||
}
|
||||
|
||||
@menuButton = GuiButton(this, Alignment(Left+0.5f-hw, Bottom-90, Width=w-10, Height=80), locale::MAIN_MENU);
|
||||
menuButton.font = FT_Medium;
|
||||
menuButton.color = Color(0xaaaaaaff);
|
||||
}
|
||||
|
||||
void hide() {
|
||||
if(previous !is null)
|
||||
popTab(this);
|
||||
Tab::hide();
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8e8e8eff);
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case KET_Key_Up:
|
||||
if(event.key == KEY_ESC) {
|
||||
if(previous !is null)
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onKeyEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is galaxyButton) {
|
||||
browseTab(this, createGalaxyTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is researchButton) {
|
||||
browseTab(this, createResearchTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is designsButton) {
|
||||
browseTab(this, createDesignOverviewTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is diplomacyButton) {
|
||||
browseTab(this, createDiplomacyTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is planetsButton) {
|
||||
browseTab(this, createPlanetsTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is wikiButton) {
|
||||
browseTab(this, createCommunityHome(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is attButton) {
|
||||
browseTab(this, createAttitudesTab(), false);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is menuButton) {
|
||||
switchToMenu();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createHomeTab() {
|
||||
return HomeTab();
|
||||
}
|
||||
|
||||
bool isHomeTab(Tab@ tab) {
|
||||
return cast<HomeTab@>(tab) !is null;
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import influence;
|
||||
import util.formatting;
|
||||
|
||||
from tabs.tabbar import popTab, browseTab, get_ActiveTab;
|
||||
from tabs.InfluenceVoteTab import createInfluenceVoteTab;
|
||||
|
||||
const double UPDATE_TIMER = 1.0;
|
||||
|
||||
class InfluenceHistoryTab : Tab {
|
||||
uint limit = 10;
|
||||
int beforeId = -1;
|
||||
bool reverse = true;
|
||||
|
||||
GuiBackgroundPanel@ bg;
|
||||
|
||||
GuiButton@ backButton;
|
||||
GuiButton@ olderButton;
|
||||
GuiButton@ newerButton;
|
||||
|
||||
InfluenceVote[] votes;
|
||||
VoteBox@[] boxes;
|
||||
|
||||
double updateTime = 0.0;
|
||||
|
||||
InfluenceHistoryTab() {
|
||||
super();
|
||||
title = locale::VOTE_HISTORY;
|
||||
|
||||
@bg = GuiBackgroundPanel(this, Alignment(Left+8, Top+8, Right-8, Bottom-8));
|
||||
bg.title = locale::VOTE_HISTORY;
|
||||
bg.titleColor = Color(0x00bffeff);
|
||||
bg.picture = Sprite(material::Propositions);
|
||||
|
||||
@backButton = GuiButton(this, recti(14, 40, 212, 70), locale::DIPLOMACY_BACK);
|
||||
|
||||
@newerButton = GuiButton(this, Alignment(Left+0.5f-222, Top+40, Left+0.5f-2, Top+70), locale::NEWER);
|
||||
|
||||
@olderButton = GuiButton(this, Alignment(Left+0.5f+2, Top+40, Left+0.5f+222, Top+70), locale::OLDER);
|
||||
|
||||
update();
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
updateTime -= time;
|
||||
if(updateTime <= 0) {
|
||||
update();
|
||||
updateTime += UPDATE_TIMER;
|
||||
}
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(reverse) {
|
||||
votes.syncFrom(getInfluenceVoteHistory(limit+1, beforeId, true));
|
||||
}
|
||||
else {
|
||||
votes.syncFrom(getInfluenceVoteHistory(limit+1, beforeId, false));
|
||||
if(votes.length <= limit) {
|
||||
beforeId = -1;
|
||||
}
|
||||
else {
|
||||
beforeId = votes[limit].id;
|
||||
votes.removeAt(limit);
|
||||
}
|
||||
votes.reverse();
|
||||
}
|
||||
|
||||
uint oldCnt = boxes.length;
|
||||
uint newCnt = min(votes.length, limit);
|
||||
for(uint i = newCnt; i < oldCnt; ++i)
|
||||
boxes[i].remove();
|
||||
boxes.length = newCnt;
|
||||
|
||||
for(uint i = 0; i < newCnt; ++i) {
|
||||
if(boxes[i] is null)
|
||||
@boxes[i] = VoteBox(this);
|
||||
boxes[i].set(votes[i]);
|
||||
boxes[i].position = vec2i(16, 78 + i * 32);
|
||||
}
|
||||
|
||||
olderButton.disabled = reverse && votes.length <= limit;
|
||||
newerButton.disabled = votes.length == 0 || beforeId == -1;
|
||||
reverse = true;
|
||||
}
|
||||
|
||||
void hide() {
|
||||
Tab::hide();
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
//Update box list size
|
||||
uint show = max((size.height - 80) / 32, 2);
|
||||
if(show != limit) {
|
||||
limit = show;
|
||||
update();
|
||||
}
|
||||
|
||||
Tab::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is backButton) {
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is olderButton) {
|
||||
if(votes.length < limit)
|
||||
return true;
|
||||
beforeId = votes[limit-1].id;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is newerButton) {
|
||||
if(votes.length == 0)
|
||||
return true;
|
||||
reverse = false;
|
||||
beforeId = votes[0].id;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0x74fc4eff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0x37ff00ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x408c2bff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Diplomacy;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabDiplomacy);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DiplomacyBG, SF_Normal, AbsolutePosition);
|
||||
Tab::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class VoteBox : BaseGuiElement {
|
||||
uint prevId = uint(-1);
|
||||
InfluenceVote@ vote;
|
||||
|
||||
GuiText@ timeBox;
|
||||
GuiMarkupText@ titleBox;
|
||||
GuiText@ statusBox;
|
||||
|
||||
GuiButton@ detailsButton;
|
||||
|
||||
VoteBox(IGuiElement@ parent) {
|
||||
super(parent, recti(0, 0, parent.size.width - 48, 32));
|
||||
|
||||
@timeBox = GuiText(this, recti(4, 6, 120, 26));
|
||||
timeBox.font = FT_Small;
|
||||
timeBox.color = Color(0x888888ff);
|
||||
timeBox.horizAlign = 0.5;
|
||||
|
||||
@titleBox = GuiMarkupText(this, Alignment(Left+124, Top+6, Right-208, Top+26));
|
||||
|
||||
@statusBox = GuiText(this, Alignment(Right-204, Top+6, Right-4, Top+26));
|
||||
|
||||
@detailsButton = GuiButton(this, Alignment(Right-84, Top+4, Right-4, Top+28), locale::VIEW);
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void set(InfluenceVote@ newVote) {
|
||||
//Only update data when set to a different vote
|
||||
if(vote !is null && newVote.id == prevId) {
|
||||
@vote = newVote;
|
||||
return;
|
||||
}
|
||||
|
||||
@vote = newVote;
|
||||
prevId = vote.id;
|
||||
|
||||
//Set the data fields
|
||||
titleBox.text = formatEmpireName(vote.startedBy)+": "+vote.formatTitle();
|
||||
timeBox.text = formatGameTime(vote.startedAt)+" - "+formatGameTime(vote.endedAt);
|
||||
|
||||
if(vote.succeeded) {
|
||||
statusBox.text = locale::PASSED;
|
||||
statusBox.color = Color(0x00ff00ff);
|
||||
}
|
||||
else {
|
||||
statusBox.text = locale::FAILED;
|
||||
statusBox.color = Color(0xff0000ff);
|
||||
}
|
||||
}
|
||||
|
||||
void remove() {
|
||||
@vote = null;
|
||||
BaseGuiElement::remove();
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
|
||||
int w = parent.size.width - 24;
|
||||
if(size.width != w)
|
||||
size = vec2i(w, size.height);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_InfluenceVoteBox, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked:
|
||||
if(evt.caller is detailsButton) {
|
||||
browseTab(ActiveTab, createInfluenceVoteTab(vote.id), true);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(evt);
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createInfluenceHistoryTab() {
|
||||
return InfluenceHistoryTab();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,99 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiText;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiButton;
|
||||
|
||||
from tabs.tabbar import newTab, switchToTab;
|
||||
|
||||
Tab@ createNameGeneratorTab() {
|
||||
return NameGeneratorTab();
|
||||
}
|
||||
|
||||
class NameGeneratorCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
Tab@ editor = createNameGeneratorTab();
|
||||
newTab(editor);
|
||||
switchToTab(editor);
|
||||
}
|
||||
};
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("name_generator", NameGeneratorCommand());
|
||||
}
|
||||
|
||||
class NameGeneratorTab : Tab {
|
||||
NameGenerator gen;
|
||||
|
||||
GuiTextbox@ filename;
|
||||
GuiButton@ saveButton;
|
||||
GuiButton@ loadButton;
|
||||
|
||||
GuiText@ mutationHeader;
|
||||
GuiTextbox@ mutationChance;
|
||||
GuiText@ nameCount;
|
||||
|
||||
GuiTextbox@ nameBox;
|
||||
GuiButton@ generateButton;
|
||||
GuiButton@ addButton;
|
||||
|
||||
NameGeneratorTab() {
|
||||
super();
|
||||
title = "Name Generator";
|
||||
gen.read("data/system_names.txt");
|
||||
|
||||
@filename = GuiTextbox(this, recti(4, 4, 404, 30), "data/system_names.txt");
|
||||
@loadButton = GuiButton(this, recti(410, 4, 510, 30), locale::LOAD);
|
||||
@saveButton = GuiButton(this, recti(516, 4, 616, 30), locale::SAVE);
|
||||
|
||||
@mutationHeader = GuiText(this, recti(4, 34, 204, 60), locale::MUTATION_CHANCE);
|
||||
@mutationChance = GuiTextbox(this, recti(210, 34, 310, 60), "0.00");
|
||||
@nameCount = GuiText(this, recti(316, 34, 610, 60));
|
||||
nameCount.horizAlign = 1.0;
|
||||
nameCount.text = format(locale::NAME_COUNT, toString(gen.nameCount));
|
||||
|
||||
@nameBox = GuiTextbox(this, recti(4, 80, 404, 106));
|
||||
@generateButton = GuiButton(this, recti(410, 80, 510, 106), locale::GENERATE);
|
||||
@addButton = GuiButton(this, recti(516, 80, 616, 106), locale::ADD);
|
||||
|
||||
nameBox.text = gen.generate();
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
switch(event.type) {
|
||||
case GUI_Clicked:
|
||||
if(event.caller is loadButton) {
|
||||
gen.clear();
|
||||
gen.read(filename.text);
|
||||
nameCount.text = format(locale::NAME_COUNT, toString(gen.nameCount));
|
||||
nameBox.text = gen.generate();
|
||||
mutationChance.text = toString(gen.mutationChance, 2);
|
||||
}
|
||||
else if(event.caller is saveButton) {
|
||||
gen.write(filename.text);
|
||||
}
|
||||
else if(event.caller is generateButton) {
|
||||
nameBox.text = gen.generate();
|
||||
}
|
||||
else if(event.caller is addButton) {
|
||||
if(!gen.hasName(nameBox.text))
|
||||
gen.addName(nameBox.text);
|
||||
nameBox.text = gen.generate();
|
||||
nameCount.text = format(locale::NAME_COUNT, toString(gen.nameCount));
|
||||
}
|
||||
break;
|
||||
case GUI_Changed:
|
||||
if(event.caller is mutationChance) {
|
||||
gen.mutationChance = toFloat(mutationChance.text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,512 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiText;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiTextbox;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiCheckbox;
|
||||
import elements.GuiButton;
|
||||
import dialogs.MaterialChooser;
|
||||
import dialogs.ColorDialog;
|
||||
import dialogs.InputDialog;
|
||||
from tabs.tabbar import newTab, switchToTab;
|
||||
|
||||
Tab@ createParticlesTab() {
|
||||
return ParticlesTab();
|
||||
}
|
||||
|
||||
class ParticlesTabCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
Tab@ editor = createParticlesTab();
|
||||
newTab(editor);
|
||||
switchToTab(editor);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("particle_editor", ParticlesTabCommand());
|
||||
}
|
||||
|
||||
class FlowEntry : GuiListText {
|
||||
ParticlesTab@ tab;
|
||||
ParticleFlow@ flow;
|
||||
uint index;
|
||||
|
||||
FlowEntry(ParticlesTab@ Tab, ParticleFlow@ Flow, uint Index) {
|
||||
@tab = Tab;
|
||||
@flow = Flow;
|
||||
index = Index;
|
||||
|
||||
string matName = Flow.materials[0];
|
||||
if(matName.length == 0)
|
||||
super("Empty Flow");
|
||||
else
|
||||
super(matName);
|
||||
}
|
||||
|
||||
void onSelect() override {
|
||||
tab.switchToFlow(flow, index);
|
||||
}
|
||||
};
|
||||
|
||||
class SizeChangeEvent : InputDialogCallback {
|
||||
ParticlesTab@ tab;
|
||||
uint index;
|
||||
|
||||
SizeChangeEvent(ParticlesTab@ Tab, uint Index) {
|
||||
index = Index;
|
||||
@tab = Tab;
|
||||
}
|
||||
|
||||
void inputCallback(InputDialog@ dialog, bool accepted) {
|
||||
tab.changeSize(index, dialog.getSpinboxInput(0));
|
||||
}
|
||||
|
||||
void changeCallback(InputDialog@ dialog) {
|
||||
tab.changeSize(index, dialog.getSpinboxInput(0));
|
||||
}
|
||||
};
|
||||
|
||||
class ColorChangeEvent : ColorDialogCallback {
|
||||
ParticlesTab@ tab;
|
||||
uint index;
|
||||
|
||||
ColorChangeEvent(ParticlesTab@ Tab, uint Index) {
|
||||
index = Index;
|
||||
@tab = Tab;
|
||||
}
|
||||
|
||||
void colorChosen(Color Col) {
|
||||
tab.changeColor(index, Col);
|
||||
}
|
||||
};
|
||||
|
||||
class ColorEntry : GuiListElement {
|
||||
ParticlesTab@ tab;
|
||||
Color col;
|
||||
|
||||
ColorEntry(Color Col, ParticlesTab@ Tab) {
|
||||
col = Col;
|
||||
@tab = Tab;
|
||||
}
|
||||
|
||||
void draw(GuiListbox@ ele, uint flags, const recti& absPos) override {
|
||||
Color solid = col;
|
||||
solid.a = 255;
|
||||
drawRectangle(absPos, solid, col, col, solid);
|
||||
}
|
||||
};
|
||||
|
||||
class onMatPicked : MaterialChoiceCallback {
|
||||
ParticlesTab@ tab;
|
||||
int editIndex;
|
||||
|
||||
onMatPicked(ParticlesTab@ editor, int EditIndex = -1) {
|
||||
editIndex = EditIndex;
|
||||
@tab = editor;
|
||||
}
|
||||
|
||||
void onMaterialChosen(const Material@ material, const string& id) {
|
||||
if(editIndex < 0)
|
||||
tab.addFlowMaterial(id);
|
||||
else
|
||||
tab.setFlowMaterial(editIndex, id);
|
||||
}
|
||||
|
||||
void onSpriteSheetChosen(const SpriteSheet@ spritebank, uint spriteIndex, const string& id) {}
|
||||
};
|
||||
|
||||
dictionary changedSystems;
|
||||
|
||||
class ParticlesTab : Tab {
|
||||
vec2i prevSize;
|
||||
RenderTarget@ rt;
|
||||
ParticleSystem@ ps;
|
||||
ParticleFlow@ flow;
|
||||
uint flowIndex = 0;
|
||||
int delFlowIndex = -1;
|
||||
Node@ node;
|
||||
|
||||
GuiTextbox@ psName;
|
||||
GuiButton@ savePS, loadPS;
|
||||
GuiListbox@ flows;
|
||||
GuiButton@ addFlow, delFlow, copyFlow;
|
||||
|
||||
GuiPanel@ flowData;
|
||||
|
||||
GuiListbox@ flowMats;
|
||||
GuiButton@ addMat, delMat, editMat;
|
||||
GuiTextbox@ flowScaleMin, flowScaleMax, flowLifeMin, flowLifeMax, flowRate;
|
||||
GuiTextbox@ flowStart, flowEnd, flowConeMin, flowConeMax, flowSpeedMin, flowSpeedMax, flowDistMin, flowDistMax;
|
||||
GuiCheckbox@ flowFlat;
|
||||
GuiTextbox@ flowStartSound;
|
||||
GuiListbox@ flowCols, flowSizes;
|
||||
GuiButton@ addCol, delCol, addSize, delSize;
|
||||
|
||||
int nextTabIndex = 0;
|
||||
void prepTab(IGuiElement@ ele) {
|
||||
ele.tabIndex = nextTabIndex++;
|
||||
}
|
||||
|
||||
ParticlesTab() {
|
||||
super();
|
||||
title = "Particle Editor";
|
||||
@psName = GuiTextbox(this, recti(4, 4, 220, 28));
|
||||
@savePS = GuiButton(this, recti(224, 4, 300, 28), "Save");
|
||||
@loadPS = GuiButton(this, recti(304, 4, 380, 28), "Load");
|
||||
|
||||
@flows = GuiListbox(this, Alignment(Left+4, Top+32, Left+220, Bottom-304));
|
||||
@addFlow = GuiButton(this, Alignment(Left+4, Bottom-260, Left+108, Bottom-220), "New Flow");
|
||||
@delFlow = GuiButton(this, Alignment(Left+112, Bottom-260, Left+220, Bottom-220), "Remove");
|
||||
@copyFlow = GuiButton(this, Alignment(Left+4, Bottom-300, Left+220, Bottom-264), "Duplicate");
|
||||
|
||||
@flowData = GuiPanel(this, Alignment(Left+4, Bottom-216, Right+0, Bottom+0));
|
||||
|
||||
@flowMats = GuiListbox(flowData, Alignment(Left+0, Top+0, Left+220, Bottom-60));
|
||||
@delMat = GuiButton(flowData, Alignment(Left+0, Bottom-56, Left+108, Bottom-32), "Remove");
|
||||
@editMat = GuiButton(flowData, Alignment(Left+112, Bottom-56, Left+220, Bottom-32), "Change");
|
||||
@addMat = GuiButton(flowData, Alignment(Left+0, Bottom-28, Left+220, Bottom-4), "Add Material");
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+0, Left+300, Top+24), "Scale:");
|
||||
@flowScaleMin = GuiTextbox(flowData, Alignment(Left+270, Top+0, Left+370, Top+24));
|
||||
prepTab(flowScaleMin);
|
||||
@flowScaleMax = GuiTextbox(flowData, Alignment(Left+374, Top+0, Left+474, Top+24));
|
||||
prepTab(flowScaleMax);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+26, Left+300, Top+52), "Life:");
|
||||
@flowLifeMin = GuiTextbox(flowData, Alignment(Left+270, Top+26, Left+370, Top+52));
|
||||
prepTab(flowLifeMin);
|
||||
@flowLifeMax = GuiTextbox(flowData, Alignment(Left+374, Top+26, Left+474, Top+52));
|
||||
prepTab(flowLifeMax);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+54, Left+300, Top+80), "Play:");
|
||||
@flowStart = GuiTextbox(flowData, Alignment(Left+270, Top+54, Left+370, Top+80));
|
||||
flowStart.tooltip = "Time offset (seconds) to begin playing this flow";
|
||||
prepTab(flowStart);
|
||||
@flowEnd = GuiTextbox(flowData, Alignment(Left+374, Top+54, Left+474, Top+80));
|
||||
flowEnd.tooltip = "Time offset (seconds) to stop playing this flow";
|
||||
prepTab(flowEnd);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+82, Left+300, Top+108), "Rate:");
|
||||
@flowRate = GuiTextbox(flowData, Alignment(Left+270, Top+82, Left+370, Top+108));
|
||||
prepTab(flowRate);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+110, Left+300, Top+136), "Cone:");
|
||||
@flowConeMin = GuiTextbox(flowData, Alignment(Left+270, Top+110, Left+370, Top+136));
|
||||
prepTab(flowConeMin);
|
||||
@flowConeMax = GuiTextbox(flowData, Alignment(Left+374, Top+110, Left+474, Top+136));
|
||||
prepTab(flowConeMax);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+138, Left+300, Top+164), "Speed:");
|
||||
@flowSpeedMin = GuiTextbox(flowData, Alignment(Left+270, Top+138, Left+370, Top+164));
|
||||
prepTab(flowSpeedMin);
|
||||
@flowSpeedMax = GuiTextbox(flowData, Alignment(Left+374, Top+138, Left+474, Top+164));
|
||||
prepTab(flowSpeedMax);
|
||||
|
||||
GuiText(flowData, Alignment(Left+224, Top+166, Left+300, Top+192), "Dist:");
|
||||
@flowDistMin = GuiTextbox(flowData, Alignment(Left+270, Top+166, Left+370, Top+192));
|
||||
flowDistMin.tooltip = "Minimum distance to spawn particles away from the center.";
|
||||
prepTab(flowDistMin);
|
||||
@flowDistMax = GuiTextbox(flowData, Alignment(Left+374, Top+166, Left+474, Top+192));
|
||||
prepTab(flowDistMax);
|
||||
|
||||
@flowFlat = GuiCheckbox(flowData, Alignment(Left+244, Top+194, Left+474, Top+220), "Flat");
|
||||
prepTab(flowFlat);
|
||||
|
||||
@flowCols = GuiListbox(flowData, Alignment(Left+478, Top, Left+550, Bottom-36));
|
||||
flowCols.DblClickConfirm = true;
|
||||
flowCols.Required = true;
|
||||
@flowSizes = GuiListbox(flowData, Alignment(Left+554, Top, Left+654, Bottom-36));
|
||||
flowSizes.DblClickConfirm = true;
|
||||
flowSizes.Required = true;
|
||||
|
||||
@addCol = GuiButton(flowData, Alignment(Left+478, Bottom-32, Left+512, Bottom-4), "Add");
|
||||
@delCol = GuiButton(flowData, Alignment(Left+516, Bottom-32, Left+550, Bottom-4), "Del");
|
||||
|
||||
@addSize = GuiButton(flowData, Alignment(Left+554, Bottom-32, Left+602, Bottom-4), "Add");
|
||||
@delSize = GuiButton(flowData, Alignment(Left+606, Bottom-32, Left+654, Bottom-4), "Del");
|
||||
|
||||
GuiText(flowData, Alignment(Left+660,Top,Left+720,Top+26), "Sound");
|
||||
@flowStartSound = GuiTextbox(flowData, Alignment(Left+724,Top,Left+824,Top+26));
|
||||
|
||||
loadParticleSystem("ImpactFlare");
|
||||
}
|
||||
|
||||
void switchToFlow(ParticleFlow@ Flow, uint Index) {
|
||||
@flow = Flow;
|
||||
flowIndex = Index;
|
||||
if(flow is null) {
|
||||
flowData.visible = false;
|
||||
}
|
||||
else {
|
||||
flows.selected = Index;
|
||||
flowData.visible = true;
|
||||
flowMats.clearItems();
|
||||
for(uint i = 0, cnt = flow.materialCount; i < cnt; ++i)
|
||||
flowMats.addItem(flow.materials[i]);
|
||||
flowCols.clearItems();
|
||||
for(uint i = 0, cnt = max(flow.colorCount,1); i < cnt; ++i)
|
||||
flowCols.addItem(ColorEntry(flow.colors[i], this));
|
||||
flowSizes.clearItems();
|
||||
for(uint i = 0, cnt = max(flow.sizeCount,1); i < cnt; ++i)
|
||||
flowSizes.addItem(toString(flow.sizes[i], 2));
|
||||
flowScaleMin.text = toString(flow.scale.min, 2);
|
||||
flowScaleMax.text = toString(flow.scale.max, 2);
|
||||
flowLifeMin.text = toString(flow.life.min, 2);
|
||||
flowLifeMax.text = toString(flow.life.max, 2);
|
||||
flowStart.text = toString(flow.start, 2);
|
||||
flowEnd.text = toString(flow.end, 2);
|
||||
flowRate.text = toString(flow.rate, 2);
|
||||
flowConeMin.text = toString(flow.cone.min, 2);
|
||||
flowConeMax.text = toString(flow.cone.max, 2);
|
||||
flowSpeedMin.text = toString(flow.speed.min, 2);
|
||||
flowSpeedMax.text = toString(flow.speed.max, 2);
|
||||
flowDistMin.text = toString(flow.spawnDist.min, 2);
|
||||
flowDistMax.text = toString(flow.spawnDist.max, 2);
|
||||
flowStartSound.text = flow.soundStart;
|
||||
flowFlat.checked = flow.flat;
|
||||
}
|
||||
}
|
||||
|
||||
void parseFlowData() {
|
||||
flow.scale.min = toDouble(flowScaleMin.text);
|
||||
flow.scale.max = toDouble(flowScaleMax.text);
|
||||
flow.life.min = toDouble(flowLifeMin.text);
|
||||
flow.life.max = toDouble(flowLifeMax.text);
|
||||
flow.start = toDouble(flowStart.text);
|
||||
flow.end = toDouble(flowEnd.text);
|
||||
flow.rate = toDouble(flowRate.text);
|
||||
flow.cone.min = toDouble(flowConeMin.text);
|
||||
flow.cone.max = toDouble(flowConeMax.text);
|
||||
flow.speed.min = toDouble(flowSpeedMin.text);
|
||||
flow.speed.max = toDouble(flowSpeedMax.text);
|
||||
flow.spawnDist.min = toDouble(flowDistMin.text);
|
||||
flow.spawnDist.max = toDouble(flowDistMax.text);
|
||||
flow.soundStart = flowStartSound.text;
|
||||
flow.flat = flowFlat.checked;
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void createFlow() {
|
||||
if(ps is null)
|
||||
return;
|
||||
ParticleFlow@ Flow = ps.createFlow();
|
||||
flows.addItem(FlowEntry(this, Flow, ps.flowCount-1));
|
||||
switchToFlow(Flow, ps.flowCount-1);
|
||||
}
|
||||
|
||||
void duplicateFlow(uint index) {
|
||||
if(ps is null)
|
||||
return;
|
||||
ParticleFlow@ Flow = ps.duplicateFlow(ps.flows[index]);
|
||||
flows.addItem(FlowEntry(this, Flow, ps.flowCount-1));
|
||||
switchToFlow(Flow, ps.flowCount-1);
|
||||
}
|
||||
|
||||
void changeColor(uint index, Color col) {
|
||||
if(flow is null)
|
||||
return;
|
||||
flow.colors[index] = col;
|
||||
flowCols.setItem(index, ColorEntry(col, this));
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void changeSize(uint index, double size) {
|
||||
if(flow is null)
|
||||
return;
|
||||
flow.sizes[index] = size;
|
||||
flowSizes.setItem(index, toString(size, 2));
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void addFlowMaterial(const string &in matName) {
|
||||
if(flow is null)
|
||||
return;
|
||||
flow.addMaterial(matName);
|
||||
flowMats.addItem(matName);
|
||||
flows.setItem(flowIndex, FlowEntry(this, flow, flowIndex));
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void setFlowMaterial(uint index, const string &in matName) {
|
||||
if(flow is null)
|
||||
return;
|
||||
flow.materials[index] = matName;
|
||||
flowMats.setItem(index, matName);
|
||||
flows.setItem(flowIndex, FlowEntry(this, flow, flowIndex));
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void loadParticleSystem(const string &in name) {
|
||||
ParticleSystem@ psys;
|
||||
if(!changedSystems.get(name, @psys))
|
||||
@ps = getParticleSystem(name).duplicate();
|
||||
else
|
||||
@ps = psys;
|
||||
flows.clearItems();
|
||||
flowData.visible = false;
|
||||
|
||||
if(ps !is null) {
|
||||
psName.text = name;
|
||||
|
||||
for(uint i = 0, cnt = ps.flowCount; i < cnt; ++i) {
|
||||
flows.addItem(FlowEntry(this, ps.flows[i], i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
psName.text = "";
|
||||
}
|
||||
|
||||
postEdit();
|
||||
}
|
||||
|
||||
void postEdit() {
|
||||
if(node !is null)
|
||||
node.markForDeletion();
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is addFlow) {
|
||||
createFlow();
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is delFlow) {
|
||||
if(flows.selected >= 0 && uint(flows.selected) < flows.itemCount && flows.itemCount > 1) {
|
||||
delFlowIndex = flows.selected;
|
||||
postEdit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is copyFlow) {
|
||||
if(flows.selected >= 0 && uint(flows.selected) < flows.itemCount) {
|
||||
duplicateFlow(uint(flows.selected));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is addMat) {
|
||||
if(flow !is null)
|
||||
openMaterialChooser(onMatPicked(this), MCM_Materials);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is delMat) {
|
||||
if(flow !is null) {
|
||||
if(flowMats.selected >= 0 && uint(flowMats.selected) < flowMats.itemCount) {
|
||||
flow.removeMaterial(flowMats.selected);
|
||||
flowMats.removeItem(flowMats.selected);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is addCol) {
|
||||
if(flow !is null) {
|
||||
int index = flow.colorCount;
|
||||
flow.addColor(index, flow.colors[index-1]);
|
||||
if(index == 0)
|
||||
flow.addColor(index, flow.colors[index-1]);
|
||||
flowCols.addItem(ColorEntry(flow.colors[index], this));
|
||||
postEdit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is delCol) {
|
||||
if(flow !is null && flowCols.selected >= 0 && uint(flowCols.selected) < flowCols.itemCount) {
|
||||
flow.removeColor(flowCols.selected);
|
||||
flowCols.removeItem(flowCols.selected);
|
||||
postEdit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is addSize) {
|
||||
if(flow !is null) {
|
||||
int index = flow.sizeCount;
|
||||
flow.addSize(index, flow.sizes[index-1]);
|
||||
if(index == 0)
|
||||
flow.addSize(index, flow.sizes[index-1]);
|
||||
flowSizes.addItem(toString(flow.sizes[index], 2));
|
||||
postEdit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is delSize) {
|
||||
if(flow !is null && flowSizes.selected >= 0 && uint(flowSizes.selected) < flowSizes.itemCount) {
|
||||
flow.removeSize(flowSizes.selected);
|
||||
flowSizes.removeItem(flowSizes.selected);
|
||||
postEdit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is editMat) {
|
||||
if(flow !is null && flowMats.selected >= 0)
|
||||
openMaterialChooser(onMatPicked(this, flowMats.selected), MCM_Materials);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is savePS) {
|
||||
string sysName = psName.text;
|
||||
if(sysName.length > 0) {
|
||||
if(ps !is null)
|
||||
ps.save("data/particles/" + sysName + ".ps");
|
||||
changedSystems.set(sysName, @ps);
|
||||
}
|
||||
else {
|
||||
sound::error.play(priority=true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is loadPS) {
|
||||
loadParticleSystem(psName.text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.type == GUI_Confirmed) {
|
||||
if(event.caller is flowCols) {
|
||||
ColorDialog(ColorChangeEvent(this, event.value), null, flow.colors[event.value]);
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is flowSizes) {
|
||||
InputDialog@ dialog = InputDialog(SizeChangeEvent(this, event.value), null);
|
||||
dialog.addSpinboxInput("Size", flow.sizes[event.value], 0.1, -1000.0, 1000.0, 3);
|
||||
addDialog(dialog);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.type == GUI_Changed) {
|
||||
if(event.caller.isChildOf(flowData)) {
|
||||
parseFlowData();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
vec2i size = AbsolutePosition.size;
|
||||
if(size != prevSize) {
|
||||
prevSize = size;
|
||||
if(rt !is null) {
|
||||
rt.size = size;
|
||||
}
|
||||
else {
|
||||
@rt = RenderTarget(size);
|
||||
rt.camera.yaw(pi * 0.45, true);
|
||||
rt.camera.pitch(pi * 0.1, true);
|
||||
}
|
||||
}
|
||||
|
||||
if((node is null || node.parent is null) && rt !is null) {
|
||||
if(delFlowIndex >= 0) {
|
||||
ps.removeFlow(delFlowIndex);
|
||||
flows.removeItem(delFlowIndex);
|
||||
switchToFlow(ps.flows[delFlowIndex], delFlowIndex);
|
||||
delFlowIndex = -1;
|
||||
}
|
||||
@node = playParticleSystem(ps, vec3d(), 20.f, rt.node);
|
||||
}
|
||||
|
||||
if(rt !is null) {
|
||||
rt.animate(frameLength);
|
||||
rt.draw(AbsolutePosition);
|
||||
}
|
||||
|
||||
Tab::draw();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,131 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiText;
|
||||
import elements.GuiPanel;
|
||||
|
||||
from tabs.tabbar import newTab, switchToTab;
|
||||
|
||||
Tab@ createSkinViewerTab() {
|
||||
return SkinViewer();
|
||||
}
|
||||
|
||||
class SkinViewerCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
Tab@ editor = createSkinViewerTab();
|
||||
newTab(editor);
|
||||
switchToTab(editor);
|
||||
}
|
||||
};
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("skin_viewer", SkinViewerCommand());
|
||||
}
|
||||
|
||||
class SkinViewer : Tab {
|
||||
dictionary skinStyles;
|
||||
GuiListbox@ styles;
|
||||
GuiPanel@ leftPanel;
|
||||
|
||||
SkinStyle selStyle;
|
||||
uint eleCnt;
|
||||
array<GuiText@> skinHeaders;
|
||||
array<GuiSkinElement@> skinExamples;
|
||||
|
||||
void draw() {
|
||||
//Draw the background
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
|
||||
SkinViewer() {
|
||||
super();
|
||||
title = "Skin Viewer";
|
||||
|
||||
@leftPanel = GuiPanel(this, Alignment(Left, Top, Right-0.25f, Bottom));
|
||||
|
||||
@styles = GuiListbox(this, Alignment(Right-0.25f, Top+0+4, Right-0-4, Bottom-0-4));
|
||||
styles.required = true;
|
||||
|
||||
updateStyles();
|
||||
updateAbsolutePosition();
|
||||
showSelectedStyle();
|
||||
}
|
||||
|
||||
void updateStyles() {
|
||||
getSkinStyles(skinStyles);
|
||||
styles.clearItems();
|
||||
dictionary_iterator style = skinStyles.iterator();
|
||||
string name; int64 value;
|
||||
while(style.iterate(name, value))
|
||||
styles.addItem(name);
|
||||
}
|
||||
|
||||
void addSkinExample(SkinStyle style, uint flags, Alignment@ alignment) {
|
||||
GuiSkinElement@ example = GuiSkinElement(leftPanel, recti(), 0);
|
||||
@example.alignment = alignment;
|
||||
example.style = style;
|
||||
example.flags = flags;
|
||||
skinExamples.insertLast(example);
|
||||
}
|
||||
|
||||
void showStyle(SkinStyle style) {
|
||||
//Remove old ones
|
||||
for(uint i = 0; i < skinExamples.length; ++i)
|
||||
skinExamples[i].remove();
|
||||
for(uint i = 0; i < skinHeaders.length; ++i)
|
||||
skinHeaders[i].remove();
|
||||
skinExamples.length = 0;
|
||||
skinHeaders.length = 0;
|
||||
selStyle = style;
|
||||
|
||||
//Add new ones
|
||||
eleCnt = skin.getStyleElementCount(style);
|
||||
int y = 0;
|
||||
for(uint i = 0; i < eleCnt; ++i) {
|
||||
uint flags = skin.getStyleElementFlags(style, i);
|
||||
|
||||
//Add header
|
||||
GuiText@ txt = GuiText(leftPanel, recti(), getElementFlagName(flags));
|
||||
@txt.alignment = Alignment(Left+4, Top+4 + y, Right-0.5f-4, Top+24 + y);
|
||||
skinHeaders.insertLast(txt);
|
||||
y += 32;
|
||||
|
||||
//Add examples
|
||||
addSkinExample(style, flags, Alignment(Left+4, Top+4 + y, Right-0.5f-4, Top+250 + y));
|
||||
|
||||
addSkinExample(style, flags, Alignment(Left+4, Top+254 + y, Left+0.0f+20, Top+270 + y));
|
||||
|
||||
addSkinExample(style, flags, Alignment(Left+24, Top+254 + y, Left+0.0f+88, Top+318 + y));
|
||||
|
||||
addSkinExample(style, flags, Alignment(Left+92, Top+254 + y, Left+0.0f+292, Top+276 + y));
|
||||
|
||||
y += 326;
|
||||
}
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(skinStyles.getSize() != getSkinStyleCount())
|
||||
updateStyles();
|
||||
if(skin.getStyleElementCount(selStyle) != eleCnt)
|
||||
showStyle(selStyle);
|
||||
}
|
||||
|
||||
void showSelectedStyle() {
|
||||
if(styles.selected >= 0) {
|
||||
int64 styleID;
|
||||
skinStyles.get(styles.getItem(styles.selected), styleID);
|
||||
showStyle(SkinStyle(styleID));
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Changed) {
|
||||
if(event.caller is styles) {
|
||||
showSelectedStyle();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
import tabs.Tab;
|
||||
from tabs.tabbar import newTab, switchToTab;
|
||||
|
||||
Tab@ createStatsTab() {
|
||||
return StatsTab();
|
||||
}
|
||||
|
||||
class StatsTabCommand : ConsoleCommand {
|
||||
void execute(const string& args) {
|
||||
Tab@ editor = createStatsTab();
|
||||
newTab(editor);
|
||||
switchToTab(editor);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
addConsoleCommand("stats_tab", StatsTabCommand());
|
||||
}
|
||||
|
||||
array<int> valuePoints;
|
||||
int findNearest(int start, int bound) {
|
||||
int above = start;
|
||||
bool validAbove = false;
|
||||
|
||||
while(!validAbove && above > 0) {
|
||||
validAbove = true;
|
||||
|
||||
for(uint i = 0, cnt = valuePoints.length; i < cnt; ++i) {
|
||||
int pt = valuePoints[i];
|
||||
if(above > pt - 24 && above < pt + 24) {
|
||||
validAbove = false;
|
||||
above = pt - 24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int below = start;
|
||||
bool validBelow = false;
|
||||
|
||||
while(!validBelow && below < bound) {
|
||||
validBelow = true;
|
||||
|
||||
for(uint i = 0, cnt = valuePoints.length; i < cnt; ++i) {
|
||||
int pt = valuePoints[i];
|
||||
if(below > pt - 24 && below < pt + 24) {
|
||||
validBelow = false;
|
||||
below = pt + 24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(validAbove) {
|
||||
if(!validBelow) {
|
||||
start = above;
|
||||
}
|
||||
else {
|
||||
int aDiff = abs(above - start);
|
||||
int bDiff = abs(below - start);
|
||||
if(aDiff < bDiff)
|
||||
start = above;
|
||||
else
|
||||
start = below;
|
||||
}
|
||||
}
|
||||
else if(validBelow) {
|
||||
start = below;
|
||||
}
|
||||
|
||||
valuePoints.insertLast(start);
|
||||
return start;
|
||||
}
|
||||
|
||||
interface StatTracker {
|
||||
void update();
|
||||
void draw(const Skin@ skin, recti bound);
|
||||
};
|
||||
|
||||
class StatsTab : Tab {
|
||||
uint endTime = 0;
|
||||
array<StatTracker@> stats;
|
||||
|
||||
double nextUpdate = 0;
|
||||
|
||||
StatsTab() {
|
||||
super();
|
||||
title = locale::STATS_TAB;
|
||||
|
||||
stats.insertLast(IntegerStat(stat::Planets, Color(0xff9955ff), 15, " Planets"));
|
||||
stats.insertLast(IntegerStat(stat::Ships, Color(0x4422ffff), 15, " Ships"));
|
||||
stats.insertLast(IntegerStat(stat::ShipsDestroyed, Color(0xff2222ff), 15, " Killed"));
|
||||
stats.insertLast(FloatStat(stat::Budget, Color(0x22ff22ff), 60, " $"));
|
||||
stats.insertLast(FloatStat(stat::Energy, Color(0xffff22ff), 60, " Energy"));
|
||||
stats.insertLast(FloatStat(stat::FTL, Color(0xff22ffff), 60, " FTL"));
|
||||
stats.insertLast(IntegerStat(stat::Influence, Color(0xffffffff), 60, " Influence"));
|
||||
}
|
||||
|
||||
void updateStats() {
|
||||
for(uint i = 0, end = stats.length; i < end; ++i)
|
||||
stats[i].update();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(gameTime > nextUpdate) {
|
||||
nextUpdate = gameTime + 1.0;
|
||||
updateStats();
|
||||
}
|
||||
|
||||
endTime = uint(gameTime);
|
||||
|
||||
valuePoints.length = 0;
|
||||
|
||||
skin.draw(SS_DiplomacyBG, SF_Normal, AbsolutePosition);
|
||||
|
||||
recti statBound = recti_centered(AbsolutePosition, AbsolutePosition.size - vec2i(64,16)) - vec2i(60,0);
|
||||
skin.draw(SS_Panel, SF_Normal, statBound);
|
||||
|
||||
statBound = recti_centered(statBound, statBound.size - vec2i(1,1));
|
||||
|
||||
for(uint i = 0, end = stats.length; i < end; ++i)
|
||||
stats[i].draw(skin, statBound);
|
||||
|
||||
Tab::draw();
|
||||
}
|
||||
}
|
||||
|
||||
final class IntegerStat : StatTracker {
|
||||
int minVal = 0, maxVal = 100;
|
||||
stat::EmpireStat stat;
|
||||
Color color;
|
||||
int filterDuration = 1;
|
||||
array<vec2i> data;
|
||||
string suffix;
|
||||
|
||||
IntegerStat(stat::EmpireStat Stat, const Color& col, int FilterDuration, string Suffix) {
|
||||
stat = Stat;
|
||||
color = col;
|
||||
filterDuration = FilterDuration;
|
||||
suffix = Suffix;
|
||||
}
|
||||
|
||||
void update() {
|
||||
minVal = 0;
|
||||
maxVal = 100;
|
||||
data.length = 0;
|
||||
|
||||
StatHistory history(playerEmpire, stat);
|
||||
|
||||
while(history.advance(1)) {
|
||||
int val = history.intVal;
|
||||
|
||||
if(val > maxVal)
|
||||
maxVal = val;
|
||||
if(val < minVal)
|
||||
minVal = val;
|
||||
|
||||
data.insertLast(vec2i(int(history.time), val));
|
||||
}
|
||||
}
|
||||
|
||||
void draw(const Skin@ skin, recti bound) {
|
||||
if(data.length == 0) {
|
||||
drawLine(bound.topLeft + vec2i(0, bound.height), bound.botRight, color);
|
||||
return;
|
||||
}
|
||||
|
||||
vec2i size = bound.size;
|
||||
|
||||
float endTime = float(gameTime);
|
||||
vec2f factor(1.f / endTime, -1.f / float(maxVal));
|
||||
|
||||
int secondStep = int(max(float(size.x) / endTime, 1.f));
|
||||
int timeStep = int(max(float(size.x * filterDuration) / endTime, float(filterDuration)));
|
||||
vec2i corner = bound.topLeft + vec2i(0,size.y);
|
||||
vec2i prev = corner;
|
||||
|
||||
//Draw segments
|
||||
for(uint i = 0, cnt = data.length; i < cnt; ++i) {
|
||||
vec2f ptf = vec2f(data[i]);
|
||||
vec2i pt = corner + vec2i(float(size.x) * ptf.x * factor.x, float(size.y) * ptf.y * factor.y);
|
||||
|
||||
if(i != 0 && prev.x >= pt.x - timeStep) {
|
||||
drawLine(prev, pt, color);
|
||||
}
|
||||
else {
|
||||
vec2i med = vec2i(pt.x - secondStep, prev.y);
|
||||
drawLine(prev, med, color);
|
||||
drawLine(med, pt, color);
|
||||
}
|
||||
prev = pt;
|
||||
}
|
||||
|
||||
//Draw final segment until current moment if nothing has changed
|
||||
if(data[data.length - 1].x < int(endTime)) {
|
||||
vec2i end = vec2i(corner.x + size.x, prev.y);
|
||||
drawLine(prev, end, color);
|
||||
prev = end;
|
||||
}
|
||||
|
||||
vec2i around = prev + vec2i(6, 0);
|
||||
around.y = findNearest(around.y - bound.topLeft.y, size.height) + bound.topLeft.y - 8;
|
||||
skin.draw(FT_Normal, around, string(data[data.length - 1].y) + suffix, color);
|
||||
}
|
||||
};
|
||||
|
||||
final class FloatStat : StatTracker {
|
||||
float minVal = 0, maxVal = 100.f;
|
||||
stat::EmpireStat stat;
|
||||
Color color;
|
||||
int filterDuration = 1;
|
||||
array<vec2f> data;
|
||||
string suffix;
|
||||
|
||||
FloatStat(stat::EmpireStat Stat, const Color& col, int FilterDuration, string Suffix) {
|
||||
stat = Stat;
|
||||
color = col;
|
||||
filterDuration = FilterDuration;
|
||||
suffix = Suffix;
|
||||
}
|
||||
|
||||
void update() {
|
||||
minVal = 0;
|
||||
maxVal = 100;
|
||||
data.length = 0;
|
||||
|
||||
StatHistory history(playerEmpire, stat);
|
||||
|
||||
while(history.advance(1)) {
|
||||
float val = history.floatVal;
|
||||
|
||||
if(val > maxVal)
|
||||
maxVal = val;
|
||||
if(val < minVal)
|
||||
minVal = val;
|
||||
|
||||
data.insertLast(vec2f(history.time, val));
|
||||
}
|
||||
}
|
||||
|
||||
void draw(const Skin@ skin, recti bound) {
|
||||
if(data.length == 0) {
|
||||
drawLine(bound.topLeft + vec2i(0, bound.height), bound.botRight, color);
|
||||
return;
|
||||
}
|
||||
|
||||
vec2i size = bound.size;
|
||||
|
||||
float endTime = float(gameTime);
|
||||
vec2f factor(1.f / endTime, -1.f / float(maxVal));
|
||||
|
||||
int secondStep = int(max(float(size.x) / endTime, 1.f));
|
||||
int timeStep = int(max(float(size.x * filterDuration) / endTime, float(filterDuration)));
|
||||
vec2i corner = bound.topLeft + vec2i(0,size.y);
|
||||
vec2i prev = corner;
|
||||
|
||||
//Draw segments
|
||||
for(uint i = 0, cnt = data.length; i < cnt; ++i) {
|
||||
vec2f ptf = data[i];
|
||||
vec2i pt = corner + vec2i(float(size.x) * ptf.x * factor.x, float(size.y) * ptf.y * factor.y);
|
||||
|
||||
if(i != 0 && prev.x >= pt.x - timeStep) {
|
||||
drawLine(prev, pt, color);
|
||||
}
|
||||
else {
|
||||
vec2i med = vec2i(pt.x - secondStep, prev.y);
|
||||
drawLine(prev, med, color);
|
||||
drawLine(med, pt, color);
|
||||
}
|
||||
prev = pt;
|
||||
}
|
||||
|
||||
//Draw final segment until current moment if nothing has changed
|
||||
if(data[data.length - 1].x < int(endTime)) {
|
||||
vec2i end = vec2i(corner.x + size.x, prev.y);
|
||||
drawLine(prev, end, color);
|
||||
prev = end;
|
||||
}
|
||||
|
||||
|
||||
vec2i around = prev + vec2i(6, 0);
|
||||
around.y = findNearest(around.y - bound.topLeft.y, size.height) + bound.topLeft.y - 8;
|
||||
skin.draw(FT_Normal, around, standardize(data[data.length - 1].y) + suffix, color);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,371 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiAccordion;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiSprite;
|
||||
import elements.GuiMarkupText;
|
||||
from elements.Gui3DObject import Gui3DObject, ObjectAction;
|
||||
from elements.GuiResources import GuiResources;
|
||||
import planet_types;
|
||||
import planet_levels;
|
||||
import resources;
|
||||
import systems;
|
||||
import util.formatting;
|
||||
from obj_selection import selectObject;
|
||||
import overlays.Popup;
|
||||
from overlays.PlanetPopup import PlanetPopup;
|
||||
|
||||
from overlays.ContextMenu import openContextMenu;
|
||||
from tabs.tabbar import get_ActiveTab, browseTab, popTab;
|
||||
import void zoomTabTo(Object@ obj) from "tabs.GalaxyTab";
|
||||
import void openOverlay(Object@ obj) from "tabs.GalaxyTab";
|
||||
|
||||
const vec2i SIZE_PER_PX(5.0, 8.0);
|
||||
|
||||
final class SystemBox {
|
||||
SystemDesc@ desc;
|
||||
recti pos;
|
||||
};
|
||||
|
||||
final class LineBox {
|
||||
SystemBox@ from;
|
||||
SystemBox@ to;
|
||||
vec2i fromPos;
|
||||
vec2i toPos;
|
||||
recti area;
|
||||
};
|
||||
|
||||
array<SystemBox> systemBoxes;
|
||||
array<LineBox@> systemLines;
|
||||
void createSystemBoxes() {
|
||||
uint sysCnt = systemCount;
|
||||
systemBoxes.length = sysCnt;
|
||||
for(uint i = 0,cnt = sysCnt; i < cnt; ++i) {
|
||||
SystemDesc@ desc = getSystem(i);
|
||||
vec2i pos = vec2i(desc.position.x / SIZE_PER_PX.x, desc.position.z / SIZE_PER_PX.y);
|
||||
vec2i size = vec2i(desc.object.planetCount*160+40, 220);
|
||||
|
||||
SystemBox@ box = systemBoxes[i];
|
||||
@box.desc = desc;
|
||||
box.pos = recti_area(pos-(size/2), size);
|
||||
|
||||
for(uint j = 0, jcnt = desc.adjacent.length; j < jcnt; ++j) {
|
||||
uint adj = desc.adjacent[j];
|
||||
if(adj < i) {
|
||||
LineBox line;
|
||||
@line.from = box;
|
||||
@line.to = systemBoxes[adj];
|
||||
line.fromPos = line.from.pos.center;
|
||||
line.toPos = line.to.pos.center;
|
||||
|
||||
line.area.topLeft.x = min(line.fromPos.x - 5, line.toPos.x - 5);
|
||||
line.area.topLeft.y = min(line.fromPos.y - 5, line.toPos.y - 5);
|
||||
line.area.botRight.x = max(line.fromPos.x + 5, line.toPos.x + 5);
|
||||
line.area.botRight.y = max(line.fromPos.y + 5, line.toPos.y + 5);
|
||||
|
||||
systemLines.insertLast(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SystemTab : Tab {
|
||||
Region@ sys;
|
||||
const SystemDesc@ desc;
|
||||
|
||||
array<PlanetPopup@> popups;
|
||||
|
||||
bool heldLeft = false;
|
||||
bool dragging = false;
|
||||
bool moved = false;
|
||||
vec2d scroll;
|
||||
vec2i dragStart;
|
||||
vec2i prevScroll;
|
||||
|
||||
set_int instantiated;
|
||||
|
||||
SystemTab() {
|
||||
super();
|
||||
title = locale::SYSTEM_TAB;
|
||||
if(systemBoxes.length == 0)
|
||||
createSystemBoxes();
|
||||
}
|
||||
|
||||
void display(Object@ system) {
|
||||
for(uint i = 0, cnt = systemBoxes.length; i < cnt; ++i) {
|
||||
SystemBox@ box = systemBoxes[i];
|
||||
if(system is box.desc.object) {
|
||||
scroll = vec2d(box.pos.center);
|
||||
prevScroll = vec2i(scroll);
|
||||
moved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
Tab::updateAbsolutePosition();
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xfcb44eff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xff9600ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8c642bff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Galaxy;
|
||||
}
|
||||
|
||||
void instantiate(const recti& relArea, SystemBox@ box) {
|
||||
instantiated.insert(box.desc.index);
|
||||
|
||||
vec2i startPos = box.pos.topLeft - relArea.topLeft + vec2i(20, 36);
|
||||
uint plCnt = box.desc.object.planetCount;
|
||||
|
||||
for(uint i = 0; i < plCnt; ++i) {
|
||||
Planet@ pl = box.desc.object.planets[i];
|
||||
PlanetPopup pop(this);
|
||||
pop.set(pl);
|
||||
pop.mouseLinked = false;
|
||||
pop.isSelectable = true;
|
||||
pop.update();
|
||||
|
||||
pop.visible = pl.visible;
|
||||
pop.position = startPos + vec2i(160*i, 0);
|
||||
popups.insertLast(pop);
|
||||
}
|
||||
}
|
||||
|
||||
void deinstantiate(SystemBox@ box) {
|
||||
instantiated.erase(box.desc.index);
|
||||
for(int i = popups.length - 1; i >= 0; --i) {
|
||||
if(popups[i].pl.region is box.desc.object) {
|
||||
popups[i].remove();
|
||||
popups.removeAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void movePopups() {
|
||||
vec2i roundedScroll(scroll);
|
||||
if(prevScroll == roundedScroll)
|
||||
return;
|
||||
|
||||
vec2i moveBy = prevScroll - roundedScroll;
|
||||
prevScroll = roundedScroll;
|
||||
for(uint i = 0, cnt = popups.length; i < cnt; ++i) {
|
||||
PlanetPopup@ pop = popups[i];
|
||||
pop.move(moveBy);
|
||||
}
|
||||
}
|
||||
|
||||
void updatePopups() {
|
||||
for(uint i = 0, cnt = popups.length; i < cnt; ++i) {
|
||||
popups[i].visible = popups[i].pl.visible;
|
||||
if(popups[i].visible)
|
||||
popups[i].update();
|
||||
}
|
||||
}
|
||||
|
||||
IGuiElement@ elementFromPosition(const vec2i& pos) {
|
||||
if(dragging) {
|
||||
//Cannot access inner elements while dragging,
|
||||
if(AbsoluteClipRect.isWithin(pos))
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return Tab::elementFromPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& evt) {
|
||||
switch(evt.type) {
|
||||
case GUI_Clicked: {
|
||||
PlanetPopup@ pop = cast<PlanetPopup>(evt.caller);
|
||||
if(pop !is null && pop.parent is this) {
|
||||
switch(evt.value) {
|
||||
case PA_Select:
|
||||
selectObject(pop.pl, shiftKey);
|
||||
return true;
|
||||
case PA_Manage:
|
||||
popTab(this);
|
||||
zoomTabTo(pop.pl);
|
||||
openOverlay(pop.pl);
|
||||
return true;
|
||||
case PA_Zoom:
|
||||
popTab(this);
|
||||
zoomTabTo(pop.pl);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
return Tab::onGuiEvent(evt);
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
switch(event.type) {
|
||||
case KET_Key_Down:
|
||||
if(event.key == KEY_ESC)
|
||||
return true;
|
||||
break;
|
||||
case KET_Key_Up:
|
||||
if(event.key == KEY_ESC) {
|
||||
if(previous !is null) {
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Tab::onKeyEvent(event, source);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(event.type == MET_Button_Up) {
|
||||
if(event.button == 1) {
|
||||
if(previous !is null) {
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case MET_Button_Down:
|
||||
if(event.button == 0) {
|
||||
heldLeft = true;
|
||||
dragStart = vec2i(event.x, event.y);
|
||||
}
|
||||
break;
|
||||
case MET_Moved: {
|
||||
vec2i mouse = vec2i(event.x, event.y);
|
||||
vec2i d = mouse - dragStart;
|
||||
|
||||
if(dragging) {
|
||||
scroll -= vec2d(double(d.x), double(d.y));
|
||||
dragStart = mouse;
|
||||
moved = true;
|
||||
}
|
||||
else if(heldLeft) {
|
||||
if(abs(d.x) >= 5 || abs(d.y) >= 5) {
|
||||
dragging = true;
|
||||
moved = true;
|
||||
scroll -= vec2d(double(d.x), double(d.y));
|
||||
dragStart = mouse;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MET_Button_Up:
|
||||
if(event.button == 0) {
|
||||
if(!dragging) {
|
||||
//Do stuff
|
||||
}
|
||||
heldLeft = false;
|
||||
dragging = false;
|
||||
dragStart = vec2i();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Tab::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(!visible)
|
||||
return;
|
||||
|
||||
if(moved) {
|
||||
movePopups();
|
||||
moved = false;
|
||||
|
||||
recti relArea = recti_area(vec2i(scroll) - (size/2), size);
|
||||
for(uint i = 0, cnt = systemBoxes.length; i < cnt; ++i) {
|
||||
SystemBox@ box = systemBoxes[i];
|
||||
bool inst = instantiated.contains(i);
|
||||
|
||||
if(box.pos.overlaps(relArea)) {
|
||||
if(!inst)
|
||||
instantiate(relArea, box);
|
||||
}
|
||||
else {
|
||||
if(inst)
|
||||
deinstantiate(box);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updatePopups();
|
||||
}
|
||||
|
||||
void drawSystemLine(const recti& relArea, LineBox@ box) {
|
||||
Color col(0xffffff30);
|
||||
vec2i from = box.fromPos - relArea.topLeft + AbsolutePosition.topLeft;
|
||||
vec2i to = box.toPos - relArea.topLeft + AbsolutePosition.topLeft;
|
||||
|
||||
bool canTrade = (box.to.desc.object.TradeMask & playerEmpire.mask) != 0
|
||||
|| (box.from.desc.object.TradeMask & playerEmpire.mask) != 0;
|
||||
if(canTrade) {
|
||||
col = playerEmpire.color;
|
||||
col.a = 0x60;
|
||||
}
|
||||
|
||||
drawLine(from, to, col, 10);
|
||||
}
|
||||
|
||||
void drawSystemBox(const recti& relArea, SystemBox@ box) {
|
||||
recti bpos = box.pos - relArea.topLeft + AbsolutePosition.topLeft;
|
||||
const Font@ ft = skin.getFont(FT_Medium);
|
||||
Color col;
|
||||
|
||||
Empire@ prim = box.desc.object.visiblePrimaryEmpire;
|
||||
if(prim !is null)
|
||||
col = prim.color;
|
||||
|
||||
skin.draw(SS_SystemPanel, SF_Normal, bpos, col);
|
||||
ft.draw(bpos.topLeft+vec2i(8, 5), box.desc.name);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_SystemListBG, SF_Normal, AbsolutePosition);
|
||||
|
||||
recti relArea = recti_area(vec2i(scroll) - (size/2), size);
|
||||
|
||||
//Draw the lines
|
||||
for(uint i = 0, cnt = systemLines.length; i < cnt; ++i) {
|
||||
LineBox@ box = systemLines[i];
|
||||
if(box.area.overlaps(relArea))
|
||||
drawSystemLine(relArea, box);
|
||||
}
|
||||
|
||||
//Draw the boxes
|
||||
for(uint i = 0, cnt = systemBoxes.length; i < cnt; ++i) {
|
||||
SystemBox@ box = systemBoxes[i];
|
||||
if(box.pos.overlaps(relArea))
|
||||
drawSystemBox(relArea, box);
|
||||
}
|
||||
|
||||
Tab::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createSystemTab() {
|
||||
return SystemTab();
|
||||
}
|
||||
|
||||
Tab@ createSystemTab(Object@ system) {
|
||||
SystemTab tab;
|
||||
tab.display(system);
|
||||
|
||||
return tab;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import elements.BaseGuiElement;
|
||||
|
||||
enum TabCategory {
|
||||
TC_Invalid,
|
||||
TC_Other,
|
||||
TC_Galaxy,
|
||||
TC_Designs,
|
||||
TC_Home,
|
||||
TC_Research,
|
||||
TC_Graphics,
|
||||
TC_Diplomacy,
|
||||
TC_Planets,
|
||||
TC_Wiki,
|
||||
TC_Attitudes,
|
||||
};
|
||||
|
||||
class Tab : BaseGuiElement {
|
||||
string title;
|
||||
Tab@ previous;
|
||||
IGuiElement@ prevFocus = this;
|
||||
bool initialized = false;
|
||||
bool flashing = false;
|
||||
bool locked = false;
|
||||
|
||||
Tab() {
|
||||
super(null, recti());
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//Called when the tab is first created and positioned
|
||||
void init() {
|
||||
}
|
||||
|
||||
//Called when the tab is asked to close
|
||||
// hide() will also be called first when closing a visible tab
|
||||
void close() {
|
||||
@prevFocus = null;
|
||||
}
|
||||
|
||||
//Called when a closed tab needs to be reopened
|
||||
// show() will also be called afterwards
|
||||
void reopen() {
|
||||
}
|
||||
|
||||
//Call to flash the tab in the tabbar until focused
|
||||
void flash() {
|
||||
if(!visible)
|
||||
flashing = true;
|
||||
}
|
||||
|
||||
//Get the title for the tab
|
||||
string& get_title() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void set_title(const string& newTitle) {
|
||||
title = newTitle;
|
||||
}
|
||||
|
||||
//Get the icon for the tab
|
||||
Sprite get_icon() {
|
||||
return Sprite();
|
||||
}
|
||||
|
||||
//Get the colors for the tab
|
||||
Color get_activeColor() {
|
||||
return Color(0xffffffff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xffffffff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0xffffffff);
|
||||
}
|
||||
|
||||
//Get the tab category
|
||||
TabCategory get_category() {
|
||||
return TC_Other;
|
||||
}
|
||||
|
||||
//Show the tab and do any necessary syncing
|
||||
void show() {
|
||||
updateAbsolutePosition();
|
||||
visible = true;
|
||||
flashing = false;
|
||||
setGuiFocus(prevFocus);
|
||||
}
|
||||
|
||||
//Hide the tab and do any necessary cleanup
|
||||
void hide() {
|
||||
@prevFocus = getGuiFocus();
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//Tick the tab. This is called regardless
|
||||
//of whether the tab is visible, so the tab itself
|
||||
//needs to figure what it needs to update
|
||||
void tick(double time) {
|
||||
}
|
||||
|
||||
//Called before any ticks, rendering or node animation
|
||||
//Should update camera position for the next frame when necessary
|
||||
void preRender(double time) {
|
||||
}
|
||||
|
||||
//Called when the 3D scene should be rendered,
|
||||
//if any exists in this tab
|
||||
void render(double time) {
|
||||
}
|
||||
|
||||
//Called whenever an object is clicked
|
||||
//Return true to prevent whatever other behaviors would normally occur
|
||||
bool objectInteraction(Object& object, uint mouseButton, bool doubleClick) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Called for utilising the joystick. Return true if the joystick is grabbed.
|
||||
bool joystick(Joystick& joystick) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void save(SaveFile& file) {
|
||||
}
|
||||
|
||||
void load(SaveFile& file) {
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,619 @@
|
||||
#priority init -200
|
||||
import tabs.Tab;
|
||||
import tabs.tabbar;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiText;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.GuiEmpire;
|
||||
import elements.GuiSkinElement;
|
||||
import elements.GuiListbox;
|
||||
import elements.GuiPanel;
|
||||
import elements.MarkupTooltip;
|
||||
import util.formatting;
|
||||
import icons;
|
||||
from multiplayer import wantSpectator;
|
||||
|
||||
class VictoryTab : Tab {
|
||||
GuiText@ heading;
|
||||
|
||||
GuiSkinElement@ victorPanel;
|
||||
GuiMarkupText@ description;
|
||||
GuiEmpire@ victor;
|
||||
|
||||
GuiSkinElement@ buttonBar;
|
||||
GuiPanel@ buttonPanel;
|
||||
|
||||
GuiButton@ rankingsButton;
|
||||
GuiListbox@ rankings;
|
||||
|
||||
array<StatPage@> stats;
|
||||
array<GuiButton@> statButtons;
|
||||
Alignment@ statAlign;
|
||||
|
||||
Sprite typeIcon;
|
||||
|
||||
VictoryTab() {
|
||||
super();
|
||||
|
||||
@heading = GuiText(this, Alignment(Left, Top+30, Right, Top+90));
|
||||
heading.horizAlign = 0.5;
|
||||
heading.font = FT_Big;
|
||||
heading.color = colors::Green;
|
||||
heading.stroke = colors::Black;
|
||||
|
||||
@victorPanel = GuiSkinElement(this, Alignment(Left+0.1f, Top+90, Right-0.1f, Top+242), SS_Panel);
|
||||
|
||||
@victor = GuiEmpire(victorPanel, Alignment(Left+6, Top+6, Width=140, Height=140));
|
||||
|
||||
@description = GuiMarkupText(victorPanel, Alignment(Left+220, Top+20, Right-6, Bottom-6));
|
||||
description.defaultFont = FT_Subtitle;
|
||||
|
||||
@buttonBar = GuiSkinElement(this, Alignment(Left+0.1f, Top+242+20, Right-0.1f, Height=42), SS_PlainBox);
|
||||
@buttonPanel = GuiPanel(this, Alignment(Left+0.1f, Top+242, Right-0.1f, Height=62));
|
||||
buttonPanel.vertType = ST_Never;
|
||||
|
||||
@statAlign = Alignment(Left+0.1f, Top+242+62, Right-0.1f, Bottom-30);
|
||||
|
||||
if(!playerEmpire.valid) {
|
||||
victorPanel.visible = false;
|
||||
heading.visible = false;
|
||||
buttonBar.alignment.top.pixels = 32;
|
||||
buttonPanel.alignment.top.pixels = 12;
|
||||
statAlign.top.pixels = 74;
|
||||
}
|
||||
|
||||
@rankingsButton = GuiButton(buttonPanel, Alignment(Left, Bottom-40, Width=135, Height=40), locale::V_RANKINGS);
|
||||
rankingsButton.buttonIcon = Sprite(material::PointsIcon);
|
||||
rankingsButton.toggleButton = true;
|
||||
rankingsButton.pressed = true;
|
||||
rankingsButton.font = FT_Bold;
|
||||
@rankings = GuiListbox(this, statAlign);
|
||||
rankings.itemHeight = 40;
|
||||
rankings.disabled = true;
|
||||
rankings.vertPadding = 8;
|
||||
rankings.style = SS_Panel;
|
||||
|
||||
addStat(ST_Int, stat::Points, 60, locale::STAT_POINTS, Sprite(material::PointsIcon), 2000);
|
||||
addStat(ST_Float, stat::Military, 60, locale::STAT_STRENGTH, icons::Strength, 5000);
|
||||
addStat(ST_Int, stat::Planets, 15, locale::STAT_PLANETS, icons::Planet, 10);
|
||||
addStat(ST_Int, stat::Ships, 15, locale::STAT_SHIPS, icons::Defense, 10);
|
||||
addStat(ST_Float, stat::Budget, 60, locale::STAT_BUDGET, icons::Money, 2000);
|
||||
addStat(ST_Float, stat::NetBudget, 60, locale::STAT_NET_BUDGET, icons::Money, 2000);
|
||||
addStat(ST_Float, stat::EnergyIncome, 60, locale::STAT_ENERGY_INCOME, icons::Energy, 2);
|
||||
addStat(ST_Float, stat::InfluenceIncome, 60, locale::STAT_INFLUENCE_INCOME, icons::Influence, 3/60.0);
|
||||
addStat(ST_Float, stat::ResearchIncome, 60, locale::STAT_RESEARCH_INCOME, icons::Research, 2);
|
||||
addStat(ST_Float, stat::ResearchTotal, 60, locale::STAT_RESEARCH_TOTAL, icons::Research, 1000);
|
||||
|
||||
updateAbsolutePosition();
|
||||
update();
|
||||
|
||||
locked = true;
|
||||
}
|
||||
|
||||
void addStat(StatType type, stat::EmpireStat Stat, int FilterDuration, const string& name, const Sprite& icon, double baseMax = 1) {
|
||||
StatPage page(this, statAlign, type, Stat, FilterDuration, name, baseMax);
|
||||
page.visible = false;
|
||||
stats.insertLast(page);
|
||||
|
||||
int index = stats.length;
|
||||
GuiButton btn(buttonPanel, Alignment(Left+135*index, Bottom-40, Width=135, Height=40), name);
|
||||
btn.toggleButton = true;
|
||||
btn.pressed = false;
|
||||
btn.buttonIcon = icon;
|
||||
btn.font = FT_Bold;
|
||||
statButtons.insertLast(btn);
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xffc283ff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xffb900ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8d7949ff);
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return typeIcon;
|
||||
}
|
||||
|
||||
void switchPage(uint page) {
|
||||
rankings.visible = page == 0;
|
||||
rankingsButton.pressed = page == 0;
|
||||
|
||||
for(uint i = 0, cnt = stats.length; i < cnt; ++i) {
|
||||
stats[i].visible = i+1 == page;
|
||||
statButtons[i].pressed = i+1 == page;
|
||||
}
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
update();
|
||||
}
|
||||
|
||||
int lastUpdate = systemTime - 1000;
|
||||
bool fullUpdate = true;
|
||||
uint nextUpdateIndex = 0;
|
||||
|
||||
void update() {
|
||||
if(systemTime - lastUpdate < 1000)
|
||||
return;
|
||||
lastUpdate = systemTime;
|
||||
|
||||
Empire@ winner = playerEmpire;
|
||||
int myVictory = playerEmpire.Victory;
|
||||
|
||||
for(uint i = 0, cnt = getEmpireCount(); i < cnt; ++i) {
|
||||
if(getEmpire(i).Victory == 1) {
|
||||
@winner = getEmpire(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Show the appropriate victory message
|
||||
if(myVictory == 1) {
|
||||
heading.text = locale::V_WON_TITLE;
|
||||
heading.color = colors::Green;
|
||||
description.text = format(locale::V_WON_TEXT, formatEmpireName(winner), formatEmpireName(playerEmpire));
|
||||
typeIcon = Sprite(material::PointsIcon);
|
||||
}
|
||||
else if(myVictory == -2 && playerEmpire.SubjugatedBy.Victory == 1) {
|
||||
heading.text = locale::V_LESSER_TITLE;
|
||||
heading.color = Color(0xfff500ff);
|
||||
description.text = format(locale::V_LESSER_TEXT, formatEmpireName(winner), formatEmpireName(playerEmpire));
|
||||
typeIcon = Sprite(material::PointsIcon);
|
||||
}
|
||||
else {
|
||||
heading.text = locale::V_LOST_TITLE;
|
||||
heading.color = colors::Red;
|
||||
description.text = format(locale::V_LOST_TEXT, formatEmpireName(winner), formatEmpireName(playerEmpire));
|
||||
typeIcon = Sprite(material::SystemUnderAttack);
|
||||
}
|
||||
|
||||
if(victorPanel.visible)
|
||||
title = heading.text;
|
||||
else
|
||||
title = locale::V_SCORES;
|
||||
|
||||
//Update rankings
|
||||
array<EmpSorter> sorted;
|
||||
for(uint i = 0, cnt = getEmpireCount(); i < cnt; ++i) {
|
||||
Empire@ other = getEmpire(i);
|
||||
if(other.major) {
|
||||
EmpSorter sort;
|
||||
@sort.emp = other;
|
||||
sorted.insertLast(sort);
|
||||
}
|
||||
}
|
||||
sorted.sortAsc();
|
||||
|
||||
rankings.clearItems();
|
||||
for(uint i = 0, cnt = sorted.length; i < cnt; ++i) {
|
||||
Empire@ emp = sorted[i].emp;
|
||||
string text = "";
|
||||
|
||||
text += format(" #$1", toString(i+1));
|
||||
text += format("[offset=100][img=$2;28;$3/] $1[/offset]", formatEmpireName(emp),
|
||||
getSpriteDesc(Sprite(emp.flag)), toString(emp.color));
|
||||
|
||||
if(hasGameEnded()) {
|
||||
string victory = "";
|
||||
if(emp.SubjugatedBy !is null)
|
||||
victory = format("[color=#aaa]$1[/color]", format(locale::V_SUBJUGATED, formatEmpireName(emp.SubjugatedBy)));
|
||||
else if(emp.Victory == 1)
|
||||
victory = format("[color=#0f0]$1[/color]", locale::V_WON_TITLE);
|
||||
else
|
||||
victory = format("[color=#f00]$1[/color]", locale::V_LOST_TITLE);
|
||||
text += format("[offset=450]$1[/offset]", victory);
|
||||
}
|
||||
else {
|
||||
string victory;
|
||||
if(emp.SubjugatedBy !is null)
|
||||
victory = format("[color=#aaa]$1[/color]", format(locale::V_SUBJUGATED, formatEmpireName(emp.SubjugatedBy)));
|
||||
text += format("[offset=450]$1[/offset]", victory);
|
||||
}
|
||||
|
||||
text += format("[offset=880]$1[/offset]", format(locale::EMPIRE_POINTS, toString(emp.points.value)));
|
||||
rankings.addItem(GuiMarkupListText(text, FT_Subtitle));
|
||||
}
|
||||
|
||||
//Update stats data
|
||||
if(fullUpdate) {
|
||||
fullUpdate = false;
|
||||
for(uint i = 0, cnt = stats.length; i < cnt; ++i)
|
||||
stats[i].update();
|
||||
}
|
||||
else {
|
||||
//TODO: Even this probably isn't necessary, make sure
|
||||
stats[(nextUpdateIndex++) % stats.length].update();
|
||||
}
|
||||
|
||||
victorPanel.color = winner.color;
|
||||
@victor.empire = winner;
|
||||
|
||||
if(!victorPanel.visible && playerEmpire.valid) {
|
||||
locked = false;
|
||||
shownVictory = false;
|
||||
closeTab(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
return BaseGuiElement::onKeyEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(event.caller is rankingsButton) {
|
||||
switchPage(0);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
for(uint i = 0, cnt = statButtons.length; i < cnt; ++i) {
|
||||
if(event.caller is statButtons[i]) {
|
||||
switchPage(i+1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_DesignOverviewBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
class EmpSorter {
|
||||
Empire@ emp;
|
||||
|
||||
int opCmp(const EmpSorter& other) const {
|
||||
if(other.emp.Victory != emp.Victory) {
|
||||
if(emp.Victory == 1)
|
||||
return -1;
|
||||
if(emp.Victory == -1)
|
||||
return 1;
|
||||
if(other.emp.Victory == 1)
|
||||
return 1;
|
||||
if(other.emp.Victory == -1)
|
||||
return -1;
|
||||
if(emp.Victory == -2) {
|
||||
if(other.emp.Victory == 0)
|
||||
return 1;
|
||||
if(emp.SubjugatedBy.Victory == 1)
|
||||
return -1;
|
||||
}
|
||||
if(other.emp.Victory == -2) {
|
||||
if(emp.Victory == 0)
|
||||
return -1;
|
||||
if(other.emp.SubjugatedBy.Victory == 1)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if(emp.points.value > other.emp.points.value)
|
||||
return -1;
|
||||
if(emp.points.value < other.emp.points.value)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class StatPage : BaseGuiElement {
|
||||
stat::EmpireStat stat;
|
||||
StatType type;
|
||||
array<StatTracker@> trackers;
|
||||
double endTime = 0;
|
||||
double minVal = 0;
|
||||
double maxVal = 0;
|
||||
double baseMin = 0;
|
||||
double baseMax = 1;
|
||||
bool sqrScale = false;
|
||||
|
||||
StatPage(IGuiElement@ parent, Alignment@ align, StatType type, stat::EmpireStat Stat, int FilterDuration, const string& name, double baseMax = 1) {
|
||||
super(parent, align);
|
||||
this.stat = Stat;
|
||||
this.type = type;
|
||||
this.baseMax = baseMax;
|
||||
if(stat == stat::Military) {
|
||||
this.sqrScale = true;
|
||||
this.baseMin = 2000;
|
||||
}
|
||||
for(uint i = 0, cnt = getEmpireCount(); i <cnt; ++i) {
|
||||
Empire@ emp = getEmpire(i);
|
||||
if(emp.major)
|
||||
trackers.insertLast(StatTracker(type, Stat, emp.color, FilterDuration, emp, sqrScale));
|
||||
}
|
||||
|
||||
addLazyMarkupTooltip(this, width=300, update=true);
|
||||
}
|
||||
|
||||
double getOffsetTime(int offset) {
|
||||
return double(offset-52) / double(size.x-64) * endTime;
|
||||
}
|
||||
|
||||
string formatValue(double amt, bool shortForm = false) {
|
||||
if(stat == stat::Budget || stat == stat::NetBudget)
|
||||
return formatMoney(int(amt));
|
||||
if(stat == stat::EnergyIncome || stat == stat::ResearchIncome)
|
||||
return standardize(amt, true)+locale::PER_SECOND;
|
||||
if(stat == stat::InfluenceIncome)
|
||||
return standardize(amt * 60.0, true)+locale::PER_MIN;
|
||||
if(type == ST_Int) {
|
||||
if(shortForm && amt >= 1000)
|
||||
return standardize(amt, true);
|
||||
else
|
||||
return toString(floor(amt), 0);
|
||||
}
|
||||
return standardize(amt, true);
|
||||
}
|
||||
|
||||
string get_tooltip() override {
|
||||
int mx = mousePos.x;
|
||||
if(mx < AbsolutePosition.topLeft.x+52 || mx > AbsolutePosition.botRight.x-12)
|
||||
return "";
|
||||
string text;
|
||||
double time = getOffsetTime(mx - absolutePosition.topLeft.x);
|
||||
text += format("[center][font=Subtitle]$1[/font][/center]", formatGameTime(time));
|
||||
for(uint i = 0, cnt = trackers.length; i < cnt; ++i) {
|
||||
double amt = trackers[i].getClosest(time).y;
|
||||
text += format("[b]$1[offset=150]$2[/offset][/b]\n",
|
||||
formatEmpireName(trackers[i].emp),
|
||||
formatValue(amt));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
void update() {
|
||||
endTime = gameTime;
|
||||
minVal = baseMin; maxVal = baseMax;
|
||||
for(uint i = 0, cnt = trackers.length; i < cnt; ++i) {
|
||||
trackers[i].update();
|
||||
minVal = min(minVal, trackers[i].minVal);
|
||||
maxVal = max(maxVal, trackers[i].maxVal);
|
||||
}
|
||||
for(uint i = 0, cnt = trackers.length; i < cnt; ++i) {
|
||||
trackers[i].minVal = minVal;
|
||||
trackers[i].maxVal = maxVal;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_Panel, SF_Normal, AbsolutePosition);
|
||||
|
||||
const Font@ ft = skin.getFont(FT_Normal);
|
||||
|
||||
{
|
||||
int interval = 100;
|
||||
vec2i pos(154, size.height-15);
|
||||
while(pos.x < size.x) {
|
||||
double time = double(pos.x-52) / double(size.x-64) * endTime;
|
||||
ft.draw(pos=recti_centered(pos+AbsolutePosition.topLeft, vec2i(200,30)),
|
||||
horizAlign=0.5, text=formatTime(time), color=Color(0xaaaaaaff));
|
||||
drawLine(vec2i(pos.x, 12)+AbsolutePosition.topLeft,
|
||||
vec2i(pos.x, size.height-40)+AbsolutePosition.topLeft,
|
||||
Color(0xaaaaaa20));
|
||||
pos.x += interval;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int interval = 40;
|
||||
vec2i pos(26, size.height-40);
|
||||
string prevVal;
|
||||
if(type == ST_Int) {
|
||||
double mult = ceil(double(size.height-52) / ceil(maxVal-minVal));
|
||||
interval = ceil(ceil(double(interval) / mult) * mult);
|
||||
}
|
||||
while(pos.y > 14) {
|
||||
double val = 0;
|
||||
if(sqrScale)
|
||||
val = minVal + (maxVal - minVal) * sqr(1.0 - (double(pos.y-12) / double(size.y-52)));
|
||||
else
|
||||
val = minVal + (maxVal - minVal) * (1.0 - (double(pos.y-12) / double(size.y-52)));
|
||||
string valDisp = formatValue(val, true);
|
||||
if(valDisp != prevVal) {
|
||||
ft.draw(pos=recti_centered(pos+AbsolutePosition.topLeft, vec2i(200,30)),
|
||||
horizAlign=0.5, text=valDisp, color=Color(0xaaaaaaff));
|
||||
prevVal = valDisp;
|
||||
}
|
||||
drawLine(vec2i(42, pos.y)+AbsolutePosition.topLeft,
|
||||
vec2i(size.width-12, pos.y)+AbsolutePosition.topLeft,
|
||||
Color(0xaaaaaa20));
|
||||
pos.y -= interval;
|
||||
}
|
||||
|
||||
if(minVal < 0 && maxVal > 0 && !sqrScale) {
|
||||
int y = size.height-40 - size.y * (-minVal) / (maxVal - minVal);
|
||||
drawLine(vec2i(42, y)+AbsolutePosition.topLeft,
|
||||
vec2i(size.width-12, y)+AbsolutePosition.topLeft,
|
||||
Color(0xaa000040), size=3);
|
||||
}
|
||||
}
|
||||
|
||||
for(uint i = 0, cnt = trackers.length; i < cnt; ++i)
|
||||
trackers[i].draw(skin, AbsolutePosition.padded(42,12,12,40));
|
||||
|
||||
if(AbsolutePosition.isWithin(mousePos)) {
|
||||
int mx = mousePos.x;
|
||||
if(mx >= AbsolutePosition.topLeft.x+52 && mx <= AbsolutePosition.botRight.x-12) {
|
||||
drawLine(vec2i(mx, AbsolutePosition.topLeft.y+12),
|
||||
vec2i(mx, AbsolutePosition.botRight.y-40),
|
||||
Color(0xaaaaaaff));
|
||||
}
|
||||
}
|
||||
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
enum StatType {
|
||||
ST_Int,
|
||||
ST_Float,
|
||||
}
|
||||
|
||||
final class StatTracker {
|
||||
double minVal = 0, maxVal = 1;
|
||||
stat::EmpireStat stat;
|
||||
Color color;
|
||||
int filterDuration = 1;
|
||||
array<vec2d> data;
|
||||
Empire@ emp;
|
||||
StatType type;
|
||||
double endTime;
|
||||
bool sqrScale = false;
|
||||
|
||||
array<vec2i> points;
|
||||
vec2i lastSize;
|
||||
|
||||
StatTracker(StatType type, stat::EmpireStat Stat, const Color& col, int FilterDuration, Empire@ emp = playerEmpire, bool sqrScale = false) {
|
||||
stat = Stat;
|
||||
color = col;
|
||||
filterDuration = FilterDuration;
|
||||
this.type = type;
|
||||
@this.emp = emp;
|
||||
this.sqrScale = sqrScale;
|
||||
}
|
||||
|
||||
vec2d getClosest(double time) {
|
||||
vec2d closest(0, 0);
|
||||
double dist = INFINITY;
|
||||
//Don't make me do a binary search you monster
|
||||
for(uint i = 0, cnt = data.length; i < cnt; ++i) {
|
||||
double d = abs(data[i].x - time);
|
||||
if(d < dist) {
|
||||
dist = d;
|
||||
closest = data[i];
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
void rebuildPoints(vec2i size) {
|
||||
array<vec3d> pts(1);
|
||||
|
||||
vec2d factor(double(size.x) / endTime, -double(size.y) / (maxVal - minVal));
|
||||
vec2d offset(0.0, -minVal);
|
||||
|
||||
uint lastX = 0;
|
||||
for(uint i = 0, cnt = data.length; i < cnt; ++i) {
|
||||
vec2d pt = data[i] + offset;
|
||||
pt.x *= factor.x;
|
||||
|
||||
if(!sqrScale) {
|
||||
pt.y *= factor.y;
|
||||
}
|
||||
else {
|
||||
if(pt.y != 0)
|
||||
pt.y = -double(size.y) * sqrt(pt.y / (maxVal - minVal));
|
||||
}
|
||||
|
||||
uint x = int(pt.x);
|
||||
if(i == 0 && x != 0)
|
||||
pts[0] = vec3d(0.0, pt.y, 1.0);
|
||||
|
||||
if(x != lastX)
|
||||
pts.resize(pts.length + 1);
|
||||
pts[pts.length-1] += vec3d(pt.x, pt.y, 1.0);
|
||||
}
|
||||
|
||||
int maxTimeDelta = max(int(ceil(double(size.x * filterDuration) / endTime)), int(1));
|
||||
|
||||
points.length = 0;
|
||||
points.reserve(pts.length + 1);
|
||||
for(uint i = 0, cnt = pts.length; i < cnt; ++i) {
|
||||
vec3d pt = pts[i];
|
||||
vec2i px = vec2i(pt.x / pt.z, pt.y / pt.z + 0.5);
|
||||
if(i > 0) {
|
||||
vec2i prev = points.last;
|
||||
if(prev.x < px.x - maxTimeDelta)
|
||||
points.insertLast(vec2i(px.x - 1, prev.y));
|
||||
}
|
||||
points.insertLast(px);
|
||||
}
|
||||
|
||||
if(points.last.x < size.x - 1)
|
||||
points.insertLast(vec2i(size.x - 1, points.last.y));
|
||||
|
||||
lastSize = size;
|
||||
}
|
||||
|
||||
void update() {
|
||||
minVal = INFINITY;
|
||||
maxVal = -INFINITY;
|
||||
data.length = 0;
|
||||
|
||||
StatHistory history(emp, stat);
|
||||
endTime = gameTime;
|
||||
|
||||
while(history.advance(1)) {
|
||||
double val = 0;
|
||||
if(type == ST_Int)
|
||||
val = history.intVal;
|
||||
else
|
||||
val = history.floatVal;
|
||||
|
||||
if(val > maxVal)
|
||||
maxVal = val;
|
||||
if(val < minVal)
|
||||
minVal = val;
|
||||
|
||||
data.insertLast(vec2d(history.time, val));
|
||||
}
|
||||
|
||||
lastSize = vec2i();
|
||||
}
|
||||
|
||||
void draw(const Skin@ skin, recti bound) {
|
||||
vec2i size = bound.size;
|
||||
if(size != lastSize)
|
||||
rebuildPoints(size);
|
||||
|
||||
if(points.length == 0) {
|
||||
drawLine(bound.topLeft + vec2i(0, bound.height), bound.botRight, color);
|
||||
return;
|
||||
}
|
||||
|
||||
vec2i corner = bound.topLeft + vec2i(0,size.y);
|
||||
vec2i prev = points[0] + corner;
|
||||
|
||||
uint lines = points.length - 1;
|
||||
uint index = 0;
|
||||
while(index < lines) {
|
||||
drawPolygonStart(PT_LineStrip, min(lines - index, 250));
|
||||
drawPolygonPoint(prev, color);
|
||||
for(uint i = 0; i < 250 && index + i < lines; ++i) {
|
||||
vec2i pt = points[index + i + 1] + corner;
|
||||
drawPolygonPoint(pt);
|
||||
prev = pt;
|
||||
}
|
||||
drawPolygonEnd();
|
||||
index += 250;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createVictoryTab() {
|
||||
return VictoryTab();
|
||||
}
|
||||
|
||||
void init() {
|
||||
/*auto@ tab = createVictoryTab();*/
|
||||
/*newTab(tab);*/
|
||||
/*switchToTab(tab);*/
|
||||
}
|
||||
|
||||
bool shownVictory = false;
|
||||
void tick(double time) {
|
||||
if(!shownVictory && (hasGameEnded() || (wantSpectator && !playerEmpire.valid))) {
|
||||
auto@ tab = createVictoryTab();
|
||||
newTab(tab);
|
||||
if(hasGameEnded())
|
||||
switchToTab(tab);
|
||||
shownVictory = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
import tabs.Tab;
|
||||
import elements.GuiPanel;
|
||||
import elements.GuiMarkupText;
|
||||
import elements.MarkupTooltip;
|
||||
import elements.GuiBackgroundPanel;
|
||||
import elements.GuiButton;
|
||||
import elements.GuiTextbox;
|
||||
import icons;
|
||||
|
||||
from tabs.tabbar import popTab, newTab, switchToTab, findTab, ActiveTab, browseTab;
|
||||
import Tab@ createCommunityDesignPage(int id) from "community.DesignPage";
|
||||
|
||||
const string URI_HINT = "://";
|
||||
void openGeneralLink(const string& link, int button = 0) {
|
||||
if(link.findFirst(URI_HINT) != -1) {
|
||||
if(button == 0)
|
||||
openBrowser(link);
|
||||
}
|
||||
else if(link.startswith_nocase("design:")) {
|
||||
int id = toInt(link.substr(7));
|
||||
if(button == 2)
|
||||
newTab(createCommunityDesignPage(id));
|
||||
else
|
||||
browseTab(ActiveTab, createCommunityDesignPage(id), true);
|
||||
}
|
||||
else {
|
||||
openWikiLink(link, button);
|
||||
}
|
||||
}
|
||||
|
||||
void openWikiLink(const string& link, int button = 0) {
|
||||
if(button == 0) {
|
||||
auto@ t = cast<WikiTab>(ActiveTab);
|
||||
if(t !is null)
|
||||
t.load(link);
|
||||
else
|
||||
browseTab(ActiveTab, createWikiTab(link), true);
|
||||
}
|
||||
else if(button == 2) {
|
||||
Tab@ newtb = createWikiTab(link, true);
|
||||
newTab(ActiveTab, newtb);
|
||||
|
||||
if(shiftKey)
|
||||
switchToTab(newtb);
|
||||
}
|
||||
}
|
||||
|
||||
class LinkableMarkupText : GuiMarkupText {
|
||||
LinkableMarkupText(IGuiElement@ parent, const recti& pos, bool paragraphize = false) {
|
||||
super(parent, pos);
|
||||
this.paragraphize = paragraphize;
|
||||
@tooltipObject = MarkupTooltip(300, 0.f, true, true);
|
||||
}
|
||||
|
||||
LinkableMarkupText(IGuiElement@ parent, Alignment@ align, bool paragraphize = false) {
|
||||
super(parent, align);
|
||||
this.paragraphize = paragraphize;
|
||||
@tooltipObject = MarkupTooltip(300, 0.f, true, true);
|
||||
}
|
||||
|
||||
void onLinkClicked(const string& link, int button) override {
|
||||
openGeneralLink(link, button);
|
||||
}
|
||||
};
|
||||
|
||||
class WikiTab : Tab {
|
||||
WebData wdata;
|
||||
bool loading = false;
|
||||
string loadPage;
|
||||
string anchor;
|
||||
string[] history;
|
||||
|
||||
GuiBackgroundPanel@ bg;
|
||||
GuiPanel@ panel;
|
||||
LinkableMarkupText@ text;
|
||||
|
||||
GuiButton@ backButton;
|
||||
GuiButton@ goButton;
|
||||
GuiButton@ homeButton;
|
||||
GuiTextbox@ navBox;
|
||||
|
||||
WikiTab() {
|
||||
super();
|
||||
@backButton = GuiButton(this, Alignment(Left+8, Top+4, Left+108, Top+36), locale::WIKI_BACK);
|
||||
backButton.buttonIcon = icons::Back;
|
||||
|
||||
@homeButton = GuiButton(this, Alignment(Left+112, Top+4, Left+212, Top+36), locale::WIKI_HOME);
|
||||
@navBox = GuiTextbox(this, Alignment(Left+216, Top+4, Right-186, Top+36));
|
||||
|
||||
@goButton = GuiButton(this, Alignment(Right-182, Top+4, Right-8, Top+36), locale::WIKI_BROWSER);
|
||||
goButton.buttonIcon = icons::Go;
|
||||
|
||||
@bg = GuiBackgroundPanel(this, Alignment(Left+8, Top+40, Right-8, Bottom-8));
|
||||
bg.titleColor = Color(0xff83bcff);
|
||||
bg.title = title;
|
||||
|
||||
@panel = GuiPanel(bg, Alignment(Left+8, Top+30, Right-4, Bottom-4));
|
||||
panel.horizType = ST_Never;
|
||||
@text = LinkableMarkupText(panel, recti(0, 0, 100, 100), true);
|
||||
text.defaultColor = Color(0xccccccff);
|
||||
load("Main Page");
|
||||
}
|
||||
|
||||
Color get_activeColor() {
|
||||
return Color(0xff83bcff);
|
||||
}
|
||||
|
||||
Color get_inactiveColor() {
|
||||
return Color(0xff0077ff);
|
||||
}
|
||||
|
||||
Color get_seperatorColor() {
|
||||
return Color(0x8d4969ff);
|
||||
}
|
||||
|
||||
TabCategory get_category() {
|
||||
return TC_Wiki;
|
||||
}
|
||||
|
||||
Sprite get_icon() {
|
||||
return Sprite(material::TabWiki);
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
Tab::updateAbsolutePosition();
|
||||
if(text.size.width != panel.size.width-20) {
|
||||
text.size = vec2i(panel.size.width-20, text.size.height);
|
||||
text.updateAbsolutePosition();
|
||||
}
|
||||
}
|
||||
|
||||
void show() {
|
||||
Tab::show();
|
||||
if(loadPage.length != 0) {
|
||||
load(loadPage);
|
||||
loadPage = "";
|
||||
}
|
||||
}
|
||||
|
||||
void load(const string& page, bool record = true, bool loadNow = false) {
|
||||
string ptitle = page;
|
||||
ptitle[0] = uppercase(ptitle[0]);
|
||||
|
||||
title = format(locale::WIKI_TITLE, ptitle);
|
||||
bg.title = ptitle;
|
||||
navBox.text = ptitle;
|
||||
|
||||
if((!visible && !loadNow) || loading) {
|
||||
loadPage = page;
|
||||
return;
|
||||
}
|
||||
|
||||
text.text = locale::WIKI_LOADING;
|
||||
panel.updateAbsolutePosition();
|
||||
|
||||
if(record) {
|
||||
if(history.length == 0 || history[history.length-1] != page)
|
||||
history.insertLast(page);
|
||||
}
|
||||
|
||||
string link = page;
|
||||
int aPos = page.findFirst("#");
|
||||
if(aPos != -1 && aPos < int(page.length)-1) {
|
||||
anchor = page.substr(aPos+1);
|
||||
link = page.substr(0, aPos);
|
||||
}
|
||||
else {
|
||||
anchor = "";
|
||||
}
|
||||
|
||||
loading = true;
|
||||
getWikiPage(link, wdata);
|
||||
}
|
||||
|
||||
void back() {
|
||||
if(history.length <= 1) {
|
||||
if(previous !is null)
|
||||
popTab(this);
|
||||
return;
|
||||
}
|
||||
|
||||
load(history[history.length - 2], false);
|
||||
history.removeAt(history.length - 1);
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(!visible)
|
||||
return;
|
||||
|
||||
backButton.disabled = history.length <= 1 && previous is null;
|
||||
if(loading) {
|
||||
if(wdata.completed) {
|
||||
if(wdata.error)
|
||||
text.text = locale::WIKI_404;
|
||||
else
|
||||
text.text = wdata.result;
|
||||
panel.updateAbsolutePosition();
|
||||
loading = false;
|
||||
|
||||
if(anchor.length != 0) {
|
||||
int pos = text.getAnchor(anchor);
|
||||
if(pos != -1)
|
||||
panel.scrollToVert(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(loadPage.length != 0) {
|
||||
load(loadPage);
|
||||
loadPage = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool onKeyEvent(const KeyboardEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case KET_Key_Up:
|
||||
if(event.key == KEY_ESC) {
|
||||
if(previous !is null)
|
||||
popTab(this);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onKeyEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
switch(event.type) {
|
||||
case GUI_Confirmed:
|
||||
if(event.caller is navBox) {
|
||||
load(navBox.text);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GUI_Clicked:
|
||||
if(event.caller is homeButton) {
|
||||
if(previous !is null && previous.category == TC_Wiki)
|
||||
popTab(this);
|
||||
else
|
||||
load("Main Page");
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is backButton) {
|
||||
back();
|
||||
return true;
|
||||
}
|
||||
else if(event.caller is goButton) {
|
||||
openBrowser("http://wiki.starruler2.com/"+navBox.text);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
skin.draw(SS_WikiBG, SF_Normal, AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
};
|
||||
|
||||
Tab@ createWikiTab() {
|
||||
return WikiTab();
|
||||
}
|
||||
|
||||
Tab@ createWikiTab(const string& page, bool loadNow = false) {
|
||||
WikiTab@ tab = WikiTab();
|
||||
tab.load(page, true, loadNow);
|
||||
return tab;
|
||||
}
|
||||
|
||||
void showWikiPage(const string& page, bool background = false) {
|
||||
if(background) {
|
||||
newTab(createWikiTab(page, true));
|
||||
}
|
||||
else {
|
||||
WikiTab@ tb = cast<WikiTab>(findTab(TC_Wiki));
|
||||
if(tb !is null) {
|
||||
tb.load(page);
|
||||
switchToTab(tb);
|
||||
}
|
||||
else {
|
||||
switchToTab(newTab(createWikiTab(page, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,953 @@
|
||||
#priority render 100
|
||||
#priority init 5
|
||||
import tabs.Tab;
|
||||
import elements.GuiButton;
|
||||
import version;
|
||||
from input import lastCamera;
|
||||
|
||||
import BaseGuiElement@ createGlobalBar() from "tabs.GlobalBar";
|
||||
|
||||
import Tab@ createHomeTab() from "tabs.HomeTab";
|
||||
import bool isHomeTab(Tab@) from "tabs.HomeTab";
|
||||
import Tab@ createDiplomacyTab() from "tabs.DiplomacyTab";
|
||||
import Tab@ createResearchTab() from "tabs.ResearchTab";
|
||||
import Tab@ createGalaxyTab() from "tabs.GalaxyTab";
|
||||
import Tab@ createPlanetsTab() from "tabs.PlanetsTab";
|
||||
import Tab@ createWikiTab() from "tabs.WikiTab";
|
||||
import Tab@ createCommunityHome() from "community.Home";
|
||||
import Tab@ createGalaxyTab(Empire@) from "tabs.GalaxyTab";
|
||||
import Tab@ createDesignOverviewTab() from "tabs.DesignOverviewTab";
|
||||
import Tab@ createAttitudesTab() from "tabs.AttitudesTab";
|
||||
import IGuiElement@ getGoDialog() from "navigation.go";
|
||||
import void toggleGoDialog() from "navigation.go";
|
||||
|
||||
const int TAB_HOME_OFFSET = 84;
|
||||
const int TAB_MAX_WIDTH = 186;
|
||||
const int BUTTON_NEW_WIDTH = 12;
|
||||
const int TAB_MIN_WIDTH = 45;
|
||||
const int TAB_HEIGHT = 26;
|
||||
const int TAB_SPACING = 8;
|
||||
const int TAB_SCRUNCH = -18;
|
||||
const int GLOBAL_BAR_HEIGHT = 50;
|
||||
const vec2i TAB_ICON_OFFSET(16, 2);
|
||||
const vec2i TAB_ICON_SIZE(24, 24);
|
||||
const vec2i TAB_CLOSE_OFFSET(14, 7);
|
||||
const vec2i TAB_TEXT_OFFSET(44, 5);
|
||||
const vec2i TAB_PADDING(4, 4);
|
||||
const string ellipsis = "...";
|
||||
const uint MAX_STORED_TABS = 8;
|
||||
const bool ALWAYS_SCRUNCH_TABS = true;
|
||||
const Color TAB_FLASH_COLOR(0xffffffff);
|
||||
const double TAB_FLASH_PERIOD = 1.0;
|
||||
|
||||
GuiTabBar@ tabBar;
|
||||
BaseGuiElement@ globalBar;
|
||||
Tab@[] tabs;
|
||||
Tab@[] closedTabs;
|
||||
Tab@ activeTab;
|
||||
|
||||
//Tab management public interface
|
||||
Tab@ newTab() {
|
||||
Tab@ tab = createHomeTab();
|
||||
newTab(tab);
|
||||
return tab;
|
||||
}
|
||||
|
||||
Tab@ get_ActiveTab() {
|
||||
return activeTab;
|
||||
}
|
||||
|
||||
uint get_tabCount() {
|
||||
return tabs.length;
|
||||
}
|
||||
|
||||
Tab@ get_Tabs(uint i) {
|
||||
return tabs[i];
|
||||
}
|
||||
|
||||
Tab@ findTab(int cat) {
|
||||
int cnt = tabs.length;
|
||||
int index = tabs.find(activeTab);
|
||||
int find = max(index, cnt - index);
|
||||
|
||||
for(int i = 0; i <= find; ++i) {
|
||||
if(index + i < cnt) {
|
||||
if(tabs[index + i].category == cat)
|
||||
return tabs[index + i];
|
||||
}
|
||||
if(index - i >= 0) {
|
||||
if(tabs[index - i].category == cat)
|
||||
return tabs[index - i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Tab@ findTab(IGuiElement@ elem) {
|
||||
while(elem !is null) {
|
||||
if(cast<Tab>(elem) !is null)
|
||||
return cast<Tab>(elem);
|
||||
@elem = elem.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void prepareTab(Tab@ tab) {
|
||||
if(tab.initialized)
|
||||
return;
|
||||
@tab.alignment = Alignment(Left, Top+TAB_HEIGHT + 2 + GLOBAL_BAR_HEIGHT, Right, Bottom);
|
||||
tab.updateAbsolutePosition();
|
||||
tab.init();
|
||||
tab.sendToBack();
|
||||
tab.initialized = true;
|
||||
}
|
||||
|
||||
Tab@ newTab(Tab@ tab) {
|
||||
prepareTab(tab);
|
||||
tabs.insertLast(tab);
|
||||
tabBar.refresh();
|
||||
return tab;
|
||||
}
|
||||
|
||||
Tab@ newTab(Tab@ from, Tab@ tab) {
|
||||
prepareTab(tab);
|
||||
int index = tabs.find(from);
|
||||
if(index >= 0)
|
||||
tabs.insertAt(index+1, tab);
|
||||
else
|
||||
tabs.insertLast(tab);
|
||||
tabBar.refresh();
|
||||
return tab;
|
||||
}
|
||||
|
||||
void switchToTab(Tab@ tab) {
|
||||
if(tab is null)
|
||||
return;
|
||||
if(tab is activeTab)
|
||||
return;
|
||||
|
||||
Tab@ prev = activeTab;
|
||||
@activeTab = tab;
|
||||
|
||||
if(prev !is null)
|
||||
prev.hide();
|
||||
tab.show();
|
||||
}
|
||||
|
||||
void switchToTab(int pos) {
|
||||
int index = tabs.find(activeTab);
|
||||
index = (index + pos) % tabs.length;
|
||||
|
||||
while(index < 0)
|
||||
index += tabs.length;
|
||||
|
||||
switchToTab(tabs[index]);
|
||||
}
|
||||
|
||||
bool switchToTab(TabCategory cat) {
|
||||
Tab@ tab = findTab(cat);
|
||||
if(tab !is null) {
|
||||
switchToTab(tab);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void closeTab() {
|
||||
closeTab(activeTab);
|
||||
}
|
||||
|
||||
Tab@ reopenTab() {
|
||||
//Switch back to the previous tab from the final home tab
|
||||
if(tabs.length == 1 && isHomeTab(tabs[0]) && tabs[0].previous !is null) {
|
||||
browseTab(tabs[0], tabs[0].previous, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Check if there are any tabs left to reopen
|
||||
if(closedTabs.length == 0)
|
||||
return null;
|
||||
|
||||
//Set the tabs to reopen
|
||||
Tab@ tab = closedTabs[0];
|
||||
if(tab !is null)
|
||||
tab.reopen();
|
||||
|
||||
//Create the new tab
|
||||
@tab = closedTabs[0];
|
||||
newTab(tab);
|
||||
closedTabs.removeAt(0);
|
||||
return tab;
|
||||
}
|
||||
|
||||
void closeTab(Tab@ tab) {
|
||||
//Don't close locked tabs
|
||||
if(tab.locked)
|
||||
return;
|
||||
|
||||
//Check if it is in the list at all
|
||||
int index = tabs.find(tab);
|
||||
if(index >= 0) {
|
||||
//Never close the last tab
|
||||
if(tabs.length == 1) {
|
||||
browseTab(activeTab, createHomeTab(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
//Remove from the list
|
||||
tabs.removeAt(index);
|
||||
|
||||
//Hide it if it is active
|
||||
if(activeTab is tab)
|
||||
switchToTab(tabs[max(0, index - 1)]);
|
||||
}
|
||||
|
||||
//Store the tab for reopening
|
||||
if(tab !is null && (!isHomeTab(tab) || tab.previous !is null)) {
|
||||
closedTabs.insertAt(0, tab);
|
||||
if(closedTabs.length >= MAX_STORED_TABS) {
|
||||
for(uint i = MAX_STORED_TABS; i < closedTabs.length; ++i)
|
||||
closedTabs[i].remove();
|
||||
closedTabs.length = MAX_STORED_TABS;
|
||||
}
|
||||
}
|
||||
|
||||
//Remove it and all previous tabs
|
||||
Tab@ first = tab;
|
||||
while(tab !is null) {
|
||||
//Close the tab
|
||||
tab.close();
|
||||
|
||||
//Go to the previous tab
|
||||
@tab = tab.previous;
|
||||
if(tab is first)
|
||||
break;
|
||||
}
|
||||
|
||||
//Refresh stuff
|
||||
tabBar.refresh();
|
||||
}
|
||||
|
||||
void browseTab(Tab@ to, bool remember = false) {
|
||||
browseTab(activeTab, to, remember);
|
||||
}
|
||||
|
||||
void browseTab(Tab@ inside, Tab@ to, bool remember = false) {
|
||||
//Make sure our new tab is initialized
|
||||
prepareTab(to);
|
||||
|
||||
if(inside.locked && !to.locked)
|
||||
to.locked = true;
|
||||
|
||||
//Set it in the list
|
||||
int index = tabs.find(inside);
|
||||
if(index >= 0)
|
||||
@tabs[index] = to;
|
||||
|
||||
//Do showing and hiding
|
||||
if(inside is activeTab)
|
||||
switchToTab(to);
|
||||
|
||||
//New tab knows where it came from
|
||||
if(remember) {
|
||||
@to.previous = inside;
|
||||
}
|
||||
else {
|
||||
Tab@ first = inside;
|
||||
while(inside !is null) {
|
||||
inside.close();
|
||||
inside.remove();
|
||||
@inside = inside.previous;
|
||||
if(inside !is null && inside.parent is null)
|
||||
@inside = null;
|
||||
if(inside is first)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Refresh stuff
|
||||
tabBar.refresh();
|
||||
}
|
||||
|
||||
void browseTab(TabCategory inside, Tab@ to, bool remember = false, bool createNew = true) {
|
||||
Tab@ tab = findTab(inside);
|
||||
if(tab is null) {
|
||||
if(createNew) {
|
||||
newTab(to);
|
||||
switchToTab(to);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@tab = activeTab;
|
||||
}
|
||||
}
|
||||
|
||||
browseTab(tab, to, remember);
|
||||
switchToTab(to);
|
||||
}
|
||||
|
||||
void popTab(Tab@ top) {
|
||||
if(top.previous is null) {
|
||||
closeTab(top);
|
||||
return;
|
||||
}
|
||||
|
||||
//Set it in the list
|
||||
int index = tabs.find(top);
|
||||
if(index >= 0)
|
||||
@tabs[index] = top.previous;
|
||||
|
||||
//Do showing and hiding
|
||||
if(top is activeTab)
|
||||
switchToTab(top.previous);
|
||||
|
||||
//New tab knows where it came from
|
||||
top.close();
|
||||
top.remove();
|
||||
|
||||
//Refresh stuff
|
||||
tabBar.refresh();
|
||||
}
|
||||
|
||||
//Tab selection gui elements
|
||||
class GuiTabBar : BaseGuiElement {
|
||||
GuiTab@[] tabs;
|
||||
GuiButton@ homeButton;
|
||||
GuiButton@ goButton;
|
||||
GuiButton@ newButton;
|
||||
bool leftGo = false;
|
||||
|
||||
GuiTabBar() {
|
||||
super(null, Alignment(Left, Top, Right, Top+TAB_HEIGHT + 3));
|
||||
|
||||
@homeButton = GuiButton(this, recti(0, 0, 30, 19));
|
||||
homeButton.navigable = false;
|
||||
homeButton.style = SS_HomeIcon;
|
||||
homeButton.position = vec2i(3, 4);
|
||||
|
||||
@goButton = GuiButton(this, recti(0, 0, 30, 19));
|
||||
goButton.navigable = false;
|
||||
goButton.style = SS_GoIcon;
|
||||
goButton.position = vec2i(35, 4);
|
||||
|
||||
@newButton = GuiButton(this, recti(0, 0, 30 + BUTTON_NEW_WIDTH, 19));
|
||||
newButton.navigable = false;
|
||||
newButton.style = SS_GameTabNew;
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void updateAbsolutePosition() {
|
||||
int w = size.width;
|
||||
BaseGuiElement::updateAbsolutePosition();
|
||||
if(size.width != w)
|
||||
refresh();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
uint cnt = ::tabs.length;
|
||||
uint oldcnt = tabs.length;
|
||||
|
||||
//Remove old tabs
|
||||
for(uint i = cnt; i < oldcnt; ++i)
|
||||
tabs[i].remove();
|
||||
tabs.length = cnt;
|
||||
|
||||
//Create new tabs
|
||||
for(uint i = oldcnt; i < cnt; ++i) {
|
||||
@tabs[i] = GuiTab(this);
|
||||
tabs[i].sendToBack();
|
||||
}
|
||||
|
||||
//Refresh tabs
|
||||
int x = TAB_HOME_OFFSET;
|
||||
int cat = TC_Invalid;
|
||||
|
||||
//Calculate the total used spacing
|
||||
int totalSpacing = 0;
|
||||
cat = TC_Invalid;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
//Scrunch tabs in the same category
|
||||
int newCat = ::tabs[i].category;
|
||||
if(newCat == cat || ALWAYS_SCRUNCH_TABS)
|
||||
totalSpacing += TAB_SCRUNCH;
|
||||
else
|
||||
totalSpacing += TAB_SPACING;
|
||||
cat = newCat;
|
||||
}
|
||||
|
||||
//Fit the tab width
|
||||
int w = TAB_MAX_WIDTH;
|
||||
bool overflow = false;
|
||||
int avail = size.width - TAB_HOME_OFFSET - newButton.size.width - TAB_SPACING - 4;
|
||||
if(cnt * w + totalSpacing > avail) {
|
||||
w = max(TAB_MIN_WIDTH, (avail - totalSpacing) / cnt);
|
||||
overflow = true;
|
||||
}
|
||||
|
||||
//Position the actual tabs
|
||||
cat = TC_Invalid;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
//Scrunch tabs in the same category
|
||||
int newCat = ::tabs[i].category;
|
||||
if(newCat == cat || ALWAYS_SCRUNCH_TABS)
|
||||
x += TAB_SCRUNCH;
|
||||
else
|
||||
x += TAB_SPACING;
|
||||
cat = newCat;
|
||||
|
||||
//Position the tab
|
||||
tabs[i].setTab(::tabs[i]);
|
||||
tabs[i].position = vec2i(x, 0);
|
||||
tabs[i].size = vec2i(w, TAB_HEIGHT);
|
||||
x += w;
|
||||
}
|
||||
|
||||
//Set new button
|
||||
if(overflow)
|
||||
newButton.position = vec2i(size.width - newButton.size.width - 4, 4);
|
||||
else
|
||||
newButton.position = vec2i(x + TAB_SPACING, 4);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
if(event.type == MET_Button_Up) {
|
||||
if(event.button == 2) {
|
||||
switchToTab(newTab());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.caller is newButton) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
switchToTab(newTab());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.caller is homeButton) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
bool isHome = isHomeTab(activeTab);
|
||||
if(!isHome || activeTab.previous is null) {
|
||||
browseTab(activeTab, createHomeTab(), true);
|
||||
}
|
||||
else {
|
||||
popTab(activeTab);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.caller is goButton) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
if(leftGo)
|
||||
leftGo = false;
|
||||
else
|
||||
toggleGoDialog();
|
||||
return true;
|
||||
}
|
||||
else if(event.type == GUI_Focused) {
|
||||
if(event.other !is null && event.other.isChildOf(getGoDialog())) {
|
||||
leftGo = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(event.type == GUI_Focus_Lost) {
|
||||
leftGo = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
//Draw the tab bar background
|
||||
skin.draw(SS_GameTabBar, SF_Normal, AbsolutePosition);
|
||||
|
||||
//Draw build version
|
||||
//skin.getFont(FT_Normal).draw(pos=AbsolutePosition.padded(8, 0, 8, 3),
|
||||
// text=SCRIPT_VERSION, horizAlign=1.0, color=Color(0xaaaaaaff));
|
||||
|
||||
//Find the active tab to draw on top
|
||||
GuiTab@ active = null;
|
||||
GuiTab@ dragging = null;
|
||||
uint cnt = tabs.length;
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
if(tabs[i].Dragging) {
|
||||
@dragging = tabs[i];
|
||||
tabs[i].Visible = false;
|
||||
}
|
||||
else if(tabs[i].tab is activeTab) {
|
||||
@active = tabs[i];
|
||||
tabs[i].Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
BaseGuiElement::draw();
|
||||
|
||||
//Draw the separator lines
|
||||
drawRectangle(recti_area(
|
||||
AbsolutePosition.topLeft + vec2i(0,24),
|
||||
vec2i(size.width, 1)), Color(0x202020ff));
|
||||
|
||||
drawRectangle(recti_area(
|
||||
AbsolutePosition.topLeft + vec2i(0, 25),
|
||||
vec2i(size.width, 2)), activeTab.seperatorColor);
|
||||
|
||||
drawRectangle(recti_area(
|
||||
AbsolutePosition.topLeft + vec2i(0,27),
|
||||
vec2i(size.width, 1)), Color(0x202020ff));
|
||||
|
||||
//Draw the active tab
|
||||
if(active !is null) {
|
||||
active.Visible = true;
|
||||
active.draw();
|
||||
}
|
||||
|
||||
//Draw the dragging tab
|
||||
if(dragging !is null) {
|
||||
dragging.Visible = true;
|
||||
dragging.draw();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class GuiTab : BaseGuiElement {
|
||||
GuiTabBar@ bar;
|
||||
GuiButton@ closeButton;
|
||||
Tab@ tab;
|
||||
bool Hovered;
|
||||
bool Focused;
|
||||
bool Pressed;
|
||||
bool LeftHeld = false;
|
||||
bool Dragging;
|
||||
vec2i dragStart;
|
||||
|
||||
GuiTab(GuiTabBar@ Bar) {
|
||||
@bar = Bar;
|
||||
Hovered = false;
|
||||
Focused = false;
|
||||
Pressed = false;
|
||||
Dragging = false;
|
||||
|
||||
super(bar, recti_area(0, 0, TAB_MAX_WIDTH, TAB_HEIGHT));
|
||||
|
||||
vec2i size = skin.getSize(SS_GameTabClose, SF_Normal);
|
||||
@closeButton = GuiButton(this, recti());
|
||||
closeButton.navigable = false;
|
||||
closeButton.style = SS_GameTabClose;
|
||||
@closeButton.alignment = Alignment(Right-TAB_CLOSE_OFFSET.x-size.x, Top+TAB_CLOSE_OFFSET.y, Right-TAB_CLOSE_OFFSET.x, Top+TAB_CLOSE_OFFSET.y+size.y);
|
||||
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void setTab(Tab@ forTab) {
|
||||
if(tab is forTab)
|
||||
return;
|
||||
@tab = forTab;
|
||||
}
|
||||
|
||||
bool onGuiEvent(const GuiEvent& event) {
|
||||
if(event.caller is closeButton) {
|
||||
if(event.type == GUI_Clicked) {
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.caller is this) {
|
||||
switch(event.type) {
|
||||
case GUI_Mouse_Entered:
|
||||
Hovered = true;
|
||||
break;
|
||||
case GUI_Mouse_Left:
|
||||
Hovered = false;
|
||||
Pressed = false;
|
||||
LeftHeld = false;
|
||||
break;
|
||||
case GUI_Focused:
|
||||
Focused = true;
|
||||
return false;
|
||||
case GUI_Focus_Lost:
|
||||
Focused = false;
|
||||
Pressed = false;
|
||||
LeftHeld = false;
|
||||
Dragging = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onGuiEvent(event);
|
||||
}
|
||||
|
||||
void click() {
|
||||
switchToTab(tab);
|
||||
}
|
||||
|
||||
void close() {
|
||||
closeTab(tab);
|
||||
}
|
||||
|
||||
bool onMouseEvent(const MouseEvent& event, IGuiElement@ source) {
|
||||
if(source is this) {
|
||||
switch(event.type) {
|
||||
case MET_Moved: {
|
||||
vec2i mouse(event.x, event.y);
|
||||
if(Dragging) {
|
||||
if(!mouseLeft) {
|
||||
Dragging = false;
|
||||
LeftHeld = false;
|
||||
return true;
|
||||
}
|
||||
if(mouse.x < AbsolutePosition.topLeft.x - 5) {
|
||||
int index = tabs.find(tab);
|
||||
if(index > 0) {
|
||||
@tabs[index] = tabs[index - 1];
|
||||
@tabs[index - 1] = tab;
|
||||
@bar.tabs[index] = bar.tabs[index - 1];
|
||||
@bar.tabs[index - 1] = this;
|
||||
swap(bar.tabs[index]);
|
||||
bar.refresh();
|
||||
}
|
||||
}
|
||||
else if(mouse.x > AbsolutePosition.botRight.x + 5) {
|
||||
int index = tabs.find(tab);
|
||||
if(index < int(tabs.length - 1)) {
|
||||
@tabs[index] = tabs[index + 1];
|
||||
@tabs[index + 1] = tab;
|
||||
@bar.tabs[index] = bar.tabs[index + 1];
|
||||
@bar.tabs[index + 1] = this;
|
||||
swap(bar.tabs[index]);
|
||||
bar.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Pressed && LeftHeld) {
|
||||
if(abs(dragStart.x - mouse.x) > 5 || abs(dragStart.y - mouse.y) > 5) {
|
||||
Pressed = false;
|
||||
Dragging = true;
|
||||
closeButton.visible = false;
|
||||
dragStart = dragStart - AbsolutePosition.topLeft;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MET_Button_Down:
|
||||
Pressed = true;
|
||||
if(event.button == 0) {
|
||||
dragStart = mousePos;
|
||||
LeftHeld = true;
|
||||
}
|
||||
return true;
|
||||
case MET_Button_Up:
|
||||
if(Dragging) {
|
||||
if(event.button == 0) {
|
||||
Dragging = false;
|
||||
LeftHeld = false;
|
||||
closeButton.visible = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(Pressed) {
|
||||
if(Hovered) {
|
||||
if(event.button == 2) {
|
||||
close();
|
||||
}
|
||||
else if(event.button == 0) {
|
||||
if(Hovered)
|
||||
click();
|
||||
}
|
||||
}
|
||||
Pressed = false;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BaseGuiElement::onMouseEvent(event, source);
|
||||
}
|
||||
|
||||
void draw(const recti& pos) {
|
||||
Color color(0xffffffff);
|
||||
|
||||
uint flags = SF_Normal;
|
||||
if(Pressed)
|
||||
flags |= SF_Pressed;
|
||||
if(Hovered)
|
||||
flags |= SF_Hovered;
|
||||
if(Focused)
|
||||
flags |= SF_Focused;
|
||||
|
||||
if(tab is activeTab) {
|
||||
flags |= SF_Active;
|
||||
color = tab.activeColor;
|
||||
}
|
||||
else {
|
||||
color = tab.inactiveColor;
|
||||
}
|
||||
|
||||
const Font@ fnt = skin.getFont(FT_Normal);
|
||||
|
||||
//Do flashing
|
||||
if(tab.flashing) {
|
||||
double cycleTime = frameTime % TAB_FLASH_PERIOD;
|
||||
float pct = 0.f;
|
||||
|
||||
if(cycleTime < TAB_FLASH_PERIOD * 0.5)
|
||||
pct = (cycleTime / (0.5 * TAB_FLASH_PERIOD));
|
||||
else
|
||||
pct = 1.0 - ((cycleTime - (0.5 * TAB_FLASH_PERIOD)) * 2.0);
|
||||
|
||||
color = color.interpolate(TAB_FLASH_COLOR, pct);
|
||||
}
|
||||
|
||||
//Tab background
|
||||
skin.draw(SS_GameTab, flags, pos, color);
|
||||
|
||||
//Category icon
|
||||
tab.icon.draw(recti_area(
|
||||
pos.topLeft + TAB_ICON_OFFSET,
|
||||
TAB_ICON_SIZE));
|
||||
|
||||
//Title text
|
||||
fnt.draw(recti_area(
|
||||
pos.topLeft + TAB_TEXT_OFFSET,
|
||||
vec2i(size.width - TAB_CLOSE_OFFSET.x - TAB_PADDING.x - TAB_TEXT_OFFSET.x,
|
||||
size.height - TAB_PADDING.y - TAB_TEXT_OFFSET.y)), tab.title, ellipsis);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
closeButton.visible = !tab.locked;
|
||||
if(Dragging) {
|
||||
clearClip();
|
||||
int maxPos = bar.tabs[bar.tabs.length - 1].AbsolutePosition.topLeft.x;
|
||||
int pos = clamp(mousePos.x - dragStart.x, TAB_HOME_OFFSET, maxPos);
|
||||
|
||||
draw(recti_area( vec2i(pos, AbsolutePosition.topLeft.y), size));
|
||||
}
|
||||
else {
|
||||
draw(AbsolutePosition);
|
||||
BaseGuiElement::draw();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Tab internal management
|
||||
void tab_next(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(1);
|
||||
}
|
||||
|
||||
void tab_previous(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(-1);
|
||||
}
|
||||
|
||||
void tab_new(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(newTab());
|
||||
}
|
||||
|
||||
void tab_close(bool pressed) {
|
||||
if(pressed)
|
||||
closeTab();
|
||||
}
|
||||
|
||||
void tab_reopen(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(reopenTab());
|
||||
}
|
||||
|
||||
void tab_1(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[0]);
|
||||
}
|
||||
|
||||
void tab_2(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[1 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_3(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[2 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_4(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[3 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_5(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[4 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_6(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[5 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_7(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[6 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_8(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[7 % tabs.length]);
|
||||
}
|
||||
|
||||
void tab_9(bool pressed) {
|
||||
if(pressed)
|
||||
switchToTab(tabs[8 % tabs.length]);
|
||||
}
|
||||
|
||||
bool tabEscape() {
|
||||
if(!settings::bEscapeGalaxyTab)
|
||||
return false;
|
||||
if(ActiveTab.category == TC_Galaxy)
|
||||
return false;
|
||||
auto@ otherTab = findTab(TC_Galaxy);
|
||||
if(otherTab is null)
|
||||
return false;
|
||||
switchToTab(otherTab);
|
||||
return true;
|
||||
}
|
||||
|
||||
void init() {
|
||||
//Create the tabbar
|
||||
@tabBar = GuiTabBar();
|
||||
|
||||
//Create the global bar
|
||||
@globalBar = createGlobalBar();
|
||||
@globalBar.alignment = Alignment(Left, Top+TAB_HEIGHT + 2, Right, Top+TAB_HEIGHT + 2 + GLOBAL_BAR_HEIGHT);
|
||||
|
||||
//Create initial galaxy view
|
||||
auto defaultTab = createGalaxyTab(playerEmpire);
|
||||
newTab(defaultTab);
|
||||
switchToTab(defaultTab);
|
||||
|
||||
newTab(createDiplomacyTab());
|
||||
if(hasDLC("Heralds"))
|
||||
newTab(createAttitudesTab());
|
||||
newTab(createResearchTab());
|
||||
newTab(createDesignOverviewTab());
|
||||
newTab(createPlanetsTab());
|
||||
newTab(createCommunityHome());
|
||||
|
||||
//Bind keybinds
|
||||
keybinds::Global.addBind(KB_TAB_NEW, "tab_new");
|
||||
keybinds::Global.addBind(KB_TAB_CLOSE, "tab_close");
|
||||
keybinds::Global.addBind(KB_TAB_REOPEN, "tab_reopen");
|
||||
keybinds::Global.addBind(KB_TAB_NEXT, "tab_next");
|
||||
keybinds::Global.addBind(KB_TAB_PREVIOUS, "tab_previous");
|
||||
|
||||
keybinds::Global.addBind(KB_TAB_1, "tab_1");
|
||||
keybinds::Global.addBind(KB_TAB_2, "tab_2");
|
||||
keybinds::Global.addBind(KB_TAB_3, "tab_3");
|
||||
keybinds::Global.addBind(KB_TAB_4, "tab_4");
|
||||
keybinds::Global.addBind(KB_TAB_5, "tab_5");
|
||||
keybinds::Global.addBind(KB_TAB_6, "tab_6");
|
||||
keybinds::Global.addBind(KB_TAB_7, "tab_7");
|
||||
keybinds::Global.addBind(KB_TAB_8, "tab_8");
|
||||
keybinds::Global.addBind(KB_TAB_9, "tab_9");
|
||||
}
|
||||
|
||||
void preReload(Message& msg) {
|
||||
tabBar.remove();
|
||||
globalBar.remove();
|
||||
}
|
||||
|
||||
void postReload(Message& msg) {
|
||||
init();
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
for(uint i = 0, cnt = tabs.length; i < cnt; ++i)
|
||||
tabs[i].tick(time);
|
||||
}
|
||||
|
||||
const Shader@ getFullscreenShader() {
|
||||
if(settings::bBloom || settings::bChromaticAberration || settings::bFilmGrain || settings::bGodRays || settings::bVignette)
|
||||
return shader::FullscreenPostProcess;
|
||||
return null;
|
||||
}
|
||||
|
||||
//Render last view for menu if requested
|
||||
void preRender(double time) {
|
||||
if(game_state == GS_Menu) {
|
||||
@fullscreenShader = shader::MenuRender;
|
||||
|
||||
lastCamera.camera.animate(time);
|
||||
updateRenderCamera(lastCamera.camera);
|
||||
}
|
||||
else {
|
||||
@fullscreenShader = getFullscreenShader();
|
||||
activeTab.preRender(time);
|
||||
}
|
||||
}
|
||||
|
||||
void render(double time) {
|
||||
if(game_state == GS_Menu) {
|
||||
prepareRender(lastCamera.camera);
|
||||
renderWorld();
|
||||
}
|
||||
else {
|
||||
activeTab.render(time);
|
||||
}
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
@fullscreenShader = null;
|
||||
}
|
||||
|
||||
void save(SaveFile& file) {
|
||||
uint cnt = tabs.length;
|
||||
uint mainTab = 0;
|
||||
file << cnt;
|
||||
for(uint i = 0, cnt = tabs.length; i < cnt; ++i) {
|
||||
uint cat = tabs[i].category;
|
||||
file << cat;
|
||||
tabs[i].save(file);
|
||||
if(tabs[i] is activeTab)
|
||||
mainTab = i;
|
||||
}
|
||||
file << mainTab;
|
||||
}
|
||||
|
||||
void load(SaveFile& file) {
|
||||
uint cnt = 0;
|
||||
file >> cnt;
|
||||
|
||||
for(uint i = 0, cnt = tabs.length; i < cnt; ++i)
|
||||
tabs[i].close();
|
||||
tabs.length = 0;
|
||||
|
||||
for(uint i = 0; i < cnt; ++i) {
|
||||
Tab@ t;
|
||||
uint cat = 0;
|
||||
file >> cat;
|
||||
|
||||
switch(cat) {
|
||||
case TC_Galaxy: @t = createGalaxyTab(); break;
|
||||
case TC_Designs: @t = createDesignOverviewTab(); break;
|
||||
case TC_Home: @t = createHomeTab(); break;
|
||||
case TC_Research: @t = createResearchTab(); break;
|
||||
case TC_Planets: @t = createPlanetsTab(); break;
|
||||
case TC_Diplomacy: @t = createDiplomacyTab(); break;
|
||||
case TC_Wiki: @t = createCommunityHome(); break;
|
||||
case TC_Attitudes: @t = createAttitudesTab(); break;
|
||||
}
|
||||
|
||||
if(t !is null) {
|
||||
t.load(file);
|
||||
newTab(t);
|
||||
}
|
||||
}
|
||||
|
||||
uint mainTab = 0;
|
||||
file >> mainTab;
|
||||
switchToTab(tabs[mainTab]);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import resources;
|
||||
import ftl;
|
||||
from obj_selection import selectedObject, selectedObjects, getSelectionPosition, getSelectionScale;
|
||||
import targeting.PointTarget;
|
||||
import targeting.targeting;
|
||||
from targeting.MoveTarget import getFleetTargetPositions;
|
||||
|
||||
class FlingTarget : PointTarget {
|
||||
double cost = 0.0;
|
||||
int scale = 1;
|
||||
Object@ obj;
|
||||
Object@ beacon;
|
||||
array<Object@> objs;
|
||||
bool inRange = false;
|
||||
|
||||
FlingTarget(Object@ beacon, Object@ obj, int totalScale, bool InRange) {
|
||||
@this.obj = obj;
|
||||
@this.beacon = beacon;
|
||||
scale = totalScale;
|
||||
inRange = InRange;
|
||||
objs = selectedObjects;
|
||||
}
|
||||
|
||||
vec3d get_origin() override {
|
||||
if(shiftKey) {
|
||||
Object@ obj = selectedObject;
|
||||
return obj.finalMoveDestination;
|
||||
}
|
||||
else {
|
||||
return getSelectionPosition(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mpos) override {
|
||||
PointTarget::hover(mpos);
|
||||
if(selectedObjects.length > 1) {
|
||||
auto@ positions = getFleetTargetPositions(objs, hovered, isFTL=true);
|
||||
cost = 0;
|
||||
for(uint i = 0, cnt = objs.length; i < cnt; ++i)
|
||||
cost += flingCost(objs[i], positions[i]);
|
||||
range = cost > playerEmpire.FTLStored ? 0.0 : INFINITY;
|
||||
}
|
||||
else {
|
||||
range = flingRange(obj);
|
||||
cost = flingCost(obj, hovered);
|
||||
}
|
||||
if(shiftKey)
|
||||
return canFlingTo(obj, hovered);
|
||||
if(beacon is null || !inRange)
|
||||
return false;
|
||||
return canFlingTo(obj, hovered) && distance <= range;
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
return shiftKey || (beacon !is null && inRange && distance <= range);
|
||||
}
|
||||
};
|
||||
|
||||
class FlingDisplay : PointDisplay {
|
||||
PlaneNode@ range;
|
||||
|
||||
~FlingDisplay() {
|
||||
if(range !is null) {
|
||||
range.visible = false;
|
||||
range.markForDeletion();
|
||||
@range = null;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(TargetMode@ mode) override {
|
||||
PointDisplay::draw(mode);
|
||||
|
||||
FlingTarget@ ht = cast<FlingTarget>(mode);
|
||||
if(ht is null)
|
||||
return;
|
||||
|
||||
if(range is null && ht.beacon !is null) {
|
||||
@range = PlaneNode(material::RangeCircle, FLING_BEACON_RANGE);
|
||||
range.visible = false;
|
||||
range.position = ht.beacon.node_position;
|
||||
range.rebuildTransform();
|
||||
range.color = Color(0x2bff0cff);
|
||||
range.visible = true;
|
||||
}
|
||||
|
||||
Color color;
|
||||
if(ht.distance <= ht.range && ht.inRange && ht.valid)
|
||||
color = Color(0x00ff00ff);
|
||||
else
|
||||
color = Color(0xff0000ff);
|
||||
|
||||
font::DroidSans_11_Bold.draw(mousePos + vec2i(16, 0),
|
||||
toString(int(ht.cost)) + " " + locale::FTL
|
||||
+ " (" + toString(ht.distance, 0) + "u)",
|
||||
color);
|
||||
|
||||
if(ht.beacon is null) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::NEED_FLING_BEACON,
|
||||
color);
|
||||
}
|
||||
else if(!ht.inRange) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::OUT_OF_BEACON_RANGE,
|
||||
color);
|
||||
}
|
||||
else if(ht.distance > ht.range) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::INSUFFICIENT_FTL,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
inColor = Color(0x00c0ffff);
|
||||
if(shiftKey)
|
||||
outColor = Color(0xffe400ff);
|
||||
else
|
||||
outColor = colors::Red;
|
||||
FlingTarget@ ht = cast<FlingTarget>(mode);
|
||||
if(ht !is null && range !is null && ht.beacon !is null) {
|
||||
range.position = ht.beacon.node_position;
|
||||
range.rebuildTransform();
|
||||
}
|
||||
PointDisplay::render(mode);
|
||||
}
|
||||
};
|
||||
|
||||
class FlingCB : TargetCallback {
|
||||
Object@ beacon;
|
||||
|
||||
FlingCB(Object@ beacon) {
|
||||
@this.beacon = beacon;
|
||||
}
|
||||
|
||||
void call(TargetMode@ mode) override {
|
||||
if(beacon is null)
|
||||
return;
|
||||
|
||||
bool anyFlung = false;
|
||||
Object@[] selection = selectedObjects;
|
||||
auto@ positions = getFleetTargetPositions(selection, mode.position, isFTL=true);
|
||||
for(uint i = 0, cnt = selection.length; i < cnt; ++i) {
|
||||
Object@ obj = selection[i];
|
||||
if(!obj.hasMover || !obj.hasLeaderAI || !canFling(obj))
|
||||
continue;
|
||||
obj.addFlingOrder(beacon, positions[i], shiftKey || obj.inFTL);
|
||||
anyFlung = true;
|
||||
}
|
||||
|
||||
if(anyFlung)
|
||||
sound::order_fling.play(priority=true);
|
||||
}
|
||||
};
|
||||
|
||||
void targetFling() {
|
||||
Object@ sel = selectedObject;
|
||||
if(sel.owner is null || !sel.owner.valid)
|
||||
return;
|
||||
|
||||
Object@ beacon = sel.owner.getClosestFlingBeacon(sel);
|
||||
|
||||
FlingTarget targ(beacon, selectedObject, max(getSelectionScale(), 1),
|
||||
beacon !is null && beacon.position.distanceToSQ(sel.position) <= FLING_BEACON_RANGE_SQ);
|
||||
FlingDisplay disp;
|
||||
FlingCB cb(beacon);
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import resources;
|
||||
import ftl;
|
||||
from obj_selection import selectedObject, selectedObjects, getSelectionPosition, getSelectionScale;
|
||||
import targeting.PointTarget;
|
||||
import targeting.targeting;
|
||||
from targeting.MoveTarget import getFleetTargetPositions;
|
||||
|
||||
class HyperdriveTarget : PointTarget {
|
||||
double cost = 0.0;
|
||||
Object@ obj;
|
||||
array<vec3d>@ offsets;
|
||||
array<Object@> objs;
|
||||
|
||||
HyperdriveTarget(Object@ Obj) {
|
||||
@obj = Obj;
|
||||
objs = selectedObjects;
|
||||
}
|
||||
|
||||
vec3d get_origin() override {
|
||||
if(shiftKey) {
|
||||
Object@ obj = selectedObject;
|
||||
if(obj is null)
|
||||
return vec3d();
|
||||
return obj.finalMoveDestination;
|
||||
}
|
||||
else {
|
||||
return getSelectionPosition(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mpos) override {
|
||||
PointTarget::hover(mpos);
|
||||
|
||||
//if(selectedObjects.length > 1) {
|
||||
auto@ positions = getFleetTargetPositions(objs, hovered);
|
||||
cost = 0;
|
||||
for(uint i = 0, cnt = objs.length; i < cnt; ++i)
|
||||
cost += hyperdriveCost(objs[i], positions[i]);
|
||||
range = cost > playerEmpire.FTLStored ? 0.0 : INFINITY;
|
||||
//}
|
||||
//else {
|
||||
// range = hyperdriveRange(obj);
|
||||
// cost = hyperdriveCost(obj, hovered);
|
||||
//}
|
||||
return canHyperdriveTo(obj, hovered) && (distance <= range || shiftKey);
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
return distance <= range || shiftKey;
|
||||
}
|
||||
};
|
||||
|
||||
class HyperdriveDisplay : PointDisplay {
|
||||
void draw(TargetMode@ mode) override {
|
||||
PointDisplay::draw(mode);
|
||||
|
||||
HyperdriveTarget@ ht = cast<HyperdriveTarget>(mode);
|
||||
if(ht is null)
|
||||
return;
|
||||
|
||||
Color color;
|
||||
if(ht.distance <= ht.range && ht.valid)
|
||||
color = Color(0x00ff00ff);
|
||||
else
|
||||
color = Color(0xff0000ff);
|
||||
|
||||
font::DroidSans_11_Bold.draw(mousePos + vec2i(16, 0),
|
||||
toString(int(ht.cost)) + " " + locale::FTL
|
||||
+ " (" + toString(ht.distance, 0) + "u)",
|
||||
color);
|
||||
|
||||
if(ht.distance > ht.range) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::INSUFFICIENT_FTL,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
inColor = Color(0x00c0ffff);
|
||||
if(shiftKey)
|
||||
outColor = Color(0xffe400ff);
|
||||
else
|
||||
outColor = colors::Red;
|
||||
PointDisplay::render(mode);
|
||||
}
|
||||
};
|
||||
|
||||
class HyperdriveCB : TargetCallback {
|
||||
void call(TargetMode@ mode) override {
|
||||
bool anyDidFTL = false;
|
||||
Object@[] selection = selectedObjects;
|
||||
auto@ positions = getFleetTargetPositions(selection, mode.position);
|
||||
for(uint i = 0, cnt = selection.length; i < cnt; ++i) {
|
||||
Object@ obj = selection[i];
|
||||
if(!obj.hasMover || !obj.hasLeaderAI || !canHyperdrive(obj))
|
||||
continue;
|
||||
anyDidFTL = true;
|
||||
obj.addHyperdriveOrder(positions[i], shiftKey || obj.inFTL);
|
||||
}
|
||||
|
||||
if(anyDidFTL)
|
||||
sound::order_hyperdrive.play(priority=true);
|
||||
|
||||
if(shiftKey) {
|
||||
HyperdriveTarget targ(selectedObject);
|
||||
targ.isShifted = true;
|
||||
HyperdriveDisplay disp;
|
||||
HyperdriveCB cb;
|
||||
startTargeting(targ, disp, cb);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void targetHyperdrive() {
|
||||
HyperdriveTarget targ(selectedObject);
|
||||
HyperdriveDisplay disp;
|
||||
HyperdriveCB cb;
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import resources;
|
||||
import ftl;
|
||||
from obj_selection import selectedObject, selectedObjects, getSelectionPosition, getSelectionScale;
|
||||
import targeting.PointTarget;
|
||||
import targeting.targeting;
|
||||
from targeting.MoveTarget import getFleetTargetPositions;
|
||||
import system_flags;
|
||||
|
||||
class JumpdriveTarget : PointTarget {
|
||||
double cost = 0.0;
|
||||
Object@ obj;
|
||||
array<Object@> objs;
|
||||
|
||||
JumpdriveTarget(Object@ obj) {
|
||||
@this.obj = obj;
|
||||
objs = selectedObjects;
|
||||
range = INFINITY;
|
||||
}
|
||||
|
||||
vec3d get_origin() override {
|
||||
if(shiftKey) {
|
||||
Object@ obj = selectedObject;
|
||||
return obj.finalMoveDestination;
|
||||
}
|
||||
else {
|
||||
return getSelectionPosition(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mpos) override {
|
||||
if(selectedObjects.length > 1) {
|
||||
auto@ positions = getFleetTargetPositions(objs, hovered, isFTL=true);
|
||||
cost = 0;
|
||||
for(uint i = 0, cnt = objs.length; i < cnt; ++i)
|
||||
cost += jumpdriveCost(objs[i], positions[i]);
|
||||
}
|
||||
else {
|
||||
cost = jumpdriveCost(obj, hovered);
|
||||
}
|
||||
if(cost <= playerEmpire.FTLStored)
|
||||
range = INFINITY;
|
||||
else
|
||||
range = 0;
|
||||
PointTarget::hover(mpos);
|
||||
return canFlingTo(obj, hovered);
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class JumpdriveDisplay : PointDisplay {
|
||||
PlaneNode@ range;
|
||||
double jumpRange;
|
||||
|
||||
~JumpdriveDisplay() {
|
||||
if(range !is null) {
|
||||
range.visible = false;
|
||||
range.markForDeletion();
|
||||
@range = null;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(TargetMode@ mode) override {
|
||||
PointDisplay::draw(mode);
|
||||
|
||||
JumpdriveTarget@ ht = cast<JumpdriveTarget>(mode);
|
||||
if(ht is null)
|
||||
return;
|
||||
|
||||
if(range is null) {
|
||||
jumpRange = cast<Ship>(ht.obj).blueprint.getEfficiencySum(SV_JumpRange);
|
||||
@range = PlaneNode(material::RangeCircle, jumpRange);
|
||||
range.visible = false;
|
||||
range.position = ht.obj.node_position;
|
||||
range.rebuildTransform();
|
||||
range.color = Color(0xff2b0cff);
|
||||
range.visible = true;
|
||||
}
|
||||
|
||||
bool isSafe = false;
|
||||
Region@ reg = getRegion(ht.hovered);
|
||||
if(reg !is null)
|
||||
isSafe = reg.getSystemFlag(playerEmpire, safetyFlag);
|
||||
|
||||
Color color;
|
||||
if(!ht.valid || ht.cost > playerEmpire.FTLStored)
|
||||
color = Color(0xff0000ff);
|
||||
else if(ht.distance >= jumpRange && !isSafe)
|
||||
color = Color(0xff8000ff);
|
||||
else
|
||||
color = Color(0x00ff00ff);
|
||||
|
||||
font::DroidSans_11_Bold.draw(mousePos + vec2i(16, 0),
|
||||
toString(int(ht.cost)) + " " + locale::FTL
|
||||
+ " (" + toString(ht.distance, 0) + "u)",
|
||||
color);
|
||||
|
||||
if(ht.cost > playerEmpire.FTLStored) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::INSUFFICIENT_FTL,
|
||||
color);
|
||||
}
|
||||
else if(ht.distance >= jumpRange && !isSafe) {
|
||||
if(ht.distance >= jumpRange * 2.0) {
|
||||
font::DroidSans_11_Bold.draw(mousePos + vec2i(16, 16),
|
||||
locale::JUMPDRIVE_SAFETY_WARNING_SEVERE,
|
||||
Color(0xff0000ff));
|
||||
}
|
||||
else {
|
||||
font::DroidSans_11.draw(mousePos + vec2i(16, 16),
|
||||
locale::JUMPDRIVE_SAFETY_WARNING,
|
||||
Color(0xff0000ff));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
JumpdriveTarget@ ht = cast<JumpdriveTarget>(mode);
|
||||
if(ht !is null && range !is null) {
|
||||
range.position = ht.obj.node_position;
|
||||
range.rebuildTransform();
|
||||
}
|
||||
PointDisplay::render(mode);
|
||||
}
|
||||
};
|
||||
|
||||
class JumpdriveCB : TargetCallback {
|
||||
void call(TargetMode@ mode) override {
|
||||
bool anyFTL = false;
|
||||
Object@[] selection = selectedObjects;
|
||||
auto@ positions = getFleetTargetPositions(selection, mode.position, isFTL=true);
|
||||
for(uint i = 0, cnt = selection.length; i < cnt; ++i) {
|
||||
Object@ obj = selection[i];
|
||||
if(!obj.hasMover || !obj.hasLeaderAI || !canJumpdrive(obj))
|
||||
continue;
|
||||
obj.addJumpdriveOrder(positions[i], shiftKey || obj.inFTL);
|
||||
anyFTL = true;
|
||||
}
|
||||
|
||||
if(anyFTL)
|
||||
sound::order_fling.play(priority=true);
|
||||
}
|
||||
};
|
||||
|
||||
void targetJumpdrive() {
|
||||
Object@ sel = selectedObject;
|
||||
if(sel.owner is null || !sel.owner.valid)
|
||||
return;
|
||||
if(!selectedObject.isShip)
|
||||
return;
|
||||
|
||||
JumpdriveTarget targ(selectedObject);
|
||||
JumpdriveDisplay disp;
|
||||
JumpdriveCB cb;
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
}
|
||||
|
||||
int safetyFlag = -1;
|
||||
void init() {
|
||||
safetyFlag = getSystemFlag("JumpdriveSafety");
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
import targeting.targeting;
|
||||
from obj_selection import selectedObjects, getSelectionPosition, selectedObject;
|
||||
from navigation.elevation import getElevationIntersect;
|
||||
import targeting.PointTarget;
|
||||
import movement;
|
||||
import ftl;
|
||||
|
||||
enum MoveMode {
|
||||
MM_Normal,
|
||||
MM_Facing,
|
||||
MM_Height,
|
||||
};
|
||||
|
||||
const double VECTOR_DELAY = 0.2;
|
||||
const double VECTOR_PROGRESS_DELAY = 0.1;
|
||||
const int VECTOR_RADIAL_SIZE = 24;
|
||||
const int FACING_LENGTH = 200;
|
||||
const Color VECTOR_RADIAL_COLOR(0x39a086aa);
|
||||
|
||||
class MoveTarget : PointTarget {
|
||||
MoveMode mode = MM_Normal;
|
||||
vec3d destination;
|
||||
bool hasFacing = false;
|
||||
bool hasHeight = false;
|
||||
double origHeight = 0;
|
||||
vec3d facingDestination;
|
||||
vec2i startAt = mousePos;
|
||||
vec2i dragPos = startAt;
|
||||
double startTime = frameTime;
|
||||
|
||||
vec3d get_origin() {
|
||||
if(shiftKey) {
|
||||
Object@ obj = selectedObject;
|
||||
return obj.finalMoveDestination;
|
||||
}
|
||||
else {
|
||||
return getSelectionPosition(true);
|
||||
}
|
||||
}
|
||||
|
||||
quaterniond get_facing() {
|
||||
return quaterniond_fromVecToVec(vec3d_front(), facingDestination - destination);
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mpos) override {
|
||||
if(mode == MM_Facing || mode == MM_Height)
|
||||
return true;
|
||||
PointTarget::hover(mpos);
|
||||
destination = hovered;
|
||||
|
||||
//Keep height if in the same region
|
||||
if(!ctrlKey) {
|
||||
vec3d orig = origin;
|
||||
Region@ targRegion = getRegion(destination);
|
||||
Region@ curRegion = getRegion(orig);
|
||||
|
||||
if(curRegion !is null && targRegion is curRegion) {
|
||||
double hdiff = orig.y - curRegion.position.y;
|
||||
|
||||
line3dd ray = activeCamera.screenToRay(mpos);
|
||||
ray.start.y -= hdiff;
|
||||
ray.end.y -= hdiff;
|
||||
|
||||
if(getElevationIntersect(ray, destination))
|
||||
destination.y += hdiff;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool onMouseButton(int button, bool pressed) override {
|
||||
if(!pressed) {
|
||||
if(button == 0) {
|
||||
mode = MM_Height;
|
||||
if(!hasHeight)
|
||||
origHeight = destination.y;
|
||||
return true;
|
||||
}
|
||||
else if(button == 1) {
|
||||
targetingClick();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(button == 0) {
|
||||
mode = MM_Facing;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseDragged(int buttons, int x, int y, int dx, int dy) override {
|
||||
if(buttons == 0x2) {
|
||||
dragPos.x += dx;
|
||||
dragPos.y -= dy;
|
||||
|
||||
if(mode == MM_Normal) {
|
||||
double curTime = frameTime;
|
||||
if(curTime - startTime > VECTOR_DELAY) {
|
||||
mode = MM_Height;
|
||||
if(!hasHeight)
|
||||
origHeight = destination.y;
|
||||
}
|
||||
else if(dragPos.distanceTo(startAt) < 4)
|
||||
return true;
|
||||
}
|
||||
if(mode == MM_Height) {
|
||||
double delta = double(dy) * 0.5;
|
||||
destination.y += delta;
|
||||
hasHeight = true;
|
||||
if(hasFacing)
|
||||
facingDestination.y += delta;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(buttons == 0x3) {
|
||||
dragPos.x += dx;
|
||||
dragPos.y -= dy;
|
||||
|
||||
if(mode == MM_Facing) {
|
||||
if(dragPos.distanceTo(startAt) > FACING_LENGTH)
|
||||
dragPos = startAt + (dragPos - startAt).normalize(FACING_LENGTH);
|
||||
PointTarget::hover(dragPos);
|
||||
facingDestination = hovered;
|
||||
facingDestination.y = destination.y;
|
||||
hasFacing = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cancelTargeting();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseDragEnd(int buttons) override {
|
||||
if(mode == MM_Height) {
|
||||
targetingClick();
|
||||
return true;
|
||||
}
|
||||
else if(mode == MM_Facing) {
|
||||
mode = MM_Height;
|
||||
return true;
|
||||
}
|
||||
cancelTargeting();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
if(playerEmpire.ForbidDeepSpace != 0) {
|
||||
if(getRegion(destination) is null) {
|
||||
cancelTargeting();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vec3d get_position() override {
|
||||
return destination;
|
||||
}
|
||||
};
|
||||
|
||||
class MoveVisuals : TargetVisuals {
|
||||
BeamNode@ moveBeam;
|
||||
BeamNode@ facingBeam;
|
||||
BeamNode@ heightBeam;
|
||||
BeamNode@ lengthBeam;
|
||||
BeamNode@ destHeightBeam;
|
||||
|
||||
MoveVisuals() {
|
||||
@moveBeam = BeamNode(material::MoveBeam, 0.001f, vec3d(), vec3d(), true);
|
||||
moveBeam.color = Color(0x00ff00ff);
|
||||
moveBeam.visible = false;
|
||||
|
||||
@facingBeam = BeamNode(material::MoveBeam, 0.001f, vec3d(), vec3d(), true);
|
||||
facingBeam.color = Color(0x00adffff);
|
||||
facingBeam.visible = false;
|
||||
|
||||
@heightBeam = BeamNode(material::MoveBeam, 0.001f, vec3d(), vec3d(), true);
|
||||
heightBeam.color = Color(0xaaaaaaff);
|
||||
heightBeam.visible = false;
|
||||
|
||||
@destHeightBeam = BeamNode(material::MoveBeam, 0.001f, vec3d(), vec3d(), true);
|
||||
destHeightBeam.color = Color(0xaaaaaaff);
|
||||
destHeightBeam.visible = false;
|
||||
|
||||
@lengthBeam = BeamNode(material::MoveBeam, 0.001f, vec3d(), vec3d(), true);
|
||||
lengthBeam.color = Color(0xaaaaaaff);
|
||||
lengthBeam.visible = false;
|
||||
}
|
||||
|
||||
~MoveVisuals() {
|
||||
moveBeam.markForDeletion();
|
||||
facingBeam.markForDeletion();
|
||||
heightBeam.markForDeletion();
|
||||
destHeightBeam.markForDeletion();
|
||||
lengthBeam.markForDeletion();
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
MoveTarget@ mt = cast<MoveTarget>(mode);
|
||||
if(mt is null)
|
||||
return;
|
||||
|
||||
vec3d dest = mt.destination;
|
||||
vec3d origin = mt.origin;
|
||||
if(mt.hasHeight) {
|
||||
double origHeight = mt.origHeight;
|
||||
vec3d flatDest = dest;
|
||||
flatDest.y = origHeight;
|
||||
|
||||
vec3d flatOrigin = origin;
|
||||
flatOrigin.y = origHeight;
|
||||
|
||||
heightBeam.visible = true;
|
||||
heightBeam.abs_position = flatDest;
|
||||
heightBeam.endPosition = dest;
|
||||
|
||||
lengthBeam.visible = true;
|
||||
lengthBeam.abs_position = flatOrigin;
|
||||
lengthBeam.endPosition = flatDest;
|
||||
}
|
||||
if(mt.mode != MM_Normal || frameTime - mt.startTime > VECTOR_DELAY) {
|
||||
moveBeam.visible = true;
|
||||
moveBeam.abs_position = origin;
|
||||
moveBeam.endPosition = dest;
|
||||
}
|
||||
if(mt.hasFacing) {
|
||||
vec3d facing = mt.facingDestination;
|
||||
facingBeam.visible = true;
|
||||
facingBeam.abs_position = dest;
|
||||
facingBeam.endPosition = facing;
|
||||
|
||||
if(mt.hasHeight) {
|
||||
vec3d flatFacing = facing;
|
||||
flatFacing.y = mt.origHeight;
|
||||
|
||||
destHeightBeam.visible = true;
|
||||
destHeightBeam.abs_position = facing;
|
||||
destHeightBeam.endPosition = flatFacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw(TargetMode@ mode) override {
|
||||
MoveTarget@ mt = cast<MoveTarget>(mode);
|
||||
if(mt is null)
|
||||
return;
|
||||
|
||||
//Draw facing progress radial
|
||||
if(mt.mode == MM_Normal) {
|
||||
double curTime = frameTime;
|
||||
double time = curTime - mt.startTime;
|
||||
|
||||
if(time > VECTOR_PROGRESS_DELAY && time < VECTOR_DELAY) {
|
||||
shader::PROGRESS = float(
|
||||
min(time - VECTOR_PROGRESS_DELAY,
|
||||
VECTOR_DELAY - VECTOR_PROGRESS_DELAY))
|
||||
/ float(VECTOR_DELAY - VECTOR_PROGRESS_DELAY);
|
||||
vec2i pos = mousePos;
|
||||
material::RadialProgress.draw(recti_area(
|
||||
pos - vec2i(VECTOR_RADIAL_SIZE / 2, VECTOR_RADIAL_SIZE / 2),
|
||||
vec2i(VECTOR_RADIAL_SIZE, VECTOR_RADIAL_SIZE)),
|
||||
VECTOR_RADIAL_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class MoveCallback : TargetCallback {
|
||||
void call(TargetMode@ mode) override {
|
||||
MoveTarget@ mt = cast<MoveTarget>(mode);
|
||||
if(mt is null)
|
||||
return;
|
||||
|
||||
Object@[]@ selection = selectedObjects;
|
||||
if(selection.length == 0)
|
||||
return;
|
||||
|
||||
if(selection[0].hasSupportAI) {
|
||||
//Movement targeting for supports
|
||||
Object@[] supports;
|
||||
double maxRad = 0.0;
|
||||
Empire@ owner;
|
||||
for(uint i = 0, cnt = selection.length; i < cnt; ++i) {
|
||||
Object@ obj = selection[i];
|
||||
if(obj.owner !is null)
|
||||
@owner = obj.owner;
|
||||
if(obj.hasSupportAI && obj.owner.controlled) {
|
||||
supports.insertLast(obj);
|
||||
if(obj.radius > maxRad)
|
||||
maxRad = obj.radius;
|
||||
}
|
||||
}
|
||||
|
||||
if(supports.length == 0)
|
||||
return;
|
||||
|
||||
//Find fleet to transfer to
|
||||
Object@ fleet = cast<Ship>(selection[0]).Leader;
|
||||
if(fleet is null || mode.position.distanceTo(fleet.position) > fleet.getFormationRadius()) {
|
||||
if(owner !is null)
|
||||
@fleet = owner.getFleetFromPosition(mode.position);
|
||||
}
|
||||
if(fleet is null)
|
||||
return;
|
||||
|
||||
//Calculate formation
|
||||
double formRad = fleet.getFormationRadius();
|
||||
uint edge = ceil(sqrt(double(supports.length)));
|
||||
double spacing = max(maxRad, 1.0) * 8;
|
||||
vec3d boxSize(edge * spacing, 0, edge * spacing);
|
||||
double boxRad = sqrt(boxSize.x * boxSize.x / 4.0 + boxSize.z * boxSize.z / 4.0);
|
||||
vec3d boxCenter = (mode.position - fleet.position);
|
||||
|
||||
//Reverse entire fleet rotation
|
||||
Ship@ leadership = cast<Ship>(fleet);
|
||||
if(leadership !is null)
|
||||
boxCenter = leadership.formationDest.inverted() * boxCenter;
|
||||
|
||||
//Keep entire box within bounds
|
||||
if(boxCenter.length + boxRad > formRad)
|
||||
boxCenter.length = formRad - boxRad;
|
||||
|
||||
//Get the spacing vectors
|
||||
vec3d right = vec3d_right();
|
||||
vec3d front = vec3d_front();
|
||||
if(mt.hasFacing) {
|
||||
quaterniond facing = mt.facing;
|
||||
right = facing * right;
|
||||
front = facing * front;
|
||||
}
|
||||
if(leadership !is null) {
|
||||
right = leadership.formationDest.inverted() * right;
|
||||
front = leadership.formationDest.inverted() * front;
|
||||
}
|
||||
|
||||
right.length = spacing;
|
||||
front.length = spacing;
|
||||
|
||||
//Transfer ships to fleet
|
||||
for(uint i = 0, cnt = supports.length; i < cnt; ++i) {
|
||||
uint x = (i % edge);
|
||||
uint y = i / edge;
|
||||
|
||||
//Calculate position in formation
|
||||
vec3d pos = boxCenter;
|
||||
if(x % 2 == 0)
|
||||
pos += right * double(x / 2);
|
||||
else
|
||||
pos -= right * double(x / 2 + 1);
|
||||
if(y % 2 == 0)
|
||||
pos += front * double(y / 2);
|
||||
else
|
||||
pos -= front * double(y / 2 + 1);
|
||||
|
||||
//Transfer and form up
|
||||
Ship@ ship = cast<Ship>(supports[i]);
|
||||
if(ship.Leader !is fleet)
|
||||
supports[i].transferTo(fleet, pos);
|
||||
else
|
||||
supports[i].setFleetOffset(pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//Movement order targeting
|
||||
if(selection.length == 1) {
|
||||
Object@ from = selection[0];
|
||||
|
||||
if(from.owner.controlled && from.hasMover && canMoveIndependently(from)) {
|
||||
sound::order_move.play(priority=true);
|
||||
if(mt.hasFacing)
|
||||
orderMove(from, mode.position, mt.facing, shiftKey);
|
||||
else
|
||||
orderMove(from, mode.position, shiftKey);
|
||||
}
|
||||
}
|
||||
else if(selection.length > 0) {
|
||||
array<Object@> orderObjs;
|
||||
//Get center to organize from
|
||||
vec3d center;
|
||||
double spacing = 1;
|
||||
for(int i = selection.length - 1; i >= 0; --i) {
|
||||
Object@ obj = selection[i];
|
||||
if(canMoveIndependently(obj)) {
|
||||
orderObjs.insertLast(obj);
|
||||
center += obj.position;
|
||||
|
||||
double size = obj.radius;
|
||||
if(obj.hasLeaderAI)
|
||||
size = obj.getFormationRadius();
|
||||
if(size > spacing)
|
||||
spacing = size;
|
||||
}
|
||||
}
|
||||
|
||||
if(orderObjs.length == 1) {
|
||||
sound::order_move.play(priority=true);
|
||||
if(mt.hasFacing)
|
||||
orderMove(orderObjs[0], mode.position, mt.facing, shiftKey);
|
||||
else
|
||||
orderMove(orderObjs[0], mode.position, shiftKey);
|
||||
}
|
||||
else {
|
||||
center /= double(orderObjs.length);
|
||||
spacing *= 2.5;
|
||||
|
||||
//Get center of target organization
|
||||
vec3d dest = mode.position;
|
||||
sound::order_move.play(priority=true);
|
||||
|
||||
//Form the objects up
|
||||
auto@ positions = getFleetTargetPositions(orderObjs, dest, mt.facing, !mt.hasFacing);
|
||||
for(uint i = 0, cnt = orderObjs.length; i < cnt; ++i) {
|
||||
if(mt.hasFacing)
|
||||
orderMove(orderObjs[i], positions[i], mt.facing, shiftKey);
|
||||
else
|
||||
orderMove(orderObjs[i], positions[i], shiftKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void targetMovement() {
|
||||
MoveTarget targ;
|
||||
MoveCallback cb;
|
||||
MoveVisuals vis;
|
||||
|
||||
startTargeting(targ, vis, cb);
|
||||
}
|
||||
|
||||
bool isExtendedMoveTarget() {
|
||||
MoveTarget@ targ = cast<MoveTarget>(mode);
|
||||
if(targ is null)
|
||||
return false;
|
||||
return frameTime - targ.startTime > VECTOR_DELAY;
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
import tabs.Tab;
|
||||
import tabs.tabbar;
|
||||
import abilities;
|
||||
import hooks;
|
||||
from gui import isGuiHovered;
|
||||
|
||||
import targeting.targeting;
|
||||
from obj_selection import hoveredObject, uiObject, selectedObjects;
|
||||
|
||||
export ObjectTargeting;
|
||||
export AbilityTargetObject;
|
||||
export targetObject;
|
||||
export toggleAbilityTargetObject;
|
||||
|
||||
import Tab@ createGalaxyTab() from "tabs.GalaxyTab";
|
||||
|
||||
class ObjectTargeting {
|
||||
Tab@ returnTo;
|
||||
Sprite icon(spritesheet::ContextIcons, 1);
|
||||
bool allowMultiple = false;
|
||||
bool isTemporary = false;
|
||||
bool drawCrosshair = true;
|
||||
Color validIconColor = colors::Green;
|
||||
Color errorIconColor = colors::Red;
|
||||
vec2i iconSize(40, 40);
|
||||
|
||||
bool valid(Object@ target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void call(Object@ target) {
|
||||
}
|
||||
|
||||
string message(Object@ target, bool valid) {
|
||||
return target.name;
|
||||
}
|
||||
|
||||
string desc(Object@ target, bool valid) {
|
||||
return "";
|
||||
}
|
||||
|
||||
string emptyMessage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void hover(Object@ target, const vec2i& mouse) {
|
||||
}
|
||||
|
||||
void draw(Object@ target, bool valid) {
|
||||
}
|
||||
|
||||
void clear() {
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
}
|
||||
};
|
||||
|
||||
class AbilityTargetObject : ObjectTargeting {
|
||||
Ability@ abl;
|
||||
Targets@ targs;
|
||||
|
||||
AbilityTargetObject(Ability@ abl) {
|
||||
@this.abl = abl;
|
||||
@targs = Targets(abl.type.targets);
|
||||
icon = abl.type.icon;
|
||||
}
|
||||
|
||||
bool valid(Object@ target) override {
|
||||
@targs.fill(0).obj = target;
|
||||
return abl.canActivate(targs);
|
||||
}
|
||||
|
||||
void call(Object@ target) override {
|
||||
@targs.fill(0).obj = target;
|
||||
double range = abl.getRange(targs);
|
||||
array<Object@> objects = selectedObjects;
|
||||
if(objects.find(abl.obj) == -1)
|
||||
objects.insertLast(abl.obj);
|
||||
bool playedSound = false;
|
||||
for(uint i = 0, cnt = objects.length; i < cnt; ++i) {
|
||||
Object@ obj = objects[i];
|
||||
if(obj is null || (!obj.isArtifact && !obj.owner.controlled) || !obj.hasAbilities)
|
||||
continue;
|
||||
int ablId = -1;
|
||||
if(obj is abl.obj)
|
||||
ablId = abl.id;
|
||||
else
|
||||
ablId = obj.findAbilityOfType(abl.type.id);
|
||||
if(ablId != -1) {
|
||||
if(obj !is null) {
|
||||
if(obj.hasLeaderAI && range != INFINITY)
|
||||
obj.addAbilityOrder(ablId, target, range, shiftKey);
|
||||
else
|
||||
obj.activateAbility(ablId, target);
|
||||
}
|
||||
else
|
||||
abl.emp.activateAbility(ablId, target);
|
||||
if(abl.type.activateSound !is null && !playedSound) {
|
||||
abl.type.activateSound.play(priority=true);
|
||||
playedSound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string message(Object@ target, bool valid) override {
|
||||
return abl.type.name;
|
||||
}
|
||||
|
||||
string desc(Object@ target, bool valid) {
|
||||
if(!valid) {
|
||||
string err = abl.getTargetError(targs);
|
||||
if(err.length != 0)
|
||||
return err;
|
||||
}
|
||||
return abl.formatCosts(targs);
|
||||
}
|
||||
};
|
||||
|
||||
class ObjectMode : TargetMode {
|
||||
Object@ obj;
|
||||
ObjectTargeting@ targ;
|
||||
|
||||
bool isValidTarget(Object@ obj) override {
|
||||
if(obj is null)
|
||||
return false;
|
||||
if(!targ.valid(obj))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mouse) override {
|
||||
@obj = hoveredObject;
|
||||
if(obj is null)
|
||||
@obj = uiObject;
|
||||
targ.hover(obj, mouse);
|
||||
return isValidTarget(obj);
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
if(obj is null) {
|
||||
if(targ.isTemporary)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if(!targ.valid(obj)) {
|
||||
if(targ.isTemporary) {
|
||||
@obj = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string get_message() override {
|
||||
if(obj is null)
|
||||
return targ.emptyMessage();
|
||||
return targ.message(obj, valid);
|
||||
}
|
||||
|
||||
string get_desc() override {
|
||||
if(obj is null)
|
||||
return "";
|
||||
return targ.desc(obj, valid);
|
||||
}
|
||||
|
||||
Object@ get_target() override {
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
class ObjectDisplay : TargetVisuals {
|
||||
ObjectTargeting@ targ;
|
||||
|
||||
void draw(TargetMode@ mode) override {
|
||||
if(isGuiHovered() && uiObject is null)
|
||||
return;
|
||||
|
||||
Color color;
|
||||
if(mode.valid)
|
||||
color = Color(0x00ff00ff);
|
||||
else
|
||||
color = Color(0xff3333ff);
|
||||
if(mode.target is null)
|
||||
color = Color(0xaaaaaaff);
|
||||
|
||||
Color iconColor = color;
|
||||
if(mode.target !is null && targ !is null) {
|
||||
if(mode.valid)
|
||||
iconColor = targ.validIconColor;
|
||||
else
|
||||
iconColor = targ.errorIconColor;
|
||||
}
|
||||
|
||||
//Draw the cursor
|
||||
vec2i isize = vec2i(40, 40);
|
||||
Sprite icon = spritesheet::ContextIcons+1;
|
||||
|
||||
if(targ !is null) {
|
||||
icon = targ.icon;
|
||||
isize = targ.iconSize;
|
||||
}
|
||||
icon.draw(recti_area(mousePos-isize/2, isize), iconColor);
|
||||
if(targ is null || targ.drawCrosshair) {
|
||||
drawLine(mousePos-vec2i(isize.x, 0), mousePos+vec2i(isize.x,0), color, 2);
|
||||
drawLine(mousePos-vec2i(0, isize.y), mousePos+vec2i(0,isize.y), color, 2);
|
||||
}
|
||||
|
||||
if(targ !is null)
|
||||
targ.draw(mode.target, mode.valid);
|
||||
|
||||
//Draw the message
|
||||
const Font@ ft = font::DroidSans_11_Bold;
|
||||
string err = mode.desc;
|
||||
if(err.length != 0) {
|
||||
ft.draw(recti_area(mousePos-vec2i(200,isize.y+30), vec2i(400, 20)), mode.message, horizAlign=0.5, color=color, stroke=colors::Black);
|
||||
@ft = font::OpenSans_11_Italic;
|
||||
ft.draw(recti_area(mousePos-vec2i(200,isize.y+5), vec2i(400, 20)), err, horizAlign=0.5, color=color, stroke=colors::Black);
|
||||
}
|
||||
else {
|
||||
ft.draw(recti_area(mousePos-vec2i(200,isize.y+5), vec2i(400, 20)), mode.message, horizAlign=0.5, color=color, stroke=colors::Black);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ObjectCB : TargetCallback {
|
||||
ObjectTargeting@ targ;
|
||||
|
||||
void call(TargetMode@ mode) override {
|
||||
if(targ.isTemporary && mode.target is null) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
if(!mode.isShifted || !shiftKey)
|
||||
clear();
|
||||
targ.call(mode.target);
|
||||
targ.clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
targ.clear();
|
||||
if(targ.returnTo !is null) {
|
||||
if(targ.returnTo is ActiveTab.previous)
|
||||
popTab(ActiveTab);
|
||||
else
|
||||
switchToTab(targ.returnTo);
|
||||
}
|
||||
}
|
||||
|
||||
void cancel(bool wasExplicit) {
|
||||
clear();
|
||||
if(wasExplicit)
|
||||
targ.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
void targetObject(ObjectTargeting@ target, Tab@ returnTo = null, bool gotoTab = true) {
|
||||
ObjectMode targ;
|
||||
ObjectDisplay disp;
|
||||
ObjectCB cb;
|
||||
|
||||
@target.returnTo = returnTo;
|
||||
@targ.targ = target;
|
||||
@disp.targ = target;
|
||||
@cb.targ = target;
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
if(target.allowMultiple)
|
||||
targ.autoMultiple = true;
|
||||
|
||||
if(gotoTab) {
|
||||
Tab@ tab = findTab(TC_Galaxy);
|
||||
if(tab !is null) {
|
||||
switchToTab(tab);
|
||||
}
|
||||
else {
|
||||
if(returnTo !is null)
|
||||
browseTab(ActiveTab, createGalaxyTab(), true);
|
||||
else
|
||||
switchToTab(newTab(createGalaxyTab()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void toggleAbilityTargetObject(Ability@ abl) {
|
||||
auto@ om = cast<ObjectMode>(mode);
|
||||
if(om !is null) {
|
||||
auto@ t = cast<AbilityTargetObject>(om.targ);
|
||||
if(t !is null) {
|
||||
if(t.abl.obj is abl.obj && t.abl.id == abl.id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetObject(AbilityTargetObject(abl));
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
import navigation.SmartCamera;
|
||||
from input import activeCamera, mouseToGrid;
|
||||
from gui import isGuiHovered;
|
||||
import abilities;
|
||||
import targeting.targeting;
|
||||
import tabs.Tab;
|
||||
import tabs.tabbar;
|
||||
import Tab@ createGalaxyTab() from "tabs.GalaxyTab";
|
||||
|
||||
class PointTargeting {
|
||||
Tab@ returnTo;
|
||||
Sprite icon(spritesheet::ContextIcons, 1);
|
||||
bool allowMultiple = false;
|
||||
|
||||
bool valid(const vec3d& pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
string message(const vec3d& pos, bool valid) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void call(const vec3d& pos) {
|
||||
}
|
||||
|
||||
string desc(const vec3d& point, bool valid) {
|
||||
return "";
|
||||
}
|
||||
|
||||
double radius(const vec3d& point) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Color get_color() {
|
||||
return Color(0x00000000);
|
||||
}
|
||||
};
|
||||
|
||||
class AbilityTargetPoint : PointTargeting {
|
||||
Ability@ abl;
|
||||
Targets@ targs;
|
||||
|
||||
AbilityTargetPoint(Ability@ abl) {
|
||||
@this.abl = abl;
|
||||
icon = abl.type.icon;
|
||||
@targs = Targets(abl.type.targets);
|
||||
}
|
||||
|
||||
bool valid(const vec3d& target) override {
|
||||
targs.fill(0).point = target;
|
||||
return abl.canActivate(targs);
|
||||
}
|
||||
|
||||
void call(const vec3d& target) override {
|
||||
double range = abl.getRange(targs);
|
||||
if(abl.obj !is null && abl.obj.hasLeaderAI && range != INFINITY)
|
||||
abl.obj.addAbilityOrder(abl.id, target, range, shiftKey);
|
||||
else if(abl.obj !is null)
|
||||
abl.obj.activateAbility(abl.id, target);
|
||||
else
|
||||
abl.emp.activateAbility(abl.id, target);
|
||||
if(abl.type.activateSound !is null)
|
||||
abl.type.activateSound.play(priority=true);
|
||||
}
|
||||
|
||||
string message(const vec3d& target, bool valid) override {
|
||||
return abl.type.name;
|
||||
}
|
||||
|
||||
string desc(const vec3d& point, bool valid) {
|
||||
if(!valid) {
|
||||
string err = abl.getTargetError(targs);
|
||||
if(err.length != 0)
|
||||
return err;
|
||||
}
|
||||
double cost = abl.getEnergyCost(targs);
|
||||
if(cost != 0 && cost != abl.type.energyCost)
|
||||
return format("$1 $2", toString(cost,0), locale::RESOURCE_ENERGY);
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
class PointTargetMode : TargetMode {
|
||||
PointTargeting@ targ;
|
||||
vec3d hovered;
|
||||
|
||||
bool hover(const vec2i& mouse) override {
|
||||
hovered = mouseToGrid(mouse);
|
||||
if(!targ.valid(hovered))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
if(!targ.valid(hovered))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
string get_message() override {
|
||||
return targ.message(hovered, valid);
|
||||
}
|
||||
|
||||
string get_desc() override {
|
||||
return targ.desc(hovered, valid);
|
||||
}
|
||||
|
||||
double get_radius() {
|
||||
return targ.radius(hovered);
|
||||
}
|
||||
};
|
||||
|
||||
class PointTargetDisplay : TargetVisuals {
|
||||
PointTargeting@ targ;
|
||||
void draw(TargetMode@ mode) override {
|
||||
if(isGuiHovered())
|
||||
return;
|
||||
|
||||
Color color = targ.color;
|
||||
if(color.a == 0) {
|
||||
if(mode.valid)
|
||||
color = Color(0x00ff00ff);
|
||||
else
|
||||
color = Color(0xff0000ff);
|
||||
}
|
||||
|
||||
//Draw the cursor
|
||||
drawLine(mousePos-vec2i(40, 0), mousePos+vec2i(40,0), color, 2);
|
||||
drawLine(mousePos-vec2i(0, 40), mousePos+vec2i(0,40), color, 2);
|
||||
targ.icon.draw(recti_area(mousePos-vec2i(20,20), vec2i(40,40)), color);
|
||||
|
||||
//Draw the message
|
||||
const Font@ ft = font::DroidSans_11_Bold;
|
||||
string err = mode.desc;
|
||||
if(err.length != 0) {
|
||||
ft.draw(recti_area(mousePos-vec2i(200,85), vec2i(400, 20)), mode.message, horizAlign=0.5, color=color);
|
||||
@ft = font::OpenSans_11_Italic;
|
||||
ft.draw(recti_area(mousePos-vec2i(200,65), vec2i(400, 20)), err, horizAlign=0.5, color=color);
|
||||
}
|
||||
else {
|
||||
ft.draw(recti_area(mousePos-vec2i(200,65), vec2i(400, 20)), mode.message, horizAlign=0.5, color=color);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PointTargetCB : TargetCallback {
|
||||
PointTargeting@ targ;
|
||||
void call(TargetMode@ mode) override {
|
||||
if(targ.returnTo !is null) {
|
||||
if(targ.returnTo is ActiveTab.previous)
|
||||
popTab(ActiveTab);
|
||||
else
|
||||
switchToTab(targ.returnTo);
|
||||
}
|
||||
targ.call(cast<PointTargetMode>(mode).hovered);
|
||||
}
|
||||
};
|
||||
|
||||
void targetPoint(PointTargeting@ target, Tab@ returnTo = null, bool gotoTab = true) {
|
||||
PointTargetMode targ;
|
||||
PointTargetDisplay disp;
|
||||
PointTargetCB cb;
|
||||
|
||||
@target.returnTo = returnTo;
|
||||
@targ.targ = target;
|
||||
@disp.targ = target;
|
||||
@cb.targ = target;
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
if(target.allowMultiple)
|
||||
targ.autoMultiple = true;
|
||||
|
||||
if(gotoTab) {
|
||||
Tab@ tab = findTab(TC_Galaxy);
|
||||
if(tab !is null) {
|
||||
switchToTab(tab);
|
||||
}
|
||||
else {
|
||||
if(returnTo !is null)
|
||||
browseTab(ActiveTab, createGalaxyTab(), true);
|
||||
else
|
||||
switchToTab(newTab(createGalaxyTab()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PointTarget : TargetMode {
|
||||
Object@ originObj;
|
||||
vec3d originPos;
|
||||
vec3d hovered;
|
||||
double range = -1.0;
|
||||
|
||||
vec3d get_origin() {
|
||||
if(originObj !is null)
|
||||
return originObj.node_position;
|
||||
return originPos;
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mouse) override {
|
||||
hovered = mouseToGrid(mouse);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
vec3d get_position() override {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
double get_distance() {
|
||||
return origin.distanceTo(position);
|
||||
}
|
||||
|
||||
double get_radius() {
|
||||
return 0.0;
|
||||
}
|
||||
};
|
||||
|
||||
class PointDisplay : TargetVisuals {
|
||||
BeamNode@ node;
|
||||
BeamNode@ node2;
|
||||
PlaneNode@ plane;
|
||||
|
||||
Color inColor = colors::Green;
|
||||
Color outColor = colors::Red;
|
||||
Color radiusColor = Color(0x00c0ff80);
|
||||
|
||||
PointDisplay() {
|
||||
@node = BeamNode(material::MoveBeam, 0.002f, vec3d(), vec3d(), true);
|
||||
node.visible = false;
|
||||
|
||||
@node2 = BeamNode(material::MoveBeam, 0.002f, vec3d(), vec3d(), true);
|
||||
node2.visible = false;
|
||||
|
||||
@plane = PlaneNode(material::Circle, 0.0);
|
||||
plane.visible = false;
|
||||
plane.color = radiusColor;
|
||||
}
|
||||
|
||||
~PointDisplay() {
|
||||
node.visible = false;
|
||||
node.markForDeletion();
|
||||
node2.visible = false;
|
||||
node2.markForDeletion();
|
||||
plane.visible = false;
|
||||
plane.markForDeletion();
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
PointTarget@ pt = cast<PointTarget>(mode);
|
||||
if(pt is null)
|
||||
return;
|
||||
|
||||
if(pt.range >= 0.0 && pt.distance > pt.range) {
|
||||
vec3d origin = pt.origin;
|
||||
vec3d target = pt.position;
|
||||
|
||||
vec3d dir = (target - origin).normalize(pt.range);
|
||||
vec3d midpos = origin + dir;
|
||||
|
||||
//In range section
|
||||
node.position = origin;
|
||||
node.endPosition = midpos;
|
||||
node.rebuildTransform();
|
||||
node.color = inColor;
|
||||
node.visible = true;
|
||||
|
||||
//Out of range section
|
||||
node2.position = midpos;
|
||||
node2.endPosition = target;
|
||||
node2.rebuildTransform();
|
||||
node2.color = outColor;
|
||||
node2.visible = true;
|
||||
}
|
||||
else {
|
||||
node.position = pt.origin;
|
||||
node.endPosition = pt.position;
|
||||
node.rebuildTransform();
|
||||
node.color = inColor;
|
||||
|
||||
node.visible = true;
|
||||
node2.visible = false;
|
||||
}
|
||||
|
||||
double rad = pt.radius;
|
||||
if(rad != 0) {
|
||||
plane.position = pt.position;
|
||||
plane.scale = rad;
|
||||
plane.rebuildTransform();
|
||||
plane.visible = true;
|
||||
}
|
||||
else {
|
||||
plane.visible = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void toggleAbilityTargetPoint(Ability@ abl) {
|
||||
auto@ om = cast<PointTargetMode>(mode);
|
||||
if(om !is null) {
|
||||
auto@ t = cast<AbilityTargetPoint>(om.targ);
|
||||
if(t !is null) {
|
||||
if(t.abl.obj is abl.obj && t.abl.id == abl.id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetPoint(AbilityTargetPoint(abl));
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import resources;
|
||||
import ftl;
|
||||
from obj_selection import selectedObject, selectedObjects, getSelectionPosition, getSelectionScale;
|
||||
import targeting.PointTarget;
|
||||
import targeting.targeting;
|
||||
|
||||
class SlipstreamTarget : PointTarget {
|
||||
double cost = 0.0;
|
||||
int scale = 1;
|
||||
Object@ obj;
|
||||
|
||||
SlipstreamTarget(Object@ obj, int totalScale) {
|
||||
@this.obj = obj;
|
||||
scale = totalScale;
|
||||
}
|
||||
|
||||
vec3d get_origin() override {
|
||||
if(shiftKey)
|
||||
return obj.finalMoveDestination;
|
||||
else
|
||||
return obj.position;
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mpos) override {
|
||||
PointTarget::hover(mpos);
|
||||
cost = slipstreamCost(obj, scale, distance);
|
||||
range = slipstreamRange(obj, scale, playerEmpire.FTLStored);
|
||||
return canSlipstreamTo(obj, hovered) && (distance <= range || shiftKey);
|
||||
}
|
||||
|
||||
double get_radius() override {
|
||||
return slipstreamInaccuracy(obj, hovered);
|
||||
}
|
||||
|
||||
bool click() override {
|
||||
return distance <= range || shiftKey;
|
||||
}
|
||||
};
|
||||
|
||||
class SlipstreamDisplay : PointDisplay {
|
||||
void draw(TargetMode@ mode) override {
|
||||
PointDisplay::draw(mode);
|
||||
|
||||
SlipstreamTarget@ ht = cast<SlipstreamTarget>(mode);
|
||||
if(ht is null)
|
||||
return;
|
||||
|
||||
Color color;
|
||||
if(ht.distance <= ht.range && ht.valid)
|
||||
color = Color(0x00ff00ff);
|
||||
else
|
||||
color = Color(0xff0000ff);
|
||||
|
||||
font::DroidSans_11_Bold.draw(mousePos + vec2i(16, 0),
|
||||
toString(int(ht.cost)) + " " + locale::FTL
|
||||
+ " (" + toString(ht.distance, 0) + "u)",
|
||||
color);
|
||||
|
||||
if(ht.distance > ht.range) {
|
||||
font::OpenSans_11_Italic.draw(mousePos + vec2i(16, 16),
|
||||
locale::INSUFFICIENT_FTL,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) override {
|
||||
inColor = Color(0x00c0ffff);
|
||||
if(shiftKey)
|
||||
outColor = Color(0xffe400ff);
|
||||
else
|
||||
outColor = colors::Red;
|
||||
PointDisplay::render(mode);
|
||||
}
|
||||
};
|
||||
|
||||
class SlipstreamCB : TargetCallback {
|
||||
void call(TargetMode@ mode) override {
|
||||
bool anyOpenedTear = false;
|
||||
Object@[]@ selection = selectedObjects;
|
||||
for(uint i = 0, cnt = selection.length; i < cnt; ++i) {
|
||||
Object@ obj = selection[i];
|
||||
if(!obj.hasMover || !obj.hasLeaderAI)
|
||||
continue;
|
||||
if(!canSlipstream(obj))
|
||||
continue;
|
||||
obj.addSlipstreamOrder(mode.position, shiftKey || obj.inFTL);
|
||||
anyOpenedTear = true;
|
||||
for(uint j = 0; j < cnt; ++j) {
|
||||
if(i == j)
|
||||
continue;
|
||||
Object@ other = selection[j];
|
||||
if(!obj.hasMover || !obj.hasLeaderAI)
|
||||
continue;
|
||||
other.addWaitOrder(obj, shiftKey || obj.inFTL, moveTo=true);
|
||||
obj.addSecondaryToSlipstream(other);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(anyOpenedTear)
|
||||
sound::order_slipstream.play(priority=true);
|
||||
}
|
||||
};
|
||||
|
||||
void targetSlipstream() {
|
||||
Object@ sel = selectedObject;
|
||||
for(uint i = 0, cnt = selectedObjects.length; i < cnt; ++i) {
|
||||
if(canSlipstream(selectedObjects[i])) {
|
||||
@sel = selectedObjects[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(sel.owner is null || !sel.owner.valid)
|
||||
return;
|
||||
if(!canSlipstream(sel))
|
||||
return;
|
||||
|
||||
SlipstreamTarget targ(sel, max(getSelectionScale(), 1));
|
||||
SlipstreamDisplay disp;
|
||||
SlipstreamCB cb;
|
||||
|
||||
startTargeting(targ, disp, cb);
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
#priority render 50
|
||||
#priority draw -10
|
||||
|
||||
funcdef bool HoverFilterCB(Object@);
|
||||
HoverFilterCB@ hoverFilter, lastHoverFilter;
|
||||
|
||||
class TargetMode {
|
||||
bool valid = false;
|
||||
bool isShifted = false;
|
||||
bool autoMultiple = false;
|
||||
|
||||
bool isValidTarget(Object@ obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hover(const vec2i& mouse) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool click() {
|
||||
return false;
|
||||
}
|
||||
|
||||
vec3d get_position() {
|
||||
return vec3d();
|
||||
}
|
||||
|
||||
Object@ get_target() {
|
||||
return null;
|
||||
}
|
||||
|
||||
string get_message() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_desc() {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool onMouseWheel(int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseButton(int button, bool pressed) {
|
||||
if(!pressed) {
|
||||
if(button == 0) {
|
||||
targetingClick();
|
||||
return true;
|
||||
}
|
||||
else if(button == 1) {
|
||||
cancelTargeting(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(button == 0 || button == 1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseMoved(int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseDragged(int buttons, int x, int y, int dx, int dy) {
|
||||
if(buttons == 0x1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onMouseDragEnd(int buttons) {
|
||||
if(buttons == 0x1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onKeyEvent(int key, bool pressed) {
|
||||
if(key == KEY_ESC) {
|
||||
if(pressed) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
cancelTargeting();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class TargetVisuals {
|
||||
void draw(TargetMode@ mode) {
|
||||
}
|
||||
|
||||
void render(TargetMode@ mode) {
|
||||
}
|
||||
};
|
||||
|
||||
class TargetCallback {
|
||||
void call(TargetMode@ mode) {
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
}
|
||||
|
||||
void cancel(bool wasExplicit) {
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
TargetMode@ mode;
|
||||
TargetVisuals@ visuals;
|
||||
TargetCallback@ cb;
|
||||
bool shown = false;
|
||||
|
||||
bool isTargeting() {
|
||||
return shown && mode !is null;
|
||||
}
|
||||
|
||||
bool targetingClick() {
|
||||
if(mode is null)
|
||||
return false;
|
||||
if(!mode.click()) {
|
||||
sound::error.play(priority=true);
|
||||
return true;
|
||||
}
|
||||
auto@ _callback = cb;
|
||||
auto@ _mode = mode;
|
||||
|
||||
if(!mode.autoMultiple || !shiftKey) {
|
||||
cancelTargeting();
|
||||
}
|
||||
else {
|
||||
sound::generic_click.play(priority=true);
|
||||
mode.isShifted = true;
|
||||
}
|
||||
|
||||
if(_callback !is null)
|
||||
_callback.call(_mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool targetMouseWheel(int x, int y) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onMouseWheel(x, y);
|
||||
}
|
||||
|
||||
bool targetMouseButton(int button, bool pressed) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onMouseButton(button, pressed);
|
||||
}
|
||||
|
||||
bool targetMouseMoved(int x, int y) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onMouseMoved(x, y);
|
||||
}
|
||||
|
||||
bool targetMouseDragged(int buttons, int x, int y, int dx, int dy) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onMouseDragged(buttons, x, y, dx, dy);
|
||||
}
|
||||
|
||||
bool targetMouseDragEnd(int buttons) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onMouseDragEnd(buttons);
|
||||
}
|
||||
|
||||
bool targetKeyEvent(int key, bool pressed) {
|
||||
if(!shown || mode is null)
|
||||
return false;
|
||||
return mode.onKeyEvent(key, pressed);
|
||||
}
|
||||
|
||||
void startTargeting(TargetMode@ Mode, TargetVisuals@ Visuals, TargetCallback@ Cb) {
|
||||
@mode = Mode;
|
||||
@visuals = Visuals;
|
||||
@cb = Cb;
|
||||
@hoverFilter = HoverFilterCB(mode.isValidTarget);
|
||||
}
|
||||
|
||||
void cancelTargeting(bool wasExplicit = false) {
|
||||
if(cb !is null)
|
||||
cb.cancel(wasExplicit);
|
||||
@mode = null;
|
||||
@visuals = null;
|
||||
@cb = null;
|
||||
@hoverFilter = null;
|
||||
}
|
||||
|
||||
void showTargeting() {
|
||||
shown = true;
|
||||
}
|
||||
|
||||
void hideTargeting() {
|
||||
shown = false;
|
||||
}
|
||||
|
||||
void tick(double time) {
|
||||
if(shown && mode !is null) {
|
||||
bool valid = mode.hover(mousePos);
|
||||
if(mode !is null) {
|
||||
mode.valid = valid;
|
||||
if(mode.isShifted && !shiftKey)
|
||||
cancelTargeting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(shown && visuals !is null)
|
||||
visuals.draw(mode);
|
||||
}
|
||||
|
||||
void render(double time) {
|
||||
if(shown && visuals !is null)
|
||||
visuals.render(mode);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import constructible;
|
||||
|
||||
void drawConstructible(Constructible@ cons, const recti& pos, bool isBox = false) {
|
||||
//Draw design model
|
||||
if(cons.dsg !is null) {
|
||||
recti shipPos;
|
||||
if(cons.dsg.hull.backgroundScale != 1.0)
|
||||
shipPos = recti_centered(pos, vec2i(double(pos.width) * cons.dsg.hull.backgroundScale,
|
||||
double(pos.height) * cons.dsg.hull.backgroundScale));
|
||||
else
|
||||
shipPos = pos;
|
||||
|
||||
shader::CUTOFF_PCT = cons.progress;
|
||||
const Model@ baseModel = cons.dsg.hull.model;
|
||||
const Material@ baseMaterial = cons.dsg.hull.material;
|
||||
quaterniond rot = quaterniond_fromAxisAngle(vec3d_front(), -0.8 * pi);
|
||||
|
||||
Material frontMat(baseMaterial);
|
||||
@frontMat.shader = shader::CutOff;
|
||||
frontMat.depthTest = DT_Always;
|
||||
|
||||
Material backMat(baseMaterial);
|
||||
@backMat.shader = shader::WireframeCutOff;
|
||||
backMat.drawMode = DM_Line;
|
||||
backMat.depthTest = DT_Always;
|
||||
|
||||
if(isBox) {
|
||||
Color lCol = cons.dsg.color;
|
||||
lCol.a = 0x20;
|
||||
Color mCol = cons.dsg.color;
|
||||
mCol.a = 0x12;
|
||||
Color dCol = cons.dsg.color;
|
||||
dCol.a = 0x05;
|
||||
|
||||
drawRectangle(pos, mCol, lCol, mCol, dCol);
|
||||
drawRectangle(pos.padded(0, 0, (1.f - cons.progress) * pos.width, 0), Color(0xffffff14));
|
||||
}
|
||||
|
||||
baseModel.draw(backMat, shipPos.padded(2), rot);
|
||||
baseModel.draw(frontMat, shipPos.padded(2), rot);
|
||||
}
|
||||
else if(cons.orbital !is null) {
|
||||
shader::CUTOFF_PCT = cons.progress;
|
||||
const Model@ baseModel = cons.orbital.model;
|
||||
const Material@ baseMaterial = cons.orbital.material;
|
||||
quaterniond rot = quaterniond();
|
||||
|
||||
Material frontMat(baseMaterial);
|
||||
@frontMat.shader = shader::CutOff;
|
||||
frontMat.depthTest = DT_Always;
|
||||
|
||||
Material backMat(baseMaterial);
|
||||
@backMat.shader = shader::WireframeCutOff;
|
||||
backMat.drawMode = DM_Line;
|
||||
backMat.depthTest = DT_Always;
|
||||
|
||||
if(isBox)
|
||||
drawRectangle(pos.padded(0, 0, (1.f - cons.progress) * pos.width, 0), Color(0xffffff14));
|
||||
|
||||
baseModel.draw(backMat, pos.padded(2), rot);
|
||||
baseModel.draw(frontMat, pos.padded(2), rot);
|
||||
}
|
||||
else {
|
||||
if(isBox)
|
||||
drawRectangle(pos.padded(0, 0, (1.f - cons.progress) * pos.width, 0), Color(0xffffff14));
|
||||
}
|
||||
}
|
||||
|
||||
void drawConstructible(Constructible@ cons, const recti& pos, const Font@ ft) {
|
||||
Color nameCol(0xffffffff);
|
||||
if(!cons.started)
|
||||
nameCol = Color(0xff0000ff);
|
||||
|
||||
int sz = ft.getLineHeight() * 2 + 6;
|
||||
ft.draw(pos=pos.resized(0, sz, 0.0, 1.0),
|
||||
text=cons.name, color=nameCol, horizAlign=0.5, vertAlign=0.0,
|
||||
stroke=colors::Black);
|
||||
|
||||
string prog = toString(cons.progress * 100.f, 0)+"%";
|
||||
if(cons.type == CT_DryDock)
|
||||
prog += " / "+toString(cons.pct * 100.f, 0)+"%";
|
||||
ft.draw(pos=pos.resized(0, sz - ft.getLineHeight(), 0.0, 1.0),
|
||||
text=prog, color=Color(0xffffffff), horizAlign=0.5, vertAlign=0.0,
|
||||
stroke=colors::Black);
|
||||
|
||||
drawConstructible(cons, pos.resized(0, pos.size.height - sz + 6));
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import elements.GuiResources;
|
||||
import planet_types;
|
||||
import resources;
|
||||
import orbitals;
|
||||
from gui import gui_root;
|
||||
|
||||
export drawPlanetIcon;
|
||||
void drawPlanetIcon(Planet@ obj, const recti& pos) {
|
||||
//Draw level and owner
|
||||
Color col;
|
||||
Empire@ owner = obj.visibleOwner;
|
||||
if(owner !is null && owner.valid) {
|
||||
col = owner.color;
|
||||
|
||||
const Material@ mat;
|
||||
uint level = obj.visibleLevel;
|
||||
switch(level) {
|
||||
case 0: @mat = material::PlanetIcon0; break;
|
||||
case 1: @mat = material::PlanetIcon1; break;
|
||||
case 2: @mat = material::PlanetIcon2; break;
|
||||
case 3: @mat = material::PlanetIcon3; break;
|
||||
case 4: @mat = material::PlanetIcon4; break;
|
||||
case 5: @mat = material::PlanetIcon5; break;
|
||||
default:
|
||||
@mat = getMaterial("PlanetIcon"+obj.visibleLevel);
|
||||
if(mat is material::error)
|
||||
@mat = material::PlanetIcon4;
|
||||
break;
|
||||
}
|
||||
mat.draw(pos, col);
|
||||
}
|
||||
|
||||
//Draw planet type
|
||||
const PlanetType@ type = getPlanetType(obj.PlanetType);
|
||||
type.icon.draw(pos.padded(0.15 * pos.width, 0.15 * pos.height));
|
||||
|
||||
//Draw resource
|
||||
{
|
||||
const ResourceType@ res = getResource(obj.primaryResourceType);
|
||||
if(res !is null)
|
||||
res.smallIcon.draw(pos.padded(0.3 * pos.width, 0.3 * pos.height));
|
||||
}
|
||||
}
|
||||
|
||||
void drawPlanetIcon(Planet@ obj, const recti& pos, Resource@ r, bool showType = true) {
|
||||
//Draw level and owner
|
||||
Color col;
|
||||
Empire@ owner = obj.visibleOwner;
|
||||
if(showType) {
|
||||
if(owner !is null && owner.valid) {
|
||||
col = owner.color;
|
||||
|
||||
const Material@ mat;
|
||||
uint level = obj.visibleLevel;
|
||||
switch(level) {
|
||||
case 0: @mat = material::PlanetIcon0; break;
|
||||
case 1: @mat = material::PlanetIcon1; break;
|
||||
case 2: @mat = material::PlanetIcon2; break;
|
||||
case 3: @mat = material::PlanetIcon3; break;
|
||||
case 4: @mat = material::PlanetIcon4; break;
|
||||
case 5: @mat = material::PlanetIcon5; break;
|
||||
default:
|
||||
@mat = getMaterial("PlanetIcon"+obj.visibleLevel);
|
||||
if(mat is material::error)
|
||||
@mat = material::PlanetIcon4;
|
||||
break;
|
||||
}
|
||||
mat.draw(pos, col);
|
||||
}
|
||||
|
||||
//Draw planet type
|
||||
const PlanetType@ type = getPlanetType(obj.PlanetType);
|
||||
type.icon.draw(pos.padded(0.15 * pos.width, 0.15 * pos.height));
|
||||
}
|
||||
|
||||
recti resourcePos = pos.padded(0.3 * pos.width, 0.3 * pos.height);
|
||||
recti expandPos = resourcePos.padded(-2);
|
||||
|
||||
//Draw resource
|
||||
if(r !is null && r.type !is null)
|
||||
drawSmallResource(r.type, r, resourcePos, obj, onPlanet=true);
|
||||
|
||||
//Draw colonizing tick
|
||||
if(obj.isBeingColonized)
|
||||
spritesheet::ResourceIconsSmallMods.draw(8, expandPos-(resourcePos.size * 0.5));
|
||||
|
||||
//Draw decay icon
|
||||
if(obj.decayTime > 0)
|
||||
spritesheet::ResourceIconsSmallMods.draw(9, expandPos);
|
||||
}
|
||||
|
||||
void drawAsteroidIcon(Asteroid@ obj, const recti& pos, Resource@ r = null) {
|
||||
//Draw level and owner
|
||||
Color col;
|
||||
Empire@ owner = obj.owner;
|
||||
if(owner !is null && owner.valid)
|
||||
col = owner.color;
|
||||
|
||||
recti resourcePos = pos.padded(0.3 * pos.width, 0.3 * pos.height);
|
||||
recti iconPos = pos.padded(0.2 * pos.width, 0.2 * pos.height);
|
||||
|
||||
vec2i offset = pos.size * 0.15;
|
||||
iconPos -= offset;
|
||||
resourcePos += offset;
|
||||
|
||||
//Draw asteroid icon
|
||||
material::AsteroidIcon.draw(iconPos, col);
|
||||
|
||||
//Draw resource
|
||||
if(r !is null)
|
||||
drawSmallResource(r.type, r, resourcePos, obj, onPlanet=true);
|
||||
}
|
||||
|
||||
void drawOrbitalIcon(Orbital@ obj, const recti& pos) {
|
||||
auto@ type = getOrbitalModule(obj.coreModule);
|
||||
if(type is null)
|
||||
return;
|
||||
|
||||
Color col;
|
||||
Empire@ owner = obj.owner;
|
||||
if(owner !is null && owner.valid)
|
||||
col = owner.color;
|
||||
type.icon.draw(pos, col);
|
||||
}
|
||||
|
||||
export drawFleetIcon;
|
||||
void drawFleetIcon(Ship@ leader, const recti& pos, double barCur, double barMax,
|
||||
const Color& barColorLeft = Color(0xff6a00ff), const Color& barColorRight = Color(0xffc600ff)) {
|
||||
auto@ bp = leader.blueprint;
|
||||
if(!leader.valid || bp is null)
|
||||
return;
|
||||
|
||||
const Design@ dsg = bp.design;
|
||||
if(dsg is null)
|
||||
return;
|
||||
|
||||
Color color;
|
||||
Empire@ owner = leader.owner;
|
||||
if(owner !is null)
|
||||
color = owner.color;
|
||||
|
||||
//In combat glow
|
||||
if(leader.inCombat) {
|
||||
double glowPct = abs((frameTime % 2.0) - 1.0);
|
||||
Color glow = Color(0xffc60020).interpolate(Color(0xffc60005), glowPct);
|
||||
drawRectangle(pos.padded(0.1 * pos.width), glow);
|
||||
}
|
||||
|
||||
dsg.icon.draw(pos.padded(0.2 * pos.width), color);
|
||||
|
||||
if(barMax != 0) {
|
||||
double pct = clamp(barCur / barMax, 0.0, 1.0);
|
||||
|
||||
//Draw the bar
|
||||
recti barPos = pos.padded(0.06 * pos.width, 0.64 * pos.width, 0.06 * pos.width, 0.06 * pos.width);
|
||||
gui_root.skin.draw(SS_ProgressBarBG, SF_Normal, barPos);
|
||||
|
||||
recti frontPos = barPos.padded(1);
|
||||
frontPos.botRight.x = frontPos.topLeft.x + pct * frontPos.width;
|
||||
|
||||
auto color = barColorLeft.interpolate(barColorRight, pct);
|
||||
gui_root.skin.draw(SS_ProgressBar, SF_Normal, frontPos, color);
|
||||
|
||||
//Draw the number
|
||||
gui_root.skin.getFont(FT_Small).draw(horizAlign=0.5, vertAlign=0.5,
|
||||
text=standardize(barCur, true), pos=barPos);
|
||||
}
|
||||
}
|
||||
|
||||
void drawFleetIcon(Ship@ leader, const recti& pos, bool showStrength = true) {
|
||||
if(leader is null || !leader.valid)
|
||||
return;
|
||||
|
||||
double maxStr = 0, curStr = 0;
|
||||
if(showStrength) {
|
||||
if(leader.supportCount > 0 && pos.height >= 30) {
|
||||
maxStr = leader.getFleetMaxStrength() / 1000.0;
|
||||
if(maxStr != 0)
|
||||
curStr = leader.getFleetStrength() / 1000.0;
|
||||
}
|
||||
}
|
||||
|
||||
drawFleetIcon(leader, pos, curStr, maxStr);
|
||||
}
|
||||
|
||||
void drawRegionIcon(Region@ region, const recti& pos) {
|
||||
material::SystemUnderAttack.draw(pos);
|
||||
}
|
||||
|
||||
export drawObjectIcon;
|
||||
void drawObjectIcon(Object@ obj, const recti& pos) {
|
||||
if(obj.isPlanet)
|
||||
drawPlanetIcon(cast<Planet>(obj), pos);
|
||||
else if(obj.isAsteroid)
|
||||
drawAsteroidIcon(cast<Asteroid>(obj), pos);
|
||||
else if(obj.isOrbital)
|
||||
drawOrbitalIcon(cast<Orbital>(obj), pos);
|
||||
else if(obj.isShip && obj.hasLeaderAI)
|
||||
drawFleetIcon(cast<Ship>(obj), pos);
|
||||
else if(obj.isArtifact)
|
||||
icons::Artifact.draw(pos);
|
||||
else if(obj.isRegion)
|
||||
drawRegionIcon(cast<Region>(obj), pos);
|
||||
}
|
||||
|
||||
void drawObjectIcon(Object@ obj, const recti& pos, Resource@ r) {
|
||||
if(obj.isPlanet)
|
||||
drawPlanetIcon(cast<Planet>(obj), pos, r);
|
||||
else if(obj.isAsteroid)
|
||||
drawAsteroidIcon(cast<Asteroid>(obj), pos, r);
|
||||
else if(obj.isOrbital)
|
||||
drawOrbitalIcon(cast<Orbital>(obj), pos);
|
||||
else if(obj.isShip && obj.hasLeaderAI)
|
||||
drawFleetIcon(cast<Ship>(obj), pos);
|
||||
else if(obj.isArtifact)
|
||||
icons::Artifact.draw(pos);
|
||||
else if(obj.isRegion)
|
||||
drawRegionIcon(cast<Region>(obj), pos);
|
||||
}
|
||||
Reference in New Issue
Block a user