Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions panorama/layout/mainmenu_news.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,6 @@
<include src="file://{resources}/scripts/mainmenu_news.js" />
</scripts>

<snippets>
<snippet name="news-full-entry">
<Button class="news-entry news-panel-style-short-entires">




<CSGOBlurTarget id="NewsEntryBlurTarget" class="news-entry__image--blur" >
<Image id="NewsHeaderImage" class="news-entry__image" src="" scaling="stretch-to-fit-x-preserve-aspect" />
</CSGOBlurTarget>
</Button>
</snippet>

<snippet name="news-info">
<Panel class="news-entry__info">
<Label html="true" class="news-entry__details stratum-font" text="{s:news_item_date}" />
<Label html="true" class="news-entry__title stratum-font" text="{s:news_item_title}" />
<Label html="true" class="news-entry__body" text="{s:h:news_item_body}" />
</Panel>
</snippet>

</snippets>


<Panel class="news-panel MainMenuModeOnly">
<Panel style="margin: 12px 0px 0px 12px;" class="news-panel-navbar">
Expand All @@ -40,10 +17,14 @@
<Image class="news-panel-navbar-logo news-panel-navbar-pwchina" textureheight="18" texturewidth="-1" src="file://{images}/icons/ui/ct_silhouette.svg" />
<Label html="false" text="#SFUI_MainMenu_News_Title" />
</Panel>
<Panel id="NewsPanelLister" class="news-panel__list vscroll">


</Panel>
<HTML id="HarmonyBlogHTML"
class="full-width full-height"
acceptsinput="true"
acceptsfocus="true"
focusonhover="true"
mousetracking="true"
popuplinks="false"
url="https://harmony.heapy.xyz/blog" />
</Panel>
</root>

Expand Down
133 changes: 43 additions & 90 deletions panorama/scripts/mainmenu_news.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,56 @@

var NewsPanel = (function () {

var _GetRssFeed = function()
{
BlogAPI.RequestRSSFeed();
}
var _Init = function() {
var elBlogHTML = $.GetContextPanel().FindChildTraverse('HarmonyBlogHTML');
if (elBlogHTML) {
elBlogHTML.SetURL('https://harmony.heapy.xyz/blog');
}
};

function _InjectCSS() {
var elBlogHTML = $.GetContextPanel().FindChildTraverse('HarmonyBlogHTML');
if (elBlogHTML) {
elBlogHTML.RunJavascript(`
var style = document.createElement('style');
style.textContent = \`
nav.sticky.top-0.z-50.flex.items-center.gap-1.border-b.border-border.px-4.py-2.backdrop-blur-sm {
display: none !important;
}
h1.text-2xl.font-semibold {
display: none !important;
}
\`;
document.head.appendChild(style);
`);
}
}

function _HTMLFinishRequest() {
_InjectCSS();
}

function _HTMLOpenPopupTab(objHtmlEventTarget, objHtml, sUrl) {
// Add custom command later here if needed, for now we allow only to open external links in 'developer 2'
if(GameInterfaceAPI.GetSettingString("developer") == 2) {
UiToolkitAPI.ShowGenericPopupYesNo( 'External Link', 'This link will open ' + sUrl + ' externally in your Browser.\n\nAre you sure that you want to open this link?', '', function() { SteamOverlayAPI.OpenUrlInOverlayOrExternalBrowser(sUrl); }, function() { } )
} else {
UiToolkitAPI.ShowGenericPopupOk( 'External Links', 'Due to security measure\'s, you cannot open any links externally from within CS Harmony unless it\'s enabled specifically in your game settings.', '', function() { } )
}
}

var _OnRssFeedReceived = function( feed )
{
if( $.GetContextPanel().BHasClass( 'news-panel--hide-news-panel' ) )
{
return;
};

var elLister = $.GetContextPanel().FindChildInLayoutFile( 'NewsPanelLister' );

if ( elLister === undefined || elLister === null || !feed )
return;

elLister.RemoveAndDeleteChildren();


var foundFirstNewsItem = false;

feed[ 'items' ].forEach( function( item, i )
{
var elEntry = $.CreatePanel( 'Panel', elLister, 'NewEntry' + i, {
acceptsinput: true
} );

var lastReadItem = GameInterfaceAPI.GetSettingString( 'ui_news_last_read_link' );


if ( !foundFirstNewsItem && !item.categories.includes( 'Minor' ) )
{
foundFirstNewsItem = true;


elEntry.AddClass( 'new' );

/*
if ( item.link != lastReadItem )
{
UiToolkitAPI.ShowCustomLayoutPopupParameters( '', 'file://{resources}/layout/popups/popup_news.xml',
'date=' + item.date + "&" +
'title=' + item.title + "&" +
'link=' + item.link );
}
*/

GameInterfaceAPI.SetSettingString( 'ui_news_last_read_link', item.link );
}

elEntry.BLoadLayoutSnippet( 'news-full-entry' );
var elImage = elEntry.FindChildInLayoutFile( 'NewsHeaderImage' );

if ( item.imageUrl )
{
elImage.SetImage( item.imageUrl );
}
else
{
elImage.SetImage( "file://{images}/store/default-news.png" );
}

var elEntryInfo = $.CreatePanel( 'Panel', elEntry, 'NewsInfo' + i );
elEntryInfo.BLoadLayoutSnippet( 'news-info' );

elEntryInfo.SetDialogVariable( 'news_item_date', item.date );
elEntryInfo.SetDialogVariable( 'news_item_title', item.title );
elEntryInfo.SetDialogVariable( 'news_item_body', item.description );


elEntry.FindChildInLayoutFile( 'NewsEntryBlurTarget' ).AddBlurPanel( elEntryInfo );

elEntry.SetPanelEvent( "onactivate", function( link, elEntry, clearNew )
{
SteamOverlayAPI.OpenURL( link );

if ( clearNew )
{
GameInterfaceAPI.SetSettingString( 'ui_news_last_read_link', link );
elEntry.RemoveClass( 'new' );
}

}.bind( SteamOverlayAPI, item.link, elEntry, i == 0 ) );

} );
};

return {
GetRssFeed : _GetRssFeed,
OnRssFeedReceived: _OnRssFeedReceived,
Init: _Init,
HTMLFinishRequest: _HTMLFinishRequest,
HTMLOpenPopupTab: _HTMLOpenPopupTab
};
})();


( function()
{
NewsPanel.GetRssFeed();
$.RegisterForUnhandledEvent( "PanoramaComponent_Blog_RSSFeedReceived", NewsPanel.OnRssFeedReceived );
NewsPanel.Init();
$.RegisterEventHandler("HTMLFinishRequest", $.GetContextPanel(), NewsPanel.HTMLFinishRequest);
$.RegisterEventHandler("HTMLOpenPopupTab", $.GetContextPanel(), NewsPanel.HTMLOpenPopupTab);
})();
2 changes: 1 addition & 1 deletion panorama/styles/mainmenu_news.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
width: 100%;
height: fill-parent-flow( 1 );
background-color: blurBackgroundColor;
background-color: #0a0a0a;
margin-bottom: 16px;
flow-children: down;

Expand Down