Changeset - r22841:0453c16d3b23
[Not reviewed]
master
0 5 0
Niels Martin Hansen - 6 years ago 2018-03-20 16:06:39
nielsm@indvikleren.dk
Feature #6090: Change music set during gameplay
5 files changed with 79 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -671,17 +671,20 @@ STR_MUSIC_TOOLTIP_TOGGLE_PROGRAM_SHUFFLE
 
STR_MUSIC_TOOLTIP_SHOW_MUSIC_TRACK_SELECTION                    :{BLACK}Show music track selection window
 

	
 
STR_ERROR_NO_SONGS                                              :{WHITE}A music set without songs has been selected. No songs will be played
 

	
 
# Playlist window
 
STR_PLAYLIST_MUSIC_PROGRAM_SELECTION                            :{WHITE}Music Programme Selection
 
STR_PLAYLIST_MUSIC_SELECTION_SETNAME                            :{WHITE}Music Programme - '{RAW_STRING}'
 
STR_PLAYLIST_TRACK_NAME                                         :{TINY_FONT}{LTBLUE}{ZEROFILL_NUM} "{RAW_STRING}"
 
STR_PLAYLIST_TRACK_INDEX                                        :{TINY_FONT}{BLACK}Track Index
 
STR_PLAYLIST_PROGRAM                                            :{TINY_FONT}{BLACK}Programme - '{STRING}'
 
STR_PLAYLIST_CLEAR                                              :{TINY_FONT}{BLACK}Clear
 
STR_PLAYLIST_CHANGE_SET                                         :{BLACK}Change set
 
STR_PLAYLIST_TOOLTIP_CLEAR_CURRENT_PROGRAM_CUSTOM1              :{BLACK}Clear current programme (Custom1 or Custom2 only)
 
STR_PLAYLIST_TOOLTIP_CHANGE_SET                                 :{BLACK}Change music selection to another installed set
 
STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK                         :{BLACK}Click on music track to add to current programme (Custom1 or Custom2 only)
 
STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK                      :{BLACK}Click on music track to remove it from current programme (Custom1 or Custom2 only)
 

	
 
# Highscore window
 
STR_HIGHSCORE_TOP_COMPANIES_WHO_REACHED                         :{BIG_FONT}{BLACK}Top companies who reached {NUM}
 
STR_HIGHSCORE_TOP_COMPANIES_NETWORK_GAME                        :{BIG_FONT}{BLACK}Company League Table in {NUM}
src/music_gui.cpp
Show inline comments
 
@@ -21,12 +21,15 @@
 
#include "zoom_func.h"
 
#include "core/random_func.hpp"
 
#include "error.h"
 
#include "core/geometry_func.hpp"
 
#include "string_func.h"
 
#include "settings_type.h"
 
#include "settings_gui.h"
 
#include "widgets/dropdown_func.h"
 
#include "widgets/dropdown_type.h"
 

	
 
#include "widgets/music_widget.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
@@ -300,12 +303,42 @@ static void SelectPlaylist(byte list)
 
{
 
	_settings_client.music.playlist = list;
 
	InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
 
	InvalidateWindowData(WC_MUSIC_WINDOW, 0);
 
}
 

	
 
/**
 
 * Change the configured music set and reset playback
 
 * @param index Index of music set to switch to
 
 */
 
void ChangeMusicSet(int index)
 
{
 
	if (BaseMusic::GetIndexOfUsedSet() == index) return;
 

	
 
	/* Resume playback after switching?
 
	 * Always if music is already playing, and also if the user is switching
 
	 * away from an empty music set.
 
	 * If the user switches away from an empty set, assume it's because they
 
	 * want to hear music now. */
 
	bool shouldplay = _song_is_active || (BaseMusic::GetUsedSet()->num_available == 0);
 
	StopMusic();
 

	
 
	const char *name = BaseMusic::GetSet(index)->name;
 
	BaseMusic::SetSet(name);
 
	free(BaseMusic::ini_set);
 
	BaseMusic::ini_set = stredup(name);
 

	
 
	InitializeMusic();
 
	ResetPlaylist();
 
	_settings_client.music.playing = shouldplay;
 

	
 
	InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
 
	InvalidateWindowData(WC_MUSIC_WINDOW, 0);
 
	InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS, 0, true);
 
}
 

	
 
struct MusicTrackSelectionWindow : public Window {
 
	MusicTrackSelectionWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
 
	{
 
		this->InitNested(number);
 
		this->LowerWidget(WID_MTS_LIST_LEFT);
 
		this->LowerWidget(WID_MTS_LIST_RIGHT);
 
@@ -316,12 +349,15 @@ struct MusicTrackSelectionWindow : publi
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case WID_MTS_PLAYLIST:
 
				SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
 
				break;
 
			case WID_MTS_CAPTION:
 
				SetDParamStr(0, BaseMusic::GetUsedSet()->name);
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
@@ -453,12 +489,19 @@ struct MusicTrackSelectionWindow : publi
 

	
 
				this->SetDirty();
 
				ResetPlaylist();
 
				break;
 
			}
 

	
 
			case WID_MTS_MUSICSET: {
 
				int selected = 0;
 
				DropDownList *dropdown = BuildMusicSetDropDownList(&selected);
 
				ShowDropDownList(this, dropdown, selected, widget, 0, true, false);
 
				break;
 
			}
 

	
 
			case WID_MTS_CLEAR: // clear
 
				for (uint i = 0; _playlists[_settings_client.music.playlist][i] != 0; i++) _playlists[_settings_client.music.playlist][i] = 0;
 
				this->SetDirty();
 
				StopMusic();
 
				ResetPlaylist();
 
				break;
 
@@ -468,18 +511,31 @@ struct MusicTrackSelectionWindow : publi
 
				SelectPlaylist(widget - WID_MTS_ALL);
 
				StopMusic();
 
				ResetPlaylist();
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
 
			case WID_MTS_MUSICSET:
 
				ChangeMusicSet(index);
 
				break;
 
			default:
 
				NOT_REACHED();
 
				break;
 
		}
 
	}
 
};
 

	
 
static const NWidgetPart _nested_music_track_selection_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_PLAYLIST_MUSIC_PROGRAM_SELECTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, WID_MTS_CAPTION), SetDataTip(STR_PLAYLIST_MUSIC_SELECTION_SETNAME, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_MTS_MUSICSET), SetDataTip(STR_PLAYLIST_CHANGE_SET, STR_PLAYLIST_TOOLTIP_CHANGE_SET),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY),
 
		NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
 
			/* Left panel. */
 
			NWidget(NWID_VERTICAL),
 
				NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
src/settings_gui.cpp
Show inline comments
 
@@ -111,25 +111,30 @@ static int GetCurRes()
 
	return i;
 
}
 

	
 
static void ShowCustCurrency();
 

	
 
template <class T>
 
static DropDownList *BuiltSetDropDownList(int *selected_index)
 
static DropDownList *BuildSetDropDownList(int *selected_index, bool allow_selection)
 
{
 
	int n = T::GetNumSets();
 
	*selected_index = T::GetIndexOfUsedSet();
 

	
 
	DropDownList *list = new DropDownList();
 
	for (int i = 0; i < n; i++) {
 
		*list->Append() = new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i));
 
		*list->Append() = new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i));
 
	}
 

	
 
	return list;
 
}
 

	
 
DropDownList *BuildMusicSetDropDownList(int *selected_index)
 
{
 
	return BuildSetDropDownList<BaseMusic>(selected_index, true);
 
}
 

	
 
/** Window for displaying the textfile of a BaseSet. */
 
template <class TBaseSet>
 
struct BaseSetTextfileWindow : public TextfileWindow {
 
	const TBaseSet* baseset; ///< View the textfile of this BaseSet.
 
	StringID content_type;   ///< STR_CONTENT_TYPE_xxx for title.
 

	
 
@@ -294,21 +299,21 @@ struct GameOptionsWindow : Window {
 
					*list->Append() = new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i);
 
				}
 
				break;
 
			}
 

	
 
			case WID_GO_BASE_GRF_DROPDOWN:
 
				list = BuiltSetDropDownList<BaseGraphics>(selected_index);
 
				list = BuildSetDropDownList<BaseGraphics>(selected_index, (_game_mode == GM_MENU));
 
				break;
 

	
 
			case WID_GO_BASE_SFX_DROPDOWN:
 
				list = BuiltSetDropDownList<BaseSounds>(selected_index);
 
				list = BuildSetDropDownList<BaseSounds>(selected_index, (_game_mode == GM_MENU));
 
				break;
 

	
 
			case WID_GO_BASE_MUSIC_DROPDOWN:
 
				list = BuiltSetDropDownList<BaseMusic>(selected_index);
 
				list = BuildMusicSetDropDownList(selected_index);
 
				break;
 

	
 
			default:
 
				return NULL;
 
		}
 

	
 
@@ -541,13 +546,13 @@ struct GameOptionsWindow : Window {
 

	
 
			case WID_GO_BASE_SFX_DROPDOWN:
 
				this->SetMediaSet<BaseSounds>(index);
 
				break;
 

	
 
			case WID_GO_BASE_MUSIC_DROPDOWN:
 
				this->SetMediaSet<BaseMusic>(index);
 
				ChangeMusicSet(index);
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
src/settings_gui.h
Show inline comments
 
@@ -10,18 +10,24 @@
 
/** @file settings_gui.h Functions for setting GUIs. */
 

	
 
#ifndef SETTING_GUI_H
 
#define SETTING_GUI_H
 

	
 
#include "gfx_type.h"
 
#include "widgets/dropdown_type.h"
 

	
 
/** Width of setting buttons */
 
#define SETTING_BUTTON_WIDTH  ((int)NWidgetScrollbar::GetHorizontalDimension().width * 2)
 
/** Height of setting buttons */
 
#define SETTING_BUTTON_HEIGHT ((int)NWidgetScrollbar::GetHorizontalDimension().height)
 

	
 
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right);
 
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable);
 
void DrawBoolButton(int x, int y, bool state, bool clickable);
 

	
 
DropDownList *BuildMusicSetDropDownList(int *selected_index);
 

	
 
/* Actually implemented in music_gui.cpp */
 
void ChangeMusicSet(int index);
 

	
 
#endif /* SETTING_GUI_H */
 

	
src/widgets/music_widget.h
Show inline comments
 
@@ -11,15 +11,17 @@
 

	
 
#ifndef WIDGETS_MUSIC_WIDGET_H
 
#define WIDGETS_MUSIC_WIDGET_H
 

	
 
/** Widgets of the #MusicTrackSelectionWindow class. */
 
enum MusicTrackSelectionWidgets {
 
	WID_MTS_CAPTION,    ///< Window caption.
 
	WID_MTS_LIST_LEFT,  ///< Left button.
 
	WID_MTS_PLAYLIST,   ///< Playlist.
 
	WID_MTS_LIST_RIGHT, ///< Right button.
 
	WID_MTS_MUSICSET,   ///< Music set selection.
 
	WID_MTS_ALL,        ///< All button.
 
	WID_MTS_OLD,        ///< Old button.
 
	WID_MTS_NEW,        ///< New button.
 
	WID_MTS_EZY,        ///< Ezy button.
 
	WID_MTS_CUSTOM1,    ///< Custom1 button.
 
	WID_MTS_CUSTOM2,    ///< Custom2 button.
0 comments (0 inline, 0 general)