Fix #31, adapt Wyrmgus' code for icon frames and allow more control over flashing or non-flashing border.
This commit is contained in:
parent
766bcfd0cc
commit
11b71b579c
7 changed files with 66 additions and 7 deletions
|
@ -54,6 +54,7 @@
|
|||
<a href="#DefineUI">DefineUI</a>
|
||||
<a href="#DefineViewports">DefineViewports</a>
|
||||
<a href="#SetGameCursor">SetGameCursor</a>
|
||||
<a href="#Icon Frame">Icon Frame</a>
|
||||
<hr>
|
||||
<h2>Intro - Introduction to UI functions and variables</h2>
|
||||
|
||||
|
@ -231,7 +232,11 @@ Selected, Clicked, Disabled, or the Default setting. Possible tags:
|
|||
<dd>Display the text at this position (overrides the main position).
|
||||
</dd>
|
||||
<dt>Border = { Color = color, Size = size}</dt>
|
||||
<dd>Draw a border with the specified color and size.
|
||||
<dd>Draw a border with the specified color and size, with the border flashing
|
||||
</dd>
|
||||
</dl>
|
||||
<dt>Border = { SolidColor = color, Size = size}</dt>
|
||||
<dd>Draw a border with the specified color and size, without any flashing of the border
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
@ -1261,6 +1266,16 @@ Set the game cursor.
|
|||
SetGameCursor("cursor-point")
|
||||
</pre>
|
||||
|
||||
<a name="Icon Frame"></a>
|
||||
<h3>Icon Frame</h3>
|
||||
Set a custom frame to be drawn around icons. Note that "IconsShift" has to be true.
|
||||
<h4>Example</h4>
|
||||
<pre>
|
||||
Preference.IconsShift = true
|
||||
Preference.IconFrameG = CGraphic:New("ui/" .. race .. "/icon_border.png", 62, 48)
|
||||
Preference.PressedIconFrameG = CGraphic:New("ui/" .. race .. "/icon_border.png", 62, 48)
|
||||
</pre>
|
||||
|
||||
<hr>
|
||||
(C) Copyright 2002-2015 by The <a href="https://launchpad.net/stratagus">Stratagus</a> Project under the <a href="../gpl.html">GNU General Public License</a>.<br>
|
||||
All trademarks and copyrights on this page are owned by their respective owners.<br>
|
||||
|
|
|
@ -287,7 +287,7 @@ public:
|
|||
int GetDrawLevel() const;
|
||||
|
||||
bool IsAttackRanged(CUnit *goal, const Vec2i &goalPos);
|
||||
|
||||
|
||||
PixelPos GetMapPixelPosTopLeft() const;
|
||||
PixelPos GetMapPixelPosCenter() const;
|
||||
|
||||
|
@ -430,10 +430,11 @@ class CPreference
|
|||
{
|
||||
public:
|
||||
CPreference() : ShowSightRange(false), ShowReactionRange(false),
|
||||
ShowAttackRange(false), ShowMessages(true), BigScreen(false),
|
||||
ShowAttackRange(false), ShowMessages(true), BigScreen(false),
|
||||
PauseOnLeave(true), AiExplores(true), GrayscaleIcons(false),
|
||||
IconsShift(false), StereoSound(true), MineNotifications(false),
|
||||
DeselectInMine(false), NoStatusLineTooltips(false),
|
||||
IconFrameG(NULL), PressedIconFrameG(NULL),
|
||||
ShowOrders(0), ShowNameDelay(0), ShowNameTime(0), AutosaveMinutes(5) {};
|
||||
|
||||
bool ShowSightRange; /// Show sight range.
|
||||
|
@ -456,6 +457,9 @@ public:
|
|||
int AutosaveMinutes; /// Autosave the game every X minutes; autosave is disabled if the value is 0
|
||||
|
||||
std::string SF2Soundfont;/// Path to SF2 soundfont
|
||||
|
||||
CGraphic *IconFrameG;
|
||||
CGraphic *PressedIconFrameG;
|
||||
};
|
||||
|
||||
extern CPreference Preference;
|
||||
|
|
|
@ -38,6 +38,9 @@ class CPreference
|
|||
unsigned int AutosaveMinutes;
|
||||
|
||||
std::string SF2Soundfont;
|
||||
|
||||
CGraphic *IconFrameG;
|
||||
CGraphic *PressedIconFrameG;
|
||||
};
|
||||
|
||||
class CUnitManager
|
||||
|
|
|
@ -191,7 +191,23 @@ void CIcon::DrawUnitIcon(const ButtonStyle &style, unsigned flags,
|
|||
s.Default.BorderColor = 0;
|
||||
s.Default.BorderSize = 2;
|
||||
}
|
||||
if (Preference.IconsShift) {
|
||||
if (Preference.IconsShift && Preference.IconFrameG && Preference.PressedIconFrameG) {
|
||||
int shift = 0;
|
||||
if (!(flags & IconClicked)) {
|
||||
int xoffset = (s.Width - Preference.IconFrameG->Width) / 2;
|
||||
int yoffset = (s.Height - Preference.IconFrameG->Height) / 2;
|
||||
Preference.IconFrameG->DrawClip(pos.x + xoffset, pos.y + yoffset);
|
||||
} else { // Shift the icon a bit to make it look like it's been pressed.
|
||||
shift = 1;
|
||||
int xoffset = (s.Width - Preference.PressedIconFrameG->Width) / 2 + shift;
|
||||
int yoffset = (s.Height - Preference.PressedIconFrameG->Height) / 2 + shift;
|
||||
Preference.PressedIconFrameG->DrawClip(pos.x + xoffset, pos.y + yoffset);
|
||||
}
|
||||
DrawUIButton(&s, flags, pos.x + shift, pos.y + shift, text, player);
|
||||
if (flags & IconSelected) {
|
||||
Video.DrawRectangle(ColorGreen, pos.x + shift, pos.y + shift, s.Width, s.Height);
|
||||
}
|
||||
} else if (Preference.IconsShift) {
|
||||
// Left and top edge of Icon
|
||||
Video.DrawHLine(ColorWhite, pos.x - 1, pos.y - 1, 49);
|
||||
Video.DrawVLine(ColorWhite, pos.x - 1, pos.y, 40);
|
||||
|
@ -216,7 +232,7 @@ void CIcon::DrawUnitIcon(const ButtonStyle &style, unsigned flags,
|
|||
DrawUIButton(&s, flags, pos.x + 1, pos.y + 1, text, player);
|
||||
if (flags & IconSelected) {
|
||||
Video.DrawRectangle(ColorGreen, pos.x + 1, pos.y + 1, 46, 38);
|
||||
}
|
||||
}
|
||||
Video.DrawRectangle(ColorGray, pos.x, pos.y, 48, 40);
|
||||
Video.DrawVLine(ColorDarkGray, pos.x - 1, pos.y - 1, 40);
|
||||
Video.DrawHLine(ColorDarkGray, pos.x - 1, pos.y - 1, 49);
|
||||
|
|
|
@ -768,6 +768,9 @@ static void ParseButtonStyleProperties(lua_State *l, ButtonStyleProperties *p)
|
|||
p->BorderColorRGB.Parse(l);
|
||||
} else if (!strcmp(value, "Size")) {
|
||||
p->BorderSize = LuaToNumber(l, -1);
|
||||
} else if (!strcmp(value, "SolidColor")) {
|
||||
p->BorderColorRGB.Parse(l);
|
||||
p->BorderColor = 1; // XXX: see uibuttons_proc.cpp#DrawUIButton
|
||||
} else {
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ CUnitInfoPanel::~CUnitInfoPanel()
|
|||
CUserInterface::CUserInterface() :
|
||||
MouseScroll(false), KeyScroll(false), KeyScrollSpeed(1),
|
||||
MouseScrollSpeed(1), MouseScrollSpeedDefault(0), MouseScrollSpeedControl(0),
|
||||
NormalFontColor("yellow"), ReverseFontColor("white"),
|
||||
NormalFontColor("yellow"), ReverseFontColor("white"),
|
||||
SingleSelectedButton(NULL),
|
||||
MaxSelectedFont(NULL), MaxSelectedTextX(0), MaxSelectedTextY(0),
|
||||
SingleTrainingButton(NULL),
|
||||
|
@ -235,6 +235,15 @@ void CUserInterface::Load()
|
|||
PieMenu.G->UseDisplayFormat();
|
||||
}
|
||||
|
||||
if (Preference.IconFrameG) {
|
||||
Preference.IconFrameG->Load();
|
||||
Preference.IconFrameG->UseDisplayFormat();
|
||||
}
|
||||
if (Preference.PressedIconFrameG) {
|
||||
Preference.PressedIconFrameG->Load();
|
||||
Preference.PressedIconFrameG->UseDisplayFormat();
|
||||
}
|
||||
|
||||
// Resolve cursors
|
||||
Point.Load();
|
||||
Glass.Load();
|
||||
|
@ -320,6 +329,13 @@ void CleanUserInterface()
|
|||
}
|
||||
UI.InfoPanelContents.clear();
|
||||
|
||||
if (Preference.IconFrameG) {
|
||||
CGraphic::Free(Preference.IconFrameG);
|
||||
}
|
||||
if (Preference.PressedIconFrameG) {
|
||||
CGraphic::Free(Preference.PressedIconFrameG);
|
||||
}
|
||||
|
||||
// Button Popups
|
||||
for (std::vector<CPopup *>::iterator popup = UI.ButtonPopups.begin();
|
||||
popup != UI.ButtonPopups.end(); ++popup) {
|
||||
|
|
|
@ -132,8 +132,10 @@ void DrawUIButton(ButtonStyle *style, unsigned flags, int x, int y,
|
|||
color.G = (p->BorderColorRGB.G > 0) << ((shift - 0x10) / 2);
|
||||
color.B = (p->BorderColorRGB.B > 0) << ((shift - 0x10) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
p->BorderColor = Video.MapRGB(TheScreen->format, color);
|
||||
} else {
|
||||
p->BorderColor = Video.MapRGB(TheScreen->format, p->BorderColorRGB);
|
||||
}
|
||||
if (p->BorderSize) {
|
||||
for (int i = 0; i < p->BorderSize; ++i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue